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

Base class for all widgets. More...

#include <widget.hpp>

Inheritance diagram for gui2::twidget:
Inheritance graph

Classes

class  tredraw_action
 Visibility set by the engine. More...
 
class  tvisible
 Visibility settings done by the user. More...
 

Public Member Functions

 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 ()
 
virtual void layout_initialise (const bool full_initialisation)
 How the layout engine works. More...
 
virtual void request_reduce_width (const unsigned maximum_width)=0
 Tries to reduce the width of a widget. More...
 
virtual void demand_reduce_width (const unsigned maximum_width)
 Tries to reduce the width of a widget. More...
 
virtual void request_reduce_height (const unsigned maximum_height)
 Tries to reduce the height of a widget. More...
 
virtual void demand_reduce_height (const unsigned maximum_height)
 Tries to reduce the height of a widget. More...
 
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 bool can_wrap () const
 Can the widget wrap. More...
 
virtual void set_origin (const tpoint &origin)
 Sets the origin of the widget. More...
 
virtual void set_size (const tpoint &size)
 Sets the size of the widget. More...
 
virtual void place (const tpoint &origin, const tpoint &size)
 Places the widget. More...
 
virtual void move (const int x_offset, const int y_offset)
 Moves a widget. More...
 
virtual void layout_children ()
 Allows a widget to update its children. 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...
 
virtual void set_visible_rectangle (const SDL_Rect &rectangle)
 Sets the visible rectangle for a 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)
 
virtual twidgetfind_at (const tpoint &coordinate, const bool must_be_active)
 Returns the widget at the wanted coordinates. More...
 
virtual const twidgetfind_at (const tpoint &coordinate, const bool must_be_active) const
 The constant version of find_at. More...
 
virtual twidgetfind (const std::string &id, const bool must_be_active)
 Returns a widget with the wanted id. More...
 
virtual const twidgetfind (const std::string &id, const bool must_be_active) const
 The constant version of find. More...
 
virtual bool has_widget (const twidget &widget) const
 Does the widget contain the widget. More...
 
virtual bool disable_click_dismiss () const =0
 Does the widget disable easy close? More...
 
virtual iterator::twalker_create_walker ()=0
 Creates a new walker object on the heap. More...
 
- 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...
 

Protected Member Functions

void set_layout_size (const tpoint &size)
 
const tpointlayout_size () const
 

Private Member Functions

virtual tpoint calculate_best_size () const =0
 Calculates the best size. More...
 
virtual void impl_draw_background (surface &)
 See draw_background. More...
 
virtual void impl_draw_background (surface &, int, int)
 
virtual void impl_draw_children (surface &, int, int)
 See draw_children. More...
 
virtual void impl_draw_foreground (surface &, int, int)
 See draw_foreground. More...
 
virtual void child_populate_dirty_list (twindow &caller, const std::vector< twidget * > &call_stack)
 Tries to add all children of a container to the dirty list. More...
 
void draw_debug_border (surface &frame_buffer)
 
void draw_debug_border (surface &frame_buffer, int x_offset, int y_offset)
 
virtual bool is_at (const tpoint &coordinate) const override
 See event::tdispatcher::is_at. More...
 
bool is_at (const tpoint &coordinate, const bool must_be_active) const
 Is the coordinate inside our area. More...
 
bool recursive_is_visible (const twidget *widget, const bool must_be_active) const
 Is the widget and every single one of its parents visible? More...
 

Private Attributes

std::string id_
 The id is the unique name of the widget in a certain context. More...
 
twidgetparent_
 The parent widget. More...
 
int x_
 The x-coordinate of the widget on the screen. More...
 
int y_
 The y-coordinate of the widget on the screen. More...
 
unsigned width_
 The width of the widget. More...
 
unsigned height_
 The height of the widget. More...
 
tpoint layout_size_
 The best size for the widget. More...
 
std::string linked_group_
 The linked group the widget belongs to. More...
 
bool is_dirty_
 Is the widget dirty? More...
 
tvisible::scoped_enum visible_
 Field for the status of the visibility. More...
 
tredraw_action::scoped_enum redraw_action_
 Field for the action to do on a drawing request. More...
 
SDL_Rect clipping_rectangle_
 The clipping rectangle if a widget is partly visible. More...
 
unsigned debug_border_mode_
 Mode for drawing the debug border. More...
 
unsigned debug_border_colour_
 The colour for the debug border. More...
 

Friends

class tdebug_layout_graph
 
class twindow
 

Additional Inherited Members

- 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...
 

Detailed Description

Base class for all widgets.

From this abstract all other widgets should derive. It contains the minimal info needed for a real widget and some pure abstract functions which need to be implemented by classes deriving from this class.

Definition at line 49 of file widget.hpp.

Constructor & Destructor Documentation

gui2::twidget::twidget ( )
Deprecated:
use the second overload.

Definition at line 28 of file widget.cpp.

References DBG_GUI_LF.

Referenced by set_id().

gui2::twidget::twidget ( const tbuilder_widget builder)
explicit

Constructor.

Parameters
builderThe builder object with the settings for the object.

Definition at line 52 of file widget.cpp.

References DBG_GUI_LF.

gui2::twidget::~twidget ( )
overridevirtual

Member Function Documentation

virtual tpoint gui2::twidget::calculate_best_size ( ) const
privatepure virtual

Calculates the best size.

This function calculates the best size and ignores the current values in the layout phase. Note containers can call the get_best_size() of their children since it is meant to update itself.

Returns
The best size for the widget.
Return values
0,0The best size is 0,0.

Implemented in gui2::policy::placement::tindependent, gui2::policy::placement::tmatrix, gui2::policy::placement::tvertical_list, gui2::ttree_view_node, gui2::tgenerator_, gui2::tgrid, gui2::policy::placement::thorizontal_list, gui2::tmatrix, gui2::tcontrol, gui2::tpane, gui2::tscrollbar_container, gui2::tcontainer_, gui2::tviewport, gui2::timage, gui2::tspacer, gui2::tdrawing, and gui2::tslider.

Referenced by get_best_size().

SDL_Rect gui2::twidget::calculate_blitting_rectangle ( const int  x_offset,
const int  y_offset 
)

Calculates the blitting rectangle of the widget.

The blitting rectangle is the entire widget rectangle, but offsetted for drawing position.

Parameters
x_offsetThe offset in the x-direction when drawn.
y_offsetThe offset in the y-direction when drawn.
Returns
The drawing rectangle.

Definition at line 321 of file widget.cpp.

References get_rectangle().

Referenced by draw_debug_border(), gui2::tpanel::impl_draw_background(), gui2::tminimap::impl_draw_background(), gui2::tcontrol::impl_draw_background(), and gui2::tpanel::impl_draw_foreground().

SDL_Rect gui2::twidget::calculate_clipping_rectangle ( const int  x_offset,
const int  y_offset 
)

Calculates the clipping rectangle of the widget.

The clipping rectangle is used then the redraw_action_ is tredraw_action::partly. Since the drawing can be offsetted it also needs offset paramters.

Parameters
x_offsetThe offset in the x-direction when drawn.
y_offsetThe offset in the y-direction when drawn.
Returns
The clipping rectangle.

Definition at line 330 of file widget.cpp.

References clipping_rectangle_.

Referenced by draw_background(), draw_children(), draw_debug_border(), and draw_foreground().

virtual bool gui2::twidget::can_mouse_focus ( ) const
inlinevirtual

Whether the mouse move/click event go 'through' this widget.

Reimplemented in gui2::tgrid, gui2::tlabel, and gui2::timage.

Definition at line 349 of file widget.hpp.

Referenced by gui2::event::tmouse_motion::signal_handler_sdl_mouse_motion().

bool gui2::twidget::can_wrap ( ) const
virtual

Can the widget wrap.

When a widget can wrap it can reduce its width by increasing its height. When a layout is too wide it should first try to wrap and if that fails it should check the vertical scrollbar status. After wrapping the height might (probably will) change so the layout engine needs to recalculate the height after wrapping.

Reimplemented in gui2::tgrid, gui2::tscrollbar_container, gui2::tcontainer_, gui2::tscroll_label, and gui2::tlabel.

Definition at line 211 of file widget.cpp.

Referenced by gui2::tcontainer_::can_wrap(), gui2::tgrid::can_wrap(), gui2::tgrid::tchild::can_wrap(), gui2::tcontrol::get_best_text_size(), gui2::tcontrol::request_reduce_width(), gui2::ttext_box::update_canvas(), and gui2::tcontrol::update_canvas().

void gui2::twidget::child_populate_dirty_list ( twindow caller,
const std::vector< twidget * > &  call_stack 
)
privatevirtual

Tries to add all children of a container to the dirty list.

Note
The function is private since everybody should call populate_dirty_list instead.
Parameters
callerThe parent window, if dirty it should register itself to this window.
call_stackThe call-stack of widgets traversed to reach this function.

Reimplemented in gui2::tscrollbar_container, gui2::tgenerator_, gui2::tgrid, gui2::tlistbox, gui2::tmatrix, gui2::tcontainer_, gui2::tpane, gui2::ttree_view, and gui2::tviewport.

Definition at line 409 of file widget.cpp.

Referenced by populate_dirty_list().

virtual iterator::twalker_* gui2::twidget::create_walker ( )
pure virtual

Creates a new walker object on the heap.

Implemented in gui2::tgrid, gui2::tmatrix, gui2::tcontainer_, gui2::ttree_view_node, gui2::tpane, gui2::tcontrol, and gui2::tviewport.

void gui2::twidget::demand_reduce_height ( const unsigned  maximum_height)
virtual

Tries to reduce the height of a widget.

This function does it more aggressively and should only be used when using scrollbars failed.

Todo:
Make pure virtual.

See Layout algorithm for more information.

Parameters
maximum_heightThe wanted maximum height.

Reimplemented in gui2::tgrid, and gui2::tcontainer_.

Definition at line 183 of file widget.cpp.

void gui2::twidget::demand_reduce_width ( const unsigned  maximum_width)
virtual

Tries to reduce the width of a widget.

This function does it more aggressively and should only be used when using scrollbars and wrapping failed.

Todo:
Make pure virtual.

See Layout algorithm for more information.

Parameters
maximum_widthThe wanted maximum width.

Reimplemented in gui2::tgrid, and gui2::tcontainer_.

Definition at line 173 of file widget.cpp.

tdialog * gui2::twidget::dialog ( )

Returns the top-level dialogue.

A window is most of the time created by a dialogue, this function returns that dialogue.

Deprecated:
The function was used to install callbacks to member functions of the dialogue. Once all widgets are converted to signals this function will be removed.
Returns
The top-level dialogue.
Return values
nullptrNo top-level window or the top-level window is not owned by a dialogue.

Definition at line 144 of file widget.cpp.

References gui2::twindow::dialog(), and get_window().

Referenced by gui2::dialog_callback(), and gui2::dialog_view_callback().

virtual bool gui2::twidget::disable_click_dismiss ( ) const
pure virtual
void gui2::twidget::draw_background ( surface frame_buffer,
int  x_offset,
int  y_offset 
)

Draws the background of a widget.

Derived should override impl_draw_background instead of changing this function.

Parameters
frame_bufferThe surface to draw upon.
x_offsetThe offset in the x-direction in the frame_buffer to draw.
y_offsetThe offset in the y-direction in the frame_buffer to draw.

Definition at line 339 of file widget.cpp.

References calculate_clipping_rectangle(), draw_debug_border(), impl_draw_background(), gui2::twidget::tredraw_action::partly, redraw_action_, gui2::twidget::tvisible::visible, and visible_.

Referenced by gui2::tviewport::impl_draw_children(), and gui2::tgrid::impl_draw_children().

void gui2::twidget::draw_children ( surface frame_buffer,
int  x_offset,
int  y_offset 
)

Draws the children of a widget.

Containers should draw their children when they get this request.

Derived should override impl_draw_children instead of changing this function.

Parameters
frame_bufferThe surface to draw upon.
x_offsetThe offset in the x-direction in the frame_buffer to draw.
y_offsetThe offset in the y-direction in the frame_buffer to draw.

Definition at line 356 of file widget.cpp.

References calculate_clipping_rectangle(), impl_draw_children(), gui2::twidget::tredraw_action::partly, redraw_action_, gui2::twidget::tvisible::visible, and visible_.

Referenced by gui2::tviewport::impl_draw_children(), gui2::tcontainer_::impl_draw_children(), gui2::tmatrix::impl_draw_children(), gui2::ttree_view_node::impl_draw_children(), gui2::tgrid::impl_draw_children(), gui2::tscrollbar_container::impl_draw_children(), and gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::impl_draw_children().

void gui2::twidget::draw_debug_border ( surface frame_buffer)
private
void gui2::twidget::draw_debug_border ( surface frame_buffer,
int  x_offset,
int  y_offset 
)
private
void gui2::twidget::draw_foreground ( surface frame_buffer,
int  x_offset,
int  y_offset 
)

Draws the foreground of the widget.

Some widgets e.g. panel and window have a back and foreground layer this function requests the drawing of the foreground.

Derived should override impl_draw_foreground instead of changing this function.

Parameters
frame_bufferThe surface to draw upon.
x_offsetThe offset in the x-direction in the frame_buffer to draw.
y_offsetThe offset in the y-direction in the frame_buffer to draw.

Definition at line 371 of file widget.cpp.

References calculate_clipping_rectangle(), impl_draw_foreground(), gui2::twidget::tredraw_action::partly, redraw_action_, gui2::twidget::tvisible::visible, and visible_.

Referenced by gui2::tviewport::impl_draw_children(), and gui2::tgrid::impl_draw_children().

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

Returns a widget with the wanted id.

Note
Since the id might not be unique inside a container there is no guarantee which widget is returned.
Parameters
idThe id of the widget to find.
must_be_activeThe widget should be active, not all widgets have an active flag, those who don't ignore flag.
Returns
The widget with the id.
Return values
nullptrNo widget with the id found (or not active if must_be_active was set).

Reimplemented in gui2::policy::placement::tindependent, gui2::twindow, gui2::tgrid, gui2::tcontrol, gui2::ttree_view_node, gui2::tmatrix, gui2::tscrollbar_container, gui2::tcontainer_, and gui2::tviewport.

Definition at line 558 of file widget.cpp.

References id_.

Referenced by gui2::tmatrix::find(), gui2::ttree_view_node::find(), gui2::tcontrol::find(), find_widget(), and gui2::tlobby_player_info::pre_show().

const twidget * gui2::twidget::find ( const std::string id,
const bool  must_be_active 
) const
virtual
twidget * gui2::twidget::find_at ( const tpoint coordinate,
const bool  must_be_active 
)
virtual
const twidget * gui2::twidget::find_at ( const tpoint coordinate,
const bool  must_be_active 
) const
virtual
tpoint gui2::twidget::get_best_size ( ) const

Gets the best size for the widget.

During the layout phase a best size will be determined, several stages might change the best size. This function will return the currently best size as determined during the layout phase.

Returns
The best size for the widget.
Return values
0,0The best size is 0,0.

Definition at line 188 of file widget.cpp.

References calculate_best_size(), gui2::twindow::get_linked_size(), get_window(), gui2::twidget::tvisible::invisible, layout_size_, linked_group_, visible_, gui2::tpoint::x, and gui2::tpoint::y.

Referenced by gui2::tviewport::calculate_best_size(), gui2::tcontainer_::calculate_best_size(), gui2::tscrollbar_container::calculate_best_size(), gui2::tmatrix::calculate_best_size(), gui2::policy::placement::thorizontal_list::calculate_best_size(), gui2::ttree_view_node::calculate_best_size(), gui2::policy::placement::tvertical_list::calculate_best_size(), gui2::policy::placement::tindependent::calculate_best_size(), gui2::tgrid::tchild::get_best_size(), gui2::ttree_view_node::get_folded_size(), gui2::ttree_view_node::get_unfolded_size(), gui2::twindow_implementation::layout(), gui2::twindow::layout(), gui2::tviewport::place(), gui2::tscrollbar_container::place(), gui2::policy::placement::thorizontal_list::place(), gui2::policy::placement::tvertical_list::place(), gui2::ttree_view_node::place(), gui2::tgrid::tchild::place(), gui2::tgrid::reduce_height(), gui2::tgrid::reduce_width(), gui2::tscrollbar_container::request_reduce_height(), gui2::tgrid::request_reduce_height(), gui2::tscrollbar_container::request_reduce_width(), gui2::tgrid::request_reduce_width(), gui2::tlistbox::resize_content(), and gui2::tlistbox::set_content_size().

SDL_Rect gui2::twidget::get_dirty_rectangle ( ) const

Gets the dirty rectangle of the widget.

Depending on the redraw_action_ it returns the rectangle this widget dirties while redrawing.

Returns
The dirty rectangle.

Definition at line 416 of file widget.cpp.

References clipping_rectangle_, gui2::twidget::tredraw_action::full, get_rectangle(), and redraw_action_.

twidget::tredraw_action::scoped_enum gui2::twidget::get_drawing_action ( ) const
unsigned gui2::twidget::get_height ( ) const
bool gui2::twidget::get_is_dirty ( ) const

Definition at line 440 of file widget.cpp.

References is_dirty_.

tpoint gui2::twidget::get_origin ( ) const
SDL_Rect gui2::twidget::get_rectangle ( ) const
tpoint gui2::twidget::get_size ( ) const
twidget::tvisible::scoped_enum gui2::twidget::get_visible ( ) const

Definition at line 471 of file widget.cpp.

References visible_.

Referenced by gui2::tscrollbar_container::calculate_best_size(), gui2::policy::placement::thorizontal_list::calculate_best_size(), gui2::ttree_view_node::calculate_best_size(), gui2::policy::placement::tvertical_list::calculate_best_size(), gui2::tgrid_implementation::cell_request_reduce_height(), gui2::tgrid_implementation::cell_request_reduce_width(), gui2::tscrollbar_container::content_resize_height(), gui2::tscrollbar_container::content_resize_request(), gui2::tscrollbar_container::content_resize_width(), gui2::tcontrol::disable_click_dismiss(), gui2::tgrid::disable_click_dismiss(), gui2::policy::placement::thorizontal_list::find_at(), gui2::policy::placement::tvertical_list::find_at(), gui2::tgrid::tchild::get_best_size(), gui2::ttree_view_node::get_current_size(), gui2::ttree_view_node::get_unfolded_size(), gui2::policy::placement::tvertical_list::handle_key_down_arrow(), gui2::policy::placement::thorizontal_list::handle_key_right_arrow(), gui2::tviewport::impl_draw_children(), gui2::tcontainer_::impl_draw_children(), gui2::tgrid::impl_draw_children(), gui2::tscrollbar_container::impl_draw_children(), gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::impl_draw_children(), gui2::tviewport::layout_initialise(), gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::layout_initialise(), gui2::policy::placement::thorizontal_list::place(), gui2::policy::placement::tvertical_list::place(), gui2::tgrid::tchild::place(), gui2::tlistbox::remove_row(), gui2::tscrollbar_container::request_reduce_height(), gui2::tscrollbar_container::request_reduce_width(), gui2::tlistbox::resize_content(), gui2::policy::placement::thorizontal_list::set_origin(), gui2::policy::placement::tvertical_list::set_origin(), gui2::tscrollbar_container::signal_handler_sdl_wheel_down(), gui2::tscrollbar_container::signal_handler_sdl_wheel_left(), gui2::tscrollbar_container::signal_handler_sdl_wheel_right(), gui2::tscrollbar_container::signal_handler_sdl_wheel_up(), gui2::tgrid::swap_child(), and gui2::tlistbox::update_content_size().

unsigned gui2::twidget::get_width ( ) const
twindow * gui2::twidget::get_window ( )

Get the parent window.

Returns
Pointer to parent window.
Return values
nullptrNo parent window found.

Definition at line 116 of file widget.cpp.

References parent_.

Referenced by gui2::tpreferences::add_hotkey_callback(), gui2::tscrollbar_container::content_resize_height(), gui2::tscrollbar_container::content_resize_request(), gui2::tscrollbar_container::content_resize_width(), dialog(), gui2::dialog_callback(), gui2::tgame_load::filter_text_changed(), gui2::tunit_create::filter_text_changed(), gui2::policy::placement::thorizontal_list::find_at(), gui2::policy::placement::tvertical_list::find_at(), gui2::policy::placement::tindependent::find_at(), get_best_size(), layout_initialise(), gui2::tlistbox::list_item_clicked(), gui2::make_dialog_callback_helper(), gui2::taddon_list::on_filtertext_changed(), gui2::tunit_preview_pane::profile_button_callback(), gui2::tscrollbar_::recalculate(), gui2::tlistbox::set_row_shown(), set_visible(), gui2::tbutton::signal_handler_left_button_click(), gui2::tlabel::signal_handler_left_button_click(), gui2::tcombobox::signal_handler_left_button_click(), gui2::ttoggle_button::signal_handler_left_button_double_click(), gui2::ttoggle_panel::signal_handler_left_button_double_click(), gui2::tscroll_label::signal_handler_left_button_down(), gui2::tbutton::signal_handler_left_button_down(), gui2::trepeating_button::signal_handler_left_button_down(), gui2::tcombobox::signal_handler_left_button_down(), gui2::ttree_view::signal_handler_left_button_down(), gui2::ttext_box::signal_handler_left_button_down(), gui2::tscrollbar_::signal_handler_left_button_down(), gui2::tslider::signal_handler_left_button_up(), gui2::tscrollbar_::signal_handler_left_button_up(), gui2::tpane::signal_handler_request_placement(), gui2::tlabel::signal_handler_right_button_click(), and ~twidget().

const twindow * gui2::twidget::get_window ( ) const

The constant version of get_window.

Definition at line 130 of file widget.cpp.

References parent_.

int gui2::twidget::get_x ( ) const
int gui2::twidget::get_y ( ) const
bool gui2::twidget::has_widget ( const twidget widget) const
virtual

Does the widget contain the widget.

Widgets can be containers which have more widgets inside them, this function will traverse in those child widgets and tries to find the wanted widget.

Parameters
widgetPointer to the widget to find.
Returns
Whether or not the widget was found.

Reimplemented in gui2::tgrid, and gui2::tcontainer_.

Definition at line 569 of file widget.cpp.

Referenced by gui2::tcontainer_::has_widget(), and gui2::tgrid::has_widget().

const std::string & gui2::twidget::id ( ) const
virtual void gui2::twidget::impl_draw_background ( surface )
inlineprivatevirtual

See draw_background.

Definition at line 587 of file widget.hpp.

Referenced by draw_background().

virtual void gui2::twidget::impl_draw_background ( surface ,
int  ,
int   
)
inlineprivatevirtual
virtual void gui2::twidget::impl_draw_children ( surface ,
int  ,
int   
)
inlineprivatevirtual
virtual void gui2::twidget::impl_draw_foreground ( surface ,
int  ,
int   
)
inlineprivatevirtual

See draw_foreground.

Reimplemented in gui2::tcontrol, gui2::ttoggle_panel, and gui2::tpanel.

Definition at line 608 of file widget.hpp.

Referenced by draw_foreground().

bool gui2::twidget::is_at ( const tpoint coordinate) const
overrideprivatevirtual

See event::tdispatcher::is_at.

Implements gui2::event::tdispatcher.

Definition at line 574 of file widget.cpp.

Referenced by find_at().

bool gui2::twidget::is_at ( const tpoint coordinate,
const bool  must_be_active 
) const
private

Is the coordinate inside our area.

Helper for find_at so also looks at our visibility.

Parameters
coordinateThe coordinate which should be inside the widget.
must_be_activeThe widget should be active, not all widgets have an active flag, those who don't ignore flag.
Returns
Status.

Definition at line 593 of file widget.cpp.

References height_, recursive_is_visible(), width_, gui2::tpoint::x, x_, gui2::tpoint::y, and y_.

void gui2::twidget::layout_children ( )
virtual

Allows a widget to update its children.

Before the window is populating the dirty list the widgets can update their content, which allows delayed initialization. This delayed initialization is only allowed if the widget resizes itself, not when being placed.

Reimplemented in gui2::tscrollbar_container, gui2::tgrid, gui2::tlistbox, gui2::tmatrix, gui2::tcontainer_, gui2::ttree_view, and gui2::tstacked_widget.

Definition at line 264 of file widget.cpp.

Referenced by gui2::tgrid::layout_children().

void gui2::twidget::layout_initialise ( const bool  full_initialisation)
virtual

How the layout engine works.

Every widget has a member layout_size_ which holds the best size in the current layout phase. When the windows starts the layout phase it calls layout_initialise which resets this value.

Every widget has two function to get the best size. get_best_size tests whether layout_size_ is set and if so returns that value otherwise it calls calculate_best_size so the size can be updated.

During the layout phase some functions can modify layout_size_ so the next call to get_best_size returns the currently best size. This means that after the layout phase get_best_size still returns this value. Initialises the layout phase.

Clears the initial best size for the widgets.

See Layout algorithm for more information.

Parameters
full_initialisationFor widgets with scrollbars it hides them unless the mode is tscrollbar_mode::always_visible. For other widgets this flag is a NOP.

Reimplemented in gui2::tgenerator_, gui2::ttree_view_node, gui2::tgrid, gui2::tcontrol, gui2::tmatrix, gui2::tscrollbar_container, gui2::tpane, gui2::tcontainer_, and gui2::tviewport.

Definition at line 162 of file widget.cpp.

References gui2::twindow::add_linked_widget(), get_window(), gui2::twidget::tvisible::invisible, layout_size_, linked_group_, and visible_.

Referenced by gui2::tviewport::layout_initialise(), gui2::tpane::layout_initialise(), gui2::tcontrol::layout_initialise(), gui2::tgrid::layout_initialise(), gui2::ttree_view_node::layout_initialise(), and gui2::tpane::signal_handler_request_placement().

const tpoint & gui2::twidget::layout_size ( ) const
protected

Definition at line 309 of file widget.cpp.

References layout_size_.

void gui2::twidget::move ( const int  x_offset,
const int  y_offset 
)
virtual

Moves a widget.

This function can be used to move the widget without dirtying it.

Todo:
Implement the function to all derived classes.
Parameters
x_offsetThe amount of pixels to move the widget in the x-direction.
y_offsetThe amount of pixels to move the widget in the y-direction.

Definition at line 258 of file widget.cpp.

References x_, and y_.

twidget * gui2::twidget::parent ( )
void gui2::twidget::place ( const tpoint origin,
const tpoint size 
)
virtual
void gui2::twidget::populate_dirty_list ( twindow caller,
std::vector< twidget * > &  call_stack 
)

Adds a widget to the dirty list if it is dirty.

See twindow::dirty_list_ for more information regarding the dirty list.

If the widget is not dirty and has children it should add itself to the call_stack and call child_populate_dirty_list with the new call_stack.

Parameters
callerThe parent window, if dirty it should register itself to this window.
call_stackThe call-stack of widgets traversed to reach this function.

Definition at line 386 of file widget.cpp.

References gui2::twindow::add_to_dirty_list(), child_populate_dirty_list(), get_drawing_action(), is_dirty_, gui2::twidget::tredraw_action::none, gui2::twidget::tvisible::visible, and visible_.

Referenced by gui2::tviewport::child_populate_dirty_list(), gui2::tcontainer_::child_populate_dirty_list(), gui2::tmatrix::child_populate_dirty_list(), gui2::tlistbox::child_populate_dirty_list(), gui2::tgrid::child_populate_dirty_list(), gui2::tscrollbar_container::child_populate_dirty_list(), gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::child_populate_dirty_list(), gui2::twindow::draw(), and gui2::ttree_view_node::impl_populate_dirty_list().

bool gui2::twidget::recursive_is_visible ( const twidget widget,
const bool  must_be_active 
) const
private

Is the widget and every single one of its parents visible?

Parameters
widgetWidget where to start the check.
must_be_activeThe widget should be active, not all widgets have an active flag, those who don't ignore flag.
Returns
Status.

Definition at line 579 of file widget.cpp.

References gui2::twidget::tvisible::hidden, gui2::twidget::tvisible::invisible, parent_, and visible_.

Referenced by is_at().

void gui2::twidget::request_reduce_height ( const unsigned  maximum_height)
virtual

Tries to reduce the height of a widget.

This function tries to do it 'friendly' and only use scrollbars.

Todo:
Make pure virtual.

See Layout algorithm for more information.

Parameters
maximum_heightThe wanted maximum height.

Reimplemented in gui2::policy::placement::tindependent, gui2::policy::placement::tmatrix, gui2::policy::placement::tvertical_list, gui2::tgenerator_, gui2::tgrid, gui2::policy::placement::thorizontal_list, gui2::tscrollbar_container, and gui2::tcontainer_.

Definition at line 178 of file widget.cpp.

Referenced by gui2::tgrid_implementation::cell_request_reduce_height().

virtual void gui2::twidget::request_reduce_width ( const unsigned  maximum_width)
pure virtual

Tries to reduce the width of a widget.

This function tries to do it 'friendly' and only use scrollbars or tries to wrap the widget.

See Layout algorithm for more information.

Parameters
maximum_widthThe wanted maximum width.

Implemented in gui2::policy::placement::tindependent, gui2::policy::placement::tmatrix, gui2::policy::placement::tvertical_list, gui2::tgenerator_, gui2::ttree_view_node, gui2::tgrid, gui2::policy::placement::thorizontal_list, gui2::tcontrol, gui2::tmatrix, gui2::tscrollbar_container, gui2::tpane, gui2::tcontainer_, and gui2::tviewport.

Referenced by gui2::tgrid_implementation::cell_request_reduce_width().

void gui2::twidget::set_debug_border_colour ( const unsigned  debug_border_colour)

Definition at line 489 of file widget.cpp.

References debug_border_colour_.

Referenced by gui2::implementation::tbuilder_control::init_control().

void gui2::twidget::set_debug_border_mode ( const unsigned  debug_border_mode)

Definition at line 484 of file widget.cpp.

References debug_border_mode_.

Referenced by gui2::implementation::tbuilder_control::init_control().

void gui2::twidget::set_id ( const std::string id)
void gui2::twidget::set_is_dirty ( const bool  is_dirty)

Definition at line 435 of file widget.cpp.

References is_dirty_.

Referenced by gui2::event::thandler::disconnect(), gui2::event::thandler::draw(), gui2::ttext_box::handle_mouse_selection(), gui2::tviewport::impl_draw_children(), gui2::tgrid::impl_draw_children(), gui2::ttext_::insert_char(), lua_gui2::intf_set_dialog_canvas(), gui2::tlistbox::layout_children(), gui2::tlistbox::order_by(), gui2::ttext_::paste_selection(), place(), gui2::tpassword_box::post_function(), gui2::ttree_view::resize_content(), gui2::tlistbox::resize_content(), gui2::tscrollbar_container::scrollbar_moved(), gui2::tcontainer_::set_active(), gui2::tslider::set_best_slider_length(), gui2::tgrid::set_column_grow_factor(), gui2::ttext_::set_cursor(), gui2::tcontrol::set_label(), gui2::tlabel::set_link_aware(), gui2::tlabel::set_link_color(), gui2::tminimap::set_map_data(), gui2::ttext_::set_maximum_length(), gui2::tprogress_bar::set_percentage(), gui2::tgrid::set_row_grow_factor(), gui2::tlistbox::set_row_shown(), gui2::tcombobox::set_selected(), gui2::ttext_::set_selection_length(), gui2::ttext_::set_selection_start(), set_size(), gui2::tbutton::set_state(), gui2::tlabel::set_state(), gui2::trepeating_button::set_state(), gui2::ttoggle_button::set_state(), gui2::tcombobox::set_state(), gui2::ttoggle_panel::set_state(), gui2::tscrollbar_::set_state(), gui2::ttext_::set_state(), gui2::tcontrol::set_text_alignment(), gui2::tcontrol::set_use_markup(), gui2::ttoggle_button::set_value(), gui2::ttext_::set_value(), gui2::ttoggle_panel::set_value(), gui2::tcombobox::set_values(), gui2::twindow::set_variable(), set_visible(), gui2::ttoggle_button::update_canvas(), gui2::tscrollbar_::update_canvas(), gui2::tlistbox::update_content_size(), and gui2::tdebug_clock::update_time().

void gui2::twidget::set_layout_size ( const tpoint size)
protected
void gui2::twidget::set_linked_group ( const std::string linked_group)
void gui2::twidget::set_origin ( const tpoint origin)
virtual

Sets the origin of the widget.

This function can be used to move the widget without dirtying it. The location is an absolute position, if a relative more is required use move.

Parameters
originThe new origin.

Reimplemented in gui2::policy::placement::tindependent, gui2::policy::placement::tmatrix, gui2::policy::placement::tvertical_list, gui2::ttree_view_node, gui2::tgenerator_, gui2::tgrid, gui2::policy::placement::thorizontal_list, gui2::tscrollbar_container, and gui2::tcontainer_.

Definition at line 216 of file widget.cpp.

References gui2::tpoint::x, x_, gui2::tpoint::y, and y_.

Referenced by gui2::tcontainer_::set_origin(), gui2::tgrid::set_origin(), gui2::ttree_view_node::set_origin(), and gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::set_origin().

void gui2::twidget::set_parent ( twidget parent)
void gui2::twidget::set_size ( const tpoint size)
virtual

Sets the size of the widget.

This version is meant to resize a widget, since the origin isn't modified. This can be used if a widget needs to change its size and the layout will be fixed later.

Parameters
sizeThe size of the widget.

Definition at line 222 of file widget.cpp.

References height_, set_is_dirty(), width_, gui2::tpoint::x, and gui2::tpoint::y.

Referenced by gui2::ttree_view_node::place(), gui2::ttree_view::resize_content(), and gui2::tlistbox::resize_content().

void gui2::twidget::set_visible ( const tvisible::scoped_enum  visible)
void gui2::twidget::set_visible_rectangle ( const SDL_Rect &  rectangle)
virtual

Friends And Related Function Documentation

friend class tdebug_layout_graph
friend

Definition at line 53 of file widget.hpp.

friend class twindow
friend

Definition at line 54 of file widget.hpp.

Member Data Documentation

SDL_Rect gui2::twidget::clipping_rectangle_
private

The clipping rectangle if a widget is partly visible.

Definition at line 710 of file widget.hpp.

Referenced by calculate_clipping_rectangle(), draw_debug_border(), get_dirty_rectangle(), and set_visible_rectangle().

unsigned gui2::twidget::debug_border_colour_
private

The colour for the debug border.

Definition at line 728 of file widget.hpp.

Referenced by draw_debug_border(), and set_debug_border_colour().

unsigned gui2::twidget::debug_border_mode_
private

Mode for drawing the debug border.

The debug border is a helper border to determine where a widget is placed. It is only intended for debugging purposes.

Possible values:

  • 0 no border
  • 1 single pixel border
  • 2 flood-filled rectangle

Definition at line 725 of file widget.hpp.

Referenced by draw_debug_border(), and set_debug_border_mode().

unsigned gui2::twidget::height_
private

The height of the widget.

Definition at line 470 of file widget.hpp.

Referenced by get_drawing_action(), get_height(), get_size(), is_at(), place(), and set_size().

std::string gui2::twidget::id_
private

The id is the unique name of the widget in a certain context.

This is needed for certain widgets so the engine knows which widget is which. E.g. it knows which button is pressed and thus which engine action is connected to the button. This doesn't mean that the id is unique in a window, e.g. a listbox can have the same id for every row.

Definition at line 183 of file widget.hpp.

Referenced by find(), id(), set_id(), and ~twidget().

bool gui2::twidget::is_dirty_
private

Is the widget dirty?

When a widget is dirty it needs to be redrawn at the next drawing cycle.

The top-level window will use populate_dirty_list and child_populate_dirty_list to find al dirty widgets, so the widget doesn't need to inform its parent regarding it being marked dirty.

Definition at line 701 of file widget.hpp.

Referenced by get_is_dirty(), populate_dirty_list(), and set_is_dirty().

tpoint gui2::twidget::layout_size_
private

The best size for the widget.

When 0,0 the real best size is returned, but in the layout phase a wrapping or a scrollbar might change the best size for that widget. This variable holds that best value.

Definition at line 479 of file widget.hpp.

Referenced by get_best_size(), layout_initialise(), layout_size(), and set_layout_size().

std::string gui2::twidget::linked_group_
private

The linked group the widget belongs to.

Todo:
For now the linked group is initialised when the layout of the widget is initialised. The best time to set it would be upon adding the widget in the window. Need to look whether it is possible in a clean way. Maybe a signal just prior to showing a window where the widget can do some of it's on things, would also be nice for widgets that need a finaliser function.

Definition at line 503 of file widget.hpp.

Referenced by get_best_size(), layout_initialise(), set_linked_group(), and ~twidget().

twidget* gui2::twidget::parent_
private

The parent widget.

If the widget has a parent it contains a pointer to the parent, else it is set to nullptr.

Definition at line 230 of file widget.hpp.

Referenced by get_window(), parent(), recursive_is_visible(), and set_parent().

tredraw_action::scoped_enum gui2::twidget::redraw_action_
private

Field for the action to do on a drawing request.

Definition at line 707 of file widget.hpp.

Referenced by draw_background(), draw_children(), draw_debug_border(), draw_foreground(), get_dirty_rectangle(), get_drawing_action(), and set_visible_rectangle().

tvisible::scoped_enum gui2::twidget::visible_
private
unsigned gui2::twidget::width_
private

The width of the widget.

Definition at line 467 of file widget.hpp.

Referenced by get_drawing_action(), get_size(), get_width(), is_at(), place(), and set_size().

int gui2::twidget::x_
private

The x-coordinate of the widget on the screen.

Definition at line 461 of file widget.hpp.

Referenced by get_origin(), get_x(), is_at(), move(), place(), and set_origin().

int gui2::twidget::y_
private

The y-coordinate of the widget on the screen.

Definition at line 464 of file widget.hpp.

Referenced by get_origin(), get_y(), is_at(), move(), place(), and set_origin().


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