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