src/video/cocoa/SDL_cocoavideo.m
author Kevin Shanahan <kmshanah@disenchant.net>
Fri, 03 May 2013 14:11:41 +0930
changeset 7140 e1896b95a8a7
parent 6885 700f1b25f77f
child 7191 75360622e65f
permissions -rw-r--r--
Fix compile on Xcode 3.1 PPC + Altivec -faltivec is given on the command line, so #include <altivec.h> is ignored in this case and #undef'ing vector causes compile to fail.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
     2
  Simple DirectMedia Layer
6885
700f1b25f77f Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6848
diff changeset
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
     7
  arising from the use of this software.
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
    11
  freely, subject to the following restrictions:
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "SDL_config.h"
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6028
diff changeset
    23
#if SDL_VIDEO_DRIVER_COCOA
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6028
diff changeset
    24
7140
e1896b95a8a7 Fix compile on Xcode 3.1 PPC + Altivec
Kevin Shanahan <kmshanah@disenchant.net>
parents: 6885
diff changeset
    25
#if defined(__APPLE__) && defined(__POWERPC__) && !defined(__APPLE_ALTIVEC__)
6356
5d4f55bdd0e1 Patched to compile on PowerPC Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6138
diff changeset
    26
#include <altivec.h>
5d4f55bdd0e1 Patched to compile on PowerPC Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6138
diff changeset
    27
#undef bool
5d4f55bdd0e1 Patched to compile on PowerPC Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6138
diff changeset
    28
#undef vector
6625
647ae2aa5674 One more OS X PowerPC build fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 6616
diff changeset
    29
#undef pixel
6356
5d4f55bdd0e1 Patched to compile on PowerPC Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6138
diff changeset
    30
#endif
5d4f55bdd0e1 Patched to compile on PowerPC Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6138
diff changeset
    31
5544
7bf3c86d8b60 Make assert dialog work on Cocoa target even if we haven't initialized video.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
    32
#include "SDL.h"
5375
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    33
#include "SDL_endian.h"
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
#include "SDL_cocoavideo.h"
4827
5660aac926e9 Got basic, pre-actually-writing-anything Cocoa to build.
egottlieb
parents: 4810
diff changeset
    35
#include "SDL_cocoashape.h"
3660
2d17445190f6 Fixed Mac OS X assertion code.
Ryan C. Gordon <icculus@icculus.org>
parents: 3647
diff changeset
    36
#include "SDL_assert.h"
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
/* Initialization/Query functions */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
static int Cocoa_VideoInit(_THIS);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
static void Cocoa_VideoQuit(_THIS);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
/* Cocoa driver bootstrap functions */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
static int
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
Cocoa_Available(void)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
{
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
    return (1);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
}
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
static void
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
Cocoa_DeleteDevice(SDL_VideoDevice * device)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
{
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
    SDL_free(device->driverdata);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
    SDL_free(device);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
}
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
static SDL_VideoDevice *
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
Cocoa_CreateDevice(int devindex)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
{
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
    SDL_VideoDevice *device;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
    SDL_VideoData *data;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
    Cocoa_RegisterApp();
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
    /* Initialize all variables that we clean on shutdown */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
    if (device) {
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
        data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
4457
5e1f9cb9fa98 Fixed compiler warnings
Sam Lantinga <slouken@libsdl.org>
parents: 3660
diff changeset
    69
    } else {
5e1f9cb9fa98 Fixed compiler warnings
Sam Lantinga <slouken@libsdl.org>
parents: 3660
diff changeset
    70
        data = NULL;
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
    }
4457
5e1f9cb9fa98 Fixed compiler warnings
Sam Lantinga <slouken@libsdl.org>
parents: 3660
diff changeset
    72
    if (!data) {
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    73
        SDL_OutOfMemory();
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
        if (device) {
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
            SDL_free(device);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
        }
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
        return NULL;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
    }
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
    device->driverdata = data;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
    81
    /* Find out what version of Mac OS X we're running */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
    82
    Gestalt(gestaltSystemVersion, &data->osversion);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
    83
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
    /* Set the function pointers */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
    device->VideoInit = Cocoa_VideoInit;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
    device->VideoQuit = Cocoa_VideoQuit;
3528
59ff7a2beb57 Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents: 3280
diff changeset
    87
    device->GetDisplayBounds = Cocoa_GetDisplayBounds;
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
    device->GetDisplayModes = Cocoa_GetDisplayModes;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
    device->SetDisplayMode = Cocoa_SetDisplayMode;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
    device->PumpEvents = Cocoa_PumpEvents;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
    device->CreateWindow = Cocoa_CreateWindow;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
    device->CreateWindowFrom = Cocoa_CreateWindowFrom;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
    device->SetWindowTitle = Cocoa_SetWindowTitle;
5375
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    95
    device->SetWindowIcon = Cocoa_SetWindowIcon;
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
    device->SetWindowPosition = Cocoa_SetWindowPosition;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
    device->SetWindowSize = Cocoa_SetWindowSize;
6681
5a0396a933b5 SetMinimumWindowSize for OS X
stopiccot
parents: 6625
diff changeset
    98
    device->SetWindowMinimumSize = Cocoa_SetWindowMinimumSize;
6788
036f53f2f5aa Added SDL_SetWindowMaximumSize() and SDL_GetWindowMaximumSize()
Sam Lantinga <slouken@libsdl.org>
parents: 6714
diff changeset
    99
    device->SetWindowMaximumSize = Cocoa_SetWindowMaximumSize;
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
    device->ShowWindow = Cocoa_ShowWindow;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   101
    device->HideWindow = Cocoa_HideWindow;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   102
    device->RaiseWindow = Cocoa_RaiseWindow;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   103
    device->MaximizeWindow = Cocoa_MaximizeWindow;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   104
    device->MinimizeWindow = Cocoa_MinimizeWindow;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
    device->RestoreWindow = Cocoa_RestoreWindow;
6425
60c08d8896e0 Use the right function pointer. :)
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   106
    device->SetWindowBordered = Cocoa_SetWindowBordered;
5249
7a963be087ef Mostly fixed fullscreen mode on Mac OS X, and you can toggle it on and off.
Sam Lantinga <slouken@libsdl.org>
parents: 5088
diff changeset
   107
    device->SetWindowFullscreen = Cocoa_SetWindowFullscreen;
5466
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5375
diff changeset
   108
    device->SetWindowGammaRamp = Cocoa_SetWindowGammaRamp;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5375
diff changeset
   109
    device->GetWindowGammaRamp = Cocoa_GetWindowGammaRamp;
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
    device->SetWindowGrab = Cocoa_SetWindowGrab;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
    device->DestroyWindow = Cocoa_DestroyWindow;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
    device->GetWindowWMInfo = Cocoa_GetWindowWMInfo;
4810
7a602fd2121f OK, it appears that dramatic hacks are not necessary to make Cocoa work...
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4457
diff changeset
   113
    
7a602fd2121f OK, it appears that dramatic hacks are not necessary to make Cocoa work...
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4457
diff changeset
   114
    device->shape_driver.CreateShaper = Cocoa_CreateShaper;
7a602fd2121f OK, it appears that dramatic hacks are not necessary to make Cocoa work...
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4457
diff changeset
   115
    device->shape_driver.SetWindowShape = Cocoa_SetWindowShape;
7a602fd2121f OK, it appears that dramatic hacks are not necessary to make Cocoa work...
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4457
diff changeset
   116
    device->shape_driver.ResizeWindowShape = Cocoa_ResizeWindowShape;
7a602fd2121f OK, it appears that dramatic hacks are not necessary to make Cocoa work...
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4457
diff changeset
   117
    
5088
455bc74f7034 Fixed bug #1100
Sam Lantinga <slouken@libsdl.org>
parents: 4862
diff changeset
   118
#if SDL_VIDEO_OPENGL_CGL
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
    device->GL_LoadLibrary = Cocoa_GL_LoadLibrary;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   120
    device->GL_GetProcAddress = Cocoa_GL_GetProcAddress;
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   121
    device->GL_UnloadLibrary = Cocoa_GL_UnloadLibrary;
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
    device->GL_CreateContext = Cocoa_GL_CreateContext;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
    device->GL_MakeCurrent = Cocoa_GL_MakeCurrent;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   124
    device->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   125
    device->GL_GetSwapInterval = Cocoa_GL_GetSwapInterval;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
    device->GL_SwapWindow = Cocoa_GL_SwapWindow;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
    device->GL_DeleteContext = Cocoa_GL_DeleteContext;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
#endif
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   129
3280
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   130
    device->StartTextInput = Cocoa_StartTextInput;
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   131
    device->StopTextInput = Cocoa_StopTextInput;
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   132
    device->SetTextInputRect = Cocoa_SetTextInputRect;
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   133
4499
c2ebe3e020c6 Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents: 4498
diff changeset
   134
    device->SetClipboardText = Cocoa_SetClipboardText;
c2ebe3e020c6 Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents: 4498
diff changeset
   135
    device->GetClipboardText = Cocoa_GetClipboardText;
c2ebe3e020c6 Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents: 4498
diff changeset
   136
    device->HasClipboardText = Cocoa_HasClipboardText;
c2ebe3e020c6 Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents: 4498
diff changeset
   137
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   138
    device->free = Cocoa_DeleteDevice;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
    return device;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
}
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
VideoBootStrap COCOA_bootstrap = {
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
    "cocoa", "SDL Cocoa video driver",
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
    Cocoa_Available, Cocoa_CreateDevice
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
};
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
int
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
Cocoa_VideoInit(_THIS)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
{
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
    Cocoa_InitModes(_this);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   153
    Cocoa_InitKeyboard(_this);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
    Cocoa_InitMouse(_this);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
    return 0;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
}
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   157
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   158
void
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   159
Cocoa_VideoQuit(_THIS)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
{
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   161
    Cocoa_QuitModes(_this);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
    Cocoa_QuitKeyboard(_this);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
    Cocoa_QuitMouse(_this);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
}
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
5375
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   166
/* This function assumes that it's called from within an autorelease pool */
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   167
NSImage *
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   168
Cocoa_CreateImage(SDL_Surface * surface)
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   169
{
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   170
    SDL_Surface *converted;
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   171
    NSBitmapImageRep *imgrep;
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   172
    Uint8 *pixels;
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   173
    int i;
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   174
    NSImage *img;
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   175
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   176
    converted = SDL_ConvertSurfaceFormat(surface, 
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   177
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   178
                                         SDL_PIXELFORMAT_RGBA8888,
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   179
#else
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   180
                                         SDL_PIXELFORMAT_ABGR8888,
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   181
#endif
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   182
                                         0);
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   183
    if (!converted) {
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   184
        return nil;
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   185
    }
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   186
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   187
    imgrep = [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes: NULL
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   188
                    pixelsWide: converted->w
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   189
                    pixelsHigh: converted->h
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   190
                    bitsPerSample: 8
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   191
                    samplesPerPixel: 4
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   192
                    hasAlpha: YES
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   193
                    isPlanar: NO
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   194
                    colorSpaceName: NSDeviceRGBColorSpace
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   195
                    bytesPerRow: converted->pitch
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   196
                    bitsPerPixel: converted->format->BitsPerPixel] autorelease];
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   197
    if (imgrep == nil) {
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   198
        SDL_FreeSurface(converted);
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   199
        return nil;
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   200
    }
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   201
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   202
    /* Copy the pixels */
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   203
    pixels = [imgrep bitmapData];
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   204
    SDL_memcpy(pixels, converted->pixels, converted->h * converted->pitch);
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   205
    SDL_FreeSurface(converted);
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   206
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   207
    /* Premultiply the alpha channel */
6028
869b6723e1fc valgrind FTW!
Sam Lantinga <slouken@libsdl.org>
parents: 5865
diff changeset
   208
    for (i = (surface->h * surface->w); i--; ) {
5375
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   209
        Uint8 alpha = pixels[3];
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   210
        pixels[0] = (Uint8)(((Uint16)pixels[0] * alpha) / 255);
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   211
        pixels[1] = (Uint8)(((Uint16)pixels[1] * alpha) / 255);
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   212
        pixels[2] = (Uint8)(((Uint16)pixels[2] * alpha) / 255);
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   213
        pixels += 4;
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   214
    }
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   215
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   216
    img = [[[NSImage alloc] initWithSize: NSMakeSize(surface->w, surface->h)] autorelease];
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   217
    if (img != nil) {
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   218
        [img addRepresentation: imgrep];
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   219
    }
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   220
    return img;
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   221
}
3647
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   222
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   223
/*
6616
4f272256d172 Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6425
diff changeset
   224
 * Mac OS X log support.
4f272256d172 Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6425
diff changeset
   225
 *
4f272256d172 Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6425
diff changeset
   226
 * This doesn't really have aything to do with the interfaces of the SDL video
4f272256d172 Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6425
diff changeset
   227
 *  subsystem, but we need to stuff this into an Objective-C source code file.
4f272256d172 Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6425
diff changeset
   228
 */
4f272256d172 Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6425
diff changeset
   229
4f272256d172 Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6425
diff changeset
   230
void SDL_NSLog(const char *text)
4f272256d172 Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6425
diff changeset
   231
{
6714
146d1d7ecdc4 Fixed bug 1641 - avoid allocating nsstring from char*
Sam Lantinga <slouken@libsdl.org>
parents: 6681
diff changeset
   232
    NSLog(@"%s", text);
6616
4f272256d172 Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6425
diff changeset
   233
}
4f272256d172 Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6425
diff changeset
   234
4f272256d172 Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6425
diff changeset
   235
/*
3647
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   236
 * Mac OS X assertion support.
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   237
 *
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   238
 * This doesn't really have aything to do with the interfaces of the SDL video
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   239
 *  subsystem, but we need to stuff this into an Objective-C source code file.
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   240
 */
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   241
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   242
SDL_assert_state
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   243
SDL_PromptAssertion_cocoa(const SDL_assert_data *data)
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   244
{
5544
7bf3c86d8b60 Make assert dialog work on Cocoa target even if we haven't initialized video.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   245
    const int initialized = (SDL_WasInit(SDL_INIT_VIDEO) != 0);
7bf3c86d8b60 Make assert dialog work on Cocoa target even if we haven't initialized video.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   246
    if (!initialized) {
7bf3c86d8b60 Make assert dialog work on Cocoa target even if we haven't initialized video.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   247
        if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) {
7bf3c86d8b60 Make assert dialog work on Cocoa target even if we haven't initialized video.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   248
            fprintf(stderr, "Assertion failed AND couldn't init video mode!\n");
7bf3c86d8b60 Make assert dialog work on Cocoa target even if we haven't initialized video.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   249
            return SDL_ASSERTION_BREAK;  /* oh well, crash hard. */
7bf3c86d8b60 Make assert dialog work on Cocoa target even if we haven't initialized video.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   250
        }
7bf3c86d8b60 Make assert dialog work on Cocoa target even if we haven't initialized video.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   251
    }
7bf3c86d8b60 Make assert dialog work on Cocoa target even if we haven't initialized video.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   252
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   253
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
3647
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   254
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   255
    NSString *msg = [NSString stringWithFormat:
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   256
            @"Assertion failure at %s (%s:%d), triggered %u time%s:\n  '%s'",
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   257
                data->function, data->filename, data->linenum,
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   258
                data->trigger_count, (data->trigger_count == 1) ? "" : "s",
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   259
                data->condition];
3647
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   260
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   261
    NSLog(@"%@", msg);
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   262
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   263
    /*
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   264
     * !!! FIXME: this code needs to deal with fullscreen modes:
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   265
     * !!! FIXME:  reset to default desktop, runModal, reset to current?
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   266
     */
3647
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   267
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   268
    NSAlert* alert = [[NSAlert alloc] init];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   269
    [alert setAlertStyle:NSCriticalAlertStyle];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   270
    [alert setMessageText:msg];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   271
    [alert addButtonWithTitle:@"Retry"];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   272
    [alert addButtonWithTitle:@"Break"];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   273
    [alert addButtonWithTitle:@"Abort"];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   274
    [alert addButtonWithTitle:@"Ignore"];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   275
    [alert addButtonWithTitle:@"Always Ignore"];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   276
    const NSInteger clicked = [alert runModal];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   277
    [alert release];
5544
7bf3c86d8b60 Make assert dialog work on Cocoa target even if we haven't initialized video.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   278
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   279
    [pool release];
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6788
diff changeset
   280
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   281
    if (!initialized) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   282
        SDL_QuitSubSystem(SDL_INIT_VIDEO);
5544
7bf3c86d8b60 Make assert dialog work on Cocoa target even if we haven't initialized video.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   283
    }
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   284
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6836
diff changeset
   285
    return (SDL_assert_state) (clicked - NSAlertFirstButtonReturn);
3647
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   286
}
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   287
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6028
diff changeset
   288
#endif /* SDL_VIDEO_DRIVER_COCOA */
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6028
diff changeset
   289
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   290
/* vim: set ts=4 sw=4 expandtab: */