src/video/quartz/SDL_QuartzWM.m
author Sam Lantinga <slouken@libsdl.org>
Sun, 20 Apr 2003 05:41:16 +0000
changeset 615 7ec821f3cbd0
parent 592 1970e458070d
child 683 5d2f027b3349
permissions -rw-r--r--
Date: Thu, 17 Apr 2003 23:27:34 -0400
From: Darrell Walisser
Subject: Yet another OS X cursor bug

The synopsis:

1. Call SDL_ShowCursor(0);
2. Call SDL_SetVideoMode();
3. Call SDL_GetEvent();
3. Call SDL_ShowCursor(1);

The result: Sometimes the cursor doesn't come back! Ack! Oddly enough,
it does come back when mousing over the dock or clicking in the menu
bar. But that's besides the point.

The reason why this is happening is a flaw in the handling of
activation/deactivation events. The short explanation is that the
HideCursor() and ShowCursor() calls must be balanced, but if the cursor
was initially hidden, HideCursor() was called again on the activate
event - so now the next ShowCursor() fails (as does the next, and the
next, for some reason).

So, here's the patch. All it does is keep track of the
HideCursor()/ShowCursor() calls so that they will always be balanced.
slouken@47
     1
/*
slouken@47
     2
    SDL - Simple DirectMedia Layer
slouken@297
     3
    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
slouken@47
     4
slouken@47
     5
    This library is free software; you can redistribute it and/or
slouken@47
     6
    modify it under the terms of the GNU Library General Public
slouken@47
     7
    License as published by the Free Software Foundation; either
slouken@47
     8
    version 2 of the License, or (at your option) any later version.
slouken@47
     9
slouken@47
    10
    This library is distributed in the hope that it will be useful,
slouken@47
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@47
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@47
    13
    Library General Public License for more details.
slouken@47
    14
slouken@47
    15
    You should have received a copy of the GNU Library General Public
slouken@47
    16
    License along with this library; if not, write to the Free
slouken@47
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@47
    18
slouken@47
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@47
    21
*/
slouken@47
    22
icculus@563
    23
static void QZ_ChangeGrabState (_THIS, int action);
icculus@563
    24
slouken@47
    25
struct WMcursor {
slouken@47
    26
    Cursor curs;
slouken@47
    27
};
slouken@47
    28
slouken@47
    29
static void QZ_FreeWMCursor     (_THIS, WMcursor *cursor) { 
slouken@47
    30
slouken@47
    31
    if ( cursor != NULL )
slouken@47
    32
        free (cursor);
slouken@47
    33
}
slouken@47
    34
slouken@47
    35
/* Use the Carbon cursor routines for now */
slouken@47
    36
static WMcursor*    QZ_CreateWMCursor   (_THIS, Uint8 *data, Uint8 *mask, 
slouken@390
    37
                                         int w, int h, int hot_x, int hot_y) { 
slouken@390
    38
    WMcursor *cursor;
slouken@390
    39
    int row, bytes;
slouken@390
    40
        
slouken@390
    41
    /* Allocate the cursor memory */
slouken@390
    42
    cursor = (WMcursor *)malloc(sizeof(WMcursor));
slouken@390
    43
    if ( cursor == NULL ) {
slouken@390
    44
        SDL_OutOfMemory();
slouken@390
    45
        return(NULL);
slouken@390
    46
    }
slouken@390
    47
    memset(cursor, 0, sizeof(*cursor));
slouken@168
    48
    
slouken@168
    49
    if (w > 16)
slouken@168
    50
        w = 16;
slouken@168
    51
    
slouken@168
    52
    if (h > 16)
slouken@168
    53
        h = 16;
slouken@168
    54
    
slouken@390
    55
    bytes = (w+7)/8;
slouken@168
    56
slouken@390
    57
    for ( row=0; row<h; ++row ) {
slouken@390
    58
        memcpy(&cursor->curs.data[row], data, bytes);
slouken@390
    59
        data += bytes;
slouken@390
    60
    }
slouken@390
    61
    for ( row=0; row<h; ++row ) {
slouken@390
    62
        memcpy(&cursor->curs.mask[row], mask, bytes);
slouken@390
    63
        mask += bytes;
slouken@390
    64
    }
slouken@390
    65
    cursor->curs.hotSpot.h = hot_x;
slouken@390
    66
    cursor->curs.hotSpot.v = hot_y;
slouken@390
    67
    
slouken@168
    68
    return(cursor);
slouken@47
    69
}
slouken@47
    70
slouken@47
    71
static int QZ_ShowWMCursor (_THIS, WMcursor *cursor) { 
slouken@47
    72
slouken@47
    73
    if ( cursor == NULL) {
icculus@563
    74
        if ( cursor_visible ) {
slouken@615
    75
            if (!cursor_hidden) {
slouken@615
    76
                HideCursor ();
slouken@615
    77
                cursor_hidden = YES;
slouken@615
    78
            }
icculus@563
    79
            cursor_visible = NO;
icculus@563
    80
            QZ_ChangeGrabState (this, QZ_HIDECURSOR);
slouken@47
    81
        }
slouken@47
    82
    }
slouken@47
    83
    else {
slouken@47
    84
        SetCursor(&cursor->curs);
icculus@563
    85
        if ( ! cursor_visible ) {
slouken@615
    86
            if (cursor_hidden) {
slouken@615
    87
                ShowCursor ();
slouken@615
    88
                cursor_hidden = NO;
slouken@615
    89
            }
icculus@563
    90
            cursor_visible = YES;
icculus@563
    91
            QZ_ChangeGrabState (this, QZ_SHOWCURSOR);
slouken@47
    92
        }
slouken@47
    93
    }
slouken@47
    94
slouken@47
    95
    return 1;
slouken@47
    96
}
slouken@47
    97
slouken@501
    98
/*
slouken@501
    99
    Coordinate conversion functions, for convenience
slouken@501
   100
    Cocoa sets the origin at the lower left corner of the window/screen
slouken@501
   101
    SDL, CoreGraphics/WindowServer, and QuickDraw use the origin at the upper left corner
slouken@501
   102
    The routines were written so they could be called before SetVideoMode() has finished;
slouken@501
   103
    this might have limited usefulness at the moment, but the extra cost is trivial.
slouken@501
   104
*/
slouken@47
   105
slouken@272
   106
/* Convert Cocoa screen coordinate to Cocoa window coordinate */
slouken@272
   107
static void QZ_PrivateGlobalToLocal (_THIS, NSPoint *p) {
slouken@272
   108
slouken@272
   109
    *p = [ qz_window convertScreenToBase:*p ];
slouken@272
   110
}
slouken@272
   111
slouken@272
   112
slouken@272
   113
/* Convert Cocoa window coordinate to Cocoa screen coordinate */
slouken@272
   114
static void QZ_PrivateLocalToGlobal (_THIS, NSPoint *p) {
slouken@272
   115
slouken@272
   116
    *p = [ qz_window convertBaseToScreen:*p ];
slouken@272
   117
}
slouken@272
   118
slouken@272
   119
/* Convert SDL coordinate to Cocoa coordinate */
slouken@272
   120
static void QZ_PrivateSDLToCocoa (_THIS, NSPoint *p) {
slouken@272
   121
slouken@272
   122
    int height;
slouken@47
   123
    
slouken@272
   124
    if ( CGDisplayIsCaptured (display_id) ) { /* capture signals fullscreen */
slouken@272
   125
    
slouken@272
   126
        height = CGDisplayPixelsHigh (display_id);
slouken@272
   127
    }
slouken@272
   128
    else {
slouken@47
   129
        
slouken@272
   130
        height = NSHeight ( [ qz_window frame ] );
slouken@272
   131
        if ( [ qz_window styleMask ] & NSTitledWindowMask ) {
slouken@272
   132
        
slouken@272
   133
            height -= 22;
slouken@272
   134
        }
slouken@272
   135
    }
slouken@272
   136
    
icculus@563
   137
    p->y = height - p->y - 1;
slouken@272
   138
}
slouken@272
   139
slouken@272
   140
/* Convert Cocoa coordinate to SDL coordinate */
slouken@272
   141
static void QZ_PrivateCocoaToSDL (_THIS, NSPoint *p) {
slouken@272
   142
slouken@272
   143
    QZ_PrivateSDLToCocoa (this, p);
slouken@272
   144
}
slouken@272
   145
slouken@272
   146
/* Convert SDL coordinate to window server (CoreGraphics) coordinate */
slouken@272
   147
static CGPoint QZ_PrivateSDLToCG (_THIS, NSPoint *p) {
slouken@272
   148
    
slouken@272
   149
    CGPoint cgp;
slouken@272
   150
    
slouken@272
   151
    if ( ! CGDisplayIsCaptured (display_id) ) { /* not captured => not fullscreen => local coord */
slouken@272
   152
    
slouken@272
   153
        int height;
slouken@272
   154
        
slouken@272
   155
        QZ_PrivateSDLToCocoa (this, p);
slouken@272
   156
        QZ_PrivateLocalToGlobal (this, p);
slouken@272
   157
        
slouken@272
   158
        height = CGDisplayPixelsHigh (display_id);
slouken@272
   159
        p->y = height - p->y;
slouken@272
   160
    }
slouken@272
   161
    
slouken@272
   162
    cgp.x = p->x;
slouken@272
   163
    cgp.y = p->y;
slouken@272
   164
    
slouken@272
   165
    return cgp;
slouken@272
   166
}
slouken@272
   167
slouken@272
   168
/* Convert window server (CoreGraphics) coordinate to SDL coordinate */
slouken@272
   169
static void QZ_PrivateCGToSDL (_THIS, NSPoint *p) {
slouken@272
   170
            
slouken@272
   171
    if ( ! CGDisplayIsCaptured (display_id) ) { /* not captured => not fullscreen => local coord */
slouken@272
   172
    
slouken@272
   173
        int height;
slouken@272
   174
slouken@272
   175
        /* Convert CG Global to Cocoa Global */
slouken@272
   176
        height = CGDisplayPixelsHigh (display_id);
slouken@272
   177
        p->y = height - p->y;
slouken@272
   178
slouken@272
   179
        QZ_PrivateGlobalToLocal (this, p);
slouken@272
   180
        QZ_PrivateCocoaToSDL (this, p);
slouken@47
   181
    }
slouken@47
   182
}
slouken@47
   183
slouken@272
   184
static void  QZ_PrivateWarpCursor (_THIS, int x, int y) {
slouken@47
   185
    
slouken@272
   186
    NSPoint p;
slouken@272
   187
    CGPoint cgp;
slouken@272
   188
    
slouken@272
   189
    p = NSMakePoint (x, y);
icculus@563
   190
    cgp = QZ_PrivateSDLToCG (this, &p);
icculus@563
   191
    QZ_PrivateCGToSDL (this, &p);
icculus@563
   192
    
icculus@563
   193
    /* this is the magic call that fixes cursor "freezing" after warp */
icculus@563
   194
    CGSetLocalEventsSuppressionInterval (0.0);
icculus@563
   195
    CGWarpMouseCursorPosition (cgp);
slouken@272
   196
}
slouken@272
   197
slouken@272
   198
static void QZ_WarpWMCursor (_THIS, Uint16 x, Uint16 y) {
slouken@272
   199
slouken@47
   200
    /* Only allow warping when in foreground */
slouken@501
   201
    if ( ! in_foreground )
slouken@47
   202
        return;
slouken@47
   203
            
slouken@47
   204
    /* Do the actual warp */
slouken@272
   205
    QZ_PrivateWarpCursor (this, x, y);
icculus@563
   206
icculus@563
   207
    /* Generate the mouse moved event */
icculus@563
   208
    SDL_PrivateMouseMotion (0, 0, x, y);
slouken@47
   209
}
slouken@47
   210
slouken@47
   211
static void QZ_MoveWMCursor     (_THIS, int x, int y) { }
slouken@47
   212
static void QZ_CheckMouseMode   (_THIS) { }
slouken@47
   213
slouken@47
   214
static void QZ_SetCaption    (_THIS, const char *title, const char *icon) {
slouken@47
   215
slouken@158
   216
    if ( qz_window != nil ) {
slouken@58
   217
        NSString *string;
slouken@58
   218
        if ( title != NULL ) {
slouken@58
   219
            string = [ [ NSString alloc ] initWithCString:title ];
slouken@158
   220
            [ qz_window setTitle:string ];
slouken@58
   221
            [ string release ];
slouken@58
   222
        }
slouken@58
   223
        if ( icon != NULL ) {
slouken@58
   224
            string = [ [ NSString alloc ] initWithCString:icon ];
slouken@158
   225
            [ qz_window setMiniwindowTitle:string ];
slouken@58
   226
            [ string release ];
slouken@58
   227
        }
slouken@58
   228
    }
slouken@47
   229
}
slouken@47
   230
slouken@269
   231
static void QZ_SetIcon       (_THIS, SDL_Surface *icon, Uint8 *mask)
slouken@269
   232
{
slouken@501
   233
    NSBitmapImageRep *imgrep;
slouken@501
   234
    NSImage *img;
slouken@501
   235
    SDL_Surface *mergedSurface;
slouken@592
   236
    int i,j;
slouken@501
   237
    NSAutoreleasePool *pool;
slouken@501
   238
    SDL_Rect rrect;
slouken@501
   239
    NSSize imgSize = {icon->w, icon->h};
slouken@501
   240
    
slouken@501
   241
    pool = [ [ NSAutoreleasePool alloc ] init ];
slouken@501
   242
    SDL_GetClipRect(icon, &rrect);
slouken@501
   243
    
slouken@501
   244
    /* create a big endian RGBA surface */
slouken@501
   245
    mergedSurface = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA, 
slouken@501
   246
                    icon->w, icon->h, 32, 0xff<<24, 0xff<<16, 0xff<<8, 0xff<<0);
slouken@501
   247
    if (mergedSurface==NULL) {
slouken@324
   248
        NSLog(@"Error creating surface for merge");
slouken@324
   249
        goto freePool;
slouken@324
   250
    }
slouken@501
   251
    
slouken@592
   252
    if (mergedSurface->pitch != 
slouken@592
   253
        mergedSurface->format->BytesPerPixel * mergedSurface->w) {
slouken@592
   254
        SDL_SetError ("merged surface has wrong format");
slouken@592
   255
        SDL_FreeSurface (mergedSurface);
slouken@592
   256
        goto freePool;
slouken@592
   257
    }
slouken@592
   258
    
slouken@501
   259
    if (SDL_BlitSurface(icon,&rrect,mergedSurface,&rrect)) {
slouken@501
   260
        NSLog(@"Error blitting to mergedSurface");
slouken@501
   261
        goto freePool;
slouken@501
   262
    }
slouken@501
   263
    
slouken@501
   264
    if (mask) {
slouken@592
   265
slouken@592
   266
        Uint32 *pixels = mergedSurface->pixels;
slouken@592
   267
        for (i = 0; i < mergedSurface->h; i++) {
slouken@592
   268
            for (j = 0; j < mergedSurface->w; j++) {
slouken@592
   269
                
slouken@592
   270
                int index = i * mergedSurface->w + j;
slouken@592
   271
                int mindex = index >> 3;
slouken@592
   272
                int bindex = 7 - (index & 0x7);
slouken@592
   273
                
slouken@592
   274
                if (mask[mindex] & (1 << bindex))
slouken@592
   275
                    pixels[index] |= 0x000000FF;
slouken@592
   276
                else
slouken@592
   277
                    pixels[index] &= 0xFFFFFF00;
slouken@592
   278
            }
slouken@592
   279
        }
slouken@501
   280
    }
slouken@501
   281
    
slouken@501
   282
    imgrep = [ [ NSBitmapImageRep alloc] 
slouken@501
   283
                    initWithBitmapDataPlanes:(unsigned char **)&mergedSurface->pixels 
slouken@501
   284
                        pixelsWide:icon->w pixelsHigh:icon->h bitsPerSample:8 samplesPerPixel:4 
slouken@501
   285
                        hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace 
slouken@501
   286
                        bytesPerRow:icon->w<<2 bitsPerPixel:32 ];
slouken@501
   287
    
slouken@501
   288
    img = [ [ NSImage alloc ] initWithSize:imgSize ];
slouken@501
   289
    
slouken@501
   290
    [ img addRepresentation: imgrep ];
slouken@501
   291
    [ NSApp setApplicationIconImage:img ];
slouken@501
   292
    
slouken@501
   293
    [ img release ];
slouken@501
   294
    [ imgrep release ];
slouken@501
   295
    SDL_FreeSurface(mergedSurface);
slouken@269
   296
freePool:
slouken@501
   297
    [pool release];
slouken@47
   298
}
slouken@47
   299
slouken@47
   300
static int  QZ_IconifyWindow (_THIS) { 
slouken@47
   301
slouken@158
   302
    if ( ! [ qz_window isMiniaturized ] ) {
slouken@158
   303
        [ qz_window miniaturize:nil ];
slouken@47
   304
        return 1;
slouken@47
   305
    }
slouken@47
   306
    else {
slouken@501
   307
        SDL_SetError ("window already iconified");
slouken@47
   308
        return 0;
slouken@47
   309
    }
slouken@47
   310
}
slouken@47
   311
slouken@47
   312
/*
slouken@47
   313
static int  QZ_GetWMInfo  (_THIS, SDL_SysWMinfo *info) { 
slouken@158
   314
    info->nsWindowPtr = qz_window;
slouken@47
   315
    return 0; 
slouken@47
   316
}*/
slouken@47
   317
icculus@563
   318
static void QZ_ChangeGrabState (_THIS, int action) {
icculus@563
   319
icculus@563
   320
    /* 
icculus@563
   321
        Figure out what the next state should be based on the action.
icculus@563
   322
        Ignore actions that can't change the current state.
icculus@563
   323
    */
icculus@563
   324
    if ( grab_state == QZ_UNGRABBED ) {
icculus@563
   325
        if ( action == QZ_ENABLE_GRAB ) {
icculus@563
   326
            if ( cursor_visible )
icculus@563
   327
                grab_state = QZ_VISIBLE_GRAB;
icculus@563
   328
            else
icculus@563
   329
                grab_state = QZ_INVISIBLE_GRAB;
icculus@563
   330
        }
icculus@563
   331
    }
icculus@563
   332
    else if ( grab_state == QZ_VISIBLE_GRAB ) {
icculus@563
   333
        if ( action == QZ_DISABLE_GRAB )
icculus@563
   334
            grab_state = QZ_UNGRABBED;
icculus@563
   335
        else if ( action == QZ_HIDECURSOR )
icculus@563
   336
            grab_state = QZ_INVISIBLE_GRAB;
icculus@563
   337
    }
icculus@563
   338
    else {
icculus@563
   339
        assert( grab_state == QZ_INVISIBLE_GRAB );
icculus@563
   340
        
icculus@563
   341
        if ( action == QZ_DISABLE_GRAB )
icculus@563
   342
            grab_state = QZ_UNGRABBED;
icculus@563
   343
        else if ( action == QZ_SHOWCURSOR )
icculus@563
   344
            grab_state = QZ_VISIBLE_GRAB;
icculus@563
   345
    }
icculus@563
   346
    
icculus@563
   347
    /* now apply the new state */
icculus@563
   348
    if (grab_state == QZ_UNGRABBED) {
icculus@563
   349
    
icculus@563
   350
        CGAssociateMouseAndMouseCursorPosition (1);
icculus@563
   351
    }
icculus@563
   352
    else if (grab_state == QZ_VISIBLE_GRAB) {
icculus@563
   353
    
icculus@563
   354
        CGAssociateMouseAndMouseCursorPosition (1);
icculus@563
   355
    }
icculus@563
   356
    else {
icculus@563
   357
        assert( grab_state == QZ_INVISIBLE_GRAB );
icculus@563
   358
icculus@563
   359
        QZ_PrivateWarpCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2);
icculus@563
   360
        CGAssociateMouseAndMouseCursorPosition (0);
icculus@563
   361
    }
icculus@563
   362
}
icculus@563
   363
slouken@47
   364
static SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode) {
slouken@47
   365
icculus@563
   366
    int doGrab = grab_mode & SDL_GRAB_ON;
icculus@563
   367
    /*int fullscreen = grab_mode & SDL_GRAB_FULLSCREEN;*/
icculus@563
   368
icculus@563
   369
    if ( this->screen == NULL ) {
icculus@563
   370
        SDL_SetError ("QZ_GrabInput: screen is NULL");
icculus@563
   371
        return SDL_GRAB_OFF;
slouken@47
   372
    }
slouken@47
   373
        
icculus@563
   374
    if ( ! video_set ) {
icculus@563
   375
        /*SDL_SetError ("QZ_GrabInput: video is not set, grab will take effect on mode switch"); */
icculus@563
   376
        current_grab_mode = grab_mode;
icculus@563
   377
        return grab_mode;       /* Will be set later on mode switch */
icculus@563
   378
    }
icculus@563
   379
icculus@563
   380
    if ( grab_mode != SDL_GRAB_QUERY ) {
icculus@563
   381
        if ( doGrab )
icculus@563
   382
            QZ_ChangeGrabState (this, QZ_ENABLE_GRAB);
icculus@563
   383
        else
icculus@563
   384
            QZ_ChangeGrabState (this, QZ_DISABLE_GRAB);
icculus@563
   385
        
icculus@563
   386
        current_grab_mode = doGrab ? SDL_GRAB_ON : SDL_GRAB_OFF;
icculus@563
   387
    }
icculus@563
   388
slouken@501
   389
    return current_grab_mode;
slouken@47
   390
}
slouken@501
   391
slouken@501
   392
/* Resize icon, BMP format */
slouken@501
   393
static unsigned char QZ_ResizeIcon[] = {
slouken@501
   394
    0x42,0x4d,0x31,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00,0x28,0x00,
slouken@501
   395
    0x00,0x00,0x0d,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x01,0x00,0x18,0x00,0x00,0x00,
slouken@501
   396
    0x00,0x00,0xfb,0x01,0x00,0x00,0x13,0x0b,0x00,0x00,0x13,0x0b,0x00,0x00,0x00,0x00,
slouken@501
   397
    0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
slouken@501
   398
    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
slouken@501
   399
    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0b,0xff,0xff,
slouken@501
   400
    0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,
slouken@501
   401
    0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,
slouken@501
   402
    0xe8,0xe8,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xda,0xda,0xda,0x87,
slouken@501
   403
    0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,0xe8,
slouken@501
   404
    0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xff,0xff,0xff,0x0b,0xff,0xff,
slouken@501
   405
    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd5,0xd5,0xd5,0x87,0x87,0x87,0xe8,0xe8,0xe8,
slouken@501
   406
    0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,
slouken@501
   407
    0xda,0xda,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
slouken@501
   408
    0xff,0xff,0xd7,0xd7,0xd7,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,
slouken@501
   409
    0xda,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xff,0xff,0xff,0x0b,0xff,0xff,
slouken@501
   410
    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd7,0xd7,0xd7,
slouken@501
   411
    0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,
slouken@501
   412
    0xe8,0xe8,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
slouken@501
   413
    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd7,0xd7,0xd7,0x87,0x87,0x87,0xe8,0xe8,
slouken@501
   414
    0xe8,0xff,0xff,0xff,0xdc,0xdc,0xdc,0x87,0x87,0x87,0xff,0xff,0xff,0x0b,0xff,0xff,
slouken@501
   415
    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
slouken@501
   416
    0xff,0xff,0xff,0xd9,0xd9,0xd9,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xdc,
slouken@501
   417
    0xdc,0xdc,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
slouken@501
   418
    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdb,0xdb,
slouken@501
   419
    0xdb,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xff,0xff,0xff,0x0b,0xff,0xff,
slouken@501
   420
    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
slouken@501
   421
    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdb,0xdb,0xdb,0x87,0x87,0x87,0xe8,
slouken@501
   422
    0xe8,0xe8,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
slouken@501
   423
    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
slouken@501
   424
    0xff,0xff,0xff,0xff,0xdc,0xdc,0xdc,0x87,0x87,0x87,0xff,0xff,0xff,0x0b,0xff,0xff,
slouken@501
   425
    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
slouken@501
   426
    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdc,
slouken@501
   427
    0xdc,0xdc,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
slouken@501
   428
    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
slouken@501
   429
    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0b
slouken@501
   430
};
slouken@501
   431
slouken@501
   432
static void QZ_DrawResizeIcon (_THIS, RgnHandle dirtyRegion) {
slouken@501
   433
slouken@501
   434
    /* Check if we should draw the resize icon */
slouken@501
   435
    if (SDL_VideoSurface->flags & SDL_RESIZABLE) {
slouken@501
   436
    
slouken@501
   437
        Rect	icon;
slouken@501
   438
        SetRect (&icon, SDL_VideoSurface->w - 13, SDL_VideoSurface->h - 13, 
slouken@501
   439
                    SDL_VideoSurface->w, SDL_VideoSurface->h);
slouken@501
   440
                    
slouken@501
   441
        if (RectInRgn (&icon, dirtyRegion)) {
slouken@501
   442
        
slouken@501
   443
            SDL_Rect icon_rect;
slouken@501
   444
            
slouken@501
   445
            /* Create the icon image */
slouken@501
   446
            if (resize_icon == NULL) {
slouken@501
   447
            
slouken@501
   448
                SDL_RWops *rw;
slouken@501
   449
                SDL_Surface *tmp;
slouken@501
   450
                
slouken@501
   451
                rw = SDL_RWFromMem (QZ_ResizeIcon, sizeof(QZ_ResizeIcon));
slouken@501
   452
                tmp = SDL_LoadBMP_RW (rw, SDL_TRUE);
slouken@501
   453
                                                                
slouken@501
   454
                resize_icon = SDL_ConvertSurface (tmp, SDL_VideoSurface->format, SDL_SRCCOLORKEY);								
slouken@501
   455
                SDL_SetColorKey (resize_icon, SDL_SRCCOLORKEY, 0xFFFFFF);
slouken@501
   456
                
slouken@501
   457
                SDL_FreeSurface (tmp);
slouken@501
   458
            }
slouken@501
   459
            
slouken@501
   460
            icon_rect.x = SDL_VideoSurface->w - 13;
slouken@501
   461
            icon_rect.y = SDL_VideoSurface->h - 13;
slouken@501
   462
            icon_rect.w = 13;
slouken@501
   463
            icon_rect.h = 13;
slouken@501
   464
            
slouken@501
   465
            SDL_BlitSurface (resize_icon, NULL, SDL_VideoSurface, &icon_rect);
slouken@501
   466
        }
slouken@501
   467
    }
icculus@563
   468
}