The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
gui2::twindow Class Reference

base class of top level items, the only item which needs to store the final canvases to draw on More...

#include <window.hpp>

Inheritance diagram for gui2::twindow:
Inheritance graph

Classes

class  tinvalidate_layout_blocker
 Helper class to block invalidate_layout. More...
 
struct  tlinked_size
 Helper struct to force widgets the have the same size. More...
 

Public Types

enum  tretval { NONE = 0, OK = -1, CANCEL = -2, AUTO_CLOSE = -3 }
 Default return values. More...
 
enum  tstatus { NEW, SHOWING, REQUEST_CLOSE, CLOSED }
 The status of the window. More...
 
- Public Types inherited from gui2::event::tdispatcher
enum  tevent_type { pre = 1, child = 2, post = 4 }
 
enum  tposition {
  front_pre_child, back_pre_child, front_child, back_child,
  front_post_child, back_post_child
}
 The position where to add a new callback in the signal handler. More...
 
enum  tmouse_behavior { all, hit, none }
 The behavior of the mouse events. More...
 

Public Member Functions

 twindow (CVideo &video, tformula< unsigned > x, 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, const unsigned maximum_width, const unsigned maximum_height, const std::string &definition, const twindow_builder::tresolution::ttip &tooltip, const twindow_builder::tresolution::ttip &helptip)
 < Needs to be initialised in show. More...
 
 ~twindow ()
 
int show (const bool restore=true, const unsigned auto_close_timeout=0)
 Shows the window. More...
 
void show_tooltip ()
 Shows the window as a tooltip. More...
 
void show_non_modal ()
 Shows the window non modal. More...
 
void draw ()
 Draws the window. More...
 
void undraw ()
 Undraws the window. More...
 
void add_to_dirty_list (const std::vector< twidget * > &call_stack)
 Adds an item to the dirty_list_. More...
 
void close ()
 Requests to close the window. More...
 
void invalidate_layout ()
 Updates the size of the window. More...
 
twindowget_window ()
 Inherited from tevent_handler. More...
 
const twindowget_window () const
 Inherited from tevent_handler. More...
 
virtual twidgetfind_at (const tpoint &coordinate, const bool must_be_active) override
 See twidget::find_at. More...
 
virtual const twidgetfind_at (const tpoint &coordinate, const bool must_be_active) const override
 See twidget::find_at. More...
 
tdialogdialog ()
 Inherited from twidget. More...
 
twidgetfind (const std::string &id, const bool must_be_active) override
 See twidget::find. More...
 
const twidgetfind (const std::string &id, const bool must_be_active) const override
 See twidget::find. More...
 
bool does_click_dismiss () const
 Does the window close easily? More...
 
void set_enter_disabled (const bool enter_disabled)
 Disable the enter key. More...
 
void set_escape_disabled (const bool escape_disabled)
 Disable the escape key. More...
 
void init_linked_size_group (const std::string &id, const bool fixed_width, const bool fixed_height)
 Initializes a linked size group. More...
 
bool has_linked_size_group (const std::string &id)
 Is the linked size group defined for this window? More...
 
void add_linked_widget (const std::string &id, twidget *widget)
 Adds a widget to a linked size group. More...
 
void remove_linked_widget (const std::string &id, const twidget *widget)
 Removes a widget from a linked size group. More...
 
CVideovideo ()
 
void set_retval (const int retval, const bool close_window=true)
 Sets there return value of the window. More...
 
void set_owner (tdialog *owner)
 
void set_click_dismiss (const bool click_dismiss)
 
bool get_need_layout () const
 
void set_variable (const std::string &key, const variant &value)
 
tpoint get_linked_size (const std::string &linked_group_id) const
 
void mouse_capture (const bool capture=true)
 
void keyboard_capture (twidget *widget)
 
void add_to_keyboard_chain (twidget *widget)
 Adds the widget to the keyboard chain. More...
 
void remove_from_keyboard_chain (twidget *widget)
 Remove the widget from the keyboard chain. More...
 
- Public Member Functions inherited from gui2::tpanel
 tpanel (const unsigned canvas_count=2)
 Constructor. More...
 
virtual SDL_Rect get_client_rect () const override
 See tcontainer_::get_client_rect. More...
 
virtual bool get_active () const override
 See tcontrol::get_active. More...
 
virtual unsigned get_state () const override
 See tcontrol::get_state. More...
 
- Public Member Functions inherited from gui2::tcontainer_
 tcontainer_ (const unsigned canvas_count)
 
virtual void layout_initialise (const bool full_initialisation) override
 See twidget::layout_initialise. More...
 
void reduce_width (const unsigned maximum_width)
 Tries to reduce the width of a container. More...
 
virtual void request_reduce_width (const unsigned maximum_width) override
 See twidget::request_reduce_width. More...
 
virtual void demand_reduce_width (const unsigned maximum_width) override
 See twidget::demand_reduce_width. More...
 
void reduce_height (const unsigned maximum_height)
 Tries to reduce the height of a container. More...
 
virtual void request_reduce_height (const unsigned maximum_height) override
 See twidget::request_reduce_height. More...
 
virtual void demand_reduce_height (const unsigned maximum_height) override
 See twidget::demand_reduce_height. More...
 
virtual bool can_wrap () const override
 See twidget::can_wrap. More...
 
virtual void place (const tpoint &origin, const tpoint &size) override
 See twidget::place. More...
 
virtual bool has_widget (const twidget &widget) const override
 See twidget::has_widget. More...
 
virtual void set_origin (const tpoint &origin) override
 See twidget::set_origin. More...
 
virtual void set_visible_rectangle (const SDL_Rect &rectangle) override
 See twidget::set_visible_rectangle. More...
 
virtual void impl_draw_children (surface &frame_buffer, int x_offset, int y_offset) override
 See twidget::impl_draw_children. More...
 
virtual void set_active (const bool active) override
 See tcontrol::set_active. More...
 
bool disable_click_dismiss () const override
 See twidget::disable_click_dismiss. More...
 
virtual iterator::twalker_create_walker () override
 See twidget::create_walker. More...
 
void init_grid (const boost::intrusive_ptr< tbuilder_grid > &grid_builder)
 Initializes and builds the grid. More...
 
tgrid::iterator begin ()
 
tgrid::iterator end ()
 
unsigned add_row (const unsigned count=1)
 
void set_rows (const unsigned rows)
 
unsigned int get_rows () const
 
void set_cols (const unsigned cols)
 
unsigned int get_cols () const
 
void set_rows_cols (const unsigned rows, const unsigned cols)
 
void set_child (twidget *widget, const unsigned row, const unsigned col, const unsigned flags, const unsigned border_size)
 
void set_row_grow_factor (const unsigned row, const unsigned factor)
 
void set_column_grow_factor (const unsigned column, const unsigned factor)
 
const tgridgrid () const
 
tgridgrid ()
 
- Public Member Functions inherited from gui2::tcontrol
 tcontrol (const unsigned canvas_count)
 
 tcontrol (const implementation::tbuilder_control &builder, const unsigned canvas_count, const std::string &control_type)
 Constructor. More...
 
virtual void set_members (const string_map &data)
 Sets the members of the control. More...
 
bool disable_click_dismiss () const override
 See twidget::disable_click_dismiss. More...
 
tpoint get_config_minimum_size () const
 Gets the minimum size as defined in the config. More...
 
tpoint get_config_default_size () const
 Gets the default size as defined in the config. More...
 
tpoint get_config_maximum_size () const
 Gets the best size as defined in the config. More...
 
virtual unsigned get_characters_per_line () const
 Returns the number of characters per line. More...
 
virtual bool get_link_aware () const
 Returns whether the label should be link_aware, in in rendering and in searching for links with get_link. More...
 
virtual std::string get_link_color () const
 Returns the color string to be used with links. More...
 
void set_definition (const std::string &definition)
 Sets the definition. More...
 
bool get_use_tooltip_on_label_overflow () const
 
void set_use_tooltip_on_label_overflow (const bool use_tooltip=true)
 
const t_stringlabel () const
 
virtual void set_label (const t_string &label)
 
virtual void set_use_markup (bool use_markup)
 
bool get_use_markup () const
 
const t_stringtooltip () const
 
void set_tooltip (const t_string &tooltip)
 
const t_stringhelp_message () const
 
void set_help_message (const t_string &help_message)
 
std::vector< tcanvas > & canvas ()
 
tcanvascanvas (const unsigned index)
 
void set_text_alignment (const PangoAlignment text_alignment)
 
PangoAlignment get_text_alignment () const
 
- Public Member Functions inherited from gui2::twidget
 twidget ()
 
 twidget (const tbuilder_widget &builder)
 Constructor. More...
 
virtual ~twidget () override
 
void set_id (const std::string &id)
 
const std::stringid () const
 
twindowget_window ()
 Get the parent window. More...
 
const twindowget_window () const
 The constant version of get_window. More...
 
tdialogdialog ()
 Returns the top-level dialogue. More...
 
void set_parent (twidget *parent)
 
twidgetparent ()
 
tpoint get_best_size () const
 Gets the best size for the widget. More...
 
virtual bool can_mouse_focus () const
 Whether the mouse move/click event go 'through' this widget. More...
 
virtual void set_size (const tpoint &size)
 Sets the size of the widget. More...
 
virtual void move (const int x_offset, const int y_offset)
 Moves a widget. More...
 
tpoint get_origin () const
 Returns the screen origin of the widget. More...
 
tpoint get_size () const
 Returns the size of the widget. More...
 
SDL_Rect get_rectangle () const
 Gets the bounding rectangle of the widget on the screen. More...
 
int get_x () const
 
int get_y () const
 
unsigned get_width () const
 
unsigned get_height () const
 
void set_linked_group (const std::string &linked_group)
 
SDL_Rect calculate_blitting_rectangle (const int x_offset, const int y_offset)
 Calculates the blitting rectangle of the widget. More...
 
SDL_Rect calculate_clipping_rectangle (const int x_offset, const int y_offset)
 Calculates the clipping rectangle of the widget. More...
 
void draw_background (surface &frame_buffer, int x_offset, int y_offset)
 Draws the background of a widget. More...
 
void draw_children (surface &frame_buffer, int x_offset, int y_offset)
 Draws the children of a widget. More...
 
void draw_foreground (surface &frame_buffer, int x_offset, int y_offset)
 Draws the foreground of the widget. More...
 
void populate_dirty_list (twindow &caller, std::vector< twidget * > &call_stack)
 Adds a widget to the dirty list if it is dirty. More...
 
SDL_Rect get_dirty_rectangle () const
 Gets the dirty rectangle of the widget. More...
 
void set_is_dirty (const bool is_dirty)
 
bool get_is_dirty () const
 
void set_visible (const tvisible::scoped_enum visible)
 
tvisible::scoped_enum get_visible () const
 
tredraw_action::scoped_enum get_drawing_action () const
 
void set_debug_border_mode (const unsigned debug_border_mode)
 
void set_debug_border_colour (const unsigned debug_border_colour)
 
- Public Member Functions inherited from gui2::tevent_executor
 tevent_executor ()
 
virtual ~tevent_executor ()
 
void set_wants_mouse_hover (const bool hover=true)
 
bool wants_mouse_hover () const
 
void set_wants_mouse_left_double_click (const bool click=true)
 
bool wants_mouse_left_double_click () const
 
void set_wants_mouse_middle_double_click (const bool click=true)
 
bool wants_mouse_middle_double_click () const
 
tevent_executorset_wants_mouse_right_double_click (const bool click=true)
 
bool wants_mouse_right_double_click () const
 
- Public Member Functions inherited from gui2::event::tdispatcher
 tdispatcher ()
 
virtual ~tdispatcher ()
 
void connect ()
 Connects the dispatcher to the event handler. More...
 
bool has_event (const tevent event, const tevent_type event_type)
 
bool fire (const tevent event, twidget &target)
 Fires an event which has no extra parameters. More...
 
bool fire (const tevent event, twidget &target, const tpoint &coordinate)
 Fires an event which takes a coordinate parameter. More...
 
bool fire (const tevent event, twidget &target, const SDLKey key, const SDLMod modifier, const utf8::string &unicode)
 Fires an event which takes keyboard parameters. More...
 
bool fire (const tevent event, twidget &target, void *)
 Fires an event which takes notification parameters. More...
 
bool fire (const tevent event, twidget &target, tmessage &message)
 Fires an event which takes message parameters. More...
 
template<tevent E>
boost::enable_if
< boost::mpl::has_key
< tset_event, boost::mpl::int_
< E > > >::type 
connect_signal (const tsignal_function &signal, const tposition position=back_child)
 Connect a signal for callback in tset_event. More...
 
template<tevent E>
boost::enable_if
< boost::mpl::has_key
< tset_event, boost::mpl::int_
< E > > >::type 
disconnect_signal (const tsignal_function &signal, const tposition position=back_child)
 Disconnect a signal for callback in tset_event. More...
 
template<tevent E>
boost::enable_if
< boost::mpl::has_key
< tset_event_mouse,
boost::mpl::int_< E >
> >::type 
connect_signal (const tsignal_mouse_function &signal, const tposition position=back_child)
 Connect a signal for callback in tset_event_mouse. More...
 
template<tevent E>
boost::enable_if
< boost::mpl::has_key
< tset_event_mouse,
boost::mpl::int_< E >
> >::type 
disconnect_signal (const tsignal_mouse_function &signal, const tposition position=back_child)
 Disconnect a signal for callback in tset_event_mouse. More...
 
template<tevent E>
boost::enable_if
< boost::mpl::has_key
< tset_event_keyboard,
boost::mpl::int_< E >
> >::type 
connect_signal (const tsignal_keyboard_function &signal, const tposition position=back_child)
 Connect a signal for callback in tset_event_keyboard. More...
 
template<tevent E>
boost::enable_if
< boost::mpl::has_key
< tset_event_keyboard,
boost::mpl::int_< E >
> >::type 
disconnect_signal (const tsignal_keyboard_function &signal, const tposition position=back_child)
 Disconnect a signal for callback in tset_event_keyboard. More...
 
template<tevent E>
boost::enable_if
< boost::mpl::has_key
< tset_event_notification,
boost::mpl::int_< E >
> >::type 
connect_signal (const tsignal_notification_function &signal, const tposition position=back_child)
 Connect a signal for callback in tset_event_notification. More...
 
template<tevent E>
boost::enable_if
< boost::mpl::has_key
< tset_event_notification,
boost::mpl::int_< E >
> >::type 
disconnect_signal (const tsignal_notification_function &signal, const tposition position=back_child)
 Disconnect a signal for callback in tset_event_notification. More...
 
template<tevent E>
boost::enable_if
< boost::mpl::has_key
< tset_event_message,
boost::mpl::int_< E >
> >::type 
connect_signal (const tsignal_message_function &signal, const tposition position=back_child)
 Connect a signal for callback in tset_event_message. More...
 
template<tevent E>
boost::enable_if
< boost::mpl::has_key
< tset_event_message,
boost::mpl::int_< E >
> >::type 
disconnect_signal (const tsignal_message_function &signal, const tposition position=back_child)
 Disconnect a signal for callback in tset_event_message. More...
 
void capture_mouse ()
 Captures the mouse. More...
 
void release_mouse ()
 Releases the mouse capture. More...
 
void set_mouse_behavior (const tmouse_behavior mouse_behavior)
 
tmouse_behavior get_mouse_behavior () const
 
void set_want_keyboard_input (const bool want_keyboard_input)
 
bool get_want_keyboard_input () const
 
void register_hotkey (const hotkey::HOTKEY_COMMAND id, const thotkey_function &function)
 Registers a hotkey. More...
 
bool execute_hotkey (const hotkey::HOTKEY_COMMAND id)
 Executes a hotkey. More...
 
- Public Member Functions inherited from cursor::setter
 setter (CURSOR_TYPE type)
 
 ~setter ()
 

Static Public Member Functions

static void update_screen_size ()
 Update the size of the screen variables in settings. More...
 
static twindowwindow_instance (const unsigned handle)
 Returns the instance of a window. More...
 
static tretval get_retval_by_id (const std::string &id)
 Gets the retval for the default buttons. More...
 
static void set_sunset (const unsigned interval)
 

Private Types

enum  tshow_mode { none, modal, tooltip }
 

Private Member Functions

void layout ()
 Layouts the window. More...
 
void layout_linked_widgets ()
 Layouts the linked widgets. More...
 
bool click_dismiss (const Uint8 mouse_button_mask)
 Handles a mouse click event for dismissing the dialogue. More...
 
virtual const std::stringget_control_type () const override
 See tcontrol::get_control_type. More...
 
void finalize (const boost::intrusive_ptr< tbuilder_grid > &content_grid)
 Finishes the initialization of the grid. More...
 
void generate_dot_file (const std::string &, const unsigned)
 
void signal_handler_sdl_video_resize (const event::tevent event, bool &handled, const tpoint &new_size)
 
void signal_handler_click_dismiss (const event::tevent event, bool &handled, bool &halt, const Uint8 mouse_button_mask)
 The handler for the click dismiss mouse 'event'. More...
 
void signal_handler_sdl_key_down (const event::tevent event, bool &handled, const SDLKey key)
 
void signal_handler_message_show_tooltip (const event::tevent event, bool &handled, event::tmessage &message)
 
void signal_handler_message_show_helptip (const event::tevent event, bool &handled, event::tmessage &message)
 
void signal_handler_request_placement (const event::tevent event, bool &handled)
 

Private Attributes

CVideovideo_
 Needed so we can change what's drawn on the screen. More...
 
tstatus status_
 The status of the window. More...
 
tshow_mode show_mode_
 The mode in which the window is shown. More...
 
int retval_
 
tdialogowner_
 The dialog that owns the window. More...
 
bool need_layout_
 When set the form needs a full layout redraw cycle. More...
 
game_logic::map_formula_callable variables_
 The variables of the canvas. More...
 
bool invalidate_layout_blocked_
 Is invalidate layout blocked see tinvalidate_layout_blocker. More...
 
bool suspend_drawing_
 Avoid drawing the window. More...
 
bool restore_
 Whether the window should undraw the window using restorer_. More...
 
surface restorer_
 When the window closes this surface is used to undraw the window. More...
 
const bool automatic_placement_
 Do we wish to place the widget automatically? More...
 
const unsigned horizontal_placement_
 Sets the horizontal placement. More...
 
const unsigned vertical_placement_
 Sets the vertical placement. More...
 
unsigned maximum_width_
 The maximum width if automatic_placement_ is true. More...
 
unsigned maximum_height_
 The maximum height if automatic_placement_ is true. More...
 
tformula< unsigned > x_
 The formula to calulate the x value of the dialog. More...
 
tformula< unsigned > y_
 The formula to calulate the y value of the dialog. More...
 
tformula< unsigned > w_
 The formula to calulate the width of the dialog. More...
 
tformula< unsigned > h_
 The formula to calulate the height of the dialog. More...
 
tformula< bool > reevaluate_best_size_
 The formula to determine whether the size is good. More...
 
game_logic::function_symbol_table functions_
 The formula definitions available for the calulation formulas. More...
 
twindow_builder::tresolution::ttip tooltip_
 The settings for the tooltip. More...
 
twindow_builder::tresolution::ttip helptip_
 The settings for the helptip. More...
 
bool click_dismiss_
 Do we want to have easy close behavior? More...
 
bool enter_disabled_
 Disable the enter key see our setter for more info. More...
 
bool escape_disabled_
 Disable the escape key see our setter for more info. More...
 
std::map< std::string,
tlinked_size
linked_size_
 List of the widgets, whose size are linked together. More...
 
Uint8 mouse_button_state_
 The state of the mouse button. More...
 
std::vector< std::vector
< twidget * > > 
dirty_list_
 The list with dirty items in the window. More...
 
event::tdistributor * event_distributor_
 

Static Private Attributes

static unsigned sunset_ = 0
 Controls the sunset feature. More...
 

Friends

class tdebug_layout_graph
 
struct twindow_implementation
 
class tinvalidate_layout_blocker
 
class tpane
 
twindowbuild (CVideo &, const twindow_builder::tresolution *)
 Builds a window. More...
 

Additional Inherited Members

- Protected Member Functions inherited from gui2::tcontainer_
virtual void layout_children () override
 See twidget::layout_children. More...
 
virtual void child_populate_dirty_list (twindow &caller, const std::vector< twidget * > &call_stack) override
 See twidget::child_populate_dirty_list. More...
 
- Protected Member Functions inherited from gui2::tcontrol
tresolution_definition_ptr config ()
 
tresolution_definition_const_ptr config () const
 
void set_config (tresolution_definition_ptr config)
 
virtual void update_canvas ()
 Updates the canvas(ses). More...
 
int get_text_maximum_width () const
 Returns the maximum width available for the text. More...
 
int get_text_maximum_height () const
 Returns the maximum height available for the text. More...
 
std::string get_label_token (const gui2::tpoint &position, const char *delimiters=" \n\r\t") const
 Exposes font::ttext::get_token, for the text label of this control. More...
 
std::string get_label_link (const gui2::tpoint &position) const
 
- Protected Member Functions inherited from gui2::twidget
void set_layout_size (const tpoint &size)
 
const tpointlayout_size () const
 

Detailed Description

base class of top level items, the only item which needs to store the final canvases to draw on

Definition at line 62 of file window.hpp.

Member Enumeration Documentation

Default return values.

These values are named return values and most are assigned to a widget automatically when using a certain id for that widget. The automatic return values are always a negative number.

Note this might be moved somewhere else since it will force people to include the button, while it should be and implementation detail for most callers.

Enumerator
NONE 

Dialog is closed with no return value, should be rare but eg a message popup can do it.

OK 

Dialog is closed with ok button.

CANCEL 

Dialog is closed with the cancel button.

AUTO_CLOSE 

The dialog is closed automatically since it's timeout has been triggered.

Definition at line 119 of file window.hpp.

Enumerator
none 
modal 
tooltip 

Definition at line 471 of file window.hpp.

The status of the window.

Enumerator
NEW 

The window is new and not yet shown.

SHOWING 

The window is being shown.

REQUEST_CLOSE 

The window has been requested to be closed but still needs to evaluate the request.

CLOSED 

The window has been closed.

Definition at line 219 of file window.hpp.

Constructor & Destructor Documentation

gui2::twindow::twindow ( CVideo video,
tformula< unsigned >  x,
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,
const unsigned  maximum_width,
const unsigned  maximum_height,
const std::string definition,
const twindow_builder::tresolution::ttip tooltip,
const twindow_builder::tresolution::ttip helptip 
)
gui2::twindow::~twindow ( )

Member Function Documentation

void gui2::twindow::add_linked_widget ( const std::string id,
twidget widget 
)

Adds a widget to a linked size group.

The group needs to exist, which is done by calling init_linked_size_group. A widget may only be member of one group.

Todo:
Untested if a new widget is added after showing the widgets.
Parameters
idThe id of the group.
widgetThe widget to add to the group.

Definition at line 984 of file window.cpp.

References gui2::event::find(), has_linked_size_group(), gui2::twidget::id(), and linked_size_.

Referenced by gui2::twidget::layout_initialise().

void gui2::twindow::add_to_dirty_list ( const std::vector< twidget * > &  call_stack)
inline

Adds an item to the dirty_list_.

Parameters
call_stackThe list of widgets traversed to get to the dirty widget.

Definition at line 213 of file window.hpp.

References dirty_list_.

Referenced by gui2::twidget::populate_dirty_list().

void gui2::twindow::add_to_keyboard_chain ( twidget widget)

Adds the widget to the keyboard chain.

Todo:
rename to keyboard_add_to_chain.
Parameters
widgetThe widget to add to the chain. The widget should be valid widget, which hasn't been added to the chain yet.

Definition at line 1400 of file window.cpp.

References event_distributor_.

Referenced by gui2::build().

bool gui2::twindow::click_dismiss ( const Uint8  mouse_button_mask)
private

Handles a mouse click event for dismissing the dialogue.

Parameters
mouse_button_maskThe SDL_BUTTON mask for the button used to dismiss the click. If the caller is from the keyboard code the value should be 0.
Returns
Whether the event should be considered as handled.

Definition at line 1240 of file window.cpp.

References does_click_dismiss(), mouse_button_state_, OK, and set_retval().

Referenced by set_click_dismiss(), signal_handler_click_dismiss(), and signal_handler_sdl_key_down().

void gui2::twindow::close ( )
inline
tdialog* gui2::twindow::dialog ( )
inline

Inherited from twidget.

Definition at line 290 of file window.hpp.

References owner_.

Referenced by gui2::twidget::dialog().

bool gui2::twindow::does_click_dismiss ( ) const
inline

Does the window close easily?

The behavior can change at run-time, but that might cause oddities with the easy close button (when one is needed).

Returns
Whether or not the window closes easily.

Definition at line 332 of file window.hpp.

References click_dismiss_, and gui2::tcontainer_::disable_click_dismiss().

Referenced by click_dismiss().

void gui2::twindow::draw ( )

Draws the window.

This routine draws the window if needed, it's called from the event handler. This is done by a drawing event. When a window is shown it manages an SDL timer which fires a drawing event every X milliseconds, that event calls this routine. Don't call it manually.

Todo:
should probably be moved to event::thandler::draw.

Definition at line 738 of file window.cpp.

References sdl::create_rect(), dirty_list_, font::draw_floating_labels(), sdl::fill_rect_alpha(), gui2::twidget::get_rectangle(), get_surface_portion(), get_video_surface(), CVideo::getSurface(), i, itor, layout(), gui2::tcontainer_::layout_children(), need_layout_, gui2::new_widgets, gui2::twidget::tredraw_action::none, gui2::twidget::populate_dirty_list(), restore_, restorer_, screen_area(), sdl_blit(), sunset_, suspend_drawing_, update_rect(), preferences::use_color_cursors(), video_, and gui2::twidget::tvisible::visible.

Referenced by show(), and twindow().

void gui2::twindow::finalize ( const boost::intrusive_ptr< tbuilder_grid > &  content_grid)
private

Finishes the initialization of the grid.

Parameters
content_gridThe new contents for the content grid.

Definition at line 1301 of file window.cpp.

References gui2::tcontainer_::grid().

Referenced by gui2::build().

twidget * gui2::twindow::find ( const std::string id,
const bool  must_be_active 
)
overridevirtual
const twidget * gui2::twindow::find ( const std::string id,
const bool  must_be_active 
) const
overridevirtual

See twidget::find.

Reimplemented from gui2::tcontainer_.

Definition at line 963 of file window.cpp.

References gui2::tcontainer_::find().

twidget * gui2::twindow::find_at ( const tpoint coordinate,
const bool  must_be_active 
)
overridevirtual

See twidget::find_at.

Reimplemented from gui2::tcontainer_.

Definition at line 947 of file window.cpp.

References gui2::tcontainer_::find_at().

const twidget * gui2::twindow::find_at ( const tpoint coordinate,
const bool  must_be_active 
) const
overridevirtual

See twidget::find_at.

Reimplemented from gui2::tcontainer_.

Definition at line 952 of file window.cpp.

References gui2::tcontainer_::find_at().

void gui2::twindow::generate_dot_file ( const std::string ,
const unsigned   
)
inlineprivate

Definition at line 697 of file window.hpp.

Referenced by layout(), show(), show_non_modal(), and show_tooltip().

const std::string & gui2::twindow::get_control_type ( ) const
overrideprivatevirtual

See tcontrol::get_control_type.

Reimplemented from gui2::tpanel.

Definition at line 1253 of file window.cpp.

tpoint gui2::twindow::get_linked_size ( const std::string linked_group_id) const
inline

Definition at line 454 of file window.hpp.

References linked_size_.

Referenced by gui2::twidget::get_best_size().

bool gui2::twindow::get_need_layout ( ) const
inline

Definition at line 444 of file window.hpp.

References need_layout_.

Referenced by gui2::tscrollbar_container::content_resize_request().

twindow::tretval gui2::twindow::get_retval_by_id ( const std::string id)
static

Gets the retval for the default buttons.

The ones for the title screen.

This is a kind of hack, but the values are hardcoded in the titlescreen and don't want to change them at the moment. It would be a good idea to add some namespaces to avoid names clashing.

The hacks which are here so the old engine can handle the event. The new engine can't handle all dialogs yet, so it needs to fall back to the old engine to make certain things happen.

Definition at line 493 of file window.cpp.

References CANCEL, gui2::ttitle_screen::CHANGE_LANGUAGE, gui2::ttitle_screen::CORES, gui2::ttitle_screen::EDIT_PREFERENCES, gui2::ttitle_screen::GET_ADDONS, gui2::ttitle_screen::LOAD_GAME, gui2::ttitle_screen::MULTIPLAYER, gui2::ttitle_screen::NEW_CAMPAIGN, NONE, OK, gui2::ttitle_screen::QUIT_GAME, gui2::ttitle_screen::SHOW_ABOUT, gui2::ttitle_screen::SHOW_HELP, gui2::ttitle_screen::START_MAP_EDITOR, and gui2::ttitle_screen::TUTORIAL.

Referenced by gui2::implementation::get_retval().

twindow& gui2::twindow::get_window ( )
inline

Inherited from tevent_handler.

Definition at line 270 of file window.hpp.

const twindow& gui2::twindow::get_window ( ) const
inline

Inherited from tevent_handler.

Definition at line 276 of file window.hpp.

bool gui2::twindow::has_linked_size_group ( const std::string id)

Is the linked size group defined for this window?

Parameters
idThe id of the group.
Returns
True if defined, false otherwise.

Definition at line 979 of file window.cpp.

References linked_size_.

Referenced by add_linked_widget(), gui2::build(), init_linked_size_group(), and remove_linked_widget().

void gui2::twindow::init_linked_size_group ( const std::string id,
const bool  fixed_width,
const bool  fixed_height 
)

Initializes a linked size group.

Note at least one of fixed_width or fixed_height must be true.

Parameters
idThe id of the group.
fixed_widthDoes the group have a fixed width?
fixed_heightDoes the group have a fixed height?

Definition at line 969 of file window.cpp.

References has_linked_size_group(), gui2::twidget::id(), and linked_size_.

Referenced by gui2::build().

void gui2::twindow::invalidate_layout ( )
void gui2::twindow::keyboard_capture ( twidget widget)
void gui2::twindow::layout ( )
private
void gui2::twindow::layout_linked_widgets ( )
private

Layouts the linked widgets.

See Layout algorithm for more information.

Definition at line 1194 of file window.cpp.

References linked_size_, gui2::tpoint::x, and gui2::tpoint::y.

Referenced by gui2::twindow_implementation::layout(), layout(), and gui2::tpane::signal_handler_request_placement().

void gui2::twindow::mouse_capture ( const bool  capture = true)
void gui2::twindow::remove_from_keyboard_chain ( twidget widget)

Remove the widget from the keyboard chain.

Todo:
rename to keyboard_remove_from_chain.
Parameters
widgetThe widget to be removed from the chain.

Definition at line 1406 of file window.cpp.

References event_distributor_.

void gui2::twindow::remove_linked_widget ( const std::string id,
const twidget widget 
)

Removes a widget from a linked size group.

The group needs to exist, which is done by calling init_linked_size_group. If the widget is no member of the group the function does nothing.

Parameters
idThe id of the group.
widgetThe widget to remove from the group.

Definition at line 995 of file window.cpp.

References gui2::event::find(), has_linked_size_group(), gui2::twidget::id(), and linked_size_.

void gui2::twindow::set_click_dismiss ( const bool  click_dismiss)
inline

Definition at line 434 of file window.hpp.

References click_dismiss(), and click_dismiss_.

Referenced by gui2::build(), and gui2::ttitle_screen::pre_show().

void gui2::twindow::set_enter_disabled ( const bool  enter_disabled)
inline

Disable the enter key.

This is added to block dialogs from being closed automatically.

Todo:
this function should be merged with the hotkey support once that has been added.

Definition at line 345 of file window.hpp.

References enter_disabled_.

Referenced by gui2::ttitle_screen::pre_show().

void gui2::twindow::set_escape_disabled ( const bool  escape_disabled)
inline

Disable the escape key.

This is added to block dialogs from being closed automatically.

Todo:
this function should be merged with the hotkey support once that has been added.

Definition at line 358 of file window.hpp.

References escape_disabled_.

Referenced by gui2::ttitle_screen::pre_show().

void gui2::twindow::set_owner ( tdialog owner)
inline

Definition at line 429 of file window.hpp.

References owner_.

void gui2::twindow::set_retval ( const int  retval,
const bool  close_window = true 
)
inline
static void gui2::twindow::set_sunset ( const unsigned  interval)
inlinestatic

Definition at line 439 of file window.hpp.

References sunset_.

Referenced by events::console_handler::do_sunset().

void gui2::twindow::set_variable ( const std::string key,
const variant value 
)
inline
int gui2::twindow::show ( const bool  restore = true,
const unsigned  auto_close_timeout = 0 
)

Shows the window.

Todo:
Clean up the show functions.

the show functions are a bit messy and can use a proper cleanup.

Parameters
restoreRestore the screenarea the window was on after closing it?
auto_close_timeoutThe time in ms after which the window will automatically close, if 0 it doesn't close.
Note
the timeout is a minimum time and there's no quarantee about how fast it closes after the minimum.
Returns
The close code of the window, predefined values are listed in tretval.

Helper class to set and restore the drawing interval.

We need to make sure we restore the value when the function ends, be it normally or due to an exception.

Todo:
Clean up the code duplication.

In the future the restoring shouldn't be needed so the duplication doesn't hurt too much but keep this todo as a reminder.

Definition at line 592 of file window.cpp.

References CLOSE_WINDOW_EVENT, draw(), generate_dot_file(), gui2::twidget::get_rectangle(), CVideo::getSurface(), invalidate_layout(), gui2::log_gui_draw, log_scope2, LOG_SCOPE_HEADER, modal, mouse_button_state_, NEW, events::pump(), gui2::tip::remove(), REQUEST_CLOSE, restore_, restorer_, retval_, sdl_blit(), show_mode_, SHOWING, status_, suspend_drawing_, font::undraw_floating_labels(), update_rect(), update_screen_size(), and video_.

void gui2::twindow::show_non_modal ( )

Shows the window non modal.

A tooltip can be interacted with unlike the tooltip.

Todo:
implement auto_close_timeout.

auto_close_timeout The time in ms after which the window will automatically close, if 0 it doesn't close.

Note
the timeout is a minimum time and there's no guarantee about how fast it closes after the minimum.

Definition at line 569 of file window.cpp.

References generate_dot_file(), gui2::event::tdispatcher::hit, invalidate_layout(), gui2::log_gui_draw, log_scope2, modal, NEW, events::pump(), gui2::event::tdispatcher::set_mouse_behavior(), show_mode_, status_, and suspend_drawing_.

Referenced by gui2::tpopup::show().

void gui2::twindow::show_tooltip ( )

Shows the window as a tooltip.

A tooltip can't be interacted with and is just shown.

Todo:
implement auto_close_timeout.

auto_close_timeout The time in ms after which the window will automatically close, if 0 it doesn't close.

Note
the timeout is a minimum time and there's no guarantee about how fast it closes after the minimum.

Definition at line 547 of file window.cpp.

References generate_dot_file(), invalidate_layout(), gui2::log_gui_draw, log_scope2, NEW, gui2::event::tdispatcher::none, gui2::event::tdispatcher::set_mouse_behavior(), gui2::event::tdispatcher::set_want_keyboard_input(), show_mode_, status_, suspend_drawing_, and gui2::tcontrol::tooltip().

Referenced by gui2::tpopup::show().

void gui2::twindow::signal_handler_click_dismiss ( const event::tevent  event,
bool &  handled,
bool &  halt,
const Uint8  mouse_button_mask 
)
private

The handler for the click dismiss mouse 'event'.

Parameters
eventSee event::tdispatcher::fire.
handledSee event::tdispatcher::fire.
haltSee event::tdispatcher::fire.
mouse_button_maskForwared to click_dismiss.

Definition at line 1427 of file window.cpp.

References click_dismiss(), DBG_GUI_E, and LOG_HEADER.

Referenced by twindow().

void gui2::twindow::signal_handler_message_show_helptip ( const event::tevent  event,
bool &  handled,
event::tmessage &  message 
)
private
void gui2::twindow::signal_handler_message_show_tooltip ( const event::tevent  event,
bool &  handled,
event::tmessage &  message 
)
private
void gui2::twindow::signal_handler_request_placement ( const event::tevent  event,
bool &  handled 
)
private

Definition at line 1489 of file window.cpp.

References DBG_GUI_E, invalidate_layout(), and LOG_HEADER.

Referenced by twindow().

void gui2::twindow::signal_handler_sdl_key_down ( const event::tevent  event,
bool &  handled,
const SDLKey  key 
)
private

Definition at line 1438 of file window.cpp.

References CANCEL, click_dismiss(), DBG_GUI_E, enter_disabled_, escape_disabled_, LOG_HEADER, OK, and set_retval().

Referenced by twindow().

void gui2::twindow::signal_handler_sdl_video_resize ( const event::tevent  event,
bool &  handled,
const tpoint new_size 
)
private
void gui2::twindow::undraw ( )
void gui2::twindow::update_screen_size ( )
static

Update the size of the screen variables in settings.

Before a window gets build the screen sizes need to be updated. This function does that. It's only done when no other window is active, if another window is active it already updates the sizes with it's resize event.

Definition at line 459 of file window.cpp.

References gui2::settings::gamemap_height, gui2::settings::gamemap_width, gui2::settings::gamemap_x_offset, display::get_singleton(), display::map_outside_area(), screen_area(), gui2::settings::screen_height, and gui2::settings::screen_width.

Referenced by gui2::get_window_builder(), gui2::load_settings(), and show().

CVideo& gui2::twindow::video ( )
inline
twindow * gui2::twindow::window_instance ( const unsigned  handle)
static

Returns the instance of a window.

Parameters
handleThe instance id of the window.
Returns
The window or nullptr.

Definition at line 454 of file window.cpp.

Referenced by gui2::event::thandler::handle_event().

Friends And Related Function Documentation

twindow* build ( CVideo ,
const twindow_builder::tresolution  
)
friend

Builds a window.

Definition at line 74 of file window_builder.cpp.

friend class tdebug_layout_graph
friend

Definition at line 64 of file window.hpp.

friend class tinvalidate_layout_blocker
friend

Definition at line 67 of file window.hpp.

friend class tpane
friend

Definition at line 68 of file window.hpp.

friend struct twindow_implementation
friend

Definition at line 66 of file window.hpp.

Member Data Documentation

const bool gui2::twindow::automatic_placement_
private

Do we wish to place the widget automatically?

Definition at line 514 of file window.hpp.

Referenced by layout().

bool gui2::twindow::click_dismiss_
private

Do we want to have easy close behavior?

Easy closing means that whenever a mouse click is done the dialog will be closed. The widgets in the window may override this behavior by registering themselves as blockers. This is tested by the function disable_click_dismiss().

The handling of easy close is done in the window, in order to do so a window either needs a click_dismiss or an ok button. Both will be hidden when not needed and when needed first the ok is tried and then the click_dismiss button. this allows adding a click_dismiss button to the window definition and use the ok from the window instance.

Todo:
After testing the click dismiss feature it should be documented in the wiki.

Definition at line 579 of file window.hpp.

Referenced by does_click_dismiss(), layout(), and set_click_dismiss().

std::vector<std::vector<twidget*> > gui2::twindow::dirty_list_
private

The list with dirty items in the window.

When drawing only the widgets that are dirty are updated. The draw() function has more information about the dirty_list_.

Definition at line 679 of file window.hpp.

Referenced by add_to_dirty_list(), and draw().

bool gui2::twindow::enter_disabled_
private

Disable the enter key see our setter for more info.

Definition at line 582 of file window.hpp.

Referenced by set_enter_disabled(), and signal_handler_sdl_key_down().

bool gui2::twindow::escape_disabled_
private

Disable the escape key see our setter for more info.

Definition at line 585 of file window.hpp.

Referenced by set_escape_disabled(), and signal_handler_sdl_key_down().

event::tdistributor* gui2::twindow::event_distributor_
private
game_logic::function_symbol_table gui2::twindow::functions_
private

The formula definitions available for the calulation formulas.

Definition at line 554 of file window.hpp.

Referenced by layout().

tformula<unsigned> gui2::twindow::h_
private

The formula to calulate the height of the dialog.

Definition at line 548 of file window.hpp.

Referenced by layout().

twindow_builder::tresolution::ttip gui2::twindow::helptip_
private

The settings for the helptip.

Definition at line 560 of file window.hpp.

Referenced by signal_handler_message_show_helptip().

const unsigned gui2::twindow::horizontal_placement_
private

Sets the horizontal placement.

Only used if automatic_placement_ is true. The value should be a tgrid placement flag.

Definition at line 522 of file window.hpp.

Referenced by layout().

bool gui2::twindow::invalidate_layout_blocked_
private

Is invalidate layout blocked see tinvalidate_layout_blocker.

Definition at line 502 of file window.hpp.

Referenced by invalidate_layout(), and gui2::twindow::tinvalidate_layout_blocker::tinvalidate_layout_blocker().

std::map<std::string, tlinked_size> gui2::twindow::linked_size_
private

List of the widgets, whose size are linked together.

Definition at line 621 of file window.hpp.

Referenced by add_linked_widget(), get_linked_size(), has_linked_size_group(), init_linked_size_group(), layout_linked_widgets(), and remove_linked_widget().

unsigned gui2::twindow::maximum_height_
private

The maximum height if automatic_placement_ is true.

Definition at line 536 of file window.hpp.

Referenced by layout().

unsigned gui2::twindow::maximum_width_
private

The maximum width if automatic_placement_ is true.

Definition at line 533 of file window.hpp.

Referenced by layout().

Uint8 gui2::twindow::mouse_button_state_
private

The state of the mouse button.

When click dismissing a dialogue in the past the DOWN event was used. This lead to a bug [1]. The obvious change was to switch to the UP event, this lead to another bug; the dialogue was directly dismissed. Since the game map code uses the UP and DOWN event to select a unit there is no simple solution.

Upon entry this value stores the mouse button state at entry. When a button is DOWN and goes UP that button does not trigger a dismissal of the dialogue, instead that button's down state is removed from this variable. Therefore the next UP event does dismiss the dialogue.

[1] https://gna.org/bugs/index.php?18970

Definition at line 668 of file window.hpp.

Referenced by click_dismiss(), and show().

bool gui2::twindow::need_layout_
private

When set the form needs a full layout redraw cycle.

This happens when either a widget changes it's size or visibility or the window is resized.

Definition at line 496 of file window.hpp.

Referenced by draw(), get_need_layout(), invalidate_layout(), and layout().

tdialog* gui2::twindow::owner_
private

The dialog that owns the window.

Definition at line 488 of file window.hpp.

Referenced by dialog(), and set_owner().

tformula<bool> gui2::twindow::reevaluate_best_size_
private

The formula to determine whether the size is good.

Definition at line 551 of file window.hpp.

Referenced by layout().

bool gui2::twindow::restore_
private

Whether the window should undraw the window using restorer_.

Definition at line 508 of file window.hpp.

Referenced by draw(), show(), and undraw().

surface gui2::twindow::restorer_
private

When the window closes this surface is used to undraw the window.

Definition at line 511 of file window.hpp.

Referenced by draw(), show(), and undraw().

int gui2::twindow::retval_
private

Definition at line 485 of file window.hpp.

Referenced by set_retval(), and show().

tshow_mode gui2::twindow::show_mode_
private

The mode in which the window is shown.

This is used to determine whether or not to remove the tip.

Definition at line 482 of file window.hpp.

Referenced by show(), show_non_modal(), show_tooltip(), and ~twindow().

tstatus gui2::twindow::status_
private

The status of the window.

Definition at line 469 of file window.hpp.

Referenced by close(), show(), show_non_modal(), and show_tooltip().

unsigned gui2::twindow::sunset_ = 0
staticprivate

Controls the sunset feature.

If this value is not 0 it will darken the entire screen every sunset_th drawing request that nothing has been modified. It's a debug feature.

Definition at line 594 of file window.hpp.

Referenced by draw(), and set_sunset().

bool gui2::twindow::suspend_drawing_
private

Avoid drawing the window.

Definition at line 505 of file window.hpp.

Referenced by draw(), show(), show_non_modal(), and show_tooltip().

twindow_builder::tresolution::ttip gui2::twindow::tooltip_
private

The settings for the tooltip.

Definition at line 557 of file window.hpp.

Referenced by signal_handler_message_show_tooltip().

game_logic::map_formula_callable gui2::twindow::variables_
private

The variables of the canvas.

Definition at line 499 of file window.hpp.

Referenced by layout(), and set_variable().

const unsigned gui2::twindow::vertical_placement_
private

Sets the vertical placement.

Only used if automatic_placement_ is true. The value should be a tgrid placement flag.

Definition at line 530 of file window.hpp.

Referenced by layout().

CVideo& gui2::twindow::video_
private

Needed so we can change what's drawn on the screen.

Definition at line 466 of file window.hpp.

Referenced by draw(), show(), signal_handler_message_show_helptip(), signal_handler_message_show_tooltip(), undraw(), and video().

tformula<unsigned> gui2::twindow::w_
private

The formula to calulate the width of the dialog.

Definition at line 545 of file window.hpp.

Referenced by layout().

tformula<unsigned> gui2::twindow::x_
private

The formula to calulate the x value of the dialog.

Definition at line 539 of file window.hpp.

Referenced by layout().

tformula<unsigned> gui2::twindow::y_
private

The formula to calulate the y value of the dialog.

Definition at line 542 of file window.hpp.

Referenced by layout().


The documentation for this class was generated from the following files: