BsEditorWidgetContainer.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include "BsEditorWidgetContainer.h"
  2. #include "BsGUITabbedTitleBar.h"
  3. #include "BsEditorWidget.h"
  4. using namespace CamelotFramework;
  5. using namespace BansheeEngine;
  6. namespace BansheeEditor
  7. {
  8. const CM::UINT32 EditorWidgetContainer::TitleBarHeight = 13;
  9. EditorWidgetContainer::EditorWidgetContainer(BS::GUIWidget* parent)
  10. :mParent(parent), mX(0), mY(0), mWidth(0), mHeight(0), mTitleBar(nullptr), mActiveWidget(-1)
  11. {
  12. mTitleBar = cm_new<GUITabbedTitleBar>(parent);
  13. }
  14. EditorWidgetContainer::~EditorWidgetContainer()
  15. {
  16. cm_delete(mTitleBar);
  17. }
  18. void EditorWidgetContainer::add(EditorWidget& widget)
  19. {
  20. auto iterFind = std::find(begin(mWidgets), end(mWidgets), &widget);
  21. if(iterFind != end(mWidgets))
  22. return;
  23. mTitleBar->addTab(widget.getName());
  24. mWidgets.push_back(&widget);
  25. widget._changeParent(*mParent);
  26. if(mActiveWidget == -1)
  27. {
  28. setActiveWidget((UINT32)mWidgets.size() - 1);
  29. }
  30. else
  31. widget._disable();
  32. }
  33. void EditorWidgetContainer::remove(EditorWidget& widget)
  34. {
  35. INT32 widgetIdx = -1;
  36. UINT32 curIdx = 0;
  37. for(auto& curWidget : mWidgets)
  38. {
  39. if(curWidget == &widget)
  40. {
  41. widgetIdx = curIdx;
  42. break;
  43. }
  44. curIdx++;
  45. }
  46. if(widgetIdx == -1)
  47. return;
  48. mWidgets.erase(mWidgets.begin() + widgetIdx);
  49. mTitleBar->removeTab((UINT32)widgetIdx);
  50. if(widgetIdx == mActiveWidget)
  51. {
  52. if(mWidgets.size() > 0)
  53. {
  54. setActiveWidget(0);
  55. }
  56. else
  57. {
  58. // TODO - Container is empty, send a signal to the parent EditorWindow and/or DockManager
  59. }
  60. }
  61. }
  62. void EditorWidgetContainer::move(EditorWidget& widget, UINT32 newPosition)
  63. {
  64. // TODO
  65. }
  66. void EditorWidgetContainer::setSize(UINT32 width, UINT32 height)
  67. {
  68. // TODO - Title bar is always TitleBarHeight size, so what happens when the container area is smaller than that?
  69. mTitleBar->setSize(width, TitleBarHeight);
  70. if(mActiveWidget >= 0)
  71. {
  72. EditorWidget* activeWidgetPtr = mWidgets[mActiveWidget];
  73. UINT32 contentHeight = (UINT32)std::max(0, (INT32)height - (INT32)TitleBarHeight);
  74. activeWidgetPtr->_setSize(width, contentHeight);
  75. }
  76. mWidth = width;
  77. mHeight = height;
  78. }
  79. void EditorWidgetContainer::setPosition(INT32 x, INT32 y)
  80. {
  81. mTitleBar->setPosition(x, y);
  82. if(mActiveWidget >= 0)
  83. {
  84. EditorWidget* activeWidgetPtr = mWidgets[mActiveWidget];
  85. activeWidgetPtr->_setPosition(x, y + TitleBarHeight);
  86. }
  87. mX = x;
  88. mY = y;
  89. }
  90. void EditorWidgetContainer::setActiveWidget(UINT32 idx)
  91. {
  92. if(mActiveWidget == idx)
  93. return;
  94. mActiveWidget = idx;
  95. UINT32 curIdx = 0;
  96. for(auto& curWidget : mWidgets)
  97. {
  98. if(curIdx != (UINT32)mActiveWidget)
  99. curWidget->_disable();
  100. else
  101. curWidget->_enable();
  102. curIdx++;
  103. }
  104. setPosition(mX, mY);
  105. setSize(mWidth, mHeight);
  106. }
  107. }