Skip to content

Commit

Permalink
Fix AU for retina
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Feb 27, 2024
1 parent 93db75c commit 4370911
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
6 changes: 3 additions & 3 deletions distrho/src/DistrhoUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ void UI::onResize(const ResizeEvent& ev)
{
UIWidget::onResize(ev);

#if !(defined(DISTRHO_PLUGIN_TARGET_VST3) || defined(DISTRHO_PLUGIN_TARGET_CLAP))
#if ! DISTRHO_UI_USES_SIZE_REQUEST
if (uiData->initializing)
return;

Expand All @@ -442,10 +442,10 @@ void UI::onResize(const ResizeEvent& ev)
#endif
}

// NOTE: only used for VST3 and CLAP
// NOTE: only used for CLAP and VST3
void UI::requestSizeChange(const uint width, const uint height)
{
#if defined(DISTRHO_PLUGIN_TARGET_VST3) || defined(DISTRHO_PLUGIN_TARGET_CLAP)
#if DISTRHO_UI_USES_SIZE_REQUEST
if (uiData->initializing)
uiData->window->setSizeFromHost(width, height);
else
Expand Down
17 changes: 7 additions & 10 deletions distrho/src/DistrhoUIAU.mm
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,9 @@ void postSetup()
{
const double scaleFactor = fUI.getScaleFactor();
const NSSize size = NSMakeSize(fUI.getWidth() / scaleFactor, fUI.getHeight() / scaleFactor);
NSView* const uiView = reinterpret_cast<NSView*>(fUI.getNativeWindowHandle());

for (NSView* subview in [uiView subviews])
{
[subview setFrameSize:size];
break;
}
[uiView setFrameSize:size];
[fParentView setFrameSize:size];
[fParentView setHidden:NO];
}

private:
Expand Down Expand Up @@ -368,7 +362,9 @@ static void sendNoteCallback(void* const ptr, const uint8_t channel, const uint8
void setSize(const uint width, const uint height)
{
const double scaleFactor = fUI.getScaleFactor();
[fParentView setFrameSize:NSMakeSize(width / scaleFactor, height / scaleFactor)];
const NSSize size = NSMakeSize(width / scaleFactor, height / scaleFactor);

[fParentView setFrameSize:size];
}

static void setSizeCallback(void* const ptr, const uint width, const uint height)
Expand Down Expand Up @@ -402,8 +398,9 @@ @implementation COCOA_VIEW_CLASS_NAME

- (id) initWithPreferredSize:(NSSize)size
{
self = [super initWithFrame: NSMakeRect(0, 0, size.width, size.height)];
[self setHidden:NO];
ui = nullptr;
self = [super initWithFrame: NSMakeRect(0, 0, size.width, size.height)];
[self setHidden:YES];
return self;
}

Expand Down
2 changes: 1 addition & 1 deletion distrho/src/DistrhoUIInternal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class UIExporter
#endif
}

#if defined(DISTRHO_PLUGIN_TARGET_VST3) || defined(DISTRHO_PLUGIN_TARGET_CLAP)
#if DISTRHO_UI_USES_SIZE_REQUEST
void setWindowSizeFromHost(const uint width, const uint height)
{
#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
Expand Down
26 changes: 15 additions & 11 deletions distrho/src/DistrhoUIPrivateData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@
#endif

#if defined(DISTRHO_PLUGIN_TARGET_AU)
# define DISTRHO_UI_USES_SCHEDULED_REPAINTS true
# define DISTRHO_UI_USES_SCHEDULED_REPAINTS 1
#else
# define DISTRHO_UI_USES_SCHEDULED_REPAINTS false
# define DISTRHO_UI_USES_SCHEDULED_REPAINTS 0
#endif

#if defined(DISTRHO_PLUGIN_TARGET_VST3) || defined(DISTRHO_PLUGIN_TARGET_CLAP)
# define DISTRHO_UI_USES_SIZE_REQUEST true
#if defined(DISTRHO_PLUGIN_TARGET_CLAP) || defined(DISTRHO_PLUGIN_TARGET_VST3)
# define DISTRHO_UI_USES_SIZE_REQUEST 1
#else
# define DISTRHO_UI_USES_SIZE_REQUEST false
# define DISTRHO_UI_USES_SIZE_REQUEST 0
#endif

#if defined(DISTRHO_PLUGIN_TARGET_AU) || defined(DISTRHO_PLUGIN_TARGET_VST2)
Expand Down Expand Up @@ -234,11 +234,15 @@ class PluginWindow : public DGL_NAMESPACE::Window
if (pData->view == nullptr)
return;

if (receivedReshapeDuringInit)
ui->uiReshape(getWidth(), getHeight());

initializing = false;
puglBackendLeave(pData->view);

if (receivedReshapeDuringInit)
{
puglBackendEnter(pData->view);
ui->uiReshape(getWidth(), getHeight());
puglBackendLeave(pData->view);
}
}

// used for temporary windows (VST/CLAP get size without active/visible view)
Expand All @@ -254,7 +258,7 @@ class PluginWindow : public DGL_NAMESPACE::Window
puglBackendEnter(pData->view);
}

#if defined(DISTRHO_PLUGIN_TARGET_VST3) || defined(DISTRHO_PLUGIN_TARGET_CLAP)
#if DISTRHO_UI_USES_SIZE_REQUEST
void setSizeFromHost(const uint width, const uint height)
{
puglSetSizeAndDefault(pData->view, width, height);
Expand Down Expand Up @@ -310,9 +314,9 @@ class PluginWindow : public DGL_NAMESPACE::Window
ui->uiScaleFactorChanged(scaleFactor);
}

# if DISTRHO_UI_FILE_BROWSER
#if DISTRHO_UI_FILE_BROWSER
void onFileSelected(const char* filename) override;
# endif
#endif

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PluginWindow)
};
Expand Down

0 comments on commit 4370911

Please sign in to comment.