CL_String CL_CSSLayoutNode_Impl::print_node(CL_CSSBoxNode *node, int indent) { CL_String output_string; output_string += CL_String(indent*2, ' '); CL_CSSBoxElement *element = dynamic_cast<CL_CSSBoxElement*>(node); CL_CSSBoxText *text = dynamic_cast<CL_CSSBoxText*>(node); if (element) { //if (element->computed_properties.font_family.names.empty()) output_string += cl_format("%1 { display: %2; float: %3; width: %4 }\r\n", element->name, to_string(element->computed_properties.display), to_string(element->computed_properties.float_box), to_string(element->computed_properties.width)); //else // output_string += cl_format("%1 { font-family: %2 }\r\n", element->name, element->computed_properties.font_family.names[0].name); } else if (text) { output_string += cl_format("[%1]\r\n", escape_text(text->text)); } else { output_string += cl_format("unknown\r\n"); } CL_CSSBoxNode *cur = node->get_first_child(); while (cur) { output_string += print_node(cur, indent+1); cur = cur->get_next_sibling(); } return output_string; }
ShaderColorInstanced::ShaderColorInstanced(CL_GraphicContext &gc) { CL_ShaderObject vertex_shader(gc, cl_shadertype_vertex, vertex); if(!vertex_shader.compile()) { throw CL_Exception(cl_format("Unable to compile vertex shader object: %1", vertex_shader.get_info_log())); } CL_ShaderObject fragment_shader(gc, cl_shadertype_fragment, fragment); if(!fragment_shader.compile()) { throw CL_Exception(cl_format("Unable to compile fragment shader object: %1", fragment_shader.get_info_log())); } program_object = CL_ProgramObject(gc); program_object.attach(vertex_shader); program_object.attach(fragment_shader); program_object.bind_attribute_location(0, "InPosition"); program_object.bind_attribute_location(1, "InNormal"); if (!program_object.link()) { throw CL_Exception(cl_format("Unable to link program object: %1", program_object.get_info_log())); } material_updated = false; light_updated = false; material_shininess = 64.0f; material_emission = CL_Vec4f(0.0f, 0.0f, 0.0f, 1.0f); light_vector = CL_Vec4f(0.0f, 0.0f, 1.0f, 0.0f); light_specular = CL_Vec4f(0.7f, 0.7f, 0.7f, 1.0f); light_diffuse = CL_Vec4f(0.7f, 0.7f, 0.7f, 1.0f); }
void CL_FontProvider_Freetype::load_font(const CL_StringRef &resource_id, CL_ResourceManager *resources) { CL_Resource resource = resources->get_resource(resource_id); if (resource.get_type() != "font") throw CL_Exception(cl_format("Resource '%1' is not of type 'font'", resource.get_name())); CL_DomElement freetype_element = resource.get_element().named_item("freetype").to_element(); if (freetype_element.is_null()) throw CL_Exception(cl_format("Font resource '%1' has no 'freetype' child element", resource.get_name())); CL_FontDescription desc; if (freetype_element.has_attribute("file")) desc.set_typeface_name(freetype_element.get_attribute("file")); else throw CL_Exception(cl_format("Font resource '%1' has no 'file' attribute", resource.get_name())); if (freetype_element.has_attribute("height")) desc.set_height(freetype_element.get_attribute_int("height", 0)); else throw CL_Exception(cl_format("Font resource '%1' has no 'height' attribute", resource.get_name())); if (freetype_element.has_attribute("average_width")) desc.set_average_width(freetype_element.get_attribute_int("average_width", 0)); if (freetype_element.has_attribute("anti_alias")) desc.set_anti_alias(freetype_element.get_attribute_bool("anti_alias", true)); if (freetype_element.has_attribute("subpixel")) desc.set_subpixel(freetype_element.get_attribute_bool("subpixel", true)); load_font(desc, resources->get_directory(resource)); }
ShaderDepth::ShaderDepth(CL_GraphicContext &gc) { CL_ShaderObject vertex_shader(gc, cl_shadertype_vertex, vertex); if(!vertex_shader.compile()) { throw CL_Exception(cl_format("Unable to compile vertex shader object: %1", vertex_shader.get_info_log())); } CL_ShaderObject fragment_shader(gc, cl_shadertype_fragment, fragment); if(!fragment_shader.compile()) { throw CL_Exception(cl_format("Unable to compile fragment shader object: %1", fragment_shader.get_info_log())); } program_object = CL_ProgramObject(gc); program_object.attach(vertex_shader); program_object.attach(fragment_shader); program_object.bind_attribute_location(0, "InPosition"); if (!program_object.link()) { throw CL_Exception(cl_format("Unable to link program object: %1", program_object.get_info_log())); } material_updated = false; material_ambient = CL_Vec4f(0.9f, 0.2f, 0.2f, 1.0f); }
void TexturePacker::process_resource(CL_Resource &item_resource, std::vector<CL_Subtexture> &packed_sub_textures, std::map<CL_Texture, CL_String> &generated_texture_filenames, int &generated_texture_index, const CL_String &image_pathname ) { // Found a sprite resource, lets modify its content! CL_Resource resource = item_resource; // Iterate through all nodes, and remove all previous image tags CL_DomElement &element = resource.get_element(); CL_DomNode cur = element.get_first_child(); while (!cur.is_null()) { CL_DomNode next = cur.get_next_sibling(); CL_DomNode::NodeType nodeType = (CL_DomNode::NodeType)cur.get_node_type(); // Only remove the <image> tag, as we want to keep the other sprite attributes if (cur.get_node_name() == "image") element.remove_child(cur); cur = next; } // Add new image tag to resource DOM std::vector<CL_Subtexture>::size_type index, size; size = packed_sub_textures.size(); for(index = 0; index < size; ++index) { CL_Subtexture subtexture = packed_sub_textures[index]; // Try to find out if we already have created a texture-on-disk for this subtexture CL_String texture_filename; CL_Texture texture = subtexture.get_texture(); std::map<CL_Texture, CL_String>::iterator it; it = generated_texture_filenames.find(texture); if(it == generated_texture_filenames.end()) { // Texture not found, generate a filename and dump texture to disk texture_filename = cl_format("texture%1.png", ++generated_texture_index); CL_PNGProvider::save(texture.get_pixeldata(), image_pathname + texture_filename); generated_texture_filenames[texture] = texture_filename; } else { // Previously dumped textures, lets reuse the filename texture_filename = (*it).second; } // Add <grid> DOM element CL_DomElement new_grid_element = element.get_owner_document().create_element("grid"); new_grid_element.set_attribute("pos", cl_format("%1,%2", subtexture.get_geometry().left + last_border_size, subtexture.get_geometry().top + last_border_size)); new_grid_element.set_attribute("size", cl_format("%1,%2", subtexture.get_geometry().get_width()- last_border_size*2, subtexture.get_geometry().get_height()- last_border_size*2)); // Add <image> DOM element CL_DomElement new_image_element = element.get_owner_document().create_element("image"); new_image_element.set_attribute("file", texture_filename); new_image_element.append_child(new_grid_element); // Add <image> element under <sprite> element element.append_child(new_image_element); } }
CL_String HTMLPage::download_url(const CL_String &page_url, const CL_String &refererer_url) { HTMLUrl url(page_url, refererer_url); CL_Console::write_line("Downloading URL: %1", url.to_string()); CL_String8 request; request = cl_format("GET %1 HTTP/1.1\r\n", url.path+url.query); if (refererer_url.empty()) request += cl_format("Host: %1\r\nConnection: close\r\nAccept: text/plain, text/html\r\nUser-Agent: CSSTokenize/0.1\r\n\r\n", url.host); else request += cl_format("Host: %1\r\nConnection: close\r\nReferer: %2\r\nAccept: text/plain, text/html\r\nUser-Agent: CSSTokenize/0.1\r\n\r\n", url.host, refererer_url); //MessageBoxW(0, CL_StringHelp::utf8_to_ucs2(cl_format("GET %1 HTTP/1.1\r\n", url.path+url.query)).c_str(), L"Download URL", MB_OK);; CL_TCPConnection connection(CL_SocketName(url.host, url.port)); connection.set_nodelay(true); connection.send(request.data(), request.length(), true); CL_String response; while (connection.get_read_event().wait(15000)) { char buffer[16*1024]; int received = connection.read(buffer, 16*1024, false); if (received == 0) break; response.append(buffer, received); } connection.disconnect_graceful(); CL_String response_header = response.substr(0, response.find("\r\n\r\n")); CL_String content = response.substr(response_header.length() + 4); if (response_header.find("Transfer-Encoding: chunked") != CL_String::npos) { CL_String::size_type start = 0; while (true) { CL_String::size_type end = content.find("\r\n", start); if (end == CL_String::npos) end = content.length(); CL_String str_length = content.substr(start, end-start); int length = CL_StringHelp::text_to_int(str_length, 16); content = content.substr(0, start) + content.substr(end+2); start += length; end = content.find("\r\n", start); if (end == CL_String::npos) end = content.length(); content = content.substr(0, start) + content.substr(end+2); if (length == 0) break; } } return content; }
int CL_CSSDocument_Impl::load_keyword(const char *keyword, unsigned char *data, int pos, int length) { int keyword_len = strlen(keyword); if (pos+keyword_len > length) throw CL_Exception(cl_format("Expected %1 at position %2", keyword, pos)); CL_String8 s((char *) data+pos, keyword_len); if (CL_StringHelp::compare(keyword, s, true) != 0) throw CL_Exception(cl_format("Expected %1 at position %2", keyword, pos)); return pos + keyword_len; }
Sound::Sound(const std::string &name) : mPaused(false) { CL_SharedPtr<SoundResource> resource = cl_dynamic_pointer_cast<SoundResource>(ResourceManager::getSingleton().getResource(name)); if (!resource) throw Exception(cl_format("Resource '%1' is not a sound resource", name)); if (!resource->isLoaded()) throw Exception(cl_format("Sound '%1' is not loaded", name)); mSession = resource->getSoundBuffer().prepare(); }
void CL_RegistryKey::delete_key(const CL_StringRef &subkey, bool recursive) { if (recursive) { DWORD result = SHDeleteKey(impl->key, CL_StringHelp::utf8_to_ucs2(subkey).c_str()); if (result != ERROR_SUCCESS) throw CL_Exception(cl_format("Unable to delete registry key %1", subkey)); } else { LONG result = RegDeleteKey(impl->key, CL_StringHelp::utf8_to_ucs2(subkey).c_str()); if (result != ERROR_SUCCESS) throw CL_Exception(cl_format("Unable to delete registry key %1", subkey)); } }
int CL_PgsqlReaderProvider::get_name_index(const CL_StringRef &name) const { int index = PQfnumber(result, name.c_str()); if (index < 0) throw CL_Exception(cl_format("No such column name %1", name)); return index; }
CL_Resource CL_ResourceManager::get_resource( const CL_String &resource_id, bool resolve_alias, int reserved) { std::map<CL_String, CL_Resource>::const_iterator it; it = impl->resources.find(resource_id); if (it != impl->resources.end()) return it->second; std::vector<CL_ResourceManager>::size_type i; for (i = 0; i < impl->additional_resources.size(); i++) { try { return impl->additional_resources[i].get_resource( resource_id, resolve_alias, reserved); } catch (const CL_Exception&) { } } throw CL_Exception(cl_format("Resource not found: %1", resource_id)); return CL_Resource(impl->document.get_document_element(), *this); }
void Options::slider_cutoff_changed() { float value = get_value(slider_cutoff, max_angle_value); CL_String text(cl_format("Cutoff : %1", value)); label_cutoff->set_text(text); spot_light_cutoff = value; }
void Options::slider_exponent_changed() { float value = get_value(slider_exponent, max_exponent_value); CL_String text(cl_format("Exponent : %1", value)); label_exponent->set_text(text); spot_light_exponent = value; }
CL_DomNode CL_DomNode::select_node(const CL_DomString &xpath_expression) const { std::vector<CL_DomNode> nodes = select_nodes(xpath_expression); if (nodes.empty()) throw CL_Exception(cl_format("Xpath did not match any node: %1", xpath_expression)); return nodes[0]; }
void Options::slider_light_zpos_changed() { float value = get_value(slider_light_zpos, max_position_value); CL_String text(cl_format("Offset Z pos : %1", value)); label_light_zpos->set_text(text); spot_light_position.z = value; }
void Options::slider_specular_blue_changed() { float value = get_value(slider_specular_blue, max_color_value); CL_String text(cl_format("Specular Blue : %1", value)); label_specular_blue->set_text(text); get_selected_specular().b = value; }
CL_RegistryKey CL_RegistryKey::create_key(const CL_StringRef &subkey, unsigned int access_rights, CreateFlags create_flags) { DWORD disposition = 0; HKEY new_key = 0; LONG result = RegCreateKeyEx(impl->key, CL_StringHelp::utf8_to_ucs2(subkey).c_str(), 0, 0, (create_flags & create_volatile) ? REG_OPTION_VOLATILE : REG_OPTION_NON_VOLATILE, access_rights, 0, &new_key, &disposition); if (result != ERROR_SUCCESS) throw CL_Exception(cl_format("Unable to create registry key %1", subkey)); if (disposition != REG_CREATED_NEW_KEY && (create_flags & create_new)) { RegCloseKey(new_key); throw CL_Exception(cl_format("Key already exists: %1", subkey)); } return CL_RegistryKey(new_key); }
void CL_RegistryKey::delete_key(PredefinedKey key, const CL_StringRef &subkey, bool recursive) { HKEY hkey = CL_RegistryKey_Impl::get_predefined_hkey(key); if (recursive) { DWORD result = SHDeleteKey(hkey, CL_StringHelp::utf8_to_ucs2(subkey).c_str()); if (result != ERROR_SUCCESS) throw CL_Exception(cl_format("Unable to delete registry key %1", subkey)); } else { LONG result = RegDeleteKey(hkey, CL_StringHelp::utf8_to_ucs2(subkey).c_str()); if (result != ERROR_SUCCESS) throw CL_Exception(cl_format("Unable to delete registry key %1", subkey)); } }
PixelPipeline::~PixelPipeline() { wait_for_workers(); #if defined(WIN32) && defined(PROFILE_PIPELINE) profiler.end_time = __rdtsc(); #endif event_stop.set(); for (std::vector<Thread>::size_type i = 0; i < worker_threads.size(); i++) worker_threads[i].join(); for (size_t i = 0; i < queue_max; i++) { delete command_queue[i]; command_queue[i] = 0; } if (cur_block && cur_block->refcount == 1) delete[] (char*) cur_block; #if defined(WIN32) && defined(PROFILE_PIPELINE) MessageBoxA(0, cl_format("Queue = %1\r\nSetEvent = %2\r\nWaitForWorkers = %3\r\nWaitForSpace = %4\r\nAllocFree = %5", (int)(profiler.queue_time*100/(profiler.end_time-profiler.start_time)), (int)(profiler.set_event_time*100/(profiler.end_time-profiler.start_time)), (int)(profiler.wait_for_workers_time*100/(profiler.end_time-profiler.start_time)), (int)(profiler.wait_for_space_time*100/(profiler.end_time-profiler.start_time)), (int)(profiler.alloc_time*100/(profiler.end_time-profiler.start_time))).c_str(), "DEBUG", MB_OK); #endif }
TileMap::TileMap(CL_GraphicContext& gc, CL_ResourceManager& resmgr, const CL_String& tileset) : map_width(0), map_height(0), cur_map_x(0), cur_map_y(0) { CL_Resource res = resmgr.get_resource(tileset); if (res.get_type() != "tilemap") throw CL_Exception(cl_format("Resource %1 is not a tilemap", tileset)); CL_DomElement element = res.get_element(); levelname = element.get_attribute("name"); CL_String resource_name = element.get_attribute("resource"); map_width = element.get_attribute_int("width"); map_height = element.get_attribute_int("height"); tiles = CL_Sprite(gc, resource_name, &resmgr); float scalex, scaley; tiles.get_scale(scalex, scaley); tile_width = tiles.get_width() * scalex; tile_height = tiles.get_height() * scaley; auto layer_nodes = element.select_nodes("layer"); for (CL_DomNode& idx : layer_nodes) { CL_DomElement layer_element = idx.to_element(); CL_String layer_tiles = layer_element.get_first_child().get_node_value(); std::vector<CL_String> tile_indices = CL_StringHelp::split_text(layer_tiles, ","); MapLayer layer; layer.map.reserve(tile_indices.size()); for (auto& tile : tile_indices) layer.map.push_back(CL_StringHelp::text_to_int(tile)); layers.push_back(layer); } }
CL_String HTMLPage::load_css(const CL_String &csstext, const CL_String &base_url) { CL_String pagecss; CL_CSSTokenizer css_tokenizer(csstext); CL_CSSToken css_token; while (true) { css_tokenizer.read(css_token, true); if (css_token.type != CL_CSSToken::type_atkeyword || css_token.value != "import") break; css_tokenizer.read(css_token, true); if (css_token.type != CL_CSSToken::type_string) break; CL_String import_url = css_token.value; css_tokenizer.read(css_token, true); if (css_token.type != CL_CSSToken::type_semi_colon) break; CL_String css = download_url(import_url, base_url); pagecss += load_css(css, HTMLUrl(import_url, base_url).to_string()); } pagecss += cl_format("@-clan-base-uri \"%1\";\r\n", base_url); pagecss += csstext; return pagecss; }
CL_String CL_Directory::get_local_appdata(const CL_StringRef &company_name, const CL_StringRef &application_name, const CL_StringRef &version, bool create_dirs_if_missing) { #if defined(WIN32) TCHAR app_data[MAX_PATH]; if (FAILED(SHGetFolderPath(0, CSIDL_LOCAL_APPDATA, 0, SHGFP_TYPE_DEFAULT, app_data))) throw CL_Exception("SHGetFolderPath failed!"); CL_String configuration_path = cl_format("%1\\%2\\%3\\%4\\", app_data, company_name, application_name, version); if (create_dirs_if_missing) { CL_String::size_type prevPos = 0; while (true) { CL_String::size_type pos = configuration_path.find_first_of("\\/", prevPos); if (pos == CL_String::npos) break; CL_StringRef folder = configuration_path.substr(0, pos); CreateDirectory(CL_StringHelp::utf8_to_ucs2(folder).c_str(), 0); prevPos = pos + 1; } } return configuration_path; #elif defined(__APPLE__) throw CL_Exception("Congratulations, you got the task to implement CL_Directory::get_local_appdata on this platform."); #else return get_appdata(company_name, application_name, version, create_dirs_if_missing); #endif }
void ComponentTypes::set_id_name(CL_GUIComponent *new_component, int id) { if (component_count.find(id) == component_count.end()) component_count[id] = 1; new_component->set_id_name(cl_format("%1%2", new_component->get_type_name(), component_count[id]++)); }
void Options::slider_diffuse_green_changed() { float value = get_value(slider_diffuse_green, max_color_value); CL_String text(cl_format("Diffuse Green : %1", value)); label_diffuse_green->set_text(text); get_selected_diffuse().g = value; }
void OnlineRaceLogic::onPlayerLeaved(const CL_String &p_name) { // get the player Player &player = getPlayer(p_name); // remove from level getLevel().removeCar(&player.getCar()); // remove from game removePlayer(player); TPlayerList::iterator itor; bool found = false; for (itor = m_remotePlayers.begin(); itor != m_remotePlayers.end(); ++itor) { if (reinterpret_cast<unsigned> (itor->get()) == reinterpret_cast<unsigned> (&player)) { m_remotePlayers.erase(itor); found = true; break; } } G_ASSERT(found); display(cl_format("Player %1 leaved", p_name)); }
void Options::slider_diffuse_blue_changed() { float value = get_value(slider_diffuse_blue, max_color_value); CL_String text(cl_format("Diffuse Blue : %1", value)); label_diffuse_blue->set_text(text); get_selected_diffuse().b = value; }
CL_ShaderObject CL_ShaderObject::load(CL_GraphicContext &gc, const CL_StringRef &resource_id, CL_ResourceManager *resources) { CL_Resource resource = resources->get_resource(resource_id); CL_String filename = resource.get_element().get_attribute("file"); CL_String type = resource.get_element().get_tag_name(); CL_ShaderType shader_type; if (type == "fragment-shader") shader_type = cl_shadertype_fragment; else if (type == "vertex-shader") shader_type = cl_shadertype_vertex; else throw CL_Exception("CL_ShaderObject: Unknown shader type: " + type); CL_VirtualDirectory directory = resources->get_directory(resource); CL_IODevice file = directory.open_file(filename, CL_File::open_existing, CL_File::access_read, CL_File::share_read); int size = file.get_size(); CL_String8 source(size, 0); file.read(&source[0], size); CL_ShaderObject shader_object(gc, shader_type, CL_StringHelp::local8_to_text(source)); if (resource.get_element().get_attribute("compile", "true") == "true") if(!shader_object.compile()) throw CL_Exception(cl_format("Unable to compiler shader program %1: %2", resource_id, shader_object.get_info_log())); return shader_object; }
CL_String CL_Directory::get_resourcedata(const CL_StringRef &application_name) { #if defined(WIN32) TCHAR exe_filename[MAX_PATH]; DWORD result = GetModuleFileName(0, exe_filename, MAX_PATH); if (result == 0 || result == MAX_PATH) throw CL_Exception("GetModuleFileName failed!"); TCHAR drive[MAX_PATH], dir[MAX_PATH], filename[MAX_PATH], extension[MAX_PATH]; #ifdef _CRT_INSECURE_DEPRECATE _tsplitpath_s(exe_filename, drive, MAX_PATH, dir, MAX_PATH, filename, MAX_PATH, extension, MAX_PATH); #else _tsplitpath(exe_filename, drive, dir, filename, extension); #endif return cl_format("%1%2Resources\\", drive, dir); #elif defined(__APPLE__) throw CL_Exception("Congratulations, you got the task to implement CL_Directory::get_resourcedata on this platform."); #else //TODO: /// In Linux, this function will return the directory "../share/application_name/" /// relative to the executable, so if it is located in "/usr/bin" it will return /// "/usr/share/application_name/" /// (Assuming that is correct!) return "Resources/"; #endif }
void CL_RegistryKey::set_value_int(const CL_StringRef &name, int value) { DWORD v = value; LONG result = RegSetValueEx(impl->key, name.empty() ? 0 : CL_StringHelp::utf8_to_ucs2(name).c_str(), 0, REG_DWORD, (const BYTE *) &v, sizeof(DWORD)); if (result != ERROR_SUCCESS) throw CL_Exception(cl_format("Unable to set registry key value %1", name)); }
void Options::slider_specular_green_changed() { float value = get_value(slider_specular_green, max_color_value); CL_String text(cl_format("Specular Green : %1", value)); label_specular_green->set_text(text); get_selected_specular().g = value; }