guiToggleButtonCtrl.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "gui/buttons/guiToggleButtonCtrl.h"
  24. #include "console/console.h"
  25. #include "console/consoleTypes.h"
  26. #include "console/engineAPI.h"
  27. #include "gfx/gfxDevice.h"
  28. #include "gfx/gfxDrawUtil.h"
  29. #include "gui/core/guiCanvas.h"
  30. #include "gui/core/guiDefaultControlRender.h"
  31. IMPLEMENT_CONOBJECT(GuiToggleButtonCtrl);
  32. ConsoleDocClass( GuiToggleButtonCtrl,
  33. "@brief Deprecated gui control.\n\n"
  34. "@deprecated GuiToggleButtonCtrl's functionality is solely based on GuiButtonBaseCtrl's ButtonTypeCheck type.\n\n"
  35. "@see GuiButtonCtrl\n"
  36. "@see GuiCheckBoxCtrl\n"
  37. "@ingroup GuiButtons"
  38. );
  39. //-----------------------------------------------------------------------------
  40. GuiToggleButtonCtrl::GuiToggleButtonCtrl()
  41. {
  42. setExtent(140, 30);
  43. mButtonText = StringTable->insert("");
  44. mStateOn = false;
  45. mButtonType = ButtonTypeCheck;
  46. }
  47. void GuiToggleButtonCtrl::onPreRender()
  48. {
  49. Parent::onPreRender();
  50. // If we have a script variable, make sure we're in sync
  51. if ( mConsoleVariable[0] )
  52. mStateOn = Con::getBoolVariable( mConsoleVariable );
  53. }
  54. void GuiToggleButtonCtrl::onRender(Point2I offset,
  55. const RectI& updateRect)
  56. {
  57. bool highlight = mMouseOver;
  58. bool depressed = mDepressed;
  59. ColorI fontColor = mActive ? ( highlight ? mProfile->mFontColorHL : mProfile->mFontColor ) : mProfile->mFontColorNA;
  60. ColorI fillColor = mActive ? ( highlight ? mProfile->mFillColorHL : mProfile->mFillColor ) : mProfile->mFillColorNA;
  61. ColorI borderColor = mActive ? ( highlight ? mProfile->mBorderColorHL : mProfile->mBorderColor ) : mProfile->mBorderColorNA;
  62. RectI boundsRect(offset, getExtent());
  63. if( !mHasTheme )
  64. {
  65. if( mProfile->mBorder != 0 )
  66. renderFilledBorder( boundsRect, borderColor, fillColor, mProfile->mBorderThickness );
  67. else
  68. GFX->getDrawUtil()->drawRectFill( boundsRect, fillColor );
  69. }
  70. else if( mHasTheme )
  71. {
  72. S32 indexMultiplier = 1;
  73. if ( !mActive )
  74. indexMultiplier = 4;
  75. else if ( mDepressed || mStateOn )
  76. indexMultiplier = 2;
  77. else if ( mMouseOver )
  78. indexMultiplier = 3;
  79. renderSizableBitmapBordersFilled( boundsRect, indexMultiplier, mProfile );
  80. }
  81. Point2I textPos = offset;
  82. if(depressed)
  83. textPos += Point2I(1,1);
  84. GFX->getDrawUtil()->setBitmapModulation( fontColor );
  85. renderJustifiedText(textPos, getExtent(), mButtonText);
  86. //render the children
  87. renderChildControls( offset, updateRect);
  88. }