From 9cc48195242fa856b58c9fbf7669ee90e1a54ce2 Mon Sep 17 00:00:00 2001 From: IlyaShurupov Date: Tue, 25 Jun 2024 18:34:38 +0300 Subject: [PATCH] dockspce widget initial --- Containers/public/List.hpp | 1 + Widgets/examples/SimpleGUI.hpp | 17 +++++++++++---- Widgets/private/DockspaceWidget.cpp | 34 +++++++++++++++++++++++++++++ Widgets/private/FloatingWidget.cpp | 4 ++-- Widgets/private/WidgetBase.cpp | 13 ++++++----- Widgets/public/DockspaceWidget.hpp | 11 ++++++++++ Widgets/public/WidgetBase.hpp | 1 + Widgets/public/Widgets.hpp | 3 ++- 8 files changed, 72 insertions(+), 12 deletions(-) create mode 100644 Widgets/private/DockspaceWidget.cpp create mode 100644 Widgets/public/DockspaceWidget.hpp diff --git a/Containers/public/List.hpp b/Containers/public/List.hpp index c1fe3d3..fafad37 100644 --- a/Containers/public/List.hpp +++ b/Containers/public/List.hpp @@ -110,6 +110,7 @@ namespace tp { } void attach(Node* node, Node* node_to) { + node->next = node->prev = nullptr; if (node_to) { if (node_to->next) { node->next = node_to->next; diff --git a/Widgets/examples/SimpleGUI.hpp b/Widgets/examples/SimpleGUI.hpp index 50f1b84..636a53a 100644 --- a/Widgets/examples/SimpleGUI.hpp +++ b/Widgets/examples/SimpleGUI.hpp @@ -23,15 +23,21 @@ namespace tp { NamedSliderWidget mSlider; }; - class SimpleWidget2 : public Widget { + class SimpleWidget2 : public DockSpaceWidget { public: SimpleWidget2() { this->mChildWidgets.pushBack(&mFloating); mFloating.addWidgetToMenu(&mWidget); - mFloating.addWidgetToMenu(&mWidget2); - // this->mChildWidgets.pushBack(&mFloating2); - // mFloating2.addWidgetToMenu(&mWidget2); + this->mChildWidgets.pushBack(&mFloating2); + mFloating2.addWidgetToMenu(&mWidget2); + + mFloating2.mArea = { 200, 100, 100, 100 }; + + this->mChildWidgets.pushBack(&mFloating3); + mFloating3.addWidgetToMenu(&mWidget3); + + mFloating3.mArea = { 400, 100, 100, 100 }; } private: @@ -40,5 +46,8 @@ namespace tp { FloatingWidget mFloating2; SimpleWidget mWidget2; + + FloatingWidget mFloating3; + SimpleWidget mWidget3; }; } \ No newline at end of file diff --git a/Widgets/private/DockspaceWidget.cpp b/Widgets/private/DockspaceWidget.cpp new file mode 100644 index 0000000..25619c9 --- /dev/null +++ b/Widgets/private/DockspaceWidget.cpp @@ -0,0 +1,34 @@ +#include "DockspaceWidget.hpp" + +using namespace tp; + +void DockSpaceWidget::eventProcess(const tp::Events& events) { + + if (this->mChildWidgets.size() > 1 && events.isPressed(InputID::MOUSE1)) { + + Widget* activeChild = nullptr; + + for (auto childNode = this->mChildWidgets.firstNode(); childNode; childNode = childNode->next) { + auto child = childNode->data; + if (child->mArea.isInside(events.getPointer())) { + + mChildWidgets.detach(childNode); + mChildWidgets.pushFront(childNode); + + child->mHandlesEvents = true; + activeChild = child; + break; + } + } + + if (activeChild) { + for (auto child : this->mChildWidgets) { + if (activeChild != child.data()) child->mHandlesEvents = false; + } + } + } +} + +void DockSpaceWidget::eventDraw(Canvas& canvas) { + canvas.rect(this->mArea, RGBA(0, 0, 0, 1), 0); +} diff --git a/Widgets/private/FloatingWidget.cpp b/Widgets/private/FloatingWidget.cpp index 9510d2b..8adc986 100644 --- a/Widgets/private/FloatingWidget.cpp +++ b/Widgets/private/FloatingWidget.cpp @@ -9,11 +9,11 @@ FloatingWidget::FloatingWidget() { } void FloatingWidget::eventProcess(const Events& events) { + mActionStartRelativePos = events.getPointerPrev() - this->mArea.pos; + checkFloating(events); checkResizing(events); - mActionStartRelativePos = events.getPointer() - this->mArea.pos; - CollapsableMenu::eventProcess(events); } diff --git a/Widgets/private/WidgetBase.cpp b/Widgets/private/WidgetBase.cpp index 620ff50..59db281 100644 --- a/Widgets/private/WidgetBase.cpp +++ b/Widgets/private/WidgetBase.cpp @@ -17,10 +17,13 @@ void Widget::procWrapper(const Events& events, const RectF& parentArea) { checkClicked(events); - eventProcess(events); + if (mHandlesEvents) { - for (auto child : mChildWidgets) { - child->procWrapper(events, getArea()); + eventProcess(events); + + for (auto child : mChildWidgets) { + child->procWrapper(events, getArea()); + } } } @@ -31,8 +34,8 @@ void Widget::drawWrapper(Canvas& canvas) { // draw child widgets canvas.pushClamp(this->mArea); - for (auto child : mChildWidgets) { - child->drawWrapper(canvas); + for (auto child = mChildWidgets.lastNode(); child; child = child->prev) { + child->data->drawWrapper(canvas); } canvas.popClamp(); } diff --git a/Widgets/public/DockspaceWidget.hpp b/Widgets/public/DockspaceWidget.hpp new file mode 100644 index 0000000..bc152e3 --- /dev/null +++ b/Widgets/public/DockspaceWidget.hpp @@ -0,0 +1,11 @@ +#include "FloatingWidget.hpp" + +namespace tp { + class DockSpaceWidget : public Widget { + public: + DockSpaceWidget() = default; + + void eventProcess(const Events& events) override; + void eventDraw(Canvas& canvas) override; + }; +} \ No newline at end of file diff --git a/Widgets/public/WidgetBase.hpp b/Widgets/public/WidgetBase.hpp index f7bcda9..2e3d7af 100644 --- a/Widgets/public/WidgetBase.hpp +++ b/Widgets/public/WidgetBase.hpp @@ -57,6 +57,7 @@ namespace tp { bool mVisible = false; bool mEnable = true; + bool mHandlesEvents = true; bool mInFocus = false; bool mHolding = false; diff --git a/Widgets/public/Widgets.hpp b/Widgets/public/Widgets.hpp index 7fa4b09..4de32ca 100644 --- a/Widgets/public/Widgets.hpp +++ b/Widgets/public/Widgets.hpp @@ -8,4 +8,5 @@ #include "SliderWidget.hpp" #include "CollapsableMenu.hpp" #include "FloatingWidget.hpp" -#include "Animations.hpp" \ No newline at end of file +#include "Animations.hpp" +#include "DockspaceWidget.hpp"