author | Sam Lantinga <slouken@libsdl.org> |
Tue, 01 Dec 2009 12:08:34 +0000 | |
changeset 3507 | 3712547eac4f |
parent 3506 | e829b6098435 |
child 3508 | a12068b6f44f |
permissions | -rw-r--r-- |
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 |
2859 | 3 |
Copyright (C) 1997-2009 Sam Lantinga |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 |
This library is free software; you can redistribute it and/or |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 |
modify it under the terms of the GNU Lesser General Public |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 |
License as published by the Free Software Foundation; either |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 |
version 2.1 of the License, or (at your option) any later version. |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 |
This library is distributed in the hope that it will be useful, |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 |
Lesser General Public License for more details. |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 |
You should have received a copy of the GNU Lesser General Public |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 |
License along with this library; if not, write to the Free Software |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 |
Sam Lantinga |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 |
slouken@libsdl.org |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 |
*/ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 |
#include "SDL_config.h" |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 |
#include "SDL_syswm.h" |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 |
#include "../SDL_sysvideo.h" |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 |
#include "../../events/SDL_keyboard_c.h" |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 |
#include "../../events/SDL_mouse_c.h" |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 |
#include "../../events/SDL_windowevents_c.h" |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 |
#include "SDL_cocoavideo.h" |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 |
static __inline__ void ConvertNSRect(NSRect *r) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 |
{ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 |
r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 |
@implementation Cocoa_WindowListener |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 |
- (void)listen:(SDL_WindowData *)data |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 |
{ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 |
NSNotificationCenter *center; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 |
_data = data; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 |
center = [NSNotificationCenter defaultCenter]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 |
[_data->window setNextResponder:self]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 |
if ([_data->window delegate] != nil) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 |
[center addObserver:self selector:@selector(windowDisExpose:) name:NSWindowDidExposeNotification object:_data->window]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 |
[center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:_data->window]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 |
[center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:_data->window]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 |
[center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:_data->window]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 |
[center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:_data->window]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 |
[center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:_data->window]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 |
[center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:_data->window]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 |
} else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 |
[_data->window setDelegate:self]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 |
[center addObserver:self selector:@selector(windowDidHide:) name:NSApplicationDidHideNotification object:NSApp]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 |
[center addObserver:self selector:@selector(windowDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 |
[_data->window setAcceptsMouseMovedEvents:YES]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 |
- (void)close |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 |
{ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 |
NSNotificationCenter *center; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 |
center = [NSNotificationCenter defaultCenter]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 |
[_data->window setNextResponder:nil]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 |
if ([_data->window delegate] != self) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 |
[center removeObserver:self name:NSWindowDidExposeNotification object:_data->window]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 |
[center removeObserver:self name:NSWindowDidMoveNotification object:_data->window]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 |
[center removeObserver:self name:NSWindowDidResizeNotification object:_data->window]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 |
[center removeObserver:self name:NSWindowDidMiniaturizeNotification object:_data->window]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 |
[center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:_data->window]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 |
[center removeObserver:self name:NSWindowDidBecomeKeyNotification object:_data->window]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 |
[center removeObserver:self name:NSWindowDidResignKeyNotification object:_data->window]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 |
} else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 |
[_data->window setDelegate:nil]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 |
[center removeObserver:self name:NSApplicationDidHideNotification object:NSApp]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 |
[center removeObserver:self name:NSApplicationDidUnhideNotification object:NSApp]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 |
- (BOOL)windowShouldClose:(id)sender |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 |
{ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 |
SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_CLOSE, 0, 0); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 |
return NO; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 |
- (void)windowDidExpose:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 |
{ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 |
SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_EXPOSED, 0, 0); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 |
- (void)windowDidMove:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 |
{ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 |
int x, y; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 |
NSRect rect = [_data->window contentRectForFrameRect:[_data->window frame]]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 |
ConvertNSRect(&rect); |
3507
3712547eac4f
The window positions are relative to the origin of the windowing system (upper left of the primary display).
Sam Lantinga <slouken@libsdl.org>
parents:
3506
diff
changeset
|
103 |
x = (int)rect.origin.x; |
3712547eac4f
The window positions are relative to the origin of the windowing system (upper left of the primary display).
Sam Lantinga <slouken@libsdl.org>
parents:
3506
diff
changeset
|
104 |
y = (int)rect.origin.y; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 |
SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_MOVED, x, y); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 |
- (void)windowDidResize:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 |
{ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 |
int w, h; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 |
NSRect rect = [_data->window contentRectForFrameRect:[_data->window frame]]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 |
w = (int)rect.size.width; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 |
h = (int)rect.size.height; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 |
SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_RESIZED, w, h); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 |
- (void)windowDidMiniaturize:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 |
{ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 |
SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_MINIMIZED, 0, 0); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 |
- (void)windowDidDeminiaturize:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 |
{ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 |
SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_RESTORED, 0, 0); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
126 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 |
- (void)windowDidBecomeKey:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 |
{ |
1962
c92e5f3e68d9
Hack to stop the beeping
Sam Lantinga <slouken@libsdl.org>
parents:
1959
diff
changeset
|
129 |
int index; |
c92e5f3e68d9
Hack to stop the beeping
Sam Lantinga <slouken@libsdl.org>
parents:
1959
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. */ |
1962
c92e5f3e68d9
Hack to stop the beeping
Sam Lantinga <slouken@libsdl.org>
parents:
1959
diff
changeset
|
132 |
index = _data->videodata->keyboard; |
c92e5f3e68d9
Hack to stop the beeping
Sam Lantinga <slouken@libsdl.org>
parents:
1959
diff
changeset
|
133 |
SDL_SetKeyboardFocus(index, _data->windowID); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 |
- (void)windowDidResignKey:(NSNotification *)aNotification |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 |
{ |
1962
c92e5f3e68d9
Hack to stop the beeping
Sam Lantinga <slouken@libsdl.org>
parents:
1959
diff
changeset
|
138 |
int index; |
2059
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
139 |
SDL_Mouse *mouse; |
1962
c92e5f3e68d9
Hack to stop the beeping
Sam Lantinga <slouken@libsdl.org>
parents:
1959
diff
changeset
|
140 |
|
2059
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
141 |
/* Some other window will get mouse events, since we're not key. */ |
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
142 |
index = _data->videodata->mouse; |
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
143 |
mouse = SDL_GetMouse(index); |
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
144 |
if (mouse->focus == _data->windowID) { |
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
145 |
SDL_SetMouseFocus(index, 0); |
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
146 |
} |
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
147 |
|
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
148 |
/* Some other window will get keyboard events, since we're not key. */ |
1962
c92e5f3e68d9
Hack to stop the beeping
Sam Lantinga <slouken@libsdl.org>
parents:
1959
diff
changeset
|
149 |
index = _data->videodata->keyboard; |
c92e5f3e68d9
Hack to stop the beeping
Sam Lantinga <slouken@libsdl.org>
parents:
1959
diff
changeset
|
150 |
SDL_SetKeyboardFocus(index, 0); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 |
- (void)windowDidHide:(NSNotification *)aNotification |
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 |
SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_HIDDEN, 0, 0); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 |
- (void)windowDidUnhide:(NSNotification *)aNotification |
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 |
SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_SHOWN, 0, 0); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 |
- (void)mouseDown:(NSEvent *)theEvent |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 |
{ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
165 |
int index; |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
166 |
int button; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 |
index = _data->videodata->mouse; |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
169 |
switch ([theEvent buttonNumber]) { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
170 |
case 0: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
171 |
button = SDL_BUTTON_LEFT; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
172 |
break; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
173 |
case 1: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
174 |
button = SDL_BUTTON_RIGHT; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
175 |
break; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
176 |
case 2: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
177 |
button = SDL_BUTTON_MIDDLE; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
178 |
break; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
179 |
default: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
180 |
button = [theEvent buttonNumber]; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
181 |
break; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
182 |
} |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
183 |
SDL_SendMouseButton(index, SDL_PRESSED, button); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
184 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
185 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
186 |
- (void)rightMouseDown:(NSEvent *)theEvent |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
187 |
{ |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
188 |
[self mouseDown:theEvent]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
189 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 |
- (void)otherMouseDown:(NSEvent *)theEvent |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 |
{ |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
193 |
[self mouseDown:theEvent]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
195 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
196 |
- (void)mouseUp:(NSEvent *)theEvent |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
197 |
{ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
198 |
int index; |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
199 |
int button; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
200 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
201 |
index = _data->videodata->mouse; |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
202 |
switch ([theEvent buttonNumber]) { |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
203 |
case 0: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
204 |
button = SDL_BUTTON_LEFT; |
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 |
case 1: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
207 |
button = SDL_BUTTON_RIGHT; |
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 |
case 2: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
210 |
button = SDL_BUTTON_MIDDLE; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
211 |
break; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
212 |
default: |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
213 |
button = [theEvent buttonNumber]; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
214 |
break; |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
215 |
} |
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
216 |
SDL_SendMouseButton(index, SDL_RELEASED, button); |
1933
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 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
219 |
- (void)rightMouseUp:(NSEvent *)theEvent |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
220 |
{ |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
221 |
[self mouseUp:theEvent]; |
1933
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 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
224 |
- (void)otherMouseUp:(NSEvent *)theEvent |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 |
{ |
1959
25d6537feea4
Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents:
1958
diff
changeset
|
226 |
[self mouseUp:theEvent]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
227 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
228 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 |
- (void)mouseMoved:(NSEvent *)theEvent |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
230 |
{ |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
231 |
SDL_Window *window = SDL_GetWindowFromID(_data->windowID); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 |
int index; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
233 |
SDL_Mouse *mouse; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
234 |
NSPoint point; |
3414 | 235 |
NSRect rect; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
236 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
237 |
index = _data->videodata->mouse; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
238 |
mouse = SDL_GetMouse(index); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
239 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
240 |
point = [NSEvent mouseLocation]; |
3409 | 241 |
if ( (window->flags & SDL_WINDOW_FULLSCREEN) ) { |
242 |
rect.size.width = CGDisplayPixelsWide(kCGDirectMainDisplay); |
|
243 |
rect.size.height = CGDisplayPixelsHigh(kCGDirectMainDisplay); |
|
3414 | 244 |
point.x = point.x - rect.origin.x; |
3409 | 245 |
point.y = rect.size.height - point.y; |
246 |
} else { |
|
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
|
247 |
point.x -= window->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
|
248 |
point.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - point.y - window->y; |
3409 | 249 |
} |
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
|
250 |
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
|
251 |
point.y < 0 || point.y >= window->h ) { |
2059
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
252 |
if (mouse->focus != 0) { |
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
253 |
SDL_SetMouseFocus(index, 0); |
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
254 |
} |
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
255 |
} else { |
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
256 |
if (mouse->focus != _data->windowID) { |
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
257 |
SDL_SetMouseFocus(index, _data->windowID); |
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
258 |
} |
2710
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2152
diff
changeset
|
259 |
SDL_SendMouseMotion(index, 0, (int)point.x, (int)point.y, 0); |
2059
4685ccd33d0e
Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents:
1973
diff
changeset
|
260 |
} |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
261 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
262 |
|
1957
c7803e4c21d3
Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents:
1956
diff
changeset
|
263 |
- (void)mouseDragged:(NSEvent *)theEvent |
c7803e4c21d3
Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents:
1956
diff
changeset
|
264 |
{ |
c7803e4c21d3
Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents:
1956
diff
changeset
|
265 |
[self mouseMoved:theEvent]; |
c7803e4c21d3
Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents:
1956
diff
changeset
|
266 |
} |
c7803e4c21d3
Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents:
1956
diff
changeset
|
267 |
|
1958
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
268 |
- (void)rightMouseDragged:(NSEvent *)theEvent |
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
269 |
{ |
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
270 |
[self mouseMoved:theEvent]; |
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
271 |
} |
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
272 |
|
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
273 |
- (void)otherMouseDragged:(NSEvent *)theEvent |
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
274 |
{ |
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
275 |
[self mouseMoved:theEvent]; |
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
276 |
} |
5fc6fb0fb605
Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents:
1957
diff
changeset
|
277 |
|
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
278 |
- (void)scrollWheel:(NSEvent *)theEvent |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
279 |
{ |
1957
c7803e4c21d3
Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents:
1956
diff
changeset
|
280 |
int index; |
c7803e4c21d3
Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents:
1956
diff
changeset
|
281 |
|
c7803e4c21d3
Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents:
1956
diff
changeset
|
282 |
index = _data->videodata->mouse; |
2152 | 283 |
SDL_SendMouseWheel(index, (int)([theEvent deltaX]+0.9f), (int)([theEvent deltaY]+0.9f)); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
284 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
285 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
286 |
@end |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
287 |
|
1973
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
288 |
@interface SDLWindow : NSWindow |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
289 |
/* These are needed for borderless/fullscreen windows */ |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
290 |
- (BOOL)canBecomeKeyWindow; |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
291 |
- (BOOL)canBecomeMainWindow; |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
292 |
@end |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
293 |
|
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
294 |
@implementation SDLWindow |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
295 |
- (BOOL)canBecomeKeyWindow |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
296 |
{ |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
297 |
return YES; |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
298 |
} |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
299 |
|
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
300 |
- (BOOL)canBecomeMainWindow |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
301 |
{ |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
302 |
return YES; |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
303 |
} |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
304 |
@end |
81255f93dfcd
Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents:
1962
diff
changeset
|
305 |
|
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
306 |
static int |
1951
7177581dc9fa
Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
307 |
SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created) |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
308 |
{ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
309 |
NSAutoreleasePool *pool; |
1951
7177581dc9fa
Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
310 |
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; |
3506
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
311 |
SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 |
SDL_WindowData *data; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
313 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
314 |
/* Allocate the window data */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
315 |
data = (SDL_WindowData *) SDL_malloc(sizeof(*data)); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
316 |
if (!data) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
317 |
SDL_OutOfMemory(); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
318 |
return -1; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
319 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
320 |
data->windowID = window->id; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
321 |
data->window = nswindow; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
322 |
data->created = created; |
3506
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
323 |
data->display = displaydata->display; |
1951
7177581dc9fa
Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
324 |
data->videodata = videodata; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
325 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
326 |
pool = [[NSAutoreleasePool alloc] init]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
327 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
328 |
/* Create an event listener for the window */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
329 |
data->listener = [[Cocoa_WindowListener alloc] init]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
330 |
[data->listener listen:data]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
331 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
332 |
/* Fill in the SDL window with the window data */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
333 |
{ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
334 |
NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
335 |
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
|
336 |
window->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
|
337 |
window->y = (int)rect.origin.y; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
338 |
window->w = (int)rect.size.width; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
339 |
window->h = (int)rect.size.height; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
340 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
341 |
if ([nswindow isVisible]) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
342 |
window->flags |= SDL_WINDOW_SHOWN; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
343 |
} else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
344 |
window->flags &= ~SDL_WINDOW_SHOWN; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
345 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
346 |
{ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
347 |
unsigned int style = [nswindow styleMask]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
348 |
|
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
349 |
if ((style & ~NSResizableWindowMask) == NSBorderlessWindowMask) { |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
350 |
window->flags |= SDL_WINDOW_BORDERLESS; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
351 |
} else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
352 |
window->flags &= ~SDL_WINDOW_BORDERLESS; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
353 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
354 |
if (style & NSResizableWindowMask) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
355 |
window->flags |= SDL_WINDOW_RESIZABLE; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
356 |
} else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
357 |
window->flags &= ~SDL_WINDOW_RESIZABLE; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
358 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
359 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
360 |
if ([nswindow isZoomed]) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
361 |
window->flags |= SDL_WINDOW_MAXIMIZED; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
362 |
} else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
363 |
window->flags &= ~SDL_WINDOW_MAXIMIZED; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
364 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
365 |
if ([nswindow isMiniaturized]) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
366 |
window->flags |= SDL_WINDOW_MINIMIZED; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
367 |
} else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
368 |
window->flags &= ~SDL_WINDOW_MINIMIZED; |
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 |
if ([nswindow isKeyWindow]) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
371 |
int index = data->videodata->keyboard; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
372 |
window->flags |= SDL_WINDOW_INPUT_FOCUS; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
373 |
SDL_SetKeyboardFocus(index, data->windowID); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
374 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
375 |
if (window->flags & SDL_WINDOW_INPUT_GRABBED) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
376 |
/* FIXME */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
377 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
378 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
379 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
380 |
/* All done! */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
381 |
[pool release]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
382 |
window->driverdata = data; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
383 |
return 0; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
384 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
385 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
386 |
int |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
387 |
Cocoa_CreateWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
388 |
{ |
3506
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
389 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
390 |
NSWindow *nswindow; |
3506
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
391 |
SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
392 |
NSRect rect; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
393 |
unsigned int style; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
394 |
NSString *title; |
1936
83946ee0ff1f
Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
1933
diff
changeset
|
395 |
int status; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
396 |
|
3506
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
397 |
rect = CGDisplayBounds(displaydata->display); |
3075
4c28a9655933
Fixed bug using SDL_WINDOWPOS_CENTERED with SDL_SetWindowPosition()
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
398 |
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
|
399 |
|| window->x == SDL_WINDOWPOS_CENTERED) { |
3506
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
400 |
rect.origin.x += (rect.size.width - window->w) / 2; |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
401 |
} else if (window->x != SDL_WINDOWPOS_UNDEFINED) { |
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
|
402 |
rect.origin.x = window->x; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
403 |
} |
3075
4c28a9655933
Fixed bug using SDL_WINDOWPOS_CENTERED with SDL_SetWindowPosition()
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
404 |
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
|
405 |
|| window->y == SDL_WINDOWPOS_CENTERED) { |
3506
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
406 |
rect.origin.y += (rect.size.height - window->h) / 2; |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
407 |
} else if (window->x != SDL_WINDOWPOS_UNDEFINED) { |
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
|
408 |
rect.origin.y = window->y; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
409 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
410 |
rect.size.width = window->w; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
411 |
rect.size.height = window->h; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
412 |
ConvertNSRect(&rect); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
413 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
414 |
if (window->flags & SDL_WINDOW_BORDERLESS) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
415 |
style = NSBorderlessWindowMask; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
416 |
} else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
417 |
style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
418 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
419 |
if (window->flags & SDL_WINDOW_RESIZABLE) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
420 |
style |= NSResizableWindowMask; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
421 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
422 |
|
3506
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
423 |
/* 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
|
424 |
NSArray *screens = [NSScreen screens]; |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
425 |
NSScreen *screen = nil; |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
426 |
NSScreen *candidate; |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
427 |
for (candidate in screens) { |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
428 |
NSRect screenRect = [candidate frame]; |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
429 |
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
|
430 |
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
|
431 |
rect.origin.y >= screenRect.origin.y && |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
432 |
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
|
433 |
screen = candidate; |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
434 |
rect.origin.x -= screenRect.origin.x; |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
435 |
rect.origin.y -= screenRect.origin.y; |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
436 |
} |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
437 |
} |
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
438 |
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
|
439 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
440 |
[pool release]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
441 |
|
1951
7177581dc9fa
Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
442 |
if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) { |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
443 |
[nswindow release]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
444 |
return -1; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
445 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
446 |
return 0; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
447 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
448 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
449 |
int |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
450 |
Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
451 |
{ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
452 |
NSAutoreleasePool *pool; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
453 |
NSWindow *nswindow = (NSWindow *) data; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
454 |
NSString *title; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
455 |
int status; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
456 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
457 |
pool = [[NSAutoreleasePool alloc] init]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
458 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
459 |
/* Query the title from the existing window */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
460 |
title = [nswindow title]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
461 |
if (title) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
462 |
window->title = SDL_strdup([title UTF8String]); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
463 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
464 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
465 |
[pool release]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
466 |
|
1951
7177581dc9fa
Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
1937
diff
changeset
|
467 |
return SetupWindowData(_this, window, nswindow, SDL_FALSE); |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
468 |
} |
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 |
void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
471 |
Cocoa_SetWindowTitle(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
472 |
{ |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
473 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
474 |
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
475 |
NSString *string; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
476 |
|
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
477 |
if(window->title) { |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
478 |
string = [[NSString alloc] initWithUTF8String:window->title]; |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
479 |
} else { |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
480 |
string = [[NSString alloc] init]; |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
481 |
} |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
482 |
[nswindow setTitle:string]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
483 |
[string release]; |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
484 |
|
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
485 |
[pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
486 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
487 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
488 |
void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
489 |
Cocoa_SetWindowPosition(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
490 |
{ |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
491 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
492 |
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; |
3506
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
493 |
SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
494 |
NSRect rect; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
495 |
|
3506
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
496 |
rect = CGDisplayBounds(displaydata->display); |
3075
4c28a9655933
Fixed bug using SDL_WINDOWPOS_CENTERED with SDL_SetWindowPosition()
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
497 |
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
|
498 |
|| window->x == SDL_WINDOWPOS_CENTERED) { |
3506
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
499 |
rect.origin.x += (rect.size.width - window->w) / 2; |
3075
4c28a9655933
Fixed bug using SDL_WINDOWPOS_CENTERED with SDL_SetWindowPosition()
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
500 |
} else { |
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
|
501 |
rect.origin.x = window->x; |
3075
4c28a9655933
Fixed bug using SDL_WINDOWPOS_CENTERED with SDL_SetWindowPosition()
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
502 |
} |
4c28a9655933
Fixed bug using SDL_WINDOWPOS_CENTERED with SDL_SetWindowPosition()
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
503 |
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
|
504 |
|| window->y == SDL_WINDOWPOS_CENTERED) { |
3506
e829b6098435
Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents:
3414
diff
changeset
|
505 |
rect.origin.y += (rect.size.height - window->h) / 2; |
3075
4c28a9655933
Fixed bug using SDL_WINDOWPOS_CENTERED with SDL_SetWindowPosition()
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
506 |
} else { |
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
|
507 |
rect.origin.y = window->y; |
3075
4c28a9655933
Fixed bug using SDL_WINDOWPOS_CENTERED with SDL_SetWindowPosition()
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
508 |
} |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
509 |
rect.size.width = window->w; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
510 |
rect.size.height = window->h; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
511 |
ConvertNSRect(&rect); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
512 |
rect = [nswindow frameRectForContentRect:rect]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
513 |
[nswindow setFrameOrigin:rect.origin]; |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
514 |
[pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
515 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
516 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
517 |
void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
518 |
Cocoa_SetWindowSize(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
519 |
{ |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
520 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
521 |
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
522 |
NSSize size; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
523 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
524 |
size.width = window->w; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
525 |
size.height = window->h; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
526 |
[nswindow setContentSize:size]; |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
527 |
[pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
528 |
} |
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 |
void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
531 |
Cocoa_ShowWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
532 |
{ |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
533 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
534 |
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
535 |
|
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
536 |
if (![nswindow isMiniaturized]) { |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
537 |
[nswindow makeKeyAndOrderFront:nil]; |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
538 |
} |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
539 |
[pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
540 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
541 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
542 |
void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
543 |
Cocoa_HideWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
544 |
{ |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
545 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
546 |
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
547 |
|
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
548 |
[nswindow orderOut:nil]; |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
549 |
[pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
550 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
551 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
552 |
void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
553 |
Cocoa_RaiseWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
554 |
{ |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
555 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
556 |
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
557 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
558 |
[nswindow makeKeyAndOrderFront:nil]; |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
559 |
[pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
560 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
561 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
562 |
void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
563 |
Cocoa_MaximizeWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
564 |
{ |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
565 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
566 |
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
567 |
|
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
568 |
[nswindow zoom:nil]; |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
569 |
[pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
570 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
571 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
572 |
void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
573 |
Cocoa_MinimizeWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
574 |
{ |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
575 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
576 |
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
577 |
|
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
578 |
[nswindow miniaturize:nil]; |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
579 |
[pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
580 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
581 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
582 |
void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
583 |
Cocoa_RestoreWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
584 |
{ |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
585 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
586 |
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
587 |
|
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
588 |
if ([nswindow isMiniaturized]) { |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
589 |
[nswindow deminiaturize:nil]; |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
590 |
} else if ([nswindow isZoomed]) { |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
591 |
[nswindow zoom:nil]; |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
592 |
} |
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
593 |
[pool release]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
594 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
595 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
596 |
void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
597 |
Cocoa_SetWindowGrab(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
598 |
{ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
599 |
if ((window->flags & SDL_WINDOW_INPUT_GRABBED) && |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
600 |
(window->flags & SDL_WINDOW_INPUT_FOCUS)) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
601 |
/* FIXME: Grab mouse */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
602 |
} else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
603 |
/* FIXME: Release mouse */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
604 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
605 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
606 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
607 |
void |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
608 |
Cocoa_DestroyWindow(_THIS, SDL_Window * window) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
609 |
{ |
1937
05e88d266921
Fixed Objective-C memory leaks
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
610 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
611 |
SDL_WindowData *data = (SDL_WindowData *) window->driverdata; |
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 |
if (data) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
614 |
[data->listener close]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
615 |
[data->listener release]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
616 |
if (data->created) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
617 |
[data->window close]; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
618 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
619 |
SDL_free(data); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
620 |
} |
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 |
SDL_bool |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
625 |
Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info) |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
626 |
{ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
627 |
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
628 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
629 |
if (info->version.major <= SDL_MAJOR_VERSION) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
630 |
//info->window = nswindow; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
631 |
return SDL_TRUE; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
632 |
} else { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
633 |
SDL_SetError("Application not compiled with SDL %d.%d\n", |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
634 |
SDL_MAJOR_VERSION, SDL_MINOR_VERSION); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
635 |
return SDL_FALSE; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
636 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
637 |
} |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
638 |
|
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
639 |
/* vi: set ts=4 sw=4 expandtab: */ |