gui2::tcontrol Class Reference

Base class for all visible items. More...

#include <control.hpp>

Inheritance diagram for gui2::tcontrol:

Inheritance graph
[legend]
Collaboration diagram for gui2::tcontrol:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 tcontrol (const unsigned canvas_count)
virtual ~tcontrol ()
void mouse_hover (tevent_handler &event)
 Inherted from twidget.
void help_key (tevent_handler &event)
 Inherted from twidget.
void set_size (const SDL_Rect &rect)
 Inherited from twidget.
twidgetfind_widget (const tpoint &coordinate, const bool must_be_active)
 Inherited from twidget.
const twidgetfind_widget (const tpoint &coordinate, const bool must_be_active) const
 Inherited from twidget.
twidgetfind_widget (const std::string &id, const bool must_be_active)
 Inherited from twidget.
const twidgetfind_widget (const std::string &id, const bool must_be_active) const
 Inherited from twidget.
void set_visible (const bool visible=true)
bool get_visible () const
void set_multiline_label (const bool multiline=true)
void set_label (const t_string &label)
const t_stringlabel () const
void set_tooltip (const t_string &tooltip)
const t_stringtooltip () const
void set_help_message (const t_string &help_message)
const t_stringhelp_message () const
std::vector< tcanvas > & canvas ()
tcanvascanvas (const unsigned index)
void set_definition (const std::string &definition)
 Inherited from twidget.
void draw (surface &surface)
 Inherited from twidget.
virtual void set_active (const bool active)=0
 Sets the control in the active state, when inactive a control can't be used and doesn't react to events.
virtual bool get_active () const =0
 Gets the active state of the control.
tpoint get_minimum_size () const
 Gets the minimum size for the object, 0,0 means no size required.
tpoint get_best_size () const
 Gets the best size for the object, 0,0 means no size required.
tpoint get_maximum_size () const
 Gets the best size for an object, 0,0 means no limits.
void load_config ()
 Inherited from twidget.

Protected Member Functions

virtual unsigned get_state () const =0
 Returns the id of the state, which is also the index for the canvas.
virtual bool full_redraw () const
 Does the widget need to restore the surface before (re)painting?
virtual void set_canvas_text ()
 Sets the text variable for the canvases.
tresolution_definition_config ()
const tresolution_definition_config () const
void set_config (tresolution_definition_ *config)

Private Member Functions

 tcontrol ()
tpoint get_single_line_best_size (const tpoint &config_size) const
 Helpers.
tpoint get_multi_line_best_size (const tpoint &config_size) const
void save_background (const surface &src)
 Saves the portion of the background.
void restore_background (surface &dst)
 Restores a portion of the background.
virtual void load_config_extra ()
 Once the config is loaded this function is called.
virtual const std::string & get_control_type () const =0
 The control_type parameter for tgui_definition::get_control() To keep the code more generic this type is required so the controls need to return the proper string here.

Private Attributes

bool visible_
 Visible state of the control, invisible isn't drawn.
bool multiline_label_
 Can the label contain multiple lines.
std::string wrapped_label_
 If multiline we need to have a version of the label wrapped to fit in the widget.
t_string label_
 The label associated with a lot of widgets to show a (non editable) text.
t_string tooltip_
 When hovering a tooltip with extra information can show up.
t_string help_message_
 When the user presses help a tooltip with even more info can be shown.
std::vector< tcanvascanvas_
 Holds all canvas objects for a control.
surface restorer_
 Holds a copy of the original background which can be used before redrawing.
tresolution_definition_config_
 Contains a pointer to the configuration of this button at the current resolution.


Detailed Description

Base class for all visible items.

Definition at line 28 of file control.hpp.


Constructor & Destructor Documentation

gui2::tcontrol::tcontrol (  )  [private]

gui2::tcontrol::tcontrol ( const unsigned  canvas_count  ) 

Definition at line 48 of file control.cpp.

virtual gui2::tcontrol::~tcontrol (  )  [inline, virtual]

Definition at line 35 of file control.hpp.


Member Function Documentation

void gui2::tcontrol::mouse_hover ( tevent_handler event  )  [virtual]

Inherted from twidget.

Reimplemented from gui2::tevent_executor.

Definition at line 61 of file control.cpp.

References DBG_G_E, gui2::settings::popup_show_time, and tooltip_.

void gui2::tcontrol::help_key ( tevent_handler event  )  [virtual]

Inherted from twidget.

Reimplemented from gui2::tevent_executor.

Definition at line 67 of file control.cpp.

References DBG_G_E, help_message_, and gui2::settings::help_show_time.

void gui2::tcontrol::set_size ( const SDL_Rect &  rect  )  [virtual]

twidget* gui2::tcontrol::find_widget ( const tpoint coordinate,
const bool  must_be_active 
) [inline, virtual]

Inherited from twidget.

Reimplemented from gui2::twidget.

Reimplemented in gui2::tcontainer_, gui2::tlistbox, gui2::tpanel, and gui2::twindow.

Definition at line 47 of file control.hpp.

References gui2::twidget::find_widget(), and get_active().

Referenced by gui2::tcontainer_::find_widget().

const twidget* gui2::tcontrol::find_widget ( const tpoint coordinate,
const bool  must_be_active 
) const [inline, virtual]

Inherited from twidget.

Reimplemented from gui2::twidget.

Reimplemented in gui2::tcontainer_, gui2::tlistbox, gui2::tpanel, and gui2::twindow.

Definition at line 54 of file control.hpp.

References gui2::twidget::find_widget(), and get_active().

twidget* gui2::tcontrol::find_widget ( const std::string &  id,
const bool  must_be_active 
) [inline, virtual]

Inherited from twidget.

Reimplemented from gui2::twidget.

Reimplemented in gui2::tcontainer_, gui2::tpanel, and gui2::twindow.

Definition at line 62 of file control.hpp.

References gui2::twidget::find_widget(), and get_active().

const twidget* gui2::tcontrol::find_widget ( const std::string &  id,
const bool  must_be_active 
) const [inline, virtual]

Inherited from twidget.

Reimplemented from gui2::twidget.

Reimplemented in gui2::tcontainer_, gui2::tpanel, and gui2::twindow.

Definition at line 69 of file control.hpp.

References gui2::twidget::find_widget(), and get_active().

void gui2::tcontrol::set_visible ( const bool  visible = true  )  [inline]

bool gui2::tcontrol::get_visible (  )  const [inline]

Definition at line 78 of file control.hpp.

References visible_.

void gui2::tcontrol::set_multiline_label ( const bool  multiline = true  )  [inline]

Definition at line 80 of file control.hpp.

References multiline_label_, and gui2::twidget::set_dirty().

Referenced by gui2::ttooltip::ttooltip().

void gui2::tcontrol::set_label ( const t_string label  ) 

const t_string& gui2::tcontrol::label (  )  const [inline]

Definition at line 85 of file control.hpp.

References label_.

void gui2::tcontrol::set_tooltip ( const t_string tooltip  )  [inline]

const t_string& gui2::tcontrol::tooltip (  )  const [inline]

Definition at line 90 of file control.hpp.

References tooltip_.

void gui2::tcontrol::set_help_message ( const t_string help_message  )  [inline]

Definition at line 93 of file control.hpp.

References help_message_.

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

const t_string& gui2::tcontrol::help_message (  )  const [inline]

Definition at line 94 of file control.hpp.

References help_message_.

std::vector<tcanvas>& gui2::tcontrol::canvas (  )  [inline]

tcanvas& gui2::tcontrol::canvas ( const unsigned  index  )  [inline]

Definition at line 97 of file control.hpp.

References canvas_.

void gui2::tcontrol::set_definition ( const std::string &  definition  )  [virtual]

Inherited from twidget.

This function sets the defintion of a control and should be called soon after creating the object since a lot of internal functions depend on the definition.

This function should be called one time only!!!

Reimplemented from gui2::twidget.

Definition at line 226 of file control.cpp.

References config(), load_config(), and gui2::twidget::set_definition().

Referenced by gui2::tbuilder_control::init_control(), and gui2::twindow::twindow().

void gui2::tcontrol::draw ( surface surface  )  [virtual]

virtual void gui2::tcontrol::set_active ( const bool  active  )  [pure virtual]

Sets the control in the active state, when inactive a control can't be used and doesn't react to events.

(Note read-only for a ttext_ is a different state.)

Implemented in gui2::tbutton, gui2::tlabel, gui2::tlistbox, gui2::tpanel, gui2::tscrollbar_, gui2::tspacer, gui2::ttext_, gui2::ttoggle_button, gui2::ttooltip, and gui2::twindow.

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

virtual bool gui2::tcontrol::get_active (  )  const [pure virtual]

tpoint gui2::tcontrol::get_minimum_size (  )  const [virtual]

Gets the minimum size for the object, 0,0 means no size required.

Implements gui2::twidget.

Reimplemented in gui2::tcontainer_.

Definition at line 100 of file control.cpp.

References config_, t_string::empty(), get_multi_line_best_size(), get_single_line_best_size(), label_, gui2::tresolution_definition_::min_height, gui2::tresolution_definition_::min_width, and multiline_label_.

tpoint gui2::tcontrol::get_best_size (  )  const [virtual]

tpoint gui2::tcontrol::get_maximum_size (  )  const [virtual]

Gets the best size for an object, 0,0 means no limits.

Implements gui2::twidget.

Definition at line 132 of file control.cpp.

References config_, gui2::tresolution_definition_::max_height, and gui2::tresolution_definition_::max_width.

void gui2::tcontrol::load_config (  )  [virtual]

Inherited from twidget.

This function shouldn't be called directly it's called by set_definition().

All classes which use this class as base should call this function in their constructor. Abstract classes shouldn't call this routine. The classes which call this routine should also define get_control_type().

Reimplemented from gui2::twidget.

Definition at line 300 of file control.cpp.

References canvas(), config(), gui2::twidget::definition(), gui2::get_control(), get_control_type(), load_config_extra(), set_canvas_text(), set_config(), size, and gui2::tresolution_definition_::state.

Referenced by set_definition(), and gui2::twindow::twindow().

tpoint gui2::tcontrol::get_single_line_best_size ( const tpoint config_size  )  const [private]

tpoint gui2::tcontrol::get_multi_line_best_size ( const tpoint config_size  )  const [private]

virtual unsigned gui2::tcontrol::get_state (  )  const [protected, pure virtual]

Returns the id of the state, which is also the index for the canvas.

Implemented in gui2::tbutton, gui2::tlabel, gui2::tlistbox, gui2::tpanel, gui2::tscrollbar_, gui2::tspacer, gui2::ttext_, gui2::ttoggle_button, gui2::ttooltip, and gui2::twindow.

Referenced by draw(), and full_redraw().

bool gui2::tcontrol::full_redraw (  )  const [protected, virtual]

Does the widget need to restore the surface before (re)painting?

Reimplemented in gui2::twindow.

Definition at line 211 of file control.cpp.

References config(), get_state(), and gui2::tresolution_definition_::state.

Referenced by draw().

void gui2::tcontrol::set_canvas_text (  )  [protected, virtual]

Sets the text variable for the canvases.

Reimplemented in gui2::ttext_box.

Definition at line 218 of file control.cpp.

References canvas(), canvas_, label_, and gui2::tcanvas::set_variable().

Referenced by load_config(), gui2::ttext_::paste_selection(), gui2::ttext_::set_cursor(), set_label(), and gui2::ttext_::set_text().

tresolution_definition_* gui2::tcontrol::config (  )  [inline, protected]

const tresolution_definition_* gui2::tcontrol::config (  )  const [inline, protected]

Definition at line 153 of file control.hpp.

References config_.

void gui2::tcontrol::set_config ( tresolution_definition_ config  )  [inline, protected]

Definition at line 155 of file control.hpp.

References config_.

Referenced by load_config().

void gui2::tcontrol::save_background ( const surface src  )  [private]

Saves the portion of the background.

We expect an empty restorer and copy the part in get_rect() to the new surface. We copy the data since we want to put it back 1:1 and not a blit so can't use get_surface_portion.

Parameters:
src background to save.

Definition at line 278 of file control.cpp.

References gui2::twidget::get_rect(), restorer_, and gui2::save_background().

Referenced by draw().

void gui2::tcontrol::restore_background ( surface dst  )  [private]

Restores a portion of the background.

See save_background for more info.

Parameters:
dst Background to restore.

Definition at line 290 of file control.cpp.

References gui2::twidget::get_rect(), gui2::restore_background(), and restorer_.

Referenced by draw().

virtual void gui2::tcontrol::load_config_extra (  )  [inline, private, virtual]

Once the config is loaded this function is called.

Reimplemented in gui2::tscrollbar_, and gui2::ttext_box.

Definition at line 198 of file control.hpp.

Referenced by load_config().

virtual const std::string& gui2::tcontrol::get_control_type (  )  const [private, pure virtual]

The control_type parameter for tgui_definition::get_control() To keep the code more generic this type is required so the controls need to return the proper string here.

Might be used at other parts as well the get the type of control involved.

Implemented in gui2::tbutton, gui2::tlabel, gui2::tlistbox, gui2::tpanel, gui2::tspacer, gui2::ttext_box, gui2::ttoggle_button, gui2::ttooltip, gui2::tvertical_scrollbar, and gui2::twindow.

Referenced by load_config().


Member Data Documentation

bool gui2::tcontrol::visible_ [private]

Visible state of the control, invisible isn't drawn.

Definition at line 160 of file control.hpp.

Referenced by draw(), get_visible(), and set_visible().

Can the label contain multiple lines.

Definition at line 163 of file control.hpp.

Referenced by draw(), get_best_size(), get_minimum_size(), and set_multiline_label().

std::string gui2::tcontrol::wrapped_label_ [private]

If multiline we need to have a version of the label wrapped to fit in the widget.

This value is cached so changes to the label or widget size should clear us.

Definition at line 168 of file control.hpp.

Referenced by draw(), set_label(), and set_size().

The label associated with a lot of widgets to show a (non editable) text.

Definition at line 171 of file control.hpp.

Referenced by draw(), get_best_size(), get_minimum_size(), get_multi_line_best_size(), get_single_line_best_size(), label(), set_canvas_text(), and set_label().

When hovering a tooltip with extra information can show up.

Reimplemented in gui2::twindow.

Definition at line 174 of file control.hpp.

Referenced by mouse_hover(), set_tooltip(), and tooltip().

When the user presses help a tooltip with even more info can be shown.

Definition at line 177 of file control.hpp.

Referenced by help_key(), help_message(), and set_help_message().

std::vector<tcanvas> gui2::tcontrol::canvas_ [private]

Holds all canvas objects for a control.

Definition at line 180 of file control.hpp.

Referenced by canvas(), set_canvas_text(), and set_size().

Holds a copy of the original background which can be used before redrawing.

This is needed for semi-tranparent items, the user defines whether it's required or not.

Definition at line 185 of file control.hpp.

Referenced by draw(), restore_background(), and save_background().

Contains a pointer to the configuration of this button at the current resolution.

Definition at line 195 of file control.hpp.

Referenced by config(), draw(), get_best_size(), get_maximum_size(), get_minimum_size(), get_multi_line_best_size(), get_single_line_best_size(), and set_config().


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

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs