guiTabPageCtrl.cc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. mIsContainer = true;
  35. }
  36. bool GuiTabPageCtrl::onMouseDownEditor(const GuiEvent &event, Point2I offset )
  37. {
  38. // This shouldn't be called if it's not design time, but check just incase
  39. if ( GuiControl::smDesignTime )
  40. {
  41. GuiEditCtrl* edit = GuiControl::smEditorHandle;
  42. if( edit )
  43. edit->select( this );
  44. }
  45. return Parent::onMouseDownEditor( event, offset );
  46. }
  47. GuiControl *GuiTabPageCtrl::findNextTabable(GuiControl *curResponder, bool firstCall)
  48. {
  49. //set the global if this is the first call (directly from the canvas)
  50. if (firstCall)
  51. {
  52. GuiControl::smCurResponder = NULL;
  53. }
  54. //if the window does not already contain the first responder, return false
  55. //ie. Can't tab into or out of a window
  56. if (! ControlIsChild(curResponder))
  57. {
  58. return NULL;
  59. }
  60. //loop through, checking each child to see if it is the one that follows the firstResponder
  61. GuiControl *tabCtrl = NULL;
  62. iterator i;
  63. for (i = begin(); i != end(); i++)
  64. {
  65. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  66. tabCtrl = ctrl->findNextTabable(curResponder, false);
  67. if (tabCtrl) break;
  68. }
  69. //to ensure the tab cycles within the current window...
  70. if (! tabCtrl)
  71. {
  72. tabCtrl = findFirstTabable();
  73. }
  74. mFirstResponder = tabCtrl;
  75. return tabCtrl;
  76. }
  77. GuiControl *GuiTabPageCtrl::findPrevTabable(GuiControl *curResponder, bool firstCall)
  78. {
  79. if (firstCall)
  80. {
  81. GuiControl::smPrevResponder = NULL;
  82. }
  83. //if the window does not already contain the first responder, return false
  84. //ie. Can't tab into or out of a window
  85. if (! ControlIsChild(curResponder))
  86. {
  87. return NULL;
  88. }
  89. //loop through, checking each child to see if it is the one that follows the firstResponder
  90. GuiControl *tabCtrl = NULL;
  91. iterator i;
  92. for (i = begin(); i != end(); i++)
  93. {
  94. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  95. tabCtrl = ctrl->findPrevTabable(curResponder, false);
  96. if (tabCtrl) break;
  97. }
  98. //to ensure the tab cycles within the current window...
  99. if (! tabCtrl)
  100. {
  101. tabCtrl = findLastTabable();
  102. }
  103. mFirstResponder = tabCtrl;
  104. return tabCtrl;
  105. }
  106. void GuiTabPageCtrl::setText(const char *txt)
  107. {
  108. Parent::setText( txt );
  109. GuiControl *parent = getParent();
  110. if( parent )
  111. parent->setUpdate();
  112. };
  113. void GuiTabPageCtrl::selectWindow(void)
  114. {
  115. //first make sure this window is the front most of its siblings
  116. GuiControl *parent = getParent();
  117. if (parent)
  118. {
  119. parent->pushObjectToBack(this);
  120. }
  121. //also set the first responder to be the one within this window
  122. setFirstResponder(mFirstResponder);
  123. }
  124. void GuiTabPageCtrl::onRender(Point2I offset, const RectI &updateRect)
  125. {
  126. RectI ctrlRect = applyMargins(offset, mBounds.extent, NormalState, mProfile);
  127. if (!ctrlRect.isValidRect())
  128. {
  129. return;
  130. }
  131. renderUniversalRect(ctrlRect, mProfile, NormalState);
  132. //Render Text
  133. RectI fillRect = applyBorders(ctrlRect.point, ctrlRect.extent, NormalState, mProfile);
  134. RectI contentRect = applyPadding(fillRect.point, fillRect.extent, NormalState, mProfile);
  135. if (contentRect.isValidRect())
  136. {
  137. //Render the childen
  138. renderChildControls(offset, contentRect, updateRect);
  139. }
  140. }