| @@ -21,16 +21,20 @@ | |||||
| START_NAMESPACE_DGL | START_NAMESPACE_DGL | ||||
| // ----------------------------------------------------------------------- | |||||
| // -------------------------------------------------------------------------------------------------------------------- | |||||
| /** | /** | ||||
| Sub-Widget class. | Sub-Widget class. | ||||
| This is a handy Widget class that can be freely positioned to be used directly on a Window. | |||||
| This class is the main entry point for creating any reusable widgets from within DGL. | |||||
| It can be freely positioned from within a parent widget, thus being named subwidget. | |||||
| This widget takes the full size of the Window it is mapped to. | |||||
| Sub-widgets can be added on top of this top-level widget, by creating them with this class as parent. | |||||
| Doing so allows for custom position and sizes. | |||||
| Many subwidgets can share the same parent, and subwidgets themselves can also have its own subwidgets. | |||||
| It is subwidgets all the way down. | |||||
| TODO check absolute vs relative position and see what makes more sense. | |||||
| @see CairoSubWidget | |||||
| */ | */ | ||||
| class SubWidget : public Widget | class SubWidget : public Widget | ||||
| { | { | ||||
| @@ -70,7 +74,7 @@ public: | |||||
| /** | /** | ||||
| Get absolute position. | Get absolute position. | ||||
| */ | */ | ||||
| const Point<int>& getAbsolutePos() const noexcept; | |||||
| Point<int> getAbsolutePos() const noexcept; | |||||
| /** | /** | ||||
| Set absolute X. | Set absolute X. | ||||
| @@ -104,7 +108,7 @@ private: | |||||
| DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SubWidget) | DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SubWidget) | ||||
| }; | }; | ||||
| // ----------------------------------------------------------------------- | |||||
| // -------------------------------------------------------------------------------------------------------------------- | |||||
| END_NAMESPACE_DGL | END_NAMESPACE_DGL | ||||
| @@ -33,8 +33,7 @@ SubWidget::~SubWidget() | |||||
| template<typename T> | template<typename T> | ||||
| bool SubWidget::contains(T x, T y) const noexcept | bool SubWidget::contains(T x, T y) const noexcept | ||||
| { | { | ||||
| const Size<uint>& size(getSize()); | |||||
| return (x >= 0 && y >= 0 && static_cast<uint>(x) < size.getWidth() && static_cast<uint>(y) < size.getHeight()); | |||||
| return Rectangle<double>(getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight()).contains(x, y); | |||||
| } | } | ||||
| template<typename T> | template<typename T> | ||||
| @@ -53,7 +52,7 @@ int SubWidget::getAbsoluteY() const noexcept | |||||
| return pData->absolutePos.getY(); | return pData->absolutePos.getY(); | ||||
| } | } | ||||
| const Point<int>& SubWidget::getAbsolutePos() const noexcept | |||||
| Point<int> SubWidget::getAbsolutePos() const noexcept | |||||
| { | { | ||||
| return pData->absolutePos; | return pData->absolutePos; | ||||
| } | } | ||||
| @@ -31,7 +31,7 @@ START_NAMESPACE_DGL | |||||
| Widget::PrivateData::PrivateData(Widget* const s, TopLevelWidget* const tlw) | Widget::PrivateData::PrivateData(Widget* const s, TopLevelWidget* const tlw) | ||||
| : self(s), | : self(s), | ||||
| topLevelWidget(tlw), | topLevelWidget(tlw), | ||||
| groupWidget(nullptr), | |||||
| parentGroupWidget(nullptr), | |||||
| id(0), | id(0), | ||||
| needsScaling(false), | needsScaling(false), | ||||
| visible(true), | visible(true), | ||||
| @@ -43,20 +43,20 @@ Widget::PrivateData::PrivateData(Widget* const s, TopLevelWidget* const tlw) | |||||
| Widget::PrivateData::PrivateData(Widget* const s, Widget* const g) | Widget::PrivateData::PrivateData(Widget* const s, Widget* const g) | ||||
| : self(s), | : self(s), | ||||
| topLevelWidget(findTopLevelWidget(g)), | topLevelWidget(findTopLevelWidget(g)), | ||||
| groupWidget(g), | |||||
| parentGroupWidget(g), | |||||
| id(0), | id(0), | ||||
| needsScaling(false), | needsScaling(false), | ||||
| visible(true), | visible(true), | ||||
| size(0, 0), | size(0, 0), | ||||
| subWidgets() | subWidgets() | ||||
| { | { | ||||
| groupWidget->pData->subWidgets.push_back(self); | |||||
| parentGroupWidget->pData->subWidgets.push_back(self); | |||||
| } | } | ||||
| Widget::PrivateData::~PrivateData() | Widget::PrivateData::~PrivateData() | ||||
| { | { | ||||
| if (groupWidget != nullptr) | |||||
| groupWidget->pData->subWidgets.remove(self); | |||||
| if (parentGroupWidget != nullptr) | |||||
| parentGroupWidget->pData->subWidgets.remove(self); | |||||
| subWidgets.clear(); | subWidgets.clear(); | ||||
| } | } | ||||
| @@ -74,8 +74,8 @@ void Widget::PrivateData::displaySubWidgets(const uint width, const uint height, | |||||
| void Widget::PrivateData::repaint() | void Widget::PrivateData::repaint() | ||||
| { | { | ||||
| if (groupWidget != nullptr) | |||||
| groupWidget->repaint(); | |||||
| if (parentGroupWidget != nullptr) | |||||
| parentGroupWidget->repaint(); | |||||
| else if (topLevelWidget != nullptr) | else if (topLevelWidget != nullptr) | ||||
| topLevelWidget->repaint(); | topLevelWidget->repaint(); | ||||
| } | } | ||||
| @@ -84,10 +84,12 @@ void Widget::PrivateData::repaint() | |||||
| TopLevelWidget* Widget::PrivateData::findTopLevelWidget(Widget* const w) | TopLevelWidget* Widget::PrivateData::findTopLevelWidget(Widget* const w) | ||||
| { | { | ||||
| if (TopLevelWidget* const tlw = dynamic_cast<TopLevelWidget*>(w)) | |||||
| return tlw; | |||||
| if (w->pData->topLevelWidget != nullptr) | if (w->pData->topLevelWidget != nullptr) | ||||
| return w->pData->topLevelWidget; | return w->pData->topLevelWidget; | ||||
| if (w->pData->groupWidget != nullptr) | |||||
| return findTopLevelWidget(w->pData->groupWidget); | |||||
| if (w->pData->parentGroupWidget != nullptr) | |||||
| return findTopLevelWidget(w->pData->parentGroupWidget); | |||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| @@ -28,7 +28,7 @@ START_NAMESPACE_DGL | |||||
| struct Widget::PrivateData { | struct Widget::PrivateData { | ||||
| Widget* const self; | Widget* const self; | ||||
| TopLevelWidget* const topLevelWidget; | TopLevelWidget* const topLevelWidget; | ||||
| Widget* const groupWidget; | |||||
| Widget* const parentGroupWidget; | |||||
| uint id; | uint id; | ||||
| bool needsScaling; | bool needsScaling; | ||||
| bool visible; | bool visible; | ||||
| @@ -36,7 +36,7 @@ struct Widget::PrivateData { | |||||
| std::list<Widget*> subWidgets; | std::list<Widget*> subWidgets; | ||||
| PrivateData(Widget* const s, TopLevelWidget* const tlw); | PrivateData(Widget* const s, TopLevelWidget* const tlw); | ||||
| PrivateData(Widget* const s, Widget* const g); | |||||
| PrivateData(Widget* const s, Widget* const pgw); | |||||
| ~PrivateData(); | ~PrivateData(); | ||||
| // NOTE display function is different depending on build type | // NOTE display function is different depending on build type | ||||
| @@ -1,6 +1,6 @@ | |||||
| /* | /* | ||||
| * DISTRHO Plugin Framework (DPF) | * DISTRHO Plugin Framework (DPF) | ||||
| * Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com> | |||||
| * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com> | |||||
| * | * | ||||
| * Permission to use, copy, modify, and/or distribute this software for any purpose with | * Permission to use, copy, modify, and/or distribute this software for any purpose with | ||||
| * or without fee is hereby granted, provided that the above copyright notice and this | * or without fee is hereby granted, provided that the above copyright notice and this | ||||
| @@ -21,7 +21,6 @@ | |||||
| // DGL Stuff | // DGL Stuff | ||||
| #include "../../dgl/SubWidget.hpp" | #include "../../dgl/SubWidget.hpp" | ||||
| // #include "Window.hpp" | |||||
| START_NAMESPACE_DGL | START_NAMESPACE_DGL | ||||
| @@ -31,6 +30,12 @@ START_NAMESPACE_DGL | |||||
| class ExampleColorWidget : public SubWidget, | class ExampleColorWidget : public SubWidget, | ||||
| public IdleCallback | public IdleCallback | ||||
| { | { | ||||
| char cur; | |||||
| bool reverse; | |||||
| int r, g, b; | |||||
| Rectangle<uint> bgFull, bgSmall; | |||||
| public: | public: | ||||
| ExampleColorWidget(TopLevelWidget* const topWidget) | ExampleColorWidget(TopLevelWidget* const topWidget) | ||||
| : SubWidget(topWidget), | : SubWidget(topWidget), | ||||
| @@ -40,7 +45,7 @@ public: | |||||
| { | { | ||||
| setSize(300, 300); | setSize(300, 300); | ||||
| // groupWidget->getApp().addIdleCallback(this); | |||||
| // topWidget->getApp().addIdleCallback(this); | |||||
| } | } | ||||
| protected: | protected: | ||||
| @@ -119,12 +124,6 @@ protected: | |||||
| // small bg, centered 2/3 size | // small bg, centered 2/3 size | ||||
| bgSmall = Rectangle<uint>(width/6, height/6, width*2/3, height*2/3); | bgSmall = Rectangle<uint>(width/6, height/6, width*2/3, height*2/3); | ||||
| } | } | ||||
| char cur; | |||||
| bool reverse; | |||||
| int r, g, b; | |||||
| Rectangle<uint> bgFull, bgSmall; | |||||
| }; | }; | ||||
| // ------------------------------------------------------ | // ------------------------------------------------------ | ||||