2
0

BsDockManagerLayout.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #include "BsDockManagerLayout.h"
  2. #include "BsDockManagerLayoutRTTI.h"
  3. #include "BsEditorWidgetManager.h"
  4. namespace BansheeEngine
  5. {
  6. DockManagerLayout::Entry::Entry()
  7. :isLeaf(true), splitPosition(0), horizontalSplit(false),
  8. parent(nullptr)
  9. {
  10. children[0] = nullptr;
  11. children[1] = nullptr;
  12. }
  13. DockManagerLayout::Entry::~Entry()
  14. { }
  15. DockManagerLayout::Entry* DockManagerLayout::Entry::createLeaf(Entry* parent, UINT32 childIdx,
  16. const Vector<String>& widgetNames)
  17. {
  18. Entry* newEntry = bs_new<Entry>();
  19. newEntry->isLeaf = true;
  20. newEntry->parent = parent;
  21. if(parent != nullptr)
  22. parent->children[childIdx] = newEntry;
  23. newEntry->widgetNames = widgetNames;
  24. return newEntry;
  25. }
  26. DockManagerLayout::Entry* DockManagerLayout::Entry::createContainer(Entry* parent, UINT32 childIdx,
  27. float splitPosition, bool horizontalSplit)
  28. {
  29. Entry* newEntry = bs_new<Entry>();
  30. newEntry->isLeaf = false;
  31. newEntry->parent = parent;
  32. if(parent != nullptr)
  33. parent->children[childIdx] = newEntry;
  34. newEntry->horizontalSplit = horizontalSplit;
  35. newEntry->splitPosition = splitPosition;
  36. return newEntry;
  37. }
  38. DockManagerLayout::~DockManagerLayout()
  39. {
  40. Stack<Entry*> todo;
  41. if(!mRootEntry.isLeaf)
  42. {
  43. todo.push(mRootEntry.children[0]);
  44. todo.push(mRootEntry.children[1]);
  45. }
  46. while(!todo.empty())
  47. {
  48. Entry* current = todo.top();
  49. todo.pop();
  50. if(!current->isLeaf)
  51. {
  52. todo.push(current->children[0]);
  53. todo.push(current->children[1]);
  54. }
  55. bs_delete(current);
  56. }
  57. }
  58. void DockManagerLayout::pruneInvalidLeaves()
  59. {
  60. Stack<Entry*> layoutTodo;
  61. layoutTodo.push(&mRootEntry);
  62. while (!layoutTodo.empty())
  63. {
  64. Entry* curEntry = layoutTodo.top();
  65. layoutTodo.pop();
  66. if (!curEntry->isLeaf)
  67. {
  68. layoutTodo.push(curEntry->children[0]);
  69. layoutTodo.push(curEntry->children[1]);
  70. }
  71. else
  72. {
  73. for (INT32 i = 0; i < (INT32)curEntry->widgetNames.size(); i++)
  74. {
  75. if (!EditorWidgetManager::instance().isValidWidget(curEntry->widgetNames[i]))
  76. {
  77. curEntry->widgetNames.erase(curEntry->widgetNames.begin() + i);
  78. i--;
  79. }
  80. }
  81. if (curEntry->widgetNames.size() == 0)
  82. {
  83. Entry* parent = curEntry->parent;
  84. if (parent != nullptr)
  85. {
  86. Entry* newParent = parent->parent;
  87. Entry* otherChild = parent->children[0] == curEntry ? parent->children[1] : parent->children[0];
  88. if (newParent != nullptr)
  89. {
  90. if (newParent->children[0] == parent)
  91. newParent->children[0] = otherChild;
  92. else
  93. newParent->children[1] = otherChild;
  94. }
  95. otherChild->parent = newParent;
  96. bs_delete(parent);
  97. bs_delete(curEntry);
  98. }
  99. }
  100. }
  101. }
  102. }
  103. /************************************************************************/
  104. /* RTTI */
  105. /************************************************************************/
  106. RTTITypeBase* DockManagerLayout::getRTTIStatic()
  107. {
  108. return DockManagerLayoutRTTI::instance();
  109. }
  110. RTTITypeBase* DockManagerLayout::getRTTI() const
  111. {
  112. return DockManagerLayout::getRTTIStatic();
  113. }
  114. }