@@ -98,6 +98,8 @@ public: | |||||
bool isResizable() const noexcept; | bool isResizable() const noexcept; | ||||
void setResizable(bool yesNo); | void setResizable(bool yesNo); | ||||
void setGeometryConstraints(uint width, uint height, bool aspect); | |||||
uint getWidth() const noexcept; | uint getWidth() const noexcept; | ||||
uint getHeight() const noexcept; | uint getHeight() const noexcept; | ||||
Size<uint> getSize() const noexcept; | Size<uint> getSize() const noexcept; | ||||
@@ -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) | void setSize(uint width, uint height, const bool forced = false) | ||||
{ | { | ||||
if (width <= 1 || height <= 1) | if (width <= 1 || height <= 1) | ||||
@@ -1236,6 +1245,11 @@ void Window::setResizable(bool yesNo) | |||||
pData->setResizable(yesNo); | pData->setResizable(yesNo); | ||||
} | } | ||||
void Window::setGeometryConstraints(uint width, uint height, bool aspect) | |||||
{ | |||||
pData->setGeometryConstraints(width, height, aspect); | |||||
} | |||||
uint Window::getWidth() const noexcept | uint Window::getWidth() const noexcept | ||||
{ | { | ||||
return pData->fWidth; | return pData->fWidth; | ||||
@@ -54,13 +54,20 @@ public: | |||||
UI class constructor. | UI class constructor. | ||||
The UI should be initialized to a default state that matches the plugin side. | 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. | Destructor. | ||||
*/ | */ | ||||
virtual ~UI(); | 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 */ | * Host state */ | ||||
@@ -37,9 +37,9 @@ const char* g_nextBundlePath = nullptr; | |||||
* UI */ | * UI */ | ||||
#ifdef HAVE_DGL | #ifdef HAVE_DGL | ||||
UI::UI(uint width, uint height) | |||||
UI::UI(uint width, uint height, bool userResizable) | |||||
: UIWidget(*d_lastUiWindow), | : UIWidget(*d_lastUiWindow), | ||||
pData(new PrivateData()) | |||||
pData(new PrivateData(userResizable)) | |||||
{ | { | ||||
((UIWidget*)this)->pData->needsFullViewport = false; | ((UIWidget*)this)->pData->needsFullViewport = false; | ||||
@@ -47,9 +47,9 @@ UI::UI(uint width, uint height) | |||||
setSize(width, height); | setSize(width, height); | ||||
} | } | ||||
#else | #else | ||||
UI::UI(uint width, uint height) | |||||
UI::UI(uint width, uint height, bool userResizable) | |||||
: UIWidget(width, height), | : UIWidget(width, height), | ||||
pData(new PrivateData()) {} | |||||
pData(new PrivateData(userResizable)) {} | |||||
#endif | #endif | ||||
UI::~UI() | UI::~UI() | ||||
@@ -57,6 +57,11 @@ UI::~UI() | |||||
delete pData; | delete pData; | ||||
} | } | ||||
void UI::setGeometryConstraints(uint minWidth, uint minHeight, bool keepAspectRatio) | |||||
{ | |||||
return getParentWindow().setGeometryConstraints(minWidth, minHeight, keepAspectRatio); | |||||
} | |||||
/* ------------------------------------------------------------------------------------------------------------ | /* ------------------------------------------------------------------------------------------------------------ | ||||
* Host state */ | * Host state */ | ||||
@@ -60,6 +60,9 @@ struct UI::PrivateData { | |||||
void* dspPtr; | void* dspPtr; | ||||
#endif | #endif | ||||
// UI | |||||
const bool userResizable; | |||||
// Callbacks | // Callbacks | ||||
void* callbacksPtr; | void* callbacksPtr; | ||||
editParamFunc editParamCallbackFunc; | editParamFunc editParamCallbackFunc; | ||||
@@ -68,12 +71,13 @@ struct UI::PrivateData { | |||||
sendNoteFunc sendNoteCallbackFunc; | sendNoteFunc sendNoteCallbackFunc; | ||||
setSizeFunc setSizeCallbackFunc; | setSizeFunc setSizeCallbackFunc; | ||||
PrivateData() noexcept | |||||
PrivateData(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), | |||||
callbacksPtr(nullptr), | callbacksPtr(nullptr), | ||||
editParamCallbackFunc(nullptr), | editParamCallbackFunc(nullptr), | ||||
setParamCallbackFunc(nullptr), | setParamCallbackFunc(nullptr), | ||||
@@ -155,9 +159,9 @@ public: | |||||
fIsReady(false) | fIsReady(false) | ||||
{ | { | ||||
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); | 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()); | setSize(fUI->getWidth(), fUI->getHeight()); | ||||
} | } | ||||
@@ -182,6 +186,7 @@ protected: | |||||
{ | { | ||||
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); | DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); | ||||
fUI->setSize(width, height); | |||||
fUI->uiReshape(width, height); | fUI->uiReshape(width, height); | ||||
fIsReady = true; | fIsReady = true; | ||||
} | } | ||||
@@ -18,6 +18,8 @@ | |||||
#include "DistrhoUI.hpp" | #include "DistrhoUI.hpp" | ||||
#include "Window.hpp" | |||||
START_NAMESPACE_DISTRHO | START_NAMESPACE_DISTRHO | ||||
// ----------------------------------------------------------------------------------------------------------- | // ----------------------------------------------------------------------------------------------------------- | ||||
@@ -26,13 +28,16 @@ class InfoExampleUI : public UI | |||||
{ | { | ||||
public: | public: | ||||
InfoExampleUI() | InfoExampleUI() | ||||
: UI(405, 256) | |||||
: UI(405, 256, true), | |||||
fScale(1.0f) | |||||
{ | { | ||||
std::memset(fParameters, 0, sizeof(float)*kParameterCount); | std::memset(fParameters, 0, sizeof(float)*kParameterCount); | ||||
std::memset(fStrBuf, 0, sizeof(char)*(0xff+1)); | std::memset(fStrBuf, 0, sizeof(char)*(0xff+1)); | ||||
fSampleRate = getSampleRate(); | fSampleRate = getSampleRate(); | ||||
fFont = createFontFromFile("sans", "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf"); | fFont = createFontFromFile("sans", "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf"); | ||||
setGeometryConstraints(405, 256, false); | |||||
} | } | ||||
protected: | protected: | ||||
@@ -69,13 +74,13 @@ protected: | |||||
*/ | */ | ||||
void onNanoDisplay() override | void onNanoDisplay() override | ||||
{ | { | ||||
static const float lineHeight = 20; | |||||
const float lineHeight = 20 * fScale; | |||||
fontSize(15.0f); | |||||
fontSize(15.0f * fScale); | |||||
textLineHeight(lineHeight); | textLineHeight(lineHeight); | ||||
float x = 0; | |||||
float y = 15; | |||||
float x = 0.0f * fScale; | |||||
float y = 15.0f * fScale; | |||||
// buffer size | // buffer size | ||||
drawLeft(x, y, "Buffer Size:"); | drawLeft(x, y, "Buffer Size:"); | ||||
@@ -104,8 +109,8 @@ protected: | |||||
y+=lineHeight; | y+=lineHeight; | ||||
// BBT | // BBT | ||||
x = 200; | |||||
y = 15; | |||||
x = 200.0f * fScale; | |||||
y = 15.0f * fScale; | |||||
const bool validBBT(fParameters[kParameterTimeValidBBT] > 0.5f); | const bool validBBT(fParameters[kParameterTimeValidBBT] > 0.5f); | ||||
drawLeft(x, y, "BBT Valid:"); | drawLeft(x, y, "BBT Valid:"); | ||||
@@ -148,6 +153,14 @@ protected: | |||||
y+=lineHeight; | y+=lineHeight; | ||||
} | } | ||||
void onResize(const ResizeEvent& ev) override | |||||
{ | |||||
fScale = static_cast<float>(ev.size.getHeight())/256.0f; | |||||
UI::onResize(ev); | |||||
} | |||||
// ------------------------------------------------------------------------------------------------------- | // ------------------------------------------------------------------------------------------------------- | ||||
private: | private: | ||||
@@ -155,8 +168,9 @@ private: | |||||
float fParameters[kParameterCount]; | float fParameters[kParameterCount]; | ||||
double fSampleRate; | double fSampleRate; | ||||
// font | |||||
// UI stuff | |||||
FontId fFont; | FontId fFont; | ||||
float fScale; | |||||
// temp buf for text | // temp buf for text | ||||
char fStrBuf[0xff+1]; | char fStrBuf[0xff+1]; | ||||
@@ -190,7 +204,7 @@ private: | |||||
beginPath(); | beginPath(); | ||||
fillColor(200, 200, 200); | fillColor(200, 200, 200); | ||||
textAlign(ALIGN_RIGHT|ALIGN_TOP); | textAlign(ALIGN_RIGHT|ALIGN_TOP); | ||||
textBox(x, y, 100, text); | |||||
textBox(x, y, 100 * fScale, text); | |||||
closePath(); | closePath(); | ||||
} | } | ||||
@@ -199,7 +213,7 @@ private: | |||||
beginPath(); | beginPath(); | ||||
fillColor(255, 255, 255); | fillColor(255, 255, 255); | ||||
textAlign(ALIGN_LEFT|ALIGN_TOP); | textAlign(ALIGN_LEFT|ALIGN_TOP); | ||||
textBox(x+105, y, 100, text); | |||||
textBox(x + (105 * fScale), y, 100 * fScale, text); | |||||
closePath(); | closePath(); | ||||
} | } | ||||