00001 /* $Id: repeating_button.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */ 00002 /* 00003 Copyright (C) 2009 - 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_REPEATING_BUTTON_HPP_INCLUDED 00017 #define GUI_WIDGETS_REPEATING_BUTTON_HPP_INCLUDED 00018 00019 #include "gui/widgets/control.hpp" 00020 #include "gui/widgets/clickable.hpp" 00021 00022 namespace gui2 { 00023 00024 class trepeating_button 00025 : public tcontrol 00026 , public tclickable_ 00027 { 00028 public: 00029 trepeating_button(); 00030 ~trepeating_button(); 00031 00032 /** 00033 * Connects a signal handler for a left mouse button down. 00034 * 00035 * This event is triggered when the button is pressed and, as long as the 00036 * button stays down, every x ms afterwards. 00037 * 00038 * @param signal The signal to connect. 00039 */ 00040 void connect_signal_mouse_left_down(const event::tsignal_function& signal); 00041 00042 /** 00043 * Disconnects a signal handler for a left mouse button down. 00044 * 00045 * @param signal The signal to disconnect (should be the same 00046 * as send to the connect call. 00047 */ 00048 void disconnect_signal_mouse_left_down( 00049 const event::tsignal_function& signal); 00050 00051 /***** ***** ***** ***** Inherited ***** ***** ***** *****/ 00052 00053 /** Inherited from tcontrol. */ 00054 void set_active(const bool active) 00055 { if(get_active() != active) set_state(active ? ENABLED : DISABLED); }; 00056 00057 /** Inherited from tcontrol. */ 00058 bool get_active() const { return state_ != DISABLED; } 00059 00060 /** Inherited from tcontrol. */ 00061 unsigned get_state() const { return state_; } 00062 00063 /** Inherited from tclickable. */ 00064 void connect_click_handler(const event::tsignal_function& signal) 00065 { 00066 connect_signal_mouse_left_down(signal); 00067 } 00068 00069 /** Inherited from tclickable. */ 00070 void disconnect_click_handler(const event::tsignal_function& signal) 00071 { 00072 disconnect_signal_mouse_left_down(signal); 00073 } 00074 00075 private: 00076 /** 00077 * Possible states of the widget. 00078 * 00079 * Note the order of the states must be the same as defined in settings.hpp. 00080 */ 00081 enum tstate { ENABLED, DISABLED, PRESSED, FOCUSSED, COUNT }; 00082 00083 void set_state(const tstate state); 00084 /** 00085 * Current state of the widget. 00086 * 00087 * The state of the widget determines what to render and how the widget 00088 * reacts to certain 'events'. 00089 */ 00090 tstate state_; 00091 00092 /** The timer for the repeating events. */ 00093 unsigned long repeat_timer_; 00094 00095 /** Inherited from tcontrol. */ 00096 const std::string& get_control_type() const; 00097 00098 /***** ***** ***** signal handlers ***** ****** *****/ 00099 00100 void signal_handler_mouse_enter(const event::tevent event, bool& handled); 00101 00102 void signal_handler_mouse_leave(const event::tevent event, bool& handled); 00103 00104 void signal_handler_left_button_down( 00105 const event::tevent event, bool& handled); 00106 00107 void signal_handler_left_button_up( 00108 const event::tevent event, bool& handled); 00109 }; 00110 00111 00112 } // namespace gui2 00113 00114 #endif 00115
| Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:55 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |