Author: mordante
Date: Fri May  1 19:25:48 2009
New Revision: 35388

URL: http://svn.gna.org/viewcvs/wesnoth?rev=35388&view=rev
Log:
Change the new layout algorithm to use exceptions.

Like the current algorithm it now throws an WML exception if the dialog
doesn't fit on the screen.

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

Modified: trunk/src/gui/auxiliary/layout_exception.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/auxiliary/layout_exception.hpp?rev=35388&r1=35387&r2=35388&view=diff
==============================================================================
--- trunk/src/gui/auxiliary/layout_exception.hpp (original)
+++ trunk/src/gui/auxiliary/layout_exception.hpp Fri May  1 19:25:48 2009
@@ -24,19 +24,28 @@
  */
 struct tlayout_exception_width_modified {};
 
+/** Basic exception when the layout doesn't fit. */
+struct tlayout_exception_resize_failed {};
+
 /**
  * Exception thrown when the width resizing has failed.
  *
  * @see layout_algorihm for more information.
  */
-struct tlayout_exception_width_resize_failed {};
+struct tlayout_exception_width_resize_failed
+       : public tlayout_exception_resize_failed
+{
+};
 
 /**
  * Exception thrown when the height resizing has failed.
  *
  * @see layout_algorihm for more information.
  */
-struct tlayout_exception_height_resize_failed {};
+struct tlayout_exception_height_resize_failed
+       : public tlayout_exception_resize_failed
+{
+};
 
 } // namespace gui2
 

Modified: trunk/src/gui/widgets/window.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window.cpp?rev=35388&r1=35387&r2=35388&view=diff
==============================================================================
--- trunk/src/gui/widgets/window.cpp (original)
+++ trunk/src/gui/widgets/window.cpp Fri May  1 19:25:48 2009
@@ -893,9 +893,24 @@
 
        /** @todo Handle linked widgets. */
 
-       if(!NEW_layout(maximum_width, maximum_height)) {
+       try {
+               NEW_layout(maximum_width, maximum_height);
+       } catch(tlayout_exception_resize_failed&) {
+
                /** @todo implement the scrollbars on the window. */
-               assert(false);
+
+               std::stringstream sstr;
+               sstr << __FILE__ << ":" << __LINE__ << " in function '" << 
__func__
+                               << "' found the following problem: Failed to 
size window;"
+                               << " wanted size " << get_best_size()
+                               << " available size "
+                               << maximum_width << ',' << maximum_height
+                               << " screen size "
+                               << settings::screen_width << ',' << 
settings::screen_height
+                               << '.';
+
+               throw twml_exception(_("Failed to show a dialog, "
+                               "which doesn't fit on the screen."), 
sstr.str());
        }
 
        tpoint size = get_best_size();
@@ -986,7 +1001,7 @@
                                        << " Wanted width " << maximum_width
                                        << " resulting width " << size.x
                                        << ".\n";
-                               return false;
+                               throw tlayout_exception_width_resize_failed();
                        }
                        DBG_GUI_L << "Status: Resize width succeeded.\n";
                }
@@ -1000,7 +1015,7 @@
                                        << " Wanted height " << maximum_height
                                        << " resulting height " << size.y
                                        << ".\n";
-                               return false;
+                               throw tlayout_exception_height_resize_failed();
                        }
                        DBG_GUI_L << "Status: Resize height succeeded.\n";
                }


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

Reply via email to