Author: mordante
Date: Fri May 1 19:52:16 2009
New Revision: 35389
URL: http://svn.gna.org/viewcvs/wesnoth?rev=35389&view=rev
Log:
Window code cleanups.
Since the last commit the return value of NEW_layout was no longer used. Moved
the file to a new separate header so it's easier to add new private functions
without the need to recompile the universe.
Added:
trunk/src/gui/widgets/window_private.hpp (with props)
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=35389&r1=35388&r2=35389&view=diff
==============================================================================
--- trunk/src/gui/widgets/window.cpp (original)
+++ trunk/src/gui/widgets/window.cpp Fri May 1 19:52:16 2009
@@ -19,7 +19,7 @@
#define GETTEXT_DOMAIN "wesnoth-lib"
-#include "gui/widgets/window.hpp"
+#include "gui/widgets/window_private.hpp"
#include "font.hpp"
#include "foreach.hpp"
@@ -894,7 +894,7 @@
/** @todo Handle linked widgets. */
try {
- NEW_layout(maximum_width, maximum_height);
+ twindow_implementation::NEW_layout(*this, maximum_width,
maximum_height);
} catch(tlayout_exception_resize_failed&) {
/** @todo implement the scrollbars on the window. */
@@ -965,73 +965,6 @@
// 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)
-{
- log_scope2(log_gui_layout, std::string("Window: ") + __func__);
-
- /*
- * For now we return the status, need to test later whether this can
- * entirely be converted to an exception based system as in 'promised'
on
- * the algorithm page.
- */
-
- try {
- tpoint size = get_best_size();
-
- DBG_GUI_L << "Best size : " << size
- << " maximum size : " << maximum_width
- << ',' << maximum_height
- << ".\n";
- if(size.x <= static_cast<int>(maximum_width)
- && size.y <= static_cast<int>(maximum_height)) {
-
- DBG_GUI_L << "Result: Fits, nothing to do.\n";
- return true;
- }
-
- if(size.x > static_cast<int>(maximum_width)) {
- NEW_reduce_width(maximum_width);
-
- size = get_best_size();
- if(size.x > static_cast<int>(maximum_width)) {
- DBG_GUI_L << "Result: Resize width failed."
- << " Wanted width " << maximum_width
- << " resulting width " << size.x
- << ".\n";
- throw tlayout_exception_width_resize_failed();
- }
- DBG_GUI_L << "Status: Resize width succeeded.\n";
- }
-
- if(size.y > static_cast<int>(maximum_height)) {
- NEW_reduce_height(maximum_height);
-
- size = get_best_size();
- if(size.y > static_cast<int>(maximum_height)) {
- DBG_GUI_L << "Result: Resize height failed."
- << " Wanted height " << maximum_height
- << " resulting height " << size.y
- << ".\n";
- throw tlayout_exception_height_resize_failed();
- }
- DBG_GUI_L << "Status: Resize height succeeded.\n";
- }
-
- assert(size.x <= static_cast<int>(maximum_width)
- && size.y <= static_cast<int>(maximum_height));
-
-
- DBG_GUI_L << "Result: Resizing succeeded.\n";
- return true;
-
- } catch (tlayout_exception_width_modified&) {
- DBG_GUI_L << "Status: Width has been modified, rerun.\n";
- NEW_layout_init(false);
- return NEW_layout(maximum_width, maximum_height);
- }
}
void twindow::do_show_tooltip(const tpoint& location, const t_string& tooltip)
@@ -1158,6 +1091,75 @@
debug_layout_->generate_dot_file(generator, domain);
}
#endif
+
+void twindow_implementation::NEW_layout(twindow& window,
+ const unsigned maximum_width, const unsigned maximum_height)
+{
+ log_scope2(log_gui_layout, std::string("Window: ") + __func__);
+
+ /*
+ * For now we return the status, need to test later whether this can
+ * entirely be converted to an exception based system as in 'promised'
on
+ * the algorithm page.
+ */
+
+ try {
+ tpoint size = window.get_best_size();
+
+ DBG_GUI_L << "Best size : " << size
+ << " maximum size : " << maximum_width
+ << ',' << maximum_height
+ << ".\n";
+ if(size.x <= static_cast<int>(maximum_width)
+ && size.y <= static_cast<int>(maximum_height)) {
+
+ DBG_GUI_L << "Result: Fits, nothing to do.\n";
+ return;
+ }
+
+ if(size.x > static_cast<int>(maximum_width)) {
+ window.NEW_reduce_width(maximum_width);
+
+ size = window.get_best_size();
+ if(size.x > static_cast<int>(maximum_width)) {
+ DBG_GUI_L << "Result: Resize width failed."
+ << " Wanted width " << maximum_width
+ << " resulting width " << size.x
+ << ".\n";
+ throw tlayout_exception_width_resize_failed();
+ }
+ DBG_GUI_L << "Status: Resize width succeeded.\n";
+ }
+
+ if(size.y > static_cast<int>(maximum_height)) {
+ window.NEW_reduce_height(maximum_height);
+
+ size = window.get_best_size();
+ if(size.y > static_cast<int>(maximum_height)) {
+ DBG_GUI_L << "Result: Resize height failed."
+ << " Wanted height " << maximum_height
+ << " resulting height " << size.y
+ << ".\n";
+ throw tlayout_exception_height_resize_failed();
+ }
+ DBG_GUI_L << "Status: Resize height succeeded.\n";
+ }
+
+ assert(size.x <= static_cast<int>(maximum_width)
+ && size.y <= static_cast<int>(maximum_height));
+
+
+ DBG_GUI_L << "Result: Resizing succeeded.\n";
+ return;
+
+ } catch (tlayout_exception_width_modified&) {
+ DBG_GUI_L << "Status: Width has been modified, rerun.\n";
+ window.NEW_layout_init(false);
+ NEW_layout(window, maximum_width, maximum_height);
+ return;
+ }
+}
+
} // namespace gui2
Modified: trunk/src/gui/widgets/window.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window.hpp?rev=35389&r1=35388&r2=35389&view=diff
==============================================================================
--- trunk/src/gui/widgets/window.hpp (original)
+++ trunk/src/gui/widgets/window.hpp Fri May 1 19:52:16 2009
@@ -59,6 +59,7 @@
, public cursor::setter
{
friend class tdebug_layout_graph;
+ friend class twindow_implementation;
// Wants to use layout().
friend class tmessage;
@@ -483,21 +484,6 @@
*/
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);
Added: trunk/src/gui/widgets/window_private.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window_private.hpp?rev=35389&view=auto
==============================================================================
--- trunk/src/gui/widgets/window_private.hpp (added)
+++ trunk/src/gui/widgets/window_private.hpp Fri May 1 19:52:16 2009
@@ -1,0 +1,58 @@
+/* $Id$ */
+/*
+ Copyright (C) 2009 by Mark de Wever <[email protected]>
+ Part of the Battle for Wesnoth Project http://www.wesnoth.org/
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 2
+ or at your option any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY.
+
+ See the COPYING file for more details.
+*/
+
+#ifndef GUI_WIDGETS_WINDOW_PRIVATE_HPP_INCLUDED
+#define GUI_WIDGETS_WINDOW_PRIVATE_HPP_INCLUDED
+
+/**
+ * @file gui/widgets/window_private.hpp
+ * Helper for header for the window.
+ *
+ * @note This file should only be included by window.cpp.
+ *
+ * This file is being used for a small experiment similar like
+ * gui/widgets/grid_private.hpp.
+ */
+
+#include "gui/widgets/window.hpp"
+
+namespace gui2 {
+
+/**
+ * Helper to implement private functions without modifing the header.
+ *
+ * The class is a helper to avoid recompilation and only has static
+ * functions.
+ */
+struct twindow_implementation
+{
+ /**
+ * Layouts the window.
+ *
+ * This part handles the actual layouting of the window.
+ *
+ * @see layout_algorihm for more information.
+ *
+ * @param window The window to operate upon.
+ * @param maximum_width The maximum width of the window.
+ * @param maximum_height The maximum height of the window.
+ */
+ static void NEW_layout(twindow& window,
+ const unsigned maximum_width, const unsigned
maximum_height);
+
+};
+
+} // namespace gui2
+
+#endif
Propchange: trunk/src/gui/widgets/window_private.hpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: trunk/src/gui/widgets/window_private.hpp
------------------------------------------------------------------------------
svn:keywords = 'Author Date Id Revision'
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits