Add reevaluate_best_size_ function for a window.

This function will be used in the tooltip window to evaluate whether the
final window size is proper. It also lets the window really handle
functions.
This commit is contained in:
Mark de Wever 2014-02-08 18:37:02 +01:00
parent b9aef81982
commit 8ff55378cc
6 changed files with 113 additions and 6 deletions

View file

@ -39,6 +39,10 @@
name=font_style
value="^(normal|bold|italic|underline)?$"
[/type]
[type]
name=function
value="^_?.*$"
[/type]
[type]
name=grow_direction
value="^horizontal|vertical$"
@ -1970,6 +1974,11 @@
type="string"
default="default"
[/key]
[key]
name="functions"
type="function"
default=""
[/key]
[key]
name="height"
type="f_unsigned"
@ -1990,6 +1999,11 @@
type="unsigned"
default=0
[/key]
[key]
name="reevaluate_best_size"
type="f_bool"
default=false
[/key]
[key]
name="vertical_placement"
type="v_align"

View file

@ -368,6 +368,42 @@ tline::tline(const config& cfg)
* gamemap_height & unsigned & The usable height of the Wesnoth gamemap,
* if no gamemap shown it's the same value as
* screen_height. $
*
* mouse_x & unsigned & The x coordinate of the mouse pointer. $
* mouse_y & unsigned & The y coordinate of the mouse pointer. $
*
* window_width & unsigned & The window width. This value has two
* meanings during the layout phase. This
* only applies if automatic placement is
* not enabled.
* - When set to 0 it should return the
* wanted maximum width. If no maximum
* is wanted it should be set to the
* '"(screen_width)"'.
* - When not equal to 0 its value is the
* best width for the window. When the
* size should remain unchanged it
* should be set to '"(window_width)"'.
* $
*
* window_height & unsigned & The window height. This value has two
* meanings during the layout phase. This
* only applies if automatic placement is
* not enabled.
* - When set to 0 it should return the
* wanted maximum height. If no maximum
* is wanted it should be set to the
* '"(screen_height)"'.
* - When not equal to 0 its value is the
* best height for the window. When the
* size should remain unchanged it
* should be set to '"(window_height)"'.
* $
*
* size_request_mode & string & A field foo:
* - maximum
* - size
*
* @end{table}
*
* Note when drawing the valid coordinates are:<br>
@ -434,6 +470,8 @@ tline::tline(const config& cfg)
* string & A text. $
* tstring & A translatable string. $
* f_tstring & Formula returning a translatable string. $
* function & A string containing a set of function
* definition for the formula language. $
*
* color & A string which contains the color, this
* a group of 4 numbers between 0 and 255
@ -548,6 +586,7 @@ tline::tline(const config& cfg)
* @allow{type}{name="t_string"}{value="^_?.*$"}
* @allow{type}{name="f_string"}{value="^.*$"}
* @allow{type}{name="f_tstring"}{value="^_?.*$"}
* @allow{type}{name="function"}{value="^_?.*$"}
*
* @allow{type}{name="color"}{value="^(?:2[0-5][0-5]|[01]?\d?\d)[.,]\s*(?:2[0-5][0-5]|[01]?\d?\d)[.,]\s*(?:2[0-5][0-5]|[01]?\d?\d)[.,]\s*(?:2[0-5][0-5]|[01]?\d?\d)$"}
*

View file

@ -80,6 +80,8 @@ twindow *build(CVideo &video, const twindow_builder::tresolution *definition)
, definition->y
, definition->width
, definition->height
, definition->reevaluate_best_size
, definition->functions
, definition->automatic_placement
, definition->horizontal_placement
, definition->vertical_placement
@ -271,6 +273,8 @@ twindow_builder::tresolution::tresolution(const config& cfg) :
y(cfg["y"]),
width(cfg["width"]),
height(cfg["height"]),
reevaluate_best_size(cfg["reevaluate_best_size"]),
functions(),
vertical_placement(
implementation::get_v_align(cfg["vertical_placement"])),
horizontal_placement(
@ -307,6 +311,11 @@ twindow_builder::tresolution::tresolution(const config& cfg) :
* width & f_unsigned & 0 & Width of the window to show. $
* height & f_unsigned & 0 & Height of the window to show. $
*
* reevaluate_best_size & f_bool & false &
* The foo $
*
* functions & function & "" &
* The function definitions s available for the formula fields in window. $
*
* vertical_placement & v_align & "" &
* The vertical placement of the window. $
@ -384,6 +393,10 @@ twindow_builder::tresolution::tresolution(const config& cfg) :
* @end{parent}{name=gui/window/resolution/}
*/
if(!cfg["functions"].empty()) {
game_logic::formula(cfg["functions"], &functions).evaluate();
}
const config &c = cfg.child("grid");
VALIDATE(c, _("No grid defined."));

View file

@ -178,6 +178,9 @@ public:
tformula<unsigned> y;
tformula<unsigned> width;
tformula<unsigned> height;
tformula<bool> reevaluate_best_size;
game_logic::function_symbol_table functions;
unsigned vertical_placement;
unsigned horizontal_placement;

View file

@ -265,6 +265,8 @@ twindow::twindow(CVideo& video,
tformula<unsigned>y,
tformula<unsigned>w,
tformula<unsigned>h,
tformula<bool>reevaluate_best_size,
const game_logic::function_symbol_table& functions,
const bool automatic_placement,
const unsigned horizontal_placement,
const unsigned vertical_placement,
@ -294,6 +296,8 @@ twindow::twindow(CVideo& video,
, y_(y)
, w_(w)
, h_(h)
, reevaluate_best_size_(reevaluate_best_size)
, functions_(functions)
, tooltip_(tooltip)
, helptip_(helptip)
, click_dismiss_(false)
@ -1004,19 +1008,25 @@ void twindow::layout()
log_scope2(log_gui_layout, LOG_SCOPE_HEADER);
const tpoint mouse = get_mouse_position();
variables_.add("mouse_x", variant(mouse.x));
variables_.add("mouse_y", variant(mouse.y));
variables_.add("window_width", variant(0));
variables_.add("window_height", variant(0));
variables_.add("size_request_mode", variant("maximum"));
get_screen_size_variables(variables_);
const int maximum_width = automatic_placement_
? maximum_width_
? std::min(maximum_width_, settings::screen_width)
: settings::screen_width
: w_(variables_);
: w_(variables_, &functions_);
const int maximum_height = automatic_placement_
? maximum_height_
? std::min(maximum_height_, settings::screen_height)
: settings::screen_height
: h_(variables_);
: h_(variables_, &functions_);
/***** Handle click dismiss status. *****/
tbutton* click_dismiss_button = NULL;
@ -1138,11 +1148,31 @@ void twindow::layout()
assert(false);
}
} else {
origin.x = x_(variables_);
origin.y = y_(variables_);
size.x = w_(variables_);
size.y = h_(variables_);
variables_.add("window_width", variant(size.x));
variables_.add("window_height", variant(size.y));
while(reevaluate_best_size_(variables_, &functions_)) {
layout_initialise(true);
twindow_implementation::layout(
*this
, w_(variables_, &functions_)
, h_(variables_, &functions_));
size = get_best_size();
variables_.add("window_width", variant(size.x));
variables_.add("window_height", variant(size.y));
}
variables_.add("size_request_mode", variant("size"));
origin.x = x_(variables_, &functions_);
origin.y = y_(variables_, &functions_);
size.x = w_(variables_, &functions_);
size.y = h_(variables_, &functions_);
}
/***** Set the window size *****/

View file

@ -65,6 +65,8 @@ public:
tformula<unsigned>y,
tformula<unsigned>w,
tformula<unsigned>h,
tformula<bool>reevaluate_best_size,
const game_logic::function_symbol_table& functions,
const bool automatic_placement,
const unsigned horizontal_placement,
const unsigned vertical_placement,
@ -497,6 +499,12 @@ private:
/** The formula to calulate the height of the dialog. */
tformula<unsigned>h_;
/** The formula to determine whether the size is good. */
tformula<bool> reevaluate_best_size_;
/** The formula definitions available for the calulation formulas. */
game_logic::function_symbol_table functions_;
/** The settings for the tooltip. */
twindow_builder::tresolution::ttip tooltip_;