Author: mordante
Date: Sun Aug 17 19:31:19 2008
New Revision: 28681
URL: http://svn.gna.org/viewcvs/wesnoth?rev=28681&view=rev
Log:
Allow the window size if not automatically placed to depend on the window size.
Modified:
trunk/src/gui/widgets/window.cpp
trunk/src/gui/widgets/window.hpp
trunk/src/gui/widgets/window_builder.cpp
trunk/src/gui/widgets/window_builder.hpp
Modified: trunk/src/gui/widgets/window.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window.cpp?rev=28681&r1=28680&r2=28681&view=diff
==============================================================================
--- trunk/src/gui/widgets/window.cpp (original)
+++ trunk/src/gui/widgets/window.cpp Sun Aug 17 19:31:19 2008
@@ -51,7 +51,10 @@
namespace gui2{
twindow::twindow(CVideo& video,
- const int x, const int y, const int w, const int h,
+ tformula<unsigned>x,
+ tformula<unsigned>y,
+ tformula<unsigned>w,
+ tformula<unsigned>h,
const bool automatic_placement,
const unsigned horizontal_placement,
const unsigned vertical_placement,
@@ -67,13 +70,15 @@
help_popup_(),
automatic_placement_(automatic_placement),
horizontal_placement_(horizontal_placement),
- vertical_placement_(vertical_placement)
+ vertical_placement_(vertical_placement),
+ x_(x),
+ y_(y),
+ w_(w),
+ h_(h)
{
// We load the config in here as exception.
set_definition(definition);
load_config();
-
- set_size(::create_rect(x, y, w, h));
tooltip_.set_definition("default");
tooltip_.set_visible(false);
@@ -221,6 +226,8 @@
}
set_size(create_rect(position, size));
+ } else {
+ update_size();
}
}
@@ -301,6 +308,17 @@
}
+void twindow::update_size()
+{
+ game_logic::map_formula_callable variables;
+ variables.add("screen_width", variant(settings::screen_width));
+ variables.add("screen_height", variant(settings::screen_height));
+
+ set_size(::create_rect(
+ x_(variables), y_(variables), w_(variables), h_(variables)));
+
+}
+
void twindow::flip()
{
// fixme we need to add the option to either call
Modified: trunk/src/gui/widgets/window.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window.hpp?rev=28681&r1=28680&r2=28681&view=diff
==============================================================================
--- trunk/src/gui/widgets/window.hpp (original)
+++ trunk/src/gui/widgets/window.hpp Sun Aug 17 19:31:19 2008
@@ -22,6 +22,7 @@
#define GUI_WIDGETS_WINDOW_HPP_INCLUDED
#include "gui/widgets/event_handler.hpp"
+#include "gui/widgets/formula.hpp"
#include "gui/widgets/helper.hpp"
#include "gui/widgets/panel.hpp"
#include "gui/widgets/settings.hpp"
@@ -45,8 +46,11 @@
class twindow : public tpanel, public tevent_handler
{
public:
- twindow(CVideo& video,
- const int x, const int y, const int w, const int h,
+ twindow(CVideo& video,
+ tformula<unsigned>x,
+ tformula<unsigned>y,
+ tformula<unsigned>w,
+ tformula<unsigned>h,
const bool automatic_placement,
const unsigned horizontal_placement,
const unsigned vertical_placement,
@@ -262,6 +266,26 @@
*/
const unsigned vertical_placement_;
+ /** The formula to calulate the x value of the dialog. */
+ tformula<unsigned>x_;
+
+ /** The formula to calulate the y value of the dialog. */
+ tformula<unsigned>y_;
+
+ /** The formula to calulate the width of the dialog. */
+ tformula<unsigned>w_;
+
+ /** The formula to calulate the height of the dialog. */
+ tformula<unsigned>h_;
+
+ /**
+ * Updates the size for the widget.
+ *
+ * Then the window isn't placed automatically the tformula for the sizes
+ * need to be recalculated and set_size() called with the result.
+ */
+ void update_size();
+
/** Does the real updating of the changes on the screen. */
void flip();
Modified: trunk/src/gui/widgets/window_builder.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window_builder.cpp?rev=28681&r1=28680&r2=28681&view=diff
==============================================================================
--- trunk/src/gui/widgets/window_builder.cpp (original)
+++ trunk/src/gui/widgets/window_builder.cpp Sun Aug 17 19:31:19 2008
@@ -90,7 +90,9 @@
}
twidget* widget = definition->grid->widgets[x * cols +
y]->build();
- window.set_child(widget, x, y,
definition->grid->flags[x * cols + y], definition->grid->border_size[x * cols
+ y]);
+ window.set_child(widget, x, y,
+ definition->grid->flags[x * cols + y],
+ definition->grid->border_size[x * cols + y]);
}
}
@@ -143,10 +145,10 @@
window_width(lexical_cast_default<unsigned>(cfg["window_width"])),
window_height(lexical_cast_default<unsigned>(cfg["window_height"])),
automatic_placement(utils::string_bool(cfg["automatic_placement"],
true)),
- x(lexical_cast_default<unsigned>(cfg["x"])),
- y(lexical_cast_default<unsigned>(cfg["y"])),
- width(lexical_cast_default<unsigned>(cfg["width"])),
- height(lexical_cast_default<unsigned>(cfg["height"])),
+ x(cfg["x"]),
+ y(cfg["y"]),
+ width(cfg["width"]),
+ height(cfg["height"]),
vertical_placement(get_v_align(cfg["vertical_placement"])),
horizontal_placement(get_h_align(cfg["horizontal_placement"])),
definition(cfg["definition"]),
@@ -171,10 +173,10 @@
* automatically placed the ''width'' and
* ''height'' are mandatory.
*
- * x (unsigned = 0) X coordinate of the window to show.
- * y (unsigned = 0) Y coordinate of the window to show.
- * width (unsigned = 0) Width of the window to show.
- * height (unsigned = 0) Height of the window to show.
+ * x (f_unsigned = 0) X coordinate of the window to show.
+ * y (f_unsigned = 0) Y coordinate of the window to show.
+ * width (f_unsigned = 0) Width of the window to show.
+ * height (f_unsigned = 0) Height of the window to show.
*
* vertical_placement (v_align = "")
* The vertical placement of the window.
@@ -189,6 +191,13 @@
* the grid needs its own documentation page.
* @end_table
*
+ * The size variables are copied to the window and will be determined runtime.
+ * This is needed since the main window can be resized and the dialog needs to
+ * resize accordingly. The following variables are available:
+ * @start_table = formula
+ * screen_width unsigned The usable width of the wesnoth main
window.
+ * screen_height unsigned The usable height of the wesnoth main
window.
+ * @end_table
*/
VALIDATE(cfg.child("grid"), _("No grid defined."));
@@ -196,8 +205,10 @@
grid = new tbuilder_grid(*(cfg.child("grid")));
if(!automatic_placement) {
- VALIDATE(width, missing_mandatory_wml_key("resolution",
"width"));
- VALIDATE(height, missing_mandatory_wml_key("resolution",
"height"));
+ VALIDATE(width.has_formula() || width(),
+ missing_mandatory_wml_key("resolution", "width"));
+ VALIDATE(height.has_formula() || height(),
+ missing_mandatory_wml_key("resolution", "height"));
}
DBG_G_P << "Window builder: parsing resolution "
Modified: trunk/src/gui/widgets/window_builder.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window_builder.hpp?rev=28681&r1=28680&r2=28681&view=diff
==============================================================================
--- trunk/src/gui/widgets/window_builder.hpp (original)
+++ trunk/src/gui/widgets/window_builder.hpp Sun Aug 17 19:31:19 2008
@@ -15,6 +15,7 @@
#ifndef GUI_WIDGETS_WINDOW_BUILDER_HPP_INCLUDED
#define GUI_WIDGETS_WINDOW_BUILDER_HPP_INCLUDED
+#include "formula.hpp"
#include "reference_counted_object.hpp"
#include "tstring.hpp"
@@ -101,10 +102,10 @@
bool automatic_placement;
- unsigned x;
- unsigned y;
- unsigned width;
- unsigned height;
+ tformula<unsigned> x;
+ tformula<unsigned> y;
+ tformula<unsigned> width;
+ tformula<unsigned> height;
unsigned vertical_placement;
unsigned horizontal_placement;
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits