guiPanel.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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/containers/guiPanel.h"
  24. #include "console/consoleTypes.h"
  25. #include "gfx/primBuilder.h"
  26. #include "gfx/gfxDrawUtil.h"
  27. //-----------------------------------------------------------------------------
  28. // GuiPanel
  29. //-----------------------------------------------------------------------------
  30. ConsoleDocClass( GuiPanel,
  31. "@brief The GuiPanel panel is a container that when opaque will "
  32. "draw a left to right gradient using its profile fill and "
  33. "fill highlight colors.\n\n"
  34. "@tsexample\n"
  35. "// Mandatory GuiDefaultProfile\n"
  36. "// Contains the fill color information required by a GuiPanel\n"
  37. "// Some values left out for sake of this example\n"
  38. "new GuiControlProfile (GuiDefaultProfile)\n"
  39. "{\n"
  40. " // fill color\n"
  41. " opaque = false;\n"
  42. " fillColor = \"242 241 240\";\n"
  43. " fillColorHL =\"228 228 235\";\n"
  44. " fillColorSEL = \"98 100 137\";\n"
  45. " fillColorNA = \"255 255 255 \";\n"
  46. "};\n\n"
  47. "new GuiPanel(TestPanel)\n"
  48. "{\n"
  49. " position = \"45 33\";\n"
  50. " extent = \"342 379\";\n"
  51. " minExtent = \"16 16\";\n"
  52. " horizSizing = \"right\";\n"
  53. " vertSizing = \"bottom\";\n"
  54. " profile = \"GuiDefaultProfile\"; // Color fill info is in this profile\n"
  55. " isContainer = \"1\";\n"
  56. "};\n"
  57. "@endtsexample\n\n"
  58. "@see GuiControlProfile\n"
  59. "@ingroup GuiContainers\n");
  60. GuiPanel::GuiPanel()
  61. {
  62. setMinExtent( Point2I( 16,16 ) );
  63. setDocking( Docking::dockNone );
  64. mIsContainer = true;
  65. }
  66. GuiPanel::~GuiPanel()
  67. {
  68. }
  69. IMPLEMENT_CONOBJECT(GuiPanel);
  70. void GuiPanel::onRender(Point2I offset, const RectI &updateRect)
  71. {
  72. if ( !mProfile->mOpaque )
  73. {
  74. RectI ctrlRect = getClientRect();
  75. ctrlRect.point += offset;
  76. // Draw border.
  77. if( mProfile->mBorder != 0 )
  78. {
  79. GFX->getDrawUtil()->drawRectFill( ctrlRect, mProfile->mBorderColor );
  80. ctrlRect.inset( mProfile->mBorderThickness, mProfile->mBorderThickness );
  81. }
  82. // Draw a gradient left to right.
  83. PrimBuild::begin( GFXTriangleStrip, 4 );
  84. PrimBuild::color( mProfile->mFillColorHL );
  85. PrimBuild::vertex2i( ctrlRect.point.x, ctrlRect.point.y );
  86. PrimBuild::vertex2i( ctrlRect.point.x, ctrlRect.point.y + ctrlRect.extent.y );
  87. PrimBuild::color( mProfile->mFillColor );
  88. PrimBuild::vertex2i( ctrlRect.point.x + ctrlRect.extent.x, ctrlRect.point.y);
  89. PrimBuild::vertex2i( ctrlRect.point.x + ctrlRect.extent.x, ctrlRect.point.y + ctrlRect.extent.y );
  90. PrimBuild::end();
  91. }
  92. Parent::onRender( offset, updateRect );
  93. }