guiSeparatorCtrl.cc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 "graphics/dgl.h"
  23. #include "console/console.h"
  24. #include "console/consoleTypes.h"
  25. #include "gui/guiCanvas.h"
  26. #include "gui/guiDefaultControlRender.h"
  27. #include "gui/editor/guiSeparatorCtrl.h"
  28. IMPLEMENT_CONOBJECT(GuiSeparatorCtrl);
  29. static EnumTable::Enums separatorTypeEnum[] =
  30. {
  31. { GuiSeparatorCtrl::separatorTypeVertical, "Vertical" },
  32. { GuiSeparatorCtrl::separatorTypeHorizontal,"Horizontal" }
  33. };
  34. static EnumTable gSeparatorTypeTable(2, &separatorTypeEnum[0]);
  35. //--------------------------------------------------------------------------
  36. GuiSeparatorCtrl::GuiSeparatorCtrl() : GuiControl()
  37. {
  38. mInvisible = false;
  39. mText = StringTable->EmptyString;
  40. mTextLeftMargin = 0;
  41. mMargin = 2;
  42. mBounds.extent.set( 12, 35 );
  43. mSeparatorType = GuiSeparatorCtrl::separatorTypeVertical;
  44. }
  45. //--------------------------------------------------------------------------
  46. void GuiSeparatorCtrl::initPersistFields()
  47. {
  48. Parent::initPersistFields();
  49. addField("Caption", TypeString, Offset(mText, GuiSeparatorCtrl));
  50. addField("Type", TypeEnum, Offset(mSeparatorType, GuiSeparatorCtrl), 1, &gSeparatorTypeTable);
  51. addField("BorderMargin", TypeS32, Offset(mMargin, GuiSeparatorCtrl));
  52. addField("Invisible", TypeBool, Offset(mInvisible, GuiSeparatorCtrl));
  53. addField("LeftMargin", TypeS32, Offset(mTextLeftMargin, GuiSeparatorCtrl));
  54. }
  55. //--------------------------------------------------------------------------
  56. void GuiSeparatorCtrl::onRender(Point2I offset, const RectI &updateRect)
  57. {
  58. Parent::onRender( offset, updateRect );
  59. if( mInvisible )
  60. return;
  61. if(mText != StringTable->EmptyString && !( mSeparatorType == separatorTypeVertical ) )
  62. {
  63. // If text is present and we have a left margin, then draw some separator, then the
  64. // text, and then the rest of the separator
  65. S32 posx = offset.x + mMargin;
  66. S32 fontheight = mProfile->mFont->getHeight();
  67. S32 seppos = (fontheight - 2) / 2 + offset.y;
  68. if(mTextLeftMargin > 0)
  69. {
  70. RectI rect(Point2I(posx,seppos),Point2I(mTextLeftMargin,2));
  71. renderSlightlyLoweredBox(rect, mProfile);
  72. posx += mTextLeftMargin;
  73. }
  74. dglSetBitmapModulation( mActive ? mProfile->mFillColor : mProfile->mFillColorNA );
  75. posx += dglDrawText(mProfile->mFont, Point2I(posx,offset.y), mText, mProfile->mFontColors);
  76. //posx += mProfile->mFont->getStrWidth(mText);
  77. RectI rect(Point2I(posx,seppos),Point2I(mBounds.extent.x - posx + offset.x,2));
  78. renderSlightlyLoweredBox(rect, mProfile, mActive);
  79. } else
  80. {
  81. if( mSeparatorType == separatorTypeHorizontal )
  82. {
  83. S32 seppos = mBounds.extent.y / 2 + offset.y;
  84. RectI rect(Point2I(offset.x + mMargin ,seppos),Point2I(mBounds.extent.x - (mMargin * 2),2));
  85. renderSlightlyLoweredBox(rect, mProfile);
  86. }
  87. else
  88. {
  89. S32 seppos = mBounds.extent.x / 2 + offset.x;
  90. RectI rect(Point2I(seppos, offset.y + mMargin),Point2I(2, mBounds.extent.y - (mMargin * 2)));
  91. renderSlightlyLoweredBox(rect, mProfile);
  92. }
  93. }
  94. renderChildControls(offset, updateRect);
  95. }