Mercurial > sdl-ios-xcode
annotate src/video/bwindow/SDL_sysvideo.cc @ 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 | 7be1046c4a68 |
children | b69bb2a368a0 |
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 /* BWindow based framebuffer implementation */ | |
29 | |
30 #include <stdlib.h> | |
31 #include <string.h> | |
32 | |
33 #include <stdio.h> | |
34 #include <unistd.h> | |
35 | |
36 #include "SDL.h" | |
37 #include "SDL_BeApp.h" | |
38 #include "SDL_BWin.h" | |
39 #include "SDL_timer.h" | |
40 #include "blank_cursor.h" | |
41 | |
42 extern "C" { | |
43 | |
44 #include "SDL_sysvideo.h" | |
45 #include "SDL_sysmouse_c.h" | |
46 #include "SDL_sysevents_c.h" | |
47 #include "SDL_events_c.h" | |
48 #include "SDL_syswm_c.h" | |
49 #include "SDL_lowvideo.h" | |
50 | |
51 #define BEOS_HIDDEN_SIZE 32 /* starting hidden window size */ | |
52 | |
53 /* Initialization/Query functions */ | |
54 static int BE_VideoInit(_THIS, SDL_PixelFormat *vformat); | |
55 static SDL_Rect **BE_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); | |
56 static SDL_Surface *BE_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); | |
57 static void BE_UpdateMouse(_THIS); | |
58 static int BE_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); | |
59 static void BE_VideoQuit(_THIS); | |
60 | |
61 /* Hardware surface functions */ | |
62 static int BE_AllocHWSurface(_THIS, SDL_Surface *surface); | |
63 static int BE_LockHWSurface(_THIS, SDL_Surface *surface); | |
64 static void BE_UnlockHWSurface(_THIS, SDL_Surface *surface); | |
65 static void BE_FreeHWSurface(_THIS, SDL_Surface *surface); | |
66 | |
67 static int BE_ToggleFullScreen(_THIS, int fullscreen); | |
68 | |
69 /* OpenGL functions */ | |
70 #ifdef HAVE_OPENGL | |
71 static void BE_GL_SwapBuffers(_THIS); | |
72 #endif | |
73 | |
74 /* FB driver bootstrap functions */ | |
75 | |
76 static int BE_Available(void) | |
77 { | |
78 return(1); | |
79 } | |
80 | |
81 static void BE_DeleteDevice(SDL_VideoDevice *device) | |
82 { | |
83 free(device->hidden); | |
84 free(device); | |
85 } | |
86 | |
87 static SDL_VideoDevice *BE_CreateDevice(int devindex) | |
88 { | |
89 SDL_VideoDevice *device; | |
90 | |
91 /* Initialize all variables that we clean on shutdown */ | |
92 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice)); | |
93 if ( device ) { | |
94 memset(device, 0, (sizeof *device)); | |
95 device->hidden = (struct SDL_PrivateVideoData *) | |
96 malloc((sizeof *device->hidden)); | |
97 } | |
98 if ( (device == NULL) || (device->hidden == NULL) ) { | |
99 SDL_OutOfMemory(); | |
100 if ( device ) { | |
101 free(device); | |
102 } | |
103 return(0); | |
104 } | |
105 memset(device->hidden, 0, (sizeof *device->hidden)); | |
106 | |
107 /* Set the function pointers */ | |
108 device->VideoInit = BE_VideoInit; | |
109 device->ListModes = BE_ListModes; | |
110 device->SetVideoMode = BE_SetVideoMode; | |
111 device->UpdateMouse = BE_UpdateMouse; | |
112 device->SetColors = BE_SetColors; | |
113 device->UpdateRects = NULL; | |
114 device->VideoQuit = BE_VideoQuit; | |
115 device->AllocHWSurface = BE_AllocHWSurface; | |
116 device->CheckHWBlit = NULL; | |
117 device->FillHWRect = NULL; | |
118 device->SetHWColorKey = NULL; | |
119 device->SetHWAlpha = NULL; | |
120 device->LockHWSurface = BE_LockHWSurface; | |
121 device->UnlockHWSurface = BE_UnlockHWSurface; | |
122 device->FlipHWSurface = NULL; | |
123 device->FreeHWSurface = BE_FreeHWSurface; | |
124 #ifdef HAVE_OPENGL | |
125 device->GL_SwapBuffers = BE_GL_SwapBuffers; | |
126 #endif | |
127 device->SetIcon = NULL; | |
128 device->SetCaption = BE_SetWMCaption; | |
129 device->GetWMInfo = NULL; | |
130 device->FreeWMCursor = BE_FreeWMCursor; | |
131 device->CreateWMCursor = BE_CreateWMCursor; | |
132 device->ShowWMCursor = BE_ShowWMCursor; | |
133 device->WarpWMCursor = BE_WarpWMCursor; | |
134 device->InitOSKeymap = BE_InitOSKeymap; | |
135 device->PumpEvents = BE_PumpEvents; | |
136 | |
137 device->free = BE_DeleteDevice; | |
138 device->ToggleFullScreen = BE_ToggleFullScreen; | |
139 | |
140 /* Set the driver flags */ | |
141 device->handles_any_size = 1; | |
142 | |
143 return device; | |
144 } | |
145 | |
146 VideoBootStrap BWINDOW_bootstrap = { | |
147 "bwindow", "BDirectWindow graphics", | |
148 BE_Available, BE_CreateDevice | |
149 }; | |
150 | |
151 static inline int ColorSpaceToBitsPerPixel(uint32 colorspace) | |
152 { | |
153 int bitsperpixel; | |
154 | |
155 bitsperpixel = 0; | |
156 switch (colorspace) { | |
157 case B_CMAP8: | |
158 bitsperpixel = 8; | |
159 break; | |
160 case B_RGB15: | |
161 case B_RGBA15: | |
162 case B_RGB15_BIG: | |
163 case B_RGBA15_BIG: | |
164 bitsperpixel = 15; | |
165 break; | |
166 case B_RGB16: | |
167 case B_RGB16_BIG: | |
168 bitsperpixel = 16; | |
169 break; | |
170 case B_RGB32: | |
171 case B_RGBA32: | |
172 case B_RGB32_BIG: | |
173 case B_RGBA32_BIG: | |
174 bitsperpixel = 32; | |
175 break; | |
176 default: | |
177 break; | |
178 } | |
179 return(bitsperpixel); | |
180 } | |
181 | |
182 /* Function to sort the display_list in bscreen */ | |
183 static int CompareModes(const void *A, const void *B) | |
184 { | |
185 const display_mode *a = (display_mode *)A; | |
186 const display_mode *b = (display_mode *)B; | |
187 | |
188 if ( a->space == b->space ) { | |
189 return((b->virtual_width*b->virtual_height)- | |
190 (a->virtual_width*a->virtual_height)); | |
191 } else { | |
192 return(ColorSpaceToBitsPerPixel(b->space)- | |
193 ColorSpaceToBitsPerPixel(a->space)); | |
194 } | |
195 } | |
196 | |
197 /* Yes, this isn't the fastest it could be, but it works nicely */ | |
198 static int BE_AddMode(_THIS, int index, unsigned int w, unsigned int h) | |
199 { | |
200 SDL_Rect *mode; | |
201 int i; | |
202 int next_mode; | |
203 | |
204 /* Check to see if we already have this mode */ | |
205 if ( SDL_nummodes[index] > 0 ) { | |
206 for ( i=SDL_nummodes[index]-1; i >= 0; --i ) { | |
207 mode = SDL_modelist[index][i]; | |
208 if ( (mode->w == w) && (mode->h == h) ) { | |
209 #ifdef BWINDOW_DEBUG | |
210 fprintf(stderr, "We already have mode %dx%d at %d bytes per pixel\n", w, h, index+1); | |
211 #endif | |
212 return(0); | |
213 } | |
214 } | |
215 } | |
216 | |
217 /* Set up the new video mode rectangle */ | |
218 mode = (SDL_Rect *)malloc(sizeof *mode); | |
219 if ( mode == NULL ) { | |
220 SDL_OutOfMemory(); | |
221 return(-1); | |
222 } | |
223 mode->x = 0; | |
224 mode->y = 0; | |
225 mode->w = w; | |
226 mode->h = h; | |
227 #ifdef BWINDOW_DEBUG | |
228 fprintf(stderr, "Adding mode %dx%d at %d bytes per pixel\n", w, h, index+1); | |
229 #endif | |
230 | |
231 /* Allocate the new list of modes, and fill in the new mode */ | |
232 next_mode = SDL_nummodes[index]; | |
233 SDL_modelist[index] = (SDL_Rect **) | |
234 realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *)); | |
235 if ( SDL_modelist[index] == NULL ) { | |
236 SDL_OutOfMemory(); | |
237 SDL_nummodes[index] = 0; | |
238 free(mode); | |
239 return(-1); | |
240 } | |
241 SDL_modelist[index][next_mode] = mode; | |
242 SDL_modelist[index][next_mode+1] = NULL; | |
243 SDL_nummodes[index]++; | |
244 | |
245 return(0); | |
246 } | |
247 | |
248 int BE_VideoInit(_THIS, SDL_PixelFormat *vformat) | |
249 { | |
250 display_mode *modes; | |
251 uint32 i, nmodes; | |
252 int bpp; | |
253 BRect bounds; | |
254 | |
255 /* Initialize the Be Application for appserver interaction */ | |
256 if ( SDL_InitBeApp() < 0 ) { | |
257 return(-1); | |
258 } | |
259 | |
260 /* It is important that this be created after SDL_InitBeApp() */ | |
261 BScreen bscreen; | |
262 | |
263 /* Save the current display mode */ | |
264 bscreen.GetMode(&saved_mode); | |
265 | |
266 /* Determine the screen depth */ | |
267 vformat->BitsPerPixel = ColorSpaceToBitsPerPixel(bscreen.ColorSpace()); | |
268 if ( vformat->BitsPerPixel == 0 ) { | |
269 SDL_SetError("Unknown BScreen colorspace: 0x%x", | |
270 bscreen.ColorSpace()); | |
271 return(-1); | |
272 } | |
273 | |
274 /* Get the video modes we can switch to in fullscreen mode */ | |
275 bscreen.GetModeList(&modes, &nmodes); | |
276 qsort(modes, nmodes, sizeof *modes, CompareModes); | |
277 for ( i=0; i<nmodes; ++i ) { | |
278 bpp = ColorSpaceToBitsPerPixel(modes[i].space); | |
279 //if ( bpp != 0 ) { // There are bugs in changing colorspace | |
280 if ( modes[i].space == saved_mode.space ) { | |
281 BE_AddMode(_this, ((bpp+7)/8)-1, | |
282 modes[i].virtual_width, | |
283 modes[i].virtual_height); | |
284 } | |
285 } | |
286 | |
287 /* Create the window and view */ | |
288 bounds.top = 0; bounds.left = 0; | |
289 bounds.right = BEOS_HIDDEN_SIZE; | |
290 bounds.bottom = BEOS_HIDDEN_SIZE; | |
291 SDL_Win = new SDL_BWin(bounds); | |
292 | |
293 /* Create the clear cursor */ | |
294 SDL_BlankCursor = BE_CreateWMCursor(_this, blank_cdata, blank_cmask, | |
295 BLANK_CWIDTH, BLANK_CHEIGHT, BLANK_CHOTX, BLANK_CHOTY); | |
296 | |
297 /* Fill in some window manager capabilities */ | |
298 _this->info.wm_available = 1; | |
299 | |
300 /* We're done! */ | |
301 return(0); | |
302 } | |
303 | |
304 /* We support any dimension at our bit-depth */ | |
305 SDL_Rect **BE_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
306 { | |
307 SDL_Rect **modes; | |
308 | |
309 modes = ((SDL_Rect **)0); | |
310 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
311 modes = SDL_modelist[((format->BitsPerPixel+7)/8)-1]; | |
312 } else { | |
313 if ( format->BitsPerPixel == | |
314 _this->screen->format->BitsPerPixel ) { | |
315 modes = ((SDL_Rect **)-1); | |
316 } | |
317 } | |
318 return(modes); | |
319 } | |
320 | |
321 /* Various screen update functions available */ | |
322 static void BE_NormalUpdate(_THIS, int numrects, SDL_Rect *rects); | |
323 | |
324 | |
325 /* Find the closest display mode for fullscreen */ | |
326 static bool BE_FindClosestFSMode(_THIS, int width, int height, int bpp, | |
327 display_mode *mode) | |
328 { | |
329 BScreen bscreen; | |
330 uint32 i, nmodes; | |
331 SDL_Rect **modes; | |
332 display_mode *dmodes; | |
333 | |
334 modes = SDL_modelist[((bpp+7)/8)-1]; | |
335 for ( i=0; modes[i] && (modes[i]->w > width) && | |
336 (modes[i]->h > height); ++i ) { | |
337 /* still looking */ | |
338 } | |
339 if ( ! modes[i] || (modes[i]->w < width) || (modes[i]->h < width) ) { | |
340 --i; /* We went too far */ | |
341 } | |
342 width = modes[i]->w; | |
343 height = modes[i]->h; | |
344 bscreen.GetModeList(&dmodes, &nmodes); | |
345 for ( i = 0; i < nmodes; ++i ) { | |
346 if ( (bpp == ColorSpaceToBitsPerPixel(dmodes[i].space)) && | |
347 (width == dmodes[i].virtual_width) && | |
348 (height == dmodes[i].virtual_height) ) { | |
349 break; | |
350 } | |
351 } | |
352 if ( i != nmodes ) { | |
353 *mode = dmodes[i]; | |
354 return true; | |
355 } else { | |
356 return false; | |
357 } | |
358 } | |
359 | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
360 static int BE_SetFullScreen(_THIS, SDL_Surface *screen, int fullscreen) |
0 | 361 { |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
362 int was_fullscreen; |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
363 bool needs_unlock; |
0 | 364 BScreen bscreen; |
365 BRect bounds; | |
366 display_mode mode; | |
367 int width, height, bpp; | |
368 | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
369 /* Set the fullscreen mode */ |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
370 was_fullscreen = SDL_Win->IsFullScreen(); |
0 | 371 SDL_Win->SetFullScreen(fullscreen); |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
372 fullscreen = SDL_Win->IsFullScreen(); |
0 | 373 |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
374 width = screen->w; |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
375 height = screen->h; |
0 | 376 |
377 /* Set the appropriate video mode */ | |
378 if ( fullscreen ) { | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
379 bpp = screen->format->BitsPerPixel; |
0 | 380 bscreen.GetMode(&mode); |
381 if ( (bpp != ColorSpaceToBitsPerPixel(mode.space)) || | |
382 (width != mode.virtual_width) || | |
383 (height != mode.virtual_height)) { | |
384 if(BE_FindClosestFSMode(_this, width, height, bpp, &mode)) { | |
385 bscreen.SetMode(&mode); | |
386 /* This simply stops the next resize event from being | |
387 * sent to the SDL handler. | |
388 */ | |
389 SDL_Win->InhibitResize(); | |
390 } else { | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
391 fullscreen = 0; |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
392 SDL_Win->SetFullScreen(fullscreen); |
0 | 393 } |
394 } | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
395 } |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
396 if ( ! fullscreen ) { |
0 | 397 bscreen.SetMode(&saved_mode); |
398 } | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
399 |
0 | 400 if ( SDL_Win->Lock() ) { |
401 int xoff, yoff; | |
402 if ( SDL_Win->Shown() ) { | |
403 needs_unlock = 1; | |
404 SDL_Win->Hide(); | |
405 } else { | |
406 needs_unlock = 0; | |
407 } | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
408 /* This resizes the window and view area, but inhibits resizing |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
409 * of the BBitmap due to the InhibitResize call above. Thus the |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
410 * bitmap (pixel data) never changes. |
0 | 411 */ |
412 SDL_Win->ResizeTo(width, height); | |
413 bounds = bscreen.Frame(); | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
414 /* Calculate offsets - used either to center window |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
415 * (windowed mode) or to set drawing offsets (fullscreen mode) |
0 | 416 */ |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
417 xoff = (bounds.IntegerWidth() - width)/2; |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
418 yoff = (bounds.IntegerHeight() - height)/2; |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
419 if ( fullscreen ) { |
0 | 420 /* Set offset for drawing */ |
421 SDL_Win->SetXYOffset(xoff, yoff); | |
422 } else { | |
423 /* Center window and reset the drawing offset */ | |
424 SDL_Win->SetXYOffset(0, 0); | |
425 } | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
426 if ( ! needs_unlock || was_fullscreen ) { |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
427 /* Center the window the first time */ |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
428 SDL_Win->MoveTo(xoff > 0 ? (float)xoff : 0.0f, |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
429 yoff > 0 ? (float)yoff : 0.0f); |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
430 } |
0 | 431 SDL_Win->Show(); |
432 | |
433 /* Unlock the window manually after the first Show() */ | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
434 if ( needs_unlock ) { |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
435 SDL_Win->Unlock(); |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
436 } |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
437 } |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
438 |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
439 /* Set the fullscreen flag in the screen surface */ |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
440 if ( fullscreen ) { |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
441 screen->flags |= SDL_FULLSCREEN; |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
442 } else { |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
443 screen->flags &= ~SDL_FULLSCREEN; |
0 | 444 } |
445 return(1); | |
446 } | |
447 | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
448 static int BE_ToggleFullScreen(_THIS, int fullscreen) |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
449 { |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
450 return BE_SetFullScreen(_this, _this->screen, fullscreen); |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
451 } |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
452 |
0 | 453 /* FIXME: check return values and cleanup here */ |
454 SDL_Surface *BE_SetVideoMode(_THIS, SDL_Surface *current, | |
455 int width, int height, int bpp, Uint32 flags) | |
456 { | |
457 BScreen bscreen; | |
458 BBitmap *bbitmap; | |
459 BRect bounds; | |
460 | |
461 /* Create the view for this window */ | |
462 if ( SDL_Win->CreateView(flags) < 0 ) { | |
463 return(NULL); | |
464 } | |
465 | |
466 current->flags = 0; /* Clear flags */ | |
467 current->w = width; | |
468 current->h = height; | |
469 SDL_Win->SetType(B_TITLED_WINDOW); | |
470 if ( flags & SDL_NOFRAME ) { | |
471 current->flags |= SDL_NOFRAME; | |
472 SDL_Win->SetLook(B_NO_BORDER_WINDOW_LOOK); | |
473 } else { | |
474 if ( (flags & SDL_RESIZABLE) && !(flags & SDL_OPENGL) ) { | |
475 current->flags |= SDL_RESIZABLE; | |
476 /* We don't want opaque resizing (TM). :-) */ | |
477 SDL_Win->SetFlags(B_OUTLINE_RESIZE); | |
478 } else { | |
479 SDL_Win->SetFlags(B_NOT_RESIZABLE|B_NOT_ZOOMABLE); | |
480 } | |
481 } | |
482 | |
483 if ( flags & SDL_OPENGL ) { | |
484 current->flags |= SDL_OPENGL; | |
485 current->pitch = 0; | |
486 current->pixels = NULL; | |
487 _this->UpdateRects = NULL; | |
488 // _this->ToggleFullScreen = NULL; | |
489 } else { | |
490 /* Create the BBitmap framebuffer */ | |
491 bounds.top = 0; bounds.left = 0; | |
492 bounds.right = width-1; | |
493 bounds.bottom = height-1; | |
494 bbitmap = new BBitmap(bounds, bscreen.ColorSpace()); | |
495 if ( ! bbitmap->IsValid() ) { | |
496 SDL_SetError("Couldn't create screen bitmap"); | |
497 delete bbitmap; | |
498 return(NULL); | |
499 } | |
500 current->pitch = bbitmap->BytesPerRow(); | |
501 current->pixels = (void *)bbitmap->Bits(); | |
502 SDL_Win->SetBitmap(bbitmap); | |
503 _this->UpdateRects = BE_NormalUpdate; | |
504 } | |
505 | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
506 /* Set the correct fullscreen mode */ |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
507 BE_SetFullScreen(_this, current, flags & SDL_FULLSCREEN ? 1 : 0); |
0 | 508 |
509 /* We're done */ | |
510 return(current); | |
511 } | |
512 | |
513 /* Update the current mouse state and position */ | |
514 void BE_UpdateMouse(_THIS) | |
515 { | |
516 BPoint point; | |
517 uint32 buttons; | |
518 | |
519 if ( SDL_Win->Lock() ) { | |
520 /* Get new input state, if still active */ | |
521 if ( SDL_Win->IsActive() ) { | |
522 (SDL_Win->View())->GetMouse(&point, &buttons, true); | |
523 } else { | |
524 point.x = -1; | |
525 point.y = -1; | |
526 } | |
527 SDL_Win->Unlock(); | |
528 | |
529 if ( (point.x >= 0) && (point.x < SDL_VideoSurface->w) && | |
530 (point.y >= 0) && (point.y < SDL_VideoSurface->h) ) { | |
531 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); | |
532 SDL_PrivateMouseMotion(0, 0, | |
533 (Sint16)point.x, (Sint16)point.y); | |
534 } else { | |
535 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); | |
536 } | |
537 } | |
538 } | |
539 | |
540 /* We don't actually allow hardware surfaces other than the main one */ | |
541 static int BE_AllocHWSurface(_THIS, SDL_Surface *surface) | |
542 { | |
543 return(-1); | |
544 } | |
545 static void BE_FreeHWSurface(_THIS, SDL_Surface *surface) | |
546 { | |
547 return; | |
548 } | |
549 static int BE_LockHWSurface(_THIS, SDL_Surface *surface) | |
550 { | |
551 return(0); | |
552 } | |
553 static void BE_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
554 { | |
555 return; | |
556 } | |
557 | |
558 static void BE_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) | |
559 { | |
560 if ( SDL_Win->BeginDraw() ) { | |
561 int i; | |
562 | |
563 for ( i=0; i<numrects; ++i ) { | |
564 BRect rect; | |
565 | |
566 rect.top = rects[i].y; | |
567 rect.left = rects[i].x; | |
568 rect.bottom = rect.top+rects[i].h-1; | |
569 rect.right = rect.left+rects[i].w-1; | |
570 SDL_Win->DrawAsync(rect); | |
571 } | |
572 SDL_Win->EndDraw(); | |
573 } | |
574 } | |
575 | |
576 #ifdef HAVE_OPENGL | |
577 void BE_GL_SwapBuffers(_THIS) | |
578 { | |
579 SDL_Win->SwapBuffers(); | |
580 } | |
581 #endif | |
582 | |
583 /* Is the system palette settable? */ | |
584 int BE_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | |
585 { | |
586 int i; | |
587 SDL_Palette *palette; | |
588 const color_map *cmap = BScreen().ColorMap(); | |
589 | |
590 /* Get the screen colormap */ | |
591 palette = _this->screen->format->palette; | |
592 for ( i=0; i<256; ++i ) { | |
593 palette->colors[i].r = cmap->color_list[i].red; | |
594 palette->colors[i].g = cmap->color_list[i].green; | |
595 palette->colors[i].b = cmap->color_list[i].blue; | |
596 } | |
597 return(0); | |
598 } | |
599 | |
600 void BE_VideoQuit(_THIS) | |
601 { | |
602 int i, j; | |
603 | |
604 if ( SDL_BlankCursor != NULL ) { | |
605 BE_FreeWMCursor(_this, SDL_BlankCursor); | |
606 SDL_BlankCursor = NULL; | |
607 } | |
608 for ( i=0; i<NUM_MODELISTS; ++i ) { | |
609 if ( SDL_modelist[i] ) { | |
610 for ( j=0; SDL_modelist[i][j]; ++j ) { | |
611 free(SDL_modelist[i][j]); | |
612 } | |
613 free(SDL_modelist[i]); | |
614 SDL_modelist[i] = NULL; | |
615 } | |
616 } | |
617 /* Restore the original video mode */ | |
618 if ( _this->screen ) { | |
619 if ( (_this->screen->flags&SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
620 BScreen bscreen; | |
621 bscreen.SetMode(&saved_mode); | |
622 } | |
623 _this->screen->pixels = NULL; | |
624 } | |
625 SDL_QuitBeApp(); | |
626 } | |
627 | |
628 }; /* Extern C */ |