gui/widgets/button.hpp

Go to the documentation of this file.
00001 /* $Id: 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_BUTTON_HPP_INCLUDED
00017 #define GUI_WIDGETS_BUTTON_HPP_INCLUDED
00018 
00019 #include "gui/widgets/control.hpp"
00020 #include "gui/widgets/clickable.hpp"
00021 
00022 namespace gui2 {
00023 
00024 /**
00025  * Simple push button.
00026  */
00027 class tbutton
00028     : public tcontrol
00029     , public tclickable_
00030 {
00031 public:
00032     tbutton();
00033 
00034     /***** ***** ***** ***** Inherited ***** ***** ***** *****/
00035 
00036     /** Inherited from tcontrol. */
00037     void set_active(const bool active)
00038         { if(get_active() != active) set_state(active ? ENABLED : DISABLED); };
00039 
00040     /** Inherited from tcontrol. */
00041     bool get_active() const { return state_ != DISABLED; }
00042 
00043     /** Inherited from tcontrol. */
00044     unsigned get_state() const { return state_; }
00045 
00046     /** Inherited from tclickable. */
00047     void connect_click_handler(const event::tsignal_function& signal)
00048     {
00049         connect_signal_mouse_left_click(*this, signal);
00050     }
00051 
00052     /** Inherited from tclickable. */
00053     void disconnect_click_handler(const event::tsignal_function& signal)
00054     {
00055         disconnect_signal_mouse_left_click(*this, signal);
00056     }
00057 
00058     /***** ***** ***** setters / getters for members ***** ****** *****/
00059 
00060     void set_retval(const int retval) { retval_ = retval; }
00061 
00062 private:
00063     /**
00064      * Possible states of the widget.
00065      *
00066      * Note the order of the states must be the same as defined in settings.hpp.
00067      */
00068     enum tstate { ENABLED, DISABLED, PRESSED, FOCUSSED, COUNT };
00069 
00070     void set_state(const tstate state);
00071     /**
00072      * Current state of the widget.
00073      *
00074      * The state of the widget determines what to render and how the widget
00075      * reacts to certain 'events'.
00076      */
00077     tstate state_;
00078 
00079     /**
00080      * The return value of the button.
00081      *
00082      * If this value is not 0 and the button is clicked it sets the retval of
00083      * the window and the window closes itself.
00084      */
00085     int retval_;
00086 
00087     /** Inherited from tcontrol. */
00088     const std::string& get_control_type() const;
00089 
00090     /***** ***** ***** signal handlers ***** ****** *****/
00091 
00092     void signal_handler_mouse_enter(const event::tevent event, bool& handled);
00093 
00094     void signal_handler_mouse_leave(const event::tevent event, bool& handled);
00095 
00096     void signal_handler_left_button_down(
00097             const event::tevent event, bool& handled);
00098 
00099     void signal_handler_left_button_up(
00100             const event::tevent event, bool& handled);
00101 
00102     void signal_handler_left_button_click(
00103             const event::tevent event, bool& handled);
00104 };
00105 
00106 
00107 } // namespace gui2
00108 
00109 #endif
00110 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

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