summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfalkTX <falktx@gmail.com>2018-09-30 09:46:38 +0200
committerfalkTX <falktx@gmail.com>2018-09-30 09:46:38 +0200
commit7cf42d65ebab1544583120c4da9981ac1b8b5a43 (patch)
treebac8e369e84c21ad0b6529a2476f8b1c064090a9
parenta7f781a4c5ae6585a89982eea7bc2f5e30298ef3 (diff)
Allow plugin UIs to be user-resizable, test with info example
-rw-r--r--dgl/Window.hpp2
-rw-r--r--dgl/src/Window.cpp14
-rw-r--r--distrho/DistrhoUI.hpp9
-rw-r--r--distrho/src/DistrhoUI.cpp13
-rw-r--r--distrho/src/DistrhoUIInternal.hpp11
-rw-r--r--examples/Info/InfoExampleUI.cpp34
6 files changed, 65 insertions, 18 deletions
diff --git a/dgl/Window.hpp b/dgl/Window.hpp
index 182ae972..b202f041 100644
--- a/dgl/Window.hpp
+++ b/dgl/Window.hpp
@@ -98,6 +98,8 @@ public:
bool isResizable() const noexcept;
void setResizable(bool yesNo);
+ void setGeometryConstraints(uint width, uint height, bool aspect);
+
uint getWidth() const noexcept;
uint getHeight() const noexcept;
Size<uint> getSize() const noexcept;
diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp
index 6a221690..8396a954 100644
--- a/dgl/src/Window.cpp
+++ b/dgl/src/Window.cpp
@@ -549,6 +549,15 @@ struct Window::PrivateData {
// -------------------------------------------------------------------
+ void setGeometryConstraints(uint width, uint height, bool aspect)
+ {
+ DISTRHO_SAFE_ASSERT_RETURN(fResizable,);
+
+ puglUpdateGeometryConstraints(fView, width, height, aspect);
+ }
+
+ // -------------------------------------------------------------------
+
void setSize(uint width, uint height, const bool forced = false)
{
if (width <= 1 || height <= 1)
@@ -1236,6 +1245,11 @@ void Window::setResizable(bool yesNo)
pData->setResizable(yesNo);
}
+void Window::setGeometryConstraints(uint width, uint height, bool aspect)
+{
+ pData->setGeometryConstraints(width, height, aspect);
+}
+
uint Window::getWidth() const noexcept
{
return pData->fWidth;
diff --git a/distrho/DistrhoUI.hpp b/distrho/DistrhoUI.hpp
index a4ec9e61..c129e2ba 100644
--- a/distrho/DistrhoUI.hpp
+++ b/distrho/DistrhoUI.hpp
@@ -54,13 +54,20 @@ public:
UI class constructor.
The UI should be initialized to a default state that matches the plugin side.
*/
- UI(uint width = 0, uint height = 0);
+ UI(uint width = 0, uint height = 0, bool userResizable = false);
/**
Destructor.
*/
virtual ~UI();
+ /**
+ Set geometry constraints for the UI when resized by the user.
+ This is a convenience function that calls getParentWindow().setGeometryConstraints()
+ @see Window::setGeometryConstraints(uint,uint,bool)
+ */
+ void setGeometryConstraints(uint minWidth, uint minHeight, bool keepAspectRatio);
+
/* --------------------------------------------------------------------------------------------------------
* Host state */
diff --git a/distrho/src/DistrhoUI.cpp b/distrho/src/DistrhoUI.cpp
index f180ee2e..9befcc6d 100644
--- a/distrho/src/DistrhoUI.cpp
+++ b/distrho/src/DistrhoUI.cpp
@@ -37,9 +37,9 @@ const char* g_nextBundlePath = nullptr;
* UI */
#ifdef HAVE_DGL
-UI::UI(uint width, uint height)
+UI::UI(uint width, uint height, bool userResizable)
: UIWidget(*d_lastUiWindow),
- pData(new PrivateData())
+ pData(new PrivateData(userResizable))
{
((UIWidget*)this)->pData->needsFullViewport = false;
@@ -47,9 +47,9 @@ UI::UI(uint width, uint height)
setSize(width, height);
}
#else
-UI::UI(uint width, uint height)
+UI::UI(uint width, uint height, bool userResizable)
: UIWidget(width, height),
- pData(new PrivateData()) {}
+ pData(new PrivateData(userResizable)) {}
#endif
UI::~UI()
@@ -57,6 +57,11 @@ UI::~UI()
delete pData;
}
+void UI::setGeometryConstraints(uint minWidth, uint minHeight, bool keepAspectRatio)
+{
+ return getParentWindow().setGeometryConstraints(minWidth, minHeight, keepAspectRatio);
+}
+
/* ------------------------------------------------------------------------------------------------------------
* Host state */
diff --git a/distrho/src/DistrhoUIInternal.hpp b/distrho/src/DistrhoUIInternal.hpp
index 8a045a93..129e3393 100644
--- a/distrho/src/DistrhoUIInternal.hpp
+++ b/distrho/src/DistrhoUIInternal.hpp
@@ -60,6 +60,9 @@ struct UI::PrivateData {
void* dspPtr;
#endif
+ // UI
+ const bool userResizable;
+
// Callbacks
void* callbacksPtr;
editParamFunc editParamCallbackFunc;
@@ -68,12 +71,13 @@ struct UI::PrivateData {
sendNoteFunc sendNoteCallbackFunc;
setSizeFunc setSizeCallbackFunc;
- PrivateData() noexcept
+ PrivateData(bool resizable) noexcept
: sampleRate(d_lastUiSampleRate),
parameterOffset(0),
#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
dspPtr(d_lastUiDspPtr),
#endif
+ userResizable(resizable),
callbacksPtr(nullptr),
editParamCallbackFunc(nullptr),
setParamCallbackFunc(nullptr),
@@ -155,9 +159,9 @@ public:
fIsReady(false)
{
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,);
+ DISTRHO_SAFE_ASSERT_RETURN(fUI->pData != nullptr,);
- // set window size
- setResizable(false);
+ setResizable(fUI->pData->userResizable);
setSize(fUI->getWidth(), fUI->getHeight());
}
@@ -182,6 +186,7 @@ protected:
{
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,);
+ fUI->setSize(width, height);
fUI->uiReshape(width, height);
fIsReady = true;
}
diff --git a/examples/Info/InfoExampleUI.cpp b/examples/Info/InfoExampleUI.cpp
index 0ba56496..2299f5fa 100644
--- a/examples/Info/InfoExampleUI.cpp
+++ b/examples/Info/InfoExampleUI.cpp
@@ -18,6 +18,8 @@
#include "DistrhoUI.hpp"
+#include "Window.hpp"
+
START_NAMESPACE_DISTRHO
// -----------------------------------------------------------------------------------------------------------
@@ -26,13 +28,16 @@ class InfoExampleUI : public UI
{
public:
InfoExampleUI()
- : UI(405, 256)
+ : UI(405, 256, true),
+ fScale(1.0f)
{
std::memset(fParameters, 0, sizeof(float)*kParameterCount);
std::memset(fStrBuf, 0, sizeof(char)*(0xff+1));
fSampleRate = getSampleRate();
fFont = createFontFromFile("sans", "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf");
+
+ setGeometryConstraints(405, 256, false);
}
protected:
@@ -69,13 +74,13 @@ protected:
*/
void onNanoDisplay() override
{
- static const float lineHeight = 20;
+ const float lineHeight = 20 * fScale;
- fontSize(15.0f);
+ fontSize(15.0f * fScale);
textLineHeight(lineHeight);
- float x = 0;
- float y = 15;
+ float x = 0.0f * fScale;
+ float y = 15.0f * fScale;
// buffer size
drawLeft(x, y, "Buffer Size:");
@@ -104,8 +109,8 @@ protected:
y+=lineHeight;
// BBT
- x = 200;
- y = 15;
+ x = 200.0f * fScale;
+ y = 15.0f * fScale;
const bool validBBT(fParameters[kParameterTimeValidBBT] > 0.5f);
drawLeft(x, y, "BBT Valid:");
@@ -148,6 +153,14 @@ protected:
y+=lineHeight;
}
+
+ void onResize(const ResizeEvent& ev) override
+ {
+ fScale = static_cast<float>(ev.size.getHeight())/256.0f;
+
+ UI::onResize(ev);
+ }
+
// -------------------------------------------------------------------------------------------------------
private:
@@ -155,8 +168,9 @@ private:
float fParameters[kParameterCount];
double fSampleRate;
- // font
+ // UI stuff
FontId fFont;
+ float fScale;
// temp buf for text
char fStrBuf[0xff+1];
@@ -190,7 +204,7 @@ private:
beginPath();
fillColor(200, 200, 200);
textAlign(ALIGN_RIGHT|ALIGN_TOP);
- textBox(x, y, 100, text);
+ textBox(x, y, 100 * fScale, text);
closePath();
}
@@ -199,7 +213,7 @@ private:
beginPath();
fillColor(255, 255, 255);
textAlign(ALIGN_LEFT|ALIGN_TOP);
- textBox(x+105, y, 100, text);
+ textBox(x + (105 * fScale), y, 100 * fScale, text);
closePath();
}