gui/widgets/toggle_button.hpp

Go to the documentation of this file.
00001 /* $Id: toggle_button.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2008 - 2012 by Mark de Wever <koraq@xs4all.nl>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 #ifndef GUI_WIDGETS_TOGGLE_BUTTON_HPP_INCLUDED
00017 #define GUI_WIDGETS_TOGGLE_BUTTON_HPP_INCLUDED
00018 
00019 #include "gui/widgets/control.hpp"
00020 #include "gui/widgets/selectable.hpp"
00021 
00022 namespace gui2 {
00023 
00024 /**
00025  * Class for a toggle button.
00026  *
00027  * A toggle button is a button with two states 'up' and 'down' or 'selected' and
00028  * 'deselected'. When the mouse is pressed on it the state changes.
00029  */
00030 class ttoggle_button : public tcontrol, public tselectable_
00031 {
00032 public:
00033     ttoggle_button();
00034 
00035     /***** ***** ***** ***** Inherited ***** ***** ***** *****/
00036 
00037     /**
00038      * Inherited from tcontrol.
00039      *
00040      * Sets the additional member
00041      *  * icon_name_              icon
00042      */
00043     void set_members(const string_map& data);
00044 
00045     /** Inherited from tcontrol. */
00046     void set_active(const bool active);
00047 
00048     /** Inherited from tcontrol. */
00049     bool get_active() const
00050         { return state_ != DISABLED && state_ != DISABLED_SELECTED; }
00051 
00052     /** Inherited from tcontrol. */
00053     unsigned get_state() const { return state_; }
00054 
00055     /** Inherited from tcontrol. */
00056     void update_canvas();
00057 
00058     /** Inherited from tselectable_ */
00059     bool get_value() const { return state_ >= ENABLED_SELECTED; }
00060 
00061     /** Inherited from tselectable_ */
00062     void set_value(const bool selected);
00063 
00064     /***** ***** ***** setters / getters for members ***** ****** *****/
00065 
00066     void set_retval(const int retval);
00067 
00068     /** Inherited from tselectable_. */
00069     void set_callback_state_change(boost::function<void (twidget*)> callback)
00070         { callback_state_change_ = callback; }
00071 
00072     void set_icon_name(const std::string& icon_name)
00073         { icon_name_ = icon_name; update_canvas(); }
00074     const std::string& icon_name() const { return icon_name_; }
00075 
00076 private:
00077     /**
00078      * Possible states of the widget.
00079      *
00080      * Note the order of the states must be the same as defined in settings.hpp.
00081      * Also note the internals do assume the order for 'up' and 'down' to be the
00082      * same and also that 'up' is before 'down'. 'up' has no suffix, 'down' has
00083      * the SELECTED suffix.
00084      */
00085     enum tstate {
00086         ENABLED,          DISABLED,          FOCUSSED,
00087         ENABLED_SELECTED, DISABLED_SELECTED, FOCUSSED_SELECTED,
00088         COUNT};
00089 
00090     void set_state(const tstate state);
00091 
00092     /**
00093      * Current state of the widget.
00094      *
00095      * The state of the widget determines what to render and how the widget
00096      * reacts to certain 'events'.
00097      */
00098     tstate state_;
00099 
00100     /**
00101      * The return value of the button.
00102      *
00103      * If this value is not 0 and the button is double clicked it sets the
00104      * retval of the window and the window closes itself.
00105      */
00106     int retval_;
00107 
00108     /** See tselectable_::set_callback_state_change. */
00109     boost::function<void (twidget*)> callback_state_change_;
00110 
00111     /**
00112      * The toggle button can contain an icon next to the text.
00113      * Maybe this will move the the tcontrol class if deemed needed.
00114      */
00115     std::string icon_name_;
00116 
00117     /** Inherited from tcontrol. */
00118     const std::string& get_control_type() const;
00119 
00120     /***** ***** ***** signal handlers ***** ****** *****/
00121 
00122     void signal_handler_mouse_enter(const event::tevent event, bool& handled);
00123 
00124     void signal_handler_mouse_leave(const event::tevent event, bool& handled);
00125 
00126     void signal_handler_left_button_click(
00127             const event::tevent event, bool& handled);
00128 
00129     void signal_handler_left_button_double_click(
00130             const event::tevent event, bool& handled);
00131 };
00132 
00133 } // namespace gui2
00134 
00135 #endif
00136 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:56 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs