guiTabPageCtrl.cc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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/consoleTypes.h"
  23. #include "console/console.h"
  24. #include "graphics/dgl.h"
  25. #include "gui/guiCanvas.h"
  26. #include "gui/containers/guiTabPageCtrl.h"
  27. #include "gui/guiDefaultControlRender.h"
  28. #include "gui/editor/guiEditCtrl.h"
  29. IMPLEMENT_CONOBJECT(GuiTabPageCtrl);
  30. GuiTabPageCtrl::GuiTabPageCtrl(void)
  31. {
  32. mBounds.extent.set(100, 200);
  33. mActive = true;
  34. }
  35. GuiControl *GuiTabPageCtrl::findNextTabable(GuiControl *curResponder, bool firstCall)
  36. {
  37. //set the global if this is the first call (directly from the canvas)
  38. if (firstCall)
  39. {
  40. GuiControl::smCurResponder = NULL;
  41. }
  42. //if the window does not already contain the first responder, return false
  43. //ie. Can't tab into or out of a window
  44. if (! ControlIsChild(curResponder))
  45. {
  46. return NULL;
  47. }
  48. //loop through, checking each child to see if it is the one that follows the firstResponder
  49. GuiControl *tabCtrl = NULL;
  50. iterator i;
  51. for (i = begin(); i != end(); i++)
  52. {
  53. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  54. tabCtrl = ctrl->findNextTabable(curResponder, false);
  55. if (tabCtrl) break;
  56. }
  57. //to ensure the tab cycles within the current window...
  58. if (! tabCtrl)
  59. {
  60. tabCtrl = findFirstTabable();
  61. }
  62. mFirstResponder = tabCtrl;
  63. return tabCtrl;
  64. }
  65. GuiControl *GuiTabPageCtrl::findPrevTabable(GuiControl *curResponder, bool firstCall)
  66. {
  67. if (firstCall)
  68. {
  69. GuiControl::smPrevResponder = NULL;
  70. }
  71. //if the window does not already contain the first responder, return false
  72. //ie. Can't tab into or out of a window
  73. if (! ControlIsChild(curResponder))
  74. {
  75. return NULL;
  76. }
  77. //loop through, checking each child to see if it is the one that follows the firstResponder
  78. GuiControl *tabCtrl = NULL;
  79. iterator i;
  80. for (i = begin(); i != end(); i++)
  81. {
  82. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  83. tabCtrl = ctrl->findPrevTabable(curResponder, false);
  84. if (tabCtrl) break;
  85. }
  86. //to ensure the tab cycles within the current window...
  87. if (! tabCtrl)
  88. {
  89. tabCtrl = findLastTabable();
  90. }
  91. mFirstResponder = tabCtrl;
  92. return tabCtrl;
  93. }
  94. void GuiTabPageCtrl::setText(const char *txt)
  95. {
  96. Parent::setText( txt );
  97. GuiControl *parent = getParent();
  98. if( parent )
  99. parent->setUpdate();
  100. };
  101. void GuiTabPageCtrl::selectWindow(void)
  102. {
  103. //first make sure this window is the front most of its siblings
  104. GuiControl *parent = getParent();
  105. if (parent)
  106. {
  107. parent->pushObjectToBack(this);
  108. }
  109. //also set the first responder to be the one within this window
  110. setFirstResponder(mFirstResponder);
  111. }
  112. void GuiTabPageCtrl::onRender(Point2I offset, const RectI &updateRect)
  113. {
  114. RectI ctrlRect = applyMargins(offset, mBounds.extent, NormalState, mProfile);
  115. if (!ctrlRect.isValidRect())
  116. {
  117. return;
  118. }
  119. renderUniversalRect(ctrlRect, mProfile, NormalState);
  120. //Render Text
  121. RectI fillRect = applyBorders(ctrlRect.point, ctrlRect.extent, NormalState, mProfile);
  122. RectI contentRect = applyPadding(fillRect.point, fillRect.extent, NormalState, mProfile);
  123. if (contentRect.isValidRect())
  124. {
  125. //Render the childen
  126. renderChildControls(offset, contentRect, updateRect);
  127. }
  128. }
  129. void GuiTabPageCtrl::parentResized(const Point2I& oldParentExtent, const Point2I& newParentExtent)
  130. {
  131. //Do nothing. If the parent of a page resized then it will tell us what size to be later.
  132. }