Torque3D Documentation / _generateds / guiToolboxButtonCtrl.cpp

guiToolboxButtonCtrl.cpp

Engine/source/gui/buttons/guiToolboxButtonCtrl.cpp

More...

Public Functions

ConsoleDocClass(GuiToolboxButtonCtrl , "@brief Unimplemented GUI <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> meant <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> interact with <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Toolbox.\n\n</a>" "For Torque 3D editors only, soon <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">deprecated\n\n</a>" " @internal" )
DefineEngineMethod(GuiToolboxButtonCtrl , setHoverBitmap , void , (const char *name) , "( filepath name ) sets the bitmap that shows when the button is disabled" )
DefineEngineMethod(GuiToolboxButtonCtrl , setLoweredBitmap , void , (const char *name) , "( filepath name ) sets the bitmap that shows when the button is disabled" )
DefineEngineMethod(GuiToolboxButtonCtrl , setNormalBitmap , void , (const char *name) , "( filepath name ) sets the bitmap that shows when the button is active" )

Detailed Description

Public Functions

ConsoleDocClass(GuiToolboxButtonCtrl , "@brief Unimplemented GUI <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> meant <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> interact with <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Toolbox.\n\n</a>" "For Torque 3D editors only, soon <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">deprecated\n\n</a>" " @internal" )

DefineEngineMethod(GuiToolboxButtonCtrl , setHoverBitmap , void , (const char *name) , "( filepath name ) sets the bitmap that shows when the button is disabled" )

DefineEngineMethod(GuiToolboxButtonCtrl , setLoweredBitmap , void , (const char *name) , "( filepath name ) sets the bitmap that shows when the button is disabled" )

DefineEngineMethod(GuiToolboxButtonCtrl , setNormalBitmap , void , (const char *name) , "( filepath name ) sets the bitmap that shows when the button is active" )

IMPLEMENT_CONOBJECT(GuiToolboxButtonCtrl )

  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/buttons/guiToolboxButtonCtrl.h"
 26
 27#include "console/console.h"
 28#include "console/engineAPI.h"
 29#include "gfx/gfxDevice.h"
 30#include "gfx/gfxDrawUtil.h"
 31#include "console/consoleTypes.h"
 32#include "gui/core/guiCanvas.h"
 33#include "gui/core/guiDefaultControlRender.h"
 34
 35
 36IMPLEMENT_CONOBJECT(GuiToolboxButtonCtrl);
 37
 38ConsoleDocClass( GuiToolboxButtonCtrl,
 39   "@brief Unimplemented GUI control meant to interact with Toolbox.\n\n"
 40   "For Torque 3D editors only, soon to be deprecated\n\n"
 41   "@internal"
 42);
 43
 44//-------------------------------------
 45GuiToolboxButtonCtrl::GuiToolboxButtonCtrl()
 46{
 47   mNormalBitmapName = StringTable->EmptyString();
 48   mLoweredBitmapName = StringTable->insert("sceneeditor/client/images/buttondown");
 49   mHoverBitmapName = StringTable->insert("sceneeditor/client/images/buttonup");
 50   setMinExtent(Point2I(16,16));
 51   setExtent(48, 48);
 52   mButtonType = ButtonTypeRadio;
 53   mTipHoverTime = 100;
 54   
 55}
 56
 57
 58//-------------------------------------
 59void GuiToolboxButtonCtrl::initPersistFields()
 60{
 61   addField("normalBitmap", TypeFilename, Offset(mNormalBitmapName, GuiToolboxButtonCtrl));
 62   addField("loweredBitmap", TypeFilename, Offset(mLoweredBitmapName, GuiToolboxButtonCtrl));
 63   addField("hoverBitmap", TypeFilename, Offset(mHoverBitmapName, GuiToolboxButtonCtrl));
 64   Parent::initPersistFields();
 65}
 66
 67
 68//-------------------------------------
 69bool GuiToolboxButtonCtrl::onWake()
 70{
 71   if (! Parent::onWake())
 72      return false;
 73
 74   setActive( true );
 75   
 76   setNormalBitmap( mNormalBitmapName );
 77   setLoweredBitmap( mLoweredBitmapName );
 78   setHoverBitmap( mHoverBitmapName );
 79
 80   return true;
 81}
 82
 83
 84//-------------------------------------
 85void GuiToolboxButtonCtrl::onSleep()
 86{
 87   mTextureNormal = NULL;
 88   mTextureLowered = NULL;
 89   mTextureHover = NULL;
 90   Parent::onSleep();
 91}
 92
 93
 94//-------------------------------------
 95
 96DefineEngineMethod( GuiToolboxButtonCtrl, setNormalBitmap, void, ( const char * name ), , "( filepath name ) sets the bitmap that shows when the button is active")
 97{
 98   object->setNormalBitmap(name);
 99}
100
101DefineEngineMethod( GuiToolboxButtonCtrl, setLoweredBitmap, void, ( const char * name ), , "( filepath name ) sets the bitmap that shows when the button is disabled")
102{
103   object->setLoweredBitmap(name);
104}
105
106DefineEngineMethod( GuiToolboxButtonCtrl, setHoverBitmap, void, ( const char * name ), , "( filepath name ) sets the bitmap that shows when the button is disabled")
107{
108   object->setHoverBitmap(name);
109}
110
111//-------------------------------------
112void GuiToolboxButtonCtrl::inspectPostApply()
113{
114   // if the extent is set to (0,0) in the gui editor and appy hit, this control will
115   // set it's extent to be exactly the size of the normal bitmap (if present)
116   Parent::inspectPostApply();
117
118   if ((getWidth() == 0) && (getHeight() == 0) && mTextureNormal)
119   {
120      setExtent( mTextureNormal->getWidth(), mTextureNormal->getHeight());
121   }
122}
123
124
125//-------------------------------------
126void GuiToolboxButtonCtrl::setNormalBitmap( StringTableEntry bitmapName )
127{
128   mNormalBitmapName = StringTable->insert( bitmapName );
129   
130   if(!isAwake())
131      return;
132
133   if ( *mNormalBitmapName )
134      mTextureNormal = GFXTexHandle( mNormalBitmapName, &GFXTexturePersistentSRGBProfile, avar("%s() - mTextureNormal (line %d)", __FUNCTION__, __LINE__) );
135   else
136      mTextureNormal = NULL;
137   
138   setUpdate();
139}   
140
141void GuiToolboxButtonCtrl::setLoweredBitmap( StringTableEntry bitmapName )
142{
143   mLoweredBitmapName = StringTable->insert( bitmapName );
144   
145   if(!isAwake())
146      return;
147
148   if ( *mLoweredBitmapName )
149      mTextureLowered = GFXTexHandle( mLoweredBitmapName, &GFXTexturePersistentSRGBProfile, avar("%s() - mTextureLowered (line %d)", __FUNCTION__, __LINE__) );
150   else
151      mTextureLowered = NULL;
152   
153   setUpdate();
154}   
155
156void GuiToolboxButtonCtrl::setHoverBitmap( StringTableEntry bitmapName )
157{
158   mHoverBitmapName = StringTable->insert( bitmapName );
159
160   if(!isAwake())
161      return;
162
163   if ( *mHoverBitmapName )
164      mTextureHover = GFXTexHandle( mHoverBitmapName, &GFXTexturePersistentSRGBProfile, avar("%s() - mTextureHover (line %d)", __FUNCTION__, __LINE__) );
165   else
166      mTextureHover = NULL;
167
168   setUpdate();
169}   
170
171
172
173//-------------------------------------
174void GuiToolboxButtonCtrl::onRender(Point2I offset, const RectI& updateRect)
175{
176   // Only render the state rect (hover/down) if we're active
177   if (mActive)
178   {
179      RectI r(offset, getExtent());
180      if ( mDepressed  || mStateOn )
181         renderStateRect( mTextureLowered , r );
182      else if ( mMouseOver )
183         renderStateRect( mTextureHover , r );
184   }
185
186   // Now render the image
187   if( mTextureNormal )
188   {
189      renderButton( mTextureNormal, offset, updateRect );
190      return;
191   }
192
193   Point2I textPos = offset;
194   if( mDepressed )
195      textPos += Point2I(1,1);
196
197   // Make sure we take the profile's textOffset into account.
198   textPos += mProfile->mTextOffset;
199
200   GFX->getDrawUtil()->setBitmapModulation( mProfile->mFontColor );
201   renderJustifiedText(textPos, getExtent(), mButtonText);
202
203}
204
205void GuiToolboxButtonCtrl::renderStateRect( GFXTexHandle &texture, const RectI& rect )
206{
207   if (texture)
208   {
209      GFX->getDrawUtil()->clearBitmapModulation();
210      GFX->getDrawUtil()->drawBitmapStretch( texture, rect );
211   }
212}
213
214//------------------------------------------------------------------------------
215
216void GuiToolboxButtonCtrl::renderButton(GFXTexHandle &texture, Point2I &offset, const RectI& updateRect)
217{
218   if (texture)
219   {
220      Point2I finalOffset = offset;
221
222      finalOffset.x += ( ( getWidth() / 2 ) - ( texture.getWidth() / 2 ) );
223      finalOffset.y += ( ( getHeight() / 2 ) - ( texture.getHeight() / 2 ) );
224
225      GFX->getDrawUtil()->clearBitmapModulation();
226      GFX->getDrawUtil()->drawBitmap(texture, finalOffset);
227      renderChildControls( offset, updateRect);
228   }
229}
230