Browse Source

Show macOS transient and standalone windows nicely centered

pull/327/head
falkTX 4 years ago
parent
commit
8a702c3672
3 changed files with 37 additions and 4 deletions
  1. +4
    -2
      dgl/src/WindowPrivateData.cpp
  2. +28
    -1
      dgl/src/pugl.cpp
  3. +5
    -1
      dgl/src/pugl.hpp

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

@@ -316,8 +316,10 @@ void Window::PrivateData::show()
PuglRect rect = puglGetFrame(view);
puglSetWindowSize(view, static_cast<uint>(rect.width), static_cast<uint>(rect.height));

#ifdef DISTRHO_OS_WINDOWS
puglWin32ShowWindowCentered(view);
#if defined(DISTRHO_OS_WINDOWS)
puglWin32ShowCentered(view);
#elif defined(DISTRHO_OS_MAC)
puglMacOSShowCentered(view);
#else
puglShow(view);
#endif


+ 28
- 1
dgl/src/pugl.cpp View File

@@ -501,6 +501,33 @@ puglMacOSRemoveChildWindow(PuglView* const view, PuglView* const child)
return PUGL_FAILURE;
}

// --------------------------------------------------------------------------------------------------------------------
// macOS specific, center view based on parent coordinates (if there is one)

void puglMacOSShowCentered(PuglView* const view)
{
if (puglShow(view) != PUGL_SUCCESS)
return;

if (view->transientParent != 0)
{
NSWindow* const transientWindow = [(NSView*)view->transientParent window];
DISTRHO_SAFE_ASSERT_RETURN(transientWindow != nullptr,);

const NSRect ourFrame = [view->impl->window frame];
const NSRect transientFrame = [transientWindow frame];

const int x = transientFrame.origin.x + transientFrame.size.width / 2 - ourFrame.size.width / 2;
const int y = transientFrame.origin.y + transientFrame.size.height / 2 + ourFrame.size.height / 2;

[view->impl->window setFrameTopLeftPoint:NSMakePoint(x, y)];
}
else
{
[view->impl->window center];
}
}

// --------------------------------------------------------------------------------------------------------------------
// macOS specific, setup file browser dialog

@@ -564,7 +591,7 @@ void puglWin32RestoreWindow(PuglView* const view)
// --------------------------------------------------------------------------------------------------------------------
// win32 specific, center view based on parent coordinates (if there is one)

void puglWin32ShowWindowCentered(PuglView* const view)
void puglWin32ShowCentered(PuglView* const view)
{
PuglInternals* impl = view->impl;
DISTRHO_SAFE_ASSERT_RETURN(impl->hwnd != nullptr,);


+ 5
- 1
dgl/src/pugl.hpp View File

@@ -108,6 +108,10 @@ puglMacOSAddChildWindow(PuglView* view, PuglView* child);
PUGL_API PuglStatus
puglMacOSRemoveChildWindow(PuglView* view, PuglView* child);

// macOS specific, center view based on parent coordinates (if there is one)
PUGL_API void
puglMacOSShowCentered(PuglView* view);

// macOS specific, setup file browser dialog
typedef void (*openPanelCallback)(PuglView* view, const char* path);
bool puglMacOSFilePanelOpen(PuglView* view, const char* startDir, const char* title, uint flags, openPanelCallback callback);
@@ -120,7 +124,7 @@ puglWin32RestoreWindow(PuglView* view);

// win32 specific, center view based on parent coordinates (if there is one)
PUGL_API void
puglWin32ShowWindowCentered(PuglView* view);
puglWin32ShowCentered(PuglView* view);

// win32 specific, set or unset WS_SIZEBOX style flag
PUGL_API void


Loading…
Cancel
Save