guiDecoyCtrl.cpp
Engine/source/gui/controls/guiDecoyCtrl.cpp
Public Functions
ConsoleDocClass(GuiDecoyCtrl , "@brief Designed soley <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> buttons, primarily used in <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">editor.\n\n</a>" "Currently editor use only, no real application without <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">extension.\n\n</a> " " @internal" )
Detailed Description
Public Functions
ConsoleDocClass(GuiDecoyCtrl , "@brief Designed soley <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> buttons, primarily used in <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">editor.\n\n</a>" "Currently editor use only, no real application without <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">extension.\n\n</a> " " @internal" )
IMPLEMENT_CONOBJECT(GuiDecoyCtrl )
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "platform/platform.h" 25#include "gui/controls/guiDecoyCtrl.h" 26#include "gui/buttons/guiButtonBaseCtrl.h" 27 28#include "console/consoleTypes.h" 29#include "console/engineAPI.h" 30#include "gfx/primBuilder.h" 31 32//----------------------------------------------------------------------------- 33// GuiDecoyCtrl 34//----------------------------------------------------------------------------- 35 36/* 37So far this control has been designed in mind solely for button controls. I'm pretty sure 38it can be used for other things, but to do anything more in depth; it has to be extended. 39Make sure you know a little about how guiCanvas hands out signals to gui controls before you tinker 40in this class. 41 42Been thinking about this class a little more. I tried pretty hard to protect this class into being 43guiControl like agnostic. But I ended up adding a check specifically for buttons in the 44onMouseUp function. Its been protected with a dynamic_cast and a NULL check; but in the end, the only way 45too solve the main problem, that GuiCanvas cannot process more than one mouse action for more than one 46gui control at a time, is for it to get a rewrite. 47*/ 48 49IMPLEMENT_CONOBJECT(GuiDecoyCtrl); 50 51ConsoleDocClass( GuiDecoyCtrl, 52 "@brief Designed soley for buttons, primarily used in editor.\n\n" 53 "Currently editor use only, no real application without extension.\n\n " 54 "@internal"); 55 56GuiDecoyCtrl::GuiDecoyCtrl() : mMouseOver(false), 57 mIsDecoy(true), 58 mDecoyReference(NULL), 59 mMouseOverDecoy(false) 60{ 61} 62 63GuiDecoyCtrl::~GuiDecoyCtrl() 64{ 65} 66 67void GuiDecoyCtrl::initPersistFields() 68{ 69 addField("isDecoy", TypeBool, Offset(mIsDecoy, GuiDecoyCtrl), "Sets this control to decoy mode"); 70 71 Parent::initPersistFields(); 72} 73 74void GuiDecoyCtrl::onMouseUp(const GuiEvent &event) 75{ 76 mouseUnlock(); 77 setUpdate(); 78 79 //this code is pretty hacky. right now there is no way that guiCanvas will allow sending more than 80 //one signal to one gui control at a time. 81 if(mIsDecoy == true) 82 { 83 mVisible = false; 84 85 GuiControl *parent = getParent(); 86 Point2I localPoint = parent->globalToLocalCoord(event.mousePoint); 87 GuiControl *tempControl = parent->findHitControl(localPoint); 88 89 //the decoy control has the responsibility of keeping track of the decoyed controls status 90 if( mDecoyReference != NULL && tempControl == mDecoyReference) 91 tempControl->onMouseUp(event); 92 else if(mDecoyReference != NULL && tempControl != mDecoyReference) 93 { 94 //as explained earlier, this control was written in the mindset for buttons. 95 //nothing bad should ever happen if not a button due to the checks in this function though. 96 GuiButtonBaseCtrl *unCastCtrl = NULL; 97 unCastCtrl = dynamic_cast<GuiButtonBaseCtrl *>( mDecoyReference ); 98 if(unCastCtrl != NULL) 99 unCastCtrl->resetState(); 100 } 101 mVisible = true; 102 } 103} 104 105void GuiDecoyCtrl::onMouseDown(const GuiEvent &event) 106{ 107 if ( !mVisible || !mAwake ) 108 return; 109 110 mouseLock(); 111 112 if(mIsDecoy == true) 113 { 114 mVisible = false; 115 116 GuiControl *parent = getParent(); 117 Point2I localPoint = parent->globalToLocalCoord(event.mousePoint); 118 119 GuiControl *tempControl = parent->findHitControl(localPoint); 120 tempControl->onMouseDown(event); 121 122 mVisible = true; 123 } 124 125 execConsoleCallback(); 126 setUpdate(); 127} 128 129void GuiDecoyCtrl::onMouseMove(const GuiEvent &event) 130{ 131 //if this control is a dead end, make sure the event stops here 132 if ( !mVisible || !mAwake ) 133 return; 134 135 //pass the event to the parent 136 GuiControl *parent = getParent(); 137 if ( parent ) 138 parent->onMouseMove( event ); 139 140 Point2I localPoint = parent->globalToLocalCoord(event.mousePoint); 141 142 //also pretty hacky. since guiCanvas, *NOT* GuiControl, distributes the calls for onMouseEnter 143 //and onMouseLeave, we simulate those calls here through a series of checks. 144 if(mIsDecoy == true) 145 { 146 mVisible = false; 147 GuiControl *tempControl = parent->findHitControl(localPoint); 148 149 //the decoy control has the responsibility of keeping track of the decoyed controls status 150 if(mMouseOverDecoy == false && mDecoyReference != NULL) 151 { 152 tempControl->onMouseEnter(event); 153 mMouseOverDecoy = true; 154 } 155 else if(tempControl != mDecoyReference && mDecoyReference != NULL) 156 { 157 mDecoyReference->onMouseLeave(event); 158 mMouseOverDecoy = false; 159 } 160 161 mDecoyReference = tempControl; 162 mVisible = true; 163 } 164} 165 166void GuiDecoyCtrl::onMouseDragged(const GuiEvent &event) 167{ 168} 169 170void GuiDecoyCtrl::onMouseEnter(const GuiEvent &event) 171{ 172 if ( !mVisible || !mAwake ) 173 return; 174 175 setUpdate(); 176 Con::executef( this , "onMouseEnter" ); 177 mMouseOver = true; 178} 179 180void GuiDecoyCtrl::onMouseLeave(const GuiEvent &event) 181{ 182 if ( !mVisible || !mAwake ) 183 return; 184 185 setUpdate(); 186 Con::executef( this , "onMouseLeave" ); 187 mMouseOver = false; 188} 189 190bool GuiDecoyCtrl::onMouseWheelUp( const GuiEvent &event ) 191{ 192 //if this control is a dead end, make sure the event stops here 193 if ( !mVisible || !mAwake ) 194 return true; 195 196 //pass the event to the parent 197 GuiControl *parent = getParent(); 198 if ( parent ) 199 return parent->onMouseWheelUp( event ); 200 else 201 return false; 202} 203 204bool GuiDecoyCtrl::onMouseWheelDown( const GuiEvent &event ) 205{ 206 //if this control is a dead end, make sure the event stops here 207 if ( !mVisible || !mAwake ) 208 return true; 209 210 //pass the event to the parent 211 GuiControl *parent = getParent(); 212 if ( parent ) 213 return parent->onMouseWheelDown( event ); 214 else 215 return false; 216} 217 218void GuiDecoyCtrl::onRightMouseDown(const GuiEvent &) 219{ 220} 221 222void GuiDecoyCtrl::onRightMouseUp(const GuiEvent &) 223{ 224} 225 226void GuiDecoyCtrl::onRightMouseDragged(const GuiEvent &) 227{ 228} 229 230void GuiDecoyCtrl::onMiddleMouseDown(const GuiEvent &) 231{ 232} 233 234void GuiDecoyCtrl::onMiddleMouseUp(const GuiEvent &) 235{ 236} 237 238void GuiDecoyCtrl::onMiddleMouseDragged(const GuiEvent &) 239{ 240} 241