mirror of
https://github.com/love2d/megasource.git
synced 2026-08-19 20:20:11 +02:00
Updated SDL2 to the latest Mercurial revision.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.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
|
||||
@@ -106,42 +106,64 @@
|
||||
|
||||
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
|
||||
{
|
||||
return NSDragOperationGeneric;
|
||||
if (([sender draggingSourceOperationMask] & NSDragOperationGeneric) == NSDragOperationGeneric) {
|
||||
return NSDragOperationGeneric;
|
||||
}
|
||||
|
||||
return NSDragOperationNone; /* no idea what to do with this, reject it. */
|
||||
}
|
||||
|
||||
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
|
||||
{ @autoreleasepool
|
||||
{
|
||||
NSURL *fileURL = [NSURL URLFromPasteboard:[sender draggingPasteboard]];
|
||||
NSNumber *isAlias = nil;
|
||||
NSPasteboard *pasteboard = [sender draggingPasteboard];
|
||||
NSArray *types = [NSArray arrayWithObject:NSFilenamesPboardType];
|
||||
NSString *desiredType = [pasteboard availableTypeFromArray:types];
|
||||
if (desiredType == nil) {
|
||||
return NO; /* can't accept anything that's being dropped here. */
|
||||
}
|
||||
|
||||
if (fileURL == nil) {
|
||||
NSData *data = [pasteboard dataForType:desiredType];
|
||||
if (data == nil) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
/* Functionality for resolving URL aliases was added with OS X 10.6. */
|
||||
if ([fileURL respondsToSelector:@selector(getResourceValue:forKey:error:)]) {
|
||||
[fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil];
|
||||
}
|
||||
SDL_assert([desiredType isEqualToString:NSFilenamesPboardType]);
|
||||
NSArray *array = [pasteboard propertyListForType:@"NSFilenamesPboardType"];
|
||||
|
||||
/* If the URL is an alias, resolve it. */
|
||||
if ([isAlias boolValue]) {
|
||||
NSURLBookmarkResolutionOptions opts = NSURLBookmarkResolutionWithoutMounting | NSURLBookmarkResolutionWithoutUI;
|
||||
NSData *bookmark = [NSURL bookmarkDataWithContentsOfURL:fileURL error:nil];
|
||||
if (bookmark != nil) {
|
||||
NSURL *resolvedURL = [NSURL URLByResolvingBookmarkData:bookmark
|
||||
options:opts
|
||||
relativeToURL:nil
|
||||
bookmarkDataIsStale:nil
|
||||
error:nil];
|
||||
for (NSString *path in array) {
|
||||
NSURL *fileURL = [[NSURL fileURLWithPath:path] autorelease];
|
||||
NSNumber *isAlias = nil;
|
||||
|
||||
if (resolvedURL != nil) {
|
||||
fileURL = resolvedURL;
|
||||
/* Functionality for resolving URL aliases was added with OS X 10.6. */
|
||||
if ([fileURL respondsToSelector:@selector(getResourceValue:forKey:error:)]) {
|
||||
[fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil];
|
||||
}
|
||||
|
||||
/* If the URL is an alias, resolve it. */
|
||||
if ([isAlias boolValue]) {
|
||||
NSURLBookmarkResolutionOptions opts = NSURLBookmarkResolutionWithoutMounting | NSURLBookmarkResolutionWithoutUI;
|
||||
NSData *bookmark = [NSURL bookmarkDataWithContentsOfURL:fileURL error:nil];
|
||||
if (bookmark != nil) {
|
||||
NSURL *resolvedURL = [NSURL URLByResolvingBookmarkData:bookmark
|
||||
options:opts
|
||||
relativeToURL:nil
|
||||
bookmarkDataIsStale:nil
|
||||
error:nil];
|
||||
|
||||
if (resolvedURL != nil) {
|
||||
fileURL = resolvedURL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!SDL_SendDropFile([[fileURL path] UTF8String])) {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
return (BOOL) SDL_SendDropFile([[fileURL path] UTF8String]);
|
||||
}
|
||||
return YES;
|
||||
}}
|
||||
|
||||
- (BOOL)wantsPeriodicDraggingUpdates
|
||||
{
|
||||
@@ -255,6 +277,7 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
|
||||
[center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
|
||||
[center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
|
||||
[center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
|
||||
[center addObserver:self selector:@selector(windowDidChangeBackingProperties:) name:NSWindowDidChangeBackingPropertiesNotification object:window];
|
||||
[center addObserver:self selector:@selector(windowWillEnterFullScreen:) name:NSWindowWillEnterFullScreenNotification object:window];
|
||||
[center addObserver:self selector:@selector(windowDidEnterFullScreen:) name:NSWindowDidEnterFullScreenNotification object:window];
|
||||
[center addObserver:self selector:@selector(windowWillExitFullScreen:) name:NSWindowWillExitFullScreenNotification object:window];
|
||||
@@ -374,7 +397,6 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
|
||||
NSNotificationCenter *center;
|
||||
NSWindow *window = _data->nswindow;
|
||||
NSView *view = [window contentView];
|
||||
NSArray *windows = nil;
|
||||
|
||||
center = [NSNotificationCenter defaultCenter];
|
||||
|
||||
@@ -386,6 +408,7 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
|
||||
[center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
|
||||
[center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
|
||||
[center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
|
||||
[center removeObserver:self name:NSWindowDidChangeBackingPropertiesNotification object:window];
|
||||
[center removeObserver:self name:NSWindowWillEnterFullScreenNotification object:window];
|
||||
[center removeObserver:self name:NSWindowDidEnterFullScreenNotification object:window];
|
||||
[center removeObserver:self name:NSWindowWillExitFullScreenNotification object:window];
|
||||
@@ -402,25 +425,6 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
|
||||
if ([view nextResponder] == self) {
|
||||
[view setNextResponder:nil];
|
||||
}
|
||||
|
||||
/* Make the next window in the z-order Key. If we weren't the foreground
|
||||
when closed, this is a no-op.
|
||||
!!! FIXME: Note that this is a hack, and there are corner cases where
|
||||
!!! FIXME: this fails (such as the About box). The typical nib+RunLoop
|
||||
!!! FIXME: handles this for Cocoa apps, but we bypass all that in SDL.
|
||||
!!! FIXME: We should remove this code when we find a better way to
|
||||
!!! FIXME: have the system do this for us. See discussion in
|
||||
!!! FIXME: http://bugzilla.libsdl.org/show_bug.cgi?id=1825
|
||||
*/
|
||||
windows = [NSApp orderedWindows];
|
||||
for (NSWindow *win in windows) {
|
||||
if (win == window) {
|
||||
continue;
|
||||
}
|
||||
|
||||
[win makeKeyAndOrderFront:self];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)isMoving
|
||||
@@ -551,13 +555,15 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
|
||||
{
|
||||
SDL_Window *window = _data->window;
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
/* We're going to get keyboard events, since we're key. */
|
||||
/* This needs to be done before restoring the relative mouse mode. */
|
||||
SDL_SetKeyboardFocus(window);
|
||||
|
||||
if (mouse->relative_mode && !mouse->relative_mode_warp && ![self isMoving]) {
|
||||
mouse->SetRelativeMouseMode(SDL_TRUE);
|
||||
}
|
||||
|
||||
/* We're going to get keyboard events, since we're key. */
|
||||
SDL_SetKeyboardFocus(window);
|
||||
|
||||
/* If we just gained focus we need the updated mouse position */
|
||||
if (!mouse->relative_mode) {
|
||||
NSPoint point;
|
||||
@@ -602,6 +608,22 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
|
||||
}
|
||||
}
|
||||
|
||||
- (void)windowDidChangeBackingProperties:(NSNotification *)aNotification
|
||||
{
|
||||
NSNumber *oldscale = [[aNotification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey];
|
||||
|
||||
if (inFullscreenTransition) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ([oldscale doubleValue] != [_data->nswindow backingScaleFactor]) {
|
||||
/* Force a resize event when the backing scale factor changes. */
|
||||
_data->window->w = 0;
|
||||
_data->window->h = 0;
|
||||
[self windowDidResize:aNotification];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)windowWillEnterFullScreen:(NSNotification *)aNotification
|
||||
{
|
||||
SDL_Window *window = _data->window;
|
||||
@@ -751,6 +773,14 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
|
||||
{
|
||||
int button;
|
||||
|
||||
/* Ignore events that aren't inside the client area (i.e. title bar.) */
|
||||
if ([theEvent window]) {
|
||||
const NSRect windowRect = [[[theEvent window] contentView] frame];
|
||||
if (!NSPointInRect([theEvent locationInWindow], windowRect)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ([self processHitTest:theEvent]) {
|
||||
return; /* dragging, drop event. */
|
||||
}
|
||||
@@ -951,10 +981,8 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
|
||||
|
||||
for (NSTouch *touch in touches) {
|
||||
const SDL_TouchID touchId = (SDL_TouchID)(intptr_t)[touch device];
|
||||
if (!SDL_GetTouch(touchId)) {
|
||||
if (SDL_AddTouch(touchId, "") < 0) {
|
||||
return;
|
||||
}
|
||||
if (SDL_AddTouch(touchId, "") < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const SDL_FingerID fingerId = (SDL_FingerID)(intptr_t)[touch identity];
|
||||
@@ -982,14 +1010,29 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
|
||||
|
||||
@end
|
||||
|
||||
@interface SDLView : NSView
|
||||
@interface SDLView : NSView {
|
||||
SDL_Window *_sdlWindow;
|
||||
}
|
||||
|
||||
- (void)setSDLWindow:(SDL_Window*)window;
|
||||
|
||||
/* The default implementation doesn't pass rightMouseDown to responder chain */
|
||||
- (void)rightMouseDown:(NSEvent *)theEvent;
|
||||
- (BOOL)mouseDownCanMoveWindow;
|
||||
- (void)drawRect:(NSRect)dirtyRect;
|
||||
@end
|
||||
|
||||
@implementation SDLView
|
||||
- (void)setSDLWindow:(SDL_Window*)window
|
||||
{
|
||||
_sdlWindow = window;
|
||||
}
|
||||
|
||||
- (void)drawRect:(NSRect)dirtyRect
|
||||
{
|
||||
SDL_SendWindowEvent(_sdlWindow, SDL_WINDOWEVENT_EXPOSED, 0, 0);
|
||||
}
|
||||
|
||||
- (void)rightMouseDown:(NSEvent *)theEvent
|
||||
{
|
||||
[[self nextResponder] rightMouseDown:theEvent];
|
||||
@@ -1020,8 +1063,8 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
|
||||
|
||||
static int
|
||||
SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
|
||||
SDL_WindowData *data;
|
||||
|
||||
@@ -1036,8 +1079,6 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
|
||||
data->videodata = videodata;
|
||||
data->nscontexts = [[NSMutableArray alloc] init];
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
/* Create an event listener for the window */
|
||||
data->listener = [[Cocoa_WindowListener alloc] init];
|
||||
|
||||
@@ -1099,16 +1140,15 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
|
||||
[nswindow setOneShot:NO];
|
||||
|
||||
/* All done! */
|
||||
[pool release];
|
||||
window->driverdata = data;
|
||||
return 0;
|
||||
}
|
||||
}}
|
||||
|
||||
int
|
||||
Cocoa_CreateWindow(_THIS, SDL_Window * window)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSWindow *nswindow;
|
||||
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
||||
NSRect rect;
|
||||
@@ -1143,9 +1183,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
|
||||
nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO screen:screen];
|
||||
}
|
||||
@catch (NSException *e) {
|
||||
SDL_SetError("%s", [[e reason] UTF8String]);
|
||||
[pool release];
|
||||
return -1;
|
||||
return SDL_SetError("%s", [[e reason] UTF8String]);
|
||||
}
|
||||
[nswindow setBackgroundColor:[NSColor blackColor]];
|
||||
|
||||
@@ -1161,7 +1199,8 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
|
||||
|
||||
/* Create a default view for this window */
|
||||
rect = [nswindow contentRectForFrameRect:[nswindow frame]];
|
||||
NSView *contentView = [[SDLView alloc] initWithFrame:rect];
|
||||
SDLView *contentView = [[SDLView alloc] initWithFrame:rect];
|
||||
[contentView setSDLWindow:window];
|
||||
|
||||
if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
|
||||
if ([contentView respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) {
|
||||
@@ -1175,70 +1214,55 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
|
||||
/* Allow files and folders to be dragged onto the window by users */
|
||||
[nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
|
||||
|
||||
[pool release];
|
||||
|
||||
if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
|
||||
[nswindow release];
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}}
|
||||
|
||||
int
|
||||
Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
NSWindow *nswindow = (NSWindow *) data;
|
||||
NSString *title;
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
/* Query the title from the existing window */
|
||||
title = [nswindow title];
|
||||
if (title) {
|
||||
window->title = SDL_strdup([title UTF8String]);
|
||||
}
|
||||
|
||||
[pool release];
|
||||
|
||||
return SetupWindowData(_this, window, nswindow, SDL_FALSE);
|
||||
}
|
||||
}}
|
||||
|
||||
void
|
||||
Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
const char *title = window->title ? window->title : "";
|
||||
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
||||
NSString *string;
|
||||
|
||||
if(window->title) {
|
||||
string = [[NSString alloc] initWithUTF8String:window->title];
|
||||
} else {
|
||||
string = [[NSString alloc] init];
|
||||
}
|
||||
NSString *string = [[NSString alloc] initWithUTF8String:title];
|
||||
[nswindow setTitle:string];
|
||||
[string release];
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}}
|
||||
|
||||
void
|
||||
Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSImage *nsimage = Cocoa_CreateImage(icon);
|
||||
|
||||
if (nsimage) {
|
||||
[NSApp setApplicationIconImage:nsimage];
|
||||
}
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}}
|
||||
|
||||
void
|
||||
Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
|
||||
NSWindow *nswindow = windata->nswindow;
|
||||
NSRect rect;
|
||||
@@ -1256,31 +1280,29 @@ Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
|
||||
s_moveHack = moveHack;
|
||||
|
||||
ScheduleContextUpdates(windata);
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}}
|
||||
|
||||
void
|
||||
Cocoa_SetWindowSize(_THIS, SDL_Window * window)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
|
||||
NSWindow *nswindow = windata->nswindow;
|
||||
NSSize size;
|
||||
|
||||
size.width = window->w;
|
||||
size.height = window->h;
|
||||
[nswindow setContentSize:size];
|
||||
NSRect frame = [nswindow frame];
|
||||
frame.origin.y = (frame.origin.y + frame.size.height) - ((float) window->h);
|
||||
frame.size.width = window->w;
|
||||
frame.size.height = window->h;
|
||||
|
||||
[nswindow setFrame:frame display:YES];
|
||||
|
||||
ScheduleContextUpdates(windata);
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}}
|
||||
|
||||
void
|
||||
Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
|
||||
|
||||
NSSize minSize;
|
||||
@@ -1288,14 +1310,12 @@ Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
|
||||
minSize.height = window->min_h;
|
||||
|
||||
[windata->nswindow setContentMinSize:minSize];
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}}
|
||||
|
||||
void
|
||||
Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
|
||||
|
||||
NSSize maxSize;
|
||||
@@ -1303,14 +1323,12 @@ Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
|
||||
maxSize.height = window->max_h;
|
||||
|
||||
[windata->nswindow setContentMaxSize:maxSize];
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}}
|
||||
|
||||
void
|
||||
Cocoa_ShowWindow(_THIS, SDL_Window * window)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
|
||||
NSWindow *nswindow = windowData->nswindow;
|
||||
|
||||
@@ -1319,23 +1337,21 @@ Cocoa_ShowWindow(_THIS, SDL_Window * window)
|
||||
[nswindow makeKeyAndOrderFront:nil];
|
||||
[windowData->listener resumeVisibleObservation];
|
||||
}
|
||||
[pool release];
|
||||
}
|
||||
}}
|
||||
|
||||
void
|
||||
Cocoa_HideWindow(_THIS, SDL_Window * window)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
||||
|
||||
[nswindow orderOut:nil];
|
||||
[pool release];
|
||||
}
|
||||
}}
|
||||
|
||||
void
|
||||
Cocoa_RaiseWindow(_THIS, SDL_Window * window)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
|
||||
NSWindow *nswindow = windowData->nswindow;
|
||||
|
||||
@@ -1348,28 +1364,24 @@ Cocoa_RaiseWindow(_THIS, SDL_Window * window)
|
||||
[nswindow makeKeyAndOrderFront:nil];
|
||||
}
|
||||
[windowData->listener resumeVisibleObservation];
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}}
|
||||
|
||||
void
|
||||
Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
|
||||
NSWindow *nswindow = windata->nswindow;
|
||||
|
||||
[nswindow zoom:nil];
|
||||
|
||||
ScheduleContextUpdates(windata);
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}}
|
||||
|
||||
void
|
||||
Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||
NSWindow *nswindow = data->nswindow;
|
||||
|
||||
@@ -1378,13 +1390,12 @@ Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
|
||||
} else {
|
||||
[nswindow miniaturize:nil];
|
||||
}
|
||||
[pool release];
|
||||
}
|
||||
}}
|
||||
|
||||
void
|
||||
Cocoa_RestoreWindow(_THIS, SDL_Window * window)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
||||
|
||||
if ([nswindow isMiniaturized]) {
|
||||
@@ -1392,8 +1403,7 @@ Cocoa_RestoreWindow(_THIS, SDL_Window * window)
|
||||
} else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
|
||||
[nswindow zoom:nil];
|
||||
}
|
||||
[pool release];
|
||||
}
|
||||
}}
|
||||
|
||||
static NSWindow *
|
||||
Cocoa_RebuildWindow(SDL_WindowData * data, NSWindow * nswindow, unsigned style)
|
||||
@@ -1418,21 +1428,20 @@ Cocoa_RebuildWindow(SDL_WindowData * data, NSWindow * nswindow, unsigned style)
|
||||
|
||||
void
|
||||
Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
if (SetWindowStyle(window, GetWindowStyle(window))) {
|
||||
if (bordered) {
|
||||
Cocoa_SetWindowTitle(_this, window); /* this got blanked out. */
|
||||
}
|
||||
}
|
||||
[pool release];
|
||||
}
|
||||
}}
|
||||
|
||||
|
||||
void
|
||||
Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||
NSWindow *nswindow = data->nswindow;
|
||||
NSRect rect;
|
||||
@@ -1472,6 +1481,11 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display
|
||||
|
||||
if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
|
||||
[nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];
|
||||
|
||||
/* Hack to restore window decorations on Mac OS X 10.10 */
|
||||
NSRect frameRect = [nswindow frame];
|
||||
[nswindow setFrame:NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width + 1, frameRect.size.height) display:NO];
|
||||
[nswindow setFrame:frameRect display:NO];
|
||||
} else {
|
||||
nswindow = Cocoa_RebuildWindow(data, nswindow, GetWindowStyle(window));
|
||||
}
|
||||
@@ -1506,9 +1520,7 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display
|
||||
}
|
||||
|
||||
ScheduleContextUpdates(data);
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}}
|
||||
|
||||
int
|
||||
Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
|
||||
@@ -1591,8 +1603,8 @@ Cocoa_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
|
||||
|
||||
void
|
||||
Cocoa_DestroyWindow(_THIS, SDL_Window * window)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||
|
||||
if (data) {
|
||||
@@ -1612,9 +1624,7 @@ Cocoa_DestroyWindow(_THIS, SDL_Window * window)
|
||||
SDL_free(data);
|
||||
}
|
||||
window->driverdata = NULL;
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}}
|
||||
|
||||
SDL_bool
|
||||
Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
|
||||
@@ -1646,9 +1656,9 @@ Cocoa_IsWindowInFullscreenSpace(SDL_Window * window)
|
||||
|
||||
SDL_bool
|
||||
Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
SDL_bool succeeded = SDL_FALSE;
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||
|
||||
if ([data->listener setFullscreenSpace:(state ? YES : NO)]) {
|
||||
@@ -1669,10 +1679,8 @@ Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state)
|
||||
}
|
||||
}
|
||||
|
||||
[pool release];
|
||||
|
||||
return succeeded;
|
||||
}
|
||||
}}
|
||||
|
||||
int
|
||||
Cocoa_SetWindowHitTest(SDL_Window * window, SDL_bool enabled)
|
||||
|
||||
Reference in New Issue
Block a user