Torque3D Documentation / _generateds / guiSwatchButtonCtrl.cpp

guiSwatchButtonCtrl.cpp

Engine/source/gui/buttons/guiSwatchButtonCtrl.cpp

More...

Public Functions

ConsoleDocClass(GuiSwatchButtonCtrl , "@brief A button that is used <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> represent color; often used in correlation with <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> color <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">picker.\n\n</a>" "A swatch button is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> push button that uses its color field <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> designate the color drawn over an image)
DefineEngineMethod(GuiSwatchButtonCtrl , setColor , void , (const char *newColor) , "Set the color of the swatch <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">control.\n</a>" "@param newColor The <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> color string given <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the swatch <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> in float format \"r g <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a91b64995742fd30063314f12340b4b5a">b</a> a\".\n" "@note It's also important <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> note that when setColor is called <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">causes\n</a>" "the <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a>'s altCommand field <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be executed." )

Detailed Description

Public Functions

ConsoleDocClass(GuiSwatchButtonCtrl , "@brief A button that is used <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> represent color; often used in correlation with <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> color <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">picker.\n\n</a>" "A swatch button is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> push button that uses its color field <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> designate the color drawn over an image)

DefineEngineMethod(GuiSwatchButtonCtrl , setColor , void , (const char *newColor) , "Set the color of the swatch <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">control.\n</a>" "@param newColor The <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> color string given <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the swatch <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> in float format \"r g <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a91b64995742fd30063314f12340b4b5a">b</a> a\".\n" "@note It's also important <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> note that when setColor is called <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">causes\n</a>" "the <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a>'s altCommand field <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be executed." )

IMPLEMENT_CONOBJECT(GuiSwatchButtonCtrl )

  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/guiSwatchButtonCtrl.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( GuiSwatchButtonCtrl );
 36
 37ConsoleDocClass( GuiSwatchButtonCtrl,
 38   "@brief A button that is used to represent color; often used in correlation with a color picker.\n\n"
 39   
 40   "A swatch button is a push button that uses its color field to designate the color drawn over an image, on top of a button.\n\n"
 41   
 42   "The color itself is a float value stored inside the GuiSwatchButtonCtrl::color field. The texture path that represents\n"
 43   "the image underlying the color is stored inside the GuiSwatchButtonCtrl::gridBitmap field.\n"
 44   "The default value assigned toGuiSwatchButtonCtrl::color is \"1 1 1 1\"( White ). The default/fallback image assigned to \n"
 45   "GuiSwatchButtonCtrl::gridBitmap is \"tools/gui/images/transp_grid\".\n\n"
 46   
 47   "@tsexample\n"
 48   "// Create a GuiSwatchButtonCtrl that calls randomFunction with its current color when clicked\n"
 49   "%swatchButton = new GuiSwatchButtonCtrl()\n"
 50   "{\n"
 51   "   profile = \"GuiInspectorSwatchButtonProfile\";\n"
 52   "   command = \"randomFunction( $ThisControl.color );\";\n"
 53   "};\n"
 54   "@endtsexample\n\n"
 55   
 56   "@ingroup GuiButtons"
 57);
 58
 59//-----------------------------------------------------------------------------
 60
 61GuiSwatchButtonCtrl::GuiSwatchButtonCtrl()
 62   : mSwatchColor(1, 1, 1, 1)
 63{
 64   mButtonText = StringTable->insert( "" );   
 65   setExtent(140, 30);
 66   
 67   static StringTableEntry sProfile = StringTable->insert( "profile" );
 68   setDataField( sProfile, NULL, "GuiInspectorSwatchButtonProfile" );
 69
 70   mGridBitmap = "tools/gui/images/transp_grid";
 71}
 72
 73void GuiSwatchButtonCtrl::initPersistFields()
 74{
 75   addField("color", TypeColorF, Offset(mSwatchColor, GuiSwatchButtonCtrl), "The foreground color of GuiSwatchButtonCtrl");
 76   addField( "gridBitmap", TypeRealString, Offset( mGridBitmap, GuiSwatchButtonCtrl ), "The bitmap used for the transparent grid" );
 77   
 78   Parent::initPersistFields();
 79}
 80
 81bool GuiSwatchButtonCtrl::onWake()
 82{      
 83   if ( !Parent::onWake() )
 84      return false;
 85
 86   if ( mGrid.isNull() )
 87      mGrid.set( mGridBitmap, &GFXDefaultGUIProfile, avar("%s() - mGrid (line %d)", __FUNCTION__, __LINE__) );
 88
 89   return true;
 90}
 91
 92void GuiSwatchButtonCtrl::onRender( Point2I offset, const RectI &updateRect )
 93{
 94   bool highlight = mMouseOver;
 95
 96   ColorI borderColor = mActive ? ( highlight ? mProfile->mBorderColorHL : mProfile->mBorderColor ) : mProfile->mBorderColorNA;
 97
 98   RectI renderRect( offset, getExtent() );
 99   if ( !highlight )
100      renderRect.inset( 1, 1 );      
101
102   GFXDrawUtil *drawer = GFX->getDrawUtil();
103   drawer->clearBitmapModulation();
104
105   // Draw background transparency grid texture...
106   if ( mGrid.isValid() )
107      drawer->drawBitmapStretch( mGrid, renderRect );
108
109   // Draw swatch color as fill...
110   drawer->drawRectFill(renderRect, mSwatchColor.toColorI());
111
112   // Draw any borders...
113   drawer->drawRect( renderRect, borderColor );
114}
115
116//-----------------------------------------------------------------------------
117
118DefineEngineMethod( GuiSwatchButtonCtrl, setColor, void, ( const char* newColor ),,
119   "Set the color of the swatch control.\n"
120   "@param newColor The new color string given to the swatch control in float format \"r g b a\".\n"
121   "@note It's also important to note that when setColor is called causes\n"
122   "the control's altCommand field to be executed." )
123{
124   object->setField( "color", newColor );
125   object->execAltConsoleCallback();
126}
127