diff options
Diffstat (limited to 'platform/macos/godot_button_view.mm')
-rw-r--r-- | platform/macos/godot_button_view.mm | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/platform/macos/godot_button_view.mm b/platform/macos/godot_button_view.mm index ae04c02bd5..7d380cbe11 100644 --- a/platform/macos/godot_button_view.mm +++ b/platform/macos/godot_button_view.mm @@ -39,39 +39,66 @@ offset = NSMakePoint(8, 8); spacing = 20; mouse_in_group = false; + rtl = false; + close_button = nullptr; + miniaturize_button = nullptr; + zoom_button = nullptr; return self; } -- (void)initButtons:(CGFloat)button_spacing offset:(NSPoint)button_offset { +- (void)initButtons:(CGFloat)button_spacing offset:(NSPoint)button_offset rtl:(bool)is_rtl { spacing = button_spacing; + rtl = is_rtl; - NSButton *close_button = [NSWindow standardWindowButton:NSWindowCloseButton forStyleMask:NSWindowStyleMaskTitled]; - [close_button setFrameOrigin:NSMakePoint(0, 0)]; + close_button = [NSWindow standardWindowButton:NSWindowCloseButton forStyleMask:NSWindowStyleMaskTitled]; + [close_button setFrameOrigin:NSMakePoint(rtl ? spacing * 2 : 0, 0)]; [self addSubview:close_button]; - NSButton *miniaturize_button = [NSWindow standardWindowButton:NSWindowMiniaturizeButton forStyleMask:NSWindowStyleMaskTitled]; + miniaturize_button = [NSWindow standardWindowButton:NSWindowMiniaturizeButton forStyleMask:NSWindowStyleMaskTitled]; [miniaturize_button setFrameOrigin:NSMakePoint(spacing, 0)]; [self addSubview:miniaturize_button]; - NSButton *zoom_button = [NSWindow standardWindowButton:NSWindowZoomButton forStyleMask:NSWindowStyleMaskTitled]; - [zoom_button setFrameOrigin:NSMakePoint(spacing * 2, 0)]; + zoom_button = [NSWindow standardWindowButton:NSWindowZoomButton forStyleMask:NSWindowStyleMaskTitled]; + [zoom_button setFrameOrigin:NSMakePoint(rtl ? 0 : spacing * 2, 0)]; [self addSubview:zoom_button]; offset.y = button_offset.y - zoom_button.frame.size.height / 2; offset.x = button_offset.x - zoom_button.frame.size.width / 2; - [self setFrameSize:NSMakeSize(zoom_button.frame.origin.x + zoom_button.frame.size.width, zoom_button.frame.size.height)]; + if (rtl) { + [self setFrameSize:NSMakeSize(close_button.frame.origin.x + close_button.frame.size.width, close_button.frame.size.height)]; + } else { + [self setFrameSize:NSMakeSize(zoom_button.frame.origin.x + zoom_button.frame.size.width, zoom_button.frame.size.height)]; + } [self displayButtons]; } +- (void)setOffset:(NSPoint)button_offset { + if (zoom_button) { + offset.y = button_offset.y - zoom_button.frame.size.height / 2; + offset.x = button_offset.x - zoom_button.frame.size.width / 2; + + [self viewDidMoveToWindow]; + } +} + +- (NSPoint)getOffset { + return offset; +} + - (void)viewDidMoveToWindow { if (!self.window) { return; } - [self setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin]; - [self setFrameOrigin:NSMakePoint(offset.x, self.window.frame.size.height - self.frame.size.height - offset.y)]; + if (rtl) { + [self setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; + [self setFrameOrigin:NSMakePoint(self.window.frame.size.width - self.frame.size.width - offset.x, self.window.frame.size.height - self.frame.size.height - offset.y)]; + } else { + [self setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin]; + [self setFrameOrigin:NSMakePoint(offset.x, self.window.frame.size.height - self.frame.size.height - offset.y)]; + } } - (BOOL)_mouseInGroup:(NSButton *)button { |