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 "OgreBorderButtonGuiElement.h" 00027 //#include "OgreActionEvent.h" 00028 //#include "OgreMouseEvent.h" 00029 #include "OgreGuiManager.h" 00030 00031 00032 namespace Ogre { 00033 00034 //----------------------------------------------------------------------- 00035 String BorderButtonGuiElement::msTypeName = "BorderButton"; 00036 BorderButtonGuiElement::CmdBorderDownMaterial BorderButtonGuiElement::msCmdBorderDownMaterial; 00037 BorderButtonGuiElement::CmdBorderUpMaterial BorderButtonGuiElement::msCmdBorderUpMaterial; 00038 BorderButtonGuiElement::CmdBorderHiliteDownMaterial BorderButtonGuiElement::msCmdBorderHiliteDownMaterial; 00039 BorderButtonGuiElement::CmdBorderHiliteUpMaterial BorderButtonGuiElement::msCmdBorderHiliteUpMaterial; 00040 BorderButtonGuiElement::CmdBorderDisabledMaterial BorderButtonGuiElement::msCmdBorderDisabledMaterial; 00041 BorderButtonGuiElement::CmdBorderButtonCaption BorderButtonGuiElement::msCmdBorderButtonCaption; 00042 00043 //----------------------------------------------------------------------- 00044 BorderButtonGuiElement::BorderButtonGuiElement(const String& name) : 00045 BorderPanelGuiElement(name), 00046 GuiPressable(name) 00047 { 00048 mButtonDown = false; 00049 mChildrenProcessEvents = false; 00050 00051 mBorderDownMaterialName = ""; 00052 mBorderUpMaterialName = ""; 00053 mBorderHiliteDownMaterialName = ""; 00054 mBorderHiliteUpMaterialName = ""; 00055 mBorderDisabledMaterialName = ""; 00056 00057 mInsideObject = 0; 00058 00059 if (createParamDictionary("BorderButtonGuiElement")) 00060 { 00061 addBaseParameters(); 00062 } 00063 setSource(this); 00064 } 00065 00066 //----------------------------------------------------------------------- 00067 void BorderButtonGuiElement::processEvent(InputEvent* e) 00068 { 00069 BorderPanelGuiElement::processEvent(e); 00070 00071 updateMaterials(); 00072 } 00073 00074 //----------------------------------------------------------------------- 00075 void BorderButtonGuiElement::updateMaterials(bool init) 00076 { 00077 bool buttonStatus; 00078 00079 // did the button's status change between last time 00080 buttonStatus = (mButtonDown != (isPressed() && isMouseWithin())); 00081 00082 mButtonDown = (isPressed() && isMouseWithin()); 00083 00084 String borderMaterialName; 00085 00086 if (mMouseWithin) 00087 { 00088 if (mButtonDown) 00089 borderMaterialName = mBorderHiliteDownMaterialName; 00090 else 00091 borderMaterialName = mBorderHiliteUpMaterialName; 00092 00093 if (strlen(borderMaterialName) == 0) 00094 { 00095 if (mButtonDown) 00096 borderMaterialName = mBorderDownMaterialName; 00097 else 00098 borderMaterialName = mBorderUpMaterialName; 00099 } 00100 } 00101 else 00102 { 00103 if (mButtonDown) 00104 borderMaterialName = mBorderDownMaterialName; 00105 else 00106 borderMaterialName = mBorderUpMaterialName; 00107 } 00108 00109 BorderPanelGuiElement::setBorderMaterialName(borderMaterialName); 00110 00111 if (buttonStatus && !init) 00112 { 00113 ChildIterator it = getChildIterator(); 00114 while (it.hasMoreElements()) 00115 { 00116 if (mMetricsMode == GMM_PIXELS) 00117 changeChild(it.getNext(), ((mButtonDown)?1:-1)); 00118 else 00119 changeChild(it.getNext(), ((mButtonDown)?0.003:-0.003)); 00120 } 00121 } 00122 } 00123 00124 //----------------------------------------------------------------------- 00125 void BorderButtonGuiElement::changeChild(GuiElement* e, Real add) 00126 { 00127 e->setLeft(e->getLeft() + add); 00128 e->setTop(e->getTop() + add); 00129 00130 e->setWidth(e->getWidth() - 2 * add); 00131 e->setHeight(e->getHeight() - 2 * add); 00132 } 00133 00134 //--------------------------------------------------------------------- 00135 void BorderButtonGuiElement::addBaseParameters(void) 00136 { 00137 BorderPanelGuiElement::addBaseParameters(); 00138 ParamDictionary* dict = getParamDictionary(); 00139 00140 dict->addParameter(ParameterDef("border_down_material", 00141 "The material to use for the border when the button is down." 00142 , PT_STRING), 00143 &BorderButtonGuiElement::msCmdBorderDownMaterial); 00144 00145 dict->addParameter(ParameterDef("border_up_material", 00146 "The material to use for the border when the button is up." 00147 , PT_STRING), 00148 &BorderButtonGuiElement::msCmdBorderUpMaterial); 00149 00150 dict->addParameter(ParameterDef("border_hilited_down_material", 00151 "The highlighted material to use for the border when the button is down." 00152 , PT_STRING), 00153 &BorderButtonGuiElement::msCmdBorderHiliteDownMaterial); 00154 00155 dict->addParameter(ParameterDef("border_hilited_up_material", 00156 "The highlighted material to use for the border when the button is up." 00157 , PT_STRING), 00158 &BorderButtonGuiElement::msCmdBorderHiliteUpMaterial); 00159 00160 dict->addParameter(ParameterDef("border_disabled_material", 00161 "The material to use for the border when the button is disabled." 00162 , PT_STRING), 00163 &BorderButtonGuiElement::msCmdBorderDisabledMaterial); 00164 00165 dict->addParameter(ParameterDef("caption", 00166 "The text in the middle of the button." 00167 , PT_STRING), 00168 &BorderButtonGuiElement::msCmdBorderButtonCaption); 00169 } 00170 00171 00172 //----------------------------------------------------------------------- 00173 void BorderButtonGuiElement::setBorderDownMaterialName(const String& name) 00174 { 00175 mBorderDownMaterialName = name; 00176 00177 } 00178 //----------------------------------------------------------------------- 00179 void BorderButtonGuiElement::setBorderUpMaterialName(const String& name) 00180 { 00181 mBorderUpMaterialName = name; 00182 setPressed(false); 00183 updateMaterials(true); 00184 } 00185 00186 //----------------------------------------------------------------------- 00187 void BorderButtonGuiElement::setBorderHiliteDownMaterialName(const String& name) 00188 { 00189 mBorderHiliteDownMaterialName = name; 00190 } 00191 //----------------------------------------------------------------------- 00192 void BorderButtonGuiElement::setBorderHiliteUpMaterialName(const String& name) 00193 { 00194 mBorderHiliteUpMaterialName = name; 00195 } 00196 //----------------------------------------------------------------------- 00197 void BorderButtonGuiElement::setBorderDisabledMaterialName(const String& name) 00198 { 00199 mBorderDisabledMaterialName = name; 00200 } 00201 00202 //--------------------------------------------------------------------- 00203 const String& BorderButtonGuiElement::getBorderDownMaterialName(void) const 00204 { 00205 return mBorderDownMaterialName; 00206 } 00207 //--------------------------------------------------------------------- 00208 const String& BorderButtonGuiElement::getBorderUpMaterialName(void) const 00209 { 00210 return mBorderUpMaterialName; 00211 } 00212 //--------------------------------------------------------------------- 00213 const String& BorderButtonGuiElement::getBorderHiliteDownMaterialName(void) const 00214 { 00215 return mBorderHiliteDownMaterialName; 00216 } 00217 //--------------------------------------------------------------------- 00218 const String& BorderButtonGuiElement::getBorderHiliteUpMaterialName(void) const 00219 { 00220 return mBorderHiliteUpMaterialName; 00221 } 00222 //--------------------------------------------------------------------- 00223 const String& BorderButtonGuiElement::getBorderDisabledMaterialName(void) const 00224 { 00225 return mBorderDisabledMaterialName; 00226 } 00227 00228 //----------------------------------------------------------------------- 00229 void BorderButtonGuiElement::setButtonCaption(const String& templateName, const String& name) 00230 { 00231 if (mInsideObject) 00232 { 00233 removeChild(mInsideObject->getName()); 00234 GuiManager::getSingleton().destroyGuiElement(mInsideObject); 00235 mInsideObject = NULL; 00236 } 00237 if (name == "") 00238 { 00239 return; 00240 00241 } 00242 mInsideObject = 00243 GuiManager::getSingleton().createGuiElementFromTemplate(templateName, "", mName + "/caption"); 00244 00245 // change left/top etc to relative 00246 // mInsideObject->setLeft(mInsideObject->getLeft()*mWidth); 00247 // mInsideObject->setWidth(mInsideObject->getWidth()*mWidth); 00248 // mInsideObject->setTop(mInsideObject->getTop()*mHeight); 00249 // mInsideObject->setWidth(mInsideObject->getHeight()*mHeight); 00250 mInsideObject->setCaption(name); 00251 00252 // do not make this cloneable, otherwise there will be 2 copies of it when it is cloned, 00253 // one copy when the children are copied, and another copy when setButtonCaption is set. 00254 mInsideObject->setCloneable(false); 00255 00256 addChild((GuiContainer*)mInsideObject); 00257 00258 } 00259 //----------------------------------------------------------------------- 00260 String BorderButtonGuiElement::getButtonCaption() const 00261 { 00262 return (mInsideObject)?mInsideObject->getCaption():String(""); 00263 } 00264 00265 //--------------------------------------------------------------------- 00266 //--------------------------------------------------------------------- 00267 // Command objects 00268 //--------------------------------------------------------------------- 00269 00270 //----------------------------------------------------------------------- 00271 String BorderButtonGuiElement::CmdBorderDownMaterial::doGet(const void* target) const 00272 { 00273 // No need right now.. 00274 return static_cast<const BorderButtonGuiElement*>(target)->getBorderDownMaterialName(); 00275 } 00276 //----------------------------------------------------------------------- 00277 void BorderButtonGuiElement::CmdBorderDownMaterial::doSet(void* target, const String& val) 00278 { 00279 std::vector<String> vec = val.split(); 00280 00281 static_cast<BorderButtonGuiElement*>(target)->setBorderDownMaterialName(val); 00282 } 00283 //----------------------------------------------------------------------- 00284 String BorderButtonGuiElement::CmdBorderUpMaterial::doGet(const void* target) const 00285 { 00286 // No need right now.. 00287 return static_cast<const BorderButtonGuiElement*>(target)->getBorderUpMaterialName(); 00288 } 00289 //----------------------------------------------------------------------- 00290 void BorderButtonGuiElement::CmdBorderUpMaterial::doSet(void* target, const String& val) 00291 { 00292 std::vector<String> vec = val.split(); 00293 00294 static_cast<BorderButtonGuiElement*>(target)->setBorderUpMaterialName(val); 00295 } 00296 //----------------------------------------------------------------------- 00297 String BorderButtonGuiElement::CmdBorderHiliteDownMaterial::doGet(const void* target) const 00298 { 00299 // No need right now.. 00300 return static_cast<const BorderButtonGuiElement*>(target)->getBorderHiliteDownMaterialName(); 00301 } 00302 //----------------------------------------------------------------------- 00303 void BorderButtonGuiElement::CmdBorderHiliteDownMaterial::doSet(void* target, const String& val) 00304 { 00305 std::vector<String> vec = val.split(); 00306 00307 static_cast<BorderButtonGuiElement*>(target)->setBorderHiliteDownMaterialName(val); 00308 } 00309 //----------------------------------------------------------------------- 00310 String BorderButtonGuiElement::CmdBorderHiliteUpMaterial::doGet(const void* target) const 00311 { 00312 // No need right now.. 00313 return static_cast<const BorderButtonGuiElement*>(target)->getBorderHiliteUpMaterialName(); 00314 } 00315 //----------------------------------------------------------------------- 00316 void BorderButtonGuiElement::CmdBorderHiliteUpMaterial::doSet(void* target, const String& val) 00317 { 00318 std::vector<String> vec = val.split(); 00319 00320 static_cast<BorderButtonGuiElement*>(target)->setBorderHiliteUpMaterialName(val); 00321 } 00322 //----------------------------------------------------------------------- 00323 String BorderButtonGuiElement::CmdBorderDisabledMaterial::doGet(const void* target) const 00324 { 00325 // No need right now.. 00326 return static_cast<const BorderButtonGuiElement*>(target)->getBorderDisabledMaterialName(); 00327 } 00328 //----------------------------------------------------------------------- 00329 void BorderButtonGuiElement::CmdBorderDisabledMaterial::doSet(void* target, const String& val) 00330 { 00331 std::vector<String> vec = val.split(); 00332 00333 static_cast<BorderButtonGuiElement*>(target)->setBorderDisabledMaterialName(val); 00334 } 00335 //----------------------------------------------------------------------- 00336 String BorderButtonGuiElement::CmdBorderButtonCaption::doGet(const void* target) const 00337 { 00338 // No need right now.. 00339 return static_cast<const BorderButtonGuiElement*>(target)->getButtonCaption(); 00340 } 00341 //----------------------------------------------------------------------- 00342 void BorderButtonGuiElement::CmdBorderButtonCaption::doSet(void* target, const String& val) 00343 { 00344 std::vector<String> vec = val.split("\t\n ", 1); 00345 00346 00347 if (vec.size() < 2) 00348 { 00349 static_cast<BorderButtonGuiElement*>(target)->setButtonCaption(val, String("")); 00350 } 00351 else 00352 { 00353 static_cast<BorderButtonGuiElement*>(target)->setButtonCaption(vec[0], vec[1]); 00354 } 00355 } 00356 //--------------------------------------------------------------------- 00357 const String& BorderButtonGuiElement::getTypeName(void) const 00358 { 00359 return msTypeName; 00360 } 00361 00362 }
Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:02 2004