Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

button_generic.cpp

Go to the documentation of this file.
00001 /*
00002         ClanGUI, copyrights by various people. Have a look in the CREDITS file.
00003         
00004         This sourcecode is distributed using the Library GNU Public Licence,
00005         version 2 or (at your option) any later version. Please read LICENSE
00006         for details.
00007 */
00008 
00009 #include "precomp.h"
00010 #include "button_generic.h"
00011 #include "API/GUI/component_options.h"
00012 #include "API/Display/Display/surface.h"
00013 
00014 CL_ComponentOptions CL_Button_Generic::create_options(
00015         const CL_Rect &pos,
00016         const std::string &text,
00017         bool toggle_mode)
00018 {
00019         CL_ComponentOptions options;
00020 
00021         options.add_option_as_int("x", pos.x1);
00022         options.add_option_as_int("y", pos.y1);
00023         options.add_option_as_int("width", pos.get_width());
00024         options.add_option_as_int("height", pos.get_height());
00025         options.add_option("text", text);
00026         options.add_option_as_bool("togglemode", toggle_mode);
00027 
00028         return options;
00029 }
00030 
00031 CL_Button_Generic::CL_Button_Generic(CL_Button *self, const CL_ComponentOptions &options, CL_StyleManager *style)
00032 :
00033         button(self),
00034         toggled(false),
00035         toggle_mode(false),
00036         captured(false),
00037         outside(false),
00038         surface_up(NULL),
00039         surface_down(NULL),
00040         surface_highlighted(NULL),
00041         surface_disabled(NULL)
00042 {
00043         if(options.exists("text"))
00044                 text = options.get_value("text");
00045 
00046         if(options.exists("toggled"))
00047                 toggled = options.get_value_as_bool("toggled");
00048 
00049         if(options.exists("sticky"))
00050                 toggle_mode = options.get_value_as_bool("togglemode");
00051 
00052         slot_key_down = self->sig_key_down().connect(CL_CreateSlot(this, &CL_Button_Generic::on_key_down));
00053         slot_key_up = self->sig_key_up().connect(CL_CreateSlot(this, &CL_Button_Generic::on_key_up));
00054         slot_mouse_move = self->sig_mouse_moved().connect(CL_CreateSlot(this, &CL_Button_Generic::on_mouse_move));
00055 }
00056 
00057 void CL_Button_Generic::on_key_down(CL_Component *comp, CL_InputDevice *device, CL_Key key)
00058 {
00059         toggled = !toggled;
00060 
00061         sig_pressed();
00062         sig_toggled(toggled);
00063         
00064         button->capture_mouse();
00065         captured = true;
00066         outside = false;
00067 }
00068 
00069 void CL_Button_Generic::on_key_up(CL_Component *comp, CL_InputDevice *device, CL_Key key)
00070 {
00071         if (outside == false)
00072         {
00073                 sig_released();
00074 
00075                 if(toggle_mode == false)
00076                 {
00077                         toggled = !toggled;
00078                         sig_toggled(toggled);
00079                 }
00080                 
00081                 sig_clicked();
00082         }
00083                 
00084         button->release_mouse();
00085         captured = false;
00086 }
00087 
00088 void CL_Button_Generic::on_mouse_move(CL_Component *comp, CL_InputDevice *device, int x, int y)
00089 {
00090         if(captured)
00091         {
00092                 bool check_outside = x < 0 || x >= button->get_width() || y < 0 || y >= button->get_height();
00093 
00094                 if(check_outside != outside)
00095                 {
00096                         outside = !outside;
00097                         toggled = !toggled;
00098                 }
00099         }
00100 }

Generated at Wed Apr 4 19:53:59 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001