diff options
author | Michael Lutz <michi@icosahedron.de> | 2021-01-07 21:18:25 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2021-02-14 11:50:18 +0100 |
commit | 0fc763bc5597e04ee528a34ca2730f780d25fb5e (patch) | |
tree | 5423154a86243834a24b17bbe1072d022acbf786 /src/video/cocoa/cocoa_wnd.mm | |
parent | 8906e9e0fd6dc7bd64f9ad2c633da6f110dbf921 (diff) | |
download | openttd-0fc763bc5597e04ee528a34ca2730f780d25fb5e.tar.xz |
Change: [OSX] Render screen in full native resolution on HiDPI displays.
Diffstat (limited to 'src/video/cocoa/cocoa_wnd.mm')
-rw-r--r-- | src/video/cocoa/cocoa_wnd.mm | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/video/cocoa/cocoa_wnd.mm b/src/video/cocoa/cocoa_wnd.mm index 089bfe834..cd194f712 100644 --- a/src/video/cocoa/cocoa_wnd.mm +++ b/src/video/cocoa/cocoa_wnd.mm @@ -417,6 +417,30 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel float _current_magnification; NSUInteger _current_mods; bool _emulated_down; + bool _use_hidpi; +} + +- (instancetype)initWithFrame:(NSRect)frameRect +{ + if (self = [ super initWithFrame:frameRect ]) { + self->_use_hidpi = [ self respondsToSelector:@selector(convertRectToBacking:) ] && [ self respondsToSelector:@selector(convertRectFromBacking:) ]; + } + return self; +} + +- (NSRect)getRealRect:(NSRect)rect +{ + return _use_hidpi ? [ self convertRectToBacking:rect ] : rect; +} + +- (NSRect)getVirtualRect:(NSRect)rect +{ + return _use_hidpi ? [ self convertRectFromBacking:rect ] : rect; +} + +- (CGFloat)getContentsScale +{ + return _use_hidpi && self.window != nil ? [ self.window backingScaleFactor ] : 1.0f; } /** @@ -483,15 +507,13 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel if ([ e window ] == nil) pt = [ self.window convertRectFromScreen:NSMakeRect(pt.x, pt.y, 0, 0) ].origin; pt = [ self convertPoint:pt fromView:nil ]; - pt.y = self.bounds.size.height - pt.y; - - return pt; + return [ self getRealRect:NSMakeRect(pt.x, self.bounds.size.height - pt.y, 0, 0) ].origin; } - (void)internalMouseMoveEvent:(NSEvent *)event { if (_cursor.fix_at) { - _cursor.UpdateCursorPositionRelative(event.deltaX, event.deltaY); + _cursor.UpdateCursorPositionRelative(event.deltaX * self.getContentsScale, event.deltaY * self.getContentsScale); } else { NSPoint pt = [ self mousePositionFromEvent:event ]; _cursor.UpdateCursorPosition(pt.x, pt.y, false); |