void GUIElementBase::_setActive(bool active) { bool isActive = (mFlags & GUIElem_Inactive) == 0; if (isActive == active) return; if (!active) { _markLayoutAsDirty(); mFlags |= GUIElem_Inactive; for (auto& child : mChildren) child->_setActive(false); } else { bool childActiveSelf = (mFlags & GUIElem_InactiveSelf) == 0; if (childActiveSelf) { mFlags &= ~GUIElem_Inactive; _markLayoutAsDirty(); for (auto& child : mChildren) child->_setActive(true); } } }
void GUITabbedTitleBar::tabDragged(UINT32 tabIdx, const Vector2I& dragPos) { INT32 idx = uniqueIdxToSeqIdx(tabIdx); if(idx != -1) { Rect2I bounds = _getLayoutData().area; if(bounds.contains(dragPos)) { if(!mDragInProgress) startDrag(idx, dragPos); mDragBtnOffset = dragPos.x - mInitialDragOffset; for(INT32 i = 0; i < idx; i++) { UINT32 width = mTabButtons[i]->_getLayoutData().area.width; INT32 centerX = mTabButtons[i]->_getLayoutData().area.x + width / 2; if(dragPos.x < centerX) { GUITabButton* temp = mTabButtons[i]; mTabButtons[i] = mTabButtons[idx]; mTabButtons[idx] = temp; break; } } for(UINT32 i = idx + 1; i < (UINT32)mTabButtons.size(); i++) { UINT32 width = mTabButtons[i]->_getLayoutData().area.width; INT32 centerX = mTabButtons[i]->_getLayoutData().area.x + width / 2; if(dragPos.x > centerX) { GUITabButton* temp = mTabButtons[i]; mTabButtons[i] = mTabButtons[idx]; mTabButtons[idx] = temp; break; } } _markLayoutAsDirty(); } else { endDrag(); _markLayoutAsDirty(); if(!onTabDraggedOff.empty()) onTabDraggedOff(tabIdx); } } }
void GUIElement::resetDimensions() { mDimensions = GUIDimensions::create(); mDimensions.updateWithStyle(mStyle); _markLayoutAsDirty(); }
void GUIElementBase::_setVisible(bool visible) { bool isVisible = (mFlags & GUIElem_Hidden) == 0; if (isVisible == visible) return; if (!visible) { _markMeshAsDirty(); mFlags |= GUIElem_Hidden; for (auto& child : mChildren) child->_setVisible(false); } else { bool childVisibleSelf = (mFlags & GUIElem_HiddenSelf) == 0; if (childVisibleSelf) { mFlags &= ~GUIElem_Hidden; _markLayoutAsDirty(); for (auto& child : mChildren) child->_setVisible(true); } } }
void GUIScrollArea::vertScrollUpdate(float scrollPos) { UINT32 scrollableHeight = (UINT32)std::max(0, INT32(mContentSize.y) - INT32(mVisibleSize.y)); mVertOffset = scrollableHeight * Math::clamp01(scrollPos); _markLayoutAsDirty(); }
void GUIScrollArea::horzScrollUpdate(float scrollPos) { UINT32 scrollableWidth = (UINT32)std::max(0, INT32(mContentSize.x) - INT32(mVisibleSize.x)); mHorzOffset = scrollableWidth * Math::clamp01(scrollPos); _markLayoutAsDirty(); }
void GUIResourceTreeView::dropTargetDragDropped(INT32 x, INT32 y) { const GUITreeView::InteractableElement* element = findElementUnderCoord(Vector2I(x, y)); TreeElement* treeElement = nullptr; if(element != nullptr) { if(element->isTreeElement()) treeElement = element->getTreeElement(); else treeElement = element->parent; } if(mDropTarget->getDropType() == OSDropType::FileList) { Vector<WString> fileList = mDropTarget->getFileList(); mDraggedResources = bs_new<InternalDraggedResources>((UINT32)fileList.size()); for(UINT32 i = 0; i < (UINT32)fileList.size(); i++) mDraggedResources->resourcePaths[i] = fileList[i]; dragAndDropEnded(treeElement); bs_delete(mDraggedResources); mDraggedResources = nullptr; unselectAll(); } mDragInProgress = false; mDropTargetDragActive = false; _markLayoutAsDirty(); }
void GUIScrollArea::scrollToHorizontal(float pct) { mHorzScroll->_setScrollPos(pct); mRecalculateHorzOffset = true; _markLayoutAsDirty(); }
void GUIScrollArea::scrollToVertical(float pct) { mVertScroll->_setScrollPos(pct); mRecalculateVertOffset = true; _markLayoutAsDirty(); }
void GUIPanel::setDepthRange(INT16 depth, UINT16 depthRangeMin, UINT16 depthRangeMax) { mDepthOffset = depth; mDepthRangeMin = depthRangeMin; mDepthRangeMax = depthRangeMax; _markLayoutAsDirty(); }
void GUITabbedTitleBar::tabDragEnd(UINT32 tabIdx, const Vector2I& dragPos) { endDrag(); if(mActiveTabIdx != tabIdx) tabToggled(tabIdx, true); _markLayoutAsDirty(); }
void GUILayout::removeElementAt(UINT32 idx) { if(idx >= (UINT32)mChildren.size()) BS_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx) + ". Valid range: 0 .. " + toString((UINT32)mChildren.size())); GUIElementBase* child = mChildren[idx]; mChildren.erase(mChildren.begin() + idx); child->_setParent(nullptr); _markLayoutAsDirty(); }
void GUIButtonBase::_setState(GUIElementState state) { Vector2I origSize = mDimensions.calculateSizeRange(_getOptimalSize()).optimal; mActiveState = state; refreshContentSprite(); Vector2I newSize = mDimensions.calculateSizeRange(_getOptimalSize()).optimal; if (origSize != newSize) _markLayoutAsDirty(); else _markContentAsDirty(); }
void GUIElementBase::resetDimensions() { bool isFixedBefore = (mDimensions.flags & GUIDF_FixedWidth) != 0 && (mDimensions.flags & GUIDF_FixedHeight) != 0; mDimensions = GUIDimensions::create(); bool isFixedAfter = (mDimensions.flags & GUIDF_FixedWidth) != 0 && (mDimensions.flags & GUIDF_FixedHeight) != 0; if (isFixedBefore != isFixedAfter) refreshChildUpdateParents(); _markLayoutAsDirty(); }
void GUIResourceTreeView::dragAndDropFinalize() { mDragInProgress = false; _markLayoutAsDirty(); DraggedResources* draggedResources = reinterpret_cast<DraggedResources*>(DragAndDropManager::instance().getDragData()); bs_delete(draggedResources); if(mDraggedResources != nullptr) { bs_delete(mDraggedResources); mDraggedResources = nullptr; } }
void GUIElementBase::setHeight(UINT32 height) { bool isFixedBefore = (mDimensions.flags & GUIDF_FixedWidth) != 0 && (mDimensions.flags & GUIDF_FixedHeight) != 0; mDimensions.flags |= GUIDF_FixedHeight | GUIDF_OverHeight; mDimensions.minHeight = mDimensions.maxHeight = height; bool isFixedAfter = (mDimensions.flags & GUIDF_FixedWidth) != 0 && (mDimensions.flags & GUIDF_FixedHeight) != 0; if (isFixedBefore != isFixedAfter) refreshChildUpdateParents(); _markLayoutAsDirty(); }
void GUIButtonBase::setContent(const GUIContent& content) { Vector2I origSize = mDimensions.calculateSizeRange(_getOptimalSize()).optimal; mContent = content; refreshContentSprite(); Vector2I newSize = mDimensions.calculateSizeRange(_getOptimalSize()).optimal; if (origSize != newSize) _markLayoutAsDirty(); else _markContentAsDirty(); }
void GUIElementBase::setWidth(UINT32 width) { bool isFixedBefore = (mDimensions.flags & GUIDF_FixedWidth) != 0 && (mDimensions.flags & GUIDF_FixedHeight) != 0; mDimensions.flags |= GUIDF_FixedWidth | GUIDF_OverWidth; mDimensions.minWidth = mDimensions.maxWidth = width; bool isFixedAfter = (mDimensions.flags & GUIDF_FixedWidth) != 0 && (mDimensions.flags & GUIDF_FixedHeight) != 0; if (isFixedBefore != isFixedAfter) refreshChildUpdateParents(); _markLayoutAsDirty(); }
void GUIWindowFrame::setFocused(bool focused) { Vector2I origSize = mDimensions.calculateSizeRange(_getOptimalSize()).optimal; if(focused) mActiveTexture = _getStyle()->focused.texture; else mActiveTexture = _getStyle()->normal.texture; Vector2I newSize = mDimensions.calculateSizeRange(_getOptimalSize()).optimal; if (origSize != newSize) _markLayoutAsDirty(); else _markContentAsDirty(); }
void GUIElement::_refreshStyle() { const GUIElementStyle* newStyle = nullptr; if(_getParentWidget() != nullptr && !mStyleName.empty()) newStyle = _getParentWidget()->getSkin().getStyle(mStyleName); else newStyle = &GUISkin::DefaultStyle; if(newStyle != mStyle) { mStyle = newStyle; mDimensions.updateWithStyle(mStyle); styleUpdated(); _markLayoutAsDirty(); } }
void GUIResourceTreeView::entryAdded(const Path& path) { Path parentPath = path.getParent(); ResourceTreeElement* parentElement = findTreeElement(parentPath); assert(parentElement != nullptr); ResourceTreeElement* newElement = addTreeElement(parentElement, path); sortTreeElement(parentElement); ProjectLibrary::LibraryEntry* libEntry = gProjectLibrary().findEntry(path); assert(libEntry != nullptr); updateFromProjectLibraryEntry(newElement, libEntry); _markLayoutAsDirty(); }
void GUIElementBase::_registerChildElement(GUIElementBase* element) { assert(!element->_isDestroyed()); GUIElementBase* parentElement = element->_getParent(); if(parentElement != nullptr) { parentElement->_unregisterChildElement(element); } element->_setParent(this); mChildren.push_back(element); element->_setActive(_isActive()); element->_setVisible(_isVisible()); element->_setDisabled(_isDisabled()); _markLayoutAsDirty(); }
void GUIElementBase::setFlexibleWidth(UINT32 minWidth, UINT32 maxWidth) { if (maxWidth < minWidth) std::swap(minWidth, maxWidth); bool isFixedBefore = (mDimensions.flags & GUIDF_FixedWidth) != 0 && (mDimensions.flags & GUIDF_FixedHeight) != 0; mDimensions.flags |= GUIDF_OverWidth; mDimensions.flags &= ~GUIDF_FixedWidth; mDimensions.minWidth = minWidth; mDimensions.maxWidth = maxWidth; bool isFixedAfter = (mDimensions.flags & GUIDF_FixedWidth) != 0 && (mDimensions.flags & GUIDF_FixedHeight) != 0; if (isFixedBefore != isFixedAfter) refreshChildUpdateParents(); _markLayoutAsDirty(); }
void GUIResourceTreeView::dropTargetDragMove(INT32 x, INT32 y) { mDragPosition = Vector2I(x, y); mDragInProgress = true; mDropTargetDragActive = true; _markLayoutAsDirty(); if(mBottomScrollBounds.contains(mDragPosition)) { if(mScrollState != ScrollState::Down) mScrollState = ScrollState::TransitioningDown; } else if(mTopScrollBounds.contains(mDragPosition)) { if(mScrollState != ScrollState::Up) mScrollState = ScrollState::TransitioningUp; } else mScrollState = ScrollState::None; }
void GUIElementBase::_unregisterChildElement(GUIElementBase* element) { bool foundElem = false; for(auto iter = mChildren.begin(); iter != mChildren.end(); ++iter) { GUIElementBase* child = *iter; if (child == element) { mChildren.erase(iter); element->_setParent(nullptr); foundElem = true; _markLayoutAsDirty(); break; } } if(!foundElem) BS_EXCEPT(InvalidParametersException, "Provided element is not a part of this element."); }
void GUIElementBase::_changeParentWidget(GUIWidget* widget) { assert(!_isDestroyed()); if (mParentWidget != widget) { if (mParentWidget != nullptr) mParentWidget->_unregisterElement(this); if (widget != nullptr) widget->_registerElement(this); } mParentWidget = widget; for(auto& child : mChildren) { child->_changeParentWidget(widget); } _markLayoutAsDirty(); }
void GUILayout::insertElement(UINT32 idx, GUIElementBase* element) { if(idx > (UINT32)mChildren.size()) BS_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx) + ". Valid range: 0 .. " + toString((UINT32)mChildren.size())); if (element->_isDestroyed()) return; GUIElementBase* parentElement = element->_getParent(); if(parentElement != nullptr) { parentElement->_unregisterChildElement(element); } element->_setParent(this); mChildren.insert(mChildren.begin() + idx, element); element->_setActive(_isActive()); element->_setVisible(_isVisible()); element->_setDisabled(_isDisabled()); _markLayoutAsDirty(); }
void GUIProgressBar::setPercent(float pct) { mPercent = pct; _markLayoutAsDirty(); }
void GUIResourceTreeView::dropTargetDragLeave() { mDragInProgress = false; mDropTargetDragActive = false; _markLayoutAsDirty(); }