diff --git a/dpf/dgl/ImageBaseWidgets.hpp b/dpf/dgl/ImageBaseWidgets.hpp index 1a4fbbe..a4bf007 100644 --- a/dpf/dgl/ImageBaseWidgets.hpp +++ b/dpf/dgl/ImageBaseWidgets.hpp @@ -192,6 +192,7 @@ public: void setEndPos(const Point& endPos) noexcept; void setEndPos(int x, int y) noexcept; + void setCheckable(bool checkable) noexcept; void setInverted(bool inverted) noexcept; void setRange(float min, float max) noexcept; void setStep(float step) noexcept; diff --git a/dpf/dgl/OpenGL.hpp b/dpf/dgl/OpenGL.hpp index 91da7e3..4d2e9ce 100644 --- a/dpf/dgl/OpenGL.hpp +++ b/dpf/dgl/OpenGL.hpp @@ -202,8 +202,9 @@ public: GLenum getType() const noexcept { return GL_UNSIGNED_BYTE; } private: - GLuint textureId; bool setupCalled; + bool textureInit; + GLuint textureId; }; // ----------------------------------------------------------------------- diff --git a/dpf/dgl/StandaloneWindow.hpp b/dpf/dgl/StandaloneWindow.hpp index 673a85e..017a3a7 100644 --- a/dpf/dgl/StandaloneWindow.hpp +++ b/dpf/dgl/StandaloneWindow.hpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2021 Filipe Coelho + * Copyright (C) 2012-2022 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 @@ -53,6 +53,15 @@ public: sgc.done(); } + /** + Get a graphics context back again. + Called when a valid graphics context is needed outside the constructor. + */ + void reinit() + { + sgc.reinit(); + } + /** Overloaded functions to ensure they apply to the Window class. */ diff --git a/dpf/dgl/Window.hpp b/dpf/dgl/Window.hpp index 9971988..b18fe07 100644 --- a/dpf/dgl/Window.hpp +++ b/dpf/dgl/Window.hpp @@ -105,13 +105,17 @@ public: /** Early context clearing, useful for standalone windows not created by you. */ void done(); + /** Get a valid context back again. */ + void reinit(); + DISTRHO_DECLARE_NON_COPYABLE(ScopedGraphicsContext) DISTRHO_PREVENT_HEAP_ALLOCATION private: Window& window; - Window::PrivateData* ppData; + Window::PrivateData* const ppData; bool active; + bool reenter; }; /** diff --git a/dpf/dgl/src/ImageBaseWidgets.cpp b/dpf/dgl/src/ImageBaseWidgets.cpp index eadc57f..213511e 100644 --- a/dpf/dgl/src/ImageBaseWidgets.cpp +++ b/dpf/dgl/src/ImageBaseWidgets.cpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2021 Filipe Coelho + * Copyright (C) 2012-2022 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 @@ -61,13 +61,20 @@ void ImageBaseAboutWindow::setImage(const ImageType& image) if (img == image) return; - img = image; - if (image.isInvalid()) + { + img = image; return; + } + + reinit(); + + img = image; setSize(image.getSize()); setGeometryConstraints(image.getWidth(), image.getHeight(), true, true); + + done(); } template @@ -428,6 +435,7 @@ struct ImageBaseSlider::PrivateData { bool usingDefault; bool dragging; + bool checkable; bool inverted; bool valueIsSet; double startedX; @@ -449,6 +457,7 @@ struct ImageBaseSlider::PrivateData { valueTmp(value), usingDefault(false), dragging(false), + checkable(false), inverted(false), valueIsSet(false), startedX(0.0), @@ -553,6 +562,16 @@ void ImageBaseSlider::setEndPos(int x, int y) noexcept setEndPos(Point(x, y)); } +template +void ImageBaseSlider::setCheckable(bool checkable) noexcept +{ + if (pData->checkable == checkable) + return; + + pData->checkable = checkable; + repaint(); +} + template void ImageBaseSlider::setInverted(bool inverted) noexcept { @@ -674,6 +693,14 @@ bool ImageBaseSlider::onMouse(const MouseEvent& ev) return true; } + if (pData->checkable) + { + const float value = d_isEqual(pData->valueTmp, pData->minimum) ? pData->maximum : pData->minimum; + setValue(value, true); + pData->valueTmp = pData->value; + return true; + } + float vper; const double x = ev.pos.getX(); const double y = ev.pos.getY(); diff --git a/dpf/dgl/src/OpenGL.cpp b/dpf/dgl/src/OpenGL.cpp index b742637..6bd3063 100644 --- a/dpf/dgl/src/OpenGL.cpp +++ b/dpf/dgl/src/OpenGL.cpp @@ -445,17 +445,17 @@ static void drawOpenGLImage(const OpenGLImage& image, const Point& pos, con OpenGLImage::OpenGLImage() : ImageBase(), - textureId(0), - setupCalled(false) + setupCalled(false), + textureInit(false), + textureId(0) { - glGenTextures(1, &textureId); - DISTRHO_SAFE_ASSERT(textureId != 0); } OpenGLImage::OpenGLImage(const char* const rdata, const uint w, const uint h, const ImageFormat fmt) : ImageBase(rdata, w, h, fmt), - textureId(0), - setupCalled(false) + setupCalled(false), + textureInit(true), + textureId(0) { glGenTextures(1, &textureId); DISTRHO_SAFE_ASSERT(textureId != 0); @@ -463,8 +463,9 @@ OpenGLImage::OpenGLImage(const char* const rdata, const uint w, const uint h, co OpenGLImage::OpenGLImage(const char* const rdata, const Size& s, const ImageFormat fmt) : ImageBase(rdata, s, fmt), - textureId(0), - setupCalled(false) + setupCalled(false), + textureInit(true), + textureId(0) { glGenTextures(1, &textureId); DISTRHO_SAFE_ASSERT(textureId != 0); @@ -472,8 +473,9 @@ OpenGLImage::OpenGLImage(const char* const rdata, const Size& s, const Ima OpenGLImage::OpenGLImage(const OpenGLImage& image) : ImageBase(image), - textureId(0), - setupCalled(false) + setupCalled(false), + textureInit(true), + textureId(0) { glGenTextures(1, &textureId); DISTRHO_SAFE_ASSERT(textureId != 0); @@ -487,6 +489,12 @@ OpenGLImage::~OpenGLImage() void OpenGLImage::loadFromMemory(const char* const rdata, const Size& s, const ImageFormat fmt) noexcept { + if (!textureInit) + { + textureInit = true; + glGenTextures(1, &textureId); + DISTRHO_SAFE_ASSERT(textureId != 0); + } setupCalled = false; ImageBase::loadFromMemory(rdata, s, fmt); } @@ -502,14 +510,23 @@ OpenGLImage& OpenGLImage::operator=(const OpenGLImage& image) noexcept size = image.size; format = image.format; setupCalled = false; + + if (image.isValid() && !textureInit) + { + textureInit = true; + glGenTextures(1, &textureId); + DISTRHO_SAFE_ASSERT(textureId != 0); + } + return *this; } // deprecated calls OpenGLImage::OpenGLImage(const char* const rdata, const uint w, const uint h, const GLenum fmt) : ImageBase(rdata, w, h, asDISTRHOImageFormat(fmt)), - textureId(0), - setupCalled(false) + setupCalled(false), + textureInit(true), + textureId(0) { glGenTextures(1, &textureId); DISTRHO_SAFE_ASSERT(textureId != 0); @@ -517,8 +534,9 @@ OpenGLImage::OpenGLImage(const char* const rdata, const uint w, const uint h, co OpenGLImage::OpenGLImage(const char* const rdata, const Size& s, const GLenum fmt) : ImageBase(rdata, s, asDISTRHOImageFormat(fmt)), - textureId(0), - setupCalled(false) + setupCalled(false), + textureInit(true), + textureId(0) { glGenTextures(1, &textureId); DISTRHO_SAFE_ASSERT(textureId != 0); diff --git a/dpf/dgl/src/Window.cpp b/dpf/dgl/src/Window.cpp index 37c61d1..20d9b24 100644 --- a/dpf/dgl/src/Window.cpp +++ b/dpf/dgl/src/Window.cpp @@ -27,12 +27,14 @@ START_NAMESPACE_DGL Window::ScopedGraphicsContext::ScopedGraphicsContext(Window& win) : window(win), ppData(nullptr), - active(puglBackendEnter(window.pData->view)) {} + active(puglBackendEnter(window.pData->view)), + reenter(false) {} Window::ScopedGraphicsContext::ScopedGraphicsContext(Window& win, Window& transientWin) : window(win), ppData(transientWin.pData), - active(false) + active(false), + reenter(true) { puglBackendLeave(ppData->view); active = puglBackendEnter(window.pData->view); @@ -51,13 +53,26 @@ void Window::ScopedGraphicsContext::done() active = false; } - if (ppData != nullptr) + if (reenter) { + reenter = false; + DISTRHO_SAFE_ASSERT_RETURN(ppData != nullptr,); + puglBackendEnter(ppData->view); - ppData = nullptr; } } +void Window::ScopedGraphicsContext::reinit() +{ + DISTRHO_SAFE_ASSERT_RETURN(!active,); + DISTRHO_SAFE_ASSERT_RETURN(!reenter,); + DISTRHO_SAFE_ASSERT_RETURN(ppData != nullptr,); + + reenter = true; + puglBackendLeave(ppData->view); + active = puglBackendEnter(window.pData->view); +} + // ----------------------------------------------------------------------- // Window diff --git a/dpf/dgl/src/pugl.cpp b/dpf/dgl/src/pugl.cpp index 5ed3b5b..001d757 100644 --- a/dpf/dgl/src/pugl.cpp +++ b/dpf/dgl/src/pugl.cpp @@ -540,9 +540,9 @@ void puglWin32ShowCentered(PuglView* const view) GetWindowRect(impl->hwnd, &rectChild) && GetWindowRect((HWND)view->transientParent, &rectParent)) { - SetWindowPos(impl->hwnd, (HWND)view->transientParent, - rectParent.left + (rectChild.right-rectChild.left)/2, - rectParent.top + (rectChild.bottom-rectChild.top)/2, + SetWindowPos(impl->hwnd, HWND_TOP, + rectParent.left + (rectParent.right-rectParent.left)/2 - (rectChild.right-rectChild.left)/2, + rectParent.top + (rectParent.bottom-rectParent.top)/2 - (rectChild.bottom-rectChild.top)/2, 0, 0, SWP_SHOWWINDOW|SWP_NOSIZE); } else @@ -564,8 +564,7 @@ void puglWin32ShowCentered(PuglView* const view) mInfo.cbSize = sizeof(mInfo); if (GetMonitorInfo(MonitorFromWindow(impl->hwnd, MONITOR_DEFAULTTOPRIMARY), &mInfo)) - SetWindowPos(impl->hwnd, - HWND_TOP, + SetWindowPos(impl->hwnd, HWND_TOP, mInfo.rcWork.left + (mInfo.rcWork.right - mInfo.rcWork.left - view->frame.width) / 2, mInfo.rcWork.top + (mInfo.rcWork.bottom - mInfo.rcWork.top - view->frame.height) / 2, 0, 0, SWP_SHOWWINDOW|SWP_NOSIZE); diff --git a/plugins/Nekobi/DistrhoPluginInfo.h b/plugins/Nekobi/DistrhoPluginInfo.h index 41ed912..3b11bb9 100644 --- a/plugins/Nekobi/DistrhoPluginInfo.h +++ b/plugins/Nekobi/DistrhoPluginInfo.h @@ -18,6 +18,8 @@ #ifndef DISTRHO_PLUGIN_INFO_H_INCLUDED #define DISTRHO_PLUGIN_INFO_H_INCLUDED +#include "DistrhoArtworkNekobi.hpp" + #define DISTRHO_PLUGIN_BRAND "DISTRHO" #define DISTRHO_PLUGIN_NAME "Nekobi" #define DISTRHO_PLUGIN_URI "http://distrho.sf.net/plugins/Nekobi" @@ -29,4 +31,7 @@ #define DISTRHO_PLUGIN_NUM_INPUTS 0 #define DISTRHO_PLUGIN_NUM_OUTPUTS 1 +#define DISTRHO_UI_DEFAULT_WIDTH DistrhoArtworkNekobi::backgroundWidth +#define DISTRHO_UI_DEFAULT_HEIGHT DistrhoArtworkNekobi::backgroundHeight + #endif // DISTRHO_PLUGIN_INFO_H_INCLUDED diff --git a/plugins/Nekobi/DistrhoUINekobi.cpp b/plugins/Nekobi/DistrhoUINekobi.cpp index 4c53224..d308217 100644 --- a/plugins/Nekobi/DistrhoUINekobi.cpp +++ b/plugins/Nekobi/DistrhoUINekobi.cpp @@ -1,6 +1,6 @@ /* * DISTRHO Nekobi Plugin, based on Nekobee by Sean Bolton and others. - * Copyright (C) 2013-2021 Filipe Coelho + * Copyright (C) 2013-2022 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -40,6 +40,7 @@ DistrhoUINekobi::DistrhoUINekobi() fSliderWaveform->setId(DistrhoPluginNekobi::paramWaveform); fSliderWaveform->setStartPos(133, 40); fSliderWaveform->setEndPos(133, 60); + fSliderWaveform->setCheckable(true); fSliderWaveform->setRange(0.0f, 1.0f); fSliderWaveform->setStep(1.0f); fSliderWaveform->setValue(0.0f); diff --git a/plugins/Nekobi/DistrhoUINekobi.hpp b/plugins/Nekobi/DistrhoUINekobi.hpp index 8106308..c2fabeb 100644 --- a/plugins/Nekobi/DistrhoUINekobi.hpp +++ b/plugins/Nekobi/DistrhoUINekobi.hpp @@ -1,6 +1,6 @@ /* * DISTRHO Nekobi Plugin, based on Nekobee by Sean Bolton and others. - * Copyright (C) 2013-2021 Filipe Coelho + * Copyright (C) 2013-2022 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -22,7 +22,6 @@ #include "ImageWidgets.hpp" -#include "DistrhoArtworkNekobi.hpp" #include "NekoWidget.hpp" using DGL_NAMESPACE::ImageAboutWindow;