| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #include "EditorWindow/BsDockManagerLayout.h"
- #include "Private/RTTI/BsDockManagerLayoutRTTI.h"
- #include "EditorWindow/BsEditorWidgetManager.h"
- namespace bs
- {
- DockManagerLayout::Entry::Entry()
- :isLeaf(true), splitPosition(0), horizontalSplit(false),
- parent(nullptr)
- {
- children[0] = nullptr;
- children[1] = nullptr;
- }
- DockManagerLayout::Entry::~Entry()
- { }
- DockManagerLayout::Entry* DockManagerLayout::Entry::createLeaf(Entry* parent, UINT32 childIdx,
- const Vector<String>& widgetNames)
- {
- Entry* newEntry = bs_new<Entry>();
- newEntry->isLeaf = true;
- newEntry->parent = parent;
- if(parent != nullptr)
- parent->children[childIdx] = newEntry;
- newEntry->widgetNames = widgetNames;
- return newEntry;
- }
- DockManagerLayout::Entry* DockManagerLayout::Entry::createContainer(Entry* parent, UINT32 childIdx,
- float splitPosition, bool horizontalSplit)
- {
- Entry* newEntry = bs_new<Entry>();
- newEntry->isLeaf = false;
- newEntry->parent = parent;
- if(parent != nullptr)
- parent->children[childIdx] = newEntry;
- newEntry->horizontalSplit = horizontalSplit;
- newEntry->splitPosition = splitPosition;
- return newEntry;
- }
- DockManagerLayout::DockManagerLayout()
- :mIsMaximized(false)
- { }
- DockManagerLayout::~DockManagerLayout()
- {
- Stack<Entry*> todo;
- if(!mRootEntry.isLeaf)
- {
- todo.push(mRootEntry.children[0]);
- todo.push(mRootEntry.children[1]);
- }
- while(!todo.empty())
- {
- Entry* current = todo.top();
- todo.pop();
- if(!current->isLeaf)
- {
- todo.push(current->children[0]);
- todo.push(current->children[1]);
- }
- bs_delete(current);
- }
- }
- void DockManagerLayout::setIsMaximized(bool maximized, const Vector<String>& widgetNames)
- {
- mIsMaximized = maximized;
- mMaximizedWidgetNames = widgetNames;
- }
- void DockManagerLayout::pruneInvalidLeaves()
- {
- Stack<Entry*> layoutTodo;
- layoutTodo.push(&mRootEntry);
- while (!layoutTodo.empty())
- {
- Entry* curEntry = layoutTodo.top();
- layoutTodo.pop();
- if (!curEntry->isLeaf)
- {
- layoutTodo.push(curEntry->children[0]);
- layoutTodo.push(curEntry->children[1]);
- }
- else
- {
- for (INT32 i = 0; i < (INT32)curEntry->widgetNames.size(); i++)
- {
- if (!EditorWidgetManager::instance().isValidWidget(curEntry->widgetNames[i]))
- {
- curEntry->widgetNames.erase(curEntry->widgetNames.begin() + i);
- i--;
- }
- }
- if (curEntry->widgetNames.empty())
- {
- Entry* parent = curEntry->parent;
- if (parent != nullptr)
- {
- Entry* newParent = parent->parent;
- Entry* otherChild = parent->children[0] == curEntry ? parent->children[1] : parent->children[0];
- if (newParent != nullptr)
- {
- if (newParent->children[0] == parent)
- newParent->children[0] = otherChild;
- else
- newParent->children[1] = otherChild;
- bs_delete(parent);
- }
- else // Parent is root
- {
- if(otherChild)
- {
- parent->isLeaf = true;
- parent->widgetNames = otherChild->widgetNames;
- parent->children[0] = nullptr;
- parent->children[1] = nullptr;
- }
- else
- {
- parent->isLeaf = false;
- parent->widgetNames.clear();
- }
- }
- if(otherChild)
- otherChild->parent = newParent;
- bs_delete(curEntry);
- }
- }
- }
- }
- for (INT32 i = 0; i < (INT32)mMaximizedWidgetNames.size(); i++)
- {
- if (!EditorWidgetManager::instance().isValidWidget(mMaximizedWidgetNames[i]))
- {
- mMaximizedWidgetNames.erase(mMaximizedWidgetNames.begin() + i);
- i--;
- }
- }
- }
- SPtr<DockManagerLayout> DockManagerLayout::clone()
- {
- std::function<void(Entry*, Entry*, Entry*)> cloneEntry = [&](Entry* toClone, Entry* parent, Entry* clone)
- {
- *clone = *toClone;
- clone->parent = parent;
- if (!toClone->isLeaf)
- {
- clone->children[0] = bs_new<Entry>();
- clone->children[1] = bs_new<Entry>();
- cloneEntry(toClone->children[0], clone, clone->children[0]);
- cloneEntry(toClone->children[1], clone, clone->children[1]);
- }
- };
- SPtr<DockManagerLayout> copy = bs_shared_ptr_new<DockManagerLayout>();
- cloneEntry(&mRootEntry, nullptr, ©->mRootEntry);
- return copy;
- }
- /************************************************************************/
- /* RTTI */
- /************************************************************************/
- RTTITypeBase* DockManagerLayout::getRTTIStatic()
- {
- return DockManagerLayoutRTTI::instance();
- }
- RTTITypeBase* DockManagerLayout::getRTTI() const
- {
- return DockManagerLayout::getRTTIStatic();
- }
- }
|