From 6bf22d0fc148bfbcbd133b0a81e0ce6d007c3d69 Mon Sep 17 00:00:00 2001 From: falkTX Date: Fri, 14 May 2021 20:57:55 +0100 Subject: [PATCH] Make ImageWidgets build again Signed-off-by: falkTX --- dgl/ImageWidgets.hpp | 50 +++++--------- dgl/Makefile | 1 + dgl/SubWidget.hpp | 5 ++ dgl/src/Common.hpp | 10 +-- dgl/src/ImageWidgets.cpp | 141 +++++++-------------------------------- dgl/src/SubWidget.cpp | 16 +++++ 6 files changed, 68 insertions(+), 155 deletions(-) diff --git a/dgl/ImageWidgets.hpp b/dgl/ImageWidgets.hpp index a88bc3ac..ec465320 100644 --- a/dgl/ImageWidgets.hpp +++ b/dgl/ImageWidgets.hpp @@ -18,36 +18,29 @@ #define DGL_IMAGE_WIDGETS_HPP_INCLUDED #include "Image.hpp" -#include "Widget.hpp" -#include "Window.hpp" +#include "StandaloneWindow.hpp" +#include "SubWidget.hpp" START_NAMESPACE_DGL // ----------------------------------------------------------------------- -#ifndef DISTRHO_OS_HAIKU -class ImageAboutWindow : public Window, - public Widget -#else -// crash when creating or opening 2nd window -class ImageAboutWindow -#endif +class ImageAboutWindow : public StandaloneWindow { public: - explicit ImageAboutWindow(Window& parent, const Image& image = Image()); - explicit ImageAboutWindow(Widget* widget, const Image& image = Image()); + explicit ImageAboutWindow(Window& parentWindow, const Image& image = Image()); + explicit ImageAboutWindow(TopLevelWidget* parentTopLevelWidget, const Image& image = Image()); void setImage(const Image& image); -#ifndef DISTRHO_OS_HAIKU + // TODO + void exec() {} + protected: void onDisplay() override; bool onKeyboard(const KeyboardEvent&) override; bool onMouse(const MouseEvent&) override; void onReshape(uint width, uint height) override; -#else - void exec() {} -#endif private: Image fImgBackground; @@ -57,7 +50,7 @@ private: // ----------------------------------------------------------------------- -class ImageButton : public Widget +class ImageButton : public SubWidget { public: class Callback @@ -67,13 +60,9 @@ public: virtual void imageButtonClicked(ImageButton* imageButton, int button) = 0; }; - explicit ImageButton(Window& parent, const Image& image); - explicit ImageButton(Window& parent, const Image& imageNormal, const Image& imageDown); - explicit ImageButton(Window& parent, const Image& imageNormal, const Image& imageHover, const Image& imageDown); - - explicit ImageButton(Widget* widget, const Image& image); - explicit ImageButton(Widget* widget, const Image& imageNormal, const Image& imageDown); - explicit ImageButton(Widget* widget, const Image& imageNormal, const Image& imageHover, const Image& imageDown); + explicit ImageButton(Widget* parentWidget, const Image& image); + explicit ImageButton(Widget* parentWidget, const Image& imageNormal, const Image& imageDown); + explicit ImageButton(Widget* parentWidget, const Image& imageNormal, const Image& imageHover, const Image& imageDown); ~ImageButton() override; @@ -93,7 +82,7 @@ private: // ----------------------------------------------------------------------- -class ImageKnob : public Widget +class ImageKnob : public SubWidget { public: enum Orientation { @@ -110,8 +99,7 @@ public: virtual void imageKnobValueChanged(ImageKnob* imageKnob, float value) = 0; }; - explicit ImageKnob(Window& parent, const Image& image, Orientation orientation = Vertical) noexcept; - explicit ImageKnob(Widget* widget, const Image& image, Orientation orientation = Vertical) noexcept; + explicit ImageKnob(Widget* parentWidget, const Image& image, Orientation orientation = Vertical) noexcept; explicit ImageKnob(const ImageKnob& imageKnob); ImageKnob& operator=(const ImageKnob& imageKnob); ~ImageKnob() override; @@ -172,7 +160,7 @@ private: // note set range and step before setting the value -class ImageSlider : public Widget +class ImageSlider : public SubWidget { public: class Callback @@ -184,8 +172,7 @@ public: virtual void imageSliderValueChanged(ImageSlider* imageSlider, float value) = 0; }; - explicit ImageSlider(Window& parent, const Image& image) noexcept; - explicit ImageSlider(Widget* widget, const Image& image) noexcept; + explicit ImageSlider(Widget* parentWidget, const Image& image) noexcept; float getValue() const noexcept; void setValue(float value, bool sendCallback = false) noexcept; @@ -242,7 +229,7 @@ private: // ----------------------------------------------------------------------- -class ImageSwitch : public Widget +class ImageSwitch : public SubWidget { public: class Callback @@ -252,8 +239,7 @@ public: virtual void imageSwitchClicked(ImageSwitch* imageSwitch, bool down) = 0; }; - explicit ImageSwitch(Window& parent, const Image& imageNormal, const Image& imageDown) noexcept; - explicit ImageSwitch(Widget* widget, const Image& imageNormal, const Image& imageDown) noexcept; + explicit ImageSwitch(Widget* parentWidget, const Image& imageNormal, const Image& imageDown) noexcept; explicit ImageSwitch(const ImageSwitch& imageSwitch) noexcept; ImageSwitch& operator=(const ImageSwitch& imageSwitch) noexcept; diff --git a/dgl/Makefile b/dgl/Makefile index 9adc3f0c..b8a3db4f 100644 --- a/dgl/Makefile +++ b/dgl/Makefile @@ -59,6 +59,7 @@ OBJS_cairo = $(OBJS_common) \ # --------------------------------------------------------------------------------------------------------------------- OBJS_opengl = $(OBJS_common) \ + ../build/dgl/ImageWidgets.cpp.o \ ../build/dgl/OpenGL.cpp.opengl.o \ ../build/dgl/NanoVG.cpp.opengl.o \ ../build/dgl/pugl.cpp.opengl.o diff --git a/dgl/SubWidget.hpp b/dgl/SubWidget.hpp index 8969ea8e..83118d32 100644 --- a/dgl/SubWidget.hpp +++ b/dgl/SubWidget.hpp @@ -109,6 +109,11 @@ public: */ void setAbsolutePos(const Point& pos) noexcept; + /** + Get parent Widget, as passed in the constructor. + */ + Widget* getParentWidget() const noexcept; + /** Request repaint of this subwidget's area to the window this widget belongs to. */ diff --git a/dgl/src/Common.hpp b/dgl/src/Common.hpp index fd1070a0..e4e4d552 100644 --- a/dgl/src/Common.hpp +++ b/dgl/src/Common.hpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2016 Filipe Coelho + * Copyright (C) 2012-2021 Filipe Coelho * * 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 @@ -32,17 +32,17 @@ struct ButtonImpl { int button; int state; - Widget* self; + SubWidget* self; ImageButton::Callback* callback_img; - ButtonImpl(Widget* const s) noexcept + ButtonImpl(SubWidget* const s) noexcept : button(-1), state(kStateNormal), self(s), callback_img(nullptr) {} - bool onMouse(const Widget::MouseEvent& ev) + bool onMouse(const Events::MouseEvent& ev) { // button was released, handle it now if (button != -1 && ! ev.press) @@ -83,7 +83,7 @@ struct ButtonImpl { return false; } - bool onMotion(const Widget::MotionEvent& ev) + bool onMotion(const Events::MotionEvent& ev) { // keep pressed if (button != -1) diff --git a/dgl/src/ImageWidgets.cpp b/dgl/src/ImageWidgets.cpp index b7c2f0db..f19c1894 100644 --- a/dgl/src/ImageWidgets.cpp +++ b/dgl/src/ImageWidgets.cpp @@ -25,30 +25,25 @@ START_NAMESPACE_DGL // ----------------------------------------------------------------------- -#ifndef DISTRHO_OS_HAIKU -ImageAboutWindow::ImageAboutWindow(Window& parent, const Image& image) - : Window(parent), - Widget((Window&)*this), +ImageAboutWindow::ImageAboutWindow(Window& parentWindow, const Image& image) + : StandaloneWindow(parentWindow.getApp()), fImgBackground(image) { + // TODO set transient Window::setResizable(false); Window::setSize(image.getSize()); Window::setTitle("About"); } -ImageAboutWindow::ImageAboutWindow(Widget* widget, const Image& image) - : Window(widget->getParentWindow()), - Widget((Window&)*this), +ImageAboutWindow::ImageAboutWindow(TopLevelWidget* const parentTopLevelWidget, const Image& image) + : StandaloneWindow(parentTopLevelWidget->getApp()), fImgBackground(image) { + // TODO set transient Window::setResizable(false); Window::setSize(image.getSize()); Window::setTitle("About"); } -#else -ImageAboutWindow::ImageAboutWindow(Window& parent, const Image& image) : fImgBackground(image) {} -ImageAboutWindow::ImageAboutWindow(Widget* widget, const Image& image) : fImgBackground(image) {} -#endif void ImageAboutWindow::setImage(const Image& image) { @@ -56,12 +51,9 @@ void ImageAboutWindow::setImage(const Image& image) return; fImgBackground = image; -#ifndef DISTRHO_OS_HAIKU Window::setSize(image.getSize()); -#endif } -#ifndef DISTRHO_OS_HAIKU void ImageAboutWindow::onDisplay() { fImgBackground.draw(); @@ -94,7 +86,6 @@ void ImageAboutWindow::onReshape(uint width, uint height) Widget::setSize(width, height); Window::onReshape(width, height); } -#endif // ----------------------------------------------------------------------- @@ -104,7 +95,7 @@ struct ImageButton::PrivateData { Image imageHover; Image imageDown; - PrivateData(Widget* const s, const Image& normal, const Image& hover, const Image& down) + PrivateData(SubWidget* const s, const Image& normal, const Image& hover, const Image& down) : impl(s), imageNormal(normal), imageHover(hover), @@ -115,40 +106,15 @@ struct ImageButton::PrivateData { // ----------------------------------------------------------------------- -ImageButton::ImageButton(Window& parent, const Image& image) - : Widget(parent), - pData(new PrivateData(this, image, image, image)) -{ - setSize(image.getSize()); -} - -ImageButton::ImageButton(Window& parent, const Image& imageNormal, const Image& imageDown) - : Widget(parent), - pData(new PrivateData(this, imageNormal, imageNormal, imageDown)) -{ - DISTRHO_SAFE_ASSERT(imageNormal.getSize() == imageDown.getSize()); - - setSize(imageNormal.getSize()); -} - -ImageButton::ImageButton(Window& parent, const Image& imageNormal, const Image& imageHover, const Image& imageDown) - : Widget(parent), - pData(new PrivateData(this, imageNormal, imageHover, imageDown)) -{ - DISTRHO_SAFE_ASSERT(imageNormal.getSize() == imageHover.getSize() && imageHover.getSize() == imageDown.getSize()); - - setSize(imageNormal.getSize()); -} - -ImageButton::ImageButton(Widget* widget, const Image& image) - : Widget(widget->getParentWindow()), +ImageButton::ImageButton(Widget* const parentWidget, const Image& image) + : SubWidget(parentWidget), pData(new PrivateData(this, image, image, image)) { setSize(image.getSize()); } -ImageButton::ImageButton(Widget* widget, const Image& imageNormal, const Image& imageDown) - : Widget(widget->getParentWindow()), +ImageButton::ImageButton(Widget* const parentWidget, const Image& imageNormal, const Image& imageDown) + : SubWidget(parentWidget), pData(new PrivateData(this, imageNormal, imageNormal, imageDown)) { DISTRHO_SAFE_ASSERT(imageNormal.getSize() == imageDown.getSize()); @@ -156,8 +122,8 @@ ImageButton::ImageButton(Widget* widget, const Image& imageNormal, const Image& setSize(imageNormal.getSize()); } -ImageButton::ImageButton(Widget* widget, const Image& imageNormal, const Image& imageHover, const Image& imageDown) - : Widget(widget->getParentWindow()), +ImageButton::ImageButton(Widget* const parentWidget, const Image& imageNormal, const Image& imageHover, const Image& imageDown) + : SubWidget(parentWidget), pData(new PrivateData(this, imageNormal, imageHover, imageDown)) { DISTRHO_SAFE_ASSERT(imageNormal.getSize() == imageHover.getSize() && imageHover.getSize() == imageDown.getSize()); @@ -203,36 +169,8 @@ bool ImageButton::onMotion(const MotionEvent& ev) // ----------------------------------------------------------------------- -ImageKnob::ImageKnob(Window& parent, const Image& image, Orientation orientation) noexcept - : Widget(parent), - fImage(image), - fMinimum(0.0f), - fMaximum(1.0f), - fStep(0.0f), - fValue(0.5f), - fValueDef(fValue), - fValueTmp(fValue), - fUsingDefault(false), - fUsingLog(false), - fOrientation(orientation), - fRotationAngle(0), - fDragging(false), - fLastX(0), - fLastY(0), - fCallback(nullptr), - fIsImgVertical(image.getHeight() > image.getWidth()), - fImgLayerWidth(fIsImgVertical ? image.getWidth() : image.getHeight()), - fImgLayerHeight(fImgLayerWidth), - fImgLayerCount(fIsImgVertical ? image.getHeight()/fImgLayerHeight : image.getWidth()/fImgLayerWidth), - fIsReady(false), - fTextureId(0) -{ - glGenTextures(1, &fTextureId); - setSize(fImgLayerWidth, fImgLayerHeight); -} - -ImageKnob::ImageKnob(Widget* widget, const Image& image, Orientation orientation) noexcept - : Widget(widget->getParentWindow()), +ImageKnob::ImageKnob(Widget* const parentWidget, const Image& image, Orientation orientation) noexcept + : SubWidget(parentWidget), fImage(image), fMinimum(0.0f), fMaximum(1.0f), @@ -260,7 +198,7 @@ ImageKnob::ImageKnob(Widget* widget, const Image& image, Orientation orientation } ImageKnob::ImageKnob(const ImageKnob& imageKnob) - : Widget(imageKnob.getParentWindow()), + : SubWidget(imageKnob.getParentWidget()), fImage(imageKnob.fImage), fMinimum(imageKnob.fMinimum), fMaximum(imageKnob.fMaximum), @@ -655,31 +593,8 @@ float ImageKnob::_invlogscale(float value) const // ----------------------------------------------------------------------- -ImageSlider::ImageSlider(Window& parent, const Image& image) noexcept - : Widget(parent), - fImage(image), - fMinimum(0.0f), - fMaximum(1.0f), - fStep(0.0f), - fValue(0.5f), - fValueDef(fValue), - fValueTmp(fValue), - fUsingDefault(false), - fDragging(false), - fInverted(false), - fValueIsSet(false), - fStartedX(0), - fStartedY(0), - fCallback(nullptr), - fStartPos(), - fEndPos(), - fSliderArea() -{ - setNeedsFullViewport(); -} - -ImageSlider::ImageSlider(Widget* widget, const Image& image) noexcept - : Widget(widget->getParentWindow()), +ImageSlider::ImageSlider(Widget* const parentWidget, const Image& image) noexcept + : SubWidget(parentWidget), fImage(image), fMinimum(0.0f), fMaximum(1.0f), @@ -698,7 +613,9 @@ ImageSlider::ImageSlider(Widget* widget, const Image& image) noexcept fEndPos(), fSliderArea() { + /* TODO setNeedsFullViewport(); + */ } float ImageSlider::getValue() const noexcept @@ -1008,20 +925,8 @@ void ImageSlider::_recheckArea() noexcept // ----------------------------------------------------------------------- -ImageSwitch::ImageSwitch(Window& parent, const Image& imageNormal, const Image& imageDown) noexcept - : Widget(parent), - fImageNormal(imageNormal), - fImageDown(imageDown), - fIsDown(false), - fCallback(nullptr) -{ - DISTRHO_SAFE_ASSERT(fImageNormal.getSize() == fImageDown.getSize()); - - setSize(fImageNormal.getSize()); -} - -ImageSwitch::ImageSwitch(Widget* widget, const Image& imageNormal, const Image& imageDown) noexcept - : Widget(widget->getParentWindow()), +ImageSwitch::ImageSwitch(Widget* parentWidget, const Image& imageNormal, const Image& imageDown) noexcept + : SubWidget(parentWidget), fImageNormal(imageNormal), fImageDown(imageDown), fIsDown(false), @@ -1033,7 +938,7 @@ ImageSwitch::ImageSwitch(Widget* widget, const Image& imageNormal, const Image& } ImageSwitch::ImageSwitch(const ImageSwitch& imageSwitch) noexcept - : Widget(imageSwitch.getParentWindow()), + : SubWidget(imageSwitch.getParentWidget()), fImageNormal(imageSwitch.fImageNormal), fImageDown(imageSwitch.fImageDown), fIsDown(imageSwitch.fIsDown), diff --git a/dgl/src/SubWidget.cpp b/dgl/src/SubWidget.cpp index b694dd33..6cd8e6d9 100644 --- a/dgl/src/SubWidget.cpp +++ b/dgl/src/SubWidget.cpp @@ -100,6 +100,11 @@ void SubWidget::setAbsolutePos(const Point& pos) noexcept pData->parentWidget->repaint(); } +Widget* SubWidget::getParentWidget() const noexcept +{ + return pData->parentWidget; +} + void SubWidget::repaint() noexcept { if (! isVisible()) @@ -113,6 +118,17 @@ void SubWidget::onPositionChanged(const PositionChangedEvent&) { } +// -------------------------------------------------------------------------------------------------------------------- +// Possible template data types + +template<> +bool SubWidget::contains(const Point& pos) const noexcept +{ + return contains(pos.getX(), pos.getY()); +} + +// float, int, uint, short, ushort + // -------------------------------------------------------------------------------------------------------------------- END_NAMESPACE_DGL