Browse Source

Handle geometry constraints for embed windows; More resize handling

Signed-off-by: falkTX <falktx@falktx.com>
pull/281/head
falkTX 4 years ago
parent
commit
8a70216311
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
11 changed files with 85 additions and 47 deletions
  1. +7
    -0
      dgl/Window.hpp
  2. +33
    -3
      dgl/src/Window.cpp
  3. +4
    -0
      dgl/src/WindowPrivateData.cpp
  4. +2
    -1
      dgl/src/WindowPrivateData.hpp
  5. +10
    -1
      distrho/DistrhoUI.hpp
  6. +1
    -11
      distrho/src/DistrhoPluginJack.cpp
  7. +1
    -3
      distrho/src/DistrhoPluginVST.cpp
  8. +12
    -15
      distrho/src/DistrhoUI.cpp
  9. +1
    -11
      distrho/src/DistrhoUIDSSI.cpp
  10. +2
    -2
      distrho/src/DistrhoUILV2.cpp
  11. +12
    -0
      distrho/src/DistrhoUIPrivateData.hpp

+ 7
- 0
dgl/Window.hpp View File

@@ -387,6 +387,13 @@ protected:
*/
virtual void onReshape(uint width, uint height);

/**
A function called when scale factor requested for this window changes.
The default implementation does nothing.
WARNING function needs a proper name
*/
virtual void onScaleFactorChanged(double scaleFactor);

#ifndef DGL_FILE_BROWSER_DISABLED
/**
A function called when a path is selected by the user, as triggered by openFileBrowser().


+ 33
- 3
dgl/src/Window.cpp View File

@@ -136,10 +136,36 @@ void Window::setHeight(const uint height)
setSize(getWidth(), height);
}

void Window::setSize(const uint width, const uint height)
void Window::setSize(uint width, uint height)
{
DISTRHO_SAFE_ASSERT_UINT2_RETURN(width > 1 && height > 1, width, height,);

if (pData->isEmbed)
{
// handle geometry constraints here
if (width < pData->minWidth)
width = pData->minWidth;
if (height < pData->minHeight)
height = pData->minHeight;
if (pData->keepAspectRatio)
{
const double ratio = static_cast<double>(pData->minWidth)
/ static_cast<double>(pData->minHeight);
const double reqRatio = static_cast<double>(width)
/ static_cast<double>(height);

if (d_isNotEqual(ratio, reqRatio))
{
// fix width
if (reqRatio > ratio)
width = height * ratio;
// fix height
else
height = width / ratio;
}
}
}

// FIXME add default and min props for this
if (pData->minWidth == 0 && pData->minHeight == 0)
puglSetDefaultSize(pData->view, static_cast<int>(width), static_cast<int>(height));
@@ -250,8 +276,7 @@ void Window::setGeometryConstraints(const uint minimumWidth,
DISTRHO_SAFE_ASSERT_RETURN(minimumHeight > 0,);

if (pData->isEmbed) {
// Did you forget to set DISTRHO_UI_USER_RESIZABLE ?
DISTRHO_SAFE_ASSERT_RETURN(isResizable(),);
// nothing to do here
} else if (! isResizable()) {
setResizable(true);
}
@@ -259,6 +284,7 @@ void Window::setGeometryConstraints(const uint minimumWidth,
pData->minWidth = minimumWidth;
pData->minHeight = minimumHeight;
pData->autoScaling = automaticallyScale;
pData->keepAspectRatio = keepAspectRatio;

const double scaleFactor = pData->scaleFactor;

@@ -290,6 +316,10 @@ void Window::onReshape(uint, uint)
puglFallbackOnResize(pData->view);
}

void Window::onScaleFactorChanged(double)
{
}

#ifndef DGL_FILE_BROWSER_DISABLED
void Window::onFileSelected(const char*)
{


+ 4
- 0
dgl/src/WindowPrivateData.cpp View File

@@ -88,6 +88,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s)
autoScaleFactor(1.0),
minWidth(0),
minHeight(0),
keepAspectRatio(false),
#ifdef DISTRHO_OS_WINDOWS
win32SelectedFile(nullptr),
#endif
@@ -110,6 +111,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s, PrivateData* c
autoScaleFactor(1.0),
minWidth(0),
minHeight(0),
keepAspectRatio(false),
#ifdef DISTRHO_OS_WINDOWS
win32SelectedFile(nullptr),
#endif
@@ -136,6 +138,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s,
autoScaleFactor(1.0),
minWidth(0),
minHeight(0),
keepAspectRatio(false),
#ifdef DISTRHO_OS_WINDOWS
win32SelectedFile(nullptr),
#endif
@@ -167,6 +170,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s,
autoScaleFactor(1.0),
minWidth(0),
minHeight(0),
keepAspectRatio(false),
#ifdef DISTRHO_OS_WINDOWS
win32SelectedFile(nullptr),
#endif


+ 2
- 1
dgl/src/WindowPrivateData.hpp View File

@@ -67,8 +67,9 @@ struct Window::PrivateData : IdleCallback {
bool autoScaling;
double autoScaleFactor;

/** Pugl minWidth, minHeight access. */
/** Pugl geometry constraints access. */
uint minWidth, minHeight;
bool keepAspectRatio;

#ifdef DISTRHO_OS_WINDOWS
/** Selected file for openFileBrowser on windows, stored for fake async operation. */


+ 10
- 1
distrho/DistrhoUI.hpp View File

@@ -264,6 +264,15 @@ protected:
*/
virtual void uiReshape(uint width, uint height);

/**
Window scale factor function, called when the scale factor changes.
This function is for plugin UIs to be able to override Window::onScaleFactorChanged(double).

The default implementation does nothing.
WARNING function needs a proper name
*/
virtual void uiScaleFactorChanged(double scaleFactor);

# ifndef DGL_FILE_BROWSER_DISABLED
/**
Window file selected function, called when a path is selected by the user, as triggered by openFileBrowser().
@@ -285,7 +294,7 @@ protected:
This is overriden here so the host knows when the UI is resized by you.
@see Widget::onResize(const ResizeEvent&)
*/
// void onResize(const ResizeEvent& ev) override;
void onResize(const ResizeEvent& ev) override;
#endif

// -------------------------------------------------------------------------------------------------------


+ 1
- 11
distrho/src/DistrhoPluginJack.cpp View File

@@ -116,7 +116,7 @@ public:
setParameterValueCallback,
setStateCallback,
sendNoteCallback,
setSizeCallback,
nullptr, // window size
nullptr, // file request
nullptr, // bundle
fPlugin.getInstancePointer(),
@@ -495,11 +495,6 @@ protected:
fPlugin.setParameterValue(index, value);
}

void setSize(const uint width, const uint height)
{
fUI.setWindowSize(width, height);
}

# if DISTRHO_PLUGIN_WANT_MIDI_INPUT
void sendNote(const uint8_t channel, const uint8_t note, const uint8_t velocity)
{
@@ -681,11 +676,6 @@ private:
thisPtr->setParameterValue(index, value);
}

static void setSizeCallback(void* ptr, uint width, uint height)
{
thisPtr->setSize(width, height);
}

# if DISTRHO_PLUGIN_WANT_MIDI_INPUT
static void sendNoteCallback(void* ptr, uint8_t channel, uint8_t note, uint8_t velocity)
{


+ 1
- 3
distrho/src/DistrhoPluginVST.cpp View File

@@ -23,8 +23,6 @@
#endif

#if DISTRHO_PLUGIN_HAS_UI
# undef DISTRHO_UI_USER_RESIZABLE
# define DISTRHO_UI_USER_RESIZABLE 0
# include "DistrhoUIInternal.hpp"
# include "../extra/RingBuffer.hpp"
#endif
@@ -386,7 +384,7 @@ protected:

void setSize(const uint width, const uint height)
{
fUI.setWindowSize(width, height);
// fUI.setWindowSize(width, height);
hostCallback(audioMasterSizeWindow, width, height);
}



+ 12
- 15
distrho/src/DistrhoUI.cpp View File

@@ -156,6 +156,10 @@ void UI::uiReshape(uint, uint)
pData->fallbackOnResize();
}

void UI::uiScaleFactorChanged(double)
{
}

# ifndef DGL_FILE_BROWSER_DISABLED
void UI::uiFileBrowserSelected(const char*)
{
@@ -165,21 +169,14 @@ void UI::uiFileBrowserSelected(const char*)
/* ------------------------------------------------------------------------------------------------------------
* UI Resize Handling, internal */

// void UI::onResize(const ResizeEvent& ev)
// {
// if (uiData->resizeInProgress)
// return;
//
// UIWidget::onResize(ev);
//
// const uint width = ev.size.getWidth();
// const uint height = ev.size.getHeight();
//
// /*
// pData->window.setSize(width, height);
// */
// uiData->setSizeCallback(width, height);
// }
void UI::onResize(const ResizeEvent& ev)
{
UIWidget::onResize(ev);

const uint width = ev.size.getWidth();
const uint height = ev.size.getHeight();
uiData->setSizeCallback(width, height);
}
#endif // !DISTRHO_PLUGIN_HAS_EXTERNAL_UI

// -----------------------------------------------------------------------------------------------------------


+ 1
- 11
distrho/src/DistrhoUIDSSI.cpp View File

@@ -98,7 +98,7 @@ class UIDssi : public IdleCallback
public:
UIDssi(const OscData& oscData, const char* const uiTitle, const double sampleRate)
: fUI(this, 0, sampleRate, nullptr,
setParameterCallback, setStateCallback, sendNoteCallback, setSizeCallback, nullptr),
setParameterCallback, setStateCallback, sendNoteCallback, nullptr, nullptr),
fHostClosed(false),
fOscData(oscData)
{
@@ -208,11 +208,6 @@ protected:
}
#endif

void setSize(const uint width, const uint height)
{
fUI.setWindowSize(width, height);
}

private:
UIExporter fUI;
bool fHostClosed;
@@ -241,11 +236,6 @@ private:
}
#endif

static void setSizeCallback(void* ptr, uint width, uint height)
{
uiPtr->setSize(width, height);
}

#undef uiPtr
};



+ 2
- 2
distrho/src/DistrhoUILV2.cpp View File

@@ -208,7 +208,7 @@ public:

int lv2ui_resize(uint width, uint height)
{
// FIXME
// this comes from the host
// fUI.setWindowSize(width, height, true);
return 0;
}
@@ -334,7 +334,7 @@ protected:

void setSize(const uint width, const uint height)
{
fUI.setWindowSize(width, height);
// fUI.setWindowSize(width, height);

if (fUiResize != nullptr && ! fWinIdWasNull)
fUiResize->ui_resize(fUiResize->handle, width, height);


+ 12
- 0
distrho/src/DistrhoUIPrivateData.hpp View File

@@ -30,6 +30,11 @@
# define DISTRHO_UI_IS_STANDALONE 0
#endif

#if defined(DISTRHO_PLUGIN_TARGET_VST)
# undef DISTRHO_UI_USER_RESIZABLE
# define DISTRHO_UI_USER_RESIZABLE 0
#endif

START_NAMESPACE_DISTRHO

using DGL_NAMESPACE::Application;
@@ -244,6 +249,13 @@ protected:
ui->uiReshape(width, height);
}

void onScaleFactorChanged(const double scaleFactor) override
{
DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,);

ui->uiScaleFactorChanged(scaleFactor);
}

# ifndef DGL_FILE_BROWSER_DISABLED
void onFileSelected(const char* const filename) override
{


Loading…
Cancel
Save