summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfalkTX <falktx@gmail.com>2018-09-30 12:30:34 +0200
committerfalkTX <falktx@gmail.com>2018-09-30 12:30:34 +0200
commit638585dc744b575eeaca794dc02e1780fa35a6b1 (patch)
treedfd1c888b14394cf1555f9ee74b46dfba67575aa
parentaa6ada4eceda538197edea224922e19303cdd112 (diff)
Add option to automatically scale plugin UIs
-rw-r--r--distrho/DistrhoUI.hpp6
-rw-r--r--distrho/src/DistrhoUI.cpp11
-rw-r--r--distrho/src/DistrhoUIInternal.hpp16
3 files changed, 27 insertions, 6 deletions
diff --git a/distrho/DistrhoUI.hpp b/distrho/DistrhoUI.hpp
index c129e2ba..6975a699 100644
--- a/distrho/DistrhoUI.hpp
+++ b/distrho/DistrhoUI.hpp
@@ -62,11 +62,11 @@ public:
virtual ~UI();
/**
- Set geometry constraints for the UI when resized by the user.
- This is a convenience function that calls getParentWindow().setGeometryConstraints()
+ Set geometry constraints for the UI when resized by the user, and optionally scale UI automatically.
@see Window::setGeometryConstraints(uint,uint,bool)
+ @see Window::setScaling(double)
*/
- void setGeometryConstraints(uint minWidth, uint minHeight, bool keepAspectRatio);
+ void setGeometryConstraints(uint minWidth, uint minHeight, bool keepAspectRatio, bool automaticallyScale = false);
/* --------------------------------------------------------------------------------------------------------
* Host state */
diff --git a/distrho/src/DistrhoUI.cpp b/distrho/src/DistrhoUI.cpp
index 9befcc6d..e48e365c 100644
--- a/distrho/src/DistrhoUI.cpp
+++ b/distrho/src/DistrhoUI.cpp
@@ -57,9 +57,16 @@ UI::~UI()
delete pData;
}
-void UI::setGeometryConstraints(uint minWidth, uint minHeight, bool keepAspectRatio)
+void UI::setGeometryConstraints(uint minWidth, uint minHeight, bool keepAspectRatio, bool automaticallyScale)
{
- return getParentWindow().setGeometryConstraints(minWidth, minHeight, keepAspectRatio);
+ DISTRHO_SAFE_ASSERT_RETURN(minWidth > 0,);
+ DISTRHO_SAFE_ASSERT_RETURN(minHeight > 0,);
+
+ pData->automaticallyScale = automaticallyScale;
+ pData->minWidth = minWidth;
+ pData->minHeight = minHeight;
+
+ getParentWindow().setGeometryConstraints(minWidth, minHeight, keepAspectRatio);
}
/* ------------------------------------------------------------------------------------------------------------
diff --git a/distrho/src/DistrhoUIInternal.hpp b/distrho/src/DistrhoUIInternal.hpp
index e05385cd..00599122 100644
--- a/distrho/src/DistrhoUIInternal.hpp
+++ b/distrho/src/DistrhoUIInternal.hpp
@@ -62,6 +62,9 @@ struct UI::PrivateData {
// UI
const bool userResizable;
+ bool automaticallyScale;
+ uint minWidth;
+ uint minHeight;
// Callbacks
void* callbacksPtr;
@@ -71,13 +74,16 @@ struct UI::PrivateData {
sendNoteFunc sendNoteCallbackFunc;
setSizeFunc setSizeCallbackFunc;
- PrivateData(bool resizable) noexcept
+ PrivateData(const bool resizable) noexcept
: sampleRate(d_lastUiSampleRate),
parameterOffset(0),
#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
dspPtr(d_lastUiDspPtr),
#endif
userResizable(resizable),
+ automaticallyScale(false),
+ minWidth(0),
+ minHeight(0),
callbacksPtr(nullptr),
editParamCallbackFunc(nullptr),
setParamCallbackFunc(nullptr),
@@ -185,6 +191,14 @@ protected:
void onReshape(uint width, uint height) override
{
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,);
+ DISTRHO_SAFE_ASSERT_RETURN(fUI->pData != nullptr,);
+
+ if (fUI->pData->automaticallyScale)
+ {
+ const double scaleHorizontal = static_cast<double>(width) / static_cast<double>(fUI->pData->minWidth);
+ const double scaleVertical = static_cast<double>(height) / static_cast<double>(fUI->pData->minHeight);
+ setScaling(scaleHorizontal < scaleVertical ? scaleHorizontal : scaleVertical);
+ }
fUI->setSize(width, height);
fUI->uiReshape(width, height);