2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* os_osx.mm */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:11:42 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2017-04-09 12:18:49 +00:00
|
|
|
#include "os_osx.h"
|
|
|
|
|
|
|
|
#include "dir_access_osx.h"
|
|
|
|
#include "drivers/gles3/rasterizer_gles3.h"
|
|
|
|
#include "main/main.h"
|
|
|
|
#include "os/keyboard.h"
|
|
|
|
#include "print_string.h"
|
|
|
|
#include "sem_osx.h"
|
|
|
|
#include "servers/physics/physics_server_sw.h"
|
|
|
|
#include "servers/visual/visual_server_raster.h"
|
2015-01-08 07:26:27 +00:00
|
|
|
|
|
|
|
#include <Carbon/Carbon.h>
|
2017-04-09 12:18:49 +00:00
|
|
|
#import <Cocoa/Cocoa.h>
|
2014-02-10 01:10:30 +00:00
|
|
|
#include <IOKit/IOCFPlugIn.h>
|
2017-04-09 12:18:49 +00:00
|
|
|
#include <IOKit/IOKitLib.h>
|
2014-02-10 01:10:30 +00:00
|
|
|
#include <IOKit/hid/IOHIDKeys.h>
|
2017-04-09 12:18:49 +00:00
|
|
|
#include <IOKit/hid/IOHIDLib.h>
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <libproc.h>
|
2014-02-10 01:10:30 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/stat.h>
|
2017-04-09 12:18:49 +00:00
|
|
|
#include <sys/types.h>
|
2014-02-10 01:10:30 +00:00
|
|
|
#include <unistd.h>
|
2017-04-09 12:18:49 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
//uses portions of glfw
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// GLFW 3.0 - www.glfw.org
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Copyright (c) 2002-2006 Marcus Geelnard
|
|
|
|
// Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
|
|
|
|
//
|
|
|
|
// This software is provided 'as-is', without any express or implied
|
|
|
|
// warranty. In no event will the authors be held liable for any damages
|
|
|
|
// arising from the use of this software.
|
|
|
|
//
|
|
|
|
// Permission is granted to anyone to use this software for any purpose,
|
|
|
|
// including commercial applications, and to alter it and redistribute it
|
|
|
|
// freely, subject to the following restrictions:
|
|
|
|
//
|
|
|
|
// 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
// claim that you wrote the original software. If you use this software
|
|
|
|
// in a product, an acknowledgment in the product documentation would
|
|
|
|
// be appreciated but is not required.
|
|
|
|
//
|
|
|
|
// 2. Altered source versions must be plainly marked as such, and must not
|
|
|
|
// be misrepresented as being the original software.
|
|
|
|
//
|
|
|
|
// 3. This notice may not be removed or altered from any source
|
|
|
|
// distribution.
|
|
|
|
//
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
static NSRect convertRectToBacking(NSRect contentRect) {
|
|
|
|
|
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
|
2017-04-09 12:18:49 +00:00
|
|
|
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6)
|
|
|
|
return [OS_OSX::singleton->window_view convertRectToBacking:contentRect];
|
|
|
|
else
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/
|
2017-04-09 12:18:49 +00:00
|
|
|
return contentRect;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
static InputModifierState translateFlags(NSUInteger flags) {
|
|
|
|
InputModifierState mod;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
mod.shift = (flags & NSShiftKeyMask);
|
|
|
|
mod.control = (flags & NSControlKeyMask);
|
|
|
|
mod.alt = (flags & NSAlternateKeyMask);
|
|
|
|
mod.meta = (flags & NSCommandKeyMask);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
return mod;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
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;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
@interface GodotApplication : NSApplication
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GodotApplication
|
|
|
|
|
|
|
|
// 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.
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)sendEvent:(NSEvent *)event {
|
|
|
|
if ([event type] == NSKeyUp && ([event modifierFlags] & NSCommandKeyMask))
|
|
|
|
[[self keyWindow] sendEvent:event];
|
|
|
|
else
|
|
|
|
[super sendEvent:event];
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface GodotApplicationDelegate : NSObject
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GodotApplicationDelegate
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
|
2016-06-04 15:35:00 +00:00
|
|
|
if (OS_OSX::singleton->get_main_loop())
|
|
|
|
OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_QUIT_REQUEST);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-06-04 15:35:00 +00:00
|
|
|
return NSTerminateCancel;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
- (void)applicationDidHide:(NSNotification *)notification {
|
|
|
|
/*
|
2017-01-14 11:26:56 +00:00
|
|
|
_Godotwindow* window;
|
|
|
|
for (window = _Godot.windowListHead; window; window = window->next)
|
|
|
|
_GodotInputWindowVisibility(window, GL_FALSE);
|
2017-04-09 11:22:40 +00:00
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)applicationDidUnhide:(NSNotification *)notification {
|
2017-04-09 12:18:49 +00:00
|
|
|
/*
|
2017-01-14 11:26:56 +00:00
|
|
|
_Godotwindow* window;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
for (window = _Godot.windowListHead; window; window = window->next) {
|
|
|
|
if ([window_object isVisible])
|
|
|
|
_GodotInputWindowVisibility(window, GL_TRUE);
|
2017-01-14 11:26:56 +00:00
|
|
|
}
|
2017-04-09 11:22:40 +00:00
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
- (void)applicationDidChangeScreenParameters:(NSNotification *)notification {
|
2017-01-14 11:26:56 +00:00
|
|
|
//_GodotInputMonitorChange();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
@interface GodotWindowDelegate : NSObject {
|
2017-01-14 11:26:56 +00:00
|
|
|
//_Godotwindow* window;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GodotWindowDelegate
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (BOOL)windowShouldClose:(id)sender {
|
2017-01-14 11:26:56 +00:00
|
|
|
//_GodotInputWindowCloseRequest(window);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (OS_OSX::singleton->get_main_loop())
|
|
|
|
OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_QUIT_REQUEST);
|
2017-04-09 11:22:40 +00:00
|
|
|
|
|
|
|
return NO;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)windowDidResize:(NSNotification *)notification {
|
|
|
|
[OS_OSX::singleton->context update];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
const NSRect contentRect = [OS_OSX::singleton->window_view frame];
|
2017-04-09 12:18:49 +00:00
|
|
|
const NSRect fbRect = contentRect; //convertRectToBacking(contentRect);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
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;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
/*
|
2017-01-14 11:26:56 +00:00
|
|
|
_GodotInputFramebufferSize(window, fbRect.size.width, fbRect.size.height);
|
|
|
|
_GodotInputWindowSize(window, contentRect.size.width, contentRect.size.height);
|
|
|
|
_GodotInputWindowDamage(window);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
if (window->cursorMode == Godot_CURSOR_DISABLED)
|
|
|
|
centerCursor(window);
|
2017-04-09 11:22:40 +00:00
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)windowDidMove:(NSNotification *)notification {
|
2017-04-09 12:18:49 +00:00
|
|
|
/*
|
2017-01-14 11:26:56 +00:00
|
|
|
[window->nsgl.context update];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
int x, y;
|
|
|
|
_GodotPlatformGetWindowPos(window, &x, &y);
|
|
|
|
_GodotInputWindowPos(window, x, y);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
if (window->cursorMode == Godot_CURSOR_DISABLED)
|
|
|
|
centerCursor(window);
|
2017-04-09 11:22:40 +00:00
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)windowDidBecomeKey:(NSNotification *)notification {
|
2017-01-14 11:26:56 +00:00
|
|
|
//_GodotInputWindowFocus(window, GL_TRUE);
|
|
|
|
//_GodotPlatformSetCursorMode(window, window->cursorMode);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (OS_OSX::singleton->get_main_loop())
|
|
|
|
OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
|
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)windowDidResignKey:(NSNotification *)notification {
|
2017-01-14 11:26:56 +00:00
|
|
|
//_GodotInputWindowFocus(window, GL_FALSE);
|
|
|
|
//_GodotPlatformSetCursorMode(window, Godot_CURSOR_NORMAL);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (OS_OSX::singleton->get_main_loop())
|
|
|
|
OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
|
|
|
|
}
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
- (void)windowDidMiniaturize:(NSNotification *)notification {
|
2015-04-02 04:32:02 +00:00
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
- (void)windowDidDeminiaturize:(NSNotification *)notification {
|
2015-04-02 04:32:02 +00:00
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
@end
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
@interface GodotContentView : NSView {
|
2017-04-09 12:18:49 +00:00
|
|
|
NSTrackingArea *trackingArea;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GodotContentView
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
+ (void)initialize {
|
|
|
|
if (self == [GodotContentView class]) {
|
2017-04-09 12:18:49 +00:00
|
|
|
/*
|
2017-04-09 11:22:40 +00:00
|
|
|
if (_glfw.ns.cursor == nil) {
|
2017-01-14 11:26:56 +00:00
|
|
|
NSImage* data = [[NSImage alloc] initWithSize:NSMakeSize(1, 1)];
|
|
|
|
_glfw.ns.cursor = [[NSCursor alloc] initWithImage:data
|
|
|
|
hotSpot:NSZeroPoint];
|
|
|
|
[data release];
|
|
|
|
}
|
2017-04-09 11:22:40 +00:00
|
|
|
*/
|
2017-01-14 11:26:56 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (id)init {
|
|
|
|
self = [super init];
|
|
|
|
trackingArea = nil;
|
|
|
|
[self updateTrackingAreas];
|
|
|
|
[self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
|
|
|
|
return self;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
- (void)dealloc {
|
2017-04-09 11:22:40 +00:00
|
|
|
[trackingArea release];
|
|
|
|
[super dealloc];
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
|
2017-04-09 11:22:40 +00:00
|
|
|
return NSDragOperationCopy;
|
2016-05-31 04:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender {
|
2017-04-09 11:22:40 +00:00
|
|
|
return NSDragOperationCopy;
|
2016-05-31 04:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
NSPasteboard *pboard = [sender draggingPasteboard];
|
|
|
|
NSArray *filenames = [pboard propertyListForType:NSFilenamesPboardType];
|
2016-05-31 04:27:48 +00:00
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
Vector<String> files;
|
2017-04-09 12:18:49 +00:00
|
|
|
for (int i = 0; i < filenames.count; i++) {
|
2017-04-09 11:22:40 +00:00
|
|
|
NSString *ns = [filenames objectAtIndex:i];
|
|
|
|
char *utfs = strdup([ns UTF8String]);
|
|
|
|
String ret;
|
|
|
|
ret.parse_utf8(utfs);
|
|
|
|
free(utfs);
|
|
|
|
files.push_back(ret);
|
|
|
|
}
|
2016-05-31 04:27:48 +00:00
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
if (files.size()) {
|
2017-04-09 12:18:49 +00:00
|
|
|
OS_OSX::singleton->main_loop->drop_files(files, 0);
|
2017-04-09 11:22:40 +00:00
|
|
|
OS_OSX::singleton->move_window_to_foreground();
|
|
|
|
}
|
2016-05-31 04:27:48 +00:00
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
return NO;
|
2016-05-31 04:27:48 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (BOOL)isOpaque {
|
|
|
|
return YES;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (BOOL)canBecomeKeyView {
|
|
|
|
return YES;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (BOOL)acceptsFirstResponder {
|
|
|
|
return YES;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)cursorUpdate:(NSEvent *)event {
|
|
|
|
//setModeCursor(window, window->cursorMode);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)mouseDown:(NSEvent *)event {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-30 03:28:29 +00:00
|
|
|
//print_line("mouse down:");
|
2017-04-09 11:22:40 +00:00
|
|
|
button_mask |= BUTTON_MASK_LEFT;
|
2014-02-10 01:10:30 +00:00
|
|
|
InputEvent ev;
|
2017-04-09 12:18:49 +00:00
|
|
|
ev.type = InputEvent::MOUSE_BUTTON;
|
2017-04-09 11:22:40 +00:00
|
|
|
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;
|
2017-04-09 12:18:49 +00:00
|
|
|
ev.mouse_button.doubleclick = [event clickCount] == 2;
|
2014-02-10 01:10:30 +00:00
|
|
|
ev.mouse_button.mod = translateFlags([event modifierFlags]);
|
|
|
|
OS_OSX::singleton->push_input(ev);
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
/*
|
2017-04-09 11:22:40 +00:00
|
|
|
_glfwInputMouseClick(window,
|
|
|
|
GLFW_MOUSE_BUTTON_LEFT,
|
|
|
|
GLFW_PRESS,
|
|
|
|
translateFlags([event modifierFlags]));
|
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)mouseDragged:(NSEvent *)event {
|
|
|
|
[self mouseMoved:event];
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)mouseUp:(NSEvent *)event {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
button_mask &= ~BUTTON_MASK_LEFT;
|
2014-02-10 01:10:30 +00:00
|
|
|
InputEvent ev;
|
2017-04-09 12:18:49 +00:00
|
|
|
ev.type = InputEvent::MOUSE_BUTTON;
|
2017-04-09 11:22:40 +00:00
|
|
|
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;
|
2014-02-10 01:10:30 +00:00
|
|
|
ev.mouse_button.mod = translateFlags([event modifierFlags]);
|
|
|
|
OS_OSX::singleton->push_input(ev);
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
/*
|
2017-04-09 11:22:40 +00:00
|
|
|
_glfwInputMouseClick(window,
|
|
|
|
GLFW_MOUSE_BUTTON_LEFT,
|
|
|
|
GLFW_RELEASE,
|
|
|
|
translateFlags([event modifierFlags]));
|
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)mouseMoved:(NSEvent *)event {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
InputEvent ev;
|
2017-04-09 11:22:40 +00:00
|
|
|
ev.type = InputEvent::MOUSE_MOTION;
|
|
|
|
ev.mouse_motion.button_mask = button_mask;
|
|
|
|
prev_mouse_x = mouse_x;
|
|
|
|
prev_mouse_y = mouse_y;
|
2014-02-10 01:10:30 +00:00
|
|
|
const NSRect contentRect = [OS_OSX::singleton->window_view frame];
|
|
|
|
const NSPoint p = [event locationInWindow];
|
2016-05-30 03:28:29 +00:00
|
|
|
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]);
|
2017-04-09 11:22:40 +00:00
|
|
|
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]);
|
2014-02-10 01:10:30 +00:00
|
|
|
ev.mouse_motion.mod = translateFlags([event modifierFlags]);
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
OS_OSX::singleton->input->set_mouse_pos(Point2(mouse_x, mouse_y));
|
2014-02-10 01:10:30 +00:00
|
|
|
OS_OSX::singleton->push_input(ev);
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
/*
|
2017-04-09 11:22:40 +00:00
|
|
|
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];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
_glfwInputCursorMotion(window, p.x, contentRect.size.height - p.y);
|
|
|
|
}
|
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)rightMouseDown:(NSEvent *)event {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
button_mask |= BUTTON_MASK_RIGHT;
|
2014-02-10 01:10:30 +00:00
|
|
|
InputEvent ev;
|
2017-04-09 12:18:49 +00:00
|
|
|
ev.type = InputEvent::MOUSE_BUTTON;
|
2017-04-09 11:22:40 +00:00
|
|
|
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;
|
2014-02-10 01:10:30 +00:00
|
|
|
ev.mouse_button.mod = translateFlags([event modifierFlags]);
|
|
|
|
OS_OSX::singleton->push_input(ev);
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
/*
|
2017-04-09 11:22:40 +00:00
|
|
|
_glfwInputMouseClick(window,
|
|
|
|
GLFW_MOUSE_BUTTON_RIGHT,
|
|
|
|
GLFW_PRESS,
|
|
|
|
translateFlags([event modifierFlags]));
|
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)rightMouseDragged:(NSEvent *)event {
|
|
|
|
[self mouseMoved:event];
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)rightMouseUp:(NSEvent *)event {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
button_mask &= ~BUTTON_MASK_RIGHT;
|
2014-02-10 01:10:30 +00:00
|
|
|
InputEvent ev;
|
2017-04-09 11:22:40 +00:00
|
|
|
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;
|
2014-02-10 01:10:30 +00:00
|
|
|
ev.mouse_button.mod = translateFlags([event modifierFlags]);
|
|
|
|
OS_OSX::singleton->push_input(ev);
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
/*
|
2017-04-09 11:22:40 +00:00
|
|
|
_glfwInputMouseClick(window,
|
|
|
|
GLFW_MOUSE_BUTTON_RIGHT,
|
|
|
|
GLFW_RELEASE,
|
|
|
|
translateFlags([event modifierFlags]));
|
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)otherMouseDown:(NSEvent *)event {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
if ((int)[event buttonNumber] != 2)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
button_mask |= BUTTON_MASK_MIDDLE;
|
2014-02-10 01:10:30 +00:00
|
|
|
InputEvent ev;
|
2017-04-09 12:18:49 +00:00
|
|
|
ev.type = InputEvent::MOUSE_BUTTON;
|
2017-04-09 11:22:40 +00:00
|
|
|
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;
|
2014-02-10 01:10:30 +00:00
|
|
|
ev.mouse_button.mod = translateFlags([event modifierFlags]);
|
|
|
|
OS_OSX::singleton->push_input(ev);
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
/*
|
2017-04-09 11:22:40 +00:00
|
|
|
_glfwInputMouseClick(window,
|
|
|
|
(int) [event buttonNumber],
|
|
|
|
GLFW_PRESS,
|
|
|
|
translateFlags([event modifierFlags]));
|
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)otherMouseDragged:(NSEvent *)event {
|
|
|
|
[self mouseMoved:event];
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)otherMouseUp:(NSEvent *)event {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
if ((int)[event buttonNumber] != 2)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
button_mask &= ~BUTTON_MASK_MIDDLE;
|
2014-02-10 01:10:30 +00:00
|
|
|
InputEvent ev;
|
2017-04-09 11:22:40 +00:00
|
|
|
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;
|
2014-02-10 01:10:30 +00:00
|
|
|
ev.mouse_button.mod = translateFlags([event modifierFlags]);
|
|
|
|
OS_OSX::singleton->push_input(ev);
|
2017-04-09 11:22:40 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
/*
|
2017-04-09 11:22:40 +00:00
|
|
|
_glfwInputMouseClick(window,
|
|
|
|
(int) [event buttonNumber],
|
|
|
|
GLFW_RELEASE,
|
|
|
|
translateFlags([event modifierFlags]));
|
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)mouseExited:(NSEvent *)event {
|
2015-09-24 21:06:15 +00:00
|
|
|
if (!OS_OSX::singleton)
|
|
|
|
return;
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
if (OS_OSX::singleton->main_loop && OS_OSX::singleton->mouse_mode != OS::MOUSE_MODE_CAPTURED)
|
2015-09-24 21:06:15 +00:00
|
|
|
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);
|
2017-04-09 11:22:40 +00:00
|
|
|
//_glfwInputCursorEnter(window, GL_FALSE);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)mouseEntered:(NSEvent *)event {
|
|
|
|
//_glfwInputCursorEnter(window, GL_TRUE);
|
2015-09-24 21:06:15 +00:00
|
|
|
if (!OS_OSX::singleton)
|
|
|
|
return;
|
2017-04-09 12:18:49 +00:00
|
|
|
if (OS_OSX::singleton->main_loop && OS_OSX::singleton->mouse_mode != OS::MOUSE_MODE_CAPTURED)
|
2015-09-24 21:06:15 +00:00
|
|
|
OS_OSX::singleton->main_loop->notification(MainLoop::NOTIFICATION_WM_MOUSE_ENTER);
|
|
|
|
if (OS_OSX::singleton->input)
|
|
|
|
OS_OSX::singleton->input->set_mouse_in_window(true);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)viewDidChangeBackingProperties {
|
2017-04-09 12:18:49 +00:00
|
|
|
/*
|
2017-04-09 11:22:40 +00:00
|
|
|
const NSRect contentRect = [window->ns.view frame];
|
|
|
|
const NSRect fbRect = convertRectToBacking(window, contentRect);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
_glfwInputFramebufferSize(window, fbRect.size.width, fbRect.size.height);
|
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)updateTrackingAreas {
|
|
|
|
if (trackingArea != nil) {
|
|
|
|
[self removeTrackingArea:trackingArea];
|
|
|
|
[trackingArea release];
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
NSTrackingAreaOptions options =
|
|
|
|
NSTrackingMouseEnteredAndExited |
|
|
|
|
NSTrackingActiveInKeyWindow |
|
|
|
|
NSTrackingCursorUpdate |
|
|
|
|
NSTrackingInVisibleRect;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
trackingArea = [[NSTrackingArea alloc]
|
|
|
|
initWithRect:[self bounds]
|
|
|
|
options:options
|
|
|
|
owner:self
|
|
|
|
userInfo:nil];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
[self addTrackingArea:trackingArea];
|
|
|
|
[super updateTrackingAreas];
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Translates a OS X keycode to a Godot keycode
|
|
|
|
//
|
2017-04-09 11:22:40 +00:00
|
|
|
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];
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
NSString *characters = [event characters];
|
2017-04-09 11:22:40 +00:00
|
|
|
NSUInteger i, length = [characters length];
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
if (length > 0 && keycode_has_unicode(ev.key.scancode)) {
|
|
|
|
for (i = 0; i < length; i++) {
|
2017-04-09 11:22:40 +00:00
|
|
|
ev.key.unicode = [characters characterAtIndex:i];
|
|
|
|
OS_OSX::singleton->push_input(ev);
|
2017-04-09 12:18:49 +00:00
|
|
|
ev.key.scancode = 0;
|
2017-04-09 11:22:40 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-02-10 01:10:30 +00:00
|
|
|
OS_OSX::singleton->push_input(ev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)flagsChanged:(NSEvent *)event {
|
2016-05-31 03:02:14 +00:00
|
|
|
InputEvent ev;
|
|
|
|
int key = [event keyCode];
|
|
|
|
int mod = [event modifierFlags];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
ev.type = InputEvent::KEY;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-31 03:02:14 +00:00
|
|
|
if (key == 0x36 || key == 0x37) {
|
|
|
|
if (mod & NSCommandKeyMask) {
|
2017-04-09 12:18:49 +00:00
|
|
|
mod &= ~NSCommandKeyMask;
|
2016-05-31 03:02:14 +00:00
|
|
|
ev.key.pressed = true;
|
|
|
|
} else {
|
|
|
|
ev.key.pressed = false;
|
|
|
|
}
|
|
|
|
} else if (key == 0x38 || key == 0x3c) {
|
|
|
|
if (mod & NSShiftKeyMask) {
|
2017-04-09 12:18:49 +00:00
|
|
|
mod &= ~NSShiftKeyMask;
|
2016-05-31 03:02:14 +00:00
|
|
|
ev.key.pressed = true;
|
|
|
|
} else {
|
|
|
|
ev.key.pressed = false;
|
|
|
|
}
|
|
|
|
} else if (key == 0x3a || key == 0x3d) {
|
|
|
|
if (mod & NSAlternateKeyMask) {
|
2017-04-09 12:18:49 +00:00
|
|
|
mod &= ~NSAlternateKeyMask;
|
2016-05-31 03:02:14 +00:00
|
|
|
ev.key.pressed = true;
|
|
|
|
} else {
|
|
|
|
ev.key.pressed = false;
|
|
|
|
}
|
|
|
|
} else if (key == 0x3b || key == 0x3e) {
|
|
|
|
if (mod & NSControlKeyMask) {
|
2017-04-09 12:18:49 +00:00
|
|
|
mod &= ~NSControlKeyMask;
|
2016-05-31 03:02:14 +00:00
|
|
|
ev.key.pressed = true;
|
|
|
|
} else {
|
|
|
|
ev.key.pressed = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
ev.key.mod = translateFlags(mod);
|
2016-05-31 03:02:14 +00:00
|
|
|
ev.key.scancode = latin_keyboard_keycode_convert(translateKey(key));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-31 03:02:14 +00:00
|
|
|
OS_OSX::singleton->push_input(ev);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)keyUp:(NSEvent *)event {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
InputEvent ev;
|
2017-04-09 11:22:40 +00:00
|
|
|
ev.type = InputEvent::KEY;
|
|
|
|
ev.key.pressed = false;
|
|
|
|
ev.key.mod = translateFlags([event modifierFlags]);
|
2015-01-05 01:39:21 +00:00
|
|
|
ev.key.scancode = latin_keyboard_keycode_convert(translateKey([event keyCode]));
|
2014-02-10 01:10:30 +00:00
|
|
|
OS_OSX::singleton->push_input(ev);
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
/*
|
2017-04-09 11:22:40 +00:00
|
|
|
const int key = translateKey([event keyCode]);
|
|
|
|
const int mods = translateFlags([event modifierFlags]);
|
|
|
|
_glfwInputKey(window, key, [event keyCode], GLFW_RELEASE, mods);
|
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (void)scrollWheel:(NSEvent *)event {
|
|
|
|
double deltaX, deltaY;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
|
2017-04-09 11:22:40 +00:00
|
|
|
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];
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-04-09 11:22:40 +00:00
|
|
|
#else
|
2014-02-10 01:10:30 +00:00
|
|
|
deltaX = [event deltaX];
|
|
|
|
deltaY = [event deltaY];
|
2017-04-09 11:22:40 +00:00
|
|
|
#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (fabs(deltaY)) {
|
|
|
|
|
|
|
|
InputEvent ev;
|
2017-04-09 12:18:49 +00:00
|
|
|
ev.type = InputEvent::MOUSE_BUTTON;
|
|
|
|
ev.mouse_button.button_index = deltaY > 0 ? BUTTON_WHEEL_UP : BUTTON_WHEEL_DOWN;
|
2017-04-09 11:22:40 +00:00
|
|
|
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;
|
2014-02-10 01:10:30 +00:00
|
|
|
OS_OSX::singleton->push_input(ev);
|
2017-04-09 11:22:40 +00:00
|
|
|
ev.mouse_button.pressed = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
OS_OSX::singleton->push_input(ev);
|
|
|
|
}
|
|
|
|
|
2016-02-04 16:16:22 +00:00
|
|
|
if (fabs(deltaX)) {
|
|
|
|
|
|
|
|
InputEvent ev;
|
2017-04-09 12:18:49 +00:00
|
|
|
ev.type = InputEvent::MOUSE_BUTTON;
|
2017-04-09 11:22:40 +00:00
|
|
|
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;
|
2016-02-04 16:16:22 +00:00
|
|
|
OS_OSX::singleton->push_input(ev);
|
2017-04-09 11:22:40 +00:00
|
|
|
ev.mouse_button.pressed = false;
|
2016-02-04 16:16:22 +00:00
|
|
|
OS_OSX::singleton->push_input(ev);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
@interface GodotWindow : NSWindow {
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GodotWindow
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
- (BOOL)canBecomeKeyWindow {
|
|
|
|
// Required for NSBorderlessWindowMask windows
|
|
|
|
return YES;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
int OS_OSX::get_video_driver_count() const {
|
|
|
|
return 1;
|
|
|
|
}
|
2017-04-09 11:22:40 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
const char *OS_OSX::get_video_driver_name(int p_driver) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return "GLES2";
|
|
|
|
}
|
|
|
|
|
|
|
|
OS::VideoMode OS_OSX::get_default_video_mode() const {
|
|
|
|
|
|
|
|
VideoMode vm;
|
2017-04-09 11:22:40 +00:00
|
|
|
vm.width = 1024;
|
|
|
|
vm.height = 600;
|
|
|
|
vm.fullscreen = false;
|
|
|
|
vm.resizable = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return vm;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS_OSX::initialize_core() {
|
|
|
|
|
|
|
|
OS_Unix::initialize_core();
|
2015-12-14 01:21:49 +00:00
|
|
|
|
|
|
|
DirAccess::make_default<DirAccessOSX>(DirAccess::ACCESS_RESOURCES);
|
|
|
|
DirAccess::make_default<DirAccessOSX>(DirAccess::ACCESS_USERDATA);
|
|
|
|
DirAccess::make_default<DirAccessOSX>(DirAccess::ACCESS_FILESYSTEM);
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
SemaphoreOSX::make_default();
|
|
|
|
}
|
|
|
|
|
2015-01-08 07:26:27 +00:00
|
|
|
static bool keyboard_layout_dirty = true;
|
|
|
|
static void keyboardLayoutChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
|
|
|
|
keyboard_layout_dirty = true;
|
|
|
|
}
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
void OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
/*** OSX INITIALIZATION ***/
|
|
|
|
/*** OSX INITIALIZATION ***/
|
|
|
|
/*** OSX INITIALIZATION ***/
|
2015-01-08 07:26:27 +00:00
|
|
|
|
|
|
|
keyboard_layout_dirty = true;
|
|
|
|
|
|
|
|
// Register to be notified on keyboard layout changes
|
|
|
|
CFNotificationCenterAddObserver(CFNotificationCenterGetDistributedCenter(),
|
2017-04-09 12:18:49 +00:00
|
|
|
NULL, keyboardLayoutChanged,
|
|
|
|
kTISNotifySelectedKeyboardInputSourceChanged, NULL,
|
|
|
|
CFNotificationSuspensionBehaviorDeliverImmediately);
|
2016-04-02 18:26:12 +00:00
|
|
|
|
2016-05-30 03:28:29 +00:00
|
|
|
if (is_hidpi_allowed() && [[NSScreen mainScreen] respondsToSelector:@selector(backingScaleFactor)]) {
|
2017-04-09 11:22:40 +00:00
|
|
|
for (NSScreen *screen in [NSScreen screens]) {
|
|
|
|
float s = [screen backingScaleFactor];
|
|
|
|
if (s > display_scale) {
|
2017-04-09 12:18:49 +00:00
|
|
|
display_scale = s;
|
2017-04-09 11:22:40 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-30 03:28:29 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
window_delegate = [[GodotWindowDelegate alloc] init];
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
// Don't use accumulation buffer support; it's not accelerated
|
|
|
|
// Aux buffers probably aren't accelerated either
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
unsigned int styleMask = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | (p_desired.resizable ? NSResizableWindowMask : 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
window_object = [[GodotWindow alloc]
|
2017-04-09 12:18:49 +00:00
|
|
|
initWithContentRect:NSMakeRect(0, 0, p_desired.width / display_scale, p_desired.height / display_scale)
|
|
|
|
styleMask:styleMask
|
|
|
|
backing:NSBackingStoreBuffered
|
|
|
|
defer:NO];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
ERR_FAIL_COND(window_object == nil);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
window_view = [[GodotContentView alloc] init];
|
|
|
|
|
2016-05-30 03:28:29 +00:00
|
|
|
window_size.width = p_desired.width;
|
|
|
|
window_size.height = p_desired.height;
|
2014-02-19 03:48:38 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6 && display_scale > 1) {
|
2017-04-09 11:22:40 +00:00
|
|
|
[window_view setWantsBestResolutionOpenGLSurface:YES];
|
|
|
|
//if (current_videomode.resizable)
|
2014-02-10 01:10:30 +00:00
|
|
|
[window_object setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
|
|
|
|
}
|
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
//[window_object setTitle:[NSString stringWithUTF8String:"GodotEnginies"]];
|
2014-02-10 01:10:30 +00:00
|
|
|
[window_object setContentView:window_view];
|
|
|
|
[window_object setDelegate:window_delegate];
|
|
|
|
[window_object setAcceptsMouseMovedEvents:YES];
|
|
|
|
[window_object center];
|
|
|
|
|
|
|
|
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6)
|
|
|
|
[window_object setRestorable:NO];
|
|
|
|
|
|
|
|
unsigned int attributeCount = 0;
|
|
|
|
|
|
|
|
// OS X needs non-zero color size, so set resonable values
|
2015-04-01 15:39:54 +00:00
|
|
|
int colorBits = 32;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
// Fail if a robustness strategy was requested
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
#define ADD_ATTR(x) \
|
|
|
|
{ attributes[attributeCount++] = x; }
|
|
|
|
#define ADD_ATTR2(x, y) \
|
|
|
|
{ \
|
|
|
|
ADD_ATTR(x); \
|
|
|
|
ADD_ATTR(y); \
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
// Arbitrary array size here
|
|
|
|
NSOpenGLPixelFormatAttribute attributes[40];
|
|
|
|
|
|
|
|
ADD_ATTR(NSOpenGLPFADoubleBuffer);
|
|
|
|
ADD_ATTR(NSOpenGLPFAClosestPolicy);
|
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
//we now need OpenGL 3 or better, maybe even change this to 3_3Core ?
|
2017-01-04 12:58:20 +00:00
|
|
|
ADD_ATTR2(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ADD_ATTR2(NSOpenGLPFAColorSize, colorBits);
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
/*
|
2017-04-09 11:22:40 +00:00
|
|
|
if (fbconfig->alphaBits > 0)
|
|
|
|
ADD_ATTR2(NSOpenGLPFAAlphaSize, fbconfig->alphaBits);
|
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ADD_ATTR2(NSOpenGLPFADepthSize, 24);
|
|
|
|
|
|
|
|
ADD_ATTR2(NSOpenGLPFAStencilSize, 8);
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
/*
|
2017-04-09 11:22:40 +00:00
|
|
|
if (fbconfig->stereo)
|
|
|
|
ADD_ATTR(NSOpenGLPFAStereo);
|
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
/*
|
2017-04-09 11:22:40 +00:00
|
|
|
if (fbconfig->samples > 0) {
|
|
|
|
ADD_ATTR2(NSOpenGLPFASampleBuffers, 1);
|
|
|
|
ADD_ATTR2(NSOpenGLPFASamples, fbconfig->samples);
|
|
|
|
}
|
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
// NOTE: All NSOpenGLPixelFormats on the relevant cards support sRGB
|
|
|
|
// frambuffer, so there's no need (and no way) to request it
|
|
|
|
|
|
|
|
ADD_ATTR(0);
|
|
|
|
|
|
|
|
#undef ADD_ATTR
|
|
|
|
#undef ADD_ATTR2
|
|
|
|
|
|
|
|
pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
|
2017-04-09 12:18:49 +00:00
|
|
|
ERR_FAIL_COND(pixelFormat == nil);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
ERR_FAIL_COND(context == nil);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
[context setView:window_view];
|
|
|
|
|
|
|
|
[context makeCurrentContext];
|
|
|
|
|
|
|
|
[NSApp activateIgnoringOtherApps:YES];
|
|
|
|
|
2015-05-05 10:02:47 +00:00
|
|
|
[window_object makeKeyAndOrderFront:nil];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-05-05 10:02:47 +00:00
|
|
|
if (p_desired.fullscreen)
|
2015-05-06 10:53:55 +00:00
|
|
|
zoomed = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
/*** END OSX INITIALIZATION ***/
|
|
|
|
/*** END OSX INITIALIZATION ***/
|
|
|
|
/*** END OSX INITIALIZATION ***/
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
bool use_gl2 = p_video_driver != 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
AudioDriverManager::add_driver(&audio_driver_osx);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
// only opengl support here...
|
2017-01-04 10:56:56 +00:00
|
|
|
RasterizerGLES3::register_config();
|
|
|
|
RasterizerGLES3::make_current();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
//rasterizer = instance_RasterizerGLES2();
|
|
|
|
//visual_server = memnew( VisualServerRaster(rasterizer) );
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
visual_server = memnew(VisualServerRaster);
|
2017-01-04 10:56:56 +00:00
|
|
|
// FIXME: Reimplement threaded rendering? Or remove?
|
2017-04-09 12:18:49 +00:00
|
|
|
/*
|
2017-01-14 11:26:56 +00:00
|
|
|
if (get_render_thread_mode()!=RENDER_THREAD_UNSAFE) {
|
|
|
|
visual_server =memnew(VisualServerWrapMT(visual_server,get_render_thread_mode()==RENDER_SEPARATE_THREAD));
|
|
|
|
}
|
2017-04-09 11:22:40 +00:00
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
visual_server->init();
|
|
|
|
visual_server->cursor_set_visible(false, 0);
|
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
AudioDriverManager::get_driver(p_audio_driver)->set_singleton();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
if (AudioDriverManager::get_driver(p_audio_driver)->init() != OK) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ERR_PRINT("Initializing audio failed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2017-04-09 12:18:49 +00:00
|
|
|
physics_server = memnew(PhysicsServerSW);
|
2014-02-10 01:10:30 +00:00
|
|
|
physics_server->init();
|
2015-05-26 04:05:08 +00:00
|
|
|
//physics_2d_server = memnew( Physics2DServerSW );
|
|
|
|
physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>();
|
2014-02-10 01:10:30 +00:00
|
|
|
physics_2d_server->init();
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
input = memnew(InputDefault);
|
|
|
|
joypad_osx = memnew(JoypadOSX);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
power_manager = memnew(power_osx);
|
2016-07-23 11:15:55 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
_ensure_data_dir();
|
|
|
|
|
2015-04-02 04:32:02 +00:00
|
|
|
NSArray *screenArray = [NSScreen screens];
|
|
|
|
printf("nscreen count %i\n", (int)[screenArray count]);
|
2017-04-09 11:22:40 +00:00
|
|
|
for (int i = 0; i < [screenArray count]; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-30 03:28:29 +00:00
|
|
|
float displayScale = 1.0;
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
if (display_scale > 1.0 && [[screenArray objectAtIndex:i] respondsToSelector:@selector(backingScaleFactor)]) {
|
|
|
|
displayScale = [[screenArray objectAtIndex:i] backingScaleFactor];
|
2016-05-30 03:28:29 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
NSRect nsrect = [[screenArray objectAtIndex:i] visibleFrame];
|
2016-05-30 03:28:29 +00:00
|
|
|
Rect2 rect = Rect2(nsrect.origin.x, nsrect.origin.y, nsrect.size.width, nsrect.size.height);
|
2017-04-09 12:18:49 +00:00
|
|
|
rect.pos *= displayScale;
|
|
|
|
rect.size *= displayScale;
|
2016-05-30 03:28:29 +00:00
|
|
|
screens.push_back(rect);
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
NSDictionary *description = [[screenArray objectAtIndex:i] deviceDescription];
|
2016-05-30 03:28:29 +00:00
|
|
|
NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue];
|
|
|
|
CGSize displayPhysicalSize = CGDisplayScreenSize(
|
2017-04-09 12:18:49 +00:00
|
|
|
[[description objectForKey:@"NSScreenNumber"] unsignedIntValue]);
|
2016-05-30 03:28:29 +00:00
|
|
|
|
|
|
|
//printf("width: %i pwidth %i rect width %i\n",int(displayPixelSize.width*displayScale),int(displayPhysicalSize.width*displayScale),int(nsrect.size.width));
|
2017-04-09 12:18:49 +00:00
|
|
|
int dpi = (displayPixelSize.width * 25.4f / displayPhysicalSize.width) * displayScale;
|
2016-05-30 03:28:29 +00:00
|
|
|
|
|
|
|
screen_dpi.push_back(dpi);
|
2015-04-02 04:32:02 +00:00
|
|
|
};
|
|
|
|
restore_rect = Rect2(get_window_position(), get_window_size());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-04-09 11:22:40 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void OS_OSX::finalize() {
|
|
|
|
|
2015-01-08 07:26:27 +00:00
|
|
|
CFNotificationCenterRemoveObserver(CFNotificationCenterGetDistributedCenter(), NULL, kTISNotifySelectedKeyboardInputSourceChanged, NULL);
|
2015-12-31 13:25:21 +00:00
|
|
|
delete_main_loop();
|
|
|
|
|
2017-01-08 20:29:57 +00:00
|
|
|
memdelete(joypad_osx);
|
2015-12-31 13:25:21 +00:00
|
|
|
memdelete(input);
|
|
|
|
|
|
|
|
visual_server->finish();
|
|
|
|
memdelete(visual_server);
|
2017-01-14 11:26:56 +00:00
|
|
|
//memdelete(rasterizer);
|
2015-12-31 13:25:21 +00:00
|
|
|
|
|
|
|
physics_server->finish();
|
|
|
|
memdelete(physics_server);
|
|
|
|
|
|
|
|
physics_2d_server->finish();
|
|
|
|
memdelete(physics_2d_server);
|
|
|
|
|
|
|
|
screens.clear();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
void OS_OSX::set_main_loop(MainLoop *p_main_loop) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
main_loop = p_main_loop;
|
2014-02-10 01:10:30 +00:00
|
|
|
input->set_main_loop(p_main_loop);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS_OSX::delete_main_loop() {
|
|
|
|
|
2015-12-31 13:25:21 +00:00
|
|
|
if (!main_loop)
|
|
|
|
return;
|
2014-02-10 01:10:30 +00:00
|
|
|
memdelete(main_loop);
|
2017-04-09 12:18:49 +00:00
|
|
|
main_loop = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String OS_OSX::get_name() {
|
|
|
|
|
|
|
|
return "OSX";
|
|
|
|
}
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
void OS_OSX::alert(const String &p_alert, const String &p_title) {
|
2016-06-22 15:58:31 +00:00
|
|
|
// Set OS X-compliant variables
|
|
|
|
NSAlert *window = [[NSAlert alloc] init];
|
|
|
|
NSString *ns_title = [NSString stringWithUTF8String:p_title.utf8().get_data()];
|
|
|
|
NSString *ns_alert = [NSString stringWithUTF8String:p_alert.utf8().get_data()];
|
|
|
|
|
|
|
|
[window addButtonWithTitle:@"OK"];
|
|
|
|
[window setMessageText:ns_title];
|
|
|
|
[window setInformativeText:ns_alert];
|
|
|
|
[window setAlertStyle:NSWarningAlertStyle];
|
|
|
|
|
|
|
|
// Display it, then release
|
|
|
|
[window runModal];
|
|
|
|
[window release];
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void OS_OSX::set_cursor_shape(CursorShape p_shape) {
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
if (cursor_shape == p_shape)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
switch (p_shape) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case CURSOR_ARROW: [[NSCursor arrowCursor] set]; break;
|
|
|
|
case CURSOR_IBEAM: [[NSCursor IBeamCursor] set]; break;
|
|
|
|
case CURSOR_POINTING_HAND: [[NSCursor pointingHandCursor] set]; break;
|
|
|
|
case CURSOR_CROSS: [[NSCursor crosshairCursor] set]; break;
|
|
|
|
case CURSOR_WAIT: [[NSCursor arrowCursor] set]; break;
|
|
|
|
case CURSOR_BUSY: [[NSCursor arrowCursor] set]; break;
|
|
|
|
case CURSOR_DRAG: [[NSCursor closedHandCursor] set]; break;
|
|
|
|
case CURSOR_CAN_DROP: [[NSCursor openHandCursor] set]; break;
|
|
|
|
case CURSOR_FORBIDDEN: [[NSCursor arrowCursor] set]; break;
|
|
|
|
case CURSOR_VSIZE: [[NSCursor resizeUpDownCursor] set]; break;
|
|
|
|
case CURSOR_HSIZE: [[NSCursor resizeLeftRightCursor] set]; break;
|
|
|
|
case CURSOR_BDIAGSIZE: [[NSCursor arrowCursor] set]; break;
|
|
|
|
case CURSOR_FDIAGSIZE: [[NSCursor arrowCursor] set]; break;
|
|
|
|
case CURSOR_MOVE: [[NSCursor arrowCursor] set]; break;
|
|
|
|
case CURSOR_VSPLIT: [[NSCursor resizeUpDownCursor] set]; break;
|
|
|
|
case CURSOR_HSPLIT: [[NSCursor resizeLeftRightCursor] set]; break;
|
|
|
|
case CURSOR_HELP: [[NSCursor arrowCursor] set]; break;
|
|
|
|
default: {};
|
|
|
|
}
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
cursor_shape = p_shape;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OS_OSX::set_mouse_show(bool p_show) {
|
|
|
|
}
|
2017-04-09 11:22:40 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void OS_OSX::set_mouse_grab(bool p_grab) {
|
|
|
|
}
|
2017-04-09 11:22:40 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
bool OS_OSX::is_mouse_grab_enabled() const {
|
|
|
|
|
|
|
|
return mouse_grab;
|
|
|
|
}
|
2014-09-20 00:01:41 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
void OS_OSX::warp_mouse_pos(const Point2 &p_to) {
|
2014-09-20 00:01:41 +00:00
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
//copied from windows impl with osx native calls
|
2017-04-09 12:18:49 +00:00
|
|
|
if (mouse_mode == MOUSE_MODE_CAPTURED) {
|
2017-04-09 11:22:40 +00:00
|
|
|
mouse_x = p_to.x;
|
|
|
|
mouse_y = p_to.y;
|
|
|
|
} else { //set OS position
|
2016-04-02 18:26:12 +00:00
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
/* this code has not been tested, please be a kind soul and fix it if it fails! */
|
2015-02-14 22:22:06 +00:00
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
//local point in window coords
|
|
|
|
NSPoint localPoint = { p_to.x, p_to.y };
|
2015-02-14 22:22:06 +00:00
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
NSPoint pointInWindow = [window_view convertPoint:localPoint toView:nil];
|
|
|
|
NSRect pointInWindowRect;
|
|
|
|
pointInWindowRect.origin = pointInWindow;
|
|
|
|
NSPoint pointOnScreen = [[window_view window] convertRectToScreen:pointInWindowRect].origin;
|
2015-02-14 22:22:06 +00:00
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
//point in scren coords
|
2017-04-09 12:18:49 +00:00
|
|
|
CGPoint lMouseWarpPos = { pointOnScreen.x, pointOnScreen.y };
|
2015-02-14 22:22:06 +00:00
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
//do the warping
|
|
|
|
CGEventSourceRef lEventRef = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
|
|
|
|
CGEventSourceSetLocalEventsSuppressionInterval(lEventRef, 0.0);
|
|
|
|
CGAssociateMouseAndMouseCursorPosition(false);
|
|
|
|
CGWarpMouseCursorPosition(lMouseWarpPos);
|
|
|
|
CGAssociateMouseAndMouseCursorPosition(true);
|
|
|
|
}
|
2014-09-20 00:01:41 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Point2 OS_OSX::get_mouse_pos() const {
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
return Vector2(mouse_x, mouse_y);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-04-09 11:22:40 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
int OS_OSX::get_mouse_button_state() const {
|
|
|
|
return button_mask;
|
|
|
|
}
|
2017-04-09 11:22:40 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
void OS_OSX::set_window_title(const String &p_title) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
[window_object setTitle:[NSString stringWithUTF8String:p_title.utf8().get_data()]];
|
|
|
|
}
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
void OS_OSX::set_icon(const Image &p_icon) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
Image img = p_icon;
|
2016-10-03 19:33:42 +00:00
|
|
|
img.convert(Image::FORMAT_RGBA8);
|
2017-04-09 12:18:49 +00:00
|
|
|
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];
|
2017-04-09 11:22:40 +00:00
|
|
|
ERR_FAIL_COND(imgrep == nil);
|
2014-02-10 01:10:30 +00:00
|
|
|
uint8_t *pixels = [imgrep bitmapData];
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
int len = img.get_width() * img.get_height();
|
2017-01-07 21:25:37 +00:00
|
|
|
PoolVector<uint8_t> data = img.get_data();
|
|
|
|
PoolVector<uint8_t>::Read r = data.read();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
/* Premultiply the alpha channel */
|
2017-04-09 12:18:49 +00:00
|
|
|
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);
|
|
|
|
pixels[i * 4 + 2] = (uint8_t)(((uint16_t)r[i * 4 + 2] * alpha) / 255);
|
|
|
|
pixels[i * 4 + 3] = alpha;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
NSImage *nsimg = [[[NSImage alloc] initWithSize:NSMakeSize(img.get_width(), img.get_height())] autorelease];
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_COND(nsimg == nil);
|
2017-04-09 12:18:49 +00:00
|
|
|
[nsimg addRepresentation:imgrep];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
[NSApp setApplicationIconImage:nsimg];
|
|
|
|
}
|
|
|
|
|
|
|
|
MainLoop *OS_OSX::get_main_loop() const {
|
|
|
|
|
|
|
|
return main_loop;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OS_OSX::can_draw() const {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
void OS_OSX::set_clipboard(const String &p_text) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
NSArray *types = [NSArray arrayWithObjects:NSStringPboardType, nil];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
|
2014-02-10 01:10:30 +00:00
|
|
|
[pasteboard declareTypes:types owner:nil];
|
|
|
|
[pasteboard setString:[NSString stringWithUTF8String:p_text.utf8().get_data()]
|
2017-04-09 12:18:49 +00:00
|
|
|
forType:NSStringPboardType];
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-04-09 11:22:40 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String OS_OSX::get_clipboard() const {
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
if (![[pasteboard types] containsObject:NSStringPboardType]) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
NSString *object = [pasteboard stringForType:NSStringPboardType];
|
2017-04-09 11:22:40 +00:00
|
|
|
if (!object) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
char *utfs = strdup([object UTF8String]);
|
|
|
|
String ret;
|
|
|
|
ret.parse_utf8(utfs);
|
|
|
|
free(utfs);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS_OSX::release_rendering_thread() {
|
|
|
|
|
|
|
|
[NSOpenGLContext clearCurrentContext];
|
|
|
|
}
|
2017-04-09 11:22:40 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void OS_OSX::make_rendering_thread() {
|
|
|
|
|
|
|
|
[context makeCurrentContext];
|
|
|
|
}
|
|
|
|
|
|
|
|
Error OS_OSX::shell_open(String p_uri) {
|
|
|
|
|
|
|
|
[[NSWorkspace sharedWorkspace] openURL:[[NSURL alloc] initWithString:[NSString stringWithUTF8String:p_uri.utf8().get_data()]]];
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2015-10-16 17:42:26 +00:00
|
|
|
String OS_OSX::get_locale() const {
|
2017-04-09 12:18:49 +00:00
|
|
|
NSString *preferredLang = [[NSLocale preferredLanguages] objectAtIndex:0];
|
2015-10-16 17:42:26 +00:00
|
|
|
return [preferredLang UTF8String];
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void OS_OSX::swap_buffers() {
|
|
|
|
|
|
|
|
[context flushBuffer];
|
|
|
|
}
|
|
|
|
|
2015-04-02 04:32:02 +00:00
|
|
|
void OS_OSX::wm_minimized(bool p_minimized) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-04-02 04:32:02 +00:00
|
|
|
minimized = p_minimized;
|
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
void OS_OSX::set_video_mode(const VideoMode &p_video_mode, int p_screen) {
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OS::VideoMode OS_OSX::get_video_mode(int p_screen) const {
|
|
|
|
|
2016-05-30 03:28:29 +00:00
|
|
|
VideoMode vm;
|
2017-04-09 12:18:49 +00:00
|
|
|
vm.width = window_size.width;
|
|
|
|
vm.height = window_size.height;
|
2016-05-30 03:28:29 +00:00
|
|
|
|
|
|
|
return vm;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-04-09 11:22:40 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
void OS_OSX::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2015-04-02 04:32:02 +00:00
|
|
|
int OS_OSX::get_screen_count() const {
|
|
|
|
|
|
|
|
return screens.size();
|
|
|
|
};
|
|
|
|
|
|
|
|
int OS_OSX::get_current_screen() const {
|
|
|
|
|
|
|
|
return current_screen;
|
|
|
|
};
|
|
|
|
|
|
|
|
void OS_OSX::set_current_screen(int p_screen) {
|
|
|
|
|
|
|
|
current_screen = p_screen;
|
|
|
|
};
|
|
|
|
|
2015-08-31 02:36:46 +00:00
|
|
|
Point2 OS_OSX::get_screen_position(int p_screen) const {
|
2015-04-02 04:32:02 +00:00
|
|
|
|
|
|
|
ERR_FAIL_INDEX_V(p_screen, screens.size(), Point2());
|
|
|
|
return screens[p_screen].pos;
|
|
|
|
};
|
|
|
|
|
2016-05-30 03:28:29 +00:00
|
|
|
int OS_OSX::get_screen_dpi(int p_screen) const {
|
|
|
|
|
|
|
|
ERR_FAIL_INDEX_V(p_screen, screens.size(), 72);
|
|
|
|
return screen_dpi[p_screen];
|
|
|
|
}
|
|
|
|
|
2016-05-11 14:44:10 +00:00
|
|
|
Size2 OS_OSX::get_screen_size(int p_screen) const {
|
2015-04-02 04:32:02 +00:00
|
|
|
|
|
|
|
ERR_FAIL_INDEX_V(p_screen, screens.size(), Point2());
|
|
|
|
return screens[p_screen].size;
|
|
|
|
};
|
|
|
|
|
|
|
|
Point2 OS_OSX::get_window_position() const {
|
|
|
|
|
2016-05-30 03:28:29 +00:00
|
|
|
Size2 wp([window_object frame].origin.x, [window_object frame].origin.y);
|
2017-04-09 12:18:49 +00:00
|
|
|
wp *= display_scale;
|
2016-06-04 15:35:00 +00:00
|
|
|
return wp;
|
2015-04-02 04:32:02 +00:00
|
|
|
};
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
void OS_OSX::set_window_position(const Point2 &p_position) {
|
2015-04-02 04:32:02 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
Point2 size = p_position;
|
|
|
|
size /= display_scale;
|
2016-05-30 03:28:29 +00:00
|
|
|
[window_object setFrame:NSMakeRect(size.x, size.y, [window_object frame].size.width, [window_object frame].size.height) display:YES];
|
2015-04-02 04:32:02 +00:00
|
|
|
};
|
|
|
|
|
2015-03-24 05:07:03 +00:00
|
|
|
Size2 OS_OSX::get_window_size() const {
|
2015-04-02 04:32:02 +00:00
|
|
|
|
2016-05-30 03:28:29 +00:00
|
|
|
return window_size;
|
2015-04-02 04:32:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void OS_OSX::set_window_size(const Size2 p_size) {
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
Size2 size = p_size;
|
2016-08-03 01:30:19 +00:00
|
|
|
|
|
|
|
// NSRect used by setFrame includes the title bar, so add it to our size.y
|
|
|
|
CGFloat menuBarHeight = [[[NSApplication sharedApplication] mainMenu] menuBarHeight];
|
|
|
|
if (menuBarHeight != 0.f) {
|
2017-04-09 12:18:49 +00:00
|
|
|
size.y += menuBarHeight;
|
2016-08-09 16:40:14 +00:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED <= 101104
|
2016-08-03 01:30:19 +00:00
|
|
|
} else {
|
2017-04-09 12:18:49 +00:00
|
|
|
size.y += [[NSStatusBar systemStatusBar] thickness];
|
2016-08-09 16:40:14 +00:00
|
|
|
#endif
|
2016-08-03 01:30:19 +00:00
|
|
|
}
|
2015-04-02 04:32:02 +00:00
|
|
|
NSRect frame = [window_object frame];
|
2016-05-30 03:28:29 +00:00
|
|
|
[window_object setFrame:NSMakeRect(frame.origin.x, frame.origin.y, size.x, size.y) display:YES];
|
2015-04-02 04:32:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void OS_OSX::set_window_fullscreen(bool p_enabled) {
|
|
|
|
|
2015-05-06 10:53:55 +00:00
|
|
|
if (zoomed != p_enabled) {
|
2015-05-05 10:02:47 +00:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
|
2015-05-06 10:53:55 +00:00
|
|
|
[window_object toggleFullScreen:nil];
|
2015-05-05 10:02:47 +00:00
|
|
|
#else
|
2015-05-06 10:53:55 +00:00
|
|
|
[window_object performZoom:nil];
|
2015-05-05 10:02:47 +00:00
|
|
|
#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/
|
2015-05-06 10:53:55 +00:00
|
|
|
}
|
2015-04-02 04:32:02 +00:00
|
|
|
zoomed = p_enabled;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool OS_OSX::is_window_fullscreen() const {
|
|
|
|
|
2015-05-05 10:02:47 +00:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
|
2017-04-09 12:18:49 +00:00
|
|
|
if ([window_object respondsToSelector:@selector(isZoomed)])
|
2015-04-02 04:32:02 +00:00
|
|
|
return [window_object isZoomed];
|
2015-05-05 10:02:47 +00:00
|
|
|
#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/
|
2015-04-02 04:32:02 +00:00
|
|
|
|
|
|
|
return zoomed;
|
|
|
|
};
|
|
|
|
|
|
|
|
void OS_OSX::set_window_resizable(bool p_enabled) {
|
|
|
|
|
|
|
|
if (p_enabled)
|
2017-04-09 12:18:49 +00:00
|
|
|
[window_object setStyleMask:[window_object styleMask] | NSResizableWindowMask];
|
2015-04-02 04:32:02 +00:00
|
|
|
else
|
2017-04-09 12:18:49 +00:00
|
|
|
[window_object setStyleMask:[window_object styleMask] & ~NSResizableWindowMask];
|
2015-04-02 04:32:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
bool OS_OSX::is_window_resizable() const {
|
|
|
|
|
|
|
|
return [window_object styleMask] & NSResizableWindowMask;
|
|
|
|
};
|
|
|
|
|
|
|
|
void OS_OSX::set_window_minimized(bool p_enabled) {
|
|
|
|
|
|
|
|
if (p_enabled)
|
|
|
|
[window_object performMiniaturize:nil];
|
|
|
|
else
|
|
|
|
[window_object deminiaturize:nil];
|
|
|
|
};
|
|
|
|
|
|
|
|
bool OS_OSX::is_window_minimized() const {
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
if ([window_object respondsToSelector:@selector(isMiniaturized)])
|
2015-04-02 04:32:02 +00:00
|
|
|
return [window_object isMiniaturized];
|
|
|
|
|
|
|
|
return minimized;
|
|
|
|
};
|
|
|
|
|
|
|
|
void OS_OSX::set_window_maximized(bool p_enabled) {
|
|
|
|
|
|
|
|
if (p_enabled) {
|
|
|
|
restore_rect = Rect2(get_window_position(), get_window_size());
|
|
|
|
[window_object setFrame:[[[NSScreen screens] objectAtIndex:current_screen] visibleFrame] display:YES];
|
|
|
|
} else {
|
|
|
|
set_window_size(restore_rect.size);
|
|
|
|
set_window_position(restore_rect.pos);
|
|
|
|
};
|
|
|
|
maximized = p_enabled;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool OS_OSX::is_window_maximized() const {
|
|
|
|
|
|
|
|
// don't know
|
|
|
|
return maximized;
|
|
|
|
};
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void OS_OSX::move_window_to_foreground() {
|
|
|
|
|
|
|
|
[window_object orderFrontRegardless];
|
|
|
|
}
|
|
|
|
|
2016-07-21 15:30:20 +00:00
|
|
|
void OS_OSX::request_attention() {
|
|
|
|
|
|
|
|
[NSApp requestUserAttention:NSCriticalRequest];
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String OS_OSX::get_executable_path() const {
|
|
|
|
|
|
|
|
int ret;
|
|
|
|
pid_t pid;
|
|
|
|
char pathbuf[PROC_PIDPATHINFO_MAXSIZE];
|
|
|
|
|
|
|
|
pid = getpid();
|
2017-04-09 12:18:49 +00:00
|
|
|
ret = proc_pidpath(pid, pathbuf, sizeof(pathbuf));
|
|
|
|
if (ret <= 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return OS::get_executable_path();
|
|
|
|
} else {
|
|
|
|
String path;
|
|
|
|
path.parse_utf8(pathbuf);
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-08 07:26:27 +00:00
|
|
|
// Returns string representation of keys, if they are printable.
|
|
|
|
//
|
|
|
|
static NSString *createStringForKeys(const CGKeyCode *keyCode, int length) {
|
|
|
|
|
|
|
|
TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource();
|
|
|
|
if (!currentKeyboard)
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
CFDataRef layoutData = (CFDataRef)TISGetInputSourceProperty(currentKeyboard, kTISPropertyUnicodeKeyLayoutData);
|
|
|
|
if (!layoutData)
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
const UCKeyboardLayout *keyboardLayout = (const UCKeyboardLayout *)CFDataGetBytePtr(layoutData);
|
|
|
|
|
|
|
|
OSStatus err;
|
|
|
|
CFMutableStringRef output = CFStringCreateMutable(NULL, 0);
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
for (int i = 0; i < length; ++i) {
|
2015-01-08 07:26:27 +00:00
|
|
|
|
|
|
|
UInt32 keysDown = 0;
|
|
|
|
UniChar chars[4];
|
|
|
|
UniCharCount realLength;
|
|
|
|
|
|
|
|
err = UCKeyTranslate(keyboardLayout,
|
2017-04-09 12:18:49 +00:00
|
|
|
keyCode[i],
|
|
|
|
kUCKeyActionDisplay,
|
|
|
|
0,
|
|
|
|
LMGetKbdType(),
|
|
|
|
kUCKeyTranslateNoDeadKeysBit,
|
|
|
|
&keysDown,
|
|
|
|
sizeof(chars) / sizeof(chars[0]),
|
|
|
|
&realLength,
|
|
|
|
chars);
|
2015-01-08 07:26:27 +00:00
|
|
|
|
|
|
|
if (err != noErr) {
|
|
|
|
CFRelease(output);
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2015-01-08 15:01:10 +00:00
|
|
|
CFStringAppendCharacters(output, chars, 1);
|
2015-01-08 07:26:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//CFStringUppercase(output, NULL);
|
|
|
|
|
|
|
|
return (NSString *)output;
|
|
|
|
}
|
2017-04-09 11:22:40 +00:00
|
|
|
|
2015-01-08 07:26:27 +00:00
|
|
|
OS::LatinKeyboardVariant OS_OSX::get_latin_keyboard_variant() const {
|
|
|
|
|
|
|
|
static LatinKeyboardVariant layout = LATIN_KEYBOARD_QWERTY;
|
|
|
|
|
|
|
|
if (keyboard_layout_dirty) {
|
|
|
|
|
|
|
|
layout = LATIN_KEYBOARD_QWERTY;
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
CGKeyCode keys[] = { kVK_ANSI_Q, kVK_ANSI_W, kVK_ANSI_E, kVK_ANSI_R, kVK_ANSI_T, kVK_ANSI_Y };
|
2015-01-08 07:26:27 +00:00
|
|
|
NSString *test = createStringForKeys(keys, 6);
|
|
|
|
|
|
|
|
if ([test isEqualToString:@"qwertz"]) {
|
|
|
|
layout = LATIN_KEYBOARD_QWERTZ;
|
|
|
|
} else if ([test isEqualToString:@"azerty"]) {
|
|
|
|
layout = LATIN_KEYBOARD_AZERTY;
|
|
|
|
} else if ([test isEqualToString:@"qzerty"]) {
|
|
|
|
layout = LATIN_KEYBOARD_QZERTY;
|
|
|
|
} else if ([test isEqualToString:@"',.pyf"]) {
|
|
|
|
layout = LATIN_KEYBOARD_DVORAK;
|
|
|
|
} else if ([test isEqualToString:@"xvlcwk"]) {
|
|
|
|
layout = LATIN_KEYBOARD_NEO;
|
|
|
|
}
|
|
|
|
|
|
|
|
[test release];
|
|
|
|
|
|
|
|
keyboard_layout_dirty = false;
|
|
|
|
return layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
return layout;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
void OS_OSX::process_events() {
|
|
|
|
|
|
|
|
while (true) {
|
2017-04-09 12:18:49 +00:00
|
|
|
NSEvent *event = [NSApp
|
|
|
|
nextEventMatchingMask:NSAnyEventMask
|
|
|
|
untilDate:[NSDate distantPast]
|
|
|
|
inMode:NSDefaultRunLoopMode
|
|
|
|
dequeue:YES];
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (event == nil)
|
|
|
|
break;
|
|
|
|
|
|
|
|
[NSApp sendEvent:event];
|
|
|
|
}
|
|
|
|
|
|
|
|
[autoreleasePool drain];
|
|
|
|
autoreleasePool = [[NSAutoreleasePool alloc] init];
|
|
|
|
}
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
void OS_OSX::push_input(const InputEvent &p_event) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
InputEvent ev = p_event;
|
2014-02-10 01:10:30 +00:00
|
|
|
//print_line("EV: "+String(ev));
|
|
|
|
input->parse_input_event(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS_OSX::run() {
|
|
|
|
|
|
|
|
force_quit = false;
|
|
|
|
|
|
|
|
if (!main_loop)
|
|
|
|
return;
|
|
|
|
|
|
|
|
main_loop->init();
|
|
|
|
|
2015-05-06 10:53:55 +00:00
|
|
|
if (zoomed) {
|
|
|
|
zoomed = false;
|
|
|
|
set_window_fullscreen(true);
|
|
|
|
}
|
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
//uint64_t last_ticks=get_ticks_usec();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
//int frames=0;
|
|
|
|
//uint64_t frame=0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
while (!force_quit) {
|
|
|
|
|
|
|
|
process_events(); // get rid of pending events
|
2017-03-26 13:59:13 +00:00
|
|
|
joypad_osx->process_joypads();
|
2017-04-09 12:18:49 +00:00
|
|
|
if (Main::iteration() == true)
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
main_loop->finish();
|
|
|
|
}
|
|
|
|
|
2014-06-26 12:14:37 +00:00
|
|
|
void OS_OSX::set_mouse_mode(MouseMode p_mode) {
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
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);
|
|
|
|
}
|
2014-06-26 12:14:37 +00:00
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
mouse_mode = p_mode;
|
2014-06-26 12:14:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OS::MouseMode OS_OSX::get_mouse_mode() const {
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
return mouse_mode;
|
2014-06-26 12:14:37 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-09-05 22:47:54 +00:00
|
|
|
String OS_OSX::get_joy_guid(int p_device) const {
|
|
|
|
return input->get_joy_guid_remapped(p_device);
|
|
|
|
}
|
|
|
|
|
2016-07-23 11:15:55 +00:00
|
|
|
PowerState OS_OSX::get_power_state() {
|
|
|
|
return power_manager->get_power_state();
|
|
|
|
}
|
|
|
|
|
|
|
|
int OS_OSX::get_power_seconds_left() {
|
|
|
|
return power_manager->get_power_seconds_left();
|
|
|
|
}
|
|
|
|
|
|
|
|
int OS_OSX::get_power_percent_left() {
|
|
|
|
return power_manager->get_power_percent_left();
|
|
|
|
}
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
OS_OSX *OS_OSX::singleton = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
OS_OSX::OS_OSX() {
|
2017-04-09 12:18:49 +00:00
|
|
|
|
|
|
|
mouse_mode = OS::MOUSE_MODE_VISIBLE;
|
|
|
|
main_loop = NULL;
|
|
|
|
singleton = this;
|
2014-02-10 01:10:30 +00:00
|
|
|
autoreleasePool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
|
|
|
eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
|
|
|
ERR_FAIL_COND(!eventSource);
|
|
|
|
|
|
|
|
CGEventSourceSetLocalEventsSuppressionInterval(eventSource, 0.0);
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
/*
|
2017-04-09 11:22:40 +00:00
|
|
|
if (pthread_key_create(&_Godot.nsgl.current, NULL) != 0) {
|
|
|
|
_GodotInputError(Godot_PLATFORM_ERROR, "NSGL: Failed to create context TLS");
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
framework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
|
|
|
|
ERR_FAIL_COND(!framework);
|
|
|
|
|
|
|
|
// Implicitly create shared NSApplication instance
|
|
|
|
[GodotApplication sharedApplication];
|
|
|
|
|
|
|
|
// In case we are unbundled, make us a proper UI application
|
|
|
|
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
|
|
|
|
2017-04-09 11:22:40 +00:00
|
|
|
#if 0
|
2014-02-10 01:10:30 +00:00
|
|
|
// Menu bar setup must go between sharedApplication above and
|
|
|
|
// finishLaunching below, in order to properly emulate the behavior
|
|
|
|
// of NSApplicationMain
|
|
|
|
createMenuBar();
|
2017-04-09 11:22:40 +00:00
|
|
|
#endif
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
[NSApp finishLaunching];
|
|
|
|
|
|
|
|
delegate = [[GodotApplicationDelegate alloc] init];
|
|
|
|
ERR_FAIL_COND(!delegate);
|
|
|
|
[NSApp setDelegate:delegate];
|
|
|
|
|
2017-04-09 12:18:49 +00:00
|
|
|
cursor_shape = CURSOR_ARROW;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-04-02 04:32:02 +00:00
|
|
|
current_screen = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-04-02 04:32:02 +00:00
|
|
|
maximized = false;
|
|
|
|
minimized = false;
|
2017-04-09 12:18:49 +00:00
|
|
|
window_size = Vector2(1024, 600);
|
2015-04-02 04:32:02 +00:00
|
|
|
zoomed = false;
|
2017-04-09 12:18:49 +00:00
|
|
|
display_scale = 1.0;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|