Torque3D Documentation / _generateds / guiButtonCtrl.cpp

guiButtonCtrl.cpp

Engine/source/gui/buttons/guiButtonCtrl.cpp

More...

Public Functions

ConsoleDocClass(GuiButtonCtrl , "@brief The most widely used button <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">class.\n\n</a>" "<a href="/coding/class/classguibuttonctrl/">GuiButtonCtrl</a> renders seperately of)

Detailed Description

Public Functions

ConsoleDocClass(GuiButtonCtrl , "@brief The most widely used button <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">class.\n\n</a>" "<a href="/coding/class/classguibuttonctrl/">GuiButtonCtrl</a> renders seperately of)

IMPLEMENT_CONOBJECT(GuiButtonCtrl )

  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/guiButtonCtrl.h"
 26
 27#include "console/console.h"
 28#include "console/consoleTypes.h"
 29#include "gfx/gfxDevice.h"
 30#include "gfx/gfxDrawUtil.h"
 31#include "gui/core/guiCanvas.h"
 32#include "gui/core/guiDefaultControlRender.h"
 33
 34IMPLEMENT_CONOBJECT(GuiButtonCtrl);
 35
 36ConsoleDocClass( GuiButtonCtrl,
 37   "@brief The most widely used button class.\n\n"
 38   
 39   "GuiButtonCtrl renders seperately of, but utilizes all of the functionality of GuiBaseButtonCtrl.\n" 
 40   "This grants GuiButtonCtrl the versatility to be either of the 3 button types.\n\n"
 41
 42   "@tsexample\n"
 43   "// Create a PushButton GuiButtonCtrl that calls randomFunction when clicked\n"
 44   "%button = new GuiButtonCtrl()\n"
 45   "{\n"
 46   "   profile    = \"GuiButtonProfile\";\n"
 47   "   buttonType = \"PushButton\";\n"
 48   "   command    = \"randomFunction();\";\n"
 49   "};\n"
 50   "@endtsexample\n\n"
 51   
 52   "@ingroup GuiButtons"
 53);
 54
 55
 56//-----------------------------------------------------------------------------
 57
 58GuiButtonCtrl::GuiButtonCtrl()
 59{
 60   setExtent(140, 30);
 61   mButtonText = StringTable->EmptyString();
 62   mHasTheme = false;
 63}
 64
 65//-----------------------------------------------------------------------------
 66
 67bool GuiButtonCtrl::onWake()
 68{
 69   if( !Parent::onWake() )
 70      return false;
 71
 72   // Button Theme?
 73   if( mProfile->constructBitmapArray() >= 36 )
 74      mHasTheme = true;
 75   else
 76      mHasTheme = false;
 77
 78   return true;
 79
 80}
 81
 82//-----------------------------------------------------------------------------
 83
 84void GuiButtonCtrl::onRender(Point2I      offset,
 85                             const RectI& updateRect)
 86{
 87   bool highlight = mMouseOver;
 88   bool depressed = mDepressed;
 89
 90   ColorI fontColor   = mActive ? ( highlight ? mProfile->mFontColorHL : mProfile->mFontColor ) : mProfile->mFontColorNA;
 91   ColorI fillColor   = mActive ? ( highlight ? mProfile->mFillColorHL : mProfile->mFillColor ) : mProfile->mFillColorNA;
 92   ColorI borderColor = mActive ? ( highlight ? mProfile->mBorderColorHL : mProfile->mBorderColor ) : mProfile->mBorderColorNA;
 93
 94   RectI boundsRect(offset, getExtent());
 95
 96   if( !mHasTheme )
 97   {
 98      if( mProfile->mBorder != 0 )
 99         renderFilledBorder( boundsRect, borderColor, fillColor, mProfile->mBorderThickness );
100      else
101         GFX->getDrawUtil()->drawRectFill( boundsRect, fillColor );
102   }
103   else
104   {
105      S32 indexMultiplier = 1;
106      
107      if( !mActive )
108         indexMultiplier = 4;
109      else if ( mDepressed || mStateOn )
110         indexMultiplier = 2;
111      else if ( mMouseOver )
112         indexMultiplier = 3;
113
114      renderSizableBitmapBordersFilled( boundsRect, indexMultiplier, mProfile );
115   }
116
117   Point2I textPos = offset;
118   if( depressed )
119      textPos += Point2I( 1, 1 );
120
121   GFX->getDrawUtil()->setBitmapModulation( fontColor );
122   renderJustifiedText( textPos, getExtent(), mButtonText );
123
124   //render the children
125   renderChildControls( offset, updateRect);
126}
127