commit 9c5317c8548109447a6863d7d5e457978036230f
parent 91d4212e930f2ec5f3416e3a78ad3fa9e7ac6d9b
Author: falkTX <falktx@falktx.com>
Date: Sun, 28 Mar 2021 17:42:39 +0100
Start splitting some code
Signed-off-by: falkTX <falktx@falktx.com>
Diffstat:
12 files changed, 644 insertions(+), 380 deletions(-)
diff --git a/dgl/Events.hpp b/dgl/Events.hpp
@@ -0,0 +1,225 @@
+/*
+ * DISTRHO Plugin Framework (DPF)
+ * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
+ *
+ * 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
+ * permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef DGL_EVENTS_HPP_INCLUDED
+#define DGL_EVENTS_HPP_INCLUDED
+
+#include "Geometry.hpp"
+
+START_NAMESPACE_DGL
+
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace Events
+{
+ /**
+ Base event data.
+ These are the fields present on all Widget events.
+
+ @a mod Currently active keyboard modifiers, @see Modifier.
+ @a mod Event flags, @see Flag.
+ @a time Event timestamp (if any).
+ */
+ struct BaseEvent {
+ uint mod;
+ uint flags;
+ uint time;
+
+ /** Constuctor */
+ BaseEvent() noexcept : mod(0x0), flags(0x0), time(0) {}
+ /** Destuctor */
+ virtual ~BaseEvent() noexcept {}
+ };
+
+ /**
+ Keyboard event.
+
+ This event represents low-level key presses and releases.
+ This can be used for "direct" keyboard handing like key bindings, but must not be interpreted as text input.
+
+ Keys are represented portably as Unicode code points, using the "natural" code point for the key.
+ The @a key field is the code for the pressed key, without any modifiers applied.
+ For example, a press or release of the 'A' key will have `key` 97 ('a')
+ regardless of whether shift or control are being held.
+
+ Alternatively, the raw @a keycode can be used to work directly with physical keys,
+ but note that this value is not portable and differs between platforms and hardware.
+
+ @a press True if the key was pressed, false if released.
+ @a key Unicode point of the key pressed.
+ @a keycode Raw keycode.
+ @see onKeyboard
+ */
+ struct KeyboardEvent : BaseEvent {
+ bool press;
+ uint key;
+ uint keycode;
+
+ /** Constuctor */
+ KeyboardEvent() noexcept
+ : BaseEvent(),
+ press(false),
+ key(0),
+ keycode(0) {}
+ };
+
+ /**
+ Special keyboard event.
+
+ This event allows the use of keys that do not have unicode points.
+ Note that some are non-printable keys.
+
+ @a press True if the key was pressed, false if released.
+ @a key The key pressed.
+ @see onSpecial
+ */
+ struct SpecialEvent : BaseEvent {
+ bool press;
+ Key key;
+
+ /** Constuctor */
+ SpecialEvent() noexcept
+ : BaseEvent(),
+ press(false),
+ key(Key(0)) {}
+ };
+
+ /**
+ Character input event.
+
+ This event represents text input, usually as the result of a key press.
+ The text is given both as a Unicode character code and a UTF-8 string.
+
+ Note that this event is generated by the platform's input system,
+ so there is not necessarily a direct correspondence between text events and physical key presses.
+ For example, with some input methods a sequence of several key presses will generate a single character.
+
+ @a keycode Raw key code.
+ @a character Unicode character code.
+ @a string UTF-8 string.
+ @see onCharacterInput
+ */
+ struct CharacterInputEvent : BaseEvent {
+ uint keycode;
+ uint character;
+ char string[8];
+
+ /** Constuctor */
+ CharacterInputEvent() noexcept
+ : BaseEvent(),
+ keycode(0),
+ character(0),
+ string{'\0','\0','\0','\0','\0','\0','\0','\0'} {}
+ };
+
+ /**
+ Mouse press or release event.
+
+ @a button The button number starting from 1 (1 = left, 2 = middle, 3 = right).
+ @a press True if the button was pressed, false if released.
+ @a pos The widget-relative coordinates of the pointer.
+ @see onMouse
+ */
+ struct MouseEvent : BaseEvent {
+ uint button;
+ bool press;
+ Point<double> pos;
+
+ /** Constuctor */
+ MouseEvent() noexcept
+ : BaseEvent(),
+ button(0),
+ press(false),
+ pos(0.0, 0.0) {}
+ };
+
+ /**
+ Mouse motion event.
+
+ @a pos The widget-relative coordinates of the pointer.
+ @see onMotion
+ */
+ struct MotionEvent : BaseEvent {
+ Point<double> pos;
+
+ /** Constuctor */
+ MotionEvent() noexcept
+ : BaseEvent(),
+ pos(0.0, 0.0) {}
+ };
+
+ /**
+ Mouse scroll event.
+
+ The scroll distance is expressed in "lines",
+ an arbitrary unit that corresponds to a single tick of a detented mouse wheel.
+ For example, `delta.y` = 1.0 scrolls 1 line up.
+ Some systems and devices support finer resolution and/or higher values for fast scrolls,
+ so programs should handle any value gracefully.
+
+ @a pos The widget-relative coordinates of the pointer.
+ @a delta The scroll distance.
+ @see onScroll
+ */
+ struct ScrollEvent : BaseEvent {
+ Point<double> pos;
+ Point<double> delta;
+
+ /** Constuctor */
+ ScrollEvent() noexcept
+ : BaseEvent(),
+ pos(0.0, 0.0),
+ delta(0.0, 0.0) {}
+ };
+
+ /**
+ Resize event.
+ @a size The new widget size.
+ @a oldSize The previous size, may be null.
+ @see onResize
+ */
+ struct ResizeEvent {
+ Size<uint> size;
+ Size<uint> oldSize;
+
+ /** Constuctor */
+ ResizeEvent() noexcept
+ : size(0, 0),
+ oldSize(0, 0) {}
+ };
+
+ /**
+ Widget position changed event.
+ @a pos The new absolute position of the widget.
+ @a oldPos The previous absolute position of the widget.
+ @see onPositionChanged
+ */
+ struct PositionChangedEvent {
+ Point<int> pos;
+ Point<int> oldPos;
+
+ /** Constuctor */
+ PositionChangedEvent() noexcept
+ : pos(0, 0),
+ oldPos(0, 0) {}
+ };
+}
+
+// --------------------------------------------------------------------------------------------------------------------
+
+END_NAMESPACE_DGL
+
+#endif // DGL_EVENTS_HPP_INCLUDED
diff --git a/dgl/StandaloneWindow.hpp b/dgl/StandaloneWindow.hpp
@@ -18,7 +18,7 @@
#define DGL_STANDALONE_WINDOW_HPP_INCLUDED
#include "Application.hpp"
-#include "Widget.hpp"
+#include "TopLevelWidget.hpp"
#include "Window.hpp"
START_NAMESPACE_DGL
@@ -40,16 +40,18 @@ public:
void exec();
private:
- Widget* fWidget;
+ TopLevelWidget* fWidget;
/** @internal */
void onReshape(uint width, uint height) override;
+#if 0
/** @internal */
- void _addWidget(Widget* widget) override;
+ void _addWidget(TopLevelWidget* widget) override;
/** @internal */
- void _removeWidget(Widget* widget) override;
+ void _removeWidget(TopLevelWidget* widget) override;
+#endif
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(StandaloneWindow)
};
diff --git a/dgl/SubWidget.hpp b/dgl/SubWidget.hpp
@@ -0,0 +1,103 @@
+/*
+ * DISTRHO Plugin Framework (DPF)
+ * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
+ *
+ * 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
+ * permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef DGL_SUBWIDGET_HPP_INCLUDED
+#define DGL_SUBWIDGET_HPP_INCLUDED
+
+#include "Widget.hpp"
+
+START_NAMESPACE_DGL
+
+// -----------------------------------------------------------------------
+
+class SubWidget : public Widget
+{
+public:
+ /**
+ Constructor.
+ */
+ explicit SubWidget(Widget* widgetToGroupTo);
+
+ /**
+ Destructor.
+ */
+ virtual ~SubWidget();
+
+ /**
+ Check if this widget contains the point defined by @a x and @a y.
+ */
+ template<typename T>
+ bool contains(T x, T y) const noexcept;
+
+ /**
+ Check if this widget contains the point @a pos.
+ */
+ template<typename T>
+ bool contains(const Point<T>& pos) const noexcept;
+
+ /**
+ Get absolute X.
+ */
+ int getAbsoluteX() const noexcept;
+
+ /**
+ Get absolute Y.
+ */
+ int getAbsoluteY() const noexcept;
+
+ /**
+ Get absolute position.
+ */
+ const Point<int>& getAbsolutePos() const noexcept;
+
+ /**
+ Set absolute X.
+ */
+ void setAbsoluteX(int x) noexcept;
+
+ /**
+ Set absolute Y.
+ */
+ void setAbsoluteY(int y) noexcept;
+
+ /**
+ Set absolute position using @a x and @a y values.
+ */
+ void setAbsolutePos(int x, int y) noexcept;
+
+ /**
+ Set absolute position.
+ */
+ void setAbsolutePos(const Point<int>& pos) noexcept;
+
+protected:
+ /**
+ A function called when the subwidget's absolute position is changed.
+ */
+ virtual void onPositionChanged(const PositionChangedEvent&);
+
+private:
+ struct PrivateData;
+ PrivateData* const pData;
+ DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SubWidget)
+};
+
+// -----------------------------------------------------------------------
+
+END_NAMESPACE_DGL
+
+#endif // DGL_SUBWIDGET_HPP_INCLUDED
+
diff --git a/dgl/TopLevelWidget.hpp b/dgl/TopLevelWidget.hpp
@@ -0,0 +1,50 @@
+/*
+ * DISTRHO Plugin Framework (DPF)
+ * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
+ *
+ * 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
+ * permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef DGL_TOP_LEVEL_WIDGET_HPP_INCLUDED
+#define DGL_TOP_LEVEL_WIDGET_HPP_INCLUDED
+
+#include "Widget.hpp"
+
+START_NAMESPACE_DGL
+
+// -----------------------------------------------------------------------
+
+/**
+ Top-Level Widget class.
+
+ This is the only Widget class that is allowed to be used directly on a Window.
+
+ 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.
+ */
+class TopLevelWidget : public Widget
+{
+public:
+ explicit TopLevelWidget(Window& windowToMapTo);
+
+private:
+ struct PrivateData;
+ PrivateData* const pData;
+ DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TopLevelWidget)
+};
+
+// -----------------------------------------------------------------------
+
+END_NAMESPACE_DGL
+
+#endif // DGL_TOP_LEVEL_WIDGET_HPP_INCLUDED
diff --git a/dgl/Widget.hpp b/dgl/Widget.hpp
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
- * Copyright (C) 2012-2019 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
* or without fee is hereby granted, provided that the above copyright notice and this
@@ -17,9 +17,7 @@
#ifndef DGL_WIDGET_HPP_INCLUDED
#define DGL_WIDGET_HPP_INCLUDED
-#include "Geometry.hpp"
-
-#include <vector>
+#include "Events.hpp"
// -----------------------------------------------------------------------
// Forward class names
@@ -33,9 +31,13 @@ END_NAMESPACE_DISTRHO
START_NAMESPACE_DGL
// class Application;
-class NanoWidget;
+// class NanoWidget;
class Window;
-class StandaloneWindow;
+// class StandaloneWindow;
+class SubWidget;
+class TopLevelWidget;
+
+using namespace Events;
// -----------------------------------------------------------------------
@@ -59,209 +61,13 @@ class StandaloneWindow;
*/
class Widget
{
-public:
- /**
- Base event data.
- These are the fields present on all Widget events.
-
- @a mod Currently active keyboard modifiers, @see Modifier.
- @a mod Event flags, @see Flag.
- @a time Event timestamp (if any).
- */
- struct BaseEvent {
- uint mod;
- uint flags;
- uint time;
-
- /** Constuctor */
- BaseEvent() noexcept : mod(0x0), flags(0x0), time(0) {}
- /** Destuctor */
- virtual ~BaseEvent() noexcept {}
- };
-
- /**
- Keyboard event.
-
- This event represents low-level key presses and releases.
- This can be used for "direct" keyboard handing like key bindings, but must not be interpreted as text input.
-
- Keys are represented portably as Unicode code points, using the "natural" code point for the key.
- The @a key field is the code for the pressed key, without any modifiers applied.
- For example, a press or release of the 'A' key will have `key` 97 ('a')
- regardless of whether shift or control are being held.
-
- Alternatively, the raw @a keycode can be used to work directly with physical keys,
- but note that this value is not portable and differs between platforms and hardware.
-
- @a press True if the key was pressed, false if released.
- @a key Unicode point of the key pressed.
- @a keycode Raw keycode.
- @see onKeyboard
- */
- struct KeyboardEvent : BaseEvent {
- bool press;
- uint key;
- uint keycode;
-
- /** Constuctor */
- KeyboardEvent() noexcept
- : BaseEvent(),
- press(false),
- key(0),
- keycode(0) {}
- };
-
- /**
- Special keyboard event.
-
- This event allows the use of keys that do not have unicode points.
- Note that some are non-printable keys.
-
- @a press True if the key was pressed, false if released.
- @a key The key pressed.
- @see onSpecial
- */
- struct SpecialEvent : BaseEvent {
- bool press;
- Key key;
-
- /** Constuctor */
- SpecialEvent() noexcept
- : BaseEvent(),
- press(false),
- key(Key(0)) {}
- };
-
- /**
- Character input event.
-
- This event represents text input, usually as the result of a key press.
- The text is given both as a Unicode character code and a UTF-8 string.
-
- Note that this event is generated by the platform's input system,
- so there is not necessarily a direct correspondence between text events and physical key presses.
- For example, with some input methods a sequence of several key presses will generate a single character.
-
- @a keycode Raw key code.
- @a character Unicode character code.
- @a string UTF-8 string.
- @see onCharacterInput
- */
- struct CharacterInputEvent : BaseEvent {
- uint keycode;
- uint character;
- char string[8];
-
- /** Constuctor */
- CharacterInputEvent() noexcept
- : BaseEvent(),
- keycode(0),
- character(0),
- string{'\0','\0','\0','\0','\0','\0','\0','\0'} {}
- };
-
- /**
- Mouse press or release event.
-
- @a button The button number starting from 1 (1 = left, 2 = middle, 3 = right).
- @a press True if the button was pressed, false if released.
- @a pos The widget-relative coordinates of the pointer.
- @see onMouse
- */
- struct MouseEvent : BaseEvent {
- uint button;
- bool press;
- Point<double> pos;
-
- /** Constuctor */
- MouseEvent() noexcept
- : BaseEvent(),
- button(0),
- press(false),
- pos(0.0, 0.0) {}
- };
-
- /**
- Mouse motion event.
-
- @a pos The widget-relative coordinates of the pointer.
- @see onMotion
- */
- struct MotionEvent : BaseEvent {
- Point<double> pos;
-
- /** Constuctor */
- MotionEvent() noexcept
- : BaseEvent(),
- pos(0.0, 0.0) {}
- };
-
- /**
- Mouse scroll event.
-
- The scroll distance is expressed in "lines",
- an arbitrary unit that corresponds to a single tick of a detented mouse wheel.
- For example, `delta.y` = 1.0 scrolls 1 line up.
- Some systems and devices support finer resolution and/or higher values for fast scrolls,
- so programs should handle any value gracefully.
-
- @a pos The widget-relative coordinates of the pointer.
- @a delta The scroll distance.
- @see onScroll
- */
- struct ScrollEvent : BaseEvent {
- Point<double> pos;
- Point<double> delta;
-
- /** Constuctor */
- ScrollEvent() noexcept
- : BaseEvent(),
- pos(0.0, 0.0),
- delta(0.0, 0.0) {}
- };
-
/**
- Resize event.
- @a size The new widget size.
- @a oldSize The previous size, may be null.
- @see onResize
+ Constructor, reserved for DGL ..
+ use TopLevelWidget or SubWidget instead
*/
- struct ResizeEvent {
- Size<uint> size;
- Size<uint> oldSize;
-
- /** Constuctor */
- ResizeEvent() noexcept
- : size(0, 0),
- oldSize(0, 0) {}
- };
-
- /**
- Widget position changed event.
- @a pos The new absolute position of the widget.
- @a oldPos The previous absolute position of the widget.
- @see onPositionChanged
- */
- struct PositionChangedEvent {
- Point<int> pos;
- Point<int> oldPos;
-
- /** Constuctor */
- PositionChangedEvent() noexcept
- : pos(0, 0),
- oldPos(0, 0) {}
- };
-
- /**
- Constructor.
- */
- explicit Widget(Window& parent);
-
- /**
- Constructor for a subwidget.
- */
- explicit Widget(Widget* groupWidget);
+ explicit Widget(TopLevelWidget& topLevelWidget);
+public:
/**
Destructor.
*/
@@ -326,68 +132,13 @@ public:
void setSize(const Size<uint>& size) noexcept;
/**
- Get absolute X.
+ Get top-level widget, as passed in the constructor.
*/
- int getAbsoluteX() const noexcept;
-
- /**
- Get absolute Y.
- */
- int getAbsoluteY() const noexcept;
-
- /**
- Get absolute position.
- */
- const Point<int>& getAbsolutePos() const noexcept;
-
- /**
- Set absolute X.
- */
- void setAbsoluteX(int x) noexcept;
-
- /**
- Set absolute Y.
- */
- void setAbsoluteY(int y) noexcept;
-
- /**
- Set absolute position using @a x and @a y values.
- */
- void setAbsolutePos(int x, int y) noexcept;
-
- /**
- Set absolute position.
- */
- void setAbsolutePos(const Point<int>& pos) noexcept;
-
-#if 0
- // TODO: should we remove this?
- /**
- Get this widget's window application.
- Same as calling getParentWindow().getApp().
- */
- Application& getParentApp() const noexcept;
-#endif
-
- /**
- Get parent window, as passed in the constructor.
- */
- Window& getParentWindow() const noexcept;
-
- /**
- Check if this widget contains the point defined by @a x and @a y.
- */
- template<typename T>
- bool contains(T x, T y) const noexcept;
-
- /**
- Check if this widget contains the point @a pos.
- */
- template<typename T>
- bool contains(const Point<T>& pos) const noexcept;
+ TopLevelWidget& getTopLevelWidget() const noexcept;
/**
Tell this widget's window to repaint itself.
+ FIXME better description, partial redraw
*/
void repaint() noexcept;
@@ -450,23 +201,14 @@ protected:
*/
virtual void onResize(const ResizeEvent&);
- /**
- A function called when the widget's absolute position is changed.
- */
- virtual void onPositionChanged(const PositionChangedEvent&);
-
- void setNeedsFullViewport();
-
private:
struct PrivateData;
PrivateData* const pData;
- /** @internal */
- explicit Widget(Widget* groupWidget, bool addToSubWidgets);
-
- friend class NanoWidget;
- friend class Window;
- friend class StandaloneWindow;
+// friend class NanoWidget;
+// friend class Window;
+// friend class StandaloneWindow;
+ friend class SubWidget;
#ifdef DISTRHO_DEFINES_H_INCLUDED
friend class DISTRHO_NAMESPACE::UI;
#endif
@@ -474,6 +216,20 @@ private:
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Widget)
};
+#if 0
+ // TODO: should we remove this?
+ /**
+ Get this widget's window application.
+ Same as calling getParentWindow().getApp().
+ */
+ Application& getParentApp() const noexcept;
+
+ /**
+ Get parent window, as passed in the constructor.
+ */
+ Window& getParentWindow() const noexcept;
+#endif
+
// -----------------------------------------------------------------------
END_NAMESPACE_DGL
diff --git a/dgl/src/StandaloneWindow.cpp b/dgl/src/StandaloneWindow.cpp
@@ -39,7 +39,8 @@ void StandaloneWindow::onReshape(uint width, uint height)
Window::onReshape(width, height);
}
-void StandaloneWindow::_addWidget(Widget* widget)
+#if 0
+void StandaloneWindow::_addWidget(TopLevelWidget* widget)
{
if (fWidget == nullptr)
{
@@ -49,7 +50,7 @@ void StandaloneWindow::_addWidget(Widget* widget)
Window::_addWidget(widget);
}
-void StandaloneWindow::_removeWidget(Widget* widget)
+void StandaloneWindow::_removeWidget(TopLevelWidget* widget)
{
if (fWidget == widget)
{
@@ -58,6 +59,7 @@ void StandaloneWindow::_removeWidget(Widget* widget)
}
Window::_removeWidget(widget);
}
+#endif
// -----------------------------------------------------------------------
diff --git a/dgl/src/SubWidget.cpp b/dgl/src/SubWidget.cpp
@@ -0,0 +1,79 @@
+/*
+ * DISTRHO Plugin Framework (DPF)
+ * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
+ *
+ * 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
+ * permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "SubWidgetPrivateData.hpp"
+
+template<typename T>
+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());
+}
+
+template<typename T>
+bool SubWidget::contains(const Point<T>& pos) const noexcept
+{
+ return contains(pos.getX(), pos.getY());
+}
+
+int SubWidget::getAbsoluteX() const noexcept
+{
+ return pData->absolutePos.getX();
+}
+
+int SubWidget::getAbsoluteY() const noexcept
+{
+ return pData->absolutePos.getY();
+}
+
+const Point<int>& SubWidget::getAbsolutePos() const noexcept
+{
+ return pData->absolutePos;
+}
+
+void SubWidget::setAbsoluteX(int x) noexcept
+{
+ setAbsolutePos(Point<int>(x, getAbsoluteY()));
+}
+
+void SubWidget::setAbsoluteY(int y) noexcept
+{
+ setAbsolutePos(Point<int>(getAbsoluteX(), y));
+}
+
+void SubWidget::setAbsolutePos(int x, int y) noexcept
+{
+ setAbsolutePos(Point<int>(x, y));
+}
+
+void SubWidget::setAbsolutePos(const Point<int>& pos) noexcept
+{
+ if (pData->absolutePos == pos)
+ return;
+
+ PositionChangedEvent ev;
+ ev.oldPos = pData->absolutePos;
+ ev.pos = pos;
+
+ pData->absolutePos = pos;
+ onPositionChanged(ev);
+
+ getTopLevelWidget().repaint();
+}
+
+void SubWidget::onPositionChanged(const PositionChangedEvent&)
+{
+}
diff --git a/dgl/src/SubWidgetPrivateData.hpp b/dgl/src/SubWidgetPrivateData.hpp
@@ -0,0 +1,49 @@
+/*
+ * DISTRHO Plugin Framework (DPF)
+ * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
+ *
+ * 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
+ * permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef DGL_SUBWIDGET_PRIVATE_DATA_HPP_INCLUDED
+#define DGL_SUBWIDGET_PRIVATE_DATA_HPP_INCLUDED
+
+#include "../SubWidget.hpp"
+#include "../WidgetPrivateData.hpp"
+
+#include <vector>
+
+START_NAMESPACE_DGL
+
+// -----------------------------------------------------------------------
+
+struct SubWidget::PrivateData {
+ SubWidget* const self;
+ Widget* const groupWidget;
+ Point<int> absolutePos;
+
+ PrivateData(SubWidget* const s, Widget* const g)
+ : self(s),
+ groupWidget(g),
+ absolutePos()
+ {
+ groupWidget->pData->subWidgets.push_back(self);
+ }
+
+ DISTRHO_DECLARE_NON_COPY_STRUCT(PrivateData)
+};
+
+// -----------------------------------------------------------------------
+
+END_NAMESPACE_DGL
+
+#endif // DGL_SUBWIDGET_PRIVATE_DATA_HPP_INCLUDED
diff --git a/dgl/src/TopLevelWidget.cpp b/dgl/src/TopLevelWidget.cpp
@@ -0,0 +1,17 @@
+/*
+ * DISTRHO Plugin Framework (DPF)
+ * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
+ *
+ * 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
+ * permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "TopLevelWidgetPrivateData.hpp"
diff --git a/dgl/src/TopLevelWidgetPrivateData.hpp b/dgl/src/TopLevelWidgetPrivateData.hpp
@@ -0,0 +1,42 @@
+/*
+ * DISTRHO Plugin Framework (DPF)
+ * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
+ *
+ * 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
+ * permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef DGL_TOP_LEVEL_WIDGET_PRIVATE_DATA_HPP_INCLUDED
+#define DGL_TOP_LEVEL_WIDGET_PRIVATE_DATA_HPP_INCLUDED
+
+#include "../TopLevelWidget.hpp"
+// #include "../WidgetPrivateData.hpp"
+
+START_NAMESPACE_DGL
+
+// -----------------------------------------------------------------------
+
+struct TopLevelWidget::PrivateData {
+ TopLevelWidget* const self;
+ Window& window;
+
+ PrivateData(TopLevelWidget* const s, Window& w)
+ : self(s),
+ window(w) {}
+
+ DISTRHO_DECLARE_NON_COPY_STRUCT(PrivateData)
+};
+
+// -----------------------------------------------------------------------
+
+END_NAMESPACE_DGL
+
+#endif // DGL_TOP_LEVEL_WIDGET_PRIVATE_DATA_HPP_INCLUDED
diff --git a/dgl/src/Widget.cpp b/dgl/src/Widget.cpp
@@ -21,20 +21,8 @@ START_NAMESPACE_DGL
// -----------------------------------------------------------------------
// Widget
-Widget::Widget(Window& parent)
- : pData(new PrivateData(this, parent, nullptr, false))
-{
-}
-
-Widget::Widget(Widget* groupWidget)
- : pData(new PrivateData(this, groupWidget->getParentWindow(), groupWidget, true))
-{
-}
-
-Widget::Widget(Widget* groupWidget, bool addToSubWidgets)
- : pData(new PrivateData(this, groupWidget->getParentWindow(), groupWidget, addToSubWidgets))
-{
-}
+Widget::Widget(TopLevelWidget& tlw)
+ : pData(new PrivateData(this, tlw)) {}
Widget::~Widget()
{
@@ -52,7 +40,7 @@ void Widget::setVisible(bool yesNo)
return;
pData->visible = yesNo;
- pData->parent.repaint();
+ pData->topLevelWidget.repaint();
}
void Widget::show()
@@ -92,7 +80,7 @@ void Widget::setWidth(uint width) noexcept
pData->size.setWidth(width);
onResize(ev);
- pData->parent.repaint();
+ pData->topLevelWidget.repaint();
}
void Widget::setHeight(uint height) noexcept
@@ -107,7 +95,7 @@ void Widget::setHeight(uint height) noexcept
pData->size.setHeight(height);
onResize(ev);
- pData->parent.repaint();
+ pData->topLevelWidget.repaint();
}
void Widget::setSize(uint width, uint height) noexcept
@@ -127,52 +115,7 @@ void Widget::setSize(const Size<uint>& size) noexcept
pData->size = size;
onResize(ev);
- pData->parent.repaint();
-}
-
-int Widget::getAbsoluteX() const noexcept
-{
- return pData->absolutePos.getX();
-}
-
-int Widget::getAbsoluteY() const noexcept
-{
- return pData->absolutePos.getY();
-}
-
-const Point<int>& Widget::getAbsolutePos() const noexcept
-{
- return pData->absolutePos;
-}
-
-void Widget::setAbsoluteX(int x) noexcept
-{
- setAbsolutePos(Point<int>(x, getAbsoluteY()));
-}
-
-void Widget::setAbsoluteY(int y) noexcept
-{
- setAbsolutePos(Point<int>(getAbsoluteX(), y));
-}
-
-void Widget::setAbsolutePos(int x, int y) noexcept
-{
- setAbsolutePos(Point<int>(x, y));
-}
-
-void Widget::setAbsolutePos(const Point<int>& pos) noexcept
-{
- if (pData->absolutePos == pos)
- return;
-
- PositionChangedEvent ev;
- ev.oldPos = pData->absolutePos;
- ev.pos = pos;
-
- pData->absolutePos = pos;
- onPositionChanged(ev);
-
- pData->parent.repaint();
+ pData->topLevelWidget.repaint();
}
#if 0
@@ -182,26 +125,15 @@ Application& Widget::getParentApp() const noexcept
}
#endif
-Window& Widget::getParentWindow() const noexcept
-{
- return pData->parent;
-}
-
-template<typename T>
-bool Widget::contains(T x, T y) const noexcept
-{
- return (x >= 0 && y >= 0 && static_cast<uint>(x) < pData->size.getWidth() && static_cast<uint>(y) < pData->size.getHeight());
-}
-
-template<typename T>
-bool Widget::contains(const Point<T>& pos) const noexcept
+TopLevelWidget& Widget::getTopLevelWidget() const noexcept
{
- return contains(pos.getX(), pos.getY());
+ return pData->topLevelWidget;
}
void Widget::repaint() noexcept
{
- pData->parent.repaint();
+ // FIXME partial repaint
+ // pData->topLevelWidget.repaint();
}
uint Widget::getId() const noexcept
@@ -248,14 +180,33 @@ void Widget::onResize(const ResizeEvent&)
{
}
-void Widget::onPositionChanged(const PositionChangedEvent&)
+// -----------------------------------------------------------------------
+
+// -----------------------------------------------------------------------
+
+// -----------------------------------------------------------------------
+
+#if 0
+Widget::Widget(Widget* groupWidget)
+ : pData(new PrivateData(this, groupWidget->getParentWindow(), groupWidget, true))
+{
+}
+
+Widget::Widget(Widget* groupWidget, bool addToSubWidgets)
+ : pData(new PrivateData(this, groupWidget->getParentWindow(), groupWidget, addToSubWidgets))
+{
+}
+
+Window& Widget::getParentWindow() const noexcept
{
+ return pData->parent;
}
void Widget::setNeedsFullViewport()
{
pData->needsFullViewport = true;
}
+#endif
// -----------------------------------------------------------------------
diff --git a/dgl/src/WidgetPrivateData.hpp b/dgl/src/WidgetPrivateData.hpp
@@ -17,7 +17,7 @@
#ifndef DGL_WIDGET_PRIVATE_DATA_HPP_INCLUDED
#define DGL_WIDGET_PRIVATE_DATA_HPP_INCLUDED
-#include "../Widget.hpp"
+#include "../TopLevelWidget.hpp"
#include "../Window.hpp"
#include <vector>
@@ -28,41 +28,29 @@ START_NAMESPACE_DGL
struct Widget::PrivateData {
Widget* const self;
- Window& parent;
- Point<int> absolutePos;
Size<uint> size;
std::vector<Widget*> subWidgets;
+ TopLevelWidget& topLevelWidget;
uint id;
- bool needsFullViewport;
bool needsScaling;
- bool skipDisplay;
bool visible;
- PrivateData(Widget* const s, Window& p, Widget* groupWidget, bool addToSubWidgets)
+ PrivateData(Widget* const s, TopLevelWidget& tlw)
: self(s),
- parent(p),
- absolutePos(0, 0),
size(0, 0),
subWidgets(),
+ topLevelWidget(tlw),
id(0),
- needsFullViewport(false),
needsScaling(false),
- skipDisplay(false),
visible(true)
{
- if (addToSubWidgets && groupWidget != nullptr)
- {
- skipDisplay = true;
- groupWidget->pData->subWidgets.push_back(self);
- }
-
- parent._addWidget(self);
+// parent._addWidget(self);
}
~PrivateData()
{
- parent._removeWidget(self);
+// parent._removeWidget(self);
subWidgets.clear();
}