| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767 |
- #include "BsGUISceneTreeView.h"
- #include "BsGUIArea.h"
- #include "BsGUILayout.h"
- #include "BsGUITexture.h"
- #include "BsGUIButton.h"
- #include "BsGUILabel.h"
- #include "BsGUISpace.h"
- #include "BsGUIWidget.h"
- #include "BsGUIToggle.h"
- #include "BsGUITreeViewEditBox.h"
- #include "BsGUIMouseEvent.h"
- #include "BsGUISkin.h"
- #include "BsGUICommandEvent.h"
- #include "CmSceneObject.h"
- #include "CmSceneManager.h"
- #include "BsCmdEditPlainFieldGO.h"
- using namespace CamelotFramework;
- using namespace BansheeEngine;
- namespace BansheeEditor
- {
- const UINT32 GUISceneTreeView::ELEMENT_EXTRA_SPACING = 3;
- const UINT32 GUISceneTreeView::INDENT_SIZE = 10;
- const UINT32 GUISceneTreeView::INITIAL_INDENT_OFFSET = 16;
- GUISceneTreeView::TreeElement::TreeElement()
- :mParent(nullptr), mFoldoutBtn(nullptr), mElement(nullptr), mIsSelected(false),
- mId(0), mIsExpanded(false), mSortedIdx(0), mIsDirty(false), mIsVisible(true)
- { }
- GUISceneTreeView::TreeElement::~TreeElement()
- {
- for(auto& child : mChildren)
- cm_delete(child);
- if(mFoldoutBtn != nullptr)
- GUIElement::destroy(mFoldoutBtn);
- if(mElement != nullptr)
- GUIElement::destroy(mElement);
- mChildren.clear();
- }
- GUISceneTreeView::GUISceneTreeView(GUIWidget& parent, GUIElementStyle* backgroundStyle, GUIElementStyle* elementBtnStyle,
- GUIElementStyle* foldoutBtnStyle, GUIElementStyle* selectionBackgroundStyle, GUIElementStyle* editBoxStyle,
- const GUILayoutOptions& layoutOptions)
- :GUIElementContainer(parent, layoutOptions), mBackgroundStyle(backgroundStyle),
- mElementBtnStyle(elementBtnStyle), mFoldoutBtnStyle(foldoutBtnStyle), mEditBoxStyle(editBoxStyle), mEditElement(nullptr), mIsElementSelected(false),
- mNameEditBox(nullptr), mSelectionBackgroundStyle(selectionBackgroundStyle)
- {
- if(mBackgroundStyle == nullptr)
- mBackgroundStyle = parent.getSkin().getStyle("TreeViewBackground");
- if(mElementBtnStyle == nullptr)
- mElementBtnStyle = parent.getSkin().getStyle("TreeViewElementBtn");
- if(mFoldoutBtnStyle == nullptr)
- mFoldoutBtnStyle = parent.getSkin().getStyle("TreeViewFoldoutBtn");
- if(mSelectionBackgroundStyle == nullptr)
- mSelectionBackgroundStyle = parent.getSkin().getStyle("TreeViewSelectionBackground");
- if(mEditBoxStyle == nullptr)
- mEditBoxStyle = parent.getSkin().getStyle("TreeViewEditBox");
- mBackgroundImage = GUITexture::create(parent, mBackgroundStyle);
- mNameEditBox = GUITreeViewEditBox::create(parent, mEditBoxStyle);
- mNameEditBox->disableRecursively();
- mNameEditBox->onInputConfirmed.connect(boost::bind(&GUISceneTreeView::onEditAccepted, this));
- mNameEditBox->onInputCanceled.connect(boost::bind(&GUISceneTreeView::onEditCanceled, this));
- _registerChildElement(mBackgroundImage);
- _registerChildElement(mNameEditBox);
- }
- GUISceneTreeView::~GUISceneTreeView()
- {
- }
- GUISceneTreeView* GUISceneTreeView::create(GUIWidget& parent, GUIElementStyle* backgroundStyle, GUIElementStyle* elementBtnStyle,
- GUIElementStyle* foldoutBtnStyle, GUIElementStyle* selectionBackgroundStyle, GUIElementStyle* editBoxStyle)
- {
- return new (cm_alloc<GUISceneTreeView, PoolAlloc>()) GUISceneTreeView(parent, backgroundStyle, elementBtnStyle, foldoutBtnStyle,
- selectionBackgroundStyle, editBoxStyle, GUILayoutOptions::create(&GUISkin::DefaultStyle));
- }
- GUISceneTreeView* GUISceneTreeView::create(GUIWidget& parent, const GUIOptions& options, GUIElementStyle* backgroundStyle,
- GUIElementStyle* elementBtnStyle, GUIElementStyle* foldoutBtnStyle, GUIElementStyle* selectionBackgroundStyle, GUIElementStyle* editBoxStyle)
- {
- return new (cm_alloc<GUISceneTreeView, PoolAlloc>()) GUISceneTreeView(parent, backgroundStyle, elementBtnStyle,
- foldoutBtnStyle, selectionBackgroundStyle, editBoxStyle, GUILayoutOptions::create(options, &GUISkin::DefaultStyle));
- }
- void GUISceneTreeView::update()
- {
- // NOTE - Instead of iterating through every visible element and comparing it with internal values,
- // I might just want to add callbacks to SceneManager that notify me of any changes and then only perform
- // update if anything is actually dirty
- struct UpdateTreeElement
- {
- UpdateTreeElement(TreeElement* element, UINT32 seqIdx, bool visible)
- :element(element), seqIdx(seqIdx), visible(visible)
- { }
- TreeElement* element;
- UINT32 seqIdx;
- bool visible;
- };
- HSceneObject root = CM::gSceneManager().getRootNode();
- mRootElement.mSceneObject = root;
- mRootElement.mId = root->getId();
- mRootElement.mSortedIdx = 0;
- mRootElement.mIsExpanded = true;
- Stack<UpdateTreeElement>::type todo;
- todo.push(UpdateTreeElement(&mRootElement, 0, true));
- while(!todo.empty())
- {
- UpdateTreeElement updateElement = todo.top();
- TreeElement* current = updateElement.element;
- HSceneObject currentSO = current->mSceneObject;
- todo.pop();
- // Check if SceneObject has changed in any way and update the tree element
- if(updateElement.visible)
- {
- bool completeMatch = (UINT32)current->mChildren.size() == currentSO->getNumChildren();
- // Early exit case - Most commonly there will be no changes between active and cached data so
- // we first do a quick check in order to avoid expensive comparison later
- if(completeMatch)
- {
- for(UINT32 i = 0; i < currentSO->getNumChildren(); i++)
- {
- UINT32 curId = currentSO->getChild(i)->getId();
- if(curId != current->mChildren[i]->mId)
- {
- completeMatch = false;
- break;
- }
- }
- }
- // Not a complete match, compare everything and insert/delete elements as needed
- if(!completeMatch)
- {
- Vector<TreeElement*>::type newChildren;
- mTempToDelete.resize(current->mChildren.size(), true);
- for(UINT32 i = 0; i < currentSO->getNumChildren(); i++)
- {
- HSceneObject currentSOChild = currentSO->getChild(i);
- UINT32 curId = currentSOChild->getId();
- bool found = false;
- for(UINT32 j = 0; j < current->mChildren.size(); j++)
- {
- TreeElement* currentChild = current->mChildren[j];
- if(curId == currentChild->mId)
- {
- mTempToDelete[j] = false;
- currentChild->mIsDirty = true;
- currentChild->mSortedIdx = (UINT32)newChildren.size();
- newChildren.push_back(currentChild);
- found = true;
- break;
- }
- }
- if(!found)
- {
- TreeElement* newChild = cm_new<TreeElement>();
- newChild->mParent = current;
- newChild->mSceneObject = currentSOChild;
- newChild->mId = currentSOChild->getId();
- newChild->mName = currentSOChild->getName();
- newChild->mSortedIdx = (UINT32)newChildren.size();
- newChild->mIsDirty = true;
- newChildren.push_back(newChild);
- }
- }
- for(UINT32 i = 0; i < current->mChildren.size(); i++)
- {
- if(!mTempToDelete[i])
- continue;
- if(current->mIsSelected)
- unselectElement(current);
- cm_delete(current->mChildren[i]);
- }
- current->mChildren = newChildren;
- current->mIsDirty = true;
- }
- // Check if name needs updating
- const String& name = current->mSceneObject->getName();
- if(current->mName != name)
- {
- current->mName = name;
- current->mIsDirty = true;
- }
- // Calculate the sorted index of the element based on its name
- TreeElement* parent = current->mParent;
- if(current->mIsDirty && parent != nullptr)
- {
- for(UINT32 i = 0; i < (UINT32)parent->mChildren.size(); i++)
- {
- INT32 stringCompare = current->mName.compare(parent->mChildren[i]->mName);
- if(stringCompare > 0)
- {
- if(current->mSortedIdx < parent->mChildren[i]->mSortedIdx)
- std::swap(current->mSortedIdx, parent->mChildren[i]->mSortedIdx);
- }
- else if(stringCompare < 0)
- {
- if(current->mSortedIdx > parent->mChildren[i]->mSortedIdx)
- std::swap(current->mSortedIdx, parent->mChildren[i]->mSortedIdx);
- }
- }
- }
- }
- bool visibilityChanged = false;
- if(current->mIsVisible != updateElement.visible)
- {
- visibilityChanged = true;
- current->mIsVisible = updateElement.visible;
- current->mIsDirty = true;
- }
-
- if(current->mIsDirty && current != &mRootElement)
- {
- if(updateElement.visible)
- {
- HString name(toWString(current->mName));
- if(current->mElement == nullptr)
- {
- current->mElement = GUILabel::create(_getParentWidget(), name, mElementBtnStyle);
- _registerChildElement(current->mElement);
- }
- if(current->mChildren.size() > 0)
- {
- if(current->mFoldoutBtn == nullptr)
- {
- current->mFoldoutBtn = GUIToggle::create(_getParentWidget(), GUIContent(HString(L"")), mFoldoutBtnStyle);
- _registerChildElement(current->mFoldoutBtn);
- current->mFoldoutBtn->onToggled.connect(boost::bind(&GUISceneTreeView::elementToggled, this, current, _1));
- }
- }
- else
- {
- if(current->mFoldoutBtn != nullptr)
- {
- GUIElement::destroy(current->mFoldoutBtn);
- current->mFoldoutBtn = nullptr;
- }
- }
- current->mElement->setContent(GUIContent(name));
- }
- else
- {
- if(current->mElement != nullptr)
- {
- GUIElement::destroy(current->mElement);
- current->mElement = nullptr;
- }
- if(current->mFoldoutBtn != nullptr)
- {
- GUIElement::destroy(current->mFoldoutBtn);
- current->mFoldoutBtn = nullptr;
- }
- if(current->mIsVisible && current->mIsSelected)
- unselectElement(current);
- }
- markContentAsDirty();
- current->mIsDirty = false;
- }
- // Queue children for next iteration
- if(visibilityChanged || current->mIsVisible)
- {
- for(UINT32 i = 0; i < (UINT32)current->mChildren.size(); i++)
- {
- todo.push(UpdateTreeElement(current->mChildren[i], i, current->mIsVisible && current->mIsExpanded));
- }
- }
- }
- }
- bool GUISceneTreeView::mouseEvent(const GUIMouseEvent& event)
- {
- if(event.getType() == GUIMouseEventType::MouseUp)
- {
- const GUISceneTreeView::InteractableElement* element = findElementUnderCoord(event.getPosition());
- if(element != nullptr && element->isTreeElement())
- {
- if(event.isCtrlDown())
- {
- selectElement(interactableToRealElement(*element));
- }
- else if(event.isShiftDown())
- {
- if(isSelectionActive())
- {
- TreeElement* selectionRoot = mSelectedElements[0].element;
- unselectAll();
- auto iterStartFind = std::find_if(mVisibleElements.begin(), mVisibleElements.end(),
- [&] (const InteractableElement& x) { return x.parent == selectionRoot->mParent; } );
- bool foundStart = false;
- bool foundEnd = false;
- for(; iterStartFind != mVisibleElements.end(); ++iterStartFind)
- {
- if(!iterStartFind->isTreeElement())
- continue;
- TreeElement* curElem = interactableToRealElement(*iterStartFind);
- if(curElem == selectionRoot)
- {
- foundStart = true;
- break;
- }
- }
- auto iterEndFind = std::find_if(mVisibleElements.begin(), mVisibleElements.end(),
- [&] (const InteractableElement& x) { return &x == element; } );
- if(iterEndFind != mVisibleElements.end())
- foundEnd = true;
- if(foundStart && foundEnd)
- {
- if(iterStartFind < iterEndFind)
- {
- for(;iterStartFind != (iterEndFind + 1); ++iterStartFind)
- {
- if(iterStartFind->isTreeElement())
- selectElement(interactableToRealElement(*element));
- }
- }
- else if(iterEndFind < iterStartFind)
- {
- for(;iterEndFind != (iterStartFind + 1); ++iterEndFind)
- {
- if(iterEndFind->isTreeElement())
- selectElement(interactableToRealElement(*element));
- }
- }
- else
- selectElement(interactableToRealElement(*element));
- }
- if(!foundStart || !foundEnd)
- selectElement(interactableToRealElement(*element));
- }
- else
- {
- selectElement(interactableToRealElement(*element));
- }
- }
- else
- {
- unselectAll();
- selectElement(interactableToRealElement(*element));
- }
- }
- markContentAsDirty();
- return true;
- }
- return false;
- }
- bool GUISceneTreeView::commandEvent(const GUICommandEvent& ev)
- {
- if(ev.getType() == GUICommandEventType::Rename)
- {
- if(isSelectionActive() && mEditElement == nullptr)
- {
- unselectAll();
- enableEdit(mSelectedElements[0].element);
- }
- return true;
- }
- return false;
- }
- bool GUISceneTreeView::isSelectionActive() const
- {
- return mIsElementSelected && mSelectedElements.size() > 0;
- }
- void GUISceneTreeView::selectElement(TreeElement* element)
- {
- auto iterFind = std::find_if(mSelectedElements.begin(), mSelectedElements.end(),
- [&] (const SelectedElement& x) { return x.element == element; });
- if(iterFind == mSelectedElements.end())
- {
- GUITexture* background = GUITexture::create(_getParentWidget(), mSelectionBackgroundStyle);
- element->mIsSelected = true;
- mSelectedElements.push_back(SelectedElement(element, background));
- mIsElementSelected = true;
- }
- }
- void GUISceneTreeView::unselectElement(TreeElement* element)
- {
- auto iterFind = std::find_if(mSelectedElements.begin(), mSelectedElements.end(),
- [&] (const SelectedElement& x) { return x.element == element; });
- if(iterFind != mSelectedElements.end())
- {
- iterFind->element->mIsSelected = false;
- GUIElement::destroy(iterFind->background);
- mSelectedElements.erase(iterFind);
- markContentAsDirty();
- }
- mIsElementSelected = mSelectedElements.size() > 0;
- }
- void GUISceneTreeView::unselectAll()
- {
- for(auto& selectedElem : mSelectedElements)
- {
- selectedElem.element->mIsSelected = false;
- GUIElement::destroy(selectedElem.background);
- }
- mSelectedElements.clear();
- mIsElementSelected = false;
- markContentAsDirty();
- }
- void GUISceneTreeView::elementToggled(TreeElement* element, bool toggled)
- {
- element->mIsExpanded = toggled;
- }
- void GUISceneTreeView::onEditAccepted()
- {
- disableEdit(true);
- }
- void GUISceneTreeView::onEditCanceled()
- {
- if(mEditElement != nullptr)
- disableEdit(false);
- }
- void GUISceneTreeView::enableEdit(TreeElement* element)
- {
- assert(mEditElement == nullptr);
- mEditElement = element;
- mNameEditBox->enableRecursively();
- mNameEditBox->setFocus(true);
- if(element->mElement != nullptr)
- element->mElement->disableRecursively();
- }
- void GUISceneTreeView::disableEdit(bool applyChanges)
- {
- assert(mEditElement != nullptr);
-
- if(mEditElement->mElement != nullptr)
- mEditElement->mElement->enableRecursively();
- if(applyChanges)
- {
- String newName = toString(mNameEditBox->getText());
- CmdEditPlainFieldGO<String>::execute(mEditElement->mSceneObject, "mName", newName);
- }
- mNameEditBox->disableRecursively();
- mEditElement = nullptr;
- }
- Vector2I GUISceneTreeView::_getOptimalSize() const
- {
- struct UpdateTreeElement
- {
- UpdateTreeElement(const TreeElement* element, UINT32 indent)
- :element(element), indent(indent)
- { }
- const TreeElement* element;
- UINT32 indent;
- };
- Vector2I optimalSize;
- if(_getLayoutOptions().fixedWidth && _getLayoutOptions().fixedHeight)
- {
- optimalSize.x = _getLayoutOptions().width;
- optimalSize.y = _getLayoutOptions().height;
- }
- else
- {
- Stack<UpdateTreeElement>::type todo;
- todo.push(UpdateTreeElement(&mRootElement, 0));
- optimalSize.y += ELEMENT_EXTRA_SPACING;
- while(!todo.empty())
- {
- UpdateTreeElement currentUpdateElement = todo.top();
- const TreeElement* current = currentUpdateElement.element;
- todo.pop();
- INT32 yOffset = 0;
- if(current->mElement != nullptr)
- {
- Vector2I curOptimalSize = current->mElement->_getOptimalSize();
- optimalSize.x = std::max(optimalSize.x,
- (INT32)(INITIAL_INDENT_OFFSET + curOptimalSize.x + currentUpdateElement.indent * INDENT_SIZE));
- yOffset = curOptimalSize.y + ELEMENT_EXTRA_SPACING;
- }
- optimalSize.y += yOffset;
- for(auto& child : current->mChildren)
- {
- if(!child->mIsVisible)
- continue;
- todo.push(UpdateTreeElement(child, currentUpdateElement.indent + 1));
- }
- }
- if(_getLayoutOptions().fixedWidth)
- optimalSize.x = _getLayoutOptions().width;
- else
- {
- if(_getLayoutOptions().minWidth > 0)
- optimalSize.x = std::max((INT32)_getLayoutOptions().minWidth, optimalSize.x);
- if(_getLayoutOptions().maxWidth > 0)
- optimalSize.x = std::min((INT32)_getLayoutOptions().maxWidth, optimalSize.x);
- }
- if(_getLayoutOptions().fixedHeight)
- optimalSize.y = _getLayoutOptions().height;
- else
- {
- if(_getLayoutOptions().minHeight > 0)
- optimalSize.y = std::max((INT32)_getLayoutOptions().minHeight, optimalSize.y);
- if(_getLayoutOptions().maxHeight > 0)
- optimalSize.y = std::min((INT32)_getLayoutOptions().maxHeight, optimalSize.y);
- }
- }
- return optimalSize;
- }
- void GUISceneTreeView::updateClippedBounds()
- {
- Vector2I offset = _getOffset();
- mClippedBounds = RectI(offset.x, offset.y, _getWidth(), _getHeight());
- }
- void GUISceneTreeView::_updateLayoutInternal(INT32 x, INT32 y, UINT32 width, UINT32 height,
- RectI clipRect, UINT8 widgetDepth, UINT16 areaDepth)
- {
- struct UpdateTreeElement
- {
- UpdateTreeElement(TreeElement* element, UINT32 indent)
- :element(element), indent(indent)
- { }
- TreeElement* element;
- UINT32 indent;
- };
- mVisibleElements.clear();
- Stack<UpdateTreeElement>::type todo;
- todo.push(UpdateTreeElement(&mRootElement, 0));
- // NOTE - Instead of iterating through all elements, try to find those within the clip rect
- // and only iterate through those. Others should somehow be marked in-active (similar to GUIElement::isDisabled()?)
- Vector<TreeElement*>::type tempOrderedElements;
- Vector2I offset(x, y);
- while(!todo.empty())
- {
- UpdateTreeElement currentUpdateElement = todo.top();
- TreeElement* current = currentUpdateElement.element;
- UINT32 indent = currentUpdateElement.indent;
- todo.pop();
- if(current->mParent != nullptr && current->mSortedIdx == 0)
- {
- mVisibleElements.push_back(InteractableElement(current->mParent, 0, RectI(x, offset.y, width, ELEMENT_EXTRA_SPACING)));
- }
- INT32 btnHeight = 0;
- INT32 yOffset = 0;
- if(current->mElement != nullptr)
- {
- Vector2I elementSize = current->mElement->_getOptimalSize();
- btnHeight = elementSize.y;
- offset.x = INITIAL_INDENT_OFFSET + indent * INDENT_SIZE;
- current->mElement->_setOffset(offset);
- current->mElement->_setWidth(elementSize.x);
- current->mElement->_setHeight(elementSize.y);
- current->mElement->_setAreaDepth(areaDepth);
- current->mElement->_setWidgetDepth(widgetDepth);
- RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
- current->mElement->_setClipRect(elemClipRect);
- mVisibleElements.push_back(InteractableElement(current->mParent, current->mSortedIdx * 2 + 1, RectI(x, offset.y, width, btnHeight)));
- mVisibleElements.push_back(InteractableElement(current->mParent, current->mSortedIdx * 2 + 2, RectI(x, offset.y + btnHeight, width, ELEMENT_EXTRA_SPACING)));
- yOffset = btnHeight + ELEMENT_EXTRA_SPACING;
- }
- if(current->mFoldoutBtn != nullptr)
- {
- Vector2I elementSize = current->mFoldoutBtn->_getOptimalSize();
- offset.x -= std::min((INT32)INITIAL_INDENT_OFFSET, elementSize.y);
- Vector2I myOffset = offset;
- if(elementSize.y > btnHeight)
- {
- UINT32 diff = elementSize.y - btnHeight;
- float half = diff * 0.5f;
- myOffset.y -= Math::floorToInt(half);
- }
- current->mFoldoutBtn->_setOffset(myOffset);
- current->mFoldoutBtn->_setWidth(elementSize.x);
- current->mFoldoutBtn->_setHeight(elementSize.y);
- current->mFoldoutBtn->_setAreaDepth(areaDepth);
- current->mFoldoutBtn->_setWidgetDepth(widgetDepth);
- RectI elemClipRect(clipRect.x - myOffset.x, clipRect.y - myOffset.y, clipRect.width, clipRect.height);
- current->mFoldoutBtn->_setClipRect(elemClipRect);
- }
- offset.y += yOffset;
- tempOrderedElements.resize(current->mChildren.size(), nullptr);
- for(auto& child : current->mChildren)
- {
- tempOrderedElements[child->mSortedIdx] = child;
- }
- for(auto iter = tempOrderedElements.rbegin(); iter != tempOrderedElements.rend(); ++iter)
- {
- TreeElement* child = *iter;
- if(!child->mIsVisible)
- continue;
- todo.push(UpdateTreeElement(child, indent + 1));
- }
- }
- for(auto selectedElem : mSelectedElements)
- {
- GUILabel* targetElement = selectedElem.element->mElement;
- Vector2I offset = targetElement->_getOffset();
- offset.x = x;
- selectedElem.background->_setOffset(offset);
- selectedElem.background->_setWidth(width);
- selectedElem.background->_setHeight(targetElement->_getHeight());
- selectedElem.background->_setAreaDepth(areaDepth + 1);
- selectedElem.background->_setWidgetDepth(widgetDepth);
- RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
- selectedElem.background->_setClipRect(elemClipRect);
- }
- if(mEditElement != nullptr)
- {
- GUILabel* targetElement = mEditElement->mElement;
- Vector2I offset = targetElement->_getOffset();
- UINT32 remainingWidth = (UINT32)std::max(0, (((INT32)width) - (offset.x - x)));
- mNameEditBox->_setOffset(offset);
- mNameEditBox->_setWidth(remainingWidth);
- mNameEditBox->_setHeight(targetElement->_getHeight());
- mNameEditBox->_setAreaDepth(areaDepth);
- mNameEditBox->_setWidgetDepth(widgetDepth);
- RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
- mNameEditBox->_setClipRect(elemClipRect);
- }
- }
- const GUISceneTreeView::InteractableElement* GUISceneTreeView::findElementUnderCoord(const CM::Vector2I& coord) const
- {
- for(auto& element : mVisibleElements)
- {
- if(element.bounds.contains(coord))
- {
- return &element;
- }
- }
- return nullptr;
- }
- GUISceneTreeView::TreeElement* GUISceneTreeView::interactableToRealElement(const GUISceneTreeView::InteractableElement& element)
- {
- if(!element.isTreeElement())
- return nullptr;
- UINT32 sortedIdx = (element.index - 1) / 2;
- auto findIter = std::find_if(element.parent->mChildren.begin(), element.parent->mChildren.end(),
- [&](const TreeElement* x) { return x->mSortedIdx == sortedIdx; });
- if(findIter != element.parent->mChildren.end())
- return *findIter;
- return nullptr;
- }
- const String& GUISceneTreeView::getGUITypeName()
- {
- static String typeName = "SceneTreeView";
- return typeName;
- }
- }
|