Mercurial > sdl-ios-xcode
annotate src/video/cocoa/SDL_cocoawindow.m @ 4675:641c13b0ce5f
Added better logging
author | Jim Grandpre <jim.tla@gmail.com> |
---|---|
date | Thu, 29 Jul 2010 12:26:59 -0400 |
parents | 89d5e2201b00 |
children | 99b4560b7aa1 |
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" |
4673
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
28 #include "../../events/SDL_touch_c.h" |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 #include "../../events/SDL_windowevents_c.h" |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 #include "SDL_cocoavideo.h" |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 static __inline__ void ConvertNSRect(NSRect *r) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height; |
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 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 @implementation Cocoa_WindowListener |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 - (void)listen:(SDL_WindowData *)data |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 NSNotificationCenter *center; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 _data = data; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 center = [NSNotificationCenter defaultCenter]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
48 [_data->nswindow setNextResponder:self]; |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
49 if ([_data->nswindow delegate] != nil) { |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
50 [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
|
51 [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
|
52 [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
|
53 [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
|
54 [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
|
55 [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
|
56 [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
|
57 } else { |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
58 [_data->nswindow setDelegate:self]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 [center addObserver:self selector:@selector(windowDidHide:) name:NSApplicationDidHideNotification object:NSApp]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 [center addObserver:self selector:@selector(windowDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
63 [_data->nswindow setAcceptsMouseMovedEvents:YES]; |
4673
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
64 [[_data->nswindow contentView] setAcceptsTouchEvents:YES]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 } |
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 - (void)close |
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 NSNotificationCenter *center; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 center = [NSNotificationCenter defaultCenter]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
73 [_data->nswindow setNextResponder:nil]; |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
74 if ([_data->nswindow delegate] != self) { |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
75 [center removeObserver:self name:NSWindowDidExposeNotification object:_data->nswindow]; |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
76 [center removeObserver:self name:NSWindowDidMoveNotification object:_data->nswindow]; |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
77 [center removeObserver:self name:NSWindowDidResizeNotification object:_data->nswindow]; |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
78 [center removeObserver:self name:NSWindowDidMiniaturizeNotification object:_data->nswindow]; |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
79 [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:_data->nswindow]; |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
80 [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:_data->nswindow]; |
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
81 [center removeObserver:self name:NSWindowDidResignKeyNotification object:_data->nswindow]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 } else { |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
83 [_data->nswindow setDelegate:nil]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 [center removeObserver:self name:NSApplicationDidHideNotification object:NSApp]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 [center removeObserver:self name:NSApplicationDidUnhideNotification object:NSApp]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 - (BOOL)windowShouldClose:(id)sender |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 { |
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
|
91 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_CLOSE, 0, 0); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 return NO; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 - (void)windowDidExpose:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 { |
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
|
97 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 } |
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 - (void)windowDidMove:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 int x, y; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
103 NSRect rect = [_data->nswindow contentRectForFrameRect:[_data->nswindow frame]]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 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
|
105 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
|
106 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
|
107 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MOVED, x, y); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 } |
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 - (void)windowDidResize:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 int w, h; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
113 NSRect rect = [_data->nswindow contentRectForFrameRect:[_data->nswindow frame]]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 w = (int)rect.size.width; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 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
|
116 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESIZED, w, h); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 - (void)windowDidMiniaturize:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 { |
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
|
121 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 - (void)windowDidDeminiaturize:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 { |
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
|
126 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESTORED, 0, 0); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 - (void)windowDidBecomeKey:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 { |
2059
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
131 /* 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
|
132 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
|
133 |
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
|
134 /* 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
|
135 Cocoa_CheckClipboardUpdate(_data->videodata); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 - (void)windowDidResignKey:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 { |
2059
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
140 /* 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
|
141 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
|
142 SDL_SetMouseFocus(NULL); |
2059
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
143 } |
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
144 |
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
145 /* 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
|
146 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
|
147 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
|
148 } |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 - (void)windowDidHide:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 { |
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
|
153 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 - (void)windowDidUnhide:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 { |
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
|
158 SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 - (void)mouseDown:(NSEvent *)theEvent |
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 int button; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
165 switch ([theEvent buttonNumber]) { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
166 case 0: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
167 button = SDL_BUTTON_LEFT; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
168 break; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
169 case 1: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
170 button = SDL_BUTTON_RIGHT; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
171 break; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
172 case 2: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
173 button = SDL_BUTTON_MIDDLE; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
174 break; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
175 default: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
176 button = [theEvent buttonNumber]; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
177 break; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
178 } |
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
|
179 SDL_SendMouseButton(_data->window, SDL_PRESSED, button); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
181 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
182 - (void)rightMouseDown:(NSEvent *)theEvent |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
183 { |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
184 [self mouseDown:theEvent]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
185 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
186 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
187 - (void)otherMouseDown:(NSEvent *)theEvent |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 { |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
189 [self mouseDown:theEvent]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 - (void)mouseUp:(NSEvent *)theEvent |
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 int button; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
195 |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
196 switch ([theEvent buttonNumber]) { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
197 case 0: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
198 button = SDL_BUTTON_LEFT; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
199 break; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
200 case 1: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
201 button = SDL_BUTTON_RIGHT; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
202 break; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
203 case 2: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
204 button = SDL_BUTTON_MIDDLE; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
205 break; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
206 default: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
207 button = [theEvent buttonNumber]; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
208 break; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
209 } |
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
|
210 SDL_SendMouseButton(_data->window, SDL_RELEASED, button); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
211 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
213 - (void)rightMouseUp:(NSEvent *)theEvent |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
214 { |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
215 [self mouseUp:theEvent]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
216 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
217 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
218 - (void)otherMouseUp:(NSEvent *)theEvent |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
219 { |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
220 [self mouseUp:theEvent]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
221 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
222 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
223 - (void)mouseMoved:(NSEvent *)theEvent |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
224 { |
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
|
225 SDL_Window *window = _data->window; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 NSPoint point; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
227 |
3517
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
3509
diff
changeset
|
228 point = [theEvent locationInWindow]; |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
3509
diff
changeset
|
229 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
|
230 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
|
231 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
|
232 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
|
233 SDL_SetMouseFocus(NULL); |
2059
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
234 } |
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
235 } 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
|
236 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
|
237 } |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
238 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
239 |
1957
c7803e4c21d3
Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents:
1956
diff
changeset
|
240 - (void)mouseDragged:(NSEvent *)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 [self mouseMoved:theEvent]; |
c7803e4c21d3
Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents:
1956
diff
changeset
|
243 } |
c7803e4c21d3
Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents:
1956
diff
changeset
|
244 |
1958
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
245 - (void)rightMouseDragged:(NSEvent *)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 [self mouseMoved:theEvent]; |
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
248 } |
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 - (void)otherMouseDragged:(NSEvent *)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 [self mouseMoved:theEvent]; |
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
253 } |
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
254 |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
255 - (void)scrollWheel:(NSEvent *)theEvent |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
256 { |
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
|
257 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
|
258 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
|
259 |
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 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 } 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
|
263 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
|
264 } |
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 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 } 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
|
268 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
|
269 } |
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
|
270 SDL_SendMouseWheel(_data->window, (int)x, (int)y); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
271 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
272 |
4673
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
273 - (void)touchesBeganWithEvent:(NSEvent *) theEvent |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
274 { |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
275 [self handleTouches:COCOA_TOUCH_DOWN withEvent:theEvent]; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
276 } |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
277 |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
278 - (void)touchesMovedWithEvent:(NSEvent *) theEvent |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
279 { |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
280 [self handleTouches:COCOA_TOUCH_MOVE withEvent:theEvent]; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
281 } |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
282 |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
283 - (void)touchesEndedWithEvent:(NSEvent *) theEvent |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
284 { |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
285 [self handleTouches:COCOA_TOUCH_UP withEvent:theEvent]; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
286 } |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
287 |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
288 - (void)touchesCancelledWithEvent:(NSEvent *) theEvent |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
289 { |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
290 [self handleTouches:COCOA_TOUCH_CANCELLED withEvent:theEvent]; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
291 } |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
292 |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
293 - (void)handleTouches:(cocoaTouchType)type withEvent:(NSEvent *)event |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
294 { |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
295 NSSet *touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:nil]; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
296 |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
297 NSEnumerator *enumerator = [touches objectEnumerator]; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
298 NSTouch *touch = (NSTouch*)[enumerator nextObject]; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
299 while (touch) { |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
300 long touchId = (long)[touch device]; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
301 if (!SDL_GetTouch(touchId)) { |
4675 | 302 printf("Adding touch: %i\n",touchId) |
4673
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
303 SDL_Touch touch; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
304 |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
305 touch.id = touchId; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
306 touch.x_min = 0; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
307 touch.x_max = 1; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
308 touch.xres = touch.x_max - touch.x_min; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
309 touch.y_min = 0; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
310 touch.y_max = 1; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
311 touch.yres = touch.y_max - touch.y_min; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
312 touch.pressure_min = 0; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
313 touch.pressure_max = 1; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
314 touch.pressureres = touch.pressure_max - touch.pressure_min; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
315 |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
316 if (SDL_AddTouch(&touch, "") < 0) { |
4674
89d5e2201b00
Prevented SDL_SendDown from sending on nonexistent touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
4673
diff
changeset
|
317 continue; |
4673
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
318 } |
4675 | 319 printf("Success, added touch: %i\n",touchId) |
4673
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
320 } |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
321 float x = [touch normalizedPosition].x; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
322 float y = [touch normalizedPosition].y; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
323 long fingerId = (long)[touch identity]; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
324 switch (type) { |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
325 case COCOA_TOUCH_DOWN: |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
326 SDL_SendFingerDown(touchId, fingerId, SDL_TRUE, x, y, 1); |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
327 break; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
328 case COCOA_TOUCH_UP: |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
329 case COCOA_TOUCH_CANCELLED: |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
330 SDL_SendFingerDown(touchId, fingerId, SDL_FALSE, x, y, 1); |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
331 break; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
332 case COCOA_TOUCH_MOVE: |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
333 SDL_SendTouchMotion(touchId, fingerId, SDL_FALSE, x, y, 1); |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
334 break; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
335 } |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
336 |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
337 touch = (NSTouch*)[enumerator nextObject]; |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
338 } |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
339 } |
c17ac64abb70
Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents:
4503
diff
changeset
|
340 |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
341 @end |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
342 |
1973
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
343 @interface SDLWindow : NSWindow |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
344 /* These are needed for borderless/fullscreen windows */ |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
345 - (BOOL)canBecomeKeyWindow; |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
346 - (BOOL)canBecomeMainWindow; |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
347 @end |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
348 |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
349 @implementation SDLWindow |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
350 - (BOOL)canBecomeKeyWindow |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
351 { |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
352 return YES; |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
353 } |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
354 |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
355 - (BOOL)canBecomeMainWindow |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
356 { |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
357 return YES; |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
358 } |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
359 @end |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
360 |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
361 static int |
1951
7177581dc9fa
Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
362 SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created) |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
363 { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
364 NSAutoreleasePool *pool; |
1951
7177581dc9fa
Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
365 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
|
366 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
|
367 SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
368 SDL_WindowData *data; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
369 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
370 /* Allocate the window data */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
371 data = (SDL_WindowData *) SDL_malloc(sizeof(*data)); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
372 if (!data) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
373 SDL_OutOfMemory(); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
374 return -1; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
375 } |
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
|
376 data->window = window; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
377 data->nswindow = nswindow; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
378 data->created = created; |
3506
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
379 data->display = displaydata->display; |
1951
7177581dc9fa
Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
380 data->videodata = videodata; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
381 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
382 pool = [[NSAutoreleasePool alloc] init]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
383 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
384 /* Create an event listener for the window */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
385 data->listener = [[Cocoa_WindowListener alloc] init]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
386 [data->listener listen:data]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
387 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
388 /* Fill in the SDL window with the window data */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
389 { |
3530
e96be66e3673
The window position is display relative, at least for now...
Sam Lantinga <slouken@libsdl.org>
parents:
3529
diff
changeset
|
390 SDL_Rect bounds; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
391 NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
392 ConvertNSRect(&rect); |
3530
e96be66e3673
The window position is display relative, at least for now...
Sam Lantinga <slouken@libsdl.org>
parents:
3529
diff
changeset
|
393 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
|
394 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
|
395 window->y = (int)rect.origin.y - bounds.y; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
396 window->w = (int)rect.size.width; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
397 window->h = (int)rect.size.height; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
398 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
399 if ([nswindow isVisible]) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
400 window->flags |= SDL_WINDOW_SHOWN; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
401 } else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
402 window->flags &= ~SDL_WINDOW_SHOWN; |
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 { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
405 unsigned int style = [nswindow styleMask]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
406 |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
407 if ((style & ~NSResizableWindowMask) == NSBorderlessWindowMask) { |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
408 window->flags |= SDL_WINDOW_BORDERLESS; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
409 } else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
410 window->flags &= ~SDL_WINDOW_BORDERLESS; |
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 if (style & NSResizableWindowMask) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
413 window->flags |= SDL_WINDOW_RESIZABLE; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
414 } else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
415 window->flags &= ~SDL_WINDOW_RESIZABLE; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
416 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
417 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
418 if ([nswindow isZoomed]) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
419 window->flags |= SDL_WINDOW_MAXIMIZED; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
420 } else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
421 window->flags &= ~SDL_WINDOW_MAXIMIZED; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
422 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
423 if ([nswindow isMiniaturized]) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
424 window->flags |= SDL_WINDOW_MINIMIZED; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
425 } else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
426 window->flags &= ~SDL_WINDOW_MINIMIZED; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
427 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
428 if ([nswindow isKeyWindow]) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
429 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
|
430 SDL_SetKeyboardFocus(data->window); |
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 if (window->flags & SDL_WINDOW_INPUT_GRABBED) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
433 /* FIXME */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
434 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
435 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
436 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
437 /* All done! */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
438 [pool release]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
439 window->driverdata = data; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
440 return 0; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
441 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
442 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
443 int |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
444 Cocoa_CreateWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
445 { |
3506
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
446 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
447 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
|
448 SDL_VideoDisplay *display = window->display; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
449 NSRect rect; |
3528
59ff7a2beb57
Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents:
3525
diff
changeset
|
450 SDL_Rect bounds; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
451 unsigned int style; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
452 |
3528
59ff7a2beb57
Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents:
3525
diff
changeset
|
453 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
|
454 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
|
455 || 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
|
456 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
|
457 } 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
|
458 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
|
459 } else { |
3530
e96be66e3673
The window position is display relative, at least for now...
Sam Lantinga <slouken@libsdl.org>
parents:
3529
diff
changeset
|
460 rect.origin.x = bounds.x + window->x; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
461 } |
3075
4c28a9655933
Fixed bug using SDL_WINDOWPOS_CENTERED with SDL_SetWindowPosition()
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
462 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
|
463 || 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
|
464 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
|
465 } 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
|
466 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
|
467 } else { |
3530
e96be66e3673
The window position is display relative, at least for now...
Sam Lantinga <slouken@libsdl.org>
parents:
3529
diff
changeset
|
468 rect.origin.y = bounds.y + window->y; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
469 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
470 rect.size.width = window->w; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
471 rect.size.height = window->h; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
472 ConvertNSRect(&rect); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
473 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
474 if (window->flags & SDL_WINDOW_BORDERLESS) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
475 style = NSBorderlessWindowMask; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
476 } else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
477 style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask); |
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 if (window->flags & SDL_WINDOW_RESIZABLE) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
480 style |= NSResizableWindowMask; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
481 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
482 |
3506
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
483 /* 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
|
484 NSArray *screens = [NSScreen screens]; |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
485 NSScreen *screen = nil; |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
486 NSScreen *candidate; |
3525
455a6c47d2c6
Fixed compilation on Mac OS X 10.4
Sam Lantinga <slouken@libsdl.org>
parents:
3517
diff
changeset
|
487 int i, count = [screens count]; |
455a6c47d2c6
Fixed compilation on Mac OS X 10.4
Sam Lantinga <slouken@libsdl.org>
parents:
3517
diff
changeset
|
488 for (i = 0; i < count; ++i) { |
3529 | 489 candidate = [screens objectAtIndex:i]; |
3506
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
490 NSRect screenRect = [candidate frame]; |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
491 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
|
492 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
|
493 rect.origin.y >= screenRect.origin.y && |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
494 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
|
495 screen = candidate; |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
496 rect.origin.x -= screenRect.origin.x; |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
497 rect.origin.y -= screenRect.origin.y; |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
498 } |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
499 } |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
500 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
|
501 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
502 [pool release]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
503 |
1951
7177581dc9fa
Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
504 if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) { |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
505 [nswindow release]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
506 return -1; |
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 return 0; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
509 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
510 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
511 int |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
512 Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
513 { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
514 NSAutoreleasePool *pool; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
515 NSWindow *nswindow = (NSWindow *) data; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
516 NSString *title; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
517 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
518 pool = [[NSAutoreleasePool alloc] init]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
519 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
520 /* Query the title from the existing window */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
521 title = [nswindow title]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
522 if (title) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
523 window->title = SDL_strdup([title UTF8String]); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
524 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
525 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
526 [pool release]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
527 |
1951
7177581dc9fa
Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
528 return SetupWindowData(_this, window, nswindow, SDL_FALSE); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
529 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
530 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
531 void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
532 Cocoa_SetWindowTitle(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
533 { |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
534 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
535 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
536 NSString *string; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
537 |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
538 if(window->title) { |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
539 string = [[NSString alloc] initWithUTF8String:window->title]; |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
540 } else { |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
541 string = [[NSString alloc] init]; |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
542 } |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
543 [nswindow setTitle:string]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
544 [string release]; |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
545 |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
546 [pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
547 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
548 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
549 void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
550 Cocoa_SetWindowPosition(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
551 { |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
552 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
553 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
|
554 SDL_VideoDisplay *display = window->display; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
555 NSRect rect; |
3528
59ff7a2beb57
Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents:
3525
diff
changeset
|
556 SDL_Rect bounds; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
557 |
3528
59ff7a2beb57
Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents:
3525
diff
changeset
|
558 Cocoa_GetDisplayBounds(_this, display, &bounds); |
3075
4c28a9655933
Fixed bug using SDL_WINDOWPOS_CENTERED with SDL_SetWindowPosition()
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
559 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
|
560 || 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
|
561 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
|
562 } else { |
3530
e96be66e3673
The window position is display relative, at least for now...
Sam Lantinga <slouken@libsdl.org>
parents:
3529
diff
changeset
|
563 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
|
564 } |
4c28a9655933
Fixed bug using SDL_WINDOWPOS_CENTERED with SDL_SetWindowPosition()
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
565 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
|
566 || 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
|
567 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
|
568 } else { |
3530
e96be66e3673
The window position is display relative, at least for now...
Sam Lantinga <slouken@libsdl.org>
parents:
3529
diff
changeset
|
569 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
|
570 } |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
571 rect.size.width = window->w; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
572 rect.size.height = window->h; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
573 ConvertNSRect(&rect); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
574 rect = [nswindow frameRectForContentRect:rect]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
575 [nswindow setFrameOrigin:rect.origin]; |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
576 [pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
577 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
578 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
579 void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
580 Cocoa_SetWindowSize(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
581 { |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
582 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
583 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
584 NSSize size; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
585 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
586 size.width = window->w; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
587 size.height = window->h; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
588 [nswindow setContentSize:size]; |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
589 [pool release]; |
1933
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 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
592 void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
593 Cocoa_ShowWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
594 { |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
595 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
596 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
597 |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
598 if (![nswindow isMiniaturized]) { |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
599 [nswindow makeKeyAndOrderFront:nil]; |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
600 } |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
601 [pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
602 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
603 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
604 void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
605 Cocoa_HideWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
606 { |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
607 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
608 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
609 |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
610 [nswindow orderOut:nil]; |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
611 [pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
612 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
613 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
614 void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
615 Cocoa_RaiseWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
616 { |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
617 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
618 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
619 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
620 [nswindow makeKeyAndOrderFront:nil]; |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
621 [pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
622 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
623 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
624 void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
625 Cocoa_MaximizeWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
626 { |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
627 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
628 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
629 |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
630 [nswindow zoom:nil]; |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
631 [pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
632 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
633 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
634 void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
635 Cocoa_MinimizeWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
636 { |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
637 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
638 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
639 |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
640 [nswindow miniaturize:nil]; |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
641 [pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
642 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
643 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
644 void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
645 Cocoa_RestoreWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
646 { |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
647 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
648 NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
649 |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
650 if ([nswindow isMiniaturized]) { |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
651 [nswindow deminiaturize:nil]; |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
652 } else if ([nswindow isZoomed]) { |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
653 [nswindow zoom:nil]; |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
654 } |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
655 [pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
656 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
657 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
658 void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
659 Cocoa_SetWindowGrab(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
660 { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
661 if ((window->flags & SDL_WINDOW_INPUT_GRABBED) && |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
662 (window->flags & SDL_WINDOW_INPUT_FOCUS)) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
663 /* FIXME: Grab mouse */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
664 } else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
665 /* FIXME: Release mouse */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
666 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
667 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
668 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
669 void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
670 Cocoa_DestroyWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
671 { |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
672 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
673 SDL_WindowData *data = (SDL_WindowData *) window->driverdata; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
674 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
675 if (data) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
676 [data->listener close]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
677 [data->listener release]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
678 if (data->created) { |
3688
6512cba48440
Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
679 [data->nswindow close]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
680 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
681 SDL_free(data); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
682 } |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
683 [pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
684 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
685 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
686 SDL_bool |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
687 Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
688 { |
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
|
689 //NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
690 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
691 if (info->version.major <= SDL_MAJOR_VERSION) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
692 //info->window = nswindow; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
693 return SDL_TRUE; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
694 } else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
695 SDL_SetError("Application not compiled with SDL %d.%d\n", |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
696 SDL_MAJOR_VERSION, SDL_MINOR_VERSION); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
697 return SDL_FALSE; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
698 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
699 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
700 |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
701 /* vi: set ts=4 sw=4 expandtab: */ |