summaryrefslogtreecommitdiff
path: root/platform/osx/os_osx.mm
diff options
context:
space:
mode:
authorBastiaanOlij <mux213@gmail.com>2017-04-09 21:22:40 +1000
committerBastiaanOlij <mux213@gmail.com>2017-04-09 21:22:40 +1000
commit5c2ddb299ba1385bae19e16590bd6207e493ace6 (patch)
tree217b35aad58f0909e9915ba9fcdaf0ea6be5694d /platform/osx/os_osx.mm
parent21727657ff6df8ebbf5860547ecd3c48f22eefe5 (diff)
Formatting of mm files
Diffstat (limited to 'platform/osx/os_osx.mm')
-rw-r--r--platform/osx/os_osx.mm1149
1 files changed, 557 insertions, 592 deletions
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index 47b4aed491..e035d2b21c 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -88,32 +88,31 @@
static NSRect convertRectToBacking(NSRect contentRect) {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
- if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6)
+ if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6)
return [OS_OSX::singleton->window_view convertRectToBacking:contentRect];
- else
+ else
#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/
return contentRect;
}
-static InputModifierState translateFlags(NSUInteger flags)
-{
- InputModifierState mod;
+static InputModifierState translateFlags(NSUInteger flags) {
+ InputModifierState mod;
- mod.shift = (flags & NSShiftKeyMask);
- mod.control = (flags & NSControlKeyMask);
- mod.alt = (flags & NSAlternateKeyMask);
- mod.meta = (flags & NSCommandKeyMask);
+ mod.shift = (flags & NSShiftKeyMask);
+ mod.control = (flags & NSControlKeyMask);
+ mod.alt = (flags & NSAlternateKeyMask);
+ mod.meta = (flags & NSCommandKeyMask);
- return mod;
+ return mod;
}
-static int mouse_x=0;
-static int mouse_y=0;
-static int prev_mouse_x=0;
-static int prev_mouse_y=0;
-static int button_mask=0;
+static int mouse_x = 0;
+static int mouse_y = 0;
+static int prev_mouse_x = 0;
+static int prev_mouse_y = 0;
+static int button_mask = 0;
@interface GodotApplication : NSApplication
@@ -124,12 +123,11 @@ static int button_mask=0;
// From http://cocoadev.com/index.pl?GameKeyboardHandlingAlmost
// This works around an AppKit bug, where key up events while holding
// down the command key don't get sent to the key window.
-- (void)sendEvent:(NSEvent *)event
-{
- if ([event type] == NSKeyUp && ([event modifierFlags] & NSCommandKeyMask))
- [[self keyWindow] sendEvent:event];
- else
- [super sendEvent:event];
+- (void)sendEvent:(NSEvent *)event {
+ if ([event type] == NSKeyUp && ([event modifierFlags] & NSCommandKeyMask))
+ [[self keyWindow] sendEvent:event];
+ else
+ [super sendEvent:event];
}
@end
@@ -139,45 +137,39 @@ static int button_mask=0;
@implementation GodotApplicationDelegate
-- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
-{
+- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
if (OS_OSX::singleton->get_main_loop())
OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_QUIT_REQUEST);
return NSTerminateCancel;
}
-- (void)applicationDidHide:(NSNotification *)notification
-{
- /*
+- (void)applicationDidHide:(NSNotification *)notification{
+/*
_Godotwindow* window;
for (window = _Godot.windowListHead; window; window = window->next)
_GodotInputWindowVisibility(window, GL_FALSE);
- */
+*/
}
-- (void)applicationDidUnhide:(NSNotification *)notification
-{
- /*
+- (void)applicationDidUnhide:(NSNotification *)notification {
+/*
_Godotwindow* window;
- for (window = _Godot.windowListHead; window; window = window->next)
- {
- if ([window_object isVisible])
- _GodotInputWindowVisibility(window, GL_TRUE);
+ for (window = _Godot.windowListHead; window; window = window->next) {
+ if ([window_object isVisible])
+ _GodotInputWindowVisibility(window, GL_TRUE);
}
- */
+*/
}
-- (void)applicationDidChangeScreenParameters:(NSNotification *) notification
-{
+- (void)applicationDidChangeScreenParameters:(NSNotification *) notification {
//_GodotInputMonitorChange();
}
@end
-@interface GodotWindowDelegate : NSObject
-{
+@interface GodotWindowDelegate : NSObject {
//_Godotwindow* window;
}
@@ -186,41 +178,39 @@ static int button_mask=0;
@implementation GodotWindowDelegate
-- (BOOL)windowShouldClose:(id)sender
-{
+- (BOOL)windowShouldClose:(id)sender {
//_GodotInputWindowCloseRequest(window);
if (OS_OSX::singleton->get_main_loop())
OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_QUIT_REQUEST);
- return NO;
+
+ return NO;
}
-- (void)windowDidResize:(NSNotification *)notification
-{
- [OS_OSX::singleton->context update];
+- (void)windowDidResize:(NSNotification *)notification {
+ [OS_OSX::singleton->context update];
- const NSRect contentRect = [OS_OSX::singleton->window_view frame];
- const NSRect fbRect = contentRect;//convertRectToBacking(contentRect);
+ const NSRect contentRect = [OS_OSX::singleton->window_view frame];
+ const NSRect fbRect = contentRect;//convertRectToBacking(contentRect);
- OS_OSX::singleton->window_size.width=fbRect.size.width*OS_OSX::singleton->display_scale;
- OS_OSX::singleton->window_size.height=fbRect.size.height*OS_OSX::singleton->display_scale;
+ OS_OSX::singleton->window_size.width=fbRect.size.width*OS_OSX::singleton->display_scale;
+ OS_OSX::singleton->window_size.height=fbRect.size.height*OS_OSX::singleton->display_scale;
- /*
+/*
_GodotInputFramebufferSize(window, fbRect.size.width, fbRect.size.height);
_GodotInputWindowSize(window, contentRect.size.width, contentRect.size.height);
_GodotInputWindowDamage(window);
if (window->cursorMode == Godot_CURSOR_DISABLED)
centerCursor(window);
- */
+*/
}
-- (void)windowDidMove:(NSNotification *)notification
-{
- /*
+- (void)windowDidMove:(NSNotification *)notification {
+/*
[window->nsgl.context update];
int x, y;
@@ -229,35 +219,30 @@ static int button_mask=0;
if (window->cursorMode == Godot_CURSOR_DISABLED)
centerCursor(window);
- */
+*/
}
-- (void)windowDidBecomeKey:(NSNotification *)notification
-{
+- (void)windowDidBecomeKey:(NSNotification *)notification {
//_GodotInputWindowFocus(window, GL_TRUE);
//_GodotPlatformSetCursorMode(window, window->cursorMode);
if (OS_OSX::singleton->get_main_loop())
OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
}
-- (void)windowDidResignKey:(NSNotification *)notification
-{
+- (void)windowDidResignKey:(NSNotification *)notification {
//_GodotInputWindowFocus(window, GL_FALSE);
//_GodotPlatformSetCursorMode(window, Godot_CURSOR_NORMAL);
if (OS_OSX::singleton->get_main_loop())
OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
}
-- (void)windowDidMiniaturize:(NSNotification*)notification
-{
+- (void)windowDidMiniaturize:(NSNotification*)notification {
OS_OSX::singleton->wm_minimized(true);
if (OS_OSX::singleton->get_main_loop())
OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
};
-- (void)windowDidDeminiaturize:(NSNotification*)notification
-{
-
+- (void)windowDidDeminiaturize:(NSNotification*)notification {
OS_OSX::singleton->wm_minimized(false);
if (OS_OSX::singleton->get_main_loop())
OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
@@ -265,296 +250,284 @@ static int button_mask=0;
@end
-@interface GodotContentView : NSView
-{
- NSTrackingArea* trackingArea;
+@interface GodotContentView : NSView {
+ NSTrackingArea* trackingArea;
}
-
-
@end
@implementation GodotContentView
-+ (void)initialize
-{
- if (self == [GodotContentView class])
- {
- /*
- if (_glfw.ns.cursor == nil)
- {
++ (void)initialize {
+ if (self == [GodotContentView class]) {
+/*
+ if (_glfw.ns.cursor == nil) {
NSImage* data = [[NSImage alloc] initWithSize:NSMakeSize(1, 1)];
_glfw.ns.cursor = [[NSCursor alloc] initWithImage:data
hotSpot:NSZeroPoint];
[data release];
}
- */
+*/
}
}
-- (id)init
-{
- self = [super init];
- trackingArea = nil;
- [self updateTrackingAreas];
- [self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
- return self;
+- (id)init {
+ self = [super init];
+ trackingArea = nil;
+ [self updateTrackingAreas];
+ [self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
+ return self;
}
--(void)dealloc
-{
- [trackingArea release];
- [super dealloc];
+-(void)dealloc {
+ [trackingArea release];
+ [super dealloc];
}
- (NSDragOperation)draggingEntered:(id < NSDraggingInfo >)sender {
- return NSDragOperationCopy;
+ return NSDragOperationCopy;
}
- (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender {
- return NSDragOperationCopy;
+ return NSDragOperationCopy;
}
- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
+ NSPasteboard *pboard = [sender draggingPasteboard];
+ NSArray *filenames = [pboard propertyListForType:NSFilenamesPboardType];
- NSPasteboard *pboard = [sender draggingPasteboard];
- NSArray *filenames = [pboard propertyListForType:NSFilenamesPboardType];
-
- Vector<String> files;
- for(int i=0;i<filenames.count;i++) {
- NSString *ns = [filenames objectAtIndex:i];
- char *utfs = strdup([ns UTF8String]);
- String ret;
- ret.parse_utf8(utfs);
- free(utfs);
- files.push_back(ret);
+ Vector<String> files;
+ for(int i=0;i<filenames.count;i++) {
+ NSString *ns = [filenames objectAtIndex:i];
+ char *utfs = strdup([ns UTF8String]);
+ String ret;
+ ret.parse_utf8(utfs);
+ free(utfs);
+ files.push_back(ret);
- }
+ }
- if (files.size()) {
- OS_OSX::singleton->main_loop->drop_files(files,0);
- OS_OSX::singleton->move_window_to_foreground();
- }
+ if (files.size()) {
+ OS_OSX::singleton->main_loop->drop_files(files,0);
+ OS_OSX::singleton->move_window_to_foreground();
+ }
- return NO;
+ return NO;
}
-- (BOOL)isOpaque
-{
- return YES;
+- (BOOL)isOpaque {
+ return YES;
}
-- (BOOL)canBecomeKeyView
-{
- return YES;
+- (BOOL)canBecomeKeyView {
+ return YES;
}
-- (BOOL)acceptsFirstResponder
-{
- return YES;
+- (BOOL)acceptsFirstResponder {
+ return YES;
}
-- (void)cursorUpdate:(NSEvent *)event
-{
- // setModeCursor(window, window->cursorMode);
+- (void)cursorUpdate:(NSEvent *)event {
+ //setModeCursor(window, window->cursorMode);
}
-- (void)mouseDown:(NSEvent *)event
-{
+- (void)mouseDown:(NSEvent *)event {
//print_line("mouse down:");
- button_mask|=BUTTON_MASK_LEFT;
+ button_mask |= BUTTON_MASK_LEFT;
InputEvent ev;
ev.type=InputEvent::MOUSE_BUTTON;
- ev.mouse_button.button_index=BUTTON_LEFT;
- ev.mouse_button.pressed=true;
- ev.mouse_button.x=mouse_x;
- ev.mouse_button.y=mouse_y;
- ev.mouse_button.global_x=mouse_x;
- ev.mouse_button.global_y=mouse_y;
- ev.mouse_button.button_mask=button_mask;
+ ev.mouse_button.button_index = BUTTON_LEFT;
+ ev.mouse_button.pressed = true;
+ ev.mouse_button.x = mouse_x;
+ ev.mouse_button.y = mouse_y;
+ ev.mouse_button.global_x = mouse_x;
+ ev.mouse_button.global_y = mouse_y;
+ ev.mouse_button.button_mask = button_mask;
ev.mouse_button.doubleclick = [event clickCount]==2;
ev.mouse_button.mod = translateFlags([event modifierFlags]);
OS_OSX::singleton->push_input(ev);
-
- /* _glfwInputMouseClick(window,
- GLFW_MOUSE_BUTTON_LEFT,
- GLFW_PRESS,
- translateFlags([event modifierFlags]));*/
+/*
+ _glfwInputMouseClick(window,
+ GLFW_MOUSE_BUTTON_LEFT,
+ GLFW_PRESS,
+ translateFlags([event modifierFlags]));
+*/
}
-- (void)mouseDragged:(NSEvent *)event
-{
- [self mouseMoved:event];
+- (void)mouseDragged:(NSEvent *)event {
+ [self mouseMoved:event];
}
-- (void)mouseUp:(NSEvent *)event
-{
+- (void)mouseUp:(NSEvent *)event {
- button_mask&=~BUTTON_MASK_LEFT;
+ button_mask &= ~BUTTON_MASK_LEFT;
InputEvent ev;
ev.type=InputEvent::MOUSE_BUTTON;
- ev.mouse_button.button_index=BUTTON_LEFT;
- ev.mouse_button.pressed=false;
- ev.mouse_button.x=mouse_x;
- ev.mouse_button.y=mouse_y;
- ev.mouse_button.global_x=mouse_x;
- ev.mouse_button.global_y=mouse_y;
- ev.mouse_button.button_mask=button_mask;
+ ev.mouse_button.button_index = BUTTON_LEFT;
+ ev.mouse_button.pressed = false;
+ ev.mouse_button.x = mouse_x;
+ ev.mouse_button.y = mouse_y;
+ ev.mouse_button.global_x = mouse_x;
+ ev.mouse_button.global_y = mouse_y;
+ ev.mouse_button.button_mask = button_mask;
ev.mouse_button.mod = translateFlags([event modifierFlags]);
OS_OSX::singleton->push_input(ev);
- /* _glfwInputMouseClick(window,
- GLFW_MOUSE_BUTTON_LEFT,
- GLFW_RELEASE,
- translateFlags([event modifierFlags]));*/
+/*
+ _glfwInputMouseClick(window,
+ GLFW_MOUSE_BUTTON_LEFT,
+ GLFW_RELEASE,
+ translateFlags([event modifierFlags]));
+*/
}
-- (void)mouseMoved:(NSEvent *)event
-{
+- (void)mouseMoved:(NSEvent *)event {
InputEvent ev;
- ev.type=InputEvent::MOUSE_MOTION;
- ev.mouse_motion.button_mask=button_mask;
- prev_mouse_x=mouse_x;
- prev_mouse_y=mouse_y;
+ ev.type = InputEvent::MOUSE_MOTION;
+ ev.mouse_motion.button_mask = button_mask;
+ prev_mouse_x = mouse_x;
+ prev_mouse_y = mouse_y;
const NSRect contentRect = [OS_OSX::singleton->window_view frame];
const NSPoint p = [event locationInWindow];
mouse_x = p.x * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]);
mouse_y = (contentRect.size.height - p.y) * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]);
- ev.mouse_motion.x=mouse_x;
- ev.mouse_motion.y=mouse_y;
- ev.mouse_motion.global_x=mouse_x;
- ev.mouse_motion.global_y=mouse_y;
- ev.mouse_motion.relative_x=[event deltaX] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]);
- ev.mouse_motion.relative_y=[event deltaY] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]);
+ ev.mouse_motion.x = mouse_x;
+ ev.mouse_motion.y = mouse_y;
+ ev.mouse_motion.global_x = mouse_x;
+ ev.mouse_motion.global_y = mouse_y;
+ ev.mouse_motion.relative_x = [event deltaX] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]);
+ ev.mouse_motion.relative_y = [event deltaY] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]);
ev.mouse_motion.mod = translateFlags([event modifierFlags]);
OS_OSX::singleton->input->set_mouse_pos(Point2(mouse_x,mouse_y));
OS_OSX::singleton->push_input(ev);
+/*
+ if (window->cursorMode == GLFW_CURSOR_DISABLED)
+ _glfwInputCursorMotion(window, [event deltaX], [event deltaY]);
+ else {
+ const NSRect contentRect = [window->ns.view frame];
+ const NSPoint p = [event locationInWindow];
- /* if (window->cursorMode == GLFW_CURSOR_DISABLED)
- _glfwInputCursorMotion(window, [event deltaX], [event deltaY]);
- else
- {
- const NSRect contentRect = [window->ns.view frame];
- const NSPoint p = [event locationInWindow];
-
- _glfwInputCursorMotion(window, p.x, contentRect.size.height - p.y);
- }*/
+ _glfwInputCursorMotion(window, p.x, contentRect.size.height - p.y);
+ }
+*/
}
-- (void)rightMouseDown:(NSEvent *)event
-{
+- (void)rightMouseDown:(NSEvent *)event {
- button_mask|=BUTTON_MASK_RIGHT;
+ button_mask |= BUTTON_MASK_RIGHT;
InputEvent ev;
ev.type=InputEvent::MOUSE_BUTTON;
- ev.mouse_button.button_index=BUTTON_RIGHT;
- ev.mouse_button.pressed=true;
- ev.mouse_button.x=mouse_x;
- ev.mouse_button.y=mouse_y;
- ev.mouse_button.global_x=mouse_x;
- ev.mouse_button.global_y=mouse_y;
- ev.mouse_button.button_mask=button_mask;
+ ev.mouse_button.button_index = BUTTON_RIGHT;
+ ev.mouse_button.pressed = true;
+ ev.mouse_button.x = mouse_x;
+ ev.mouse_button.y = mouse_y;
+ ev.mouse_button.global_x = mouse_x;
+ ev.mouse_button.global_y = mouse_y;
+ ev.mouse_button.button_mask = button_mask;
ev.mouse_button.mod = translateFlags([event modifierFlags]);
OS_OSX::singleton->push_input(ev);
- /* _glfwInputMouseClick(window,
- GLFW_MOUSE_BUTTON_RIGHT,
- GLFW_PRESS,
- translateFlags([event modifierFlags]));*/
+/*
+ _glfwInputMouseClick(window,
+ GLFW_MOUSE_BUTTON_RIGHT,
+ GLFW_PRESS,
+ translateFlags([event modifierFlags]));
+*/
}
-- (void)rightMouseDragged:(NSEvent *)event
-{
- [self mouseMoved:event];
+- (void)rightMouseDragged:(NSEvent *)event {
+ [self mouseMoved:event];
}
-- (void)rightMouseUp:(NSEvent *)event
-{
+- (void)rightMouseUp:(NSEvent *)event {
- button_mask&=~BUTTON_MASK_RIGHT;
+ button_mask &= ~BUTTON_MASK_RIGHT;
InputEvent ev;
- ev.type=InputEvent::MOUSE_BUTTON;
- ev.mouse_button.button_index=BUTTON_RIGHT;
- ev.mouse_button.pressed=false;
- ev.mouse_button.x=mouse_x;
- ev.mouse_button.y=mouse_y;
- ev.mouse_button.global_x=mouse_x;
- ev.mouse_button.global_y=mouse_y;
- ev.mouse_button.button_mask=button_mask;
+ ev.type = InputEvent::MOUSE_BUTTON;
+ ev.mouse_button.button_index = BUTTON_RIGHT;
+ ev.mouse_button.pressed = false;
+ ev.mouse_button.x = mouse_x;
+ ev.mouse_button.y = mouse_y;
+ ev.mouse_button.global_x = mouse_x;
+ ev.mouse_button.global_y = mouse_y;
+ ev.mouse_button.button_mask = button_mask;
ev.mouse_button.mod = translateFlags([event modifierFlags]);
OS_OSX::singleton->push_input(ev);
- /*_glfwInputMouseClick(window,
- GLFW_MOUSE_BUTTON_RIGHT,
- GLFW_RELEASE,
- translateFlags([event modifierFlags]));*/
+/*
+ _glfwInputMouseClick(window,
+ GLFW_MOUSE_BUTTON_RIGHT,
+ GLFW_RELEASE,
+ translateFlags([event modifierFlags]));
+*/
}
-- (void)otherMouseDown:(NSEvent *)event
-{
+- (void)otherMouseDown:(NSEvent *)event {
if ((int) [event buttonNumber]!=2)
return;
- button_mask|=BUTTON_MASK_MIDDLE;
+ button_mask |= BUTTON_MASK_MIDDLE;
InputEvent ev;
ev.type=InputEvent::MOUSE_BUTTON;
- ev.mouse_button.button_index=BUTTON_MIDDLE;
- ev.mouse_button.pressed=true;
- ev.mouse_button.x=mouse_x;
- ev.mouse_button.y=mouse_y;
- ev.mouse_button.global_x=mouse_x;
- ev.mouse_button.global_y=mouse_y;
- ev.mouse_button.button_mask=button_mask;
+ ev.mouse_button.button_index = BUTTON_MIDDLE;
+ ev.mouse_button.pressed = true;
+ ev.mouse_button.x = mouse_x;
+ ev.mouse_button.y = mouse_y;
+ ev.mouse_button.global_x = mouse_x;
+ ev.mouse_button.global_y = mouse_y;
+ ev.mouse_button.button_mask = button_mask;
ev.mouse_button.mod = translateFlags([event modifierFlags]);
OS_OSX::singleton->push_input(ev);
- /*_glfwInputMouseClick(window,
- (int) [event buttonNumber],
- GLFW_PRESS,
- translateFlags([event modifierFlags]));*/
+/*
+ _glfwInputMouseClick(window,
+ (int) [event buttonNumber],
+ GLFW_PRESS,
+ translateFlags([event modifierFlags]));
+*/
}
-- (void)otherMouseDragged:(NSEvent *)event
-{
- [self mouseMoved:event];
+- (void)otherMouseDragged:(NSEvent *)event {
+ [self mouseMoved:event];
}
-- (void)otherMouseUp:(NSEvent *)event
-{
+- (void)otherMouseUp:(NSEvent *)event {
if ((int) [event buttonNumber]!=2)
return;
- button_mask&=~BUTTON_MASK_MIDDLE;
+ button_mask &= ~BUTTON_MASK_MIDDLE;
InputEvent ev;
- ev.type=InputEvent::MOUSE_BUTTON;
- ev.mouse_button.button_index=BUTTON_MIDDLE;
- ev.mouse_button.pressed=false;
- ev.mouse_button.x=mouse_x;
- ev.mouse_button.y=mouse_y;
- ev.mouse_button.global_x=mouse_x;
- ev.mouse_button.global_y=mouse_y;
- ev.mouse_button.button_mask=button_mask;
+ ev.type = InputEvent::MOUSE_BUTTON;
+ ev.mouse_button.button_index = BUTTON_MIDDLE;
+ ev.mouse_button.pressed = false;
+ ev.mouse_button.x = mouse_x;
+ ev.mouse_button.y = mouse_y;
+ ev.mouse_button.global_x = mouse_x;
+ ev.mouse_button.global_y = mouse_y;
+ ev.mouse_button.button_mask = button_mask;
ev.mouse_button.mod = translateFlags([event modifierFlags]);
OS_OSX::singleton->push_input(ev);
- /* _glfwInputMouseClick(window,
- (int) [event buttonNumber],
- GLFW_RELEASE,
- translateFlags([event modifierFlags]));*/
+
+/*
+ _glfwInputMouseClick(window,
+ (int) [event buttonNumber],
+ GLFW_RELEASE,
+ translateFlags([event modifierFlags]));
+*/
}
-- (void)mouseExited:(NSEvent *)event
-{
+- (void)mouseExited:(NSEvent *)event {
if (!OS_OSX::singleton)
return;
@@ -562,12 +535,11 @@ static int button_mask=0;
OS_OSX::singleton->main_loop->notification(MainLoop::NOTIFICATION_WM_MOUSE_EXIT);
if (OS_OSX::singleton->input)
OS_OSX::singleton->input->set_mouse_in_window(false);
- // _glfwInputCursorEnter(window, GL_FALSE);
+ //_glfwInputCursorEnter(window, GL_FALSE);
}
-- (void)mouseEntered:(NSEvent *)event
-{
- // _glfwInputCursorEnter(window, GL_TRUE);
+- (void)mouseEntered:(NSEvent *)event {
+ //_glfwInputCursorEnter(window, GL_TRUE);
if (!OS_OSX::singleton)
return;
if (OS_OSX::singleton->main_loop && OS_OSX::singleton->mouse_mode!=OS::MOUSE_MODE_CAPTURED)
@@ -577,207 +549,199 @@ static int button_mask=0;
}
-- (void)viewDidChangeBackingProperties
-{
- /* const NSRect contentRect = [window->ns.view frame];
- const NSRect fbRect = convertRectToBacking(window, contentRect);
+- (void)viewDidChangeBackingProperties {
+/*
+ const NSRect contentRect = [window->ns.view frame];
+ const NSRect fbRect = convertRectToBacking(window, contentRect);
- _glfwInputFramebufferSize(window, fbRect.size.width, fbRect.size.height);*/
+ _glfwInputFramebufferSize(window, fbRect.size.width, fbRect.size.height);
+*/
}
-- (void)updateTrackingAreas
-{
- if (trackingArea != nil)
- {
- [self removeTrackingArea:trackingArea];
- [trackingArea release];
- }
+- (void)updateTrackingAreas {
+ if (trackingArea != nil) {
+ [self removeTrackingArea:trackingArea];
+ [trackingArea release];
+ }
- NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited |
- NSTrackingActiveInKeyWindow |
- NSTrackingCursorUpdate |
- NSTrackingInVisibleRect;
+ NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited |
+ NSTrackingActiveInKeyWindow |
+ NSTrackingCursorUpdate |
+ NSTrackingInVisibleRect;
- trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds]
- options:options
- owner:self
- userInfo:nil];
+ trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds]
+ options:options
+ owner:self
+ userInfo:nil];
- [self addTrackingArea:trackingArea];
- [super updateTrackingAreas];
+ [self addTrackingArea:trackingArea];
+ [super updateTrackingAreas];
}
// Translates a OS X keycode to a Godot keycode
//
-static int translateKey(unsigned int key)
-{
- // Keyboard symbol translation table
- static const unsigned int table[128] =
- {
- /* 00 */ KEY_A,
- /* 01 */ KEY_S,
- /* 02 */ KEY_D,
- /* 03 */ KEY_F,
- /* 04 */ KEY_H,
- /* 05 */ KEY_G,
- /* 06 */ KEY_Z,
- /* 07 */ KEY_X,
- /* 08 */ KEY_C,
- /* 09 */ KEY_V,
- /* 0a */ KEY_UNKNOWN,
- /* 0b */ KEY_B,
- /* 0c */ KEY_Q,
- /* 0d */ KEY_W,
- /* 0e */ KEY_E,
- /* 0f */ KEY_R,
- /* 10 */ KEY_Y,
- /* 11 */ KEY_T,
- /* 12 */ KEY_1,
- /* 13 */ KEY_2,
- /* 14 */ KEY_3,
- /* 15 */ KEY_4,
- /* 16 */ KEY_6,
- /* 17 */ KEY_5,
- /* 18 */ KEY_EQUAL,
- /* 19 */ KEY_9,
- /* 1a */ KEY_7,
- /* 1b */ KEY_MINUS,
- /* 1c */ KEY_8,
- /* 1d */ KEY_0,
- /* 1e */ KEY_BRACERIGHT,
- /* 1f */ KEY_O,
- /* 20 */ KEY_U,
- /* 21 */ KEY_BRACELEFT,
- /* 22 */ KEY_I,
- /* 23 */ KEY_P,
- /* 24 */ KEY_RETURN,
- /* 25 */ KEY_L,
- /* 26 */ KEY_J,
- /* 27 */ KEY_APOSTROPHE,
- /* 28 */ KEY_K,
- /* 29 */ KEY_SEMICOLON,
- /* 2a */ KEY_BACKSLASH,
- /* 2b */ KEY_COMMA,
- /* 2c */ KEY_SLASH,
- /* 2d */ KEY_N,
- /* 2e */ KEY_M,
- /* 2f */ KEY_PERIOD,
- /* 30 */ KEY_TAB,
- /* 31 */ KEY_SPACE,
- /* 32 */ KEY_QUOTELEFT,
- /* 33 */ KEY_BACKSPACE,
- /* 34 */ KEY_UNKNOWN,
- /* 35 */ KEY_ESCAPE,
- /* 36 */ KEY_META,
- /* 37 */ KEY_META,
- /* 38 */ KEY_SHIFT,
- /* 39 */ KEY_CAPSLOCK,
- /* 3a */ KEY_ALT,
- /* 3b */ KEY_CONTROL,
- /* 3c */ KEY_SHIFT,
- /* 3d */ KEY_ALT,
- /* 3e */ KEY_CONTROL,
- /* 3f */ KEY_UNKNOWN, /* Function */
- /* 40 */ KEY_UNKNOWN,
- /* 41 */ KEY_KP_PERIOD,
- /* 42 */ KEY_UNKNOWN,
- /* 43 */ KEY_KP_MULTIPLY,
- /* 44 */ KEY_UNKNOWN,
- /* 45 */ KEY_KP_ADD,
- /* 46 */ KEY_UNKNOWN,
- /* 47 */ KEY_NUMLOCK, /* Really KeypadClear... */
- /* 48 */ KEY_UNKNOWN, /* VolumeUp */
- /* 49 */ KEY_UNKNOWN, /* VolumeDown */
- /* 4a */ KEY_UNKNOWN, /* Mute */
- /* 4b */ KEY_KP_DIVIDE,
- /* 4c */ KEY_KP_ENTER,
- /* 4d */ KEY_UNKNOWN,
- /* 4e */ KEY_KP_SUBTRACT,
- /* 4f */ KEY_UNKNOWN,
- /* 50 */ KEY_UNKNOWN,
- /* 51 */ KEY_EQUAL, //wtf equal?
- /* 52 */ KEY_KP_0,
- /* 53 */ KEY_KP_1,
- /* 54 */ KEY_KP_2,
- /* 55 */ KEY_KP_3,
- /* 56 */ KEY_KP_4,
- /* 57 */ KEY_KP_5,
- /* 58 */ KEY_KP_6,
- /* 59 */ KEY_KP_7,
- /* 5a */ KEY_UNKNOWN,
- /* 5b */ KEY_KP_8,
- /* 5c */ KEY_KP_9,
- /* 5d */ KEY_UNKNOWN,
- /* 5e */ KEY_UNKNOWN,
- /* 5f */ KEY_UNKNOWN,
- /* 60 */ KEY_F5,
- /* 61 */ KEY_F6,
- /* 62 */ KEY_F7,
- /* 63 */ KEY_F3,
- /* 64 */ KEY_F8,
- /* 65 */ KEY_F9,
- /* 66 */ KEY_UNKNOWN,
- /* 67 */ KEY_F11,
- /* 68 */ KEY_UNKNOWN,
- /* 69 */ KEY_F13,
- /* 6a */ KEY_F16,
- /* 6b */ KEY_F14,
- /* 6c */ KEY_UNKNOWN,
- /* 6d */ KEY_F10,
- /* 6e */ KEY_UNKNOWN,
- /* 6f */ KEY_F12,
- /* 70 */ KEY_UNKNOWN,
- /* 71 */ KEY_F15,
- /* 72 */ KEY_INSERT, /* Really Help... */
- /* 73 */ KEY_HOME,
- /* 74 */ KEY_PAGEUP,
- /* 75 */ KEY_DELETE,
- /* 76 */ KEY_F4,
- /* 77 */ KEY_END,
- /* 78 */ KEY_F2,
- /* 79 */ KEY_PAGEDOWN,
- /* 7a */ KEY_F1,
- /* 7b */ KEY_LEFT,
- /* 7c */ KEY_RIGHT,
- /* 7d */ KEY_DOWN,
- /* 7e */ KEY_UP,
- /* 7f */ KEY_UNKNOWN,
- };
-
- if (key >= 128)
- return KEY_UNKNOWN;
-
- return table[key];
-}
-- (void)keyDown:(NSEvent *)event
-{
- InputEvent ev;
- ev.type=InputEvent::KEY;
- ev.key.pressed=true;
- ev.key.mod=translateFlags([event modifierFlags]);
- ev.key.scancode = latin_keyboard_keycode_convert(translateKey([event keyCode]));
- ev.key.echo = [event isARepeat];
-
- NSString* characters = [event characters];
- NSUInteger i, length = [characters length];
-
-
- if (length>0 && keycode_has_unicode(ev.key.scancode)) {
-
-
- for (i = 0; i < length; i++) {
- ev.key.unicode=[characters characterAtIndex:i];
+static int translateKey(unsigned int key) {
+ // Keyboard symbol translation table
+ static const unsigned int table[128] = {
+ /* 00 */ KEY_A,
+ /* 01 */ KEY_S,
+ /* 02 */ KEY_D,
+ /* 03 */ KEY_F,
+ /* 04 */ KEY_H,
+ /* 05 */ KEY_G,
+ /* 06 */ KEY_Z,
+ /* 07 */ KEY_X,
+ /* 08 */ KEY_C,
+ /* 09 */ KEY_V,
+ /* 0a */ KEY_UNKNOWN,
+ /* 0b */ KEY_B,
+ /* 0c */ KEY_Q,
+ /* 0d */ KEY_W,
+ /* 0e */ KEY_E,
+ /* 0f */ KEY_R,
+ /* 10 */ KEY_Y,
+ /* 11 */ KEY_T,
+ /* 12 */ KEY_1,
+ /* 13 */ KEY_2,
+ /* 14 */ KEY_3,
+ /* 15 */ KEY_4,
+ /* 16 */ KEY_6,
+ /* 17 */ KEY_5,
+ /* 18 */ KEY_EQUAL,
+ /* 19 */ KEY_9,
+ /* 1a */ KEY_7,
+ /* 1b */ KEY_MINUS,
+ /* 1c */ KEY_8,
+ /* 1d */ KEY_0,
+ /* 1e */ KEY_BRACERIGHT,
+ /* 1f */ KEY_O,
+ /* 20 */ KEY_U,
+ /* 21 */ KEY_BRACELEFT,
+ /* 22 */ KEY_I,
+ /* 23 */ KEY_P,
+ /* 24 */ KEY_RETURN,
+ /* 25 */ KEY_L,
+ /* 26 */ KEY_J,
+ /* 27 */ KEY_APOSTROPHE,
+ /* 28 */ KEY_K,
+ /* 29 */ KEY_SEMICOLON,
+ /* 2a */ KEY_BACKSLASH,
+ /* 2b */ KEY_COMMA,
+ /* 2c */ KEY_SLASH,
+ /* 2d */ KEY_N,
+ /* 2e */ KEY_M,
+ /* 2f */ KEY_PERIOD,
+ /* 30 */ KEY_TAB,
+ /* 31 */ KEY_SPACE,
+ /* 32 */ KEY_QUOTELEFT,
+ /* 33 */ KEY_BACKSPACE,
+ /* 34 */ KEY_UNKNOWN,
+ /* 35 */ KEY_ESCAPE,
+ /* 36 */ KEY_META,
+ /* 37 */ KEY_META,
+ /* 38 */ KEY_SHIFT,
+ /* 39 */ KEY_CAPSLOCK,
+ /* 3a */ KEY_ALT,
+ /* 3b */ KEY_CONTROL,
+ /* 3c */ KEY_SHIFT,
+ /* 3d */ KEY_ALT,
+ /* 3e */ KEY_CONTROL,
+ /* 3f */ KEY_UNKNOWN, /* Function */
+ /* 40 */ KEY_UNKNOWN,
+ /* 41 */ KEY_KP_PERIOD,
+ /* 42 */ KEY_UNKNOWN,
+ /* 43 */ KEY_KP_MULTIPLY,
+ /* 44 */ KEY_UNKNOWN,
+ /* 45 */ KEY_KP_ADD,
+ /* 46 */ KEY_UNKNOWN,
+ /* 47 */ KEY_NUMLOCK, /* Really KeypadClear... */
+ /* 48 */ KEY_UNKNOWN, /* VolumeUp */
+ /* 49 */ KEY_UNKNOWN, /* VolumeDown */
+ /* 4a */ KEY_UNKNOWN, /* Mute */
+ /* 4b */ KEY_KP_DIVIDE,
+ /* 4c */ KEY_KP_ENTER,
+ /* 4d */ KEY_UNKNOWN,
+ /* 4e */ KEY_KP_SUBTRACT,
+ /* 4f */ KEY_UNKNOWN,
+ /* 50 */ KEY_UNKNOWN,
+ /* 51 */ KEY_EQUAL, //wtf equal?
+ /* 52 */ KEY_KP_0,
+ /* 53 */ KEY_KP_1,
+ /* 54 */ KEY_KP_2,
+ /* 55 */ KEY_KP_3,
+ /* 56 */ KEY_KP_4,
+ /* 57 */ KEY_KP_5,
+ /* 58 */ KEY_KP_6,
+ /* 59 */ KEY_KP_7,
+ /* 5a */ KEY_UNKNOWN,
+ /* 5b */ KEY_KP_8,
+ /* 5c */ KEY_KP_9,
+ /* 5d */ KEY_UNKNOWN,
+ /* 5e */ KEY_UNKNOWN,
+ /* 5f */ KEY_UNKNOWN,
+ /* 60 */ KEY_F5,
+ /* 61 */ KEY_F6,
+ /* 62 */ KEY_F7,
+ /* 63 */ KEY_F3,
+ /* 64 */ KEY_F8,
+ /* 65 */ KEY_F9,
+ /* 66 */ KEY_UNKNOWN,
+ /* 67 */ KEY_F11,
+ /* 68 */ KEY_UNKNOWN,
+ /* 69 */ KEY_F13,
+ /* 6a */ KEY_F16,
+ /* 6b */ KEY_F14,
+ /* 6c */ KEY_UNKNOWN,
+ /* 6d */ KEY_F10,
+ /* 6e */ KEY_UNKNOWN,
+ /* 6f */ KEY_F12,
+ /* 70 */ KEY_UNKNOWN,
+ /* 71 */ KEY_F15,
+ /* 72 */ KEY_INSERT, /* Really Help... */
+ /* 73 */ KEY_HOME,
+ /* 74 */ KEY_PAGEUP,
+ /* 75 */ KEY_DELETE,
+ /* 76 */ KEY_F4,
+ /* 77 */ KEY_END,
+ /* 78 */ KEY_F2,
+ /* 79 */ KEY_PAGEDOWN,
+ /* 7a */ KEY_F1,
+ /* 7b */ KEY_LEFT,
+ /* 7c */ KEY_RIGHT,
+ /* 7d */ KEY_DOWN,
+ /* 7e */ KEY_UP,
+ /* 7f */ KEY_UNKNOWN,
+ };
+
+ if (key >= 128)
+ return KEY_UNKNOWN;
+
+ return table[key];
+}
+
+- (void)keyDown:(NSEvent *)event {
+ InputEvent ev;
+ ev.type = InputEvent::KEY;
+ ev.key.pressed = true;
+ ev.key.mod = translateFlags([event modifierFlags]);
+ ev.key.scancode = latin_keyboard_keycode_convert(translateKey([event keyCode]));
+ ev.key.echo = [event isARepeat];
+
+ NSString* characters = [event characters];
+ NSUInteger i, length = [characters length];
+
+ if (length>0 && keycode_has_unicode(ev.key.scancode)) {
+ for (i = 0; i < length; i++) {
+ ev.key.unicode = [characters characterAtIndex:i];
+ OS_OSX::singleton->push_input(ev);
+ ev.key.scancode=0;
+ }
+ } else {
OS_OSX::singleton->push_input(ev);
- ev.key.scancode=0;
}
-
- } else {
- OS_OSX::singleton->push_input(ev);
- }
}
-- (void)flagsChanged:(NSEvent *)event
-{
+- (void)flagsChanged:(NSEvent *)event {
InputEvent ev;
int key = [event keyCode];
int mod = [event modifierFlags];
@@ -816,66 +780,62 @@ static int translateKey(unsigned int key)
return;
}
- ev.key.mod=translateFlags(mod);
+ ev.key.mod = translateFlags(mod);
ev.key.scancode = latin_keyboard_keycode_convert(translateKey(key));
OS_OSX::singleton->push_input(ev);
}
-- (void)keyUp:(NSEvent *)event
-{
+- (void)keyUp:(NSEvent *)event {
InputEvent ev;
- ev.type=InputEvent::KEY;
- ev.key.pressed=false;
- ev.key.mod=translateFlags([event modifierFlags]);
+ ev.type = InputEvent::KEY;
+ ev.key.pressed = false;
+ ev.key.mod = translateFlags([event modifierFlags]);
ev.key.scancode = latin_keyboard_keycode_convert(translateKey([event keyCode]));
OS_OSX::singleton->push_input(ev);
-
- /* const int key = translateKey([event keyCode]);
- const int mods = translateFlags([event modifierFlags]);
- _glfwInputKey(window, key, [event keyCode], GLFW_RELEASE, mods);*/
+ /*
+ const int key = translateKey([event keyCode]);
+ const int mods = translateFlags([event modifierFlags]);
+ _glfwInputKey(window, key, [event keyCode], GLFW_RELEASE, mods);
+*/
}
-- (void)scrollWheel:(NSEvent *)event
-{
-
- double deltaX, deltaY;
+- (void)scrollWheel:(NSEvent *)event {
+ double deltaX, deltaY;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
- if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6)
- {
- deltaX = [event scrollingDeltaX];
- deltaY = [event scrollingDeltaY];
-
- if ([event hasPreciseScrollingDeltas])
- {
- deltaX *= 0.1;
- deltaY *= 0.1;
+ if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) {
+ deltaX = [event scrollingDeltaX];
+ deltaY = [event scrollingDeltaY];
+
+ if ([event hasPreciseScrollingDeltas]) {
+ deltaX *= 0.1;
+ deltaY *= 0.1;
+ }
+ } else {
+ deltaX = [event deltaX];
+ deltaY = [event deltaY];
}
- }
- else
-#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/
- {
+#else
deltaX = [event deltaX];
deltaY = [event deltaY];
- }
-
+#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/
if (fabs(deltaY)) {
InputEvent ev;
ev.type=InputEvent::MOUSE_BUTTON;
- ev.mouse_button.button_index=deltaY >0 ? BUTTON_WHEEL_UP : BUTTON_WHEEL_DOWN;
- ev.mouse_button.pressed=true;
- ev.mouse_button.x=mouse_x;
- ev.mouse_button.y=mouse_y;
- ev.mouse_button.global_x=mouse_x;
- ev.mouse_button.global_y=mouse_y;
- ev.mouse_button.button_mask=button_mask;
+ ev.mouse_button.button_index = deltaY >0 ? BUTTON_WHEEL_UP : BUTTON_WHEEL_DOWN;
+ ev.mouse_button.pressed = true;
+ ev.mouse_button.x = mouse_x;
+ ev.mouse_button.y = mouse_y;
+ ev.mouse_button.global_x = mouse_x;
+ ev.mouse_button.global_y = mouse_y;
+ ev.mouse_button.button_mask = button_mask;
OS_OSX::singleton->push_input(ev);
- ev.mouse_button.pressed=false;
+ ev.mouse_button.pressed = false;
OS_OSX::singleton->push_input(ev);
}
@@ -883,15 +843,15 @@ static int translateKey(unsigned int key)
InputEvent ev;
ev.type=InputEvent::MOUSE_BUTTON;
- ev.mouse_button.button_index=deltaX < 0 ? BUTTON_WHEEL_RIGHT : BUTTON_WHEEL_LEFT;
- ev.mouse_button.pressed=true;
- ev.mouse_button.x=mouse_x;
- ev.mouse_button.y=mouse_y;
- ev.mouse_button.global_x=mouse_x;
- ev.mouse_button.global_y=mouse_y;
- ev.mouse_button.button_mask=button_mask;
+ ev.mouse_button.button_index = deltaX < 0 ? BUTTON_WHEEL_RIGHT : BUTTON_WHEEL_LEFT;
+ ev.mouse_button.pressed = true;
+ ev.mouse_button.x = mouse_x;
+ ev.mouse_button.y = mouse_y;
+ ev.mouse_button.global_x = mouse_x;
+ ev.mouse_button.global_y = mouse_y;
+ ev.mouse_button.button_mask = button_mask;
OS_OSX::singleton->push_input(ev);
- ev.mouse_button.pressed=false;
+ ev.mouse_button.pressed = false;
OS_OSX::singleton->push_input(ev);
}
}
@@ -904,19 +864,18 @@ static int translateKey(unsigned int key)
@implementation GodotWindow
-- (BOOL)canBecomeKeyWindow
-{
- // Required for NSBorderlessWindowMask windows
- return YES;
+- (BOOL)canBecomeKeyWindow {
+ // Required for NSBorderlessWindowMask windows
+ return YES;
}
@end
int OS_OSX::get_video_driver_count() const {
-
return 1;
}
+
const char * OS_OSX::get_video_driver_name(int p_driver) const {
return "GLES2";
@@ -925,10 +884,10 @@ const char * OS_OSX::get_video_driver_name(int p_driver) const {
OS::VideoMode OS_OSX::get_default_video_mode() const {
VideoMode vm;
- vm.width=1024;
- vm.height=600;
- vm.fullscreen=false;
- vm.resizable=true;
+ vm.width = 1024;
+ vm.height = 600;
+ vm.fullscreen = false;
+ vm.resizable = true;
return vm;
}
@@ -960,32 +919,32 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
// Register to be notified on keyboard layout changes
CFNotificationCenterAddObserver(CFNotificationCenterGetDistributedCenter(),
- NULL, keyboardLayoutChanged,
- kTISNotifySelectedKeyboardInputSourceChanged, NULL,
- CFNotificationSuspensionBehaviorDeliverImmediately);
+ NULL, keyboardLayoutChanged,
+ kTISNotifySelectedKeyboardInputSourceChanged, NULL,
+ CFNotificationSuspensionBehaviorDeliverImmediately);
if (is_hidpi_allowed() && [[NSScreen mainScreen] respondsToSelector:@selector(backingScaleFactor)]) {
- for (NSScreen *screen in [NSScreen screens]) {
- float s = [screen backingScaleFactor];
- if (s > display_scale) {
- display_scale=s;
- }
- }
+ for (NSScreen *screen in [NSScreen screens]) {
+ float s = [screen backingScaleFactor];
+ if (s > display_scale) {
+ display_scale = s;
+ }
+ }
}
window_delegate = [[GodotWindowDelegate alloc] init];
- // Don't use accumulation buffer support; it's not accelerated
- // Aux buffers probably aren't accelerated either
+ // Don't use accumulation buffer support; it's not accelerated
+ // Aux buffers probably aren't accelerated either
unsigned int styleMask = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | (p_desired.resizable?NSResizableWindowMask:0);
window_object = [[GodotWindow alloc]
- initWithContentRect:NSMakeRect(0, 0, p_desired.width/display_scale, p_desired.height/display_scale)
- styleMask:styleMask
- backing:NSBackingStoreBuffered
- defer:NO];
+ initWithContentRect:NSMakeRect(0, 0, p_desired.width/display_scale, p_desired.height/display_scale)
+ styleMask:styleMask
+ backing:NSBackingStoreBuffered
+ defer:NO];
ERR_FAIL_COND( window_object==nil );
@@ -995,8 +954,8 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
window_size.height = p_desired.height;
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6 && display_scale>1) {
- [window_view setWantsBestResolutionOpenGLSurface:YES];
- //if (current_videomode.resizable)
+ [window_view setWantsBestResolutionOpenGLSurface:YES];
+ //if (current_videomode.resizable)
[window_object setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
}
@@ -1031,21 +990,26 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
ADD_ATTR2(NSOpenGLPFAColorSize, colorBits);
- /* if (fbconfig->alphaBits > 0)
- ADD_ATTR2(NSOpenGLPFAAlphaSize, fbconfig->alphaBits);*/
+/*
+ if (fbconfig->alphaBits > 0)
+ ADD_ATTR2(NSOpenGLPFAAlphaSize, fbconfig->alphaBits);
+*/
ADD_ATTR2(NSOpenGLPFADepthSize, 24);
ADD_ATTR2(NSOpenGLPFAStencilSize, 8);
- /*if (fbconfig->stereo)
- ADD_ATTR(NSOpenGLPFAStereo);*/
+/*
+ if (fbconfig->stereo)
+ ADD_ATTR(NSOpenGLPFAStereo);
+*/
- /* if (fbconfig->samples > 0)
- {
- ADD_ATTR2(NSOpenGLPFASampleBuffers, 1);
- ADD_ATTR2(NSOpenGLPFASamples, fbconfig->samples);
- }*/
+/*
+ if (fbconfig->samples > 0) {
+ ADD_ATTR2(NSOpenGLPFASampleBuffers, 1);
+ ADD_ATTR2(NSOpenGLPFASamples, fbconfig->samples);
+ }
+*/
// NOTE: All NSOpenGLPixelFormats on the relevant cards support sRGB
// frambuffer, so there's no need (and no way) to request it
@@ -1059,12 +1023,10 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
ERR_FAIL_COND( pixelFormat == nil);
- context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat
- shareContext:nil];
+ context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
ERR_FAIL_COND(context==nil);
-
[context setView:window_view];
[context makeCurrentContext];
@@ -1083,7 +1045,6 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
bool use_gl2=p_video_driver!=1;
-
AudioDriverManager::add_driver(&audio_driver_osx);
// only opengl support here...
@@ -1095,11 +1056,11 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
visual_server = memnew( VisualServerRaster );
// FIXME: Reimplement threaded rendering? Or remove?
- /*
+/*
if (get_render_thread_mode()!=RENDER_THREAD_UNSAFE) {
visual_server =memnew(VisualServerWrapMT(visual_server,get_render_thread_mode()==RENDER_SEPARATE_THREAD));
}
- */
+*/
visual_server->init();
visual_server->cursor_set_visible(false, 0);
@@ -1126,7 +1087,7 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
NSArray *screenArray = [NSScreen screens];
printf("nscreen count %i\n", (int)[screenArray count]);
- for (int i=0; i<[screenArray count]; i++) {
+ for (int i = 0; i < [screenArray count]; i++) {
float displayScale = 1.0;
@@ -1143,7 +1104,7 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
NSDictionary *description = [[screenArray objectAtIndex: i] deviceDescription];
NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue];
CGSize displayPhysicalSize = CGDisplayScreenSize(
- [[description objectForKey:@"NSScreenNumber"] unsignedIntValue]);
+ [[description objectForKey:@"NSScreenNumber"] unsignedIntValue]);
//printf("width: %i pwidth %i rect width %i\n",int(displayPixelSize.width*displayScale),int(displayPhysicalSize.width*displayScale),int(nsrect.size.width));
int dpi = (displayPixelSize.width * 25.4f / displayPhysicalSize.width)*displayScale;
@@ -1153,6 +1114,7 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
};
restore_rect = Rect2(get_window_position(), get_window_size());
}
+
void OS_OSX::finalize() {
CFNotificationCenterRemoveObserver(CFNotificationCenterGetDistributedCenter(), NULL, kTISNotifySelectedKeyboardInputSourceChanged, NULL);
@@ -1173,7 +1135,6 @@ void OS_OSX::finalize() {
screens.clear();
-
}
void OS_OSX::set_main_loop( MainLoop * p_main_loop ) {
@@ -1245,9 +1206,11 @@ void OS_OSX::set_cursor_shape(CursorShape p_shape) {
void OS_OSX::set_mouse_show(bool p_show) {
}
+
void OS_OSX::set_mouse_grab(bool p_grab) {
}
+
bool OS_OSX::is_mouse_grab_enabled() const {
return mouse_grab;
@@ -1255,42 +1218,43 @@ bool OS_OSX::is_mouse_grab_enabled() const {
void OS_OSX::warp_mouse_pos(const Point2& p_to) {
- //copied from windows impl with osx native calls
- if (mouse_mode == MOUSE_MODE_CAPTURED){
- mouse_x = p_to.x;
- mouse_y = p_to.y;
- }
- else{ //set OS position
+ //copied from windows impl with osx native calls
+ if (mouse_mode == MOUSE_MODE_CAPTURED){
+ mouse_x = p_to.x;
+ mouse_y = p_to.y;
+ } else { //set OS position
- /* this code has not been tested, please be a kind soul and fix it if it fails! */
+ /* this code has not been tested, please be a kind soul and fix it if it fails! */
- //local point in window coords
- NSPoint localPoint = { p_to.x, p_to.y };
+ //local point in window coords
+ NSPoint localPoint = { p_to.x, p_to.y };
- NSPoint pointInWindow = [window_view convertPoint:localPoint toView:nil];
- NSRect pointInWindowRect;
- pointInWindowRect.origin = pointInWindow;
- NSPoint pointOnScreen = [[window_view window] convertRectToScreen:pointInWindowRect].origin;
+ NSPoint pointInWindow = [window_view convertPoint:localPoint toView:nil];
+ NSRect pointInWindowRect;
+ pointInWindowRect.origin = pointInWindow;
+ NSPoint pointOnScreen = [[window_view window] convertRectToScreen:pointInWindowRect].origin;
- //point in scren coords
- CGPoint lMouseWarpPos = { pointOnScreen.x, pointOnScreen.y};
+ //point in scren coords
+ CGPoint lMouseWarpPos = { pointOnScreen.x, pointOnScreen.y};
- //do the warping
- CGEventSourceRef lEventRef = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
- CGEventSourceSetLocalEventsSuppressionInterval(lEventRef, 0.0);
- CGAssociateMouseAndMouseCursorPosition(false);
- CGWarpMouseCursorPosition(lMouseWarpPos);
- CGAssociateMouseAndMouseCursorPosition(true);
- }
+ //do the warping
+ CGEventSourceRef lEventRef = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
+ CGEventSourceSetLocalEventsSuppressionInterval(lEventRef, 0.0);
+ CGAssociateMouseAndMouseCursorPosition(false);
+ CGWarpMouseCursorPosition(lMouseWarpPos);
+ CGAssociateMouseAndMouseCursorPosition(true);
+ }
}
Point2 OS_OSX::get_mouse_pos() const {
return Vector2(mouse_x,mouse_y);
}
+
int OS_OSX::get_mouse_button_state() const {
return button_mask;
}
+
void OS_OSX::set_window_title(const String& p_title) {
[window_object setTitle:[NSString stringWithUTF8String:p_title.utf8().get_data()]];
@@ -1302,16 +1266,16 @@ void OS_OSX::set_icon(const Image& p_icon) {
Image img=p_icon;
img.convert(Image::FORMAT_RGBA8);
NSBitmapImageRep *imgrep= [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes: NULL
- pixelsWide: p_icon.get_width()
- pixelsHigh: p_icon.get_height()
- bitsPerSample: 8
- samplesPerPixel: 4
- hasAlpha: YES
- isPlanar: NO
- colorSpaceName: NSDeviceRGBColorSpace
- bytesPerRow: p_icon.get_width()*4
- bitsPerPixel: 32] autorelease];
- ERR_FAIL_COND(imgrep==nil);
+ pixelsWide: p_icon.get_width()
+ pixelsHigh: p_icon.get_height()
+ bitsPerSample: 8
+ samplesPerPixel: 4
+ hasAlpha: YES
+ isPlanar: NO
+ colorSpaceName: NSDeviceRGBColorSpace
+ bytesPerRow: p_icon.get_width()*4
+ bitsPerPixel: 32] autorelease];
+ ERR_FAIL_COND(imgrep == nil);
uint8_t *pixels = [imgrep bitmapData];
int len = img.get_width()*img.get_height();
@@ -1319,7 +1283,7 @@ void OS_OSX::set_icon(const Image& p_icon) {
PoolVector<uint8_t>::Read r = data.read();
/* Premultiply the alpha channel */
- for (int i = 0; i<len ; i++) {
+ for (int i = 0; i < len ; i++) {
uint8_t alpha = r[i*4+3];
pixels[i*4+0] = (uint8_t)(((uint16_t)r[i*4+0] * alpha) / 255);
pixels[i*4+1] = (uint8_t)(((uint16_t)r[i*4+1] * alpha) / 255);
@@ -1355,18 +1319,17 @@ void OS_OSX::set_clipboard(const String& p_text) {
[pasteboard setString:[NSString stringWithUTF8String:p_text.utf8().get_data()]
forType:NSStringPboardType];
}
+
String OS_OSX::get_clipboard() const {
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
- if (![[pasteboard types] containsObject:NSStringPboardType])
- {
+ if (![[pasteboard types] containsObject:NSStringPboardType]) {
return "";
}
NSString* object = [pasteboard stringForType:NSStringPboardType];
- if (!object)
- {
+ if (!object) {
return "";
}
@@ -1383,6 +1346,7 @@ void OS_OSX::release_rendering_thread() {
[NSOpenGLContext clearCurrentContext];
}
+
void OS_OSX::make_rendering_thread() {
[context makeCurrentContext];
@@ -1396,7 +1360,7 @@ Error OS_OSX::shell_open(String p_uri) {
}
String OS_OSX::get_locale() const {
- NSString* preferredLang = [[NSLocale preferredLanguages] objectAtIndex:0];
+ NSString* preferredLang = [[NSLocale preferredLanguages] objectAtIndex:0];
return [preferredLang UTF8String];
}
@@ -1423,11 +1387,11 @@ OS::VideoMode OS_OSX::get_video_mode(int p_screen) const {
return vm;
}
+
void OS_OSX::get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen) const {
}
-
int OS_OSX::get_screen_count() const {
return screens.size();
@@ -1623,15 +1587,15 @@ static NSString *createStringForKeys(const CGKeyCode *keyCode, int length) {
UniCharCount realLength;
err = UCKeyTranslate(keyboardLayout,
- keyCode[i],
- kUCKeyActionDisplay,
- 0,
- LMGetKbdType(),
- kUCKeyTranslateNoDeadKeysBit,
- &keysDown,
- sizeof(chars) / sizeof(chars[0]),
- &realLength,
- chars);
+ keyCode[i],
+ kUCKeyActionDisplay,
+ 0,
+ LMGetKbdType(),
+ kUCKeyTranslateNoDeadKeysBit,
+ &keysDown,
+ sizeof(chars) / sizeof(chars[0]),
+ &realLength,
+ chars);
if (err != noErr) {
CFRelease(output);
@@ -1645,6 +1609,7 @@ static NSString *createStringForKeys(const CGKeyCode *keyCode, int length) {
return (NSString *)output;
}
+
OS::LatinKeyboardVariant OS_OSX::get_latin_keyboard_variant() const {
static LatinKeyboardVariant layout = LATIN_KEYBOARD_QWERTY;
@@ -1735,29 +1700,29 @@ void OS_OSX::run() {
void OS_OSX::set_mouse_mode(MouseMode p_mode) {
- if (p_mode==mouse_mode)
- return;
-
- if (p_mode==MOUSE_MODE_CAPTURED) {
- // Apple Docs state that the display parameter is not used.
- // "This parameter is not used. By default, you may pass kCGDirectMainDisplay."
- // https://developer.apple.com/library/mac/documentation/graphicsimaging/reference/Quartz_Services_Ref/Reference/reference.html
- CGDisplayHideCursor(kCGDirectMainDisplay);
- CGAssociateMouseAndMouseCursorPosition(false);
- } else if (p_mode==MOUSE_MODE_HIDDEN) {
- CGDisplayHideCursor(kCGDirectMainDisplay);
- CGAssociateMouseAndMouseCursorPosition(true);
- } else {
- CGDisplayShowCursor(kCGDirectMainDisplay);
- CGAssociateMouseAndMouseCursorPosition(true);
- }
+ if (p_mode==mouse_mode)
+ return;
+
+ if (p_mode==MOUSE_MODE_CAPTURED) {
+ // Apple Docs state that the display parameter is not used.
+ // "This parameter is not used. By default, you may pass kCGDirectMainDisplay."
+ // https://developer.apple.com/library/mac/documentation/graphicsimaging/reference/Quartz_Services_Ref/Reference/reference.html
+ CGDisplayHideCursor(kCGDirectMainDisplay);
+ CGAssociateMouseAndMouseCursorPosition(false);
+ } else if (p_mode==MOUSE_MODE_HIDDEN) {
+ CGDisplayHideCursor(kCGDirectMainDisplay);
+ CGAssociateMouseAndMouseCursorPosition(true);
+ } else {
+ CGDisplayShowCursor(kCGDirectMainDisplay);
+ CGAssociateMouseAndMouseCursorPosition(true);
+ }
- mouse_mode=p_mode;
+ mouse_mode=p_mode;
}
OS::MouseMode OS_OSX::get_mouse_mode() const {
- return mouse_mode;
+ return mouse_mode;
}
@@ -1792,12 +1757,12 @@ OS_OSX::OS_OSX() {
CGEventSourceSetLocalEventsSuppressionInterval(eventSource, 0.0);
- /*if (pthread_key_create(&_Godot.nsgl.current, NULL) != 0)
- {
- _GodotInputError(Godot_PLATFORM_ERROR,
- "NSGL: Failed to create context TLS");
- return GL_FALSE;
- }*/
+/*
+ if (pthread_key_create(&_Godot.nsgl.current, NULL) != 0) {
+ _GodotInputError(Godot_PLATFORM_ERROR, "NSGL: Failed to create context TLS");
+ return GL_FALSE;
+ }
+*/
framework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
ERR_FAIL_COND(!framework);
@@ -1808,12 +1773,12 @@ OS_OSX::OS_OSX() {
// In case we are unbundled, make us a proper UI application
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
- #if 0
+#if 0
// Menu bar setup must go between sharedApplication above and
// finishLaunching below, in order to properly emulate the behavior
// of NSApplicationMain
createMenuBar();
- #endif
+#endif
[NSApp finishLaunching];