toggle_button.cpp

Go to the documentation of this file.
00001 /* $Id: toggle_button.cpp 26515 2008-05-10 12:40:14Z 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 #include "gui/widgets/toggle_button.hpp"
00016 
00017 #include "log.hpp"
00018 
00019 #define DBG_G LOG_STREAM_INDENT(debug, gui)
00020 #define LOG_G LOG_STREAM_INDENT(info, gui)
00021 #define WRN_G LOG_STREAM_INDENT(warn, gui)
00022 #define ERR_G LOG_STREAM_INDENT(err, gui)
00023 
00024 #define DBG_G_D LOG_STREAM_INDENT(debug, gui_draw)
00025 #define LOG_G_D LOG_STREAM_INDENT(info, gui_draw)
00026 #define WRN_G_D LOG_STREAM_INDENT(warn, gui_draw)
00027 #define ERR_G_D LOG_STREAM_INDENT(err, gui_draw)
00028 
00029 #define DBG_G_E LOG_STREAM_INDENT(debug, gui_event)
00030 #define LOG_G_E LOG_STREAM_INDENT(info, gui_event)
00031 #define WRN_G_E LOG_STREAM_INDENT(warn, gui_event)
00032 #define ERR_G_E LOG_STREAM_INDENT(err, gui_event)
00033 
00034 #define DBG_G_P LOG_STREAM_INDENT(debug, gui_parse)
00035 #define LOG_G_P LOG_STREAM_INDENT(info, gui_parse)
00036 #define WRN_G_P LOG_STREAM_INDENT(warn, gui_parse)
00037 #define ERR_G_P LOG_STREAM_INDENT(err, gui_parse)
00038 
00039 namespace gui2 {
00040 
00041 
00042 void ttoggle_button::mouse_enter(tevent_handler&) 
00043 { 
00044     DBG_G_E << "Toggle button: mouse enter.\n"; 
00045 
00046     if(is_selected()) {
00047         set_state(FOCUSSED_SELECTED);
00048     } else {
00049         set_state(FOCUSSED);
00050     }
00051 }
00052 
00053 void ttoggle_button::mouse_leave(tevent_handler&) 
00054 { 
00055     DBG_G_E << "Toggle button: mouse leave.\n"; 
00056 
00057     if(is_selected()) {
00058         set_state(ENABLED_SELECTED);
00059     } else {
00060         set_state(ENABLED);
00061     }
00062 }
00063 
00064 void ttoggle_button::mouse_left_button_click(tevent_handler&) 
00065 { 
00066     DBG_G_E << "Toggle button: left mouse button click.\n"; 
00067 
00068     if(is_selected()) {
00069         set_state(ENABLED);
00070     } else {
00071         set_state(ENABLED_SELECTED);
00072     }
00073 
00074     if(callback_mouse_left_click_) {
00075         callback_mouse_left_click_(this);
00076     }
00077 }
00078 
00079 void ttoggle_button::set_active(const bool active)
00080 {
00081     if(active) {
00082         if(is_selected()) {
00083             set_state(ENABLED_SELECTED);
00084         } else {
00085             set_state(ENABLED);
00086         }
00087     } else {
00088         if(is_selected()) {
00089             set_state(DISABLED_SELECTED);
00090         } else {
00091             set_state(DISABLED);
00092         }
00093     }
00094 }
00095 
00096 void ttoggle_button::set_selected(const bool selected)
00097 {
00098     if(selected == is_selected()) {
00099         return;
00100     }
00101 
00102     if(selected) {
00103         set_state(static_cast<tstate>(state_ + ENABLED_SELECTED));
00104     } else {
00105         set_state(static_cast<tstate>(state_ - ENABLED_SELECTED));
00106     }
00107 }
00108 
00109 void ttoggle_button::set_state(tstate state)
00110 {
00111     if(state != state_) {
00112         state_ = state;
00113         set_dirty(true);
00114     }
00115 }
00116 
00117 } // namespace gui2
00118 

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