bool load_font_config() { //read font config separately, so we do not have to re-read the whole //config when changing languages config cfg; try { const std::string& cfg_path = filesystem::get_wml_location("hardwired/fonts.cfg"); if(cfg_path.empty()) { ERR_FT << "could not resolve path to fonts.cfg, file not found\n"; return false; } filesystem::scoped_istream stream = preprocess_file(cfg_path); read(cfg, *stream); } catch(config::error &e) { ERR_FT << "could not read fonts.cfg:\n" << e.message << '\n'; return false; } const config &fonts_config = cfg.child("fonts"); if (!fonts_config) return false; std::set<std::string> known_fonts; for (const config &font : fonts_config.child_range("font")) { known_fonts.insert(font["name"]); if (font.has_attribute("bold_name")) { known_fonts.insert(font["bold_name"]); } if (font.has_attribute("italic_name")) { known_fonts.insert(font["italic_name"]); } } family_order_sans = fonts_config["family_order"]; family_order_mono = fonts_config["family_order_monospace"]; if(family_order_mono.empty()) { ERR_FT << "No monospace font family order defined, falling back to sans serif order\n"; family_order_mono = family_order_sans; } std::vector<font::subset_descriptor> fontlist; for(auto font : utils::split(fonts_config["order"])) { add_font_to_fontlist(fonts_config, fontlist, font); known_fonts.erase(font); } for(auto kfont : known_fonts) { add_font_to_fontlist(fonts_config, fontlist, kfont); } if(fontlist.empty()) return false; sdl_ttf::set_font_list(fontlist); return true; }
void team::change_team(const std::string& name, const t_string& user_name) { info_.team_name = name; if(!user_name.empty()) { info_.user_team_name = user_name; } else { info_.user_team_name = name; } clear_caches(); }
void write_key_val(std::ostream &out, const std::string &key, const t_string &value, unsigned int level, std::string& textdomain) { bool first = true; if (value.empty()) { out << std::string(level, '\t') << key << AttributeEquals << AttributePrefix << AttributePostfix << AttributeEndPostfix;; return; } for(t_string::walker w(value); !w.eos(); w.next()) { std::string part(w.begin(), w.end()); if(w.translatable()) { if(w.textdomain() != textdomain) { out << TextdomainPrefix << w.textdomain() << TextdomainPostfix; textdomain = w.textdomain(); } if(first) { out << std::string(level, '\t') << key << AttributeEquals; } out << TranslatableAttributePrefix << escaped_string(part) << AttributePostfix; } else { if(first) { out << std::string(level, '\t') << key << AttributeEquals; } out << AttributePrefix << escaped_string(part) << AttributePostfix; } if(w.last()) { out << AttributeEndPostfix; } else { out << AttributeContPostfix; out << std::string(level+1, '\t'); } first = false; } }
void ttext::draw(surface& canvas , const game_logic::map_formula_callable& variables) { assert(variables.has_key("text")); // We first need to determine the size of the text which need the rendered // text. So resolve and render the text first and then start to resolve // the other formulas. const t_string text = text_(variables); if(text.empty()) { DBG_GUI_D << "Text: no text to render, leave.\n"; return; } static font::ttext text_renderer; text_renderer.set_text(text, text_markup_(variables)); text_renderer.set_font_size(font_size_) .set_font_style(font_style_) .set_alignment(text_alignment_(variables)) .set_foreground_color(color_) .set_maximum_width(maximum_width_(variables)) .set_maximum_height(maximum_height_(variables)) .set_ellipse_mode(variables.has_key("text_wrap_mode") ? static_cast<PangoEllipsizeMode> (variables.query_value("text_wrap_mode").as_int()) : PANGO_ELLIPSIZE_END); surface surf = text_renderer.render(); if(surf->w == 0) { DBG_GUI_D << "Text: Rendering '" << text << "' resulted in an empty canvas, leave.\n"; return; } game_logic::map_formula_callable local_variables(variables); local_variables.add("text_width", variant(surf->w)); local_variables.add("text_height", variant(surf->h)); /* std::cerr << "Text: drawing text '" << text << " maximum width " << maximum_width_(variables) << " maximum height " << maximum_height_(variables) << " text width " << surf->w << " text height " << surf->h; */ ///@todo formulas are now recalculated every draw cycle which is a // bit silly unless there has been a resize. So to optimize we should // use an extra flag or do the calculation in a separate routine. const unsigned x = x_(local_variables); const unsigned y = y_(local_variables); const unsigned w = w_(local_variables); const unsigned h = h_(local_variables); DBG_GUI_D << "Text: drawing text '" << text << "' drawn from " << x << ',' << y << " width " << w << " height " << h << " canvas size " << canvas->w << ',' << canvas->h << ".\n"; VALIDATE(static_cast<int>(x) < canvas->w && static_cast<int>(y) < canvas->h , _("Text doesn't start on canvas.")); // A text might be to long and will be clipped. if(surf->w > static_cast<int>(w)) { WRN_GUI_D << "Text: text is too wide for the " "canvas and will be clipped.\n"; } if(surf->h > static_cast<int>(h)) { WRN_GUI_D << "Text: text is too high for the " "canvas and will be clipped.\n"; } SDL_Rect dst = ::create_rect(x, y, canvas->w, canvas->h); blit_surface(surf, 0, canvas, &dst); }
/*WIKI * @begin{tag}{name="tip"}{min="0"}{max="-1"} * @begin{table}{config} * source & t_string & & Author * text & t_string & & Text of the tip. * @end{table} * @end{tag}{name="tip"} * @end{parent}{name="gui/"} */ const std::string& tgui_definition::read(const config& cfg) { id = cfg["id"].str(); description = cfg["description"]; VALIDATE(!id.empty(), missing_mandatory_wml_key("gui", "id")); VALIDATE(!description.empty(), missing_mandatory_wml_key("gui", "description")); DBG_GUI_P << "Parsing gui " << id << '\n'; /***** Control definitions *****/ for(auto & widget_type : registred_widget_type()) { widget_type.second(*this, widget_type.first, cfg, nullptr); } /***** Window types *****/ for(const auto & w : cfg.child_range("window")) { std::pair<std::string, twindow_builder> child; child.first = child.second.read(w); window_types.insert(child); } if(id == "default") { // The default gui needs to define all window types since we're the // fallback in case another gui doesn't define the window type. for(std::vector<std::string>::const_iterator itor = registered_window_types().begin(); itor != registered_window_types().end(); ++itor) { const std::string error_msg( "Window not defined in WML: '" + *itor + "'. Perhaps a mismatch between data and source versions." " Try --data-dir <trunk-dir>"); VALIDATE(window_types.find(*itor) != window_types.end(), error_msg); } } /***** settings *****/ /** * @todo Regarding sounds: * Need to evaluate but probably we want the widget definition be able to: * - Override the default (and clear it). This will allow toggle buttons in * a * listbox to sound like a toggle panel. * - Override the default and above per instance of the widget, some buttons * can give a different sound. */ const config& settings = cfg.child("settings"); popup_show_delay_ = settings["popup_show_delay"]; popup_show_time_ = settings["popup_show_time"]; help_show_time_ = settings["help_show_time"]; double_click_time_ = settings["double_click_time"]; repeat_button_repeat_time_ = settings["repeat_button_repeat_time"]; VALIDATE(double_click_time_, missing_mandatory_wml_key("settings", "double_click_time")); sound_button_click_ = settings["sound_button_click"].str(); sound_toggle_button_click_ = settings["sound_toggle_button_click"].str(); sound_toggle_panel_click_ = settings["sound_toggle_panel_click"].str(); sound_slider_adjust_ = settings["sound_slider_adjust"].str(); has_helptip_message_ = settings["has_helptip_message"]; VALIDATE(!has_helptip_message_.empty(), missing_mandatory_wml_key("[settings]", "has_helptip_message")); tips_ = tips::load(cfg); return id; }
bool DirUtil::EnumFilesOrDir( const t_string &path, std::vector<t_string> &fileList, int enumType) { if (path.empty()) { return false; } t_string strDirPath = MakePathRegular(path); if (strDirPath.find_last_of(DEFAULT_PATH_SPLITER) != strDirPath.length() - 1) { strDirPath.push_back(DEFAULT_PATH_SPLITER); } t_string filter = strDirPath; filter.append(_T("*")); WIN32_FIND_DATA fd; HANDLE hFind = FindFirstFile( filter.c_str(), &fd ); if ( hFind == INVALID_HANDLE_VALUE ){ return false; } do { if (ENUM_FILE & enumType) { if (!(fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)) { if (ENUM_ONLY_FILE_NAME & enumType) { fileList.push_back(fd.cFileName); } else { t_string fp = strDirPath; fp.append(fd.cFileName); fileList.push_back(fp); } } } if (ENUM_DIR & enumType) { if ( _tcscmp(fd.cFileName, _T(".")) != 0 && _tcscmp(fd.cFileName, _T("..")) != 0 && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { if (ENUM_ONLY_FILE_NAME & enumType) { fileList.push_back(fd.cFileName); } else { t_string fp = strDirPath; fp.append(fd.cFileName); fileList.push_back(fp); } } } } while ( FindNextFile( hFind, &fd ) != 0 ); FindClose( hFind ); return true; }