guiButtonCtrl.cc 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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 "console/console.h"
  23. #include "graphics/dgl.h"
  24. #include "console/consoleTypes.h"
  25. #include "platform/platformAudio.h"
  26. #include "gui/guiCanvas.h"
  27. #include "gui/buttons/guiButtonCtrl.h"
  28. #include "gui/guiDefaultControlRender.h"
  29. IMPLEMENT_CONOBJECT(GuiButtonCtrl);
  30. GuiButtonCtrl::GuiButtonCtrl()
  31. {
  32. mBounds.extent.set(140, 30);
  33. mButtonText = StringTable->EmptyString;
  34. }
  35. bool GuiButtonCtrl::onWake()
  36. {
  37. if( !Parent::onWake() )
  38. return false;
  39. // Button Theme?
  40. if( mProfile->constructBitmapArray() >= 36 )
  41. mHasTheme = true;
  42. else
  43. mHasTheme = false;
  44. return true;
  45. }
  46. //--------------------------------------------------------------------------
  47. void GuiButtonCtrl::onRender(Point2I offset,
  48. const RectI& updateRect)
  49. {
  50. bool highlight = mMouseOver;
  51. bool depressed = mDepressed;
  52. ColorI fontColor = mActive ? (highlight ? mProfile->mFontColorHL : mProfile->mFontColor) : mProfile->mFontColorNA;
  53. ColorI backColor = mActive ? mProfile->mFillColor : mProfile->mFillColorNA;
  54. ColorI borderColor = mActive ? mProfile->mBorderColor : mProfile->mBorderColorNA;
  55. RectI boundsRect(offset, mBounds.extent);
  56. if( mProfile->mBorder != 0 && !mHasTheme )
  57. {
  58. if (mDepressed || mStateOn)
  59. renderFilledBorder( boundsRect, mProfile->mBorderColorHL, mProfile->mFillColorHL );
  60. else
  61. renderFilledBorder( boundsRect, mProfile->mBorderColor, mProfile->mFillColor );
  62. }
  63. else if( mHasTheme )
  64. {
  65. S32 indexMultiplier = 1;
  66. if ( mDepressed || mStateOn )
  67. indexMultiplier = 3;
  68. else if ( mMouseOver )
  69. indexMultiplier = 2;
  70. else if ( !mActive )
  71. indexMultiplier = 4;
  72. renderSizableBitmapBordersFilled( boundsRect, indexMultiplier, mProfile );
  73. }
  74. Point2I textPos = offset;
  75. if(depressed)
  76. textPos += Point2I(1,1);
  77. dglSetBitmapModulation( fontColor );
  78. renderJustifiedText(textPos, mBounds.extent, mButtonText);
  79. //render the children
  80. renderChildControls( offset, updateRect);
  81. }