Browse Source

Add option to automatically scale plugin UIs

pull/83/head
falkTX 6 years ago
parent
commit
638585dc74
3 changed files with 27 additions and 6 deletions
  1. +3
    -3
      distrho/DistrhoUI.hpp
  2. +9
    -2
      distrho/src/DistrhoUI.cpp
  3. +15
    -1
      distrho/src/DistrhoUIInternal.hpp

+ 3
- 3
distrho/DistrhoUI.hpp View File

@@ -62,11 +62,11 @@ public:
virtual ~UI(); 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::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 */ * Host state */


+ 9
- 2
distrho/src/DistrhoUI.cpp View File

@@ -57,9 +57,16 @@ UI::~UI()
delete pData; 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);
} }


/* ------------------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------------------


+ 15
- 1
distrho/src/DistrhoUIInternal.hpp View File

@@ -62,6 +62,9 @@ struct UI::PrivateData {


// UI // UI
const bool userResizable; const bool userResizable;
bool automaticallyScale;
uint minWidth;
uint minHeight;


// Callbacks // Callbacks
void* callbacksPtr; void* callbacksPtr;
@@ -71,13 +74,16 @@ struct UI::PrivateData {
sendNoteFunc sendNoteCallbackFunc; sendNoteFunc sendNoteCallbackFunc;
setSizeFunc setSizeCallbackFunc; setSizeFunc setSizeCallbackFunc;


PrivateData(bool resizable) noexcept
PrivateData(const bool resizable) noexcept
: sampleRate(d_lastUiSampleRate), : sampleRate(d_lastUiSampleRate),
parameterOffset(0), parameterOffset(0),
#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
dspPtr(d_lastUiDspPtr), dspPtr(d_lastUiDspPtr),
#endif #endif
userResizable(resizable), userResizable(resizable),
automaticallyScale(false),
minWidth(0),
minHeight(0),
callbacksPtr(nullptr), callbacksPtr(nullptr),
editParamCallbackFunc(nullptr), editParamCallbackFunc(nullptr),
setParamCallbackFunc(nullptr), setParamCallbackFunc(nullptr),
@@ -185,6 +191,14 @@ protected:
void onReshape(uint width, uint height) override void onReshape(uint width, uint height) override
{ {
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); 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->setSize(width, height);
fUI->uiReshape(width, height); fUI->uiReshape(width, height);


Loading…
Cancel
Save