From 2d6cbf8a0bb81bfe55a7d4e04d53a704f93c6b2e Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 9 Oct 2019 18:02:19 +0200 Subject: Make FileBrowser window always-on-top and try to position it inside the plugin gui window rectangle. --- plugingui/nativewindow_cocoa.mm | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'plugingui/nativewindow_cocoa.mm') diff --git a/plugingui/nativewindow_cocoa.mm b/plugingui/nativewindow_cocoa.mm index aaacd0e..d8e889a 100644 --- a/plugingui/nativewindow_cocoa.mm +++ b/plugingui/nativewindow_cocoa.mm @@ -576,6 +576,18 @@ void NativeWindowCocoa::setFixedSize(std::size_t width, std::size_t height) [priv->window setMaxSize:NSMakeSize(width, height + 22)]; } +void NativeWindowCocoa::setAlwaysOnTop(bool always_on_top) +{ + if(always_on_top) + { + [priv->window setLevel: NSStatusWindowLevel]; + } + else + { + [priv->window setLevel: NSNormalWindowLevel]; + } +} + void NativeWindowCocoa::resize(std::size_t width, std::size_t height) { [priv->window setContentSize:NSMakeSize(width, height)]; @@ -597,13 +609,15 @@ std::pair NativeWindowCocoa::getSize() const void NativeWindowCocoa::move(int x, int y) { - [priv->window setFrameTopLeftPoint:NSMakePoint(x, y)]; + NSRect screen = [[NSScreen mainScreen] frame]; + [priv->window setFrameTopLeftPoint:NSMakePoint(x, screen.size.height - y)]; } std::pair NativeWindowCocoa::getPosition() const { + NSRect screen = [[NSScreen mainScreen] frame]; NSPoint pos = [[priv->window contentView] frame].origin; - return {pos.x, pos.y}; + return {pos.x, screen.size.height - pos.y}; } void NativeWindowCocoa::show() @@ -757,6 +771,27 @@ void* NativeWindowCocoa::getNativeWindowHandle() const } } +Point NativeWindowCocoa::translateToScreen(const Point& point) +{ + NSRect e = [[NSScreen mainScreen] frame]; + NSRect frame; + if(native_window) + { + frame = [priv->parent_view frame]; + } + else + { + frame = [priv->view frame]; + } + + NSRect rect { { point.x + frame.origin.x, + frame.size.height - point.y + frame.origin.y}, + {0.0, 0.0} }; + rect = [priv->window convertRectToScreen:rect]; + + return { (int)rect.origin.x, (int)(e.size.height - rect.origin.y) }; +} + Window& NativeWindowCocoa::getWindow() { return window; -- cgit v1.2.3