Mercurial > sdl-ios-xcode
changeset 4065:0c76e6d1c3d6 SDL-1.2
Fixed bug #373
Patch contributed from Transgaming's Cider project
- create a window and view in fullscreen mode so the cursor can be set
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 14 Jul 2007 08:00:50 +0000 |
parents | 940fddb81bea |
children | 58a5055da431 |
files | src/video/quartz/SDL_QuartzVideo.m src/video/quartz/SDL_QuartzWM.m |
diffstat | 2 files changed, 69 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/video/quartz/SDL_QuartzVideo.m Sat Jul 14 07:26:34 2007 +0000 +++ b/src/video/quartz/SDL_QuartzVideo.m Sat Jul 14 08:00:50 2007 +0000 @@ -367,6 +367,13 @@ SDL_free (sw_buffers[0]); } + /* If we still have a valid window, close it. */ + if ( qz_window ) { + [ qz_window close ]; + [ qz_window release ]; + qz_window = nil; + window_view = nil; + } /* Release the OpenGL context Do this first to avoid trash on the display before fade @@ -411,6 +418,8 @@ boolean_t exact_match = 0; NSRect screen_rect; CGError error; + NSRect contentRect; + BOOL isCustom = NO; CGDisplayFadeReservationToken fade_token = kCGDisplayFadeReservationInvalidToken; /* Fade to black to hide resolution-switching flicker (and garbage @@ -503,6 +512,59 @@ if ( CGDisplayCanSetPalette (display_id) ) current->flags |= SDL_HWPALETTE; + /* The code below checks for any valid custom windows and views. If none are + available, then we create new ones. Window/View code was added in FULLSCREEN + so that special events like the changing of the cursor image would be handled + ( only the front-most and active application can change the cursor appearance + and with no valid window/view in FULLSCREEN, SDL wouldn't update its cursor. ) + */ + /* Check for user-specified window and view */ + { + char *windowPtrString = getenv ("SDL_NSWindowPointer"); + char *viewPtrString = getenv ("SDL_NSQuickDrawViewPointer"); + + contentRect = NSMakeRect (0, 0, width, height); + + if (windowPtrString && viewPtrString) { + /* Release any previous window */ + if ( qz_window ) { + [ qz_window release ]; + qz_window = nil; + } + + qz_window = (NSWindow*)atoi(windowPtrString); + window_view = (NSQuickDrawView*)atoi(viewPtrString); + isCustom = YES; + /* + Retain reference to window because we + might release it in QZ_UnsetVideoMode + */ + [ qz_window retain ]; + } + } + /* Check if we should recreate the window */ + if (qz_window == nil) { + /* Manually create a window, avoids having a nib file resource */ + qz_window = [ [ SDL_QuartzWindow alloc ] + initWithContentRect:contentRect + styleMask:nil + backing:NSBackingStoreBuffered + defer:NO ]; + + if (qz_window != nil) { + [ qz_window setAcceptsMouseMovedEvents:YES ]; + [ qz_window setViewsNeedDisplay:NO ]; + } + } + /* We already have a window, just change its size */ + else { + if (!isCustom) { + [ qz_window setContentSize:contentRect.size ]; + current->flags |= (SDL_NOFRAME|SDL_RESIZABLE) & mode_flags; + [ window_view setFrameSize:contentRect.size ]; + } + } + /* Setup OpenGL for a fullscreen context */ if (flags & SDL_OPENGL) { @@ -513,6 +575,12 @@ goto ERR_NO_GL; } + /* Initialize the NSView and add it to our window. The presence of a valid window and + view allow the cursor to be changed whilst in fullscreen.*/ + window_view = [ [ NSView alloc ] initWithFrame:contentRect ]; + [ [ qz_window contentView ] addSubview:window_view ]; + [ window_view release ]; + ctx = [ gl_context cglContext ]; err = CGLSetFullScreen (ctx);
--- a/src/video/quartz/SDL_QuartzWM.m Sat Jul 14 07:26:34 2007 +0000 +++ b/src/video/quartz/SDL_QuartzWM.m Sat Jul 14 08:00:50 2007 +0000 @@ -105,7 +105,7 @@ } BOOL QZ_IsMouseInWindow (_THIS) { - if (qz_window == nil) return YES; /*fullscreen*/ + if (qz_window == nil || (mode_flags & SDL_FULLSCREEN)) return YES; /*fullscreen*/ else { NSPoint p = [ qz_window mouseLocationOutsideOfEventStream ]; p.y -= 1.0f; /* Apparently y goes from 1 to h, not from 0 to h-1 (i.e. the "location of the mouse" seems to be defined as "the location of the top left corner of the mouse pointer's hot pixel" */