00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright © 2000-2002 The OGRE Team 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 #include "OgreStableHeaders.h" 00026 00027 #include "OgreGuiControl.h" 00028 #include "OgreActionEvent.h" 00029 #include "OgreMouseEvent.h" 00030 00031 namespace Ogre { 00032 00033 //----------------------------------------------------------------------- 00034 GuiControl::GuiControl(const String& name) : 00035 ActionTarget() 00036 { 00037 mPressed = false; 00038 mMouseWithin = false; 00039 mEnabled = true; 00040 00041 mActionCommand = name; 00042 } 00043 00044 //----------------------------------------------------------------------- 00045 void GuiControl::processEvent(InputEvent* e) 00046 { 00047 if (!mEnabled || e->isConsumed()) 00048 return; 00049 00050 switch(e->getID()) 00051 { 00052 case ActionEvent::AE_ACTION_PERFORMED: 00053 processActionEvent(static_cast<ActionEvent*>(e)); 00054 break; 00055 00056 case MouseEvent::ME_MOUSE_PRESSED: 00057 setPressed(true); 00058 break; 00059 00060 case MouseEvent::ME_MOUSE_RELEASED: 00061 setPressed(false); 00062 break; 00063 00064 case MouseEvent::ME_MOUSE_ENTERED: 00065 setMouseWithin(true); 00066 break; 00067 00068 case MouseEvent::ME_MOUSE_EXITED: 00069 setMouseWithin(false); 00070 break; 00071 00072 case MouseEvent::ME_MOUSE_CLICKED: 00073 fireActionPerformed(); 00074 break; 00075 00076 default: 00077 break; 00078 } 00079 } 00080 00081 //----------------------------------------------------------------------- 00082 const String& GuiControl::getActionCommand() const 00083 { 00084 return mActionCommand; 00085 } 00086 00087 //----------------------------------------------------------------------- 00088 void GuiControl::setActionCommand(const String& action) 00089 { 00090 mActionCommand = action; 00091 } 00092 00093 //----------------------------------------------------------------------- 00094 bool GuiControl::isPressed() const 00095 { 00096 return mPressed; 00097 } 00098 00099 //----------------------------------------------------------------------- 00100 void GuiControl::setPressed(bool b) 00101 { 00102 mPressed = b; 00103 } 00104 00105 //----------------------------------------------------------------------- 00106 bool GuiControl::isEnabled() const 00107 { 00108 return mEnabled; 00109 } 00110 00111 //----------------------------------------------------------------------- 00112 void GuiControl::setEnabled(bool b) 00113 { 00114 if (b) 00115 { 00116 mEnabled = true; 00117 } 00118 else 00119 { 00120 mPressed = false; 00121 mMouseWithin = false; 00122 mButtonDown = false; 00123 mEnabled = false; 00124 } 00125 } 00126 00127 //----------------------------------------------------------------------- 00128 bool GuiControl::isMouseWithin() const 00129 { 00130 return mMouseWithin; 00131 } 00132 00133 //----------------------------------------------------------------------- 00134 void GuiControl::setMouseWithin(bool b) 00135 { 00136 mMouseWithin = b; 00137 } 00138 00139 //----------------------------------------------------------------------- 00140 void GuiControl::fireActionPerformed() 00141 { 00142 ActionEvent* ae = new ActionEvent(this, ActionEvent::AE_ACTION_PERFORMED, 0, 0, getActionCommand()); 00143 processEvent(ae); 00144 delete ae; 00145 } 00146 } 00147
Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:28 2004