src/video/cocoa/SDL_cocoavideo.m
author Ryan C. Gordon <icculus@icculus.org>
Thu, 13 Sep 2012 01:43:53 -0400
changeset 6422 fd0ac1b56115
parent 6356 5d4f55bdd0e1
child 6425 60c08d8896e0
permissions -rwxr-xr-x
Added SDL_SetWindowBordered() API.
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
6138
4c64952a58fb Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
     3
  Copyright (C) 1997-2012 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
6356
5d4f55bdd0e1 Patched to compile on PowerPC Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6138
diff changeset
    25
#if defined(__APPLE__) && defined(__POWERPC__)
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
5d4f55bdd0e1 Patched to compile on PowerPC Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6138
diff changeset
    29
#endif
5d4f55bdd0e1 Patched to compile on PowerPC Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6138
diff changeset
    30
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
    31
#include "SDL.h"
5375
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    32
#include "SDL_endian.h"
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
#include "SDL_cocoavideo.h"
4827
5660aac926e9 Got basic, pre-actually-writing-anything Cocoa to build.
egottlieb
parents: 4810
diff changeset
    34
#include "SDL_cocoashape.h"
3660
2d17445190f6 Fixed Mac OS X assertion code.
Ryan C. Gordon <icculus@icculus.org>
parents: 3647
diff changeset
    35
#include "SDL_assert.h"
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
/* Initialization/Query functions */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
static int Cocoa_VideoInit(_THIS);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
static void Cocoa_VideoQuit(_THIS);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
/* Cocoa driver bootstrap functions */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
static int
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
Cocoa_Available(void)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
{
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
    return (1);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
}
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
static void
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
Cocoa_DeleteDevice(SDL_VideoDevice * device)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
{
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
    SDL_free(device->driverdata);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
    SDL_free(device);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
}
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
static SDL_VideoDevice *
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
Cocoa_CreateDevice(int devindex)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
{
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
    SDL_VideoDevice *device;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
    SDL_VideoData *data;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
    Cocoa_RegisterApp();
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
    /* 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
    65
    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
    66
    if (device) {
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
        data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
4457
5e1f9cb9fa98 Fixed compiler warnings
Sam Lantinga <slouken@libsdl.org>
parents: 3660
diff changeset
    68
    } else {
5e1f9cb9fa98 Fixed compiler warnings
Sam Lantinga <slouken@libsdl.org>
parents: 3660
diff changeset
    69
        data = NULL;
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    70
    }
4457
5e1f9cb9fa98 Fixed compiler warnings
Sam Lantinga <slouken@libsdl.org>
parents: 3660
diff changeset
    71
    if (!data) {
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
        SDL_OutOfMemory();
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    73
        if (device) {
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
            SDL_free(device);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
        }
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
        return NULL;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
    }
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
    device->driverdata = data;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
    80
    /* 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
    81
    Gestalt(gestaltSystemVersion, &data->osversion);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
    82
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
    /* Set the function pointers */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
    device->VideoInit = Cocoa_VideoInit;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
    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
    86
    device->GetDisplayBounds = Cocoa_GetDisplayBounds;
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
    device->GetDisplayModes = Cocoa_GetDisplayModes;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
    device->SetDisplayMode = Cocoa_SetDisplayMode;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
    device->PumpEvents = Cocoa_PumpEvents;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
    device->CreateWindow = Cocoa_CreateWindow;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
    device->CreateWindowFrom = Cocoa_CreateWindowFrom;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
    device->SetWindowTitle = Cocoa_SetWindowTitle;
5375
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    94
    device->SetWindowIcon = Cocoa_SetWindowIcon;
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
    device->SetWindowPosition = Cocoa_SetWindowPosition;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
    device->SetWindowSize = Cocoa_SetWindowSize;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
    device->ShowWindow = Cocoa_ShowWindow;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
    device->HideWindow = Cocoa_HideWindow;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
    device->RaiseWindow = Cocoa_RaiseWindow;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
    device->MaximizeWindow = Cocoa_MaximizeWindow;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   101
    device->MinimizeWindow = Cocoa_MinimizeWindow;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   102
    device->RestoreWindow = Cocoa_RestoreWindow;
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6356
diff changeset
   103
    device->SetWindowFullscreen = 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
   104
    device->SetWindowFullscreen = Cocoa_SetWindowFullscreen;
5466
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5375
diff changeset
   105
    device->SetWindowGammaRamp = Cocoa_SetWindowGammaRamp;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5375
diff changeset
   106
    device->GetWindowGammaRamp = Cocoa_GetWindowGammaRamp;
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
    device->SetWindowGrab = Cocoa_SetWindowGrab;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
    device->DestroyWindow = Cocoa_DestroyWindow;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
    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
   110
    
7a602fd2121f OK, it appears that dramatic hacks are not necessary to make Cocoa work...
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4457
diff changeset
   111
    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
   112
    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
   113
    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
   114
    
5088
455bc74f7034 Fixed bug #1100
Sam Lantinga <slouken@libsdl.org>
parents: 4862
diff changeset
   115
#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
   116
    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
   117
    device->GL_GetProcAddress = Cocoa_GL_GetProcAddress;
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   118
    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
   119
    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
   120
    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
   121
    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
   122
    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
   123
    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
   124
    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
   125
#endif
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
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
   127
    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
   128
    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
   129
    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
   130
4499
c2ebe3e020c6 Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents: 4498
diff changeset
   131
    device->SetClipboardText = Cocoa_SetClipboardText;
c2ebe3e020c6 Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents: 4498
diff changeset
   132
    device->GetClipboardText = Cocoa_GetClipboardText;
c2ebe3e020c6 Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents: 4498
diff changeset
   133
    device->HasClipboardText = Cocoa_HasClipboardText;
c2ebe3e020c6 Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents: 4498
diff changeset
   134
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
    device->free = Cocoa_DeleteDevice;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   136
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   137
    return device;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   138
}
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
VideoBootStrap COCOA_bootstrap = {
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
    "cocoa", "SDL Cocoa video driver",
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
    Cocoa_Available, Cocoa_CreateDevice
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
};
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
int
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
Cocoa_VideoInit(_THIS)
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
    Cocoa_InitModes(_this);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
    Cocoa_InitKeyboard(_this);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
    Cocoa_InitMouse(_this);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
    return 0;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   153
}
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
void
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
Cocoa_VideoQuit(_THIS)
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
    Cocoa_QuitModes(_this);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   159
    Cocoa_QuitKeyboard(_this);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
    Cocoa_QuitMouse(_this);
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   161
}
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
5375
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   163
/* 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
   164
NSImage *
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   165
Cocoa_CreateImage(SDL_Surface * surface)
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   166
{
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   167
    SDL_Surface *converted;
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   168
    NSBitmapImageRep *imgrep;
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   169
    Uint8 *pixels;
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   170
    int i;
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   171
    NSImage *img;
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   172
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   173
    converted = SDL_ConvertSurfaceFormat(surface, 
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   174
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   175
                                         SDL_PIXELFORMAT_RGBA8888,
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   176
#else
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   177
                                         SDL_PIXELFORMAT_ABGR8888,
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   178
#endif
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   179
                                         0);
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   180
    if (!converted) {
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   181
        return nil;
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   182
    }
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   183
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   184
    imgrep = [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes: NULL
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   185
                    pixelsWide: converted->w
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   186
                    pixelsHigh: converted->h
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   187
                    bitsPerSample: 8
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   188
                    samplesPerPixel: 4
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   189
                    hasAlpha: YES
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   190
                    isPlanar: NO
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   191
                    colorSpaceName: NSDeviceRGBColorSpace
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   192
                    bytesPerRow: converted->pitch
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   193
                    bitsPerPixel: converted->format->BitsPerPixel] autorelease];
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   194
    if (imgrep == nil) {
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   195
        SDL_FreeSurface(converted);
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   196
        return nil;
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   197
    }
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   198
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   199
    /* Copy the pixels */
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   200
    pixels = [imgrep bitmapData];
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   201
    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
   202
    SDL_FreeSurface(converted);
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   203
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   204
    /* Premultiply the alpha channel */
6028
869b6723e1fc valgrind FTW!
Sam Lantinga <slouken@libsdl.org>
parents: 5865
diff changeset
   205
    for (i = (surface->h * surface->w); i--; ) {
5375
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   206
        Uint8 alpha = pixels[3];
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   207
        pixels[0] = (Uint8)(((Uint16)pixels[0] * alpha) / 255);
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   208
        pixels[1] = (Uint8)(((Uint16)pixels[1] * alpha) / 255);
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   209
        pixels[2] = (Uint8)(((Uint16)pixels[2] * alpha) / 255);
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   210
        pixels += 4;
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   211
    }
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   212
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   213
    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
   214
    if (img != nil) {
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   215
        [img addRepresentation: imgrep];
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   216
    }
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   217
    return img;
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   218
}
3647
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   219
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   220
/*
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   221
 * 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
   222
 *
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   223
 * 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
   224
 *  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
   225
 */
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   226
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   227
SDL_assert_state
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   228
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
   229
{
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
   230
    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
   231
    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
   232
        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
   233
            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
   234
            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
   235
        }
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
   236
    }
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
   237
3647
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   238
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   239
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   240
    NSString *msg = [NSString stringWithFormat:
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   241
            @"Assertion failure at %s (%s:%d), triggered %u time%s:\n  '%s'",
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   242
                data->function, data->filename, data->linenum,
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   243
                data->trigger_count, (data->trigger_count == 1) ? "" : "s",
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   244
                data->condition];
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   245
5865
40dfc30cea83 Fixed a NSLog() format string.
Ryan C. Gordon <icculus@icculus.org>
parents: 5544
diff changeset
   246
    NSLog(@"%@", msg);
3647
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   247
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   248
    /*
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   249
     * !!! FIXME: this code needs to deal with fullscreen modes:
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   250
     * !!! FIXME:  reset to default desktop, runModal, reset to current?
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   251
     */
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   252
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   253
    NSAlert* alert = [[NSAlert alloc] init];
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   254
    [alert setAlertStyle:NSCriticalAlertStyle];
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   255
    [alert setMessageText:msg];
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   256
    [alert addButtonWithTitle:@"Retry"];
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   257
    [alert addButtonWithTitle:@"Break"];
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   258
    [alert addButtonWithTitle:@"Abort"];
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   259
    [alert addButtonWithTitle:@"Ignore"];
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   260
    [alert addButtonWithTitle:@"Always Ignore"];
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   261
    const NSInteger clicked = [alert runModal];
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   262
    [pool 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
   263
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
   264
    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
   265
        SDL_QuitSubSystem(SDL_INIT_VIDEO);
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
   266
    }
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
   267
3647
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   268
    return (SDL_assert_state) (clicked - NSAlertFirstButtonReturn);
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   269
}
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3528
diff changeset
   270
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6028
diff changeset
   271
#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
   272
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   273
/* vim: set ts=4 sw=4 expandtab: */