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 00026 #include "OgreCursorGuiElement.h" 00027 #include "OgreEventProcessor.h" 00028 #include "OgreInput.h" 00029 #include "OgreOverlayManager.h" 00030 #include "OgreStringConverter.h" 00031 00032 00033 namespace Ogre { 00034 00035 //--------------------------------------------------------------------- 00036 String CursorGuiElement::msTypeName = "Cursor"; 00037 00038 CursorGuiElement::CmdOffsetX CursorGuiElement::msCmdOffsetX; 00039 CursorGuiElement::CmdOffsetY CursorGuiElement::msCmdOffsetY; 00040 00041 CursorGuiElement::CursorGuiElement(const String& name) : 00042 PanelGuiElement(name), mOffsetX(0.0), mOffsetY(0.0) 00043 { 00044 mVisible = false; // cursors are initially hidden 00045 00046 if (createParamDictionary("CursorGuiElement")) 00047 { 00048 addBaseParameters(); 00049 } 00050 00051 setWidth(0.01); 00052 setHeight(0.01); 00053 } 00054 //--------------------------------------------------------------------- 00055 const String& CursorGuiElement::getTypeName(void) const 00056 { 00057 return msTypeName; 00058 } 00059 //--------------------------------------------------------------------- 00060 void CursorGuiElement::show(void) 00061 { 00062 if (!mVisible) { 00063 OverlayManager &om = OverlayManager::getSingleton(); 00064 setLeft(om.getMouseX() - mOffsetX); 00065 setTop(om.getMouseY() - mOffsetY); 00066 om.addMouseMotionListener(this); 00067 } 00068 PanelGuiElement::show(); 00069 } 00070 //--------------------------------------------------------------------- 00071 void CursorGuiElement::hide(void) 00072 { 00073 if (mVisible) { 00074 OverlayManager &om = OverlayManager::getSingleton(); 00075 om.removeMouseMotionListener(this); 00076 } 00077 PanelGuiElement::hide(); 00078 } 00079 //--------------------------------------------------------------------- 00080 void CursorGuiElement::setOffsetX(Real x) 00081 { 00082 setLeft(mLeft + mOffsetX - x); 00083 mOffsetX = x; 00084 } 00085 //--------------------------------------------------------------------- 00086 void CursorGuiElement::setOffsetY(Real y) 00087 { 00088 setTop(mTop + mOffsetY - y); 00089 mOffsetY = y; 00090 } 00091 //--------------------------------------------------------------------- 00092 GuiElement* CursorGuiElement::findElementAt(Real x, Real y) // relative to parent 00093 { 00094 return NULL; // override this so it won't find itself! 00095 } 00096 //--------------------------------------------------------------------- 00097 void CursorGuiElement::mouseMoved(MouseEvent* e) 00098 { 00099 setLeft(e->getX() - mOffsetX); 00100 setTop(e->getY() - mOffsetY); 00101 } 00102 //--------------------------------------------------------------------- 00103 void CursorGuiElement::mouseDragged(MouseEvent* e) 00104 { 00105 mouseMoved(e); 00106 } 00107 //--------------------------------------------------------------------- 00108 void CursorGuiElement::addBaseParameters(void) 00109 { 00110 PanelGuiElement::addBaseParameters(); 00111 ParamDictionary* dict = getParamDictionary(); 00112 00113 dict->addParameter(ParameterDef("x_offset", 00114 "Specifies the x offset that will be added to the mouse coordinates.", PT_STRING), 00115 &msCmdOffsetX); 00116 dict->addParameter(ParameterDef("y_offset", 00117 "Specifies the y offset that will be added to the mouse coordinates.", PT_STRING), 00118 &msCmdOffsetY); 00119 } 00120 //----------------------------------------------------------------------- 00121 String CursorGuiElement::CmdOffsetX::doGet(const void* target) const 00122 { 00123 return StringConverter::toString( 00124 static_cast<const CursorGuiElement*>(target)->getOffsetX() ); 00125 } 00126 void CursorGuiElement::CmdOffsetX::doSet(void* target, const String& val) 00127 { 00128 static_cast<CursorGuiElement*>(target)->setOffsetX(StringConverter::parseReal(val)); 00129 } 00130 //----------------------------------------------------------------------- 00131 String CursorGuiElement::CmdOffsetY::doGet(const void* target) const 00132 { 00133 return StringConverter::toString( 00134 static_cast<const CursorGuiElement*>(target)->getOffsetY() ); 00135 } 00136 void CursorGuiElement::CmdOffsetY::doSet(void* target, const String& val) 00137 { 00138 static_cast<CursorGuiElement*>(target)->setOffsetY(StringConverter::parseReal(val)); 00139 } 00140 00141 } 00142
Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:18 2004