mail[Wesnoth-commits] r33686 - in /trunk: changelog src/gui/widgets/window.cpp src/gui/widgets/window.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by koraq on March 15, 2009 - 17:42:
Author: mordante
Date: Sun Mar 15 17:42:15 2009
New Revision: 33686

URL: http://svn.gna.org/viewcvs/wesnoth?rev=33686&view=rev
Log:
Activated the new layout algorithm.

This algorithm will now only be used if the normal layout algorithm
fails, this to avoid possible regressions in the new algorithm.
After 1.6 this algorithm will be polished and replace the current
algorithm. (Fixes bug #13180).

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

Modified: trunk/changelog
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=33686&r1=33685&r2=33686&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Sun Mar 15 17:42:15 2009
@@ -20,6 +20,7 @@
    * Fixed bug #13123: When you're downloading add-ons they do not appear in
      the campaigns list until BfW is restarted
    * The size of the message dialogs now really depends on the size of the 
map
+   * Started with a new layout engine for the new widgets (bug #13180)
  * Miscellaneous and bug fixes:
    * Fix another campaign replay bug (#13139)
    * Fix WML [advancefrom] bug (#13176)

Modified: trunk/src/gui/widgets/window.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window.cpp?rev=33686&r1=33685&r2=33686&view=diff
==============================================================================
--- trunk/src/gui/widgets/window.cpp (original)
+++ trunk/src/gui/widgets/window.cpp Sun Mar 15 17:42:15 2009
@@ -555,19 +555,16 @@
                generate_dot_file("horizontal_scrollbar", LAYOUT);
        }
 
-       // *** shrink (can change height)
-       if(size.x > maximum_width) {
-               layout_shrink_width(maximum_width);
-               size = get_best_size();
-               generate_dot_file("shrink_width", LAYOUT);
-       }
-
        // *** failed?
        if(size.x > maximum_width) {
                ERR_G_L << "Failed to resize window, wanted width "
                        << size.x << " available width "
                        << maximum_width << ".\n";
-               assert(false);
+
+               // Fall back to the new layout engine.
+               layout2(maximum_width, maximum_height);
+               size = get_best_size();
+               assert(size.x <= maximum_width && size.y <= maximum_height);
        }
 
        /***** Does the height fit in the available height? ******/
@@ -591,7 +588,11 @@
                ERR_G_L << "Failed to resize window, wanted height "
                        << size.y << " available height "
                        << maximum_height << ".\n";
-               assert(false);
+
+               // Fall back to the new layout engine.
+               layout2(maximum_width, maximum_height);
+               size = get_best_size();
+               assert(size.x <= maximum_width && size.y <= maximum_height);
        }
 
        /***** Get the best location for the window *****/
@@ -642,6 +643,58 @@
 
        // The widgets might have moved so set the mouse location properly.
        init_mouse_location();
+}
+
+void twindow::layout2(
+               const unsigned maximum_width, const unsigned maximum_height)
+{
+       /**
+        * @todo The following features are not done yet:
+        * - Linked widget support.
+        */
+
+       DBG_G_L << "twindow " << __func__ << ": maximum size "
+                       << maximum_width << ',' << maximum_height << ".\n";
+
+       layout_init2(true);
+
+       bool done = false;
+       unsigned run = 1;
+       while(!done) {
+               done = true;
+
+               tpoint size = get_best_size();
+               generate_dot_file("get_initial_best_size-"
+                               + lexical_cast<std::string>(run), LAYOUT);
+
+               try {
+
+                       /***** Does the width fit in the available width? 
*****/
+                       if(size.x > static_cast<int>(maximum_width)) {
+                               layout_fit_width(maximum_width, FORCE);
+                               size = get_best_size();
+                               generate_dot_file("layout_fit_width-"
+                                               + 
lexical_cast<std::string>(run), LAYOUT);
+                               assert(size.x <= 
static_cast<int>(maximum_width));
+                       }
+
+                       /***** Does the height fit in the available height? 
*****/
+                       // This part hasn't been implemented yet.
+#if 0
+                       if(size.y > maximum_height) {
+                               layout_fit_height(maximum_height);
+                               size = get_best_size();
+                               generate_dot_file("layout_fit_height-"
+                                               + 
lexical_cast<std::string>(run), LAYOUT);
+                               assert(size.y <= maximum_height);
+                       }
+#endif
+               } catch(trelayout_exception&) {
+                       layout_init2(false);
+                       done = false;
+                       ++run;
+               }
+       }
 }
 
 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=33686&r1=33685&r2=33686&view=diff
==============================================================================
--- trunk/src/gui/widgets/window.hpp (original)
+++ trunk/src/gui/widgets/window.hpp Sun Mar 15 17:42:15 2009
@@ -40,6 +40,14 @@
 
 class tdialog;
 class tdebug_layout_graph;
+
+/**
+ * Dummy struct for the layout engine.
+ *
+ * When an object changes it's width in the height phase of the layout engine
+ * things might need to change so rerun the layout phase in that case.
+ */
+struct trelayout_exception {};
 
 /**
  * base class of top level items, the only item
@@ -429,6 +437,17 @@
        /** Layouts the window. */
        void layout();
 
+       /**
+        * Layouts the window.
+        *
+        * 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.
+        *
+        * @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);
+
        /** Inherited from tevent_handler. */
        void do_show_tooltip(const tpoint& location, const t_string& tooltip);
 




Related Messages


Powered by MHonArc, Updated Sun Mar 15 18:00:30 2009