Mercurial > sdl-ios-xcode
comparison src/video/quartz/SDL_QuartzWM.m @ 47:45b1c4303f87
Added initial support for Quartz video (thanks Darrell!)
author | Sam Lantinga <slouken@lokigames.com> |
---|---|
date | Thu, 07 Jun 2001 14:28:11 +0000 |
parents | |
children | bd6b0a910a65 |
comparison
equal
deleted
inserted
replaced
46:3dcf26fa9d15 | 47:45b1c4303f87 |
---|---|
1 /* | |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
20 slouken@devolution.com | |
21 */ | |
22 | |
23 struct WMcursor { | |
24 Cursor curs; | |
25 }; | |
26 | |
27 static void QZ_FreeWMCursor (_THIS, WMcursor *cursor) { | |
28 | |
29 if ( cursor != NULL ) | |
30 free (cursor); | |
31 } | |
32 | |
33 /* Use the Carbon cursor routines for now */ | |
34 static WMcursor* QZ_CreateWMCursor (_THIS, Uint8 *data, Uint8 *mask, | |
35 int w, int h, int hot_x, int hot_y) { | |
36 WMcursor *cursor; | |
37 int row, bytes; | |
38 cursor = (WMcursor *)malloc(sizeof(WMcursor)); | |
39 if ( cursor == NULL ) { | |
40 SDL_OutOfMemory(); | |
41 return(NULL); | |
42 } | |
43 memset(cursor, 0, sizeof(*cursor)); | |
44 | |
45 bytes = (w/8); | |
46 if ( bytes > 2 ) { | |
47 bytes = 2; | |
48 } | |
49 for ( row=0; row<h && (row < 16); ++row ) { | |
50 memcpy(&cursor->curs.data[row], data, bytes); | |
51 data += w/8; | |
52 } | |
53 for ( row=0; row<h && (row < 16); ++row ) { | |
54 memcpy(&cursor->curs.mask[row], mask, bytes); | |
55 mask += w/8; | |
56 } | |
57 cursor->curs.hotSpot.h = hot_x; | |
58 cursor->curs.hotSpot.v = hot_y; | |
59 | |
60 return(cursor); | |
61 } | |
62 | |
63 static int QZ_ShowWMCursor (_THIS, WMcursor *cursor) { | |
64 | |
65 static int visible = 1; | |
66 | |
67 if ( cursor == NULL) { | |
68 if ( visible ) { | |
69 HideCursor (); | |
70 visible = 0; | |
71 } | |
72 } | |
73 else { | |
74 SetCursor(&cursor->curs); | |
75 if ( ! visible ) { | |
76 ShowCursor (); | |
77 visible = 1; | |
78 } | |
79 } | |
80 | |
81 return 1; | |
82 } | |
83 | |
84 static void QZ_PrivateWarpCursor (_THIS, int fullscreen, int h, int x, int y) { | |
85 | |
86 CGPoint p; | |
87 | |
88 /* We require absolute screen coordiates for our warp */ | |
89 p.x = x; | |
90 p.y = h - y; | |
91 | |
92 if ( fullscreen ) | |
93 /* Already absolute coordinates */ | |
94 CGDisplayMoveCursorToPoint(display_id, p); | |
95 else { | |
96 /* Convert to absolute screen coordinates */ | |
97 NSPoint base, screen; | |
98 base = NSMakePoint (p.x, p.y); | |
99 screen = [ window convertBaseToScreen:base ]; | |
100 p.x = screen.x; | |
101 p.y = device_height - screen.y; | |
102 CGDisplayMoveCursorToPoint (display_id, p); | |
103 } | |
104 } | |
105 | |
106 static void QZ_WarpWMCursor (_THIS, Uint16 x, Uint16 y) { | |
107 | |
108 /* Only allow warping when in foreground */ | |
109 if ( ! inForeground ) | |
110 return; | |
111 | |
112 /* Do the actual warp */ | |
113 QZ_PrivateWarpCursor (this, SDL_VideoSurface->flags & SDL_FULLSCREEN, | |
114 SDL_VideoSurface->h, x, y); | |
115 | |
116 /* Generate mouse moved event */ | |
117 SDL_PrivateMouseMotion (SDL_RELEASED, 0, x, y); | |
118 } | |
119 | |
120 static void QZ_MoveWMCursor (_THIS, int x, int y) { } | |
121 static void QZ_CheckMouseMode (_THIS) { } | |
122 | |
123 static void QZ_SetCaption (_THIS, const char *title, const char *icon) { | |
124 | |
125 NSString *str = [ [ NSString alloc ] initWithCString:title ]; | |
126 if (window != nil) | |
127 [ window setTitle:str ]; | |
128 | |
129 [ windowTitle release ]; | |
130 windowTitle = str; | |
131 } | |
132 | |
133 static void QZ_SetIcon (_THIS, SDL_Surface *icon, Uint8 *mask) { | |
134 /* Convert icon/mask to NSImage, assign with NSWindow's setMiniwindowImage method */ | |
135 } | |
136 | |
137 static int QZ_IconifyWindow (_THIS) { | |
138 | |
139 /* Bug! minimize erases the framebuffer */ | |
140 if ( ! [ window isMiniaturized ] ) { | |
141 [ window miniaturize:nil ]; | |
142 return 1; | |
143 } | |
144 else { | |
145 SDL_SetError ("window already iconified"); | |
146 return 0; | |
147 } | |
148 } | |
149 | |
150 /* | |
151 static int QZ_GetWMInfo (_THIS, SDL_SysWMinfo *info) { | |
152 info->nsWindowPtr = window; | |
153 return 0; | |
154 }*/ | |
155 | |
156 static SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode) { | |
157 | |
158 switch (grab_mode) { | |
159 case SDL_GRAB_QUERY: | |
160 break; | |
161 case SDL_GRAB_OFF: | |
162 CGAssociateMouseAndMouseCursorPosition (1); | |
163 currentGrabMode = SDL_GRAB_OFF; | |
164 break; | |
165 case SDL_GRAB_ON: | |
166 QZ_WarpWMCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2); | |
167 CGAssociateMouseAndMouseCursorPosition (0); | |
168 currentGrabMode = SDL_GRAB_ON; | |
169 break; | |
170 case SDL_GRAB_FULLSCREEN: | |
171 break; | |
172 } | |
173 | |
174 return currentGrabMode; | |
175 } |