Mercurial > sdl-ios-xcode
annotate src/video/cocoa/SDL_cocoawindow.m @ 4565:e2d46c5c7483
Fixed key repeat detection on X11, and simplified the code for everyone else.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 21 Jul 2010 21:47:12 -0700 |
parents | 524dfefd554c |
children | c17ac64abb70 |
rev | line source |
---|---|
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 |
4498
3d91e31fcf71
I missed the Objective C files when updating the copyright date...
Sam Lantinga <slouken@libsdl.org>
parents:
4484
diff
changeset
|
3 Copyright (C) 1997-2010 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" |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 #include "../../events/SDL_windowevents_c.h" |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 #include "SDL_cocoavideo.h" |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 static __inline__ void ConvertNSRect(NSRect *r) |
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 r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height; |
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 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 @implementation Cocoa_WindowListener |
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 - (void)listen:(SDL_WindowData *)data |
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 NSNotificationCenter *center; |
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 _data = data; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 center = [NSNotificationCenter defaultCenter]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
47 [_data->nswindow setNextResponder:self]; |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
48 if ([_data->nswindow delegate] != nil) { |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
49 [center addObserver:self selector:@selector(windowDisExpose:) name:NSWindowDidExposeNotification object:_data->nswindow]; |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
50 [center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:_data->nswindow]; |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
51 [center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:_data->nswindow]; |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
52 [center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:_data->nswindow]; |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
53 [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:_data->nswindow]; |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
54 [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:_data->nswindow]; |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
55 [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:_data->nswindow]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 } else { |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
57 [_data->nswindow setDelegate:self]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 [center addObserver:self selector:@selector(windowDidHide:) name:NSApplicationDidHideNotification object:NSApp]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 [center addObserver:self selector:@selector(windowDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
62 [_data->nswindow setAcceptsMouseMovedEvents:YES]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 - (void)close |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 NSNotificationCenter *center; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 center = [NSNotificationCenter defaultCenter]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
71 [_data->nswindow setNextResponder:nil]; |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
72 if ([_data->nswindow delegate] != self) { |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
73 [center removeObserver:self name:NSWindowDidExposeNotification object:_data->nswindow]; |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
74 [center removeObserver:self name:NSWindowDidMoveNotification object:_data->nswindow]; |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
75 [center removeObserver:self name:NSWindowDidResizeNotification object:_data->nswindow]; |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
76 [center removeObserver:self name:NSWindowDidMiniaturizeNotification object:_data->nswindow]; |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
77 [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:_data->nswindow]; |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
78 [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:_data->nswindow]; |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
79 [center removeObserver:self name:NSWindowDidResignKeyNotification object:_data->nswindow]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 } else { |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
81 [_data->nswindow setDelegate:nil]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 [center removeObserver:self name:NSApplicationDidHideNotification object:NSApp]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 [center removeObserver:self name:NSApplicationDidUnhideNotification object:NSApp]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 - (BOOL)windowShouldClose:(id)sender |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 { |
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
|
89 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_CLOSE, 0, 0); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 return NO; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 - (void)windowDidExpose:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 { |
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
|
95 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 - (void)windowDidMove:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 int x, y; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
101 NSRect rect = [_data->nswindow contentRectForFrameRect:[_data->nswindow frame]]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 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
|
103 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
|
104 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
|
105 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MOVED, x, y); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 - (void)windowDidResize:(NSNotification *)aNotification |
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 int w, h; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
111 NSRect rect = [_data->nswindow contentRectForFrameRect:[_data->nswindow frame]]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 w = (int)rect.size.width; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 h = (int)rect.size.height; |
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
|
114 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESIZED, w, h); |
1933
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 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 - (void)windowDidMiniaturize:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 { |
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
|
119 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 - (void)windowDidDeminiaturize:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 { |
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
|
124 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESTORED, 0, 0); |
1933
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 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 - (void)windowDidBecomeKey:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 { |
2059
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
129 /* We're going to get keyboard events, since we're 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
|
130 SDL_SetKeyboardFocus(_data->window); |
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
|
131 |
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
|
132 /* 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
|
133 Cocoa_CheckClipboardUpdate(_data->videodata); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 } |
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 - (void)windowDidResignKey:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 { |
2059
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
138 /* 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
|
139 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
|
140 SDL_SetMouseFocus(NULL); |
2059
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
141 } |
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
142 |
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
143 /* 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
|
144 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
|
145 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
|
146 } |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 - (void)windowDidHide:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 { |
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
|
151 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 - (void)windowDidUnhide:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 { |
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
|
156 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 - (void)mouseDown:(NSEvent *)theEvent |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 { |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
161 int button; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
163 switch ([theEvent buttonNumber]) { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
164 case 0: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
165 button = SDL_BUTTON_LEFT; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
166 break; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
167 case 1: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
168 button = SDL_BUTTON_RIGHT; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
169 break; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
170 case 2: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
171 button = SDL_BUTTON_MIDDLE; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
172 break; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
173 default: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
174 button = [theEvent buttonNumber]; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
175 break; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
176 } |
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
|
177 SDL_SendMouseButton(_data->window, SDL_PRESSED, button); |
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)rightMouseDown:(NSEvent *)theEvent |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
181 { |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
182 [self mouseDown:theEvent]; |
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)otherMouseDown:(NSEvent *)theEvent |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
186 { |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
187 [self mouseDown:theEvent]; |
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)mouseUp:(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: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
205 button = [theEvent buttonNumber]; |
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_RELEASED, 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)rightMouseUp:(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 mouseUp: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)otherMouseUp:(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 mouseUp: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)mouseMoved:(NSEvent *)theEvent |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
222 { |
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
|
223 SDL_Window *window = _data->window; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
224 NSPoint point; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 |
3517
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
3509
diff
changeset
|
226 point = [theEvent locationInWindow]; |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
3509
diff
changeset
|
227 point.y = window->h - point.y; |
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
|
228 if ( point.x < 0 || point.x >= window->w || |
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
|
229 point.y < 0 || point.y >= window->h ) { |
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
|
230 if (SDL_GetMouseFocus() == 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
|
231 SDL_SetMouseFocus(NULL); |
2059
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
232 } |
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
233 } else { |
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
|
234 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
|
235 } |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
236 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
237 |
1957
c7803e4c21d3
Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents:
1956
diff
changeset
|
238 - (void)mouseDragged:(NSEvent *)theEvent |
c7803e4c21d3
Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents:
1956
diff
changeset
|
239 { |
c7803e4c21d3
Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents:
1956
diff
changeset
|
240 [self mouseMoved:theEvent]; |
c7803e4c21d3
Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents:
1956
diff
changeset
|
241 } |
c7803e4c21d3
Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents:
1956
diff
changeset
|
242 |
1958
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
243 - (void)rightMouseDragged:(NSEvent *)theEvent |
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
244 { |
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
245 [self mouseMoved:theEvent]; |
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
246 } |
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
247 |
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
248 - (void)otherMouseDragged:(NSEvent *)theEvent |
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
249 { |
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
250 [self mouseMoved:theEvent]; |
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
251 } |
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
252 |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
253 - (void)scrollWheel:(NSEvent *)theEvent |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
254 { |
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
|
255 float x = [theEvent deltaX]; |
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
|
256 float y = [theEvent deltaY]; |
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
|
257 |
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
|
258 if (x > 0) { |
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
|
259 x += 0.9f; |
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
|
260 } else if (x < 0) { |
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
|
261 x -= 0.9f; |
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
|
262 } |
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
|
263 if (y > 0) { |
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
|
264 y += 0.9f; |
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
|
265 } else if (y < 0) { |
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
|
266 y -= 0.9f; |
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
|
267 } |
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
|
268 SDL_SendMouseWheel(_data->window, (int)x, (int)y); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
269 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
270 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
271 @end |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
272 |
1973
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
273 @interface SDLWindow : NSWindow |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
274 /* These are needed for borderless/fullscreen windows */ |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
275 - (BOOL)canBecomeKeyWindow; |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
276 - (BOOL)canBecomeMainWindow; |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
277 @end |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
278 |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
279 @implementation SDLWindow |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
280 - (BOOL)canBecomeKeyWindow |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
281 { |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
282 return YES; |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
283 } |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
284 |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
285 - (BOOL)canBecomeMainWindow |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
286 { |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
287 return YES; |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
288 } |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
289 @end |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
290 |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
291 static int |
1951
7177581dc9fa
Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
292 SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created) |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
293 { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
294 NSAutoreleasePool *pool; |
1951
7177581dc9fa
Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
295 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; |
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
|
296 SDL_VideoDisplay *display = window->display; |
3530
e96be66e3673
The window position is display relative, at least for now...
Sam Lantinga <slouken@libsdl.org>
parents:
3529
diff
changeset
|
297 SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
298 SDL_WindowData *data; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
299 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
300 /* Allocate the window data */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
301 data = (SDL_WindowData *) SDL_malloc(sizeof(*data)); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
302 if (!data) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
303 SDL_OutOfMemory(); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
304 return -1; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
305 } |
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
|
306 data->window = window; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
307 data->nswindow = nswindow; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
308 data->created = created; |
3506
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
309 data->display = displaydata->display; |
1951
7177581dc9fa
Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
310 data->videodata = videodata; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
311 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 pool = [[NSAutoreleasePool alloc] init]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
313 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
314 /* Create an event listener for the window */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
315 data->listener = [[Cocoa_WindowListener alloc] init]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
316 [data->listener listen:data]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
317 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
318 /* Fill in the SDL window with the window data */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
319 { |
3530
e96be66e3673
The window position is display relative, at least for now...
Sam Lantinga <slouken@libsdl.org>
parents:
3529
diff
changeset
|
320 SDL_Rect bounds; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
321 NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
322 ConvertNSRect(&rect); |
3530
e96be66e3673
The window position is display relative, at least for now...
Sam Lantinga <slouken@libsdl.org>
parents:
3529
diff
changeset
|
323 Cocoa_GetDisplayBounds(_this, display, &bounds); |
e96be66e3673
The window position is display relative, at least for now...
Sam Lantinga <slouken@libsdl.org>
parents:
3529
diff
changeset
|
324 window->x = (int)rect.origin.x - bounds.x; |
e96be66e3673
The window position is display relative, at least for now...
Sam Lantinga <slouken@libsdl.org>
parents:
3529
diff
changeset
|
325 window->y = (int)rect.origin.y - bounds.y; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
326 window->w = (int)rect.size.width; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
327 window->h = (int)rect.size.height; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
328 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
329 if ([nswindow isVisible]) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
330 window->flags |= SDL_WINDOW_SHOWN; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
331 } else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
332 window->flags &= ~SDL_WINDOW_SHOWN; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
333 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
334 { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
335 unsigned int style = [nswindow styleMask]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
336 |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
337 if ((style & ~NSResizableWindowMask) == NSBorderlessWindowMask) { |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
338 window->flags |= SDL_WINDOW_BORDERLESS; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
339 } else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
340 window->flags &= ~SDL_WINDOW_BORDERLESS; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
341 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
342 if (style & NSResizableWindowMask) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
343 window->flags |= SDL_WINDOW_RESIZABLE; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
344 } else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
345 window->flags &= ~SDL_WINDOW_RESIZABLE; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
346 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
347 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
348 if ([nswindow isZoomed]) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
349 window->flags |= SDL_WINDOW_MAXIMIZED; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
350 } else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
351 window->flags &= ~SDL_WINDOW_MAXIMIZED; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
352 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
353 if ([nswindow isMiniaturized]) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
354 window->flags |= SDL_WINDOW_MINIMIZED; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
355 } else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
356 window->flags &= ~SDL_WINDOW_MINIMIZED; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
357 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
358 if ([nswindow isKeyWindow]) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
359 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
|
360 SDL_SetKeyboardFocus(data->window); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
361 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
362 if (window->flags & SDL_WINDOW_INPUT_GRABBED) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
363 /* FIXME */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
364 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
365 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
366 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
367 /* All done! */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
368 [pool release]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
369 window->driverdata = data; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
370 return 0; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
371 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
372 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
373 int |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
374 Cocoa_CreateWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
375 { |
3506
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
376 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
377 NSWindow *nswindow; |
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
|
378 SDL_VideoDisplay *display = window->display; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
379 NSRect rect; |
3528
59ff7a2beb57
Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents:
3525
diff
changeset
|
380 SDL_Rect bounds; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
381 unsigned int style; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
382 |
3528
59ff7a2beb57
Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents:
3525
diff
changeset
|
383 Cocoa_GetDisplayBounds(_this, display, &bounds); |
3075
4c28a9655933
Fixed bug using SDL_WINDOWPOS_CENTERED with SDL_SetWindowPosition()
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
384 if ((window->flags & SDL_WINDOW_FULLSCREEN) |
4c28a9655933
Fixed bug using SDL_WINDOWPOS_CENTERED with SDL_SetWindowPosition()
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
385 || window->x == SDL_WINDOWPOS_CENTERED) { |
3528
59ff7a2beb57
Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents:
3525
diff
changeset
|
386 rect.origin.x = bounds.x + (bounds.w - window->w) / 2; |
59ff7a2beb57
Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents:
3525
diff
changeset
|
387 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { |
59ff7a2beb57
Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents:
3525
diff
changeset
|
388 rect.origin.x = bounds.x; |
59ff7a2beb57
Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents:
3525
diff
changeset
|
389 } else { |
3530
e96be66e3673
The window position is display relative, at least for now...
Sam Lantinga <slouken@libsdl.org>
parents:
3529
diff
changeset
|
390 rect.origin.x = bounds.x + window->x; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
391 } |
3075
4c28a9655933
Fixed bug using SDL_WINDOWPOS_CENTERED with SDL_SetWindowPosition()
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
392 if ((window->flags & SDL_WINDOW_FULLSCREEN) |
4c28a9655933
Fixed bug using SDL_WINDOWPOS_CENTERED with SDL_SetWindowPosition()
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
393 || window->y == SDL_WINDOWPOS_CENTERED) { |
3528
59ff7a2beb57
Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents:
3525
diff
changeset
|
394 rect.origin.y = bounds.y + (bounds.h - window->h) / 2; |
59ff7a2beb57
Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents:
3525
diff
changeset
|
395 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { |
59ff7a2beb57
Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents:
3525
diff
changeset
|
396 rect.origin.y = bounds.y; |
59ff7a2beb57
Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents:
3525
diff
changeset
|
397 } else { |
3530
e96be66e3673
The window position is display relative, at least for now...
Sam Lantinga <slouken@libsdl.org>
parents:
3529
diff
changeset
|
398 rect.origin.y = bounds.y + window->y; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
399 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
400 rect.size.width = window->w; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
401 rect.size.height = window->h; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
402 ConvertNSRect(&rect); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
403 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
404 if (window->flags & SDL_WINDOW_BORDERLESS) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
405 style = NSBorderlessWindowMask; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
406 } else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
407 style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
408 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
409 if (window->flags & SDL_WINDOW_RESIZABLE) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
410 style |= NSResizableWindowMask; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
411 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
412 |
3506
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
413 /* 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
|
414 NSArray *screens = [NSScreen screens]; |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
415 NSScreen *screen = nil; |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
416 NSScreen *candidate; |
3525
455a6c47d2c6
Fixed compilation on Mac OS X 10.4
Sam Lantinga <slouken@libsdl.org>
parents:
3517
diff
changeset
|
417 int i, count = [screens count]; |
455a6c47d2c6
Fixed compilation on Mac OS X 10.4
Sam Lantinga <slouken@libsdl.org>
parents:
3517
diff
changeset
|
418 for (i = 0; i < count; ++i) { |
3529 | 419 candidate = [screens objectAtIndex:i]; |
3506
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
420 NSRect screenRect = [candidate frame]; |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
421 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
|
422 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
|
423 rect.origin.y >= screenRect.origin.y && |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
424 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
|
425 screen = candidate; |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
426 rect.origin.x -= screenRect.origin.x; |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
427 rect.origin.y -= screenRect.origin.y; |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
428 } |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
429 } |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
430 nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:FALSE screen:screen]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
431 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
432 [pool release]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
433 |
1951
7177581dc9fa
Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
434 if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) { |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
435 [nswindow release]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
436 return -1; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
437 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
438 return 0; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
439 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
440 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
441 int |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
442 Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
443 { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
444 NSAutoreleasePool *pool; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
445 NSWindow *nswindow = (NSWindow *) data; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
446 NSString *title; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
447 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
448 pool = [[NSAutoreleasePool alloc] init]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
449 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
450 /* Query the title from the existing window */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
451 title = [nswindow title]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
452 if (title) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
453 window->title = SDL_strdup([title UTF8String]); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
454 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
455 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
456 [pool release]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
457 |
1951
7177581dc9fa
Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
458 return SetupWindowData(_this, window, nswindow, SDL_FALSE); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
459 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
460 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
461 void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
462 Cocoa_SetWindowTitle(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
463 { |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
464 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
465 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
466 NSString *string; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
467 |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
468 if(window->title) { |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
469 string = [[NSString alloc] initWithUTF8String:window->title]; |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
470 } else { |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
471 string = [[NSString alloc] init]; |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
472 } |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
473 [nswindow setTitle:string]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
474 [string release]; |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
475 |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
476 [pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
477 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
478 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
479 void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
480 Cocoa_SetWindowPosition(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
481 { |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
482 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
483 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; |
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
|
484 SDL_VideoDisplay *display = window->display; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
485 NSRect rect; |
3528
59ff7a2beb57
Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents:
3525
diff
changeset
|
486 SDL_Rect bounds; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
487 |
3528
59ff7a2beb57
Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents:
3525
diff
changeset
|
488 Cocoa_GetDisplayBounds(_this, display, &bounds); |
3075
4c28a9655933
Fixed bug using SDL_WINDOWPOS_CENTERED with SDL_SetWindowPosition()
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
489 if ((window->flags & SDL_WINDOW_FULLSCREEN) |
4c28a9655933
Fixed bug using SDL_WINDOWPOS_CENTERED with SDL_SetWindowPosition()
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
490 || window->x == SDL_WINDOWPOS_CENTERED) { |
3528
59ff7a2beb57
Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents:
3525
diff
changeset
|
491 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
|
492 } else { |
3530
e96be66e3673
The window position is display relative, at least for now...
Sam Lantinga <slouken@libsdl.org>
parents:
3529
diff
changeset
|
493 rect.origin.x = bounds.x + window->x; |
3075
4c28a9655933
Fixed bug using SDL_WINDOWPOS_CENTERED with SDL_SetWindowPosition()
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
494 } |
4c28a9655933
Fixed bug using SDL_WINDOWPOS_CENTERED with SDL_SetWindowPosition()
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
495 if ((window->flags & SDL_WINDOW_FULLSCREEN) |
4c28a9655933
Fixed bug using SDL_WINDOWPOS_CENTERED with SDL_SetWindowPosition()
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
496 || window->y == SDL_WINDOWPOS_CENTERED) { |
3528
59ff7a2beb57
Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents:
3525
diff
changeset
|
497 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
|
498 } else { |
3530
e96be66e3673
The window position is display relative, at least for now...
Sam Lantinga <slouken@libsdl.org>
parents:
3529
diff
changeset
|
499 rect.origin.y = bounds.y + window->y; |
3075
4c28a9655933
Fixed bug using SDL_WINDOWPOS_CENTERED with SDL_SetWindowPosition()
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
500 } |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
501 rect.size.width = window->w; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
502 rect.size.height = window->h; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
503 ConvertNSRect(&rect); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
504 rect = [nswindow frameRectForContentRect:rect]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
505 [nswindow setFrameOrigin:rect.origin]; |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
506 [pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
507 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
508 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
509 void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
510 Cocoa_SetWindowSize(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
511 { |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
512 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
513 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
514 NSSize size; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
515 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
516 size.width = window->w; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
517 size.height = window->h; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
518 [nswindow setContentSize:size]; |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
519 [pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
520 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
521 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
522 void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
523 Cocoa_ShowWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
524 { |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
525 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
526 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
527 |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
528 if (![nswindow isMiniaturized]) { |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
529 [nswindow makeKeyAndOrderFront:nil]; |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
530 } |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
531 [pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
532 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
533 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
534 void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
535 Cocoa_HideWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
536 { |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
537 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
538 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
539 |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
540 [nswindow orderOut:nil]; |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
541 [pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
542 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
543 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
544 void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
545 Cocoa_RaiseWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
546 { |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
547 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
548 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
549 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
550 [nswindow makeKeyAndOrderFront:nil]; |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
551 [pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
552 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
553 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
554 void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
555 Cocoa_MaximizeWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
556 { |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
557 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
558 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
559 |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
560 [nswindow zoom:nil]; |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
561 [pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
562 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
563 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
564 void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
565 Cocoa_MinimizeWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
566 { |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
567 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
568 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
569 |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
570 [nswindow miniaturize:nil]; |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
571 [pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
572 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
573 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
574 void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
575 Cocoa_RestoreWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
576 { |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
577 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
578 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
579 |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
580 if ([nswindow isMiniaturized]) { |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
581 [nswindow deminiaturize:nil]; |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
582 } else if ([nswindow isZoomed]) { |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
583 [nswindow zoom:nil]; |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
584 } |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
585 [pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
586 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
587 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
588 void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
589 Cocoa_SetWindowGrab(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
590 { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
591 if ((window->flags & SDL_WINDOW_INPUT_GRABBED) && |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
592 (window->flags & SDL_WINDOW_INPUT_FOCUS)) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
593 /* FIXME: Grab mouse */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
594 } else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
595 /* FIXME: Release mouse */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
596 } |
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 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
599 void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
600 Cocoa_DestroyWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
601 { |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
602 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
603 SDL_WindowData *data = (SDL_WindowData *) window->driverdata; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
604 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
605 if (data) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
606 [data->listener close]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
607 [data->listener release]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
608 if (data->created) { |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
609 [data->nswindow close]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
610 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
611 SDL_free(data); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
612 } |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
613 [pool release]; |
1933
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 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
616 SDL_bool |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
617 Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
618 { |
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
|
619 //NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
620 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
621 if (info->version.major <= SDL_MAJOR_VERSION) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
622 //info->window = nswindow; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
623 return SDL_TRUE; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
624 } else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
625 SDL_SetError("Application not compiled with SDL %d.%d\n", |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
626 SDL_MAJOR_VERSION, SDL_MINOR_VERSION); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
627 return SDL_FALSE; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
628 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
629 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
630 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
631 /* vi: set ts=4 sw=4 expandtab: */ |