Author: mordante
Date: Mon Apr 13 15:01:55 2009
New Revision: 34858

URL: http://svn.gna.org/viewcvs/wesnoth?rev=34858&view=rev
Log:
Add the initial code of the new layout algorithm.

This new algorithm will be developed parallel with the current
algorithm. Once the new algorithm is finished it will be enabled and the
old code will be removed. Until that time it only works with
--new-widgets.

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

Modified: trunk/src/gui/widgets/window.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window.cpp?rev=34858&r1=34857&r2=34858&view=diff
==============================================================================
--- trunk/src/gui/widgets/window.cpp (original)
+++ trunk/src/gui/widgets/window.cpp Mon Apr 13 15:01:55 2009
@@ -288,7 +288,11 @@
                        update_rect(rect);
                }
 
-               layout();
+               if(gui2::new_widgets) {
+                       NEW_layout();
+               } else {
+                       layout();
+               }
 
                // Get new surface for restoring
                SDL_Rect rect = get_rect();
@@ -710,6 +714,95 @@
                        ++run;
                }
        }
+}
+
+void twindow::NEW_layout()
+{
+       /**** Initialize and get initial size. *****/
+
+       boost::intrusive_ptr<const twindow_definition::tresolution> conf =
+               boost::dynamic_pointer_cast<const 
twindow_definition::tresolution>
+               (config());
+       assert(conf);
+
+       log_scope2(gui_layout, "Window: Recalculate size");
+
+       NEW_layout_init(true);
+       generate_dot_file("layout_init", LAYOUT);
+
+       const game_logic::map_formula_callable variables =
+               get_screen_size_variables();
+
+       const int maximum_width = automatic_placement_ ?
+                       settings::screen_width :  w_(variables);
+
+       const int maximum_height = automatic_placement_ ?
+                       settings::screen_height :  h_(variables);
+
+       if(!NEW_layout(maximum_width, maximum_height)) {
+               /** @todo implement the scrollbars on the window. */
+               assert(false);
+       }
+
+       tpoint size = get_best_size();
+
+       assert(size.x <= maximum_width && size.y <= maximum_height);
+
+       /***** Get the best location for the window *****/
+
+       tpoint origin(0, 0);
+
+       if(automatic_placement_) {
+
+               switch(horizontal_placement_) {
+                       case tgrid::HORIZONTAL_ALIGN_LEFT :
+                               // Do nothing
+                               break;
+                       case tgrid::HORIZONTAL_ALIGN_CENTER :
+                               origin.x = (settings::screen_width - size.x) / 
2;
+                               break;
+                       case tgrid::HORIZONTAL_ALIGN_RIGHT :
+                               origin.x = settings::screen_width - size.x;
+                               break;
+                       default :
+                               assert(false);
+               }
+               switch(vertical_placement_) {
+                       case tgrid::VERTICAL_ALIGN_TOP :
+                               // Do nothing
+                               break;
+                       case tgrid::VERTICAL_ALIGN_CENTER :
+                               origin.y = (settings::screen_height - size.y) / 
2;
+                               break;
+                       case tgrid::VERTICAL_ALIGN_BOTTOM :
+                               origin.y = settings::screen_height - size.y;
+                               break;
+                       default :
+                               assert(false);
+               }
+       } else {
+               origin.x = x_(variables);
+               origin.y = y_(variables);
+
+               size.x = w_(variables);
+               size.y = h_(variables);
+       }
+
+       /***** Set the window size *****/
+       set_size(origin, size);
+
+       generate_dot_file("layout_finished", LAYOUT);
+       need_layout_ = false;
+
+       // The widgets might have moved so set the mouse location properly.
+       init_mouse_location();
+}
+
+bool twindow::NEW_layout(
+               const unsigned /*maximum_width*/, const unsigned 
/*maximum_height*/)
+{
+       /** @todo Do something. */
+       return true;
 }
 
 void twindow::do_show_tooltip(const tpoint& location, const t_string& tooltip)

Modified: trunk/src/gui/widgets/window.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window.hpp?rev=34858&r1=34857&r2=34858&view=diff
==============================================================================
--- trunk/src/gui/widgets/window.hpp (original)
+++ trunk/src/gui/widgets/window.hpp Mon Apr 13 15:01:55 2009
@@ -434,7 +434,12 @@
        /** List of the widgets, whose size are linked together. */
        std::map<std::string, tlinked_size> linked_size_;
 
-       /** Layouts the window. */
+       /** 
+        * Layouts the window.
+        *
+        * @deprecated Will be removed after the new layout algorithm is
+        * implemented.
+        */
        void layout();
 
        /**
@@ -443,10 +448,38 @@
         * This is a new routine which will be used as fallback when the normal
         * layout engine fails. In 1.7 this will become the real layout engine.
         *
+        * @deprecated Will be removed after the new layout algorithm is
+        * implemented.
+        *
         * @param maximum_width       The maximum width of the window.
         * @param maximum_height      The maximum height of the window.
         */
        void layout2(const unsigned maximum_width, const unsigned 
maximum_height);
+
+       /**
+        * Layouts the window.
+        *
+        * This part does the pre and post processing for the actual layout
+        * algorithm.
+        *
+        * @see layout_algorihm for more information.
+        */
+       void NEW_layout();
+
+       /**
+        * Layouts the window.
+        *
+        * This part handles the actual layouting of the window.
+        *
+        * @see layout_algorihm for more information.
+        *
+        * @param maximum_width       The maximum width of the window.
+        * @param maximum_height      The maximum height of the window.
+        *
+        * @returns                   The result of the layouting.
+        */
+       bool NEW_layout(
+                       const unsigned maximum_width, const unsigned 
maximum_height);
 
        /** Inherited from tevent_handler. */
        void do_show_tooltip(const tpoint& location, const t_string& tooltip);


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

Reply via email to