static void do_resolve_rects(const config& cfg, config& resolved_config, config* resol_cfg = nullptr) { // recursively resolve children for(const config::any_child& value : cfg.all_children_range()) { config& childcfg = resolved_config.add_child(value.key); do_resolve_rects(value.cfg, childcfg, value.key == "resolution" ? &childcfg : resol_cfg); } // copy all key/values resolved_config.merge_attributes(cfg); // override default reference rect with "ref" parameter if any if(!cfg["ref"].empty()) { if(resol_cfg == nullptr) { ERR_DP << "Use of ref= outside a [resolution] block" << std::endl; } else { // DBG_DP << ">> Looking for " << cfg["ref"] << "\n"; const config& ref = find_ref(cfg["ref"], *resol_cfg); if(ref["id"].empty()) { ERR_DP << "Reference to non-existent rect id \"" << cfg["ref"] << "\"" << std::endl; } else if(ref["rect"].empty()) { ERR_DP << "Reference to id \"" << cfg["ref"] << "\" which does not have a \"rect\"\n"; } else { ref_rect = read_rect(ref); } } } // resolve the rect value to absolute coordinates if(!cfg["rect"].empty()) { resolved_config["rect"] = resolve_rect(cfg["rect"]); } }
static SDL_Rect read_sdl_rect(const config& cfg) { SDL_Rect sdlrect; const _rect rect = read_rect(cfg); sdlrect.x = rect.x1; sdlrect.y = rect.y1; sdlrect.w = (rect.x2 > rect.x1) ? (rect.x2 - rect.x1) : 0; sdlrect.h = (rect.y2 > rect.y1) ? (rect.y2 - rect.y1) : 0; return sdlrect; }
SDL_Rect read_sdl_rect(const std::string& str) { SDL_Rect sdlrect; const _rect rect = read_rect(str); sdlrect.x = rect.x1; sdlrect.y = rect.y1; sdlrect.w = (rect.x2 > rect.x1) ? (rect.x2 - rect.x1) : 0; sdlrect.h = (rect.y2 > rect.y1) ? (rect.y2 - rect.y1) : 0; return sdlrect; }
/** * \brief Load the configuration. */ void bf::configuration::load() { if ( create_config_file() ) { std::string path ( path_configuration::get_instance().get_config_directory() + s_config_file_name ); std::ifstream f( path.c_str() ); if (f) { claw::configuration_file config(f); main_rect = read_rect( config, s_main_frame_section ); } } } // configuration::load()
static void do_resolve_rects(const config& cfg, config& resolved_config, config* resol_cfg = NULL) { // recursively resolve children for(config::all_children_iterator i = cfg.ordered_begin(); i != cfg.ordered_end(); ++i) { const config::all_children_iterator::value_type& value = *i; config& childcfg = resolved_config.add_child(value.first); do_resolve_rects(*value.second, childcfg, (value.first == "resolution") ? &childcfg : resol_cfg); } // copy all key/values for(string_map::const_iterator j = cfg.values.begin(); j != cfg.values.end(); ++j) { resolved_config.values[j->first] = j->second; } // override default reference rect with "ref" parameter if any if (!cfg["ref"].empty()) { if (resol_cfg == NULL) { ERR_DP << "Use of ref= outside a [resolution] block\n"; } else { //DBG_DP << ">> Looking for " << cfg["ref"] << "\n"; const config ref = find_ref (cfg["ref"], *resol_cfg); if (ref["id"].empty()) { ERR_DP << "Reference to non-existent rect id \"" << cfg["ref"] << "\"\n"; } else if (ref["rect"].empty()) { ERR_DP << "Reference to id \"" << cfg["ref"] << "\" which does not have a \"rect\"\n"; } else { ref_rect = read_rect(ref); } } } // resolve the rect value to absolute coordinates if (!cfg["rect"].empty()) { resolved_config.values["rect"] = resolve_rect(cfg["rect"]); } }