Author: mordante
Date: Mon Apr 28 18:10:27 2008
New Revision: 26209

URL: http://svn.gna.org/viewcvs/wesnoth?rev=26209&view=rev
Log:
Make the window defintion also more general.
Make text_font_size no longer mandatory.

Modified:
    trunk/src/gui/widgets/settings.cpp
    trunk/src/gui/widgets/settings.hpp
    trunk/src/gui/widgets/window.cpp
    trunk/src/gui/widgets/window.hpp

Modified: trunk/src/gui/widgets/settings.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/settings.cpp?rev=26209&r1=26208&r2=26209&view=diff
==============================================================================
--- trunk/src/gui/widgets/settings.cpp (original)
+++ trunk/src/gui/widgets/settings.cpp Mon Apr 28 18:10:27 2008
@@ -182,24 +182,13 @@
 
        DBG_G_P << "Parsing gui " << id << '\n';
 
-       /***** Window definitions *****/
-       const config::child_list& window_cfgs = 
cfg.get_children("window_definition");
-       for(std::vector<config*>::const_iterator itor = window_cfgs.begin();
-                       itor != window_cfgs.end(); ++itor) {
-
-               std::pair<std::string, twindow_definition> child;
-               child.first = child.second.read(**itor);
-               windows.insert(child);
-       }
-
-       VALIDATE(windows.find("default") != windows.end(), _ ("No default 
window defined."));
-
        /***** Control definitions *****/
        load_definitions<tbutton_definition>("button", 
cfg.get_children("button_definition"));
        load_definitions<tlabel_definition>("label", 
cfg.get_children("label_definition"));
        load_definitions<tspacer_definition>("spacer", 
cfg.get_children("spacer_definition"));
        load_definitions<ttext_box_definition>("text_box", 
cfg.get_children("text_box_definition"));
        load_definitions<ttooltip_definition>("tooltip", 
cfg.get_children("tooltip_definition"));
+       load_definitions<twindow_definition>("window", 
cfg.get_children("window_definition"));
 
        /***** Window types *****/
        const config::child_list& window_instance_cfgs = 
cfg.get_children("window");
@@ -320,7 +309,7 @@
  *     text_extra_height (unsigned = 0)
  *                                   The extra height needed to determine the
  *                                   minimal size for the text.
- *     text_font_size (unsigned)     The font size, which needs to be used to 
+ *     text_font_size (unsigned = 0) The font size, which needs to be used to 
  *                                   determine the minimal size for the text.
  *     text_font_style (font_style = "")  
  *                                   The font style, which needs to be used to
@@ -332,8 +321,6 @@
  * @end_table
  *
  */
-
-       VALIDATE(text_font_size, missing_mandatory_wml_key("resolution", 
"text_font_size"));
 
        DBG_G_P << "Parsing resolution " 
                << window_width << ", " << window_height << '\n';
@@ -557,7 +544,8 @@
        state.push_back(tstate_definition(cfg.child("state_enabled")));
 }
 
-const std::string& twindow_definition::read(const config& cfg)
+twindow_definition::twindow_definition(const config& cfg) : 
+       tcontrol_definition(cfg)
 {
 /*WIKI (FIXME cleanup)
  * [window_definition]
@@ -570,34 +558,18 @@
  *                                   resolutions.
  * [/window_definition]
  */
-       id = cfg["id"];
-       description = cfg["description"];
-
-       VALIDATE(!id.empty(), missing_mandatory_wml_key("gui", "id"));
-       VALIDATE(!description.empty(), missing_mandatory_wml_key("gui", 
"description"));
 
        DBG_G_P << "Parsing window " << id << '\n';
 
-       const config::child_list& cfgs = cfg.get_children("resolution");
-       VALIDATE(!cfgs.empty(), _("No resolution defined."));
-       for(std::vector<config*>::const_iterator itor = cfgs.begin();
-                       itor != cfgs.end(); ++itor) {
-
-               resolutions.push_back(tresolution(**itor));
-       }
-
-       return id;
+       load_resolutions<tresolution>(cfg.get_children("resolution"));
 }
 
 twindow_definition::tresolution::tresolution(const config& cfg) :
-       window_width(lexical_cast_default<unsigned>(cfg["window_width"])),
-       window_height(lexical_cast_default<unsigned>(cfg["window_height"])),
+       tresolution_definition_(cfg),
        top_border(lexical_cast_default<unsigned>(cfg["top_border"])),
        bottom_border(lexical_cast_default<unsigned>(cfg["bottom_border"])),
        left_border(lexical_cast_default<unsigned>(cfg["left_border"])),
        right_border(lexical_cast_default<unsigned>(cfg["right_border"])),
-       min_width(lexical_cast_default<unsigned>(cfg["min_width"])),
-       min_height(lexical_cast_default<unsigned>(cfg["min_height"])),
        background(cfg.child("background")),
        foreground(cfg.child("foreground"))
 {
@@ -671,36 +643,6 @@
        assert(false);
 }
 
-std::vector<twindow_definition::tresolution>::const_iterator get_window(const 
std::string& definition)
-{
-       std::map<std::string, twindow_definition>::const_iterator 
-               window = current_gui->second.windows.find(definition);
-
-       if(window == current_gui->second.windows.end()) {
-               LOG_G << "Window: definition '" 
-                       << definition << "' not found, falling back to 
'default'.\n";
-               window = current_gui->second.windows.find("default");
-               assert(window != current_gui->second.windows.end());
-       }
-
-       for(std::vector<twindow_definition::tresolution>::const_iterator 
-                       itor = window->second.resolutions.begin(),
-                       end = window->second.resolutions.end();
-                       itor != end;
-                       ++itor) {
-
-               if(screen_width <= itor->window_width &&
-                               screen_height <= itor->window_height) {
-
-                       return itor;
-               } else if (itor == end - 1) {
-                       return itor;
-               }
-       }
-
-       assert(false);
-}
-
 std::vector<twindow_builder::tresolution>::const_iterator 
get_window_builder(const std::string& type)
 {
        std::map<std::string, twindow_builder>::const_iterator 
@@ -730,5 +672,4 @@
        assert(false);
 }
 
-
 } // namespace gui2

Modified: trunk/src/gui/widgets/settings.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/settings.hpp?rev=26209&r1=26208&r2=26209&view=diff
==============================================================================
--- trunk/src/gui/widgets/settings.hpp (original)
+++ trunk/src/gui/widgets/settings.hpp Mon Apr 28 18:10:27 2008
@@ -159,33 +159,20 @@
        };
 };
 
-struct twindow_definition
-{
-
-       std::string id;
-       t_string description;
-
-       const std::string& read(const config& cfg);
-
-       struct tresolution 
-       {
-       private:
-               tresolution();
-
-       public:
-               tresolution(const config& cfg);
-
-               unsigned window_width;
-               unsigned window_height;
+struct twindow_definition : public tcontrol_definition
+{
+
+       twindow_definition(const config& cfg);
+
+       struct tresolution : public tresolution_definition_
+       {
+               tresolution(const config& cfg);
 
                unsigned top_border;
                unsigned bottom_border;
 
                unsigned left_border;
                unsigned right_border;
-
-               unsigned min_width;
-               unsigned min_height;
 
                struct tlayer
                {
@@ -200,10 +187,7 @@
 
                tlayer background;
                tlayer foreground;
-
-       };
-
-       std::vector<tresolution> resolutions;
+       };
 };
 
 struct tgui_definition
@@ -227,7 +211,6 @@
 };
 
        tresolution_definition_* get_control(const std::string& control_type, 
const std::string& definition);
-       std::vector<twindow_definition::tresolution>::const_iterator 
get_window(const std::string& definition);
 
        std::vector<twindow_builder::tresolution>::const_iterator 
get_window_builder(const std::string& type);
 

Modified: trunk/src/gui/widgets/window.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window.cpp?rev=26209&r1=26208&r2=26209&view=diff
==============================================================================
--- trunk/src/gui/widgets/window.cpp (original)
+++ trunk/src/gui/widgets/window.cpp Mon Apr 28 18:10:27 2008
@@ -91,7 +91,21 @@
 
        // Update all configs.
        load_config();
-       
+
+       // FIXME hack to load config stuff here
+       tcontrol::load_config();
+
+       const twindow_definition::tresolution* conf = dynamic_cast<const 
twindow_definition::tresolution*>(config());
+       assert(conf);
+       canvas_background_ = conf->background.canvas;
+       canvas_background_.set_width(get_width());
+       canvas_background_.set_height(get_height());
+
+       canvas_foreground_ = conf->foreground.canvas;
+       canvas_foreground_.set_width(get_width());
+       canvas_foreground_.set_height(get_height());
+       // End of hack
+
        // We cut a piece of the screen and use that, that way all coordinates
        // are relative to the window.
        SDL_Rect rect = get_rect();
@@ -111,7 +125,6 @@
                        const bool draw_foreground = need_layout_;
                        if(need_layout_) {
                                DBG_G << "Window: layout client area.\n";
-                               resolve_definition();
                                layout(get_client_rect());
 
                                screen = make_neutral_surface(restorer_);
@@ -218,31 +231,16 @@
        need_layout_ = true;
 }
 
-void twindow::resolve_definition()
-{
-       if(definition_ == 
std::vector<twindow_definition::tresolution>::const_iterator()) {
-               definition_ = gui2::get_window(definition());
-
-               canvas_background_ = definition_->background.canvas;
-               canvas_background_.set_width(get_width());
-               canvas_background_.set_height(get_height());
-
-               canvas_foreground_ = definition_->foreground.canvas;
-               canvas_foreground_.set_width(get_width());
-               canvas_foreground_.set_height(get_height());
-       }
-
-}
-
 SDL_Rect twindow::get_client_rect() const
 {
-       assert(definition_ != 
std::vector<twindow_definition::tresolution>::const_iterator());
+       const twindow_definition::tresolution* conf = dynamic_cast<const 
twindow_definition::tresolution*>(config());
+       assert(conf);
 
        SDL_Rect result = get_rect();
-       result.x = definition_->left_border;
-       result.y = definition_->top_border;
-       result.w -= definition_->left_border + definition_->right_border;
-       result.h -= definition_->top_border + definition_->bottom_border;
+       result.x = conf->left_border;
+       result.y = conf->top_border;
+       result.w -= conf->left_border + conf->right_border;
+       result.h -= conf->top_border + conf->bottom_border;
 
        // FIXME validate for an available client area.
        

Modified: trunk/src/gui/widgets/window.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window.hpp?rev=26209&r1=26208&r2=26209&view=diff
==============================================================================
--- trunk/src/gui/widgets/window.hpp (original)
+++ trunk/src/gui/widgets/window.hpp Mon Apr 28 18:10:27 2008
@@ -126,10 +126,6 @@
                canvas_background_,
                canvas_foreground_;
 
-       std::vector<twindow_definition::tresolution>::const_iterator 
definition_;
-
-       void resolve_definition();
-
        //! Inherited from tevent_handler.
        void do_show_tooltip(const tpoint& location, const t_string& tooltip);
        void do_remove_tooltip() { tooltip_.set_visible(false); }


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to