Skip to content

Commit cbb6c04

Browse files
committed
A few more fixes
Signed-off-by: falkTX <falktx@falktx.com>
1 parent 0cba155 commit cbb6c04

11 files changed

Lines changed: 111 additions & 32 deletions

dpf/dgl/ImageBaseWidgets.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ class ImageBaseSlider : public SubWidget
192192
void setEndPos(const Point<int>& endPos) noexcept;
193193
void setEndPos(int x, int y) noexcept;
194194

195+
void setCheckable(bool checkable) noexcept;
195196
void setInverted(bool inverted) noexcept;
196197
void setRange(float min, float max) noexcept;
197198
void setStep(float step) noexcept;

dpf/dgl/OpenGL.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,9 @@ class OpenGLImage : public ImageBase
202202
GLenum getType() const noexcept { return GL_UNSIGNED_BYTE; }
203203

204204
private:
205-
GLuint textureId;
206205
bool setupCalled;
206+
bool textureInit;
207+
GLuint textureId;
207208
};
208209

209210
// -----------------------------------------------------------------------

dpf/dgl/StandaloneWindow.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* DISTRHO Plugin Framework (DPF)
3-
* Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
3+
* Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com>
44
*
55
* Permission to use, copy, modify, and/or distribute this software for any purpose with
66
* or without fee is hereby granted, provided that the above copyright notice and this
@@ -53,6 +53,15 @@ class StandaloneWindow : public Window,
5353
sgc.done();
5454
}
5555

56+
/**
57+
Get a graphics context back again.
58+
Called when a valid graphics context is needed outside the constructor.
59+
*/
60+
void reinit()
61+
{
62+
sgc.reinit();
63+
}
64+
5665
/**
5766
Overloaded functions to ensure they apply to the Window class.
5867
*/

dpf/dgl/Window.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,17 @@ class DISTRHO_API Window
105105
/** Early context clearing, useful for standalone windows not created by you. */
106106
void done();
107107

108+
/** Get a valid context back again. */
109+
void reinit();
110+
108111
DISTRHO_DECLARE_NON_COPYABLE(ScopedGraphicsContext)
109112
DISTRHO_PREVENT_HEAP_ALLOCATION
110113

111114
private:
112115
Window& window;
113-
Window::PrivateData* ppData;
116+
Window::PrivateData* const ppData;
114117
bool active;
118+
bool reenter;
115119
};
116120

117121
/**

dpf/dgl/src/ImageBaseWidgets.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* DISTRHO Plugin Framework (DPF)
3-
* Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
3+
* Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com>
44
*
55
* Permission to use, copy, modify, and/or distribute this software for any purpose with
66
* or without fee is hereby granted, provided that the above copyright notice and this
@@ -61,13 +61,20 @@ void ImageBaseAboutWindow<ImageType>::setImage(const ImageType& image)
6161
if (img == image)
6262
return;
6363

64-
img = image;
65-
6664
if (image.isInvalid())
65+
{
66+
img = image;
6767
return;
68+
}
69+
70+
reinit();
71+
72+
img = image;
6873

6974
setSize(image.getSize());
7075
setGeometryConstraints(image.getWidth(), image.getHeight(), true, true);
76+
77+
done();
7178
}
7279

7380
template <class ImageType>
@@ -428,6 +435,7 @@ struct ImageBaseSlider<ImageType>::PrivateData {
428435
bool usingDefault;
429436

430437
bool dragging;
438+
bool checkable;
431439
bool inverted;
432440
bool valueIsSet;
433441
double startedX;
@@ -449,6 +457,7 @@ struct ImageBaseSlider<ImageType>::PrivateData {
449457
valueTmp(value),
450458
usingDefault(false),
451459
dragging(false),
460+
checkable(false),
452461
inverted(false),
453462
valueIsSet(false),
454463
startedX(0.0),
@@ -553,6 +562,16 @@ void ImageBaseSlider<ImageType>::setEndPos(int x, int y) noexcept
553562
setEndPos(Point<int>(x, y));
554563
}
555564

565+
template <class ImageType>
566+
void ImageBaseSlider<ImageType>::setCheckable(bool checkable) noexcept
567+
{
568+
if (pData->checkable == checkable)
569+
return;
570+
571+
pData->checkable = checkable;
572+
repaint();
573+
}
574+
556575
template <class ImageType>
557576
void ImageBaseSlider<ImageType>::setInverted(bool inverted) noexcept
558577
{
@@ -674,6 +693,14 @@ bool ImageBaseSlider<ImageType>::onMouse(const MouseEvent& ev)
674693
return true;
675694
}
676695

696+
if (pData->checkable)
697+
{
698+
const float value = d_isEqual(pData->valueTmp, pData->minimum) ? pData->maximum : pData->minimum;
699+
setValue(value, true);
700+
pData->valueTmp = pData->value;
701+
return true;
702+
}
703+
677704
float vper;
678705
const double x = ev.pos.getX();
679706
const double y = ev.pos.getY();

dpf/dgl/src/OpenGL.cpp

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -445,35 +445,37 @@ static void drawOpenGLImage(const OpenGLImage& image, const Point<int>& pos, con
445445

446446
OpenGLImage::OpenGLImage()
447447
: ImageBase(),
448-
textureId(0),
449-
setupCalled(false)
448+
setupCalled(false),
449+
textureInit(false),
450+
textureId(0)
450451
{
451-
glGenTextures(1, &textureId);
452-
DISTRHO_SAFE_ASSERT(textureId != 0);
453452
}
454453

455454
OpenGLImage::OpenGLImage(const char* const rdata, const uint w, const uint h, const ImageFormat fmt)
456455
: ImageBase(rdata, w, h, fmt),
457-
textureId(0),
458-
setupCalled(false)
456+
setupCalled(false),
457+
textureInit(true),
458+
textureId(0)
459459
{
460460
glGenTextures(1, &textureId);
461461
DISTRHO_SAFE_ASSERT(textureId != 0);
462462
}
463463

464464
OpenGLImage::OpenGLImage(const char* const rdata, const Size<uint>& s, const ImageFormat fmt)
465465
: ImageBase(rdata, s, fmt),
466-
textureId(0),
467-
setupCalled(false)
466+
setupCalled(false),
467+
textureInit(true),
468+
textureId(0)
468469
{
469470
glGenTextures(1, &textureId);
470471
DISTRHO_SAFE_ASSERT(textureId != 0);
471472
}
472473

473474
OpenGLImage::OpenGLImage(const OpenGLImage& image)
474475
: ImageBase(image),
475-
textureId(0),
476-
setupCalled(false)
476+
setupCalled(false),
477+
textureInit(true),
478+
textureId(0)
477479
{
478480
glGenTextures(1, &textureId);
479481
DISTRHO_SAFE_ASSERT(textureId != 0);
@@ -487,6 +489,12 @@ OpenGLImage::~OpenGLImage()
487489

488490
void OpenGLImage::loadFromMemory(const char* const rdata, const Size<uint>& s, const ImageFormat fmt) noexcept
489491
{
492+
if (!textureInit)
493+
{
494+
textureInit = true;
495+
glGenTextures(1, &textureId);
496+
DISTRHO_SAFE_ASSERT(textureId != 0);
497+
}
490498
setupCalled = false;
491499
ImageBase::loadFromMemory(rdata, s, fmt);
492500
}
@@ -502,23 +510,33 @@ OpenGLImage& OpenGLImage::operator=(const OpenGLImage& image) noexcept
502510
size = image.size;
503511
format = image.format;
504512
setupCalled = false;
513+
514+
if (image.isValid() && !textureInit)
515+
{
516+
textureInit = true;
517+
glGenTextures(1, &textureId);
518+
DISTRHO_SAFE_ASSERT(textureId != 0);
519+
}
520+
505521
return *this;
506522
}
507523

508524
// deprecated calls
509525
OpenGLImage::OpenGLImage(const char* const rdata, const uint w, const uint h, const GLenum fmt)
510526
: ImageBase(rdata, w, h, asDISTRHOImageFormat(fmt)),
511-
textureId(0),
512-
setupCalled(false)
527+
setupCalled(false),
528+
textureInit(true),
529+
textureId(0)
513530
{
514531
glGenTextures(1, &textureId);
515532
DISTRHO_SAFE_ASSERT(textureId != 0);
516533
}
517534

518535
OpenGLImage::OpenGLImage(const char* const rdata, const Size<uint>& s, const GLenum fmt)
519536
: ImageBase(rdata, s, asDISTRHOImageFormat(fmt)),
520-
textureId(0),
521-
setupCalled(false)
537+
setupCalled(false),
538+
textureInit(true),
539+
textureId(0)
522540
{
523541
glGenTextures(1, &textureId);
524542
DISTRHO_SAFE_ASSERT(textureId != 0);

dpf/dgl/src/Window.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ START_NAMESPACE_DGL
2727
Window::ScopedGraphicsContext::ScopedGraphicsContext(Window& win)
2828
: window(win),
2929
ppData(nullptr),
30-
active(puglBackendEnter(window.pData->view)) {}
30+
active(puglBackendEnter(window.pData->view)),
31+
reenter(false) {}
3132

3233
Window::ScopedGraphicsContext::ScopedGraphicsContext(Window& win, Window& transientWin)
3334
: window(win),
3435
ppData(transientWin.pData),
35-
active(false)
36+
active(false),
37+
reenter(true)
3638
{
3739
puglBackendLeave(ppData->view);
3840
active = puglBackendEnter(window.pData->view);
@@ -51,13 +53,26 @@ void Window::ScopedGraphicsContext::done()
5153
active = false;
5254
}
5355

54-
if (ppData != nullptr)
56+
if (reenter)
5557
{
58+
reenter = false;
59+
DISTRHO_SAFE_ASSERT_RETURN(ppData != nullptr,);
60+
5661
puglBackendEnter(ppData->view);
57-
ppData = nullptr;
5862
}
5963
}
6064

65+
void Window::ScopedGraphicsContext::reinit()
66+
{
67+
DISTRHO_SAFE_ASSERT_RETURN(!active,);
68+
DISTRHO_SAFE_ASSERT_RETURN(!reenter,);
69+
DISTRHO_SAFE_ASSERT_RETURN(ppData != nullptr,);
70+
71+
reenter = true;
72+
puglBackendLeave(ppData->view);
73+
active = puglBackendEnter(window.pData->view);
74+
}
75+
6176
// -----------------------------------------------------------------------
6277
// Window
6378

dpf/dgl/src/pugl.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,9 @@ void puglWin32ShowCentered(PuglView* const view)
540540
GetWindowRect(impl->hwnd, &rectChild) &&
541541
GetWindowRect((HWND)view->transientParent, &rectParent))
542542
{
543-
SetWindowPos(impl->hwnd, (HWND)view->transientParent,
544-
rectParent.left + (rectChild.right-rectChild.left)/2,
545-
rectParent.top + (rectChild.bottom-rectChild.top)/2,
543+
SetWindowPos(impl->hwnd, HWND_TOP,
544+
rectParent.left + (rectParent.right-rectParent.left)/2 - (rectChild.right-rectChild.left)/2,
545+
rectParent.top + (rectParent.bottom-rectParent.top)/2 - (rectChild.bottom-rectChild.top)/2,
546546
0, 0, SWP_SHOWWINDOW|SWP_NOSIZE);
547547
}
548548
else
@@ -564,8 +564,7 @@ void puglWin32ShowCentered(PuglView* const view)
564564
mInfo.cbSize = sizeof(mInfo);
565565

566566
if (GetMonitorInfo(MonitorFromWindow(impl->hwnd, MONITOR_DEFAULTTOPRIMARY), &mInfo))
567-
SetWindowPos(impl->hwnd,
568-
HWND_TOP,
567+
SetWindowPos(impl->hwnd, HWND_TOP,
569568
mInfo.rcWork.left + (mInfo.rcWork.right - mInfo.rcWork.left - view->frame.width) / 2,
570569
mInfo.rcWork.top + (mInfo.rcWork.bottom - mInfo.rcWork.top - view->frame.height) / 2,
571570
0, 0, SWP_SHOWWINDOW|SWP_NOSIZE);

plugins/Nekobi/DistrhoPluginInfo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#ifndef DISTRHO_PLUGIN_INFO_H_INCLUDED
1919
#define DISTRHO_PLUGIN_INFO_H_INCLUDED
2020

21+
#include "DistrhoArtworkNekobi.hpp"
22+
2123
#define DISTRHO_PLUGIN_BRAND "DISTRHO"
2224
#define DISTRHO_PLUGIN_NAME "Nekobi"
2325
#define DISTRHO_PLUGIN_URI "http://distrho.sf.net/plugins/Nekobi"
@@ -29,4 +31,7 @@
2931
#define DISTRHO_PLUGIN_NUM_INPUTS 0
3032
#define DISTRHO_PLUGIN_NUM_OUTPUTS 1
3133

34+
#define DISTRHO_UI_DEFAULT_WIDTH DistrhoArtworkNekobi::backgroundWidth
35+
#define DISTRHO_UI_DEFAULT_HEIGHT DistrhoArtworkNekobi::backgroundHeight
36+
3237
#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED

plugins/Nekobi/DistrhoUINekobi.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* DISTRHO Nekobi Plugin, based on Nekobee by Sean Bolton and others.
3-
* Copyright (C) 2013-2021 Filipe Coelho <falktx@falktx.com>
3+
* Copyright (C) 2013-2022 Filipe Coelho <falktx@falktx.com>
44
*
55
* This program is free software; you can redistribute it and/or
66
* modify it under the terms of the GNU General Public License as
@@ -40,6 +40,7 @@ DistrhoUINekobi::DistrhoUINekobi()
4040
fSliderWaveform->setId(DistrhoPluginNekobi::paramWaveform);
4141
fSliderWaveform->setStartPos(133, 40);
4242
fSliderWaveform->setEndPos(133, 60);
43+
fSliderWaveform->setCheckable(true);
4344
fSliderWaveform->setRange(0.0f, 1.0f);
4445
fSliderWaveform->setStep(1.0f);
4546
fSliderWaveform->setValue(0.0f);

0 commit comments

Comments
 (0)