src/video/cocoa/SDL_cocoawindow.m
author Sam Lantinga <slouken@libsdl.org>
Mon, 21 Feb 2011 22:03:39 -0800
changeset 5380 2de85077eb0b
parent 5379 78c071fe4c37
child 5388 6e586f65f8ef
permissions -rw-r--r--
Simplified and unified the window creation process a little.
slouken@1933
     1
/*
slouken@1933
     2
    SDL - Simple DirectMedia Layer
slouken@5262
     3
    Copyright (C) 1997-2011 Sam Lantinga
slouken@1933
     4
slouken@1933
     5
    This library is free software; you can redistribute it and/or
slouken@1933
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1933
     7
    License as published by the Free Software Foundation; either
slouken@1933
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1933
     9
slouken@1933
    10
    This library is distributed in the hope that it will be useful,
slouken@1933
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1933
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1933
    13
    Lesser General Public License for more details.
slouken@1933
    14
slouken@1933
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1933
    16
    License along with this library; if not, write to the Free Software
slouken@1933
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1933
    18
slouken@1933
    19
    Sam Lantinga
slouken@1933
    20
    slouken@libsdl.org
slouken@1933
    21
*/
slouken@1933
    22
#include "SDL_config.h"
slouken@1933
    23
slouken@1933
    24
#include "SDL_syswm.h"
slouken@1933
    25
#include "../SDL_sysvideo.h"
slouken@1933
    26
#include "../../events/SDL_keyboard_c.h"
slouken@1933
    27
#include "../../events/SDL_mouse_c.h"
slouken@4673
    28
#include "../../events/SDL_touch_c.h"
slouken@1933
    29
#include "../../events/SDL_windowevents_c.h"
slouken@1933
    30
#include "SDL_cocoavideo.h"
eligottlieb@4811
    31
#include "SDL_cocoashape.h"
gzjjgod@5057
    32
#include "SDL_cocoamouse.h"
slouken@1933
    33
slouken@1933
    34
static __inline__ void ConvertNSRect(NSRect *r)
slouken@1933
    35
{
slouken@1933
    36
    r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height;
slouken@1933
    37
}
slouken@1933
    38
slouken@1933
    39
@implementation Cocoa_WindowListener
slouken@1933
    40
slouken@1933
    41
- (void)listen:(SDL_WindowData *)data
slouken@1933
    42
{
slouken@1933
    43
    NSNotificationCenter *center;
slouken@5371
    44
    NSWindow *window = data->nswindow;
slouken@5371
    45
    NSView *view = [window contentView];
slouken@1933
    46
slouken@1933
    47
    _data = data;
slouken@1933
    48
slouken@1933
    49
    center = [NSNotificationCenter defaultCenter];
slouken@1933
    50
slouken@5374
    51
    if ([window delegate] != nil) {
slouken@5374
    52
        [center addObserver:self selector:@selector(windowDidExpose:) name:NSWindowDidExposeNotification object:window];
slouken@5374
    53
        [center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:window];
slouken@5374
    54
        [center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:window];
slouken@5374
    55
        [center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:window];
slouken@5374
    56
        [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
slouken@5374
    57
        [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
slouken@5374
    58
        [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
slouken@5374
    59
    } else {
slouken@5374
    60
        [window setDelegate:self];
slouken@5374
    61
    }
slouken@1933
    62
    [center addObserver:self selector:@selector(windowDidHide:) name:NSApplicationDidHideNotification object:NSApp];
slouken@1933
    63
    [center addObserver:self selector:@selector(windowDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp];
slouken@1933
    64
slouken@5371
    65
    [window setNextResponder:self];
slouken@5371
    66
    [window setAcceptsMouseMovedEvents:YES];
slouken@5371
    67
slouken@5371
    68
    [view setNextResponder:self];
slouken@5371
    69
    [view addTrackingRect:[view visibleRect] owner:self userData:nil assumeInside:NO];
slouken@4927
    70
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
slouken@5371
    71
    [view setAcceptsTouchEvents:YES];
slouken@4925
    72
#endif
slouken@1933
    73
}
slouken@1933
    74
slouken@1933
    75
- (void)close
slouken@1933
    76
{
slouken@1933
    77
    NSNotificationCenter *center;
slouken@5371
    78
    NSWindow *window = _data->nswindow;
slouken@5371
    79
    NSView *view = [window contentView];
slouken@1933
    80
slouken@1933
    81
    center = [NSNotificationCenter defaultCenter];
slouken@1933
    82
slouken@5374
    83
    if ([window delegate] != self) {
slouken@5374
    84
        [center removeObserver:self name:NSWindowDidExposeNotification object:window];
slouken@5374
    85
        [center removeObserver:self name:NSWindowDidMoveNotification object:window];
slouken@5374
    86
        [center removeObserver:self name:NSWindowDidResizeNotification object:window];
slouken@5374
    87
        [center removeObserver:self name:NSWindowDidMiniaturizeNotification object:window];
slouken@5374
    88
        [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
slouken@5374
    89
        [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
slouken@5374
    90
        [center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
slouken@5374
    91
    } else {
slouken@5374
    92
        [window setDelegate:nil];
slouken@5374
    93
    }
slouken@1933
    94
    [center removeObserver:self name:NSApplicationDidHideNotification object:NSApp];
slouken@1933
    95
    [center removeObserver:self name:NSApplicationDidUnhideNotification object:NSApp];
slouken@5371
    96
slouken@5374
    97
    if ([window nextResponder] == self) {
slouken@5374
    98
        [window setNextResponder:nil];
slouken@5374
    99
    }
slouken@5374
   100
    if ([view nextResponder] == self) {
slouken@5374
   101
        [view setNextResponder:nil];
slouken@5374
   102
    }
slouken@1933
   103
}
slouken@1933
   104
slouken@1933
   105
- (BOOL)windowShouldClose:(id)sender
slouken@1933
   106
{
slouken@3685
   107
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
slouken@1933
   108
    return NO;
slouken@1933
   109
}
slouken@1933
   110
slouken@1933
   111
- (void)windowDidExpose:(NSNotification *)aNotification
slouken@1933
   112
{
slouken@3685
   113
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
slouken@1933
   114
}
slouken@1933
   115
slouken@1933
   116
- (void)windowDidMove:(NSNotification *)aNotification
slouken@1933
   117
{
slouken@1933
   118
    int x, y;
slouken@3688
   119
    NSRect rect = [_data->nswindow contentRectForFrameRect:[_data->nswindow frame]];
slouken@1933
   120
    ConvertNSRect(&rect);
slouken@3507
   121
    x = (int)rect.origin.x;
slouken@3507
   122
    y = (int)rect.origin.y;
slouken@3685
   123
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MOVED, x, y);
slouken@1933
   124
}
slouken@1933
   125
slouken@1933
   126
- (void)windowDidResize:(NSNotification *)aNotification
slouken@1933
   127
{
slouken@1933
   128
    int w, h;
slouken@3688
   129
    NSRect rect = [_data->nswindow contentRectForFrameRect:[_data->nswindow frame]];
slouken@1933
   130
    w = (int)rect.size.width;
slouken@1933
   131
    h = (int)rect.size.height;
slouken@4937
   132
    if (SDL_IsShapedWindow(_data->window))
slouken@4937
   133
        Cocoa_ResizeWindowShape(_data->window);
slouken@3685
   134
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESIZED, w, h);
slouken@1933
   135
}
slouken@1933
   136
slouken@1933
   137
- (void)windowDidMiniaturize:(NSNotification *)aNotification
slouken@1933
   138
{
slouken@3685
   139
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
slouken@1933
   140
}
slouken@1933
   141
slouken@1933
   142
- (void)windowDidDeminiaturize:(NSNotification *)aNotification
slouken@1933
   143
{
slouken@3685
   144
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
slouken@1933
   145
}
slouken@1933
   146
slouken@1933
   147
- (void)windowDidBecomeKey:(NSNotification *)aNotification
slouken@1933
   148
{
slouken@5367
   149
    SDL_Window *window = _data->window;
slouken@5367
   150
slouken@3688
   151
    /* We're going to get keyboard events, since we're key. */
slouken@5367
   152
    SDL_SetKeyboardFocus(window);
slouken@5367
   153
slouken@5367
   154
    /* If we just gained focus we need the updated mouse position */
slouken@5371
   155
    if (SDL_GetMouseFocus() == window) {
slouken@5367
   156
        NSPoint point;
slouken@5367
   157
        point = [NSEvent mouseLocation];
slouken@5367
   158
        point = [_data->nswindow convertScreenToBase:point];
slouken@5367
   159
        point.y = window->h - point.y;
slouken@5367
   160
        SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y);
slouken@5367
   161
    }
slouken@1962
   162
slouken@4503
   163
    /* Check to see if someone updated the clipboard */
slouken@4503
   164
    Cocoa_CheckClipboardUpdate(_data->videodata);
slouken@1933
   165
}
slouken@1933
   166
slouken@1933
   167
- (void)windowDidResignKey:(NSNotification *)aNotification
slouken@1933
   168
{
slouken@2059
   169
    /* Some other window will get mouse events, since we're not key. */
slouken@4465
   170
    if (SDL_GetMouseFocus() == _data->window) {
slouken@4465
   171
        SDL_SetMouseFocus(NULL);
slouken@2059
   172
    }
slouken@2059
   173
slouken@2059
   174
    /* Some other window will get keyboard events, since we're not key. */
slouken@4465
   175
    if (SDL_GetKeyboardFocus() == _data->window) {
slouken@4465
   176
        SDL_SetKeyboardFocus(NULL);
slouken@4465
   177
    }
slouken@1933
   178
}
slouken@1933
   179
slouken@1933
   180
- (void)windowDidHide:(NSNotification *)aNotification
slouken@1933
   181
{
slouken@3685
   182
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
slouken@1933
   183
}
slouken@1933
   184
slouken@1933
   185
- (void)windowDidUnhide:(NSNotification *)aNotification
slouken@1933
   186
{
slouken@3685
   187
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
slouken@1933
   188
}
slouken@1933
   189
slouken@1933
   190
- (void)mouseDown:(NSEvent *)theEvent
slouken@1933
   191
{
slouken@1959
   192
    int button;
slouken@1933
   193
slouken@1959
   194
    switch ([theEvent buttonNumber]) {
slouken@1959
   195
    case 0:
slouken@1959
   196
        button = SDL_BUTTON_LEFT;
slouken@1959
   197
        break;
slouken@1959
   198
    case 1:
slouken@1959
   199
        button = SDL_BUTTON_RIGHT;
slouken@1959
   200
        break;
slouken@1959
   201
    case 2:
slouken@1959
   202
        button = SDL_BUTTON_MIDDLE;
slouken@1959
   203
        break;
slouken@1959
   204
    default:
slouken@5061
   205
        button = [theEvent buttonNumber] + 1;
slouken@1959
   206
        break;
slouken@1959
   207
    }
slouken@4484
   208
    SDL_SendMouseButton(_data->window, SDL_PRESSED, button);
slouken@1933
   209
}
slouken@1933
   210
slouken@1933
   211
- (void)rightMouseDown:(NSEvent *)theEvent
slouken@1933
   212
{
slouken@1959
   213
    [self mouseDown:theEvent];
slouken@1933
   214
}
slouken@1933
   215
slouken@1933
   216
- (void)otherMouseDown:(NSEvent *)theEvent
slouken@1933
   217
{
slouken@1959
   218
    [self mouseDown:theEvent];
slouken@1933
   219
}
slouken@1933
   220
slouken@1933
   221
- (void)mouseUp:(NSEvent *)theEvent
slouken@1933
   222
{
slouken@1959
   223
    int button;
slouken@1933
   224
slouken@1959
   225
    switch ([theEvent buttonNumber]) {
slouken@1959
   226
    case 0:
slouken@1959
   227
        button = SDL_BUTTON_LEFT;
slouken@1959
   228
        break;
slouken@1959
   229
    case 1:
slouken@1959
   230
        button = SDL_BUTTON_RIGHT;
slouken@1959
   231
        break;
slouken@1959
   232
    case 2:
slouken@1959
   233
        button = SDL_BUTTON_MIDDLE;
slouken@1959
   234
        break;
slouken@1959
   235
    default:
slouken@5061
   236
        button = [theEvent buttonNumber] + 1;
slouken@1959
   237
        break;
slouken@1959
   238
    }
slouken@4484
   239
    SDL_SendMouseButton(_data->window, SDL_RELEASED, button);
slouken@1933
   240
}
slouken@1933
   241
slouken@1933
   242
- (void)rightMouseUp:(NSEvent *)theEvent
slouken@1933
   243
{
slouken@1959
   244
    [self mouseUp:theEvent];
slouken@1933
   245
}
slouken@1933
   246
slouken@1933
   247
- (void)otherMouseUp:(NSEvent *)theEvent
slouken@1933
   248
{
slouken@1959
   249
    [self mouseUp:theEvent];
slouken@1933
   250
}
slouken@1933
   251
slouken@5371
   252
- (void)mouseEntered:(NSEvent *)theEvent
slouken@5371
   253
{
slouken@5376
   254
    SDL_Mouse *mouse = SDL_GetMouse();
slouken@5376
   255
slouken@5371
   256
    SDL_SetMouseFocus(_data->window);
slouken@5376
   257
slouken@5376
   258
    if (!mouse->cursor_shown) {
slouken@5376
   259
        [NSCursor hide];
slouken@5376
   260
    }
slouken@5371
   261
}
slouken@5371
   262
slouken@5371
   263
- (void)mouseExited:(NSEvent *)theEvent
slouken@5371
   264
{
slouken@5371
   265
    SDL_Window *window = _data->window;
slouken@5376
   266
    SDL_Mouse *mouse = SDL_GetMouse();
slouken@5371
   267
slouken@5371
   268
    if (SDL_GetMouseFocus() == window) {
slouken@5371
   269
        if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
slouken@5371
   270
            int x, y;
slouken@5371
   271
            NSPoint point;
slouken@5371
   272
            CGPoint cgpoint;
slouken@5371
   273
slouken@5371
   274
            point = [theEvent locationInWindow];
slouken@5371
   275
            point.y = window->h - point.y;
slouken@5371
   276
slouken@5371
   277
            SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y);
slouken@5371
   278
            SDL_GetMouseState(&x, &y);
slouken@5371
   279
            cgpoint.x = window->x + x;
slouken@5371
   280
            cgpoint.y = window->y + y;
slouken@5371
   281
            CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
slouken@5371
   282
        } else {
slouken@5371
   283
            SDL_SetMouseFocus(NULL);
slouken@5371
   284
        }
slouken@5371
   285
    }
slouken@5376
   286
slouken@5376
   287
    if (!mouse->cursor_shown) {
slouken@5376
   288
        [NSCursor unhide];
slouken@5376
   289
    }
slouken@5371
   290
}
slouken@5371
   291
slouken@1933
   292
- (void)mouseMoved:(NSEvent *)theEvent
slouken@1933
   293
{
slouken@3685
   294
    SDL_Window *window = _data->window;
slouken@1933
   295
slouken@5371
   296
#ifdef RELATIVE_MOTION
slouken@5371
   297
    if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
gzjjgod@5059
   298
        return;
slouken@5371
   299
    }
slouken@5371
   300
#endif
gzjjgod@5059
   301
slouken@5371
   302
    if (SDL_GetMouseFocus() == window) {
slouken@5371
   303
        NSPoint point;
slouken@5371
   304
slouken@5371
   305
        point = [theEvent locationInWindow];
slouken@5371
   306
        point.y = window->h - point.y;
slouken@5371
   307
slouken@4484
   308
        SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y);
slouken@2059
   309
    }
slouken@1933
   310
}
slouken@1933
   311
slouken@1957
   312
- (void)mouseDragged:(NSEvent *)theEvent
slouken@1957
   313
{
slouken@1957
   314
    [self mouseMoved:theEvent];
slouken@1957
   315
}
slouken@1957
   316
slouken@1958
   317
- (void)rightMouseDragged:(NSEvent *)theEvent
slouken@1958
   318
{
slouken@1958
   319
    [self mouseMoved:theEvent];
slouken@1958
   320
}
slouken@1958
   321
slouken@1958
   322
- (void)otherMouseDragged:(NSEvent *)theEvent
slouken@1958
   323
{
slouken@1958
   324
    [self mouseMoved:theEvent];
slouken@1958
   325
}
slouken@1958
   326
slouken@1933
   327
- (void)scrollWheel:(NSEvent *)theEvent
slouken@1933
   328
{
gzjjgod@5057
   329
    Cocoa_HandleMouseWheel(_data->window, theEvent);
slouken@3688
   330
}
slouken@3688
   331
slouken@4673
   332
- (void)touchesBeganWithEvent:(NSEvent *) theEvent
slouken@4673
   333
{
slouken@4673
   334
    [self handleTouches:COCOA_TOUCH_DOWN withEvent:theEvent];
slouken@4673
   335
}
slouken@4673
   336
slouken@4673
   337
- (void)touchesMovedWithEvent:(NSEvent *) theEvent
slouken@4673
   338
{
slouken@4673
   339
    [self handleTouches:COCOA_TOUCH_MOVE withEvent:theEvent];
slouken@4673
   340
}
slouken@4673
   341
slouken@4673
   342
- (void)touchesEndedWithEvent:(NSEvent *) theEvent
slouken@4673
   343
{
slouken@4673
   344
    [self handleTouches:COCOA_TOUCH_UP withEvent:theEvent];
slouken@4673
   345
}
slouken@4673
   346
slouken@4673
   347
- (void)touchesCancelledWithEvent:(NSEvent *) theEvent
slouken@4673
   348
{
slouken@4673
   349
    [self handleTouches:COCOA_TOUCH_CANCELLED withEvent:theEvent];
slouken@4673
   350
}
slouken@4673
   351
slouken@4673
   352
- (void)handleTouches:(cocoaTouchType)type withEvent:(NSEvent *)event
slouken@4673
   353
{
slouken@4927
   354
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
slouken@4680
   355
    NSSet *touches = 0;
slouken@4680
   356
    NSEnumerator *enumerator;
slouken@4680
   357
    NSTouch *touch;
slouken@4673
   358
slouken@4680
   359
    switch (type) {
slouken@4680
   360
        case COCOA_TOUCH_DOWN:
slouken@4680
   361
            touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:nil];
slouken@4680
   362
            break;
slouken@4680
   363
        case COCOA_TOUCH_UP:
slouken@4680
   364
        case COCOA_TOUCH_CANCELLED:
slouken@4680
   365
            touches = [event touchesMatchingPhase:NSTouchPhaseEnded inView:nil];
slouken@4680
   366
            break;
slouken@4680
   367
        case COCOA_TOUCH_MOVE:
slouken@4680
   368
            touches = [event touchesMatchingPhase:NSTouchPhaseMoved inView:nil];
slouken@4680
   369
            break;
slouken@4680
   370
    }
slouken@4680
   371
slouken@4680
   372
    enumerator = [touches objectEnumerator];
slouken@4680
   373
    touch = (NSTouch*)[enumerator nextObject];
slouken@4673
   374
    while (touch) {
slouken@4680
   375
        SDL_TouchID touchId = (SDL_TouchID)[touch device];
slouken@4673
   376
        if (!SDL_GetTouch(touchId)) {
slouken@4673
   377
            SDL_Touch touch;
slouken@4673
   378
slouken@4673
   379
            touch.id = touchId;
slouken@4673
   380
            touch.x_min = 0;
slouken@4673
   381
            touch.x_max = 1;
jimtla@4678
   382
            touch.native_xres = touch.x_max - touch.x_min;
slouken@4673
   383
            touch.y_min = 0;
slouken@4673
   384
            touch.y_max = 1;
jimtla@4678
   385
            touch.native_yres = touch.y_max - touch.y_min;
slouken@4673
   386
            touch.pressure_min = 0;
slouken@4673
   387
            touch.pressure_max = 1;
jimtla@4678
   388
            touch.native_pressureres = touch.pressure_max - touch.pressure_min;
slouken@4673
   389
            
slouken@4673
   390
            if (SDL_AddTouch(&touch, "") < 0) {
slouken@4680
   391
                return;
slouken@4673
   392
            }
slouken@4673
   393
        } 
slouken@4687
   394
slouken@4687
   395
        SDL_FingerID fingerId = (SDL_FingerID)[touch identity];
slouken@4673
   396
        float x = [touch normalizedPosition].x;
slouken@4673
   397
        float y = [touch normalizedPosition].y;
slouken@5261
   398
        /* Make the origin the upper left instead of the lower left */
slouken@5261
   399
        y = 1.0f - y;
slouken@4687
   400
slouken@4673
   401
        switch (type) {
slouken@4673
   402
        case COCOA_TOUCH_DOWN:
slouken@4673
   403
            SDL_SendFingerDown(touchId, fingerId, SDL_TRUE, x, y, 1);
slouken@4673
   404
            break;
slouken@4673
   405
        case COCOA_TOUCH_UP:
slouken@4673
   406
        case COCOA_TOUCH_CANCELLED:
slouken@4673
   407
            SDL_SendFingerDown(touchId, fingerId, SDL_FALSE, x, y, 1);
slouken@4673
   408
            break;
slouken@4673
   409
        case COCOA_TOUCH_MOVE:
slouken@4673
   410
            SDL_SendTouchMotion(touchId, fingerId, SDL_FALSE, x, y, 1);
slouken@4673
   411
            break;
slouken@4673
   412
        }
slouken@4673
   413
        
slouken@4673
   414
        touch = (NSTouch*)[enumerator nextObject];
slouken@4673
   415
    }
slouken@4927
   416
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 */
slouken@1933
   417
}
slouken@1933
   418
slouken@1933
   419
@end
slouken@1933
   420
slouken@1973
   421
@interface SDLWindow : NSWindow
slouken@1973
   422
/* These are needed for borderless/fullscreen windows */
slouken@1973
   423
- (BOOL)canBecomeKeyWindow;
slouken@1973
   424
- (BOOL)canBecomeMainWindow;
slouken@1973
   425
@end
slouken@1973
   426
slouken@1973
   427
@implementation SDLWindow
slouken@1973
   428
- (BOOL)canBecomeKeyWindow
slouken@1973
   429
{
slouken@1973
   430
    return YES;
slouken@1973
   431
}
slouken@1973
   432
slouken@1973
   433
- (BOOL)canBecomeMainWindow
slouken@1973
   434
{
slouken@1973
   435
    return YES;
slouken@1973
   436
}
slouken@1973
   437
@end
slouken@1973
   438
slouken@5379
   439
@interface SDLView : NSView
slouken@5379
   440
/* The default implementation doesn't pass rightMouseDown to responder chain */
slouken@5379
   441
- (void)rightMouseDown:(NSEvent *)theEvent;
gzjjgod@4915
   442
@end
gzjjgod@4915
   443
gzjjgod@4915
   444
@implementation SDLView
gzjjgod@4915
   445
- (void)rightMouseDown:(NSEvent *)theEvent
gzjjgod@4915
   446
{
slouken@5371
   447
    [[self nextResponder] rightMouseDown:theEvent];
gzjjgod@4915
   448
}
gzjjgod@4915
   449
@end
gzjjgod@4915
   450
slouken@5249
   451
static unsigned int
slouken@5305
   452
GetWindowStyle(SDL_Window * window)
slouken@5249
   453
{
slouken@5249
   454
    unsigned int style;
slouken@5249
   455
slouken@5305
   456
	if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@5249
   457
        style = NSBorderlessWindowMask;
slouken@5305
   458
	} else {
slouken@5305
   459
		if (window->flags & SDL_WINDOW_BORDERLESS) {
slouken@5305
   460
			style = NSBorderlessWindowMask;
slouken@5305
   461
		} else {
slouken@5305
   462
			style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
slouken@5305
   463
		}
slouken@5305
   464
		if (window->flags & SDL_WINDOW_RESIZABLE) {
slouken@5305
   465
			style |= NSResizableWindowMask;
slouken@5305
   466
		}
slouken@5305
   467
	}
slouken@5249
   468
    return style;
slouken@5249
   469
}
slouken@5249
   470
slouken@1933
   471
static int
slouken@1951
   472
SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
slouken@1933
   473
{
slouken@1933
   474
    NSAutoreleasePool *pool;
slouken@1951
   475
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
slouken@1933
   476
    SDL_WindowData *data;
slouken@1933
   477
slouken@1933
   478
    /* Allocate the window data */
slouken@5249
   479
    data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
slouken@1933
   480
    if (!data) {
slouken@1933
   481
        SDL_OutOfMemory();
slouken@1933
   482
        return -1;
slouken@1933
   483
    }
slouken@3685
   484
    data->window = window;
slouken@3688
   485
    data->nswindow = nswindow;
slouken@1933
   486
    data->created = created;
slouken@1951
   487
    data->videodata = videodata;
slouken@1933
   488
slouken@1933
   489
    pool = [[NSAutoreleasePool alloc] init];
slouken@1933
   490
slouken@1933
   491
    /* Create an event listener for the window */
slouken@1933
   492
    data->listener = [[Cocoa_WindowListener alloc] init];
slouken@1933
   493
slouken@1933
   494
    /* Fill in the SDL window with the window data */
slouken@1933
   495
    {
slouken@1933
   496
        NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
slouken@5371
   497
        NSView *contentView = [[SDLView alloc] initWithFrame:rect];
gzjjgod@4915
   498
        [nswindow setContentView: contentView];
gzjjgod@4915
   499
        [contentView release];
gzjjgod@4915
   500
slouken@1933
   501
        ConvertNSRect(&rect);
slouken@5261
   502
        window->x = (int)rect.origin.x;
slouken@5261
   503
        window->y = (int)rect.origin.y;
slouken@5261
   504
        window->w = (int)rect.size.width;
slouken@5261
   505
        window->h = (int)rect.size.height;
slouken@1933
   506
    }
slouken@5371
   507
slouken@5371
   508
    /* Set up the listener after we create the view */
slouken@5371
   509
    [data->listener listen:data];
slouken@5371
   510
slouken@1933
   511
    if ([nswindow isVisible]) {
slouken@1933
   512
        window->flags |= SDL_WINDOW_SHOWN;
slouken@1933
   513
    } else {
slouken@1933
   514
        window->flags &= ~SDL_WINDOW_SHOWN;
slouken@1933
   515
    }
slouken@1933
   516
    {
slouken@1933
   517
        unsigned int style = [nswindow styleMask];
slouken@1933
   518
slouken@5380
   519
        if (style == NSBorderlessWindowMask) {
slouken@1933
   520
            window->flags |= SDL_WINDOW_BORDERLESS;
slouken@1933
   521
        } else {
slouken@1933
   522
            window->flags &= ~SDL_WINDOW_BORDERLESS;
slouken@1933
   523
        }
slouken@1933
   524
        if (style & NSResizableWindowMask) {
slouken@1933
   525
            window->flags |= SDL_WINDOW_RESIZABLE;
slouken@1933
   526
        } else {
slouken@1933
   527
            window->flags &= ~SDL_WINDOW_RESIZABLE;
slouken@1933
   528
        }
slouken@1933
   529
    }
slouken@5380
   530
    /* isZoomed always returns true if the window is not resizable */
slouken@5380
   531
    if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
slouken@1933
   532
        window->flags |= SDL_WINDOW_MAXIMIZED;
slouken@1933
   533
    } else {
slouken@1933
   534
        window->flags &= ~SDL_WINDOW_MAXIMIZED;
slouken@1933
   535
    }
slouken@1933
   536
    if ([nswindow isMiniaturized]) {
slouken@1933
   537
        window->flags |= SDL_WINDOW_MINIMIZED;
slouken@1933
   538
    } else {
slouken@1933
   539
        window->flags &= ~SDL_WINDOW_MINIMIZED;
slouken@1933
   540
    }
slouken@1933
   541
    if ([nswindow isKeyWindow]) {
slouken@1933
   542
        window->flags |= SDL_WINDOW_INPUT_FOCUS;
slouken@4465
   543
        SDL_SetKeyboardFocus(data->window);
slouken@1933
   544
    }
slouken@1933
   545
slouken@1933
   546
    /* All done! */
slouken@1933
   547
    [pool release];
slouken@1933
   548
    window->driverdata = data;
slouken@1933
   549
    return 0;
slouken@1933
   550
}
slouken@1933
   551
slouken@1933
   552
int
slouken@1933
   553
Cocoa_CreateWindow(_THIS, SDL_Window * window)
slouken@1933
   554
{
slouken@3506
   555
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@1933
   556
    NSWindow *nswindow;
slouken@5246
   557
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
slouken@1933
   558
    NSRect rect;
slouken@3528
   559
    SDL_Rect bounds;
slouken@1933
   560
    unsigned int style;
slouken@1933
   561
slouken@3528
   562
    Cocoa_GetDisplayBounds(_this, display, &bounds);
slouken@5380
   563
    rect.origin.x = window->x;
slouken@5380
   564
    rect.origin.y = window->y;
slouken@1933
   565
    rect.size.width = window->w;
slouken@1933
   566
    rect.size.height = window->h;
slouken@1933
   567
    ConvertNSRect(&rect);
slouken@1933
   568
slouken@5305
   569
    style = GetWindowStyle(window);
slouken@1933
   570
slouken@3506
   571
    /* Figure out which screen to place this window */
slouken@3506
   572
    NSArray *screens = [NSScreen screens];
slouken@3506
   573
    NSScreen *screen = nil;
slouken@3506
   574
    NSScreen *candidate;
slouken@3525
   575
    int i, count = [screens count];
slouken@3525
   576
    for (i = 0; i < count; ++i) {
slouken@3529
   577
        candidate = [screens objectAtIndex:i];
slouken@3506
   578
        NSRect screenRect = [candidate frame];
slouken@3506
   579
        if (rect.origin.x >= screenRect.origin.x &&
slouken@3506
   580
            rect.origin.x < screenRect.origin.x + screenRect.size.width &&
slouken@3506
   581
            rect.origin.y >= screenRect.origin.y &&
slouken@3506
   582
            rect.origin.y < screenRect.origin.y + screenRect.size.height) {
slouken@3506
   583
            screen = candidate;
slouken@3506
   584
            rect.origin.x -= screenRect.origin.x;
slouken@3506
   585
            rect.origin.y -= screenRect.origin.y;
slouken@3506
   586
        }
slouken@3506
   587
    }
slouken@5379
   588
    nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:YES screen:screen];
slouken@1933
   589
slouken@1933
   590
    [pool release];
slouken@1933
   591
slouken@1951
   592
    if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
slouken@1933
   593
        [nswindow release];
slouken@1933
   594
        return -1;
slouken@1933
   595
    }
slouken@1933
   596
    return 0;
slouken@1933
   597
}
slouken@1933
   598
slouken@1933
   599
int
slouken@1933
   600
Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
slouken@1933
   601
{
slouken@1933
   602
    NSAutoreleasePool *pool;
slouken@1933
   603
    NSWindow *nswindow = (NSWindow *) data;
slouken@1933
   604
    NSString *title;
slouken@1933
   605
slouken@1933
   606
    pool = [[NSAutoreleasePool alloc] init];
slouken@1933
   607
slouken@1933
   608
    /* Query the title from the existing window */
slouken@1933
   609
    title = [nswindow title];
slouken@1933
   610
    if (title) {
slouken@1933
   611
        window->title = SDL_strdup([title UTF8String]);
slouken@1933
   612
    }
slouken@1933
   613
slouken@1933
   614
    [pool release];
slouken@1933
   615
slouken@1951
   616
    return SetupWindowData(_this, window, nswindow, SDL_FALSE);
slouken@1933
   617
}
slouken@1933
   618
slouken@1933
   619
void
slouken@1933
   620
Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
slouken@1933
   621
{
slouken@1937
   622
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   623
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   624
    NSString *string;
slouken@1933
   625
slouken@1956
   626
    if(window->title) {
slouken@1956
   627
        string = [[NSString alloc] initWithUTF8String:window->title];
slouken@1956
   628
    } else {
slouken@1956
   629
        string = [[NSString alloc] init];
slouken@1956
   630
    }
slouken@1933
   631
    [nswindow setTitle:string];
slouken@1933
   632
    [string release];
slouken@1956
   633
slouken@1937
   634
    [pool release];
slouken@1933
   635
}
slouken@1933
   636
slouken@1933
   637
void
slouken@5375
   638
Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
slouken@5375
   639
{
slouken@5375
   640
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@5375
   641
    NSImage *nsimage = Cocoa_CreateImage(icon);
slouken@5375
   642
slouken@5375
   643
    if (nsimage) {
slouken@5375
   644
        [NSApp setApplicationIconImage:nsimage];
slouken@5375
   645
    }
slouken@5375
   646
slouken@5375
   647
    [pool release];
slouken@5375
   648
}
slouken@5375
   649
slouken@5375
   650
void
slouken@1933
   651
Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
slouken@1933
   652
{
slouken@1937
   653
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   654
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@5246
   655
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
slouken@1933
   656
    NSRect rect;
slouken@3528
   657
    SDL_Rect bounds;
slouken@1933
   658
slouken@3528
   659
    Cocoa_GetDisplayBounds(_this, display, &bounds);
slouken@5249
   660
    if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
slouken@3528
   661
        rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
slouken@3075
   662
    } else {
slouken@5246
   663
        rect.origin.x = window->x;
slouken@3075
   664
    }
slouken@5249
   665
    if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
slouken@3528
   666
        rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
slouken@3075
   667
    } else {
slouken@5246
   668
        rect.origin.y = window->y;
slouken@3075
   669
    }
slouken@1933
   670
    rect.size.width = window->w;
slouken@1933
   671
    rect.size.height = window->h;
slouken@1933
   672
    ConvertNSRect(&rect);
slouken@1933
   673
    rect = [nswindow frameRectForContentRect:rect];
slouken@1933
   674
    [nswindow setFrameOrigin:rect.origin];
slouken@1937
   675
    [pool release];
slouken@1933
   676
}
slouken@1933
   677
slouken@1933
   678
void
slouken@1933
   679
Cocoa_SetWindowSize(_THIS, SDL_Window * window)
slouken@1933
   680
{
slouken@1937
   681
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   682
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   683
    NSSize size;
slouken@1933
   684
slouken@1933
   685
    size.width = window->w;
slouken@1933
   686
    size.height = window->h;
slouken@1933
   687
    [nswindow setContentSize:size];
slouken@1937
   688
    [pool release];
slouken@1933
   689
}
slouken@1933
   690
slouken@1933
   691
void
slouken@1933
   692
Cocoa_ShowWindow(_THIS, SDL_Window * window)
slouken@1933
   693
{
slouken@1937
   694
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   695
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   696
slouken@1956
   697
    if (![nswindow isMiniaturized]) {
slouken@1956
   698
        [nswindow makeKeyAndOrderFront:nil];
slouken@1956
   699
    }
slouken@1937
   700
    [pool release];
slouken@1933
   701
}
slouken@1933
   702
slouken@1933
   703
void
slouken@1933
   704
Cocoa_HideWindow(_THIS, SDL_Window * window)
slouken@1933
   705
{
slouken@1956
   706
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   707
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   708
slouken@1956
   709
    [nswindow orderOut:nil];
slouken@1956
   710
    [pool release];
slouken@1933
   711
}
slouken@1933
   712
slouken@1933
   713
void
slouken@1933
   714
Cocoa_RaiseWindow(_THIS, SDL_Window * window)
slouken@1933
   715
{
slouken@1937
   716
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   717
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   718
slouken@1933
   719
    [nswindow makeKeyAndOrderFront:nil];
slouken@1937
   720
    [pool release];
slouken@1933
   721
}
slouken@1933
   722
slouken@1933
   723
void
slouken@1933
   724
Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
slouken@1933
   725
{
slouken@1937
   726
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   727
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   728
slouken@1956
   729
    [nswindow zoom:nil];
slouken@1937
   730
    [pool release];
slouken@1933
   731
}
slouken@1933
   732
slouken@1933
   733
void
slouken@1933
   734
Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
slouken@1933
   735
{
slouken@1937
   736
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   737
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   738
slouken@1956
   739
    [nswindow miniaturize:nil];
slouken@1937
   740
    [pool release];
slouken@1933
   741
}
slouken@1933
   742
slouken@1933
   743
void
slouken@1933
   744
Cocoa_RestoreWindow(_THIS, SDL_Window * window)
slouken@1933
   745
{
slouken@1956
   746
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   747
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   748
slouken@1956
   749
    if ([nswindow isMiniaturized]) {
slouken@1956
   750
        [nswindow deminiaturize:nil];
slouken@5380
   751
    } else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
slouken@1956
   752
        [nswindow zoom:nil];
slouken@1956
   753
    }
slouken@1956
   754
    [pool release];
slouken@1933
   755
}
slouken@1933
   756
slouken@1933
   757
void
slouken@5305
   758
Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
slouken@5249
   759
{
slouken@5249
   760
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@5249
   761
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@5249
   762
    NSWindow *nswindow = data->nswindow;
slouken@5249
   763
    NSRect rect;
slouken@5249
   764
slouken@5305
   765
    if (fullscreen) {
slouken@5249
   766
        SDL_Rect bounds;
slouken@5249
   767
slouken@5249
   768
        Cocoa_GetDisplayBounds(_this, display, &bounds);
slouken@5249
   769
        rect.origin.x = bounds.x;
slouken@5249
   770
        rect.origin.y = bounds.y;
slouken@5249
   771
        rect.size.width = bounds.w;
slouken@5249
   772
        rect.size.height = bounds.h;
slouken@5249
   773
        ConvertNSRect(&rect);
slouken@5249
   774
slouken@5361
   775
        if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
slouken@5361
   776
            [nswindow performSelector: @selector(setStyleMask:) withObject: (id)NSBorderlessWindowMask];
slouken@5361
   777
        }
slouken@5361
   778
        [nswindow setFrameOrigin:rect.origin];
slouken@5261
   779
        [nswindow setContentSize:rect.size];
slouken@5249
   780
    } else {
slouken@5361
   781
        if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
slouken@5378
   782
            [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];
slouken@5361
   783
        }
slouken@5249
   784
slouken@5261
   785
        // This doesn't seem to do anything...
slouken@5261
   786
        //[nswindow setFrameOrigin:origin];
slouken@5249
   787
    }
slouken@5249
   788
slouken@5249
   789
#ifdef FULLSCREEN_TOGGLEABLE
slouken@5305
   790
    if (fullscreen) {
slouken@5249
   791
        /* OpenGL is rendering to the window, so make it visible! */
slouken@5249
   792
        [nswindow setLevel:CGShieldingWindowLevel()];
slouken@5249
   793
    } else {
slouken@5249
   794
        [nswindow setLevel:kCGNormalWindowLevel];
slouken@5249
   795
    }
slouken@5249
   796
#endif
slouken@5249
   797
    [nswindow makeKeyAndOrderFront:nil];
slouken@5249
   798
slouken@5249
   799
    [pool release];
slouken@5249
   800
}
slouken@5249
   801
slouken@5371
   802
NSPoint origin;
slouken@5249
   803
void
slouken@1933
   804
Cocoa_SetWindowGrab(_THIS, SDL_Window * window)
slouken@1933
   805
{
slouken@5371
   806
#ifdef RELATIVE_MOTION
slouken@5371
   807
    /* FIXME: work in progress
slouken@5371
   808
        You set relative mode by using the following code in conjunction with
slouken@5371
   809
        CGDisplayHideCursor(kCGDirectMainDisplay) and
slouken@5371
   810
        CGDisplayShowCursor(kCGDirectMainDisplay)
slouken@5371
   811
    */
slouken@1933
   812
    if ((window->flags & SDL_WINDOW_INPUT_GRABBED) &&
slouken@1933
   813
        (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
slouken@5371
   814
        CGAssociateMouseAndMouseCursorPosition(NO);
slouken@1933
   815
    } else {
slouken@5371
   816
        CGAssociateMouseAndMouseCursorPosition(YES);
slouken@1933
   817
    }
slouken@5371
   818
#else
slouken@5371
   819
    /* Move the cursor to the nearest point in the window */
slouken@5371
   820
    if ((window->flags & SDL_WINDOW_INPUT_GRABBED) &&
slouken@5371
   821
        (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
slouken@5371
   822
        int x, y;
slouken@5371
   823
        CGPoint cgpoint;
slouken@5371
   824
slouken@5371
   825
        SDL_GetMouseState(&x, &y);
slouken@5371
   826
        cgpoint.x = window->x + x;
slouken@5371
   827
        cgpoint.y = window->y + y;
slouken@5371
   828
        CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
slouken@5371
   829
    }
slouken@5371
   830
#endif
slouken@1933
   831
}
slouken@1933
   832
slouken@1933
   833
void
slouken@1933
   834
Cocoa_DestroyWindow(_THIS, SDL_Window * window)
slouken@1933
   835
{
slouken@1937
   836
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@1933
   837
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@1933
   838
slouken@1933
   839
    if (data) {
slouken@1933
   840
        [data->listener close];
slouken@1933
   841
        [data->listener release];
slouken@1933
   842
        if (data->created) {
slouken@3688
   843
            [data->nswindow close];
slouken@1933
   844
        }
slouken@1933
   845
        SDL_free(data);
slouken@1933
   846
    }
slouken@1937
   847
    [pool release];
slouken@1933
   848
}
slouken@1933
   849
slouken@1933
   850
SDL_bool
slouken@1933
   851
Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
slouken@1933
   852
{
slouken@4900
   853
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   854
slouken@1933
   855
    if (info->version.major <= SDL_MAJOR_VERSION) {
slouken@4900
   856
        info->subsystem = SDL_SYSWM_COCOA;
slouken@5056
   857
        info->info.cocoa.window = nswindow;
slouken@1933
   858
        return SDL_TRUE;
slouken@1933
   859
    } else {
slouken@1933
   860
        SDL_SetError("Application not compiled with SDL %d.%d\n",
slouken@1933
   861
                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
slouken@1933
   862
        return SDL_FALSE;
slouken@1933
   863
    }
slouken@1933
   864
}
slouken@1933
   865
slouken@1933
   866
/* vi: set ts=4 sw=4 expandtab: */