Mercurial > sdl-ios-xcode
annotate src/video/photon/SDL_ph_image.c @ 172:37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 11 Sep 2001 19:00:18 +0000 |
parents | 8cc4dbfab9ab |
children | e8157fcb3114 |
rev | line source |
---|---|
0 | 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 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 #include <stdlib.h> | |
29 #include <Ph.h> | |
30 #include <photon/Pg.h> | |
31 | |
32 #include "SDL_error.h" | |
33 #include "SDL_endian.h" | |
34 #include "SDL_ph_image_c.h" | |
35 | |
36 //printf("%s:%s:%d\n", __FILE__, __PRETTY_FUNCTION__, __LINE__ ); | |
37 | |
38 /* Various screen update functions available */ | |
39 //static void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects); | |
40 //static void ph_DummyUpdate(_THIS, int numrects, SDL_Rect *rects); | |
41 | |
42 int ph_SetupImage(_THIS, SDL_Surface *screen) | |
43 { | |
44 int type = 0; | |
45 | |
46 /* Determine image type */ | |
47 switch(screen->format->BitsPerPixel) | |
48 { | |
49 case 8:{ | |
50 type = Pg_IMAGE_PALETTE_BYTE; | |
51 } | |
52 break; | |
53 case 15:{ | |
54 type = Pg_IMAGE_DIRECT_555; | |
55 } | |
56 break; | |
57 case 16:{ | |
58 type = Pg_IMAGE_DIRECT_565; | |
59 } | |
60 break; | |
61 | |
62 case 24:{ | |
63 type = Pg_IMAGE_DIRECT_888; | |
64 } | |
65 break; | |
66 | |
67 case 32:{ | |
68 type = Pg_IMAGE_DIRECT_8888; | |
69 } | |
70 break; | |
71 default:{ | |
72 /* should never get here */ | |
73 fprintf(stderr,"error: unsupported bbp = %d\n", | |
74 screen->format->BitsPerPixel); | |
75 return -1; | |
76 } | |
77 break; | |
78 } | |
79 | |
80 //using shared memory for speed (set last param to 1) | |
19
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
81 if ((SDL_Image = PhCreateImage( NULL, screen->w, screen->h, type, NULL, 0, 1 )) == NULL) |
0 | 82 { |
83 fprintf(stderr,"error: PhCreateImage failed.\n"); | |
84 return -1; | |
85 } | |
86 | |
87 screen->pixels = SDL_Image->image; | |
88 | |
89 this->UpdateRects = ph_NormalUpdate; | |
90 | |
91 return 0; | |
92 } | |
93 | |
94 int ph_SetupOCImage(_THIS, SDL_Surface *screen) //Offscreen context | |
95 { | |
96 int type = 0; | |
97 | |
98 /* Determine image type */ | |
99 switch(screen->format->BitsPerPixel) | |
100 { | |
101 case 8:{ | |
102 type = Pg_IMAGE_PALETTE_BYTE; | |
103 } | |
104 break; | |
105 case 15:{ | |
106 type = Pg_IMAGE_DIRECT_555; | |
107 } | |
108 break; | |
109 case 16:{ | |
110 type = Pg_IMAGE_DIRECT_565; | |
111 } | |
112 break; | |
113 | |
114 case 24:{ | |
115 type = Pg_IMAGE_DIRECT_888; | |
116 } | |
117 break; | |
118 | |
119 case 32:{ | |
120 type = Pg_IMAGE_DIRECT_8888; | |
121 } | |
122 break; | |
123 default:{ | |
124 /* should never get here */ | |
125 fprintf(stderr,"error: unsupported bbp = %d\n", | |
126 screen->format->BitsPerPixel); | |
127 return -1; | |
128 } | |
129 break; | |
130 } | |
131 | |
132 OCImage.FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof( FRAMEDATA))); | |
133 OCImage.FrameData1 = (FRAMEDATA *) malloc((size_t)(sizeof( FRAMEDATA))); | |
134 | |
135 if(OCImage.direct_context == NULL) | |
136 OCImage.direct_context = PdCreateDirectContext(); | |
137 | |
138 OCImage.offscreen_context = PdCreateOffscreenContext(0,screen->w,screen->h, Pg_OSC_MEM_PAGE_ALIGN); | |
139 | |
140 if (OCImage.offscreen_context == NULL) | |
141 { | |
142 printf("PdCreateOffscreenContext failed\n"); | |
143 return -1; | |
144 } | |
145 | |
146 OCImage.Stride = OCImage.offscreen_context->pitch; | |
147 | |
148 if (OCImage.flags & SDL_DOUBLEBUF) | |
149 printf("hardware flag for doublebuf offscreen context\n"); | |
150 | |
151 | |
152 OCImage.dc_ptr.ptr8 = (unsigned char *) PdGetOffscreenContextPtr(OCImage.offscreen_context); | |
153 | |
154 OCImage.CurrentFrameData = OCImage.FrameData0; | |
155 OCImage.CurrentFrameData->Y = OCImage.dc_ptr.ptr8; | |
156 OCImage.CurrentFrameData->U = NULL; | |
157 OCImage.CurrentFrameData->V = NULL; | |
158 OCImage.current = 0; | |
159 | |
160 if(OCImage.dc_ptr.ptr8 == NULL) | |
161 { | |
162 printf("PdGetOffscreenContextPtr failed\n"); | |
163 return -1; | |
164 } | |
165 | |
166 PhDCSetCurrent(OCImage.offscreen_context); | |
167 | |
168 screen->pixels = OCImage.CurrentFrameData->Y; | |
169 | |
170 this->UpdateRects = ph_OCUpdate; | |
171 | |
172 return 0; | |
173 } | |
174 | |
175 | |
176 void ph_DestroyImage(_THIS, SDL_Surface *screen) | |
177 { | |
178 | |
179 | |
180 if(SDL_Image == NULL) | |
181 return; | |
182 | |
183 if (OCImage.offscreen_context != NULL) | |
184 { | |
185 | |
186 PhDCRelease(OCImage.offscreen_context); | |
187 OCImage.offscreen_context = NULL; | |
188 free(OCImage.FrameData0); | |
189 OCImage.FrameData0 = NULL; | |
190 free(OCImage.FrameData1); | |
191 OCImage.FrameData1 = NULL; | |
192 } | |
193 | |
194 if (SDL_Image->image) | |
195 { | |
19
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
196 // SDL_Image->flags=Ph_RELEASE_IMAGE; |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
197 // PhReleaseImage(SDL_Image); |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
198 PgShmemDestroy(SDL_Image->image); // Use this if you using shared memory, or uncomment |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
199 // lines above if not (and comment this line ;-) |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
200 free(SDL_Image); |
0 | 201 } |
202 | |
19
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
203 if ( screen ) |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
204 { |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
205 screen->pixels = NULL; |
0 | 206 } |
207 | |
208 SDL_Image = NULL; | |
209 } | |
210 | |
211 int ph_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags) | |
212 { | |
213 | |
214 ph_DestroyImage(this, screen); | |
215 | |
216 if( flags & SDL_HWSURFACE) | |
217 { | |
218 OCImage.flags = flags; //needed for SDL_DOUBLEBUF check | |
219 return ph_SetupOCImage(this,screen); | |
220 } | |
221 else if(flags & SDL_OPENGL) /* No image when using GL */ | |
222 { | |
223 return 0; | |
224 } | |
225 else | |
226 { | |
227 return ph_SetupImage(this, screen); | |
228 } | |
229 | |
230 } | |
231 | |
232 int ph_AllocHWSurface(_THIS, SDL_Surface *surface) | |
233 { | |
234 | |
235 return(-1); | |
236 } | |
237 | |
238 void ph_FreeHWSurface(_THIS, SDL_Surface *surface) | |
239 { | |
240 | |
241 return; | |
242 } | |
243 | |
244 int ph_FlipHWSurface(_THIS, SDL_Surface *surface) | |
245 { | |
246 | |
247 return(0); | |
248 } | |
249 | |
250 int ph_LockHWSurface(_THIS, SDL_Surface *surface) | |
251 { | |
252 | |
253 if ( (surface == SDL_VideoSurface) && blit_queued ) { | |
254 // XSync(GFX_Display, False); | |
255 PgFlush(); | |
256 blit_queued = 0; | |
257 } | |
258 return(0); | |
259 } | |
260 | |
261 void ph_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
262 { | |
263 | |
264 return; | |
265 } | |
266 | |
267 static PhPoint_t ph_pos; | |
268 static PhRect_t ph_rect; | |
269 static int i; | |
270 | |
271 void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) | |
272 { | |
273 | |
274 for ( i=0; i<numrects; ++i ) | |
275 { | |
276 if ( rects[i].w == 0 ) { /* Clipped? */ | |
277 continue; | |
278 } | |
279 | |
280 ph_pos.x = rects[i].x; | |
281 ph_pos.y = rects[i].y; | |
282 ph_rect.ul.x = rects[i].x; | |
283 ph_rect.ul.y = rects[i].y; | |
284 ph_rect.lr.x = rects[i].x + rects[i].w; | |
285 ph_rect.lr.y = rects[i].y + rects[i].h; | |
286 | |
287 if (PgDrawPhImageRectmx( &ph_pos, SDL_Image, &ph_rect, 0 ) < 0) | |
288 { | |
289 fprintf(stderr,"error: PgDrawPhImageRectmx failed.\n"); | |
290 } | |
291 } | |
292 if (PgFlush() < 0) | |
293 { | |
294 fprintf(stderr,"error: PgFlush failed.\n"); | |
295 } | |
296 } | |
297 void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects) | |
298 { | |
299 PhPoint_t zero = {0}; | |
300 PhRect_t src_rect; | |
301 PhRect_t dest_rect; | |
302 | |
303 if(OCImage.direct_context == NULL) | |
304 { | |
305 return; | |
306 } | |
307 | |
308 PgSetRegion(PtWidgetRid(window)); | |
309 PgSetClipping(0,NULL); | |
310 PgWaitHWIdle(); | |
311 | |
312 | |
313 for ( i=0; i<numrects; ++i ) | |
314 { | |
315 if ( rects[i].w == 0 ) { /* Clipped? */ | |
316 continue; | |
317 } | |
318 | |
319 src_rect.ul.x=rects[i].x; | |
320 src_rect.ul.y=rects[i].y; | |
321 dest_rect.ul.x=rects[i].x; | |
322 dest_rect.ul.y=rects[i].y; | |
323 | |
324 dest_rect.lr.x=src_rect.lr.x= rects[i].x +rects[i].w; | |
325 dest_rect.lr.y=src_rect.lr.y= rects[i].y +rects[i].h; | |
326 | |
327 zero.x = zero.y = 0; | |
328 PgSetTranslation (&zero, 0); | |
329 PgSetRegion(PtWidgetRid(window)); | |
330 PgSetClipping(0,NULL); | |
331 PgContextBlitArea(OCImage.offscreen_context, (PhArea_t *)(&src_rect), NULL, (PhArea_t *)(&dest_rect)); | |
332 | |
333 } | |
334 if (PgFlush() < 0) | |
335 { | |
336 fprintf(stderr,"error: PgFlush failed.\n"); | |
337 } | |
338 | |
339 //later used to toggling double buffer | |
340 if(OCImage.current == 0) | |
341 { | |
342 OCImage.CurrentFrameData = OCImage.FrameData0; | |
343 } | |
344 else | |
345 { | |
346 OCImage.CurrentFrameData = OCImage.FrameData1; | |
347 } | |
348 } | |
349 |