2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
2015-06-01 22:55:06 +02:00
|
|
|
// GLFW 3.2 OS X - www.glfw.org
|
2010-09-07 17:34:51 +02:00
|
|
|
//------------------------------------------------------------------------
|
2016-06-01 15:42:18 +02:00
|
|
|
// Copyright (c) 2009-2016 Camilla Berglund <elmindreda@elmindreda.org>
|
2010-09-07 17:34:51 +02:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
|
2016-03-16 15:05:50 +01:00
|
|
|
#include <float.h>
|
2014-09-09 16:26:57 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2012-02-15 01:44:55 +01:00
|
|
|
// Needed for _NSGetProgname
|
|
|
|
#include <crt_externs.h>
|
|
|
|
|
2010-09-16 03:05:55 +02:00
|
|
|
|
2014-09-02 16:52:16 +02:00
|
|
|
// Returns the specified standard cursor
|
|
|
|
//
|
|
|
|
static NSCursor* getStandardCursor(int shape)
|
|
|
|
{
|
|
|
|
switch (shape)
|
|
|
|
{
|
|
|
|
case GLFW_ARROW_CURSOR:
|
|
|
|
return [NSCursor arrowCursor];
|
|
|
|
case GLFW_IBEAM_CURSOR:
|
|
|
|
return [NSCursor IBeamCursor];
|
|
|
|
case GLFW_CROSSHAIR_CURSOR:
|
|
|
|
return [NSCursor crosshairCursor];
|
|
|
|
case GLFW_HAND_CURSOR:
|
|
|
|
return [NSCursor pointingHandCursor];
|
|
|
|
case GLFW_HRESIZE_CURSOR:
|
|
|
|
return [NSCursor resizeLeftRightCursor];
|
|
|
|
case GLFW_VRESIZE_CURSOR:
|
|
|
|
return [NSCursor resizeUpDownCursor];
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2016-02-23 12:26:42 +01:00
|
|
|
// Returns the style mask corresponding to the window settings
|
|
|
|
//
|
|
|
|
static NSUInteger getStyleMask(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
NSUInteger styleMask = 0;
|
|
|
|
|
|
|
|
if (window->monitor || !window->decorated)
|
|
|
|
styleMask |= NSBorderlessWindowMask;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
styleMask |= NSTitledWindowMask | NSClosableWindowMask |
|
|
|
|
NSMiniaturizableWindowMask;
|
|
|
|
|
|
|
|
if (window->resizable)
|
|
|
|
styleMask |= NSResizableWindowMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
return styleMask;
|
|
|
|
}
|
|
|
|
|
2013-09-19 01:05:51 +02:00
|
|
|
// Center the cursor in the view of the window
|
|
|
|
//
|
|
|
|
static void centerCursor(_GLFWwindow *window)
|
|
|
|
{
|
|
|
|
int width, height;
|
|
|
|
_glfwPlatformGetWindowSize(window, &width, &height);
|
|
|
|
_glfwPlatformSetCursorPos(window, width / 2.0, height / 2.0);
|
|
|
|
}
|
|
|
|
|
2016-05-30 21:21:09 +02:00
|
|
|
// Returns whether the cursor is in the client area of the specified window
|
2016-05-25 14:06:02 +02:00
|
|
|
//
|
2016-05-30 21:21:09 +02:00
|
|
|
static GLFWbool cursorInClientArea(_GLFWwindow* window)
|
2016-05-25 14:06:02 +02:00
|
|
|
{
|
2016-05-30 21:21:09 +02:00
|
|
|
const NSPoint pos = [window->ns.object mouseLocationOutsideOfEventStream];
|
|
|
|
return [window->ns.view mouse:pos inRect:[window->ns.view frame]];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Updates the cursor image according to its cursor mode
|
|
|
|
//
|
|
|
|
static void updateCursorImage(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
if (window->cursorMode == GLFW_CURSOR_NORMAL)
|
2016-05-25 14:06:02 +02:00
|
|
|
{
|
|
|
|
if (window->cursor)
|
|
|
|
[(NSCursor*) window->cursor->ns.object set];
|
|
|
|
else
|
|
|
|
[[NSCursor arrowCursor] set];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[(NSCursor*) _glfw.ns.cursor set];
|
|
|
|
}
|
|
|
|
|
2015-12-07 21:03:24 +01:00
|
|
|
// Transforms the specified y-coordinate between the CG display and NS screen
|
|
|
|
// coordinate systems
|
|
|
|
//
|
|
|
|
static float transformY(float y)
|
|
|
|
{
|
2015-12-07 21:17:03 +01:00
|
|
|
return CGDisplayBounds(CGMainDisplayID()).size.height - y;
|
2015-12-07 21:03:24 +01:00
|
|
|
}
|
|
|
|
|
2016-02-23 12:34:35 +01:00
|
|
|
// Make the specified window and its video mode active on its monitor
|
2013-05-02 18:16:23 +02:00
|
|
|
//
|
2016-02-23 12:34:35 +01:00
|
|
|
static GLFWbool acquireMonitor(_GLFWwindow* window)
|
2013-05-02 18:16:23 +02:00
|
|
|
{
|
2015-12-03 18:16:46 +01:00
|
|
|
const GLFWbool status = _glfwSetVideoModeNS(window->monitor, &window->videoMode);
|
2015-12-07 21:03:24 +01:00
|
|
|
const CGRect bounds = CGDisplayBounds(window->monitor->ns.displayID);
|
|
|
|
const NSRect frame = NSMakeRect(bounds.origin.x,
|
|
|
|
transformY(bounds.origin.y + bounds.size.height),
|
|
|
|
bounds.size.width,
|
|
|
|
bounds.size.height);
|
|
|
|
|
|
|
|
[window->ns.object setFrame:frame display:YES];
|
2016-02-23 12:34:35 +01:00
|
|
|
|
|
|
|
_glfwInputMonitorWindowChange(window->monitor, window);
|
2014-11-04 20:00:05 +01:00
|
|
|
return status;
|
2013-05-02 18:16:23 +02:00
|
|
|
}
|
|
|
|
|
2016-02-23 12:34:35 +01:00
|
|
|
// Remove the window and restore the original video mode
|
2013-05-02 18:16:23 +02:00
|
|
|
//
|
2016-02-23 12:34:35 +01:00
|
|
|
static void releaseMonitor(_GLFWwindow* window)
|
2013-05-02 18:16:23 +02:00
|
|
|
{
|
2016-02-23 12:34:35 +01:00
|
|
|
if (window->monitor->window != window)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_glfwInputMonitorWindowChange(window->monitor, NULL);
|
2015-12-03 18:16:46 +01:00
|
|
|
_glfwRestoreVideoModeNS(window->monitor);
|
2013-05-02 18:16:23 +02:00
|
|
|
}
|
|
|
|
|
2015-05-15 18:05:20 +02:00
|
|
|
// Translates OS X key modifiers into GLFW ones
|
|
|
|
//
|
|
|
|
static int translateFlags(NSUInteger flags)
|
|
|
|
{
|
|
|
|
int mods = 0;
|
|
|
|
|
|
|
|
if (flags & NSShiftKeyMask)
|
|
|
|
mods |= GLFW_MOD_SHIFT;
|
|
|
|
if (flags & NSControlKeyMask)
|
|
|
|
mods |= GLFW_MOD_CONTROL;
|
|
|
|
if (flags & NSAlternateKeyMask)
|
|
|
|
mods |= GLFW_MOD_ALT;
|
|
|
|
if (flags & NSCommandKeyMask)
|
|
|
|
mods |= GLFW_MOD_SUPER;
|
|
|
|
|
|
|
|
return mods;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Translates a OS X keycode to a GLFW keycode
|
|
|
|
//
|
|
|
|
static int translateKey(unsigned int key)
|
|
|
|
{
|
|
|
|
if (key >= sizeof(_glfw.ns.publicKeys) / sizeof(_glfw.ns.publicKeys[0]))
|
|
|
|
return GLFW_KEY_UNKNOWN;
|
|
|
|
|
|
|
|
return _glfw.ns.publicKeys[key];
|
|
|
|
}
|
|
|
|
|
2015-07-27 03:40:54 +02:00
|
|
|
// Translate a GLFW keycode to a Cocoa modifier flag
|
|
|
|
//
|
|
|
|
static NSUInteger translateKeyToModifierFlag(int key)
|
|
|
|
{
|
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
case GLFW_KEY_LEFT_SHIFT:
|
|
|
|
case GLFW_KEY_RIGHT_SHIFT:
|
|
|
|
return NSShiftKeyMask;
|
|
|
|
case GLFW_KEY_LEFT_CONTROL:
|
|
|
|
case GLFW_KEY_RIGHT_CONTROL:
|
|
|
|
return NSControlKeyMask;
|
|
|
|
case GLFW_KEY_LEFT_ALT:
|
|
|
|
case GLFW_KEY_RIGHT_ALT:
|
|
|
|
return NSAlternateKeyMask;
|
|
|
|
case GLFW_KEY_LEFT_SUPER:
|
|
|
|
case GLFW_KEY_RIGHT_SUPER:
|
|
|
|
return NSCommandKeyMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-13 17:19:20 +01:00
|
|
|
// Defines a constant for empty ranges in NSTextInputClient
|
|
|
|
//
|
2016-02-26 10:34:23 +01:00
|
|
|
static const NSRange kEmptyRange = { NSNotFound, 0 };
|
2015-11-13 17:19:20 +01:00
|
|
|
|
2013-05-02 18:16:23 +02:00
|
|
|
|
2013-02-04 13:22:10 +01:00
|
|
|
//------------------------------------------------------------------------
|
2010-09-07 17:34:51 +02:00
|
|
|
// Delegate for window related notifications
|
2013-02-04 13:22:10 +01:00
|
|
|
//------------------------------------------------------------------------
|
2010-09-07 17:34:51 +02:00
|
|
|
|
|
|
|
@interface GLFWWindowDelegate : NSObject
|
2010-09-15 18:57:25 +02:00
|
|
|
{
|
|
|
|
_GLFWwindow* window;
|
|
|
|
}
|
|
|
|
|
2014-05-04 12:18:20 +02:00
|
|
|
- (id)initWithGlfwWindow:(_GLFWwindow *)initWindow;
|
2010-09-15 18:57:25 +02:00
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GLFWWindowDelegate
|
|
|
|
|
2010-09-17 00:39:35 +02:00
|
|
|
- (id)initWithGlfwWindow:(_GLFWwindow *)initWindow
|
2010-09-15 18:57:25 +02:00
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self != nil)
|
|
|
|
window = initWindow;
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)windowShouldClose:(id)sender
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2012-08-10 13:31:15 +02:00
|
|
|
_glfwInputWindowCloseRequest(window);
|
2010-09-07 17:34:51 +02:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidResize:(NSNotification *)notification
|
|
|
|
{
|
2016-03-28 13:19:31 +02:00
|
|
|
if (window->context.client != GLFW_NO_API)
|
2015-11-09 16:48:55 +01:00
|
|
|
[window->context.nsgl.object update];
|
2015-05-15 15:28:27 +02:00
|
|
|
|
2016-05-30 21:21:09 +02:00
|
|
|
if (_glfw.ns.disabledCursorWindow == window)
|
2014-02-11 18:24:01 +01:00
|
|
|
centerCursor(window);
|
|
|
|
|
2013-06-03 12:51:57 +02:00
|
|
|
const NSRect contentRect = [window->ns.view frame];
|
2015-10-18 19:15:36 +02:00
|
|
|
const NSRect fbRect = [window->ns.view convertRectToBacking:contentRect];
|
2013-06-03 12:51:57 +02:00
|
|
|
|
|
|
|
_glfwInputFramebufferSize(window, fbRect.size.width, fbRect.size.height);
|
|
|
|
_glfwInputWindowSize(window, contentRect.size.width, contentRect.size.height);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2010-09-17 00:25:09 +02:00
|
|
|
- (void)windowDidMove:(NSNotification *)notification
|
|
|
|
{
|
2016-03-28 13:19:31 +02:00
|
|
|
if (window->context.client != GLFW_NO_API)
|
2015-11-09 16:48:55 +01:00
|
|
|
[window->context.nsgl.object update];
|
2015-05-15 15:28:27 +02:00
|
|
|
|
2016-05-30 21:21:09 +02:00
|
|
|
if (_glfw.ns.disabledCursorWindow == window)
|
2014-02-11 18:24:01 +01:00
|
|
|
centerCursor(window);
|
|
|
|
|
2013-01-24 19:30:31 +01:00
|
|
|
int x, y;
|
|
|
|
_glfwPlatformGetWindowPos(window, &x, &y);
|
|
|
|
_glfwInputWindowPos(window, x, y);
|
2010-09-17 00:25:09 +02:00
|
|
|
}
|
|
|
|
|
2010-09-17 00:39:35 +02:00
|
|
|
- (void)windowDidMiniaturize:(NSNotification *)notification
|
2010-09-16 03:05:55 +02:00
|
|
|
{
|
2015-08-28 12:00:06 +02:00
|
|
|
if (window->monitor)
|
2016-02-23 12:34:35 +01:00
|
|
|
releaseMonitor(window);
|
2015-08-28 12:00:06 +02:00
|
|
|
|
2015-08-23 19:30:04 +02:00
|
|
|
_glfwInputWindowIconify(window, GLFW_TRUE);
|
2010-09-16 03:05:55 +02:00
|
|
|
}
|
|
|
|
|
2010-09-17 00:39:35 +02:00
|
|
|
- (void)windowDidDeminiaturize:(NSNotification *)notification
|
2010-09-16 03:05:55 +02:00
|
|
|
{
|
2015-08-28 12:00:06 +02:00
|
|
|
if (window->monitor)
|
2016-02-23 12:34:35 +01:00
|
|
|
acquireMonitor(window);
|
2015-08-28 12:00:06 +02:00
|
|
|
|
2015-08-23 19:30:04 +02:00
|
|
|
_glfwInputWindowIconify(window, GLFW_FALSE);
|
2010-09-16 03:05:55 +02:00
|
|
|
}
|
|
|
|
|
2010-09-17 00:39:35 +02:00
|
|
|
- (void)windowDidBecomeKey:(NSNotification *)notification
|
2010-09-16 03:05:55 +02:00
|
|
|
{
|
2016-05-30 21:21:09 +02:00
|
|
|
if (_glfw.ns.disabledCursorWindow == window)
|
2014-02-11 18:24:01 +01:00
|
|
|
centerCursor(window);
|
|
|
|
|
2015-08-23 19:30:04 +02:00
|
|
|
_glfwInputWindowFocus(window, GLFW_TRUE);
|
2015-07-02 13:04:56 +02:00
|
|
|
_glfwPlatformSetCursorMode(window, window->cursorMode);
|
2010-09-16 03:05:55 +02:00
|
|
|
}
|
|
|
|
|
2010-09-17 00:39:35 +02:00
|
|
|
- (void)windowDidResignKey:(NSNotification *)notification
|
2010-09-16 03:05:55 +02:00
|
|
|
{
|
2015-05-06 23:52:39 +02:00
|
|
|
if (window->monitor && window->autoIconify)
|
2015-08-28 12:00:06 +02:00
|
|
|
_glfwPlatformIconifyWindow(window);
|
2014-12-29 19:21:31 +01:00
|
|
|
|
2015-08-23 19:30:04 +02:00
|
|
|
_glfwInputWindowFocus(window, GLFW_FALSE);
|
2010-09-16 03:05:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2012-03-07 15:04:14 +01:00
|
|
|
|
2013-02-04 13:22:10 +01:00
|
|
|
//------------------------------------------------------------------------
|
2010-09-16 03:05:55 +02:00
|
|
|
// Delegate for application related notifications
|
2013-02-04 13:22:10 +01:00
|
|
|
//------------------------------------------------------------------------
|
2010-09-16 03:05:55 +02:00
|
|
|
|
|
|
|
@interface GLFWApplicationDelegate : NSObject
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GLFWApplicationDelegate
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
|
|
|
|
{
|
2010-09-16 03:05:55 +02:00
|
|
|
_GLFWwindow* window;
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
for (window = _glfw.windowListHead; window; window = window->next)
|
2012-08-10 13:31:15 +02:00
|
|
|
_glfwInputWindowCloseRequest(window);
|
2010-09-07 17:34:51 +02:00
|
|
|
|
|
|
|
return NSTerminateCancel;
|
|
|
|
}
|
|
|
|
|
2013-06-06 01:28:01 +02:00
|
|
|
- (void)applicationDidChangeScreenParameters:(NSNotification *) notification
|
|
|
|
{
|
|
|
|
_glfwInputMonitorChange();
|
|
|
|
}
|
|
|
|
|
2014-12-16 22:34:15 +01:00
|
|
|
- (void)applicationDidFinishLaunching:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
[NSApp stop:nil];
|
|
|
|
|
|
|
|
_glfwPlatformPostEmptyEvent();
|
|
|
|
}
|
|
|
|
|
2015-09-09 13:31:40 +02:00
|
|
|
- (void)applicationDidHide:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < _glfw.monitorCount; i++)
|
2015-12-03 18:16:46 +01:00
|
|
|
_glfwRestoreVideoModeNS(_glfw.monitors[i]);
|
2015-09-09 13:31:40 +02:00
|
|
|
}
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
@end
|
|
|
|
|
2012-03-07 15:04:14 +01:00
|
|
|
|
2013-02-04 13:22:10 +01:00
|
|
|
//------------------------------------------------------------------------
|
2010-09-07 17:34:51 +02:00
|
|
|
// Content view class for the GLFW window
|
2013-02-04 13:22:10 +01:00
|
|
|
//------------------------------------------------------------------------
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2015-11-13 17:19:20 +01:00
|
|
|
@interface GLFWContentView : NSView <NSTextInputClient>
|
2010-09-15 18:57:25 +02:00
|
|
|
{
|
|
|
|
_GLFWwindow* window;
|
2012-03-26 14:46:42 +02:00
|
|
|
NSTrackingArea* trackingArea;
|
2015-11-13 17:19:20 +01:00
|
|
|
NSMutableAttributedString* markedText;
|
2010-09-15 18:57:25 +02:00
|
|
|
}
|
|
|
|
|
2010-09-17 00:39:35 +02:00
|
|
|
- (id)initWithGlfwWindow:(_GLFWwindow *)initWindow;
|
2010-09-15 18:57:25 +02:00
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GLFWContentView
|
|
|
|
|
2013-04-17 00:37:06 +02:00
|
|
|
+ (void)initialize
|
|
|
|
{
|
|
|
|
if (self == [GLFWContentView class])
|
|
|
|
{
|
2013-04-21 22:46:35 +02:00
|
|
|
if (_glfw.ns.cursor == nil)
|
|
|
|
{
|
2014-01-06 15:34:49 +01:00
|
|
|
NSImage* data = [[NSImage alloc] initWithSize:NSMakeSize(16, 16)];
|
2013-04-21 22:46:35 +02:00
|
|
|
_glfw.ns.cursor = [[NSCursor alloc] initWithImage:data
|
|
|
|
hotSpot:NSZeroPoint];
|
|
|
|
[data release];
|
|
|
|
}
|
2013-04-17 00:37:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-17 00:39:35 +02:00
|
|
|
- (id)initWithGlfwWindow:(_GLFWwindow *)initWindow
|
2010-09-15 18:57:25 +02:00
|
|
|
{
|
2015-05-15 15:28:27 +02:00
|
|
|
self = [super init];
|
2010-09-15 18:57:25 +02:00
|
|
|
if (self != nil)
|
2012-03-26 14:46:42 +02:00
|
|
|
{
|
2010-09-15 18:57:25 +02:00
|
|
|
window = initWindow;
|
2012-03-26 14:46:42 +02:00
|
|
|
trackingArea = nil;
|
2015-11-13 17:19:20 +01:00
|
|
|
markedText = [[NSMutableAttributedString alloc] init];
|
2013-12-22 16:38:56 +01:00
|
|
|
|
2012-03-26 14:46:42 +02:00
|
|
|
[self updateTrackingAreas];
|
2013-07-10 11:42:14 +02:00
|
|
|
[self registerForDraggedTypes:[NSArray arrayWithObjects:
|
|
|
|
NSFilenamesPboardType, nil]];
|
2012-03-26 14:46:42 +02:00
|
|
|
}
|
2010-09-15 18:57:25 +02:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2015-11-13 17:19:20 +01:00
|
|
|
- (void)dealloc
|
2012-03-26 14:46:42 +02:00
|
|
|
{
|
|
|
|
[trackingArea release];
|
2015-11-13 17:19:20 +01:00
|
|
|
[markedText release];
|
2012-03-26 14:46:42 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
- (BOOL)isOpaque
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)canBecomeKeyView
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)acceptsFirstResponder
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2013-09-19 01:05:51 +02:00
|
|
|
- (void)cursorUpdate:(NSEvent *)event
|
|
|
|
{
|
2016-05-30 21:21:09 +02:00
|
|
|
updateCursorImage(window);
|
2013-09-19 01:05:51 +02:00
|
|
|
}
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
- (void)mouseDown:(NSEvent *)event
|
|
|
|
{
|
2012-12-09 19:19:00 +01:00
|
|
|
_glfwInputMouseClick(window,
|
|
|
|
GLFW_MOUSE_BUTTON_LEFT,
|
|
|
|
GLFW_PRESS,
|
2013-05-30 17:19:12 +02:00
|
|
|
translateFlags([event modifierFlags]));
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseDragged:(NSEvent *)event
|
|
|
|
{
|
|
|
|
[self mouseMoved:event];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseUp:(NSEvent *)event
|
|
|
|
{
|
2012-12-09 19:19:00 +01:00
|
|
|
_glfwInputMouseClick(window,
|
|
|
|
GLFW_MOUSE_BUTTON_LEFT,
|
|
|
|
GLFW_RELEASE,
|
2013-05-30 17:19:12 +02:00
|
|
|
translateFlags([event modifierFlags]));
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseMoved:(NSEvent *)event
|
|
|
|
{
|
2013-04-26 17:20:31 +02:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
2014-02-11 18:24:01 +01:00
|
|
|
{
|
2016-05-25 14:06:02 +02:00
|
|
|
const double dx = [event deltaX] - window->ns.cursorWarpDeltaX;
|
|
|
|
const double dy = [event deltaY] - window->ns.cursorWarpDeltaY;
|
|
|
|
|
|
|
|
_glfwInputCursorPos(window,
|
|
|
|
window->virtualCursorPosX + dx,
|
|
|
|
window->virtualCursorPosY + dy);
|
2014-02-11 18:24:01 +01:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
else
|
|
|
|
{
|
2013-06-04 01:51:40 +02:00
|
|
|
const NSRect contentRect = [window->ns.view frame];
|
2014-02-11 18:24:01 +01:00
|
|
|
const NSPoint pos = [event locationInWindow];
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2016-05-25 14:06:02 +02:00
|
|
|
_glfwInputCursorPos(window, pos.x, contentRect.size.height - pos.y);
|
2011-05-21 22:50:25 +02:00
|
|
|
}
|
2014-02-11 18:24:01 +01:00
|
|
|
|
2016-05-24 12:23:58 +02:00
|
|
|
window->ns.cursorWarpDeltaX = 0;
|
|
|
|
window->ns.cursorWarpDeltaY = 0;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rightMouseDown:(NSEvent *)event
|
|
|
|
{
|
2012-12-09 19:19:00 +01:00
|
|
|
_glfwInputMouseClick(window,
|
|
|
|
GLFW_MOUSE_BUTTON_RIGHT,
|
|
|
|
GLFW_PRESS,
|
2013-05-30 17:19:12 +02:00
|
|
|
translateFlags([event modifierFlags]));
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rightMouseDragged:(NSEvent *)event
|
|
|
|
{
|
|
|
|
[self mouseMoved:event];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rightMouseUp:(NSEvent *)event
|
|
|
|
{
|
2012-12-09 19:19:00 +01:00
|
|
|
_glfwInputMouseClick(window,
|
|
|
|
GLFW_MOUSE_BUTTON_RIGHT,
|
|
|
|
GLFW_RELEASE,
|
2013-05-30 17:19:12 +02:00
|
|
|
translateFlags([event modifierFlags]));
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)otherMouseDown:(NSEvent *)event
|
|
|
|
{
|
2012-12-09 19:19:00 +01:00
|
|
|
_glfwInputMouseClick(window,
|
2013-10-08 16:42:17 +02:00
|
|
|
(int) [event buttonNumber],
|
2012-12-09 19:19:00 +01:00
|
|
|
GLFW_PRESS,
|
2013-05-30 17:19:12 +02:00
|
|
|
translateFlags([event modifierFlags]));
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)otherMouseDragged:(NSEvent *)event
|
|
|
|
{
|
|
|
|
[self mouseMoved:event];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)otherMouseUp:(NSEvent *)event
|
|
|
|
{
|
2012-12-09 19:19:00 +01:00
|
|
|
_glfwInputMouseClick(window,
|
2013-10-08 16:42:17 +02:00
|
|
|
(int) [event buttonNumber],
|
2012-12-09 19:19:00 +01:00
|
|
|
GLFW_RELEASE,
|
2013-05-30 17:19:12 +02:00
|
|
|
translateFlags([event modifierFlags]));
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2012-03-26 14:46:42 +02:00
|
|
|
- (void)mouseExited:(NSEvent *)event
|
|
|
|
{
|
2015-08-23 19:30:04 +02:00
|
|
|
_glfwInputCursorEnter(window, GLFW_FALSE);
|
2012-03-26 14:46:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseEntered:(NSEvent *)event
|
|
|
|
{
|
2015-08-23 19:30:04 +02:00
|
|
|
_glfwInputCursorEnter(window, GLFW_TRUE);
|
2012-03-26 14:46:42 +02:00
|
|
|
}
|
|
|
|
|
2013-06-03 12:51:57 +02:00
|
|
|
- (void)viewDidChangeBackingProperties
|
|
|
|
{
|
|
|
|
const NSRect contentRect = [window->ns.view frame];
|
2015-10-18 19:15:36 +02:00
|
|
|
const NSRect fbRect = [window->ns.view convertRectToBacking:contentRect];
|
2013-06-03 12:51:57 +02:00
|
|
|
|
|
|
|
_glfwInputFramebufferSize(window, fbRect.size.width, fbRect.size.height);
|
2015-08-31 22:22:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)drawRect:(NSRect)rect
|
|
|
|
{
|
2015-01-05 22:33:02 +01:00
|
|
|
_glfwInputWindowDamage(window);
|
2013-06-03 12:51:57 +02:00
|
|
|
}
|
|
|
|
|
2012-03-26 14:46:42 +02:00
|
|
|
- (void)updateTrackingAreas
|
|
|
|
{
|
|
|
|
if (trackingArea != nil)
|
|
|
|
{
|
|
|
|
[self removeTrackingArea:trackingArea];
|
|
|
|
[trackingArea release];
|
|
|
|
}
|
|
|
|
|
2014-12-29 19:00:53 +01:00
|
|
|
const NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited |
|
|
|
|
NSTrackingActiveInKeyWindow |
|
2014-12-31 22:23:35 +01:00
|
|
|
NSTrackingEnabledDuringMouseDrag |
|
2014-12-29 19:00:53 +01:00
|
|
|
NSTrackingCursorUpdate |
|
|
|
|
NSTrackingInVisibleRect |
|
|
|
|
NSTrackingAssumeInside;
|
2012-03-26 14:46:42 +02:00
|
|
|
|
|
|
|
trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds]
|
|
|
|
options:options
|
|
|
|
owner:self
|
|
|
|
userInfo:nil];
|
|
|
|
|
|
|
|
[self addTrackingArea:trackingArea];
|
2013-07-18 04:36:43 +02:00
|
|
|
[super updateTrackingAreas];
|
2012-03-26 14:46:42 +02:00
|
|
|
}
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
- (void)keyDown:(NSEvent *)event
|
|
|
|
{
|
2013-05-30 17:19:12 +02:00
|
|
|
const int key = translateKey([event keyCode]);
|
|
|
|
const int mods = translateFlags([event modifierFlags]);
|
2014-06-12 23:04:20 +02:00
|
|
|
|
2013-05-30 17:19:12 +02:00
|
|
|
_glfwInputKey(window, key, [event keyCode], GLFW_PRESS, mods);
|
2012-12-09 19:19:00 +01:00
|
|
|
|
2015-11-13 17:19:20 +01:00
|
|
|
[self interpretKeyEvents:[NSArray arrayWithObject:event]];
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)flagsChanged:(NSEvent *)event
|
|
|
|
{
|
2013-05-30 17:19:12 +02:00
|
|
|
int action;
|
2014-06-17 11:29:34 +02:00
|
|
|
const unsigned int modifierFlags =
|
2013-04-08 03:04:10 +02:00
|
|
|
[event modifierFlags] & NSDeviceIndependentModifierFlagsMask;
|
2014-06-17 11:29:34 +02:00
|
|
|
const int key = translateKey([event keyCode]);
|
|
|
|
const int mods = translateFlags(modifierFlags);
|
2015-07-27 03:40:54 +02:00
|
|
|
const NSUInteger keyFlag = translateKeyToModifierFlag(key);
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2015-07-27 03:40:54 +02:00
|
|
|
if (keyFlag & modifierFlags)
|
2014-06-17 11:29:34 +02:00
|
|
|
{
|
2014-06-18 21:07:54 +02:00
|
|
|
if (window->keys[key] == GLFW_PRESS)
|
2014-06-17 11:29:34 +02:00
|
|
|
action = GLFW_RELEASE;
|
|
|
|
else
|
|
|
|
action = GLFW_PRESS;
|
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
else
|
2013-04-21 21:54:33 +02:00
|
|
|
action = GLFW_RELEASE;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2013-05-30 17:19:12 +02:00
|
|
|
_glfwInputKey(window, key, [event keyCode], action, mods);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)keyUp:(NSEvent *)event
|
|
|
|
{
|
2013-05-30 17:19:12 +02:00
|
|
|
const int key = translateKey([event keyCode]);
|
|
|
|
const int mods = translateFlags([event modifierFlags]);
|
|
|
|
_glfwInputKey(window, key, [event keyCode], GLFW_RELEASE, mods);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)scrollWheel:(NSEvent *)event
|
|
|
|
{
|
2013-07-18 04:36:43 +02:00
|
|
|
double deltaX, deltaY;
|
|
|
|
|
2015-10-18 19:15:36 +02:00
|
|
|
deltaX = [event scrollingDeltaX];
|
|
|
|
deltaY = [event scrollingDeltaY];
|
2013-07-18 04:36:43 +02:00
|
|
|
|
2015-10-18 19:15:36 +02:00
|
|
|
if ([event hasPreciseScrollingDeltas])
|
2013-07-18 04:36:43 +02:00
|
|
|
{
|
2015-10-18 19:15:36 +02:00
|
|
|
deltaX *= 0.1;
|
|
|
|
deltaY *= 0.1;
|
2013-07-18 04:36:43 +02:00
|
|
|
}
|
2012-03-28 22:39:48 +02:00
|
|
|
|
|
|
|
if (fabs(deltaX) > 0.0 || fabs(deltaY) > 0.0)
|
2014-10-26 13:53:45 +01:00
|
|
|
_glfwInputScroll(window, deltaX, deltaY);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 11:42:14 +02:00
|
|
|
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
|
|
|
|
{
|
2013-12-22 16:38:56 +01:00
|
|
|
if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
|
|
|
|
== NSDragOperationGeneric)
|
|
|
|
{
|
|
|
|
[self setNeedsDisplay:YES];
|
2013-07-10 11:42:14 +02:00
|
|
|
return NSDragOperationGeneric;
|
|
|
|
}
|
2013-12-22 16:38:56 +01:00
|
|
|
|
|
|
|
return NSDragOperationNone;
|
2013-07-10 11:42:14 +02:00
|
|
|
}
|
|
|
|
|
2013-12-22 16:38:56 +01:00
|
|
|
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
|
|
|
|
{
|
2013-07-10 11:42:14 +02:00
|
|
|
[self setNeedsDisplay:YES];
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2013-12-22 16:38:56 +01:00
|
|
|
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
|
|
|
|
{
|
|
|
|
NSPasteboard* pasteboard = [sender draggingPasteboard];
|
|
|
|
NSArray* files = [pasteboard propertyListForType:NSFilenamesPboardType];
|
|
|
|
|
2014-02-11 18:24:01 +01:00
|
|
|
const NSRect contentRect = [window->ns.view frame];
|
2016-05-25 14:06:02 +02:00
|
|
|
_glfwInputCursorPos(window,
|
|
|
|
[sender draggingLocation].x,
|
|
|
|
contentRect.size.height - [sender draggingLocation].y);
|
2013-12-22 16:38:56 +01:00
|
|
|
|
2013-12-22 19:28:46 +01:00
|
|
|
const int count = [files count];
|
|
|
|
if (count)
|
2013-12-22 16:38:56 +01:00
|
|
|
{
|
2013-12-22 19:28:46 +01:00
|
|
|
NSEnumerator* e = [files objectEnumerator];
|
2015-01-27 23:04:22 +01:00
|
|
|
char** paths = calloc(count, sizeof(char*));
|
2014-02-13 18:33:01 +01:00
|
|
|
int i;
|
2013-12-22 16:38:56 +01:00
|
|
|
|
2014-02-13 18:33:01 +01:00
|
|
|
for (i = 0; i < count; i++)
|
2015-01-27 23:04:22 +01:00
|
|
|
paths[i] = strdup([[e nextObject] UTF8String]);
|
2013-12-22 16:38:56 +01:00
|
|
|
|
2015-01-27 23:04:22 +01:00
|
|
|
_glfwInputDrop(window, count, (const char**) paths);
|
2013-12-22 16:38:56 +01:00
|
|
|
|
2014-02-13 18:33:01 +01:00
|
|
|
for (i = 0; i < count; i++)
|
2015-01-27 23:04:22 +01:00
|
|
|
free(paths[i]);
|
|
|
|
free(paths);
|
2013-12-22 16:38:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
2013-07-10 11:42:14 +02:00
|
|
|
}
|
|
|
|
|
2013-12-22 16:38:56 +01:00
|
|
|
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
|
|
|
|
{
|
2013-07-10 11:42:14 +02:00
|
|
|
[self setNeedsDisplay:YES];
|
|
|
|
}
|
|
|
|
|
2015-11-13 17:19:20 +01:00
|
|
|
- (BOOL)hasMarkedText
|
|
|
|
{
|
2016-02-26 10:34:23 +01:00
|
|
|
return [markedText length] > 0;
|
2015-11-13 17:19:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRange)markedRange
|
|
|
|
{
|
2016-02-26 10:34:23 +01:00
|
|
|
if ([markedText length] > 0)
|
|
|
|
return NSMakeRange(0, [markedText length] - 1);
|
|
|
|
else
|
|
|
|
return kEmptyRange;
|
2015-11-13 17:19:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRange)selectedRange
|
|
|
|
{
|
|
|
|
return kEmptyRange;
|
|
|
|
}
|
|
|
|
|
2016-02-26 10:34:23 +01:00
|
|
|
- (void)setMarkedText:(id)string
|
2015-11-13 17:19:20 +01:00
|
|
|
selectedRange:(NSRange)selectedRange
|
|
|
|
replacementRange:(NSRange)replacementRange
|
|
|
|
{
|
2016-02-26 10:34:23 +01:00
|
|
|
if ([string isKindOfClass:[NSAttributedString class]])
|
|
|
|
[markedText initWithAttributedString:string];
|
2015-11-13 17:19:20 +01:00
|
|
|
else
|
2016-02-26 10:34:23 +01:00
|
|
|
[markedText initWithString:string];
|
2015-11-13 17:19:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)unmarkText
|
|
|
|
{
|
|
|
|
[[markedText mutableString] setString:@""];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*)validAttributesForMarkedText
|
|
|
|
{
|
|
|
|
return [NSArray array];
|
|
|
|
}
|
|
|
|
|
2016-02-26 10:34:23 +01:00
|
|
|
- (NSAttributedString*)attributedSubstringForProposedRange:(NSRange)range
|
2015-11-13 17:19:20 +01:00
|
|
|
actualRange:(NSRangePointer)actualRange
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2016-02-26 10:34:23 +01:00
|
|
|
- (NSUInteger)characterIndexForPoint:(NSPoint)point
|
2015-11-13 17:19:20 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-26 10:34:23 +01:00
|
|
|
- (NSRect)firstRectForCharacterRange:(NSRange)range
|
2015-11-13 17:19:20 +01:00
|
|
|
actualRange:(NSRangePointer)actualRange
|
|
|
|
{
|
2016-02-26 10:47:29 +01:00
|
|
|
int xpos, ypos;
|
|
|
|
_glfwPlatformGetWindowPos(window, &xpos, &ypos);
|
2016-02-26 10:46:49 +01:00
|
|
|
const NSRect contentRect = [window->ns.view frame];
|
2016-02-26 10:47:29 +01:00
|
|
|
return NSMakeRect(xpos, transformY(ypos + contentRect.size.height), 0.0, 0.0);
|
2015-11-13 17:19:20 +01:00
|
|
|
}
|
|
|
|
|
2016-02-26 10:34:23 +01:00
|
|
|
- (void)insertText:(id)string replacementRange:(NSRange)replacementRange
|
2015-11-13 17:19:20 +01:00
|
|
|
{
|
2016-02-26 10:34:23 +01:00
|
|
|
NSString* characters;
|
2015-11-13 17:19:20 +01:00
|
|
|
NSEvent* event = [NSApp currentEvent];
|
|
|
|
const int mods = translateFlags([event modifierFlags]);
|
2016-02-26 10:34:23 +01:00
|
|
|
const int plain = !(mods & GLFW_MOD_SUPER);
|
2015-11-13 17:19:20 +01:00
|
|
|
|
2016-02-26 10:34:23 +01:00
|
|
|
if ([string isKindOfClass:[NSAttributedString class]])
|
|
|
|
characters = [string string];
|
|
|
|
else
|
|
|
|
characters = (NSString*) string;
|
2015-11-13 17:19:20 +01:00
|
|
|
|
|
|
|
NSUInteger i, length = [characters length];
|
|
|
|
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
const unichar codepoint = [characters characterAtIndex:i];
|
|
|
|
if ((codepoint & 0xff00) == 0xf700)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
_glfwInputChar(window, codepoint, mods, plain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-28 10:53:48 +01:00
|
|
|
- (void)doCommandBySelector:(SEL)selector
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
@end
|
|
|
|
|
2012-03-07 15:04:14 +01:00
|
|
|
|
2013-04-08 15:16:32 +02:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// GLFW window class
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
|
|
|
|
@interface GLFWWindow : NSWindow {}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GLFWWindow
|
|
|
|
|
|
|
|
- (BOOL)canBecomeKeyWindow
|
|
|
|
{
|
|
|
|
// Required for NSBorderlessWindowMask windows
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
2013-02-04 13:22:10 +01:00
|
|
|
//------------------------------------------------------------------------
|
2012-02-15 01:44:55 +01:00
|
|
|
// GLFW application class
|
2013-02-04 13:22:10 +01:00
|
|
|
//------------------------------------------------------------------------
|
2012-02-15 01:44:55 +01:00
|
|
|
|
|
|
|
@interface GLFWApplication : NSApplication
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GLFWApplication
|
|
|
|
|
|
|
|
// 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];
|
|
|
|
}
|
|
|
|
|
2016-03-31 21:10:12 +02:00
|
|
|
|
|
|
|
// No-op thread entry point
|
|
|
|
//
|
|
|
|
- (void)doNothing:(id)object
|
|
|
|
{
|
|
|
|
}
|
2012-02-15 01:44:55 +01:00
|
|
|
@end
|
|
|
|
|
2013-02-24 22:04:54 +01:00
|
|
|
#if defined(_GLFW_USE_MENUBAR)
|
|
|
|
|
2012-02-15 01:44:55 +01:00
|
|
|
// Try to figure out what the calling application is called
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2012-02-15 01:44:55 +01:00
|
|
|
static NSString* findAppName(void)
|
|
|
|
{
|
2013-07-15 18:37:02 +02:00
|
|
|
size_t i;
|
2012-02-15 01:44:55 +01:00
|
|
|
NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
|
|
|
|
|
|
|
|
// Keys to search for as potential application names
|
|
|
|
NSString* GLFWNameKeys[] =
|
|
|
|
{
|
|
|
|
@"CFBundleDisplayName",
|
|
|
|
@"CFBundleName",
|
|
|
|
@"CFBundleExecutable",
|
|
|
|
};
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(GLFWNameKeys) / sizeof(GLFWNameKeys[0]); i++)
|
|
|
|
{
|
|
|
|
id name = [infoDictionary objectForKey:GLFWNameKeys[i]];
|
|
|
|
if (name &&
|
|
|
|
[name isKindOfClass:[NSString class]] &&
|
2013-06-04 01:51:40 +02:00
|
|
|
![name isEqualToString:@""])
|
2012-02-15 01:44:55 +01:00
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char** progname = _NSGetProgname();
|
|
|
|
if (progname && *progname)
|
|
|
|
return [NSString stringWithUTF8String:*progname];
|
|
|
|
|
|
|
|
// Really shouldn't get here
|
|
|
|
return @"GLFW Application";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set up the menu bar (manually)
|
|
|
|
// This is nasty, nasty stuff -- calls to undocumented semi-private APIs that
|
|
|
|
// could go away at any moment, lots of stuff that really should be
|
|
|
|
// localize(d|able), etc. Loading a nib would save us this horror, but that
|
2015-01-05 21:55:15 +01:00
|
|
|
// doesn't seem like a good thing to require of GLFW users.
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2012-03-05 20:30:59 +01:00
|
|
|
static void createMenuBar(void)
|
2012-02-15 01:44:55 +01:00
|
|
|
{
|
|
|
|
NSString* appName = findAppName();
|
|
|
|
|
|
|
|
NSMenu* bar = [[NSMenu alloc] init];
|
|
|
|
[NSApp setMainMenu:bar];
|
|
|
|
|
|
|
|
NSMenuItem* appMenuItem =
|
|
|
|
[bar addItemWithTitle:@"" action:NULL keyEquivalent:@""];
|
|
|
|
NSMenu* appMenu = [[NSMenu alloc] init];
|
|
|
|
[appMenuItem setSubmenu:appMenu];
|
|
|
|
|
|
|
|
[appMenu addItemWithTitle:[NSString stringWithFormat:@"About %@", appName]
|
|
|
|
action:@selector(orderFrontStandardAboutPanel:)
|
|
|
|
keyEquivalent:@""];
|
|
|
|
[appMenu addItem:[NSMenuItem separatorItem]];
|
|
|
|
NSMenu* servicesMenu = [[NSMenu alloc] init];
|
|
|
|
[NSApp setServicesMenu:servicesMenu];
|
|
|
|
[[appMenu addItemWithTitle:@"Services"
|
|
|
|
action:NULL
|
|
|
|
keyEquivalent:@""] setSubmenu:servicesMenu];
|
2015-09-29 04:21:44 +02:00
|
|
|
[servicesMenu release];
|
2012-02-15 01:44:55 +01:00
|
|
|
[appMenu addItem:[NSMenuItem separatorItem]];
|
|
|
|
[appMenu addItemWithTitle:[NSString stringWithFormat:@"Hide %@", appName]
|
|
|
|
action:@selector(hide:)
|
|
|
|
keyEquivalent:@"h"];
|
|
|
|
[[appMenu addItemWithTitle:@"Hide Others"
|
|
|
|
action:@selector(hideOtherApplications:)
|
|
|
|
keyEquivalent:@"h"]
|
|
|
|
setKeyEquivalentModifierMask:NSAlternateKeyMask | NSCommandKeyMask];
|
|
|
|
[appMenu addItemWithTitle:@"Show All"
|
|
|
|
action:@selector(unhideAllApplications:)
|
|
|
|
keyEquivalent:@""];
|
|
|
|
[appMenu addItem:[NSMenuItem separatorItem]];
|
|
|
|
[appMenu addItemWithTitle:[NSString stringWithFormat:@"Quit %@", appName]
|
|
|
|
action:@selector(terminate:)
|
|
|
|
keyEquivalent:@"q"];
|
|
|
|
|
|
|
|
NSMenuItem* windowMenuItem =
|
|
|
|
[bar addItemWithTitle:@"" action:NULL keyEquivalent:@""];
|
2015-09-29 04:21:44 +02:00
|
|
|
[bar release];
|
2012-02-15 01:44:55 +01:00
|
|
|
NSMenu* windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
|
|
|
|
[NSApp setWindowsMenu:windowMenu];
|
|
|
|
[windowMenuItem setSubmenu:windowMenu];
|
|
|
|
|
2013-09-10 19:33:32 +02:00
|
|
|
[windowMenu addItemWithTitle:@"Minimize"
|
2012-02-15 01:44:55 +01:00
|
|
|
action:@selector(performMiniaturize:)
|
|
|
|
keyEquivalent:@"m"];
|
|
|
|
[windowMenu addItemWithTitle:@"Zoom"
|
|
|
|
action:@selector(performZoom:)
|
|
|
|
keyEquivalent:@""];
|
|
|
|
[windowMenu addItem:[NSMenuItem separatorItem]];
|
|
|
|
[windowMenu addItemWithTitle:@"Bring All to Front"
|
|
|
|
action:@selector(arrangeInFront:)
|
|
|
|
keyEquivalent:@""];
|
|
|
|
|
2015-10-18 19:15:36 +02:00
|
|
|
// TODO: Make this appear at the bottom of the menu (for consistency)
|
|
|
|
[windowMenu addItem:[NSMenuItem separatorItem]];
|
|
|
|
[[windowMenu addItemWithTitle:@"Enter Full Screen"
|
|
|
|
action:@selector(toggleFullScreen:)
|
|
|
|
keyEquivalent:@"f"]
|
|
|
|
setKeyEquivalentModifierMask:NSControlKeyMask | NSCommandKeyMask];
|
2013-10-28 13:01:58 +01:00
|
|
|
|
2012-03-05 20:09:06 +01:00
|
|
|
// Prior to Snow Leopard, we need to use this oddly-named semi-private API
|
|
|
|
// to get the application menu working properly.
|
2013-10-08 16:49:00 +02:00
|
|
|
SEL setAppleMenuSelector = NSSelectorFromString(@"setAppleMenu:");
|
|
|
|
[NSApp performSelector:setAppleMenuSelector withObject:appMenu];
|
2012-02-15 01:44:55 +01:00
|
|
|
}
|
|
|
|
|
2013-01-24 19:45:21 +01:00
|
|
|
#endif /* _GLFW_USE_MENUBAR */
|
|
|
|
|
2012-02-15 01:44:55 +01:00
|
|
|
// Initialize the Cocoa Application Kit
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2015-08-23 19:30:04 +02:00
|
|
|
static GLFWbool initializeAppKit(void)
|
2012-02-15 01:44:55 +01:00
|
|
|
{
|
|
|
|
if (NSApp)
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_TRUE;
|
2012-02-15 01:44:55 +01:00
|
|
|
|
|
|
|
// Implicitly create shared NSApplication instance
|
|
|
|
[GLFWApplication sharedApplication];
|
|
|
|
|
2016-03-31 21:10:12 +02:00
|
|
|
// Make Cocoa enter multi-threaded mode
|
|
|
|
[NSThread detachNewThreadSelector:@selector(doNothing:)
|
|
|
|
toTarget:NSApp
|
|
|
|
withObject:nil];
|
|
|
|
|
2013-11-07 18:03:39 +01:00
|
|
|
// In case we are unbundled, make us a proper UI application
|
|
|
|
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
2013-06-16 20:27:35 +02:00
|
|
|
|
2013-01-24 19:45:21 +01:00
|
|
|
#if defined(_GLFW_USE_MENUBAR)
|
2012-10-17 17:11:56 +02:00
|
|
|
// Menu bar setup must go between sharedApplication above and
|
|
|
|
// finishLaunching below, in order to properly emulate the behavior
|
|
|
|
// of NSApplicationMain
|
2012-03-05 20:30:59 +01:00
|
|
|
createMenuBar();
|
2013-01-24 19:45:21 +01:00
|
|
|
#endif
|
2012-02-15 01:44:55 +01:00
|
|
|
|
2014-12-16 22:34:15 +01:00
|
|
|
// There can only be one application delegate, but we allocate it the
|
|
|
|
// first time a window is created to keep all window code in this file
|
2015-01-04 17:49:12 +01:00
|
|
|
_glfw.ns.delegate = [[GLFWApplicationDelegate alloc] init];
|
|
|
|
if (_glfw.ns.delegate == nil)
|
2014-12-16 22:34:15 +01:00
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Cocoa: Failed to create application delegate");
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2014-12-16 22:34:15 +01:00
|
|
|
}
|
|
|
|
|
2015-01-04 17:49:12 +01:00
|
|
|
[NSApp setDelegate:_glfw.ns.delegate];
|
2014-12-16 22:34:15 +01:00
|
|
|
[NSApp run];
|
2012-02-15 01:44:55 +01:00
|
|
|
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_TRUE;
|
2012-02-15 01:44:55 +01:00
|
|
|
}
|
|
|
|
|
2012-01-31 17:53:19 +01:00
|
|
|
// Create the Cocoa window
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2015-08-23 19:30:04 +02:00
|
|
|
static GLFWbool createWindow(_GLFWwindow* window,
|
|
|
|
const _GLFWwndconfig* wndconfig)
|
2012-01-31 17:53:19 +01:00
|
|
|
{
|
2014-04-06 13:46:16 +02:00
|
|
|
window->ns.delegate = [[GLFWWindowDelegate alloc] initWithGlfwWindow:window];
|
|
|
|
if (window->ns.delegate == nil)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Cocoa: Failed to create window delegate");
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2014-04-06 13:46:16 +02:00
|
|
|
}
|
|
|
|
|
2014-10-28 22:10:39 +01:00
|
|
|
NSRect contentRect;
|
|
|
|
|
2016-03-14 15:17:28 +01:00
|
|
|
if (window->monitor)
|
2015-09-01 18:33:34 +02:00
|
|
|
{
|
|
|
|
GLFWvidmode mode;
|
|
|
|
int xpos, ypos;
|
|
|
|
|
|
|
|
_glfwPlatformGetVideoMode(window->monitor, &mode);
|
|
|
|
_glfwPlatformGetMonitorPos(window->monitor, &xpos, &ypos);
|
|
|
|
|
|
|
|
contentRect = NSMakeRect(xpos, ypos, mode.width, mode.height);
|
|
|
|
}
|
2014-10-28 22:10:39 +01:00
|
|
|
else
|
|
|
|
contentRect = NSMakeRect(0, 0, wndconfig->width, wndconfig->height);
|
|
|
|
|
2013-04-08 03:07:52 +02:00
|
|
|
window->ns.object = [[GLFWWindow alloc]
|
2014-10-28 22:10:39 +01:00
|
|
|
initWithContentRect:contentRect
|
2016-02-23 12:26:42 +01:00
|
|
|
styleMask:getStyleMask(window)
|
2012-01-31 17:53:19 +01:00
|
|
|
backing:NSBackingStoreBuffered
|
|
|
|
defer:NO];
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
if (window->ns.object == nil)
|
2012-01-31 17:53:19 +01:00
|
|
|
{
|
2012-12-31 21:05:28 +01:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR, "Cocoa: Failed to create window");
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2012-01-31 17:53:19 +01:00
|
|
|
}
|
|
|
|
|
2016-03-14 15:17:28 +01:00
|
|
|
if (window->monitor)
|
2014-10-28 22:10:39 +01:00
|
|
|
[window->ns.object setLevel:NSMainMenuWindowLevel + 1];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[window->ns.object center];
|
|
|
|
|
2016-02-23 12:26:42 +01:00
|
|
|
if (wndconfig->resizable)
|
|
|
|
[window->ns.object setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
|
|
|
|
|
2014-10-28 22:10:39 +01:00
|
|
|
if (wndconfig->floating)
|
|
|
|
[window->ns.object setLevel:NSFloatingWindowLevel];
|
2015-10-13 12:50:59 +02:00
|
|
|
|
|
|
|
if (wndconfig->maximized)
|
|
|
|
[window->ns.object zoom:nil];
|
2014-10-28 22:10:39 +01:00
|
|
|
}
|
2014-05-23 14:01:02 +02:00
|
|
|
|
2015-05-15 15:28:27 +02:00
|
|
|
window->ns.view = [[GLFWContentView alloc] initWithGlfwWindow:window];
|
|
|
|
|
|
|
|
#if defined(_GLFW_USE_RETINA)
|
2015-10-18 19:15:36 +02:00
|
|
|
[window->ns.view setWantsBestResolutionOpenGLSurface:YES];
|
2015-05-15 15:28:27 +02:00
|
|
|
#endif /*_GLFW_USE_RETINA*/
|
|
|
|
|
2016-03-16 14:48:53 +01:00
|
|
|
[window->ns.object makeFirstResponder:window->ns.view];
|
2013-01-02 01:40:42 +01:00
|
|
|
[window->ns.object setTitle:[NSString stringWithUTF8String:wndconfig->title]];
|
|
|
|
[window->ns.object setDelegate:window->ns.delegate];
|
|
|
|
[window->ns.object setAcceptsMouseMovedEvents:YES];
|
2015-05-15 15:28:27 +02:00
|
|
|
[window->ns.object setContentView:window->ns.view];
|
2015-10-18 19:15:36 +02:00
|
|
|
[window->ns.object setRestorable:NO];
|
2012-07-02 15:24:02 +02:00
|
|
|
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_TRUE;
|
2012-01-31 17:53:19 +01:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-03-07 15:04:14 +01:00
|
|
|
|
2012-01-31 17:53:19 +01:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW platform API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-08-06 17:56:41 +02:00
|
|
|
int _glfwPlatformCreateWindow(_GLFWwindow* window,
|
|
|
|
const _GLFWwndconfig* wndconfig,
|
2014-03-06 20:05:32 +01:00
|
|
|
const _GLFWctxconfig* ctxconfig,
|
2012-08-06 17:56:41 +02:00
|
|
|
const _GLFWfbconfig* fbconfig)
|
2012-01-31 17:53:19 +01:00
|
|
|
{
|
2012-02-26 03:24:42 +01:00
|
|
|
if (!initializeAppKit())
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2012-02-15 01:44:55 +01:00
|
|
|
|
2012-01-31 17:53:19 +01:00
|
|
|
if (!createWindow(window, wndconfig))
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2012-01-31 17:53:19 +01:00
|
|
|
|
2016-03-28 13:19:31 +02:00
|
|
|
if (ctxconfig->client != GLFW_NO_API)
|
2015-06-18 14:03:02 +02:00
|
|
|
{
|
2016-03-28 13:19:31 +02:00
|
|
|
if (ctxconfig->source == GLFW_NATIVE_CONTEXT_API)
|
|
|
|
{
|
|
|
|
if (!_glfwCreateContextNSGL(window, ctxconfig, fbconfig))
|
|
|
|
return GLFW_FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_API_UNAVAILABLE, "Cocoa: EGL not available");
|
2015-06-18 14:03:02 +02:00
|
|
|
return GLFW_FALSE;
|
2016-03-28 13:19:31 +02:00
|
|
|
}
|
2015-06-18 14:03:02 +02:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2016-03-14 15:17:28 +01:00
|
|
|
if (window->monitor)
|
2014-10-28 22:10:39 +01:00
|
|
|
{
|
|
|
|
_glfwPlatformShowWindow(window);
|
2016-02-23 12:26:42 +01:00
|
|
|
_glfwPlatformFocusWindow(window);
|
2016-02-23 12:34:35 +01:00
|
|
|
if (!acquireMonitor(window))
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2016-05-25 14:06:02 +02:00
|
|
|
|
|
|
|
centerCursor(window);
|
2014-10-28 22:10:39 +01:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_TRUE;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2012-08-06 17:56:41 +02:00
|
|
|
void _glfwPlatformDestroyWindow(_GLFWwindow* window)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2016-05-30 21:21:09 +02:00
|
|
|
if (_glfw.ns.disabledCursorWindow == window)
|
|
|
|
_glfw.ns.disabledCursorWindow = NULL;
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
[window->ns.object orderOut:nil];
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-09-27 21:37:36 +02:00
|
|
|
if (window->monitor)
|
2016-02-23 12:34:35 +01:00
|
|
|
releaseMonitor(window);
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2016-03-28 13:19:31 +02:00
|
|
|
if (window->context.client != GLFW_NO_API)
|
2016-05-25 14:43:51 +02:00
|
|
|
window->context.destroy(window);
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
[window->ns.object setDelegate:nil];
|
|
|
|
[window->ns.delegate release];
|
|
|
|
window->ns.delegate = nil;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
[window->ns.view release];
|
|
|
|
window->ns.view = nil;
|
2012-03-26 15:29:01 +02:00
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
[window->ns.object close];
|
|
|
|
window->ns.object = nil;
|
2016-03-18 12:01:48 +01:00
|
|
|
|
|
|
|
[_glfw.ns.autoreleasePool drain];
|
|
|
|
_glfw.ns.autoreleasePool = [[NSAutoreleasePool alloc] init];
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2010-09-15 18:57:25 +02:00
|
|
|
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
[window->ns.object setTitle:[NSString stringWithUTF8String:title]];
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2016-03-07 14:55:30 +01:00
|
|
|
void _glfwPlatformSetWindowIcon(_GLFWwindow* window,
|
|
|
|
int count, const GLFWimage* images)
|
|
|
|
{
|
|
|
|
// Regular windows do not have icons
|
|
|
|
}
|
|
|
|
|
2013-01-24 19:30:31 +01:00
|
|
|
void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos)
|
|
|
|
{
|
|
|
|
const NSRect contentRect =
|
|
|
|
[window->ns.object contentRectForFrameRect:[window->ns.object frame]];
|
|
|
|
|
|
|
|
if (xpos)
|
|
|
|
*xpos = contentRect.origin.x;
|
|
|
|
if (ypos)
|
2013-05-22 21:37:41 +02:00
|
|
|
*ypos = transformY(contentRect.origin.y + contentRect.size.height);
|
2013-01-24 19:30:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y)
|
|
|
|
{
|
2013-07-09 17:08:26 +02:00
|
|
|
const NSRect contentRect = [window->ns.view frame];
|
|
|
|
const NSRect dummyRect = NSMakeRect(x, transformY(y + contentRect.size.height), 0, 0);
|
|
|
|
const NSRect frameRect = [window->ns.object frameRectForContentRect:dummyRect];
|
2013-01-24 19:30:31 +01:00
|
|
|
[window->ns.object setFrameOrigin:frameRect.origin];
|
|
|
|
}
|
|
|
|
|
2012-11-25 14:53:33 +01:00
|
|
|
void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height)
|
|
|
|
{
|
2013-06-04 01:51:40 +02:00
|
|
|
const NSRect contentRect = [window->ns.view frame];
|
2012-11-25 14:53:33 +01:00
|
|
|
|
|
|
|
if (width)
|
|
|
|
*width = contentRect.size.width;
|
|
|
|
if (height)
|
|
|
|
*height = contentRect.size.height;
|
|
|
|
}
|
|
|
|
|
2010-09-15 18:57:25 +02:00
|
|
|
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2015-01-19 02:37:15 +01:00
|
|
|
if (window->monitor)
|
2016-02-23 12:26:42 +01:00
|
|
|
{
|
|
|
|
if (window->monitor->window == window)
|
|
|
|
acquireMonitor(window);
|
|
|
|
}
|
2015-01-19 02:37:15 +01:00
|
|
|
else
|
|
|
|
[window->ns.object setContentSize:NSMakeSize(width, height)];
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2014-02-13 02:57:59 +01:00
|
|
|
void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window,
|
|
|
|
int minwidth, int minheight,
|
|
|
|
int maxwidth, int maxheight)
|
|
|
|
{
|
|
|
|
if (minwidth == GLFW_DONT_CARE || minheight == GLFW_DONT_CARE)
|
|
|
|
[window->ns.object setContentMinSize:NSMakeSize(0, 0)];
|
|
|
|
else
|
|
|
|
[window->ns.object setContentMinSize:NSMakeSize(minwidth, minheight)];
|
|
|
|
|
|
|
|
if (maxwidth == GLFW_DONT_CARE || maxheight == GLFW_DONT_CARE)
|
2016-03-16 15:05:50 +01:00
|
|
|
[window->ns.object setContentMaxSize:NSMakeSize(DBL_MAX, DBL_MAX)];
|
2014-02-13 02:57:59 +01:00
|
|
|
else
|
|
|
|
[window->ns.object setContentMaxSize:NSMakeSize(maxwidth, maxheight)];
|
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int numer, int denom)
|
|
|
|
{
|
|
|
|
if (numer == GLFW_DONT_CARE || denom == GLFW_DONT_CARE)
|
|
|
|
[window->ns.object setContentAspectRatio:NSMakeSize(0, 0)];
|
|
|
|
else
|
|
|
|
[window->ns.object setContentAspectRatio:NSMakeSize(numer, denom)];
|
|
|
|
}
|
|
|
|
|
2013-06-03 12:51:57 +02:00
|
|
|
void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height)
|
|
|
|
{
|
2013-06-16 18:32:16 +02:00
|
|
|
const NSRect contentRect = [window->ns.view frame];
|
2015-10-18 19:15:36 +02:00
|
|
|
const NSRect fbRect = [window->ns.view convertRectToBacking:contentRect];
|
2013-06-16 18:32:16 +02:00
|
|
|
|
|
|
|
if (width)
|
|
|
|
*width = (int) fbRect.size.width;
|
|
|
|
if (height)
|
|
|
|
*height = (int) fbRect.size.height;
|
2013-06-03 12:51:57 +02:00
|
|
|
}
|
|
|
|
|
2014-03-25 21:30:13 +01:00
|
|
|
void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
|
|
|
|
int* left, int* top,
|
|
|
|
int* right, int* bottom)
|
|
|
|
{
|
|
|
|
const NSRect contentRect = [window->ns.view frame];
|
|
|
|
const NSRect frameRect = [window->ns.object frameRectForContentRect:contentRect];
|
|
|
|
|
|
|
|
if (left)
|
|
|
|
*left = contentRect.origin.x - frameRect.origin.x;
|
|
|
|
if (top)
|
|
|
|
*top = frameRect.origin.y + frameRect.size.height -
|
|
|
|
contentRect.origin.y - contentRect.size.height;
|
|
|
|
if (right)
|
|
|
|
*right = frameRect.origin.x + frameRect.size.width -
|
|
|
|
contentRect.origin.x - contentRect.size.width;
|
|
|
|
if (bottom)
|
|
|
|
*bottom = contentRect.origin.y - frameRect.origin.y;
|
|
|
|
}
|
|
|
|
|
2010-09-15 18:57:25 +02:00
|
|
|
void _glfwPlatformIconifyWindow(_GLFWwindow* window)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
[window->ns.object miniaturize:nil];
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2010-09-15 18:57:25 +02:00
|
|
|
void _glfwPlatformRestoreWindow(_GLFWwindow* window)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2015-10-13 12:50:59 +02:00
|
|
|
if ([window->ns.object isMiniaturized])
|
|
|
|
[window->ns.object deminiaturize:nil];
|
|
|
|
else if ([window->ns.object isZoomed])
|
|
|
|
[window->ns.object zoom:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformMaximizeWindow(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
if (![window->ns.object isZoomed])
|
|
|
|
[window->ns.object zoom:nil];
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2012-08-21 20:01:57 +02:00
|
|
|
void _glfwPlatformShowWindow(_GLFWwindow* window)
|
2016-02-21 15:42:49 +01:00
|
|
|
{
|
|
|
|
[window->ns.object orderFront:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformHideWindow(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
[window->ns.object orderOut:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformFocusWindow(_GLFWwindow* window)
|
2012-08-21 20:01:57 +02:00
|
|
|
{
|
2013-11-07 18:07:46 +01:00
|
|
|
// Make us the active application
|
2013-11-10 13:56:27 +01:00
|
|
|
// HACK: This has been moved here from initializeAppKit to prevent
|
|
|
|
// applications using only hidden windows from being activated, but
|
|
|
|
// should probably not be done every time any window is shown
|
2013-11-07 18:07:46 +01:00
|
|
|
[NSApp activateIgnoringOtherApps:YES];
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
[window->ns.object makeKeyAndOrderFront:nil];
|
2012-08-21 20:01:57 +02:00
|
|
|
}
|
|
|
|
|
2016-02-23 12:26:42 +01:00
|
|
|
void _glfwPlatformSetWindowMonitor(_GLFWwindow* window,
|
|
|
|
_GLFWmonitor* monitor,
|
|
|
|
int xpos, int ypos,
|
|
|
|
int width, int height,
|
|
|
|
int refreshRate)
|
|
|
|
{
|
|
|
|
if (window->monitor == monitor)
|
|
|
|
{
|
|
|
|
if (monitor)
|
|
|
|
{
|
|
|
|
if (monitor->window == window)
|
|
|
|
acquireMonitor(window);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const NSRect contentRect =
|
|
|
|
NSMakeRect(xpos, transformY(ypos + height), width, height);
|
|
|
|
const NSRect frameRect =
|
|
|
|
[window->ns.object frameRectForContentRect:contentRect
|
|
|
|
styleMask:getStyleMask(window)];
|
|
|
|
|
|
|
|
[window->ns.object setFrame:frameRect display:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->monitor)
|
|
|
|
releaseMonitor(window);
|
|
|
|
|
|
|
|
_glfwInputWindowMonitorChange(window, monitor);
|
|
|
|
|
|
|
|
const NSUInteger styleMask = getStyleMask(window);
|
|
|
|
[window->ns.object setStyleMask:styleMask];
|
|
|
|
[window->ns.object makeFirstResponder:window->ns.view];
|
|
|
|
|
|
|
|
NSRect contentRect;
|
|
|
|
|
|
|
|
if (monitor)
|
|
|
|
{
|
|
|
|
GLFWvidmode mode;
|
|
|
|
|
|
|
|
_glfwPlatformGetVideoMode(window->monitor, &mode);
|
|
|
|
_glfwPlatformGetMonitorPos(window->monitor, &xpos, &ypos);
|
|
|
|
|
|
|
|
contentRect = NSMakeRect(xpos, transformY(ypos + mode.height),
|
|
|
|
mode.width, mode.height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
contentRect = NSMakeRect(xpos, transformY(ypos + height),
|
|
|
|
width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
NSRect frameRect = [window->ns.object frameRectForContentRect:contentRect
|
|
|
|
styleMask:styleMask];
|
|
|
|
[window->ns.object setFrame:frameRect display:YES];
|
|
|
|
|
|
|
|
if (monitor)
|
|
|
|
{
|
|
|
|
[window->ns.object setLevel:NSMainMenuWindowLevel + 1];
|
|
|
|
[window->ns.object setHasShadow:NO];
|
|
|
|
|
|
|
|
acquireMonitor(window);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (window->numer != GLFW_DONT_CARE &&
|
|
|
|
window->denom != GLFW_DONT_CARE)
|
|
|
|
{
|
|
|
|
[window->ns.object setContentAspectRatio:NSMakeSize(window->numer,
|
|
|
|
window->denom)];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->minwidth != GLFW_DONT_CARE &&
|
|
|
|
window->minheight != GLFW_DONT_CARE)
|
|
|
|
{
|
|
|
|
[window->ns.object setContentMinSize:NSMakeSize(window->minwidth,
|
|
|
|
window->minheight)];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->maxwidth != GLFW_DONT_CARE &&
|
|
|
|
window->maxheight != GLFW_DONT_CARE)
|
|
|
|
{
|
|
|
|
[window->ns.object setContentMaxSize:NSMakeSize(window->maxwidth,
|
|
|
|
window->maxheight)];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->floating)
|
|
|
|
[window->ns.object setLevel:NSFloatingWindowLevel];
|
|
|
|
else
|
|
|
|
[window->ns.object setLevel:NSNormalWindowLevel];
|
|
|
|
|
|
|
|
[window->ns.object setHasShadow:YES];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-26 12:25:48 +01:00
|
|
|
int _glfwPlatformWindowFocused(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
return [window->ns.object isKeyWindow];
|
|
|
|
}
|
|
|
|
|
|
|
|
int _glfwPlatformWindowIconified(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
return [window->ns.object isMiniaturized];
|
|
|
|
}
|
|
|
|
|
|
|
|
int _glfwPlatformWindowVisible(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
return [window->ns.object isVisible];
|
2012-08-21 20:01:57 +02:00
|
|
|
}
|
|
|
|
|
2015-10-13 12:50:59 +02:00
|
|
|
int _glfwPlatformWindowMaximized(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
return [window->ns.object isZoomed];
|
|
|
|
}
|
|
|
|
|
2010-09-15 18:57:25 +02:00
|
|
|
void _glfwPlatformPollEvents(void)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2012-10-21 16:17:20 +02:00
|
|
|
for (;;)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2012-10-21 16:17:20 +02:00
|
|
|
NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask
|
|
|
|
untilDate:[NSDate distantPast]
|
|
|
|
inMode:NSDefaultRunLoopMode
|
|
|
|
dequeue:YES];
|
|
|
|
if (event == nil)
|
|
|
|
break;
|
|
|
|
|
|
|
|
[NSApp sendEvent:event];
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
[_glfw.ns.autoreleasePool drain];
|
|
|
|
_glfw.ns.autoreleasePool = [[NSAutoreleasePool alloc] init];
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2012-10-05 05:42:47 +02:00
|
|
|
void _glfwPlatformWaitEvents(void)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
// I wanted to pass NO to dequeue:, and rely on PollEvents to
|
|
|
|
// dequeue and send. For reasons not at all clear to me, passing
|
|
|
|
// NO to dequeue: causes this method never to return.
|
|
|
|
NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask
|
|
|
|
untilDate:[NSDate distantFuture]
|
|
|
|
inMode:NSDefaultRunLoopMode
|
|
|
|
dequeue:YES];
|
|
|
|
[NSApp sendEvent:event];
|
|
|
|
|
|
|
|
_glfwPlatformPollEvents();
|
|
|
|
}
|
|
|
|
|
2016-02-02 21:11:16 +01:00
|
|
|
void _glfwPlatformWaitEventsTimeout(double timeout)
|
|
|
|
{
|
|
|
|
NSDate* date = [NSDate dateWithTimeIntervalSinceNow:timeout];
|
|
|
|
NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask
|
|
|
|
untilDate:date
|
|
|
|
inMode:NSDefaultRunLoopMode
|
|
|
|
dequeue:YES];
|
|
|
|
if (event)
|
|
|
|
[NSApp sendEvent:event];
|
|
|
|
|
|
|
|
_glfwPlatformPollEvents();
|
|
|
|
}
|
|
|
|
|
2014-02-10 18:16:58 +01:00
|
|
|
void _glfwPlatformPostEmptyEvent(void)
|
|
|
|
{
|
2014-10-21 07:41:58 +02:00
|
|
|
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
2014-02-10 18:16:58 +01:00
|
|
|
NSEvent* event = [NSEvent otherEventWithType:NSApplicationDefined
|
|
|
|
location:NSMakePoint(0, 0)
|
|
|
|
modifierFlags:0
|
|
|
|
timestamp:0
|
|
|
|
windowNumber:0
|
|
|
|
context:nil
|
|
|
|
subtype:0
|
|
|
|
data1:0
|
|
|
|
data2:0];
|
|
|
|
[NSApp postEvent:event atStart:YES];
|
2014-10-21 07:41:58 +02:00
|
|
|
[pool drain];
|
2014-02-10 18:16:58 +01:00
|
|
|
}
|
|
|
|
|
2014-02-11 18:24:01 +01:00
|
|
|
void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos)
|
|
|
|
{
|
|
|
|
const NSRect contentRect = [window->ns.view frame];
|
|
|
|
const NSPoint pos = [window->ns.object mouseLocationOutsideOfEventStream];
|
|
|
|
|
|
|
|
if (xpos)
|
|
|
|
*xpos = pos.x;
|
|
|
|
if (ypos)
|
|
|
|
*ypos = contentRect.size.height - pos.y - 1;
|
|
|
|
}
|
|
|
|
|
2013-03-28 00:30:08 +01:00
|
|
|
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2016-05-30 21:21:09 +02:00
|
|
|
updateCursorImage(window);
|
2013-10-09 19:03:47 +02:00
|
|
|
|
2014-02-11 18:24:01 +01:00
|
|
|
const NSRect contentRect = [window->ns.view frame];
|
|
|
|
const NSPoint pos = [window->ns.object mouseLocationOutsideOfEventStream];
|
|
|
|
|
2016-05-24 12:23:58 +02:00
|
|
|
window->ns.cursorWarpDeltaX += x - pos.x;
|
|
|
|
window->ns.cursorWarpDeltaY += y - contentRect.size.height + pos.y;
|
2014-02-11 18:24:01 +01:00
|
|
|
|
2012-09-27 21:37:36 +02:00
|
|
|
if (window->monitor)
|
2012-07-02 15:23:36 +02:00
|
|
|
{
|
2013-05-22 18:03:54 +02:00
|
|
|
CGDisplayMoveCursorToPoint(window->monitor->ns.displayID,
|
|
|
|
CGPointMake(x, y));
|
2012-07-02 15:23:36 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-17 19:38:32 +02:00
|
|
|
const NSRect localRect = NSMakeRect(x, contentRect.size.height - y - 1, 0, 0);
|
|
|
|
const NSRect globalRect = [window->ns.object convertRectToScreen:localRect];
|
|
|
|
const NSPoint globalPoint = globalRect.origin;
|
2013-05-22 18:03:54 +02:00
|
|
|
|
|
|
|
CGWarpMouseCursorPosition(CGPointMake(globalPoint.x,
|
|
|
|
transformY(globalPoint.y)));
|
2012-07-02 15:23:36 +02:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2015-07-02 13:04:56 +02:00
|
|
|
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
2011-09-06 17:38:00 +02:00
|
|
|
{
|
2015-07-02 13:04:56 +02:00
|
|
|
if (mode == GLFW_CURSOR_DISABLED)
|
2016-05-25 14:06:02 +02:00
|
|
|
{
|
2016-05-30 21:21:09 +02:00
|
|
|
_glfw.ns.disabledCursorWindow = window;
|
2016-05-25 14:06:02 +02:00
|
|
|
_glfwPlatformGetCursorPos(window,
|
|
|
|
&_glfw.ns.restoreCursorPosX,
|
|
|
|
&_glfw.ns.restoreCursorPosY);
|
|
|
|
centerCursor(window);
|
2013-04-22 00:38:51 +02:00
|
|
|
CGAssociateMouseAndMouseCursorPosition(false);
|
2016-05-25 14:06:02 +02:00
|
|
|
}
|
2016-05-30 21:21:09 +02:00
|
|
|
else if (_glfw.ns.disabledCursorWindow == window)
|
2016-05-25 14:06:02 +02:00
|
|
|
{
|
2016-05-30 21:21:09 +02:00
|
|
|
_glfw.ns.disabledCursorWindow = NULL;
|
2013-04-22 00:38:51 +02:00
|
|
|
CGAssociateMouseAndMouseCursorPosition(true);
|
2016-05-25 14:06:02 +02:00
|
|
|
_glfwPlatformSetCursorPos(window,
|
|
|
|
_glfw.ns.restoreCursorPosX,
|
|
|
|
_glfw.ns.restoreCursorPosY);
|
|
|
|
}
|
|
|
|
|
2016-05-30 21:21:09 +02:00
|
|
|
if (cursorInClientArea(window))
|
|
|
|
updateCursorImage(window);
|
2011-09-06 17:38:00 +02:00
|
|
|
}
|
|
|
|
|
2015-07-02 14:24:50 +02:00
|
|
|
const char* _glfwPlatformGetKeyName(int key, int scancode)
|
|
|
|
{
|
|
|
|
if (key != GLFW_KEY_UNKNOWN)
|
|
|
|
scancode = _glfw.ns.nativeKeys[key];
|
|
|
|
|
|
|
|
if (!_glfwIsPrintable(_glfw.ns.publicKeys[scancode]))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
UInt32 deadKeyState = 0;
|
|
|
|
UniChar characters[8];
|
|
|
|
UniCharCount characterCount = 0;
|
|
|
|
|
|
|
|
if (UCKeyTranslate([(NSData*) _glfw.ns.unicodeData bytes],
|
|
|
|
scancode,
|
|
|
|
kUCKeyActionDisplay,
|
|
|
|
0,
|
|
|
|
LMGetKbdType(),
|
|
|
|
kUCKeyTranslateNoDeadKeysBit,
|
|
|
|
&deadKeyState,
|
|
|
|
sizeof(characters) / sizeof(characters[0]),
|
|
|
|
&characterCount,
|
|
|
|
characters) != noErr)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!characterCount)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
CFStringRef string = CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault,
|
|
|
|
characters,
|
|
|
|
characterCount,
|
|
|
|
kCFAllocatorNull);
|
|
|
|
CFStringGetCString(string,
|
|
|
|
_glfw.ns.keyName,
|
|
|
|
sizeof(_glfw.ns.keyName),
|
|
|
|
kCFStringEncodingUTF8);
|
|
|
|
CFRelease(string);
|
|
|
|
|
|
|
|
return _glfw.ns.keyName;
|
|
|
|
}
|
|
|
|
|
2014-02-23 16:43:17 +01:00
|
|
|
int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
|
|
|
|
const GLFWimage* image,
|
|
|
|
int xhot, int yhot)
|
2013-12-04 14:19:22 +01:00
|
|
|
{
|
2014-02-23 16:43:17 +01:00
|
|
|
NSImage* native;
|
2013-12-04 14:19:22 +01:00
|
|
|
NSBitmapImageRep* rep;
|
|
|
|
|
2015-07-21 17:22:14 +02:00
|
|
|
if (!initializeAppKit())
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2015-07-21 17:22:14 +02:00
|
|
|
|
2013-12-04 14:19:22 +01:00
|
|
|
rep = [[NSBitmapImageRep alloc]
|
|
|
|
initWithBitmapDataPlanes:NULL
|
2014-02-23 16:43:17 +01:00
|
|
|
pixelsWide:image->width
|
|
|
|
pixelsHigh:image->height
|
2013-12-04 14:19:22 +01:00
|
|
|
bitsPerSample:8
|
|
|
|
samplesPerPixel:4
|
|
|
|
hasAlpha:YES
|
|
|
|
isPlanar:NO
|
|
|
|
colorSpaceName:NSCalibratedRGBColorSpace
|
|
|
|
bitmapFormat:NSAlphaNonpremultipliedBitmapFormat
|
2014-02-23 16:43:17 +01:00
|
|
|
bytesPerRow:image->width * 4
|
2013-12-04 14:19:22 +01:00
|
|
|
bitsPerPixel:32];
|
|
|
|
|
|
|
|
if (rep == nil)
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2013-12-04 14:19:22 +01:00
|
|
|
|
2014-02-23 16:43:17 +01:00
|
|
|
memcpy([rep bitmapData], image->pixels, image->width * image->height * 4);
|
2013-12-04 14:19:22 +01:00
|
|
|
|
2014-02-23 16:43:17 +01:00
|
|
|
native = [[NSImage alloc] initWithSize:NSMakeSize(image->width, image->height)];
|
|
|
|
[native addRepresentation: rep];
|
2013-12-04 14:19:22 +01:00
|
|
|
|
2014-02-23 16:43:17 +01:00
|
|
|
cursor->ns.object = [[NSCursor alloc] initWithImage:native
|
2014-01-23 15:24:57 +01:00
|
|
|
hotSpot:NSMakePoint(xhot, yhot)];
|
2013-12-04 14:19:22 +01:00
|
|
|
|
2014-02-23 16:43:17 +01:00
|
|
|
[native release];
|
2013-12-04 14:19:22 +01:00
|
|
|
[rep release];
|
|
|
|
|
2014-01-23 15:24:57 +01:00
|
|
|
if (cursor->ns.object == nil)
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2013-12-04 14:19:22 +01:00
|
|
|
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_TRUE;
|
2013-12-04 14:19:22 +01:00
|
|
|
}
|
|
|
|
|
2014-09-02 16:52:16 +02:00
|
|
|
int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
|
|
|
{
|
2015-07-21 17:22:14 +02:00
|
|
|
if (!initializeAppKit())
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2015-07-21 17:22:14 +02:00
|
|
|
|
2014-09-02 16:52:16 +02:00
|
|
|
cursor->ns.object = getStandardCursor(shape);
|
|
|
|
if (!cursor->ns.object)
|
|
|
|
{
|
2015-03-10 19:51:14 +01:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Cocoa: Failed to retrieve standard cursor");
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2014-09-02 16:52:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[cursor->ns.object retain];
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_TRUE;
|
2014-09-02 16:52:16 +02:00
|
|
|
}
|
|
|
|
|
2013-12-04 14:19:22 +01:00
|
|
|
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
|
|
|
|
{
|
2014-01-23 15:24:57 +01:00
|
|
|
if (cursor->ns.object)
|
|
|
|
[(NSCursor*) cursor->ns.object release];
|
2013-12-04 14:19:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor)
|
|
|
|
{
|
2016-05-30 21:21:09 +02:00
|
|
|
if (cursorInClientArea(window))
|
|
|
|
updateCursorImage(window);
|
2013-12-04 14:19:22 +01:00
|
|
|
}
|
|
|
|
|
2014-09-09 16:26:57 +02:00
|
|
|
void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)
|
|
|
|
{
|
|
|
|
NSArray* types = [NSArray arrayWithObjects:NSStringPboardType, nil];
|
|
|
|
|
|
|
|
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
|
|
|
|
[pasteboard declareTypes:types owner:nil];
|
|
|
|
[pasteboard setString:[NSString stringWithUTF8String:string]
|
|
|
|
forType:NSStringPboardType];
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
|
|
|
|
|
|
|
|
if (![[pasteboard types] containsObject:NSStringPboardType])
|
|
|
|
{
|
2015-03-10 19:51:14 +01:00
|
|
|
_glfwInputError(GLFW_FORMAT_UNAVAILABLE,
|
|
|
|
"Cocoa: Failed to retrieve string from pasteboard");
|
2014-09-09 16:26:57 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSString* object = [pasteboard stringForType:NSStringPboardType];
|
|
|
|
if (!object)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Cocoa: Failed to retrieve object from pasteboard");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(_glfw.ns.clipboardString);
|
|
|
|
_glfw.ns.clipboardString = strdup([object UTF8String]);
|
|
|
|
|
|
|
|
return _glfw.ns.clipboardString;
|
|
|
|
}
|
|
|
|
|
2016-03-23 10:24:01 +01:00
|
|
|
char** _glfwPlatformGetRequiredInstanceExtensions(uint32_t* count)
|
2015-08-10 20:19:04 +02:00
|
|
|
{
|
|
|
|
*count = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance,
|
|
|
|
VkPhysicalDevice device,
|
2016-03-23 10:24:01 +01:00
|
|
|
uint32_t queuefamily)
|
2015-08-10 20:19:04 +02:00
|
|
|
{
|
|
|
|
return GLFW_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
|
|
|
|
_GLFWwindow* window,
|
|
|
|
const VkAllocationCallbacks* allocator,
|
|
|
|
VkSurfaceKHR* surface)
|
|
|
|
{
|
|
|
|
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
|
|
|
}
|
|
|
|
|
2013-01-15 22:38:14 +01:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW native API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
GLFWAPI id glfwGetCocoaWindow(GLFWwindow* handle)
|
|
|
|
{
|
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
2013-02-20 00:28:08 +01:00
|
|
|
_GLFW_REQUIRE_INIT_OR_RETURN(nil);
|
2013-01-15 22:38:14 +01:00
|
|
|
return window->ns.object;
|
|
|
|
}
|
|
|
|
|