00001 /************************************************************************ 00002 filename: CEGUITabButton.cpp 00003 created: 8/8/2004 00004 author: Steve Streeting 00005 00006 purpose: Implementation of TabButton widget 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/CEGUITabButton.h" 00027 00028 // Start of CEGUI namespace section 00029 namespace CEGUI 00030 { 00031 const String TabButton::EventNamespace("TabButton"); 00032 00033 /************************************************************************* 00034 Event name constants 00035 *************************************************************************/ 00036 const String TabButton::EventClicked( (utf8*)"Clicked" ); 00037 00038 00039 /************************************************************************* 00040 Constructor 00041 *************************************************************************/ 00042 TabButton::TabButton(const String& type, const String& name) : 00043 ButtonBase(type, name), 00044 d_selected(false), 00045 d_rightOfSelected(true) 00046 { 00047 // add the additional events generated by this derived class 00048 addTabButtonEvents(); 00049 } 00050 00051 00052 /************************************************************************* 00053 Destructor 00054 *************************************************************************/ 00055 TabButton::~TabButton(void) 00056 { 00057 } 00058 00059 00060 /************************************************************************* 00061 Add button specific events 00062 *************************************************************************/ 00063 void TabButton::addTabButtonEvents(void) 00064 { 00065 addEvent(EventClicked); 00066 } 00067 00068 00069 /************************************************************************* 00070 handler invoked internally when the button is clicked. 00071 *************************************************************************/ 00072 void TabButton::onClicked(WindowEventArgs& e) 00073 { 00074 fireEvent(EventClicked, e, EventNamespace); 00075 } 00076 00077 00078 /************************************************************************* 00079 Handler for mouse button release events 00080 *************************************************************************/ 00081 void TabButton::onMouseButtonUp(MouseEventArgs& e) 00082 { 00083 if ((e.button == LeftButton) && isPushed()) 00084 { 00085 Window* sheet = System::getSingleton().getGUISheet(); 00086 00087 if (sheet != NULL) 00088 { 00089 // if mouse was released over this widget 00090 if (this == sheet->getChildAtPosition(e.position)) 00091 { 00092 // fire event 00093 WindowEventArgs args(this); 00094 onClicked(args); 00095 } 00096 00097 } 00098 00099 e.handled = true; 00100 } 00101 00102 // default handling 00103 ButtonBase::onMouseButtonUp(e); 00104 } 00105 /************************************************************************* 00106 Draw method 00107 *************************************************************************/ 00108 void TabButton::drawSelf(float z) 00109 { 00110 if (isHovering()) 00111 { 00112 drawHover(z); 00113 } 00114 else if (d_selected) 00115 { 00116 drawPushed(z); 00117 } 00118 else 00119 { 00120 drawNormal(z); 00121 } 00122 } 00123 /************************************************************************* 00124 Set target window 00125 *************************************************************************/ 00126 void TabButton::setTargetWindow(Window* wnd) 00127 { 00128 d_targetWindow = wnd; 00129 // Copy initial text 00130 setText(wnd->getText()); 00131 // Parent control will keep text up to date, since changes affect layout 00132 } 00133 00134 } // End of CEGUI namespace section