guiIconButtonCtrl.cpp
Engine/source/gui/buttons/guiIconButtonCtrl.cpp
Public Variables
Public Functions
ConsoleDocClass(GuiIconButtonCtrl , "@brief Draws the bitmap within <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> special button control. Only <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> single bitmap is used and <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">the\n</a>" "button will be drawn in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> highlighted <a href="/coding/file/zipobject_8cpp/#zipobject_8cpp_1ac6c3dfb4c3a68f849f32cbfb21da4e77">mode</a> when the mouse hovers over it or when <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">it\n</a>" "has been <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">clicked.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classguiiconbuttonctrl/">GuiIconButtonCtrl</a>(TestIconButton)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " buttonMargin = \"4 4\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " iconBitmap = \"art/gui/lagIcon.png\";\n" " iconLocation = \"Center\";\n" " sizeIconToButton = \"0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " makeIconSquare = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " textLocation = \"Bottom\";\n" " textMargin = \"-2\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " autoSize = \"0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " text = \"Lag Icon\";\n" " textID = \"\"STR_LAG\"\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " buttonType = \"PushButton\";\n" " profile = \"GuiIconButtonProfile\";\n" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiControl\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiButtonCtrl\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiCore\n</a>" )
DefineEngineMethod(GuiIconButtonCtrl , setBitmap , void , (const char *buttonFilename) , "@brief Set the bitmap <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> use <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the button portion of this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">control.\n\n</a>" "@param buttonFilename Filename <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">image\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Define the button <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">filename\n</a>" "% buttonFilename)
ImplementEnumType(GuiIconButtonIconLocation , "\n\n" "@ingroup GuiImages" )
ImplementEnumType(GuiIconButtonTextLocation , "\n\n" "@ingroup GuiImages" )
Detailed Description
Public Variables
const ColorI colorBlack (0, 0, 0)
const ColorI colorWhite (255, 255, 255)
EndImplementEnumType
Public Functions
ConsoleDocClass(GuiIconButtonCtrl , "@brief Draws the bitmap within <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> special button control. Only <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> single bitmap is used and <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">the\n</a>" "button will be drawn in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> highlighted <a href="/coding/file/zipobject_8cpp/#zipobject_8cpp_1ac6c3dfb4c3a68f849f32cbfb21da4e77">mode</a> when the mouse hovers over it or when <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">it\n</a>" "has been <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">clicked.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classguiiconbuttonctrl/">GuiIconButtonCtrl</a>(TestIconButton)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " buttonMargin = \"4 4\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " iconBitmap = \"art/gui/lagIcon.png\";\n" " iconLocation = \"Center\";\n" " sizeIconToButton = \"0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " makeIconSquare = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " textLocation = \"Bottom\";\n" " textMargin = \"-2\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " autoSize = \"0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " text = \"Lag Icon\";\n" " textID = \"\"STR_LAG\"\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " buttonType = \"PushButton\";\n" " profile = \"GuiIconButtonProfile\";\n" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiControl\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiButtonCtrl\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiCore\n</a>" )
DefineEngineMethod(GuiIconButtonCtrl , setBitmap , void , (const char *buttonFilename) , "@brief Set the bitmap <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> use <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the button portion of this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">control.\n\n</a>" "@param buttonFilename Filename <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">image\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Define the button <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">filename\n</a>" "% buttonFilename)
IMPLEMENT_CONOBJECT(GuiIconButtonCtrl )
ImplementEnumType(GuiIconButtonIconLocation , "\n\n" "@ingroup GuiImages" )
ImplementEnumType(GuiIconButtonTextLocation , "\n\n" "@ingroup GuiImages" )
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 25//------------------------------------- 26// 27// Icon Button Control 28// Draws the bitmap within a special button control. Only a single bitmap is used and the 29// button will be drawn in a highlighted mode when the mouse hovers over it or when it 30// has been clicked. 31// 32// Use mTextLocation to choose where within the button the text will be drawn, if at all. 33// Use mTextMargin to set the text away from the button sides or from the bitmap. 34// Use mButtonMargin to set everything away from the button sides. 35// Use mErrorBitmapName to set the name of a bitmap to draw if the main bitmap cannot be found. 36// Use mFitBitmapToButton to force the bitmap to fill the entire button extent. Usually used 37// with no button text defined. 38// 39// 40 41#include "platform/platform.h" 42#include "gui/buttons/guiIconButtonCtrl.h" 43 44#include "console/console.h" 45#include "gfx/gfxDevice.h" 46#include "gfx/gfxDrawUtil.h" 47#include "console/consoleTypes.h" 48#include "gui/core/guiCanvas.h" 49#include "gui/core/guiDefaultControlRender.h" 50#include "console/engineAPI.h" 51 52static const ColorI colorWhite(255,255,255); 53static const ColorI colorBlack(0,0,0); 54 55IMPLEMENT_CONOBJECT(GuiIconButtonCtrl); 56 57ConsoleDocClass( GuiIconButtonCtrl, 58 "@brief Draws the bitmap within a special button control. Only a single bitmap is used and the\n" 59 "button will be drawn in a highlighted mode when the mouse hovers over it or when it\n" 60 "has been clicked.\n\n" 61 62 "@tsexample\n" 63 "new GuiIconButtonCtrl(TestIconButton)\n" 64 "{\n" 65 " buttonMargin = \"4 4\";\n" 66 " iconBitmap = \"art/gui/lagIcon.png\";\n" 67 " iconLocation = \"Center\";\n" 68 " sizeIconToButton = \"0\";\n" 69 " makeIconSquare = \"1\";\n" 70 " textLocation = \"Bottom\";\n" 71 " textMargin = \"-2\";\n" 72 " autoSize = \"0\";\n" 73 " text = \"Lag Icon\";\n" 74 " textID = \"\"STR_LAG\"\";\n" 75 " buttonType = \"PushButton\";\n" 76 " profile = \"GuiIconButtonProfile\";\n" 77 "};\n" 78 "@endtsexample\n\n" 79 80 "@see GuiControl\n" 81 "@see GuiButtonCtrl\n\n" 82 83 "@ingroup GuiCore\n" 84); 85 86 87GuiIconButtonCtrl::GuiIconButtonCtrl() 88{ 89 mBitmapName = StringTable->EmptyString(); 90 mTextLocation = TextLocLeft; 91 mIconLocation = IconLocLeft; 92 mTextMargin = 4; 93 mButtonMargin.set(4,4); 94 95 mFitBitmapToButton = false; 96 mMakeIconSquare = false; 97 98 mErrorBitmapName = StringTable->EmptyString(); 99 mErrorTextureHandle = NULL; 100 101 mAutoSize = false; 102 103 setExtent(140, 30); 104} 105 106ImplementEnumType( GuiIconButtonTextLocation, 107 "\n\n" 108 "@ingroup GuiImages" ) 109 { GuiIconButtonCtrl::TextLocNone, "None" }, 110 { GuiIconButtonCtrl::TextLocBottom, "Bottom" }, 111 { GuiIconButtonCtrl::TextLocRight, "Right" }, 112 { GuiIconButtonCtrl::TextLocTop, "Top" }, 113 { GuiIconButtonCtrl::TextLocLeft, "Left" }, 114 { GuiIconButtonCtrl::TextLocCenter, "Center" }, 115EndImplementEnumType; 116 117ImplementEnumType( GuiIconButtonIconLocation, 118 "\n\n" 119 "@ingroup GuiImages" ) 120 { GuiIconButtonCtrl::IconLocNone, "None" }, 121 { GuiIconButtonCtrl::IconLocLeft, "Left" }, 122 { GuiIconButtonCtrl::IconLocRight, "Right" }, 123 { GuiIconButtonCtrl::IconLocCenter, "Center" } 124EndImplementEnumType; 125 126void GuiIconButtonCtrl::initPersistFields() 127{ 128 addField( "buttonMargin", TypePoint2I, Offset( mButtonMargin, GuiIconButtonCtrl ),"Margin area around the button.\n"); 129 addField( "iconBitmap", TypeFilename, Offset( mBitmapName, GuiIconButtonCtrl ),"Bitmap file for the icon to display on the button.\n"); 130 addField( "iconLocation", TYPEID< IconLocation >(), Offset( mIconLocation, GuiIconButtonCtrl ),"Where to place the icon on the control. Options are 0 (None), 1 (Left), 2 (Right), 3 (Center).\n"); 131 addField( "sizeIconToButton", TypeBool, Offset( mFitBitmapToButton, GuiIconButtonCtrl ),"If true, the icon will be scaled to be the same size as the button.\n"); 132 addField( "makeIconSquare", TypeBool, Offset( mMakeIconSquare, GuiIconButtonCtrl ),"If true, will make sure the icon is square.\n"); 133 addField( "textLocation", TYPEID< TextLocation >(), Offset( mTextLocation, GuiIconButtonCtrl ),"Where to place the text on the control.\n" 134 "Options are 0 (None), 1 (Bottom), 2 (Right), 3 (Top), 4 (Left), 5 (Center).\n"); 135 addField( "textMargin", TypeS32, Offset( mTextMargin, GuiIconButtonCtrl ),"Margin between the icon and the text.\n"); 136 addField( "autoSize", TypeBool, Offset( mAutoSize, GuiIconButtonCtrl ),"If true, the text and icon will be automatically sized to the size of the control.\n"); 137 Parent::initPersistFields(); 138} 139 140bool GuiIconButtonCtrl::onWake() 141{ 142 if (! Parent::onWake()) 143 return false; 144 setActive(true); 145 146 setBitmap(mBitmapName); 147 148 if( mProfile ) 149 mProfile->constructBitmapArray(); 150 151 return true; 152} 153 154void GuiIconButtonCtrl::onSleep() 155{ 156 mTextureNormal = NULL; 157 Parent::onSleep(); 158} 159 160void GuiIconButtonCtrl::inspectPostApply() 161{ 162 Parent::inspectPostApply(); 163} 164 165void GuiIconButtonCtrl::onStaticModified(const char* slotName, const char* newValue) 166{ 167 if ( isProperlyAdded() && !dStricmp(slotName, "autoSize") ) 168 resize( getPosition(), getExtent() ); 169} 170 171bool GuiIconButtonCtrl::resize(const Point2I &newPosition, const Point2I &newExtent) 172{ 173 if ( !mAutoSize || !mProfile->mFont ) 174 return Parent::resize( newPosition, newExtent ); 175 176 Point2I autoExtent( mMinExtent ); 177 178 if ( mIconLocation != IconLocNone ) 179 { 180 autoExtent.y = mTextureNormal.getHeight() + mButtonMargin.y * 2; 181 autoExtent.x = mTextureNormal.getWidth() + mButtonMargin.x * 2; 182 } 183 184 if ( mTextLocation != TextLocNone && mButtonText && mButtonText[0] ) 185 { 186 U32 strWidth = mProfile->mFont->getStrWidthPrecise( mButtonText ); 187 188 if ( mTextLocation == TextLocLeft || mTextLocation == TextLocRight ) 189 { 190 autoExtent.x += strWidth + mTextMargin * 2; 191 } 192 else // Top, Bottom, Center 193 { 194 strWidth += mTextMargin * 2; 195 if ( strWidth > autoExtent.x ) 196 autoExtent.x = strWidth; 197 } 198 } 199 200 return Parent::resize( newPosition, autoExtent ); 201} 202 203void GuiIconButtonCtrl::setBitmap(const char *name) 204{ 205 mBitmapName = StringTable->insert(name); 206 if(!isAwake()) 207 return; 208 209 if (*mBitmapName) 210 { 211 mTextureNormal = GFXTexHandle( name, &GFXTexturePersistentSRGBProfile, avar("%s() - mTextureNormal (line %d)", __FUNCTION__, __LINE__) ); 212 } 213 else 214 { 215 mTextureNormal = NULL; 216 } 217 218 // So that extent is recalculated if autoSize is set. 219 resize( getPosition(), getExtent() ); 220 221 setUpdate(); 222} 223 224void GuiIconButtonCtrl::onRender(Point2I offset, const RectI& updateRect) 225{ 226 renderButton( offset, updateRect); 227} 228 229void GuiIconButtonCtrl::renderButton( Point2I &offset, const RectI& updateRect ) 230{ 231 bool highlight = mMouseOver; 232 bool depressed = mDepressed; 233 234 ColorI fontColor = mActive ? (highlight ? mProfile->mFontColorHL : mProfile->mFontColor) : mProfile->mFontColorNA; 235 236 RectI boundsRect(offset, getExtent()); 237 238 GFXDrawUtil *drawer = GFX->getDrawUtil(); 239 240 if (mDepressed || mStateOn) 241 { 242 // If there is a bitmap array then render using it. 243 // Otherwise use a standard fill. 244 if(mProfile->mUseBitmapArray && mProfile->mBitmapArrayRects.size()) 245 renderBitmapArray(boundsRect, statePressed); 246 else 247 renderSlightlyLoweredBox(boundsRect, mProfile); 248 } 249 else if(mMouseOver && mActive) 250 { 251 // If there is a bitmap array then render using it. 252 // Otherwise use a standard fill. 253 if(mProfile->mUseBitmapArray && mProfile->mBitmapArrayRects.size()) 254 renderBitmapArray(boundsRect, stateMouseOver); 255 else 256 renderSlightlyRaisedBox(boundsRect, mProfile); 257 } 258 else 259 { 260 // If there is a bitmap array then render using it. 261 // Otherwise use a standard fill. 262 if(mProfile->mUseBitmapArray && mProfile->mBitmapArrayRects.size()) 263 { 264 if(mActive) 265 renderBitmapArray(boundsRect, stateNormal); 266 else 267 renderBitmapArray(boundsRect, stateDisabled); 268 } 269 else 270 { 271 drawer->drawRectFill(boundsRect, mProfile->mFillColorNA); 272 drawer->drawRect(boundsRect, mProfile->mBorderColorNA); 273 } 274 } 275 276 Point2I textPos = offset; 277 if(depressed) 278 textPos += Point2I(1,1); 279 280 RectI iconRect( 0, 0, 0, 0 ); 281 282 // Render the icon 283 if ( mTextureNormal && mIconLocation != GuiIconButtonCtrl::IconLocNone ) 284 { 285 // Render the normal bitmap 286 drawer->clearBitmapModulation(); 287 288 // Maintain the bitmap size or fill the button? 289 if ( !mFitBitmapToButton ) 290 { 291 Point2I textureSize( mTextureNormal->getWidth(), mTextureNormal->getHeight() ); 292 iconRect.set( offset + mButtonMargin, textureSize ); 293 294 if ( mIconLocation == IconLocRight ) 295 { 296 iconRect.point.x = ( offset.x + getWidth() ) - ( mButtonMargin.x + textureSize.x ); 297 iconRect.point.y = offset.y + ( getHeight() - textureSize.y ) / 2; 298 } 299 else if ( mIconLocation == IconLocLeft ) 300 { 301 iconRect.point.x = offset.x + mButtonMargin.x; 302 iconRect.point.y = offset.y + ( getHeight() - textureSize.y ) / 2; 303 } 304 else if ( mIconLocation == IconLocCenter ) 305 { 306 iconRect.point.x = offset.x + ( getWidth() - textureSize.x ) / 2; 307 iconRect.point.y = offset.y + ( getHeight() - textureSize.y ) / 2; 308 } 309 310 drawer->drawBitmapStretch( mTextureNormal, iconRect ); 311 312 } 313 else 314 { 315 iconRect.set( offset + mButtonMargin, getExtent() - (mButtonMargin * 2) ); 316 317 if ( mMakeIconSquare ) 318 { 319 // Square the icon to the smaller axis extent. 320 if ( iconRect.extent.x < iconRect.extent.y ) 321 iconRect.extent.y = iconRect.extent.x; 322 else 323 iconRect.extent.x = iconRect.extent.y; 324 } 325 326 drawer->drawBitmapStretch( mTextureNormal, iconRect ); 327 } 328 } 329 330 // Render text 331 if ( mTextLocation != TextLocNone ) 332 { 333 // Clip text to fit (appends ...), 334 // pad some space to keep it off our border 335 String text( mButtonText ); 336 S32 textWidth = clipText( text, getWidth() - 4 - mTextMargin ); 337 338 drawer->setBitmapModulation( fontColor ); 339 340 if ( mTextLocation == TextLocRight ) 341 { 342 Point2I start( mTextMargin, ( getHeight() - mProfile->mFont->getHeight() ) / 2 ); 343 if ( mTextureNormal && mIconLocation != IconLocNone ) 344 { 345 start.x = iconRect.extent.x + mButtonMargin.x + mTextMargin; 346 } 347 348 drawer->drawText( mProfile->mFont, start + offset, text, mProfile->mFontColors ); 349 } 350 351 if ( mTextLocation == TextLocLeft ) 352 { 353 Point2I start( mTextMargin, ( getHeight() - mProfile->mFont->getHeight() ) / 2 ); 354 355 drawer->drawText( mProfile->mFont, start + offset, text, mProfile->mFontColors ); 356 } 357 358 if ( mTextLocation == TextLocCenter ) 359 { 360 Point2I start; 361 if ( mTextureNormal && mIconLocation == IconLocLeft ) 362 { 363 start.set( ( getWidth() - textWidth - iconRect.extent.x ) / 2 + iconRect.extent.x, 364 ( getHeight() - mProfile->mFont->getHeight() ) / 2 ); 365 } 366 else 367 start.set( ( getWidth() - textWidth ) / 2, ( getHeight() - mProfile->mFont->getHeight() ) / 2 ); 368 drawer->setBitmapModulation( fontColor ); 369 drawer->drawText( mProfile->mFont, start + offset, text, mProfile->mFontColors ); 370 } 371 372 if ( mTextLocation == TextLocBottom ) 373 { 374 Point2I start; 375 start.set( ( getWidth() - textWidth ) / 2, getHeight() - mProfile->mFont->getHeight() - mTextMargin ); 376 377 // If the text is longer then the box size 378 // it will get clipped, force Left Justify 379 if( textWidth > getWidth() ) 380 start.x = 0; 381 382 drawer->setBitmapModulation( fontColor ); 383 drawer->drawText( mProfile->mFont, start + offset, text, mProfile->mFontColors ); 384 } 385 } 386 387 renderChildControls( offset, updateRect); 388} 389 390// Draw the bitmap array's borders according to the button's state. 391void GuiIconButtonCtrl::renderBitmapArray(RectI &bounds, S32 state) 392{ 393 switch(state) 394 { 395 case stateNormal: 396 if(mProfile->mBorder == -2) 397 renderSizableBitmapBordersFilled(bounds, 1, mProfile); 398 else 399 renderFixedBitmapBordersFilled(bounds, 1, mProfile); 400 break; 401 402 case stateMouseOver: 403 if(mProfile->mBorder == -2) 404 renderSizableBitmapBordersFilled(bounds, 2, mProfile); 405 else 406 renderFixedBitmapBordersFilled(bounds, 2, mProfile); 407 break; 408 409 case statePressed: 410 if(mProfile->mBorder == -2) 411 renderSizableBitmapBordersFilled(bounds, 3, mProfile); 412 else 413 renderFixedBitmapBordersFilled(bounds, 3, mProfile); 414 break; 415 416 case stateDisabled: 417 if(mProfile->mBorder == -2) 418 renderSizableBitmapBordersFilled(bounds, 4, mProfile); 419 else 420 renderFixedBitmapBordersFilled(bounds, 4, mProfile); 421 break; 422 } 423} 424 425DefineEngineMethod( GuiIconButtonCtrl, setBitmap, void, (const char* buttonFilename),, 426 "@brief Set the bitmap to use for the button portion of this control.\n\n" 427 "@param buttonFilename Filename for the image\n" 428 "@tsexample\n" 429 "// Define the button filename\n" 430 "%buttonFilename = \"pearlButton\";\n\n" 431 "// Inform the GuiIconButtonCtrl control to update its main button graphic to the defined bitmap\n" 432 "%thisGuiIconButtonCtrl.setBitmap(%buttonFilename);\n" 433 "@endtsexample\n\n" 434 "@see GuiControl\n" 435 "@see GuiButtonCtrl\n\n") 436{ 437 char* argBuffer = Con::getArgBuffer( 512 ); 438 Platform::makeFullPathName( buttonFilename, argBuffer, 512 ); 439 object->setBitmap( argBuffer ); 440} 441