Torque3D Documentation / _generateds / guiToggleButtonCtrl.cpp

guiToggleButtonCtrl.cpp

Engine/source/gui/buttons/guiToggleButtonCtrl.cpp

More...

Public Functions

ConsoleDocClass(GuiToggleButtonCtrl , "@brief Deprecated gui <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">control.\n\n</a>" "@deprecated <a href="/coding/class/classguitogglebuttonctrl/">GuiToggleButtonCtrl</a>'s functionality is solely based on <a href="/coding/class/classguibuttonbasectrl/">GuiButtonBaseCtrl</a>'s ButtonTypeCheck <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">type.\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiButtonCtrl\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiCheckBoxCtrl\n</a>" "@ingroup GuiButtons" )

Detailed Description

Public Functions

ConsoleDocClass(GuiToggleButtonCtrl , "@brief Deprecated gui <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">control.\n\n</a>" "@deprecated <a href="/coding/class/classguitogglebuttonctrl/">GuiToggleButtonCtrl</a>'s functionality is solely based on <a href="/coding/class/classguibuttonbasectrl/">GuiButtonBaseCtrl</a>'s ButtonTypeCheck <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">type.\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiButtonCtrl\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiCheckBoxCtrl\n</a>" "@ingroup GuiButtons" )

IMPLEMENT_CONOBJECT(GuiToggleButtonCtrl )

  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/guiToggleButtonCtrl.h"
 26
 27#include "console/console.h"
 28#include "console/consoleTypes.h"
 29#include "console/engineAPI.h"
 30#include "gfx/gfxDevice.h"
 31#include "gfx/gfxDrawUtil.h"
 32#include "gui/core/guiCanvas.h"
 33#include "gui/core/guiDefaultControlRender.h"
 34
 35IMPLEMENT_CONOBJECT(GuiToggleButtonCtrl);
 36
 37ConsoleDocClass( GuiToggleButtonCtrl,
 38   "@brief Deprecated gui control.\n\n"
 39   
 40   "@deprecated GuiToggleButtonCtrl's functionality is solely based on GuiButtonBaseCtrl's ButtonTypeCheck type.\n\n"
 41   
 42   "@see GuiButtonCtrl\n"
 43   "@see GuiCheckBoxCtrl\n"
 44   
 45   "@ingroup GuiButtons"
 46);
 47
 48//-----------------------------------------------------------------------------
 49
 50GuiToggleButtonCtrl::GuiToggleButtonCtrl()
 51{
 52   setExtent(140, 30);
 53   mButtonText = StringTable->EmptyString();
 54   mStateOn = false;
 55   mButtonType = ButtonTypeCheck;
 56}
 57
 58void GuiToggleButtonCtrl::onPreRender()
 59{
 60   Parent::onPreRender();
 61
 62   // If we have a script variable, make sure we're in sync
 63   if ( mConsoleVariable[0] )
 64      mStateOn = Con::getBoolVariable( mConsoleVariable );
 65}
 66
 67void GuiToggleButtonCtrl::onRender(Point2I      offset,
 68                                   const RectI& updateRect)
 69{
 70   bool highlight = mMouseOver;
 71   bool depressed = mDepressed;
 72
 73   ColorI fontColor   = mActive ? ( highlight ? mProfile->mFontColorHL : mProfile->mFontColor ) : mProfile->mFontColorNA;
 74   ColorI fillColor   = mActive ? ( highlight ? mProfile->mFillColorHL : mProfile->mFillColor ) : mProfile->mFillColorNA;
 75   ColorI borderColor = mActive ? ( highlight ? mProfile->mBorderColorHL : mProfile->mBorderColor ) : mProfile->mBorderColorNA;
 76
 77   RectI boundsRect(offset, getExtent());
 78
 79   if( !mHasTheme )
 80   {
 81      if( mProfile->mBorder != 0 )
 82         renderFilledBorder( boundsRect, borderColor, fillColor, mProfile->mBorderThickness );
 83      else
 84         GFX->getDrawUtil()->drawRectFill( boundsRect, fillColor );
 85   }
 86   else if( mHasTheme )
 87   {
 88      S32 indexMultiplier = 1;
 89      if ( !mActive )
 90         indexMultiplier = 4;
 91      else if ( mDepressed || mStateOn )
 92         indexMultiplier = 2;
 93      else if ( mMouseOver )
 94         indexMultiplier = 3;
 95
 96
 97      renderSizableBitmapBordersFilled( boundsRect, indexMultiplier, mProfile );
 98   }
 99
100   Point2I textPos = offset;
101   if(depressed)
102      textPos += Point2I(1,1);
103
104   GFX->getDrawUtil()->setBitmapModulation( fontColor );
105   renderJustifiedText(textPos, getExtent(), mButtonText);
106
107   //render the children
108   renderChildControls( offset, updateRect);
109}
110