src/video/quartz/SDL_QuartzVideo.m
author Ryan C. Gordon <icculus@icculus.org>
Tue, 23 Aug 2011 06:04:54 -0400
branchSDL-1.2
changeset 5639 72659c5c8616
parent 5628 f78f29271dfd
child 5645 80e036f88a6e
permissions -rw-r--r--
Cleaned up Snow Leopard display mode rework.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     1
/*
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
4159
a1b03ba2fcd0 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 4139
diff changeset
     3
    Copyright (C) 1997-2009  Sam Lantinga
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     4
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     6
    modify it under the terms of the GNU Library General Public
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     8
    version 2 of the License, or (at your option) any later version.
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     9
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    13
    Library General Public License for more details.
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    14
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    15
    You should have received a copy of the GNU Library General Public
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    16
    License along with this library; if not, write to the Free
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    18
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    19
    Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 197
diff changeset
    20
    slouken@libsdl.org
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    21
*/
1403
376665398b25 Catch the C++ and Objective C sources too...
Sam Lantinga <slouken@libsdl.org>
parents: 1340
diff changeset
    22
#include "SDL_config.h"
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    23
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    24
#include "SDL_QuartzVideo.h"
761
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    25
#include "SDL_QuartzWindow.h"
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    26
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
    27
/* Fixed in Snow Leopard */
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
    28
#if __MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    29
/*
761
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    30
    Add methods to get at private members of NSScreen. 
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    31
    Since there is a bug in Apple's screen switching code
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    32
    that does not update this variable when switching
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    33
    to fullscreen, we'll set it manually (but only for the
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    34
    main screen).
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    35
*/
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    36
@interface NSScreen (NSScreenAccess)
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    37
- (void) setFrame:(NSRect)frame;
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    38
@end
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    39
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    40
@implementation NSScreen (NSScreenAccess)
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    41
- (void) setFrame:(NSRect)frame;
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    42
{
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    43
    _frame = frame;
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    44
}
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    45
@end
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    46
static inline void QZ_SetFrame(NSScreen *nsscreen, NSRect frame)
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    47
{
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    48
    [nsscreen setFrame:frame];
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    49
}
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    50
#else
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    51
static inline void QZ_SetFrame(NSScreen *nsscreen, NSRect frame)
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    52
{
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    53
}
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    54
#endif
761
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    55
4123
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    56
@interface SDLTranslatorResponder : NSTextView
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    57
{
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    58
}
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    59
- (void) doCommandBySelector:(SEL)myselector;
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    60
@end
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    61
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    62
@implementation SDLTranslatorResponder
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    63
- (void) doCommandBySelector:(SEL) myselector {}
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    64
@end
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
    65
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    66
/* absent in 10.3.9.  */
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    67
CG_EXTERN CGImageRef CGBitmapContextCreateImage (CGContextRef);
761
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    68
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    69
/* Bootstrap functions */
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    70
static int              QZ_Available ();
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    71
static SDL_VideoDevice* QZ_CreateDevice (int device_index);
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    72
static void             QZ_DeleteDevice (SDL_VideoDevice *device);
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    73
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    74
/* Initialization, Query, Setup, and Redrawing functions */
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    75
static int          QZ_VideoInit        (_THIS, SDL_PixelFormat *video_format);
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    76
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    77
static SDL_Rect**   QZ_ListModes        (_THIS, SDL_PixelFormat *format,
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    78
                                         Uint32 flags);
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
    79
static void         QZ_UnsetVideoMode   (_THIS, BOOL to_desktop);
761
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    80
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    81
static SDL_Surface* QZ_SetVideoMode     (_THIS, SDL_Surface *current,
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    82
                                         int width, int height, int bpp,
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    83
                                         Uint32 flags);
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    84
static int          QZ_ToggleFullScreen (_THIS, int on);
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    85
static int          QZ_SetColors        (_THIS, int first_color,
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    86
                                         int num_colors, SDL_Color *colors);
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    87
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    88
static void         QZ_UpdateRects      (_THIS, int num_rects, SDL_Rect *rects);
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    89
static void         QZ_VideoQuit        (_THIS);
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    90
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    91
static int  QZ_LockHWSurface(_THIS, SDL_Surface *surface);
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    92
static void QZ_UnlockHWSurface(_THIS, SDL_Surface *surface);
1120
8e1fde455471 Patch by me to fix crash described below.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
    93
static int QZ_AllocHWSurface(_THIS, SDL_Surface *surface);
761
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
    94
static void QZ_FreeHWSurface (_THIS, SDL_Surface *surface);
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    95
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    96
/* Bootstrap binding, enables entry point into the driver */
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    97
VideoBootStrap QZ_bootstrap = {
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
    98
    "Quartz", "Mac OS X CoreGraphics", QZ_Available, QZ_CreateDevice
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    99
};
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   100
588
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   101
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   102
/* !!! FIXME: clean out the pre-10.6 code when it makes sense to do so. */
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   103
#define FORCE_OLD_API 0 || (MAC_OS_X_VERSION_MAX_ALLOWED < 1060)
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   104
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   105
#if FORCE_OLD_API
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   106
#undef MAC_OS_X_VERSION_MIN_REQUIRED
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   107
#define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_5
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   108
#endif
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   109
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   110
static inline BOOL IS_SNOW_LEOPARD_OR_LATER(_THIS)
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   111
{
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   112
#if FORCE_OLD_API
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   113
    return NO;
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   114
#else
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   115
    return (system_version >= 0x1060);
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   116
#endif
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   117
}
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   118
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   119
static void QZ_ReleaseDisplayMode(_THIS, const void *moderef)
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   120
{
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   121
    /* we only own these references in the 10.6+ API. */
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   122
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   123
    if (IS_SNOW_LEOPARD_OR_LATER(this)) {
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   124
        CGDisplayModeRelease((CGDisplayModeRef) moderef);
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   125
    }
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   126
#endif
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   127
}
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   128
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   129
static void QZ_ReleaseDisplayModeList(_THIS, CFArrayRef mode_list)
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   130
{
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   131
    /* we only own these references in the 10.6+ API. */
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   132
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   133
    if (IS_SNOW_LEOPARD_OR_LATER(this)) {
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   134
        CFRelease(mode_list);
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   135
    }
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   136
#endif
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   137
}
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   138
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   139
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   140
/* Bootstrap functions */
4317
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   141
static int QZ_Available ()
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   142
{
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   143
    return 1;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   144
}
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   145
4317
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   146
static SDL_VideoDevice* QZ_CreateDevice (int device_index)
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   147
{
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   148
#pragma unused (device_index)
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   149
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   150
    SDL_VideoDevice *device;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   151
    SDL_PrivateVideoData *hidden;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   152
1756
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   153
    device = (SDL_VideoDevice*) SDL_malloc (sizeof (*device) );
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   154
    hidden = (SDL_PrivateVideoData*) SDL_malloc (sizeof (*hidden) );
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   155
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   156
    if (device == NULL || hidden == NULL)
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   157
        SDL_OutOfMemory ();
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   158
1756
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   159
    SDL_memset (device, 0, sizeof (*device) );
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   160
    SDL_memset (hidden, 0, sizeof (*hidden) );
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   161
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   162
    device->hidden = hidden;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   163
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   164
    device->VideoInit        = QZ_VideoInit;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   165
    device->ListModes        = QZ_ListModes;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   166
    device->SetVideoMode     = QZ_SetVideoMode;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   167
    device->ToggleFullScreen = QZ_ToggleFullScreen;
1212
7663bb0f52c7 To: sdl@libsdl.org
Ryan C. Gordon <icculus@icculus.org>
parents: 1189
diff changeset
   168
    device->UpdateMouse      = QZ_UpdateMouse;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   169
    device->SetColors        = QZ_SetColors;
5569
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   170
    device->UpdateRects      = QZ_UpdateRects;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   171
    device->VideoQuit        = QZ_VideoQuit;
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   172
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   173
    device->LockHWSurface   = QZ_LockHWSurface;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   174
    device->UnlockHWSurface = QZ_UnlockHWSurface;
1120
8e1fde455471 Patch by me to fix crash described below.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   175
    device->AllocHWSurface   = QZ_AllocHWSurface;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   176
    device->FreeHWSurface   = QZ_FreeHWSurface;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   177
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   178
    device->SetGamma     = QZ_SetGamma;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   179
    device->GetGamma     = QZ_GetGamma;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   180
    device->SetGammaRamp = QZ_SetGammaRamp;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   181
    device->GetGammaRamp = QZ_GetGammaRamp;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   182
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   183
    device->GL_GetProcAddress = QZ_GL_GetProcAddress;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   184
    device->GL_GetAttribute   = QZ_GL_GetAttribute;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   185
    device->GL_MakeCurrent    = QZ_GL_MakeCurrent;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   186
    device->GL_SwapBuffers    = QZ_GL_SwapBuffers;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   187
    device->GL_LoadLibrary    = QZ_GL_LoadLibrary;
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   188
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   189
    device->FreeWMCursor   = QZ_FreeWMCursor;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   190
    device->CreateWMCursor = QZ_CreateWMCursor;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   191
    device->ShowWMCursor   = QZ_ShowWMCursor;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   192
    device->WarpWMCursor   = QZ_WarpWMCursor;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   193
    device->MoveWMCursor   = QZ_MoveWMCursor;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   194
    device->CheckMouseMode = QZ_CheckMouseMode;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   195
    device->InitOSKeymap   = QZ_InitOSKeymap;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   196
    device->PumpEvents     = QZ_PumpEvents;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   197
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   198
    device->SetCaption    = QZ_SetCaption;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   199
    device->SetIcon       = QZ_SetIcon;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   200
    device->IconifyWindow = QZ_IconifyWindow;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   201
    /*device->GetWMInfo     = QZ_GetWMInfo;*/
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   202
    device->GrabInput     = QZ_GrabInput;
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   203
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   204
    /*
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   205
     * This is a big hassle, needing QuickDraw and QuickTime on older
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   206
     *  systems, and god knows what on 10.6, so we immediately fail here,
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   207
     *  which causes SDL to make an RGB surface and manage the YUV overlay
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   208
     *  in software. Sorry. Use SDL 1.3 if you want YUV rendering in a pixel
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   209
     *  shader.  :)
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   210
     */
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   211
    /*device->CreateYUVOverlay = QZ_CreateYUVOverlay;*/
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   212
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   213
    device->free             = QZ_DeleteDevice;
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   214
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   215
    return device;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   216
}
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   217
4317
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   218
static void QZ_DeleteDevice (SDL_VideoDevice *device)
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   219
{
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   220
    _THIS = device;
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   221
    QZ_ReleaseDisplayMode(this, save_mode);
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   222
    QZ_ReleaseDisplayMode(this, mode);
1756
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   223
    SDL_free (device->hidden);
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   224
    SDL_free (device);
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   225
}
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   226
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   227
static void QZ_GetModeInfo(_THIS, const void *_mode, Uint32 *w, Uint32 *h, Uint32 *bpp)
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   228
{
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   229
    *w = *h = *bpp = 0;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   230
    if (_mode == NULL) {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   231
        return;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   232
    }
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   233
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   234
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   235
    if (IS_SNOW_LEOPARD_OR_LATER(this)) {
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   236
        CGDisplayModeRef vidmode = (CGDisplayModeRef) _mode;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   237
        CFStringRef fmt = CGDisplayModeCopyPixelEncoding(vidmode);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   238
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   239
        *w = (Uint32) CGDisplayModeGetWidth(vidmode);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   240
        *h = (Uint32) CGDisplayModeGetHeight(vidmode);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   241
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   242
        /* we only care about the 32-bit modes... */
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   243
        if (CFStringCompare(fmt, CFSTR(IO32BitDirectPixels),
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   244
                            kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   245
            *bpp = 32;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   246
        }
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   247
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   248
        CFRelease(fmt);
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   249
    }
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   250
#endif
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   251
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   252
#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6)
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   253
    if (!IS_SNOW_LEOPARD_OR_LATER(this)) {
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   254
        CFDictionaryRef vidmode = (CFDictionaryRef) _mode;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   255
        CFNumberGetValue (
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   256
            CFDictionaryGetValue (vidmode, kCGDisplayBitsPerPixel),
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   257
            kCFNumberSInt32Type, bpp);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   258
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   259
        CFNumberGetValue (
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   260
            CFDictionaryGetValue (vidmode, kCGDisplayWidth),
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   261
            kCFNumberSInt32Type, w);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   262
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   263
        CFNumberGetValue (
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   264
            CFDictionaryGetValue (vidmode, kCGDisplayHeight),
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   265
            kCFNumberSInt32Type, h);
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   266
    }
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   267
#endif
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   268
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   269
    /* we only care about the 32-bit modes... */
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   270
    if (*bpp != 32) {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   271
        *bpp = 0;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   272
    }
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   273
}
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   274
4317
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   275
static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format)
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   276
{
4049
60f677630282 Added key composition support, courtesy of Kuon
Sam Lantinga <slouken@libsdl.org>
parents: 3936
diff changeset
   277
    NSRect r = NSMakeRect(0.0, 0.0, 0.0, 0.0);
3936
c5c3c772f5aa Let app set SDL_VIDEO_ALLOW_SCREENSAVER environment variable to override SDL's
Ryan C. Gordon <icculus@icculus.org>
parents: 3877
diff changeset
   278
    const char *env = NULL;
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   279
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   280
    if ( Gestalt(gestaltSystemVersion, &system_version) != noErr )
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   281
        system_version = 0;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   282
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   283
    /* Initialize the video settings; this data persists between mode switches */
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   284
    display_id = kCGDirectMainDisplay;
4317
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   285
4319
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   286
#if 0 /* The mouse event code needs to take this into account... */
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   287
    env = getenv("SDL_VIDEO_FULLSCREEN_DISPLAY");
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   288
    if ( env ) {
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   289
        int monitor = SDL_atoi(env);
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   290
    	CGDirectDisplayID activeDspys [3];
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   291
    	CGDisplayCount dspyCnt;
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   292
    	CGGetActiveDisplayList (3, activeDspys, &dspyCnt);
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   293
        if ( monitor >= 0 && monitor < dspyCnt ) {
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   294
    	    display_id = activeDspys[monitor];
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   295
        }
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   296
    }
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   297
#endif
edefeb52a627 Added support for SDL_VIDEO_FULLSCREEN_DISPLAY, but mouse events need to be fixed up.
Sam Lantinga <slouken@libsdl.org>
parents: 4317
diff changeset
   298
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   299
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   300
    if (IS_SNOW_LEOPARD_OR_LATER(this)) {
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   301
        save_mode = CGDisplayCopyDisplayMode(display_id);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   302
    }
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   303
#endif
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   304
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   305
#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6)
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   306
    if (!IS_SNOW_LEOPARD_OR_LATER(this)) {
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   307
        save_mode = CGDisplayCurrentMode(display_id);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   308
    }
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   309
#endif
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   310
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   311
    if (save_mode == NULL) {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   312
        SDL_SetError("Couldn't figure out current display mode.");
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   313
        return -1;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   314
    }
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   315
4139
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   316
    /* Allow environment override of screensaver disable. */
3936
c5c3c772f5aa Let app set SDL_VIDEO_ALLOW_SCREENSAVER environment variable to override SDL's
Ryan C. Gordon <icculus@icculus.org>
parents: 3877
diff changeset
   317
    env = SDL_getenv("SDL_VIDEO_ALLOW_SCREENSAVER");
4139
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   318
    if ( env ) {
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   319
        allow_screensaver = SDL_atoi(env);
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   320
    } else {
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   321
#ifdef SDL_VIDEO_DISABLE_SCREENSAVER
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   322
        allow_screensaver = 0;
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   323
#else
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   324
        allow_screensaver = 1;
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   325
#endif
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4123
diff changeset
   326
    }
3936
c5c3c772f5aa Let app set SDL_VIDEO_ALLOW_SCREENSAVER environment variable to override SDL's
Ryan C. Gordon <icculus@icculus.org>
parents: 3877
diff changeset
   327
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   328
    /* Gather some information that is useful to know about the display */
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   329
    QZ_GetModeInfo(this, save_mode, &device_width, &device_height, &device_bpp);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   330
    if (device_bpp == 0) {
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   331
        QZ_ReleaseDisplayMode(this, save_mode);
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   332
        save_mode = NULL;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   333
        SDL_SetError("Unsupported display mode");
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   334
        return -1;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   335
    }
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   336
1545
8d9bb0cf2c2a Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   337
    /* Determine the current screen size */
8d9bb0cf2c2a Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   338
    this->info.current_w = device_width;
8d9bb0cf2c2a Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   339
    this->info.current_h = device_height;
8d9bb0cf2c2a Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   340
8d9bb0cf2c2a Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   341
    /* Determine the default screen depth */
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   342
    video_format->BitsPerPixel = device_bpp;
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   343
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   344
    /* Set misc globals */
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   345
    current_grab_mode = SDL_GRAB_OFF;
761
c5b2b6d2d1fe Date: Wed, 31 Dec 2003 21:55:30 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 683
diff changeset
   346
    cursor_should_be_visible    = YES;
779
68c8da837fc0 Date: Tue, 6 Jan 2004 21:54:02 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 768
diff changeset
   347
    cursor_visible              = YES;
823
d67e76f25874 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 816
diff changeset
   348
    current_mods = 0;
4123
9d90d7765fa7 Guillaume Borios fixed bug #508
Sam Lantinga <slouken@libsdl.org>
parents: 4090
diff changeset
   349
    field_edit =  [[SDLTranslatorResponder alloc] initWithFrame:r];
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   350
555
2536446a92de From: Darrell Walisser
Sam Lantinga <slouken@libsdl.org>
parents: 501
diff changeset
   351
    /* register for sleep notifications so wake from sleep generates SDL_VIDEOEXPOSE */
2536446a92de From: Darrell Walisser
Sam Lantinga <slouken@libsdl.org>
parents: 501
diff changeset
   352
    QZ_RegisterForSleepNotifications (this);
2536446a92de From: Darrell Walisser
Sam Lantinga <slouken@libsdl.org>
parents: 501
diff changeset
   353
    
1271
092722dbc766 Whoops! (hope this compiles...)
Sam Lantinga <slouken@libsdl.org>
parents: 1220
diff changeset
   354
    /* Fill in some window manager capabilities */
092722dbc766 Whoops! (hope this compiles...)
Sam Lantinga <slouken@libsdl.org>
parents: 1220
diff changeset
   355
    this->info.wm_available = 1;
092722dbc766 Whoops! (hope this compiles...)
Sam Lantinga <slouken@libsdl.org>
parents: 1220
diff changeset
   356
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   357
    return 0;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   358
}
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   359
4317
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   360
static SDL_Rect** QZ_ListModes (_THIS, SDL_PixelFormat *format, Uint32 flags)
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   361
{
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   362
    CFArrayRef mode_list = NULL;          /* list of available fullscreen modes */
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   363
    CFIndex num_modes;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   364
    CFIndex i;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   365
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   366
    int list_size = 0;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   367
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   368
    /* Any windowed mode is acceptable */
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   369
    if ( (flags & SDL_FULLSCREEN) == 0 )
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   370
        return (SDL_Rect**)-1;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   371
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   372
    /* Free memory from previous call, if any */
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   373
    if ( client_mode_list != NULL ) {
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   374
        int i;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   375
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   376
        for (i = 0; client_mode_list[i] != NULL; i++)
1756
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   377
            SDL_free (client_mode_list[i]);
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   378
1756
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   379
        SDL_free (client_mode_list);
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   380
        client_mode_list = NULL;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   381
    }
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   382
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   383
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   384
    if (IS_SNOW_LEOPARD_OR_LATER(this)) {
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   385
        mode_list = CGDisplayCopyAllDisplayModes(display_id, NULL);
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   386
    }
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   387
#endif
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   388
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   389
#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6)
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   390
    if (!IS_SNOW_LEOPARD_OR_LATER(this)) {
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   391
        mode_list = CGDisplayAvailableModes(display_id);
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   392
    }
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   393
#endif
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   394
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   395
    num_modes = CFArrayGetCount (mode_list);
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   396
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   397
    /* Build list of modes with the requested bpp */
155
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   398
    for (i = 0; i < num_modes; i++) {
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   399
        Uint32 width, height, bpp;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   400
        const void *onemode = CFArrayGetValueAtIndex(mode_list, i);
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   401
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   402
        QZ_GetModeInfo(this, onemode, &width, &height, &bpp);
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   403
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   404
        if (bpp && (bpp == format->BitsPerPixel)) {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   405
            int hasMode = SDL_FALSE;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   406
            int i;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   407
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   408
            /* Check if mode is already in the list */
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   409
            for (i = 0; i < list_size; i++) {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   410
                if (client_mode_list[i]->w == width &&
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   411
                    client_mode_list[i]->h == height) {
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   412
                        hasMode = SDL_TRUE;
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   413
                        break;
155
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   414
                }
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   415
            }
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   416
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   417
            /* Grow the list and add mode to the list */
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   418
            if ( ! hasMode ) {
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   419
                SDL_Rect *rect;
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   420
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   421
                list_size++;
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   422
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   423
                if (client_mode_list == NULL)
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   424
                    client_mode_list = (SDL_Rect**) 
1756
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   425
                        SDL_malloc (sizeof(*client_mode_list) * (list_size+1) );
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   426
                else {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   427
                    /* !!! FIXME: this leaks memory if SDL_realloc() fails! */
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   428
                    client_mode_list = (SDL_Rect**)
1756
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   429
                        SDL_realloc (client_mode_list, sizeof(*client_mode_list) * (list_size+1));
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   430
                }
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   431
1756
eed7a3f396ce Using the SDL C runtime functions
Sam Lantinga <slouken@libsdl.org>
parents: 1629
diff changeset
   432
                rect = (SDL_Rect*) SDL_malloc (sizeof(**client_mode_list));
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   433
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   434
                if (client_mode_list == NULL || rect == NULL) {
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   435
                    QZ_ReleaseDisplayModeList(this, mode_list);
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   436
                    SDL_OutOfMemory ();
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   437
                    return NULL;
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   438
                }
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   439
1218
057d313e36a2 Quartz target: set x and y field of mode list to 0 in SDL_ListMode call.
Ryan C. Gordon <icculus@icculus.org>
parents: 1212
diff changeset
   440
                rect->x = rect->y = 0;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   441
                rect->w = width;
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   442
                rect->h = height;
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   443
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   444
                client_mode_list[list_size-1] = rect;
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   445
                client_mode_list[list_size]   = NULL;
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   446
            }
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   447
        }
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   448
    }
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   449
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   450
    QZ_ReleaseDisplayModeList(this, mode_list);
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   451
155
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   452
    /* Sort list largest to smallest (by area) */
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   453
    {
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   454
        int i, j;
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   455
        for (i = 0; i < list_size; i++) {
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   456
            for (j = 0; j < list_size-1; j++) {
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   457
155
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   458
                int area1, area2;
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   459
                area1 = client_mode_list[j]->w * client_mode_list[j]->h;
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   460
                area2 = client_mode_list[j+1]->w * client_mode_list[j+1]->h;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   461
155
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   462
                if (area1 < area2) {
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   463
                    SDL_Rect *tmp = client_mode_list[j];
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   464
                    client_mode_list[j] = client_mode_list[j+1];
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   465
                    client_mode_list[j+1] = tmp;
155
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   466
                }
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   467
            }
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   468
        }
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   469
    }
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   470
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   471
    return client_mode_list;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   472
}
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   473
657
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   474
static SDL_bool QZ_WindowPosition(_THIS, int *x, int *y)
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   475
{
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   476
    const char *window = getenv("SDL_VIDEO_WINDOW_POS");
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   477
    if ( window ) {
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   478
        if ( sscanf(window, "%d,%d", x, y) == 2 ) {
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   479
            return SDL_TRUE;
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   480
        }
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   481
    }
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   482
    return SDL_FALSE;
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   483
}
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   484
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   485
static CGError QZ_SetDisplayMode(_THIS, const void *vidmode)
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   486
{
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   487
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   488
    if (IS_SNOW_LEOPARD_OR_LATER(this)) {
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   489
        return CGDisplaySetDisplayMode(display_id, (CGDisplayModeRef) vidmode, NULL);
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   490
    }
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   491
#endif
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   492
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   493
#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6)
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   494
    if (!IS_SNOW_LEOPARD_OR_LATER(this)) {
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   495
        return CGDisplaySwitchToMode(display_id, (CFDictionaryRef) vidmode);
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   496
    }
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   497
#endif
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   498
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   499
    return kCGErrorFailure;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   500
}
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   501
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   502
static inline CGError QZ_RestoreDisplayMode(_THIS)
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   503
{
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   504
    return QZ_SetDisplayMode(this, save_mode);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   505
}
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   506
4317
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   507
static void QZ_UnsetVideoMode (_THIS, BOOL to_desktop)
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   508
{
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   509
    /* Reset values that may change between switches */
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   510
    this->info.blit_fill  = 0;
5569
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   511
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   512
    if (cg_context) {
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   513
        CGContextFlush (cg_context);
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   514
        CGContextRelease (cg_context);
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   515
        cg_context = nil;
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   516
    }
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   517
    
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   518
    /* Release fullscreen resources */
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   519
    if ( mode_flags & SDL_FULLSCREEN ) {
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   520
435
140798e1e7a6 Darrell's fix for Quartz mouse motion
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
   521
        NSRect screen_rect;
5569
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   522
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   523
        /* If we still have a valid window, close it. */
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   524
        if ( qz_window ) {
4090
fedb379bedd0 Fixed bug #458
Sam Lantinga <slouken@libsdl.org>
parents: 4070
diff changeset
   525
            NSCAssert([ qz_window delegate ] == nil, @"full screen window shouldn't have a delegate"); /* if that should ever change, we'd have to release it here */
fedb379bedd0 Fixed bug #458
Sam Lantinga <slouken@libsdl.org>
parents: 4070
diff changeset
   526
            [ qz_window close ]; /* includes release because [qz_window isReleasedWhenClosed] */
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   527
            qz_window = nil;
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   528
            window_view = nil;
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   529
        }
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   530
        /* 
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   531
            Release the OpenGL context
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   532
            Do this first to avoid trash on the display before fade
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   533
        */
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   534
        if ( mode_flags & SDL_OPENGL ) {
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   535
        
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   536
            QZ_TearDownOpenGL (this);
5606
cf638ceb1f2c Fixed SDL 1.2 fullscreen OpenGL on Mac OS X 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5574
diff changeset
   537
            #ifdef __powerpc__  /* we only use this for pre-10.3 compatibility. */
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   538
            CGLSetFullScreen (NULL);
5606
cf638ceb1f2c Fixed SDL 1.2 fullscreen OpenGL on Mac OS X 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5574
diff changeset
   539
            #endif
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   540
        }
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   541
        if (to_desktop) {
3877
81f66f258d77 Fixed bug #281
Sam Lantinga <slouken@libsdl.org>
parents: 1756
diff changeset
   542
            ShowMenuBar ();
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   543
            /* Restore original screen resolution/bpp */
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   544
            QZ_RestoreDisplayMode (this);
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   545
            CGReleaseAllDisplays ();
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   546
            /* 
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   547
                Reset the main screen's rectangle
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   548
                See comment in QZ_SetVideoFullscreen for why we do this
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   549
            */
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   550
            screen_rect = NSMakeRect(0,0,device_width,device_height);
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   551
            QZ_SetFrame([ NSScreen mainScreen ], screen_rect);
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   552
        }
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   553
    }
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   554
    /* Release window mode resources */
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   555
    else {
4090
fedb379bedd0 Fixed bug #458
Sam Lantinga <slouken@libsdl.org>
parents: 4070
diff changeset
   556
        id delegate = [ qz_window delegate ];
fedb379bedd0 Fixed bug #458
Sam Lantinga <slouken@libsdl.org>
parents: 4070
diff changeset
   557
        [ qz_window close ]; /* includes release because [qz_window isReleasedWhenClosed] */
fedb379bedd0 Fixed bug #458
Sam Lantinga <slouken@libsdl.org>
parents: 4070
diff changeset
   558
        if (delegate != nil) [ delegate release ];
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   559
        qz_window = nil;
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   560
        window_view = nil;
1160
72c6c3e5bb85 Closed a memory leak caused when quitting video subsystem on Quartz target.
Ryan C. Gordon <icculus@icculus.org>
parents: 1144
diff changeset
   561
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   562
        /* Release the OpenGL context */
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   563
        if ( mode_flags & SDL_OPENGL )
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   564
            QZ_TearDownOpenGL (this);
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   565
    }
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   566
155
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   567
    /* Signal successful teardown */
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   568
    video_set = SDL_FALSE;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   569
}
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   570
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   571
static const void *QZ_BestMode(_THIS, const int bpp, const int w, const int h)
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   572
{
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   573
    const void *best = NULL;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   574
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   575
    if (bpp == 0) {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   576
        return NULL;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   577
    }
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   578
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   579
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   580
    if (IS_SNOW_LEOPARD_OR_LATER(this)) {
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   581
        /* apparently, we have to roll our own now. :/ */
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   582
        CFArrayRef mode_list = CGDisplayCopyAllDisplayModes(display_id, NULL);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   583
        if (mode_list != NULL) {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   584
            const CFIndex num_modes = CFArrayGetCount(mode_list);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   585
            CFIndex i;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   586
            for (i = 0; i < num_modes; i++) {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   587
                const void *vidmode = CFArrayGetValueAtIndex(mode_list, i);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   588
                Uint32 thisw, thish, thisbpp;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   589
                QZ_GetModeInfo(this, vidmode, &thisw, &thish, &thisbpp);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   590
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   591
                /* We only care about exact matches, apparently. */
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   592
                if ((thisbpp == bpp) && (thisw == w) && (thish == h)) {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   593
                    best = vidmode;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   594
                    break;  /* got it! */
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   595
                }
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   596
            }
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   597
            CGDisplayModeRetain((CGDisplayModeRef) best);  /* NULL is ok */
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   598
            CFRelease(mode_list);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   599
        }
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   600
    }
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   601
#endif
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   602
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   603
#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6)
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   604
    if (!IS_SNOW_LEOPARD_OR_LATER(this)) {
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   605
        boolean_t exact = 0;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   606
        best = CGDisplayBestModeForParameters(display_id, bpp, w, h, &exact);
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   607
        if (!exact) {
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   608
            best = NULL;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   609
        }
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   610
    }
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   611
#endif
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   612
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   613
    return best;
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   614
}
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   615
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   616
static SDL_Surface* QZ_SetVideoFullScreen (_THIS, SDL_Surface *current, int width,
4317
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   617
                                           int height, int bpp, Uint32 flags)
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   618
{
435
140798e1e7a6 Darrell's fix for Quartz mouse motion
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
   619
    NSRect screen_rect;
588
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   620
    CGError error;
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   621
    NSRect contentRect;
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   622
    CGDisplayFadeReservationToken fade_token = kCGDisplayFadeReservationInvalidToken;
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   623
5569
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   624
    current->flags = SDL_FULLSCREEN;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   625
    current->w = width;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   626
    current->h = height;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   627
4442
31b0f2e06e3c SDL-1.2: Quartz fullscreen video contentRect was used uninitialized.
Ryan C. Gordon <icculus@icculus.org>
parents: 4389
diff changeset
   628
    contentRect = NSMakeRect (0, 0, width, height);
31b0f2e06e3c SDL-1.2: Quartz fullscreen video contentRect was used uninitialized.
Ryan C. Gordon <icculus@icculus.org>
parents: 4389
diff changeset
   629
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   630
    /* Fade to black to hide resolution-switching flicker (and garbage
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   631
       that is displayed by a destroyed OpenGL context, if applicable) */
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   632
    if ( CGAcquireDisplayFadeReservation (5, &fade_token) == kCGErrorSuccess ) {
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   633
        CGDisplayFade (fade_token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, TRUE);
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   634
    }
435
140798e1e7a6 Darrell's fix for Quartz mouse motion
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
   635
    
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   636
    /* Destroy any previous mode */
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   637
    if (video_set == SDL_TRUE)
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   638
        QZ_UnsetVideoMode (this, FALSE);
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   639
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   640
    /* Sorry, QuickDraw was ripped out. */
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   641
    if (getenv("SDL_NSWindowPointer") || getenv("SDL_NSQuickDrawViewPointer")) {
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   642
        SDL_SetError ("Embedded QuickDraw windows are no longer supported");
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   643
        goto ERR_NO_MATCH;
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   644
    }
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   645
5639
72659c5c8616 Cleaned up Snow Leopard display mode rework.
Ryan C. Gordon <icculus@icculus.org>
parents: 5628
diff changeset
   646
    QZ_ReleaseDisplayMode(this, mode);  /* NULL is okay. */
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   647
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   648
    /* See if requested mode exists */
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   649
    mode = QZ_BestMode(this, bpp, width, height);
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   650
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   651
    /* Require an exact match to the requested mode */
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   652
    if ( mode == NULL ) {
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   653
        SDL_SetError ("Failed to find display resolution: %dx%dx%d", width, height, bpp);
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   654
        goto ERR_NO_MATCH;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   655
    }
155
2d162219f433 Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 117
diff changeset
   656
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   657
    /* Put up the blanking window (a window above all other windows) */
588
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   658
    if (getenv ("SDL_SINGLEDISPLAY"))
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   659
        error = CGDisplayCapture (display_id);
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   660
    else
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   661
        error = CGCaptureAllDisplays ();
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   662
        
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   663
    if ( CGDisplayNoErr != error ) {
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   664
        SDL_SetError ("Failed capturing display");
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   665
        goto ERR_NO_CAPTURE;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   666
    }
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   667
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   668
    /* Do the physical switch */
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   669
    if ( CGDisplayNoErr != QZ_SetDisplayMode(this, mode) ) {
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   670
        SDL_SetError ("Failed switching display resolution");
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   671
        goto ERR_NO_SWITCH;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   672
    }
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   673
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   674
    /* Check if we should recreate the window */
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   675
    if (qz_window == nil) {
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   676
        /* Manually create a window, avoids having a nib file resource */
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   677
        qz_window = [ [ SDL_QuartzWindow alloc ] 
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   678
            initWithContentRect:contentRect
5569
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   679
                styleMask:NSBorderlessWindowMask
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   680
                    backing:NSBackingStoreBuffered
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   681
                        defer:NO ];
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   682
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   683
        if (qz_window != nil) {
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   684
            [ qz_window setAcceptsMouseMovedEvents:YES ];
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   685
            [ qz_window setViewsNeedDisplay:NO ];
5569
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   686
            [ qz_window setContentView: [ [ [ SDL_QuartzView alloc ] init ] autorelease ] ];
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   687
        }
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   688
    }
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   689
    /* We already have a window, just change its size */
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   690
    else {
4267
27f972dd5aff Removed isCustom ... not used any more.
Ryan C. Gordon <icculus@icculus.org>
parents: 4265
diff changeset
   691
        [ qz_window setContentSize:contentRect.size ];
27f972dd5aff Removed isCustom ... not used any more.
Ryan C. Gordon <icculus@icculus.org>
parents: 4265
diff changeset
   692
        current->flags |= (SDL_NOFRAME|SDL_RESIZABLE) & mode_flags;
27f972dd5aff Removed isCustom ... not used any more.
Ryan C. Gordon <icculus@icculus.org>
parents: 4265
diff changeset
   693
        [ window_view setFrameSize:contentRect.size ];
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   694
    }
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   695
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   696
    /* Setup OpenGL for a fullscreen context */
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   697
    if (flags & SDL_OPENGL) {
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   698
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   699
        CGLError err;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   700
        CGLContextObj ctx;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   701
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   702
        if ( ! QZ_SetupOpenGL (this, bpp, flags) ) {
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   703
            goto ERR_NO_GL;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   704
        }
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   705
4065
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   706
        /* Initialize the NSView and add it to our window.  The presence of a valid window and
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   707
           view allow the cursor to be changed whilst in fullscreen.*/
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   708
        window_view = [ [ NSView alloc ] initWithFrame:contentRect ];
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   709
        [ [ qz_window contentView ] addSubview:window_view ];	
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   710
        [ window_view release ];
0c76e6d1c3d6 Fixed bug #373
Sam Lantinga <slouken@libsdl.org>
parents: 4049
diff changeset
   711
5606
cf638ceb1f2c Fixed SDL 1.2 fullscreen OpenGL on Mac OS X 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5574
diff changeset
   712
#ifdef __powerpc__  /* there's a Cocoa API for this in 10.3 */
cf638ceb1f2c Fixed SDL 1.2 fullscreen OpenGL on Mac OS X 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5574
diff changeset
   713
        /* CGLSetFullScreen() will handle this for us. */
cf638ceb1f2c Fixed SDL 1.2 fullscreen OpenGL on Mac OS X 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5574
diff changeset
   714
        [ qz_window setLevel:NSNormalWindowLevel ];
cf638ceb1f2c Fixed SDL 1.2 fullscreen OpenGL on Mac OS X 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5574
diff changeset
   715
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   716
        ctx = QZ_GetCGLContextObj (gl_context);
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   717
        err = CGLSetFullScreen (ctx);
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   718
        if (err) {
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   719
            SDL_SetError ("Error setting OpenGL fullscreen: %s", CGLErrorString(err));
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   720
            goto ERR_NO_GL;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   721
        }
5606
cf638ceb1f2c Fixed SDL 1.2 fullscreen OpenGL on Mac OS X 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5574
diff changeset
   722
#else
cf638ceb1f2c Fixed SDL 1.2 fullscreen OpenGL on Mac OS X 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5574
diff changeset
   723
        [ qz_window setLevel:CGShieldingWindowLevel() ];
cf638ceb1f2c Fixed SDL 1.2 fullscreen OpenGL on Mac OS X 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5574
diff changeset
   724
        [ gl_context setView:window_view ];
cf638ceb1f2c Fixed SDL 1.2 fullscreen OpenGL on Mac OS X 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5574
diff changeset
   725
        [ gl_context setFullScreen ];
cf638ceb1f2c Fixed SDL 1.2 fullscreen OpenGL on Mac OS X 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5574
diff changeset
   726
        [ gl_context update ];
cf638ceb1f2c Fixed SDL 1.2 fullscreen OpenGL on Mac OS X 10.7.
Ryan C. Gordon <icculus@icculus.org>
parents: 5574
diff changeset
   727
#endif
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   728
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   729
        [ gl_context makeCurrentContext];
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   730
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   731
        glClear (GL_COLOR_BUFFER_BIT);
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   732
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   733
        [ gl_context flushBuffer ];
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   734
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   735
        current->flags |= SDL_OPENGL;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   736
    }
5569
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   737
    /* For 2D, we build a CGBitmapContext */
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   738
    else {
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   739
        CGColorSpaceRef cgColorspace;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   740
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   741
        /* Only recreate the view if it doesn't already exist */
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   742
        if (window_view == nil) {
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   743
            window_view = [ [ NSView alloc ] initWithFrame:contentRect ];
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   744
            [ window_view setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable ];
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   745
            [ [ qz_window contentView ] addSubview:window_view ];
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   746
            [ window_view release ];
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   747
        }
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   748
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   749
        cgColorspace = CGColorSpaceCreateDeviceRGB();
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   750
        current->pitch = 4 * current->w;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   751
        current->pixels = SDL_malloc (current->h * current->pitch);
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   752
        
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   753
        cg_context = CGBitmapContextCreate (current->pixels, current->w, current->h,
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   754
                        8, current->pitch, cgColorspace,
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   755
                        kCGImageAlphaNoneSkipFirst);
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   756
        CGColorSpaceRelease (cgColorspace);
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   757
        
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   758
        current->flags |= SDL_SWSURFACE;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   759
        current->flags |= SDL_ASYNCBLIT;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   760
        current->hwdata = (void *) cg_context;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   761
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   762
        /* Force this window to draw above _everything_. */
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   763
        [ qz_window setLevel:CGShieldingWindowLevel() ];
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   764
    }
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   765
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   766
    [ qz_window setHasShadow:NO];
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   767
    [ qz_window setOpaque:YES];
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   768
    [ qz_window makeKeyAndOrderFront:nil ];
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   769
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   770
    /* If we don't hide menu bar, it will get events and interrupt the program */
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   771
    HideMenuBar ();
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   772
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   773
    /* Fade in again (asynchronously) */
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   774
    if ( fade_token != kCGDisplayFadeReservationInvalidToken ) {
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   775
        CGDisplayFade (fade_token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   776
        CGReleaseDisplayFadeReservation(fade_token);
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   777
    }
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   778
435
140798e1e7a6 Darrell's fix for Quartz mouse motion
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
   779
    /* 
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   780
        There is a bug in Cocoa where NSScreen doesn't synchronize
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   781
        with CGDirectDisplay, so the main screen's frame is wrong.
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   782
        As a result, coordinate translation produces incorrect results.
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   783
        We can hack around this bug by setting the screen rect
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   784
        ourselves. This hack should be removed if/when the bug is fixed.
435
140798e1e7a6 Darrell's fix for Quartz mouse motion
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
   785
    */
140798e1e7a6 Darrell's fix for Quartz mouse motion
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
   786
    screen_rect = NSMakeRect(0,0,width,height);
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   787
    QZ_SetFrame([ NSScreen mainScreen ], screen_rect);
435
140798e1e7a6 Darrell's fix for Quartz mouse motion
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
   788
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   789
    /* Save the flags to ensure correct tear-down */
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   790
    mode_flags = current->flags;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   791
1629
ef4a796e7f24 Fixed bug #55
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
   792
    /* Set app state, hide cursor if necessary, ... */
ef4a796e7f24 Fixed bug #55
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
   793
    QZ_DoActivate(this);
1119
430d8d701f69 SDL_GetAppState() correction when toggling fullscreen on OSX.
Ryan C. Gordon <icculus@icculus.org>
parents: 967
diff changeset
   794
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   795
    return current;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   796
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   797
    /* Since the blanking window covers *all* windows (even force quit) correct recovery is crucial */
5628
f78f29271dfd Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 5619
diff changeset
   798
ERR_NO_GL:      QZ_RestoreDisplayMode(this);
588
2c6510c0a304 Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
Sam Lantinga <slouken@libsdl.org>
parents: 576
diff changeset
   799
ERR_NO_SWITCH:  CGReleaseAllDisplays ();
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   800
ERR_NO_CAPTURE:
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   801
ERR_NO_MATCH:   if ( fade_token != kCGDisplayFadeReservationInvalidToken ) {
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   802
                    CGDisplayFade (fade_token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   803
                    CGReleaseDisplayFadeReservation (fade_token);
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   804
                }
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   805
                return NULL;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   806
}
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   807
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   808
static SDL_Surface* QZ_SetVideoWindowed (_THIS, SDL_Surface *current, int width,
4317
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   809
                                         int height, int *bpp, Uint32 flags)
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   810
{
58
bd6b0a910a65 * Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents: 56
diff changeset
   811
    unsigned int style;
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   812
    NSRect contentRect;
657
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   813
    int center_window = 1;
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   814
    int origin_x, origin_y;
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   815
    CGDisplayFadeReservationToken fade_token = kCGDisplayFadeReservationInvalidToken;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   816
58
bd6b0a910a65 * Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents: 56
diff changeset
   817
    current->flags = 0;
bd6b0a910a65 * Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents: 56
diff changeset
   818
    current->w = width;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   819
    current->h = height;
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   820
    
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   821
    contentRect = NSMakeRect (0, 0, width, height);
4265
c7b1d5eaa77d Fixed SDL_VIDEO_WINDOW_POS environment variable for Quartz target.
Ryan C. Gordon <icculus@icculus.org>
parents: 4236
diff changeset
   822
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   823
    /*
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   824
        Check if we should completely destroy the previous mode 
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   825
        - If it is fullscreen
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   826
        - If it has different noframe or resizable attribute
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   827
        - If it is OpenGL (since gl attributes could be different)
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   828
        - If new mode is OpenGL, but previous mode wasn't
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   829
    */
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   830
    if (video_set == SDL_TRUE) {
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   831
        if (mode_flags & SDL_FULLSCREEN) {
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   832
            /* Fade to black to hide resolution-switching flicker (and garbage
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   833
               that is displayed by a destroyed OpenGL context, if applicable) */
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   834
            if (CGAcquireDisplayFadeReservation (5, &fade_token) == kCGErrorSuccess) {
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   835
                CGDisplayFade (fade_token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, TRUE);
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   836
            }
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   837
            QZ_UnsetVideoMode (this, TRUE);
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   838
        }
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   839
        else if ( ((mode_flags ^ flags) & (SDL_NOFRAME|SDL_RESIZABLE)) ||
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   840
                  (mode_flags & SDL_OPENGL) || 
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   841
                  (flags & SDL_OPENGL) ) {
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   842
            QZ_UnsetVideoMode (this, TRUE);
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   843
        }
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   844
    }
683
5d2f027b3349 Date: Sat, 9 Aug 2003 20:14:06 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 674
diff changeset
   845
    
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   846
    /* Sorry, QuickDraw was ripped out. */
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   847
    if (getenv("SDL_NSWindowPointer") || getenv("SDL_NSQuickDrawViewPointer")) {
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   848
        SDL_SetError ("Embedded QuickDraw windows are no longer supported");
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   849
        if (fade_token != kCGDisplayFadeReservationInvalidToken) {
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   850
            CGDisplayFade (fade_token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   851
            CGReleaseDisplayFadeReservation (fade_token);
683
5d2f027b3349 Date: Sat, 9 Aug 2003 20:14:06 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 674
diff changeset
   852
        }
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   853
        return NULL;
683
5d2f027b3349 Date: Sat, 9 Aug 2003 20:14:06 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 674
diff changeset
   854
    }
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   855
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   856
    /* Check if we should recreate the window */
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   857
    if (qz_window == nil) {
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   858
    
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   859
        /* Set the window style based on input flags */
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   860
        if ( flags & SDL_NOFRAME ) {
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   861
            style = NSBorderlessWindowMask;
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   862
            current->flags |= SDL_NOFRAME;
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   863
        } else {
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   864
            style = NSTitledWindowMask;
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   865
            style |= (NSMiniaturizableWindowMask | NSClosableWindowMask);
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   866
            if ( flags & SDL_RESIZABLE ) {
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   867
                style |= NSResizableWindowMask;
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   868
                current->flags |= SDL_RESIZABLE;
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   869
            }
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   870
        }
4265
c7b1d5eaa77d Fixed SDL_VIDEO_WINDOW_POS environment variable for Quartz target.
Ryan C. Gordon <icculus@icculus.org>
parents: 4236
diff changeset
   871
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   872
        /* Manually create a window, avoids having a nib file resource */
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   873
        qz_window = [ [ SDL_QuartzWindow alloc ] 
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   874
            initWithContentRect:contentRect
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   875
                styleMask:style 
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   876
                    backing:NSBackingStoreBuffered
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   877
                        defer:NO ];
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   878
                          
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   879
        if (qz_window == nil) {
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   880
            SDL_SetError ("Could not create the Cocoa window");
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   881
            if (fade_token != kCGDisplayFadeReservationInvalidToken) {
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   882
                CGDisplayFade (fade_token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   883
                CGReleaseDisplayFadeReservation (fade_token);
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   884
            }
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   885
            return NULL;
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   886
        }
4265
c7b1d5eaa77d Fixed SDL_VIDEO_WINDOW_POS environment variable for Quartz target.
Ryan C. Gordon <icculus@icculus.org>
parents: 4236
diff changeset
   887
4090
fedb379bedd0 Fixed bug #458
Sam Lantinga <slouken@libsdl.org>
parents: 4070
diff changeset
   888
        /*[ qz_window setReleasedWhenClosed:YES ];*/ /* no need to set this as it's the default for NSWindows */
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   889
        QZ_SetCaption(this, this->wm_title, this->wm_icon);
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   890
        [ qz_window setAcceptsMouseMovedEvents:YES ];
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   891
        [ qz_window setViewsNeedDisplay:NO ];
4265
c7b1d5eaa77d Fixed SDL_VIDEO_WINDOW_POS environment variable for Quartz target.
Ryan C. Gordon <icculus@icculus.org>
parents: 4236
diff changeset
   892
c7b1d5eaa77d Fixed SDL_VIDEO_WINDOW_POS environment variable for Quartz target.
Ryan C. Gordon <icculus@icculus.org>
parents: 4236
diff changeset
   893
        if ( QZ_WindowPosition(this, &origin_x, &origin_y) ) {
c7b1d5eaa77d Fixed SDL_VIDEO_WINDOW_POS environment variable for Quartz target.
Ryan C. Gordon <icculus@icculus.org>
parents: 4236
diff changeset
   894
            /* have to flip the Y value (NSPoint is lower left corner origin) */
c7b1d5eaa77d Fixed SDL_VIDEO_WINDOW_POS environment variable for Quartz target.
Ryan C. Gordon <icculus@icculus.org>
parents: 4236
diff changeset
   895
            [ qz_window setFrameTopLeftPoint:NSMakePoint((float) origin_x, (float) (this->info.current_h - origin_y))];
c7b1d5eaa77d Fixed SDL_VIDEO_WINDOW_POS environment variable for Quartz target.
Ryan C. Gordon <icculus@icculus.org>
parents: 4236
diff changeset
   896
            center_window = 0;
4267
27f972dd5aff Removed isCustom ... not used any more.
Ryan C. Gordon <icculus@icculus.org>
parents: 4265
diff changeset
   897
        } else if ( center_window ) {
657
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   898
            [ qz_window center ];
714053f573e7 Date: Thu, 24 Jul 2003 01:40:17 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 656
diff changeset
   899
        }
4265
c7b1d5eaa77d Fixed SDL_VIDEO_WINDOW_POS environment variable for Quartz target.
Ryan C. Gordon <icculus@icculus.org>
parents: 4236
diff changeset
   900
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   901
        [ qz_window setDelegate:
4090
fedb379bedd0 Fixed bug #458
Sam Lantinga <slouken@libsdl.org>
parents: 4070
diff changeset
   902
            [ [ SDL_QuartzWindowDelegate alloc ] init ] ];
4070
b8f2db95145e Patch from Christian Walther
Sam Lantinga <slouken@libsdl.org>
parents: 4065
diff changeset
   903
        [ qz_window setContentView: [ [ [ SDL_QuartzView alloc ] init ] autorelease ] ];
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   904
    }
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   905
    /* We already have a window, just change its size */
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   906
    else {
4267
27f972dd5aff Removed isCustom ... not used any more.
Ryan C. Gordon <icculus@icculus.org>
parents: 4265
diff changeset
   907
        [ qz_window setContentSize:contentRect.size ];
27f972dd5aff Removed isCustom ... not used any more.
Ryan C. Gordon <icculus@icculus.org>
parents: 4265
diff changeset
   908
        current->flags |= (SDL_NOFRAME|SDL_RESIZABLE) & mode_flags;
27f972dd5aff Removed isCustom ... not used any more.
Ryan C. Gordon <icculus@icculus.org>
parents: 4265
diff changeset
   909
        [ window_view setFrameSize:contentRect.size ];
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   910
    }
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   911
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   912
    /* For OpenGL, we bind the context to a subview */
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   913
    if ( flags & SDL_OPENGL ) {
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   914
1183
634d85aefc8c Fixed bug reported here:
Ryan C. Gordon <icculus@icculus.org>
parents: 1181
diff changeset
   915
        if ( ! QZ_SetupOpenGL (this, *bpp, flags) ) {
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   916
            if (fade_token != kCGDisplayFadeReservationInvalidToken) {
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   917
                CGDisplayFade (fade_token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   918
                CGReleaseDisplayFadeReservation (fade_token);
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   919
            }
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   920
            return NULL;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   921
        }
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   922
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   923
        window_view = [ [ NSView alloc ] initWithFrame:contentRect ];
832
f003714db2f4 Date: Mon, 16 Feb 2004 19:21:51 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 823
diff changeset
   924
        [ window_view setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable ];
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   925
        [ [ qz_window contentView ] addSubview:window_view ];
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   926
        [ gl_context setView: window_view ];
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   927
        [ window_view release ];
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   928
        [ gl_context makeCurrentContext];
158
4382c38dfbee Date: Tue, 21 Aug 2001 03:50:01 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 155
diff changeset
   929
        [ qz_window makeKeyAndOrderFront:nil ];
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   930
        current->flags |= SDL_OPENGL;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   931
    }
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   932
    /* For 2D, we build a CGBitmapContext */
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   933
    else {
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   934
        CGColorSpaceRef cgColorspace;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   935
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   936
        /* Only recreate the view if it doesn't already exist */
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   937
        if (window_view == nil) {
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   938
        
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   939
            window_view = [ [ NSView alloc ] initWithFrame:contentRect ];
832
f003714db2f4 Date: Mon, 16 Feb 2004 19:21:51 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 823
diff changeset
   940
            [ window_view setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable ];
501
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   941
            [ [ qz_window contentView ] addSubview:window_view ];
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   942
            [ window_view release ];
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   943
            [ qz_window makeKeyAndOrderFront:nil ];
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   944
        }
74262d2647ca Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
Sam Lantinga <slouken@libsdl.org>
parents: 500
diff changeset
   945
        
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   946
        cgColorspace = CGColorSpaceCreateDeviceRGB();
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   947
        current->pitch = 4 * current->w;
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   948
        current->pixels = SDL_malloc (current->h * current->pitch);
498
4b8ff8ac2c07 Fixed window update problems on MacOS X 10.2 (thanks Darrell!)
Sam Lantinga <slouken@libsdl.org>
parents: 450
diff changeset
   949
        
4204
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   950
        cg_context = CGBitmapContextCreate (current->pixels, current->w, current->h,
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   951
                        8, current->pitch, cgColorspace,
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   952
                        kCGImageAlphaNoneSkipFirst);
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   953
        CGColorSpaceRelease (cgColorspace);
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   954
        
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   955
        current->flags |= SDL_SWSURFACE;
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   956
        current->flags |= SDL_ASYNCBLIT;
976bc19f8f6b 1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   957
        current->hwdata = (void *) cg_context;
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   958
    }
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   959
272
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   960
    /* Save flags to ensure correct teardown */
d1447a846d80 Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   961
    mode_flags = current->flags;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   962
1340
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   963
    /* Fade in again (asynchronously) if we came from a fullscreen mode and faded to black */
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   964
    if (fade_token != kCGDisplayFadeReservationInvalidToken) {
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   965
        CGDisplayFade (fade_token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   966
        CGReleaseDisplayFadeReservation (fade_token);
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   967
    }
58b114ef50e7 Faster fades when changing to/from/between fullscreen modes on Mac OS X. Also,
Ryan C. Gordon <icculus@icculus.org>
parents: 1271
diff changeset
   968
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   969
    return current;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   970
}
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   971
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   972
static SDL_Surface* QZ_SetVideoMode (_THIS, SDL_Surface *current, int width,
4317
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   973
                                     int height, int bpp, Uint32 flags)
719faf118c38 Put the braces on the next line so vi can find the beginning of the function.
Sam Lantinga <slouken@libsdl.org>
parents: 4267
diff changeset
   974
{
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   975
    current->flags = 0;
852
2651b6b43840 Quartz fix:
Ryan C. Gordon <icculus@icculus.org>
parents: 832
diff changeset
   976
    current->pixels = NULL;
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   977
5569
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   978
    /* Force bpp to 32 */
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   979
    bpp = 32;
d81e8404bd7f Quartz: Ripped out all the legacy CoreGraphics code.
Ryan C. Gordon <icculus@icculus.org>
parents: 5568
diff changeset
   980
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   981
    /* Setup full screen video */
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   982
    if ( flags & SDL_FULLSCREEN ) {
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   983
        current = QZ_SetVideoFullScreen (this, current, width, height, bpp, flags );
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   984
        if (current == NULL)
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   985
            return NULL;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   986
    }
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   987
    /* Setup windowed video */
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   988
    else {
1183
634d85aefc8c Fixed bug reported here:
Ryan C. Gordon <icculus@icculus.org>
parents: 1181
diff changeset
   989
        current = QZ_SetVideoWindowed (this, current, width, height, &bpp, flags);
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   990
        if (current == NULL)
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   991
            return NULL;
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   992
    }
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   993
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   994
    /* Setup the new pixel format */
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   995
    {
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   996
        int amask = 0,
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   997
        rmask = 0,
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   998
        gmask = 0,
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
   999
        bmask = 0;
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
  1000
47
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1001
        switch (bpp) {
45b1c4303f87 Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1002
            case 16:   /* (1)-5-5-5 RGB */
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 359
diff changeset
  1003
                amask = 0;
58
bd6b0a910a65 * Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents: 56
diff changeset
  1004
                rmask = 0x7C00;
bd6b0a910a65 * Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents: 56
diff changeset
  1005
                gmask = 0x03E0;
bd6b0a910a65 * Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents: 56
diff changeset
  1006
                bmask = 0x001F;
47