Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CEGUICheckbox.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002         filename:       CEGUICheckbox.cpp
00003         created:        13/4/2004
00004         author:         Paul D Turner
00005         
00006         purpose:        Implementation of Checkbox base class
00007 *************************************************************************/
00008 /*************************************************************************
00009     Crazy Eddie's GUI System (http://www.cegui.org.uk)
00010     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00011 
00012     This library is free software; you can redistribute it and/or
00013     modify it under the terms of the GNU Lesser General Public
00014     License as published by the Free Software Foundation; either
00015     version 2.1 of the License, or (at your option) any later version.
00016 
00017     This library is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020     Lesser General Public License for more details.
00021 
00022     You should have received a copy of the GNU Lesser General Public
00023     License along with this library; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 *************************************************************************/
00026 #include "elements/CEGUICheckbox.h"
00027 
00028 // Start of CEGUI namespace section
00029 namespace CEGUI
00030 {
00031 const String Checkbox::EventNamespace("Checkbox");
00032 
00033 /*************************************************************************
00034         Definitions for Properties
00035 *************************************************************************/
00036 CheckboxProperties::Selected    Checkbox::d_selectedProperty;
00037 
00038 
00039 /*************************************************************************
00040         Event name constants
00041 *************************************************************************/
00042 // generated internally by Window
00043 const String Checkbox::EventCheckStateChanged( (utf8*)"CheckStateChanged" );
00044 
00045 
00046 /*************************************************************************
00047         Constructor
00048 *************************************************************************/
00049 Checkbox::Checkbox(const String& type, const String& name) :
00050         ButtonBase(type, name),
00051         d_selected(false)
00052 {
00053         // add events for this widget
00054         addCheckboxEvents();
00055 
00056         addCheckboxProperties();
00057 }
00058 
00059 
00060 /*************************************************************************
00061         Destructor
00062 *************************************************************************/
00063 Checkbox::~Checkbox(void)
00064 {
00065 }
00066 
00067 
00068 /*************************************************************************
00069         set whether the check-box is selected or not    
00070 *************************************************************************/
00071 void Checkbox::setSelected(bool select)
00072 {
00073         if (select != d_selected)
00074         {
00075                 d_selected = select;
00076                 requestRedraw();
00077 
00078         WindowEventArgs args(this);
00079                 onSelectStateChange(args);
00080         }
00081 
00082 }
00083 
00084 
00085 /*************************************************************************
00086         event triggered internally when state of check-box changes      
00087 *************************************************************************/
00088 void Checkbox::onSelectStateChange(WindowEventArgs& e)
00089 {
00090         fireEvent(EventCheckStateChanged, e, EventNamespace);
00091 }
00092 
00093 
00094 /*************************************************************************
00095         Handler for mouse button up events
00096 *************************************************************************/
00097 void Checkbox::onMouseButtonUp(MouseEventArgs& e)
00098 {
00099         if ((e.button == LeftButton) && isPushed())
00100         {
00101                 Window* sheet = System::getSingleton().getGUISheet();
00102 
00103                 if (sheet != NULL)
00104                 {
00105                         // if mouse was released over this widget
00106                         if (this == sheet->getChildAtPosition(e.position))
00107                         {
00108                                 // toggle selected state
00109                                 setSelected(d_selected ^ true);
00110                         }
00111 
00112                 }
00113 
00114                 e.handled = true;
00115         }
00116 
00117         // default handling
00118         ButtonBase::onMouseButtonUp(e);
00119 }
00120 
00121 
00122 /*************************************************************************
00123         Add check-box specific events
00124 *************************************************************************/
00125 void Checkbox::addCheckboxEvents(void)
00126 {
00127         addEvent(EventCheckStateChanged);
00128 }
00129 
00130 /*************************************************************************
00131         Add properties
00132 *************************************************************************/
00133 void Checkbox::addCheckboxProperties(void)
00134 {
00135         addProperty(&d_selectedProperty);
00136 }
00137 
00138 
00139 
00140 } // End of  CEGUI namespace section

Generated on Wed Sep 7 09:56:30 2005 for Crazy Eddies GUI System by  doxygen 1.4.3