Skip to content

Commit

Permalink
A few more fixes
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Oct 31, 2022
1 parent 0cba155 commit cbb6c04
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 32 deletions.
1 change: 1 addition & 0 deletions dpf/dgl/ImageBaseWidgets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class ImageBaseSlider : public SubWidget
void setEndPos(const Point<int>& 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;
Expand Down
3 changes: 2 additions & 1 deletion dpf/dgl/OpenGL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ class OpenGLImage : public ImageBase
GLenum getType() const noexcept { return GL_UNSIGNED_BYTE; }

private:
GLuint textureId;
bool setupCalled;
bool textureInit;
GLuint textureId;
};

// -----------------------------------------------------------------------
Expand Down
11 changes: 10 additions & 1 deletion dpf/dgl/StandaloneWindow.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2022 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
Expand Down Expand Up @@ -53,6 +53,15 @@ class StandaloneWindow : public Window,
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.
*/
Expand Down
6 changes: 5 additions & 1 deletion dpf/dgl/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,17 @@ class DISTRHO_API Window
/** 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;
};

/**
Expand Down
33 changes: 30 additions & 3 deletions dpf/dgl/src/ImageBaseWidgets.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2022 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
Expand Down Expand Up @@ -61,13 +61,20 @@ void ImageBaseAboutWindow<ImageType>::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 <class ImageType>
Expand Down Expand Up @@ -428,6 +435,7 @@ struct ImageBaseSlider<ImageType>::PrivateData {
bool usingDefault;

bool dragging;
bool checkable;
bool inverted;
bool valueIsSet;
double startedX;
Expand All @@ -449,6 +457,7 @@ struct ImageBaseSlider<ImageType>::PrivateData {
valueTmp(value),
usingDefault(false),
dragging(false),
checkable(false),
inverted(false),
valueIsSet(false),
startedX(0.0),
Expand Down Expand Up @@ -553,6 +562,16 @@ void ImageBaseSlider<ImageType>::setEndPos(int x, int y) noexcept
setEndPos(Point<int>(x, y));
}

template <class ImageType>
void ImageBaseSlider<ImageType>::setCheckable(bool checkable) noexcept
{
if (pData->checkable == checkable)
return;

pData->checkable = checkable;
repaint();
}

template <class ImageType>
void ImageBaseSlider<ImageType>::setInverted(bool inverted) noexcept
{
Expand Down Expand Up @@ -674,6 +693,14 @@ bool ImageBaseSlider<ImageType>::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();
Expand Down
46 changes: 32 additions & 14 deletions dpf/dgl/src/OpenGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,35 +445,37 @@ static void drawOpenGLImage(const OpenGLImage& image, const Point<int>& 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);
}

OpenGLImage::OpenGLImage(const char* const rdata, const Size<uint>& 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);
}

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);
Expand All @@ -487,6 +489,12 @@ OpenGLImage::~OpenGLImage()

void OpenGLImage::loadFromMemory(const char* const rdata, const Size<uint>& s, const ImageFormat fmt) noexcept
{
if (!textureInit)
{
textureInit = true;
glGenTextures(1, &textureId);
DISTRHO_SAFE_ASSERT(textureId != 0);
}
setupCalled = false;
ImageBase::loadFromMemory(rdata, s, fmt);
}
Expand All @@ -502,23 +510,33 @@ 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);
}

OpenGLImage::OpenGLImage(const char* const rdata, const Size<uint>& 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);
Expand Down
23 changes: 19 additions & 4 deletions dpf/dgl/src/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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

Expand Down
9 changes: 4 additions & 5 deletions dpf/dgl/src/pugl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions plugins/Nekobi/DistrhoPluginInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
3 changes: 2 additions & 1 deletion plugins/Nekobi/DistrhoUINekobi.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DISTRHO Nekobi Plugin, based on Nekobee by Sean Bolton and others.
* Copyright (C) 2013-2021 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2013-2022 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions plugins/Nekobi/DistrhoUINekobi.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DISTRHO Nekobi Plugin, based on Nekobee by Sean Bolton and others.
* Copyright (C) 2013-2021 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2013-2022 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
Expand All @@ -22,7 +22,6 @@

#include "ImageWidgets.hpp"

#include "DistrhoArtworkNekobi.hpp"
#include "NekoWidget.hpp"

using DGL_NAMESPACE::ImageAboutWindow;
Expand Down

0 comments on commit cbb6c04

Please sign in to comment.