Author: mordante
Date: Sat May 23 11:17:44 2009
New Revision: 35843

URL: http://svn.gna.org/viewcvs/wesnoth?rev=35843&view=rev
Log:
Add a very crude proof-of-concept multi page widget.

The widget is used in the campaign selection dialog, which doesn't work
properly (but is only used with --new-widgets). The code still needs a lot of
polishing and testing, which will be done later.

Added:
    trunk/data/gui/default/widget/multi_page_default.cfg   (with props)
Modified:
    trunk/data/gui/default/window/campaign_dialog.cfg
    trunk/src/gui/auxiliary/window_builder.cpp
    trunk/src/gui/auxiliary/window_builder_private.hpp
    trunk/src/gui/widgets/generator.cpp
    trunk/src/gui/widgets/generator_private.hpp
    trunk/src/gui/widgets/listbox.hpp
    trunk/src/gui/widgets/settings.cpp
    trunk/src/gui/widgets/settings.hpp

Added: trunk/data/gui/default/widget/multi_page_default.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/gui/default/widget/multi_page_default.cfg?rev=35843&view=auto
==============================================================================
--- trunk/data/gui/default/widget/multi_page_default.cfg (added)
+++ trunk/data/gui/default/widget/multi_page_default.cfg Sat May 23 11:17:44 
2009
@@ -1,0 +1,126 @@
+#textdomain wesnoth-lib
+###
+### Definition of a multi page
+###
+
+#define _GUI_RESOLUTION RESOLUTION FONT_SIZE FONT_STYLE FONT_COLOUR_ENABLED 
FONT_COLOUR_DISABLED
+       [resolution]
+
+               {RESOLUTION}
+
+               min_width = 0
+               min_height = 0
+
+               default_width = 0
+               default_height = 0
+
+               max_width = 0
+               max_height = 0
+
+               text_font_size = {FONT_SIZE}
+               text_font_style = {FONT_STYLE}
+
+               [state_enabled]
+
+                       [draw]
+                       [/draw]
+       
+               [/state_enabled]
+
+               [state_disabled]
+
+                       [draw]
+                       [/draw]
+
+               [/state_disabled]
+
+               [grid]
+
+                       [row]
+                               grow_factor = 1
+
+                               [column]
+                                       grow_factor = 1
+                                                               horizontal_grow 
= "true" # needed ?
+                                                               vertical_grow = 
"true" # needed ?
+
+                                       [grid]
+                                               id = "_content_grid"
+
+                                               [row]
+
+                                                       [column]
+                                                               horizontal_grow 
= "true"
+                                                               vertical_grow = 
"true"
+
+                                                               [grid]
+                                                                       id = 
"_list_grid"
+                                                               [/grid]
+
+                                                       [/column]
+
+                                               [/row]
+
+                                       [/grid]
+
+                               [/column]
+
+                               [column]
+                                       grow_factor = 0
+
+                                       {GUI__VERTICAL_SCROLLBAR_GRID}
+
+                               [/column]
+
+                       [/row]
+
+                       [row]
+                               grow_factor = 0
+
+                               [column]
+
+
+                                       {GUI__HORIZONTAL_SCROLLBAR_GRID}
+
+                               [/column]
+
+                               [column]
+
+                                       [spacer]
+                                       [/spacer]
+
+                               [/column]
+
+                       [/row]
+
+               [/grid]
+
+       [/resolution]
+#enddef
+
+[multi_page_definition]
+       id = "default"
+       description = "Testing version."
+
+       {_GUI_RESOLUTION 
+               ({GUI_TINY__RESOLUTION})
+               ({GUI_TINY__FONT_SIZE__DEFAULT})
+               ()
+               ({GUI__FONT_COLOUR_ENABLED__DEFAULT})
+               ({GUI__FONT_COLOUR_DISABLED__DEFAULT})
+       }
+
+       
+       {_GUI_RESOLUTION 
+               ({GUI_NORMAL__RESOLUTION}) 
+               ({GUI_NORMAL__FONT_SIZE__DEFAULT}) 
+               () 
+               ({GUI__FONT_COLOUR_ENABLED__DEFAULT}) 
+               ({GUI__FONT_COLOUR_DISABLED__DEFAULT}) 
+       }
+
+[/multi_page_definition]
+
+#undef _GUI_RESOLUTION 
+
+

Propchange: trunk/data/gui/default/widget/multi_page_default.cfg
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: trunk/data/gui/default/window/campaign_dialog.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/gui/default/window/campaign_dialog.cfg?rev=35843&r1=35842&r2=35843&view=diff
==============================================================================
--- trunk/data/gui/default/window/campaign_dialog.cfg (original)
+++ trunk/data/gui/default/window/campaign_dialog.cfg Sat May 23 11:17:44 2009
@@ -97,44 +97,55 @@
                                                                border_size = 5
                                                                
vertical_alignment = "top"
 
-                                                               # FIXME show 
the addon pane.
-                                                               [panel]
-                                                                       
definition = "default"
-                                                                       [grid]
-
+                                                               [multi_page]
+                                                                       
definition = "default"
+                                                                       
[list_definition]
                                                                                
[row]
-                                                                               
        grow_factor = 0
 
                                                                                
        [column]
 
-                                                                               
                [scroll_label]
-                                                                               
                        id = "description"
-                                                                               
                        definition = "default"
-                                                                               
                [/scroll_label]
+                                                                               
                [grid]
+
+                                                                               
                        [row]
+                                                                               
                                grow_factor = 0
+
+                                                                               
                                [column]
+
+                                                                               
                                        [label]
+                                                                               
                                                id = "description"
+                                                                               
                                                definition = "default"
+
+                                                                               
                                                wrap = "true"
+                                                                               
                                        [/label]
+
+                                                                               
                                [/column]
+
+                                                                               
                        [/row]
+
+                                                                               
                        [row]
+                                                                               
                                grow_factor = 1
+
+                                                                               
                                [column]
+                                                                               
                                        horizontal_alignment = "center"
+                                                                               
                                        vertical_alignment = "top"
+
+                                                                               
                                        [image]
+                                                                               
                                                id = "image"
+                                                                               
                                                definition = "default"
+                                                                               
                                        [/image]
+
+                                                                               
                                [/column]
+
+                                                                               
                        [/row]
+
+                                                                               
                [/grid]
 
                                                                                
        [/column]
 
                                                                                
[/row]
-
-                                                                               
[row]
-                                                                               
        grow_factor = 1
-
-                                                                               
        [column]
-                                                                               
                horizontal_alignment = "center"
-                                                                               
                vertical_alignment = "top"
-
-                                                                               
                [image]
-                                                                               
                        id = "image"
-                                                                               
                        definition = "default"
-                                                                               
                [/image]
-
-                                                                               
        [/column]
-
-                                                                               
[/row]
-
-                                                                       [/grid]
-
-                                                               [/panel]
+                                                                       
[/list_definition]
+
+                                                               [/multi_page]
 
                                                        [/column]
 

Modified: trunk/src/gui/auxiliary/window_builder.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/auxiliary/window_builder.cpp?rev=35843&r1=35842&r2=35843&view=diff
==============================================================================
--- trunk/src/gui/auxiliary/window_builder.cpp (original)
+++ trunk/src/gui/auxiliary/window_builder.cpp Sat May 23 11:17:44 2009
@@ -182,6 +182,7 @@
        TRY(listbox);
        TRY(menubar);
        TRY(minimap);
+       TRY(multi_page);
        TRY(panel);
        TRY(scroll_label);
        TRY(slider);
@@ -927,6 +928,107 @@
        return minimap;
 }
 
+tbuilder_multi_page::tbuilder_multi_page(const config& cfg) :
+       tbuilder_control(cfg),
+       vertical_scrollbar_mode(
+                       get_scrollbar_mode(cfg["vertical_scrollbar_mode"])),
+       horizontal_scrollbar_mode(
+                       get_scrollbar_mode(cfg["horizontal_scrollbar_mode"])),
+       builder(0),
+       data()
+{
+/*WIKI
+ * @page = GUIWidgetInstanceWML
+ * @order = 2_multi_page
+ *
+ * == Multi page ==
+ *
+ * Instance of a multi page.
+ *
+ * List with the multi page specific variables:
+ * @start_table = config
+ *     vertical_scrollbar_mode (scrollbar_mode = auto | initial_auto)
+ *                                     Determines whether or not to show the
+ *                                     scrollbar. The default of initial_auto
+ *                                     is used when --new-widgets is used.
+ *                                     In the future the default will be
+ *                                     auto.
+ *     horizontal_scrollbar_mode (scrollbar_mode = auto | initial_auto)
+ *                                     Determines whether or not to show the
+ *                                     scrollbar. The default of initial_auto
+ *                                     is used when --new-widgets is used.
+ *                                     In the future the default will be
+ *                                     initial_auto.
+ *
+ *     list_definition (section)       This defines how a listbox item
+ *                                     looks. It must contain the grid
+ *                                     definition for 1 row of the list.
+ *
+ *     list_data(section = [])         A grid alike section which stores the
+ *                                     initial data for the listbox. Every row
+ *                                     must have the same number of columns as
+ *                                     the 'list_definition'.
+ * @end_table
+ */
+
+       const config &l = cfg.child("list_definition");
+
+       VALIDATE(l, _("No list defined."));
+       builder = new tbuilder_grid(l);
+       assert(builder);
+       VALIDATE(builder->rows == 1,
+                       _("A 'list_definition' should contain one row."));
+
+       const config &data_cfg = cfg.child("list_data");
+       if (!data_cfg) return;
+
+       foreach (const config &row, data_cfg.child_range("row"))
+       {
+               unsigned col = 0;
+
+               foreach (const config &c, row.child_range("column"))
+               {
+                       data.push_back(string_map());
+                       foreach (const config::attribute &i, 
c.attribute_range()) {
+                               data.back()[i.first] = i.second;
+                       }
+                       ++col;
+               }
+
+               VALIDATE(col == builder->cols, _("'list_data' must have "
+                       "the same number of columns as the 
'list_definition'."));
+       }
+}
+
+twidget* tbuilder_multi_page::build() const
+{
+       tlistbox *listbox = new tlistbox(
+                       true, true, tgenerator_::independant, false);
+
+       init_control(listbox);
+
+       listbox->set_list_builder(builder); // FIXME in finalize???
+
+       listbox->set_vertical_scrollbar_mode(vertical_scrollbar_mode);
+       listbox->set_horizontal_scrollbar_mode(horizontal_scrollbar_mode);
+
+       DBG_GUI_G << "Window builder: placed listbox '"
+               << id << "' with defintion '"
+               << definition << "'.\n";
+
+       boost::intrusive_ptr<const tlistbox_definition::tresolution> conf =
+               boost::dynamic_pointer_cast
+               <const tlistbox_definition::tresolution>(listbox->config());
+       assert(conf);
+
+
+       conf->grid->build(&listbox->grid());
+
+       listbox->finalize(NULL, NULL, data);
+
+       return listbox;
+}
+
 tbuilder_panel::tbuilder_panel(const config& cfg) :
        tbuilder_control(cfg),
        grid(0)

Modified: trunk/src/gui/auxiliary/window_builder_private.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/auxiliary/window_builder_private.hpp?rev=35843&r1=35842&r2=35843&view=diff
==============================================================================
--- trunk/src/gui/auxiliary/window_builder_private.hpp (original)
+++ trunk/src/gui/auxiliary/window_builder_private.hpp Sat May 23 11:17:44 2009
@@ -167,6 +167,7 @@
        std::vector<string_map>list_data;
 };
 
+
 struct tbuilder_menubar : public tbuilder_control
 {
        tbuilder_menubar(const config& cfg);
@@ -200,6 +201,32 @@
        }
 
        twidget* build () const;
+};
+
+struct tbuilder_multi_page
+       : public tbuilder_control
+{
+
+private:
+       tbuilder_multi_page();
+public:
+       tbuilder_multi_page(const config& cfg);
+
+       twidget* build () const;
+
+       tscrollbar_container::tscrollbar_mode
+                       vertical_scrollbar_mode,
+                       horizontal_scrollbar_mode;
+
+       tbuilder_grid_ptr builder;
+
+       /**
+        * Multi page data.
+        *
+        * Contains a vector with the data to set in every cell, it's used to
+        * serialize the data in the config, so the config is no longer 
required.
+        */
+       std::vector<string_map> data;
 };
 
 struct tbuilder_panel : public tbuilder_control

Modified: trunk/src/gui/widgets/generator.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/generator.cpp?rev=35843&r1=35842&r2=35843&view=diff
==============================================================================
--- trunk/src/gui/widgets/generator.cpp (original)
+++ trunk/src/gui/widgets/generator.cpp Sat May 23 11:17:44 2009
@@ -240,6 +240,51 @@
                        select_item(i);
                        return;
                }
+       }
+}
+
+tpoint tindependant::calculate_best_size() const
+{
+       /*
+        * The best size is the combination of the greatest width and greatest
+        * height.
+        */
+       tpoint result(0, 0);
+       for(size_t i = 0; i < get_item_count(); ++i) {
+
+               const tgrid& grid = get_item(i);
+
+               const tpoint best_size = grid.get_best_size();
+
+               if(best_size.x > result.x) {
+                       result.x = best_size.x;
+               }
+
+               if(best_size.y > result.y) {
+                       result.y = best_size.y;
+               }
+       }
+
+       return result;
+}
+
+void tindependant::set_size(const tpoint& origin, const tpoint& size)
+{
+       /*
+        * Set every item to it's best size, need to evaluate whether
+        * this is the best idea or that the size works better.
+        */
+
+       for(size_t i = 0; i < get_item_count(); ++i) {
+
+               tgrid& grid = get_item(i);
+
+               tpoint best_size = grid.get_best_size();
+               assert(best_size.x <= size.x);
+               assert(best_size.y <= size.y);
+
+               grid.set_size(origin, best_size);
+
        }
 }
 

Modified: trunk/src/gui/widgets/generator_private.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/generator_private.hpp?rev=35843&r1=35842&r2=35843&view=diff
==============================================================================
--- trunk/src/gui/widgets/generator_private.hpp (original)
+++ trunk/src/gui/widgets/generator_private.hpp Sat May 23 11:17:44 2009
@@ -350,48 +350,70 @@
        : public virtual tgenerator_
 {
        /** See thorizontal_list::create_item(). */
-       void create_item(const unsigned /*index*/) { ERROR_LOG(false); }
+       void create_item(const unsigned /*index*/)
+       {
+               /* DO NOTHING */
+       }
 
        /** See thorizontal_list::calculate_best_size(). */
-       tpoint calculate_best_size() const
-               { ERROR_LOG(false); }
+       tpoint calculate_best_size() const;
 
        /** See thorizontal_list::set_size(). */
-       void set_size(const tpoint& /*origin*/, const tpoint& /*size*/)
-               { ERROR_LOG(false); }
+       void set_size(const tpoint& origin, const tpoint& size);
 
        /** See thorizontal_list::set_origin(). */
        void set_origin(const tpoint& /*origin*/)
-               { ERROR_LOG(false); }
+       {
+               /* DO NOTHING */
+               /** @todo Evaluate what we need to do here. */
+       }
 
        /** See thorizontal_list::set_visible_area(). */
        void set_visible_area(const SDL_Rect& /*area*/)
-               { ERROR_LOG(false); }
+       {
+               /* DO NOTHING */
+               /** @todo Evaluate what we need to do here. */
+       }
 
        /** See thorizontal_list::find_widget(). */
-       twidget* find_widget(const tpoint&, const bool) { ERROR_LOG(false); }
+       twidget* find_widget(const tpoint&, const bool)
+       {
+               /** @todo implement. */
+               return NULL;
+       }
 
        /** See thorizontal_list::find_widget(). */
        const twidget* find_widget(const tpoint&, const bool) const
-               { ERROR_LOG(false); }
+       {
+               /** @todo implement. */
+               return NULL;
+       }
 
        /***** ***** ***** ***** keyboard functions ***** ***** ***** *****/
 
        /** Inherited from tgenerator_. */
        void handle_key_up_arrow(SDLMod, bool&)
-               { ERROR_LOG(false); }
+       {
+               /* DO NOTHING */
+       }
 
        /** Inherited from tgenerator_. */
        void handle_key_down_arrow(SDLMod, bool&)
-               { ERROR_LOG(false); }
+       {
+               /* DO NOTHING */
+       }
 
        /** Inherited from tgenerator_. */
        void handle_key_left_arrow(SDLMod, bool&)
-               { ERROR_LOG(false); }
+       {
+               /* DO NOTHING */
+       }
 
        /** Inherited from tgenerator_. */
        void handle_key_right_arrow(SDLMod, bool&)
-               { ERROR_LOG(false); }
+       {
+               /* DO NOTHING */
+       }
 };
 
 } // namespace placement

Modified: trunk/src/gui/widgets/listbox.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/listbox.hpp?rev=35843&r1=35842&r2=35843&view=diff
==============================================================================
--- trunk/src/gui/widgets/listbox.hpp (original)
+++ trunk/src/gui/widgets/listbox.hpp Sat May 23 11:17:44 2009
@@ -26,6 +26,7 @@
                : public tscrollbar_container
 {
        friend struct tbuilder_listbox;
+       friend struct tbuilder_multi_page;
        friend class tdebug_layout_graph;
 
        /** @todo Remove this item, part of the markup hack. */

Modified: trunk/src/gui/widgets/settings.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/settings.cpp?rev=35843&r1=35842&r2=35843&view=diff
==============================================================================
--- trunk/src/gui/widgets/settings.cpp (original)
+++ trunk/src/gui/widgets/settings.cpp Sat May 23 11:17:44 2009
@@ -196,6 +196,10 @@
  *                                   options. This version is used for map
  *                                   previews, there will be a another version
  *                                   which allows interaction.
+ *     Multi_page                    A multi page is a control that contains
+ *                                   serveral 'pages' of which only one is
+ *                                   visible. The pages can contain the same
+ *                                   of different info.
  *     Panel                         A panel is a container with can have it's
  *                                   own visual attributes.
  *     Scroll_label                  A label which can have scrollbars.
@@ -264,6 +268,7 @@
        load_definitions<tlistbox_definition>("listbox", cfg);
        load_definitions<tmenubar_definition>("menubar", cfg);
        load_definitions<tminimap_definition>("minimap", cfg);
+       load_definitions<tmulti_page_definition>("multi_page", cfg);
        load_definitions<tpanel_definition>("panel", cfg);
        load_definitions<tscroll_label_definition>("scroll_label", cfg);
        load_definitions<tslider_definition>("slider", cfg);
@@ -828,6 +833,37 @@
        load_resolutions<tresolution>(cfg);
 }
 
+tmulti_page_definition::tmulti_page_definition(const config& cfg) :
+       tcontrol_definition(cfg)
+{
+       DBG_GUI_P << "Parsing multipage " << id << '\n';
+
+       load_resolutions<tresolution>(cfg);
+}
+
+tmulti_page_definition::tresolution::tresolution(const config& cfg) :
+       tresolution_definition_(cfg),
+       grid(NULL)
+{
+/*WIKI
+ * @page = GUIWidgetDefinitionWML
+ * @order = 1_multi_page
+ *
+ * == Multi page ==
+ *
+ * The documentation is not written yet.
+ */
+
+       // Note the order should be the same as the enum tstate is listbox.hpp.
+       state.push_back(tstate_definition(cfg.child("state_enabled")));
+       state.push_back(tstate_definition(cfg.child("state_disabled")));
+
+       const config &child = cfg.child("grid");
+       VALIDATE(child, _("No grid defined."));
+
+       grid = new tbuilder_grid(child);
+}
+
 tpanel_definition::tresolution::tresolution(const config& cfg) :
        tresolution_definition_(cfg),
        top_border(lexical_cast_default<unsigned>(cfg["top_border"])),

Modified: trunk/src/gui/widgets/settings.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/settings.hpp?rev=35843&r1=35842&r2=35843&view=diff
==============================================================================
--- trunk/src/gui/widgets/settings.hpp (original)
+++ trunk/src/gui/widgets/settings.hpp Sat May 23 11:17:44 2009
@@ -240,6 +240,20 @@
        };
 };
 
+struct tmulti_page_definition
+       : public tcontrol_definition
+{
+       tmulti_page_definition(const config& cfg);
+
+       struct tresolution : public tresolution_definition_
+       {
+               tresolution(const config& cfg);
+
+               tbuilder_grid_ptr grid;
+
+       };
+};
+
 struct tpanel_definition : public tcontrol_definition
 {
 


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

Reply via email to