toggle_button.hpp

Go to the documentation of this file.
00001 /* $Id: toggle_button.hpp 26662 2008-05-17 07:18:31Z mordante $ */
00002 /*
00003    copyright (C) 2008 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 version 2
00008    or at your option any later version.
00009    this program is distributed in the hope that it will be useful,
00010    but without any warranty.
00011 
00012    see the copying file for more details.
00013 */
00014 
00015 #ifndef __GUI_WIDGETS_TOGGLE_BUTTON_HPP_INCLUDED__
00016 #define __GUI_WIDGETS_TOGGLE_BUTTON_HPP_INCLUDED__
00017 
00018 #include "gui/widgets/control.hpp"
00019 
00020 namespace gui2 {
00021 
00022 // Class for a toggle button
00023 class ttoggle_button : public tcontrol, public tselectable_
00024 {
00025 public:
00026     ttoggle_button() : 
00027         tcontrol(COUNT),
00028         state_(ENABLED),
00029         callback_mouse_left_click_(0)
00030     {
00031     }
00032 
00033     void mouse_enter(tevent_handler&);
00034     void mouse_leave(tevent_handler&);
00035 
00036     void mouse_left_button_click(tevent_handler&);
00037 
00038     void set_active(const bool active);
00039     bool get_active() const
00040         { return state_ != DISABLED && state_ != DISABLED_SELECTED; }
00041     unsigned get_state() const { return state_; }
00042 
00043     /** Inherited from tselectable_ */
00044     bool is_selected() const { return state_ >= ENABLED_SELECTED; }
00045 
00046     /** Inherited from tselectable_ */
00047     void set_selected(const bool selected = true);
00048 
00049     void set_callback_mouse_left_click(void (*callback) (twidget*)) 
00050         { callback_mouse_left_click_ = callback; }
00051     
00052 private:
00053     //! Note the order of the states must be the same as defined in settings.hpp.
00054     //! Also note the internals do assume the order for up and down to be the same
00055     //! and also that 'up' is before 'down'.
00056     enum tstate { 
00057         ENABLED,          DISABLED,          FOCUSSED, 
00058         ENABLED_SELECTED, DISABLED_SELECTED, FOCUSSED_SELECTED, 
00059         COUNT};
00060 
00061     void set_state(tstate state);
00062     tstate state_;
00063  
00064     /** This callback is used when the control gets a left click. */
00065     void (*callback_mouse_left_click_) (twidget*);
00066 
00067     //! Inherited from tcontrol.
00068     const std::string& get_control_type() const 
00069         { static const std::string type = "toggle_button"; return type; }
00070 
00071 };
00072 
00073 
00074 } // namespace gui2
00075 
00076 #endif
00077 
00078 

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