comparison src/video/nanox/SDL_nxvideo.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
38 #include "SDL_nxmouse_c.h" 38 #include "SDL_nxmouse_c.h"
39 #include "SDL_nximage_c.h" 39 #include "SDL_nximage_c.h"
40 #include "SDL_nxevents_c.h" 40 #include "SDL_nxevents_c.h"
41 41
42 // Initialization/Query functions 42 // Initialization/Query functions
43 static int NX_VideoInit (_THIS, SDL_PixelFormat * vformat); 43 static int NX_VideoInit(_THIS, SDL_PixelFormat * vformat);
44 static SDL_Surface *NX_SetVideoMode (_THIS, SDL_Surface * current, int width, 44 static SDL_Surface *NX_SetVideoMode(_THIS, SDL_Surface * current, int width,
45 int height, int bpp, Uint32 flags); 45 int height, int bpp, Uint32 flags);
46 static int NX_SetColors (_THIS, int firstcolor, int ncolors, 46 static int NX_SetColors(_THIS, int firstcolor, int ncolors,
47 SDL_Color * colors); 47 SDL_Color * colors);
48 static void NX_VideoQuit (_THIS); 48 static void NX_VideoQuit(_THIS);
49 static void NX_DestroyWindow (_THIS, SDL_Surface * screen); 49 static void NX_DestroyWindow(_THIS, SDL_Surface * screen);
50 static int NX_ToggleFullScreen (_THIS, int on); 50 static int NX_ToggleFullScreen(_THIS, int on);
51 static void NX_UpdateMouse (_THIS); 51 static void NX_UpdateMouse(_THIS);
52 static int NX_SetGammaRamp (_THIS, Uint16 * ramp); 52 static int NX_SetGammaRamp(_THIS, Uint16 * ramp);
53 static int NX_GetGammaRamp (_THIS, Uint16 * ramp); 53 static int NX_GetGammaRamp(_THIS, Uint16 * ramp);
54 54
55 // Microwin driver bootstrap functions 55 // Microwin driver bootstrap functions
56 static int 56 static int
57 NX_Available () 57 NX_Available()
58 { 58 {
59 Dprintf ("enter NX_Available\n"); 59 Dprintf("enter NX_Available\n");
60 60
61 if (GrOpen () < 0) 61 if (GrOpen() < 0)
62 return 0; 62 return 0;
63 GrClose (); 63 GrClose();
64 64
65 Dprintf ("leave NX_Available\n"); 65 Dprintf("leave NX_Available\n");
66 return 1; 66 return 1;
67 } 67 }
68 68
69 static void 69 static void
70 NX_DeleteDevice (SDL_VideoDevice * device) 70 NX_DeleteDevice(SDL_VideoDevice * device)
71 { 71 {
72 Dprintf ("enter NX_DeleteDevice\n"); 72 Dprintf("enter NX_DeleteDevice\n");
73 73
74 if (device) { 74 if (device) {
75 if (device->hidden) 75 if (device->hidden)
76 SDL_free (device->hidden); 76 SDL_free(device->hidden);
77 if (device->gl_data) 77 if (device->gl_data)
78 SDL_free (device->gl_data); 78 SDL_free(device->gl_data);
79 SDL_free (device); 79 SDL_free(device);
80 } 80 }
81 81
82 Dprintf ("leave NX_DeleteDevice\n"); 82 Dprintf("leave NX_DeleteDevice\n");
83 } 83 }
84 84
85 static SDL_VideoDevice * 85 static SDL_VideoDevice *
86 NX_CreateDevice (int devindex) 86 NX_CreateDevice(int devindex)
87 { 87 {
88 SDL_VideoDevice *device; 88 SDL_VideoDevice *device;
89 89
90 Dprintf ("enter NX_CreateDevice\n"); 90 Dprintf("enter NX_CreateDevice\n");
91 91
92 // Initialize all variables that we clean on shutdown 92 // Initialize all variables that we clean on shutdown
93 device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice)); 93 device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
94 if (device) { 94 if (device) {
95 SDL_memset (device, 0, (sizeof *device)); 95 SDL_memset(device, 0, (sizeof *device));
96 device->hidden = (struct SDL_PrivateVideoData *) 96 device->hidden = (struct SDL_PrivateVideoData *)
97 SDL_malloc ((sizeof *device->hidden)); 97 SDL_malloc((sizeof *device->hidden));
98 device->gl_data = NULL; 98 device->gl_data = NULL;
99 } 99 }
100 if ((device == NULL) || (device->hidden == NULL)) { 100 if ((device == NULL) || (device->hidden == NULL)) {
101 SDL_OutOfMemory (); 101 SDL_OutOfMemory();
102 NX_DeleteDevice (device); 102 NX_DeleteDevice(device);
103 return 0; 103 return 0;
104 } 104 }
105 SDL_memset (device->hidden, 0, (sizeof *device->hidden)); 105 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
106 106
107 // Set the function pointers 107 // Set the function pointers
108 device->VideoInit = NX_VideoInit; 108 device->VideoInit = NX_VideoInit;
109 device->ListModes = NX_ListModes; 109 device->ListModes = NX_ListModes;
110 device->SetVideoMode = NX_SetVideoMode; 110 device->SetVideoMode = NX_SetVideoMode;
149 device->InitOSKeymap = NX_InitOSKeymap; 149 device->InitOSKeymap = NX_InitOSKeymap;
150 device->PumpEvents = NX_PumpEvents; 150 device->PumpEvents = NX_PumpEvents;
151 151
152 device->free = NX_DeleteDevice; 152 device->free = NX_DeleteDevice;
153 153
154 Dprintf ("leave NX_CreateDevice\n"); 154 Dprintf("leave NX_CreateDevice\n");
155 return device; 155 return device;
156 } 156 }
157 157
158 VideoBootStrap NX_bootstrap = { 158 VideoBootStrap NX_bootstrap = {
159 "nanox", "nanox", NX_Available, NX_CreateDevice 159 "nanox", "nanox", NX_Available, NX_CreateDevice
160 }; 160 };
161 161
162 static void 162 static void
163 create_aux_windows (_THIS) 163 create_aux_windows(_THIS)
164 { 164 {
165 GR_WM_PROPERTIES props; 165 GR_WM_PROPERTIES props;
166 166
167 Dprintf ("enter create_aux_windows\n"); 167 Dprintf("enter create_aux_windows\n");
168 168
169 // Don't create any extra windows if we are being managed 169 // Don't create any extra windows if we are being managed
170 if (SDL_windowid) { 170 if (SDL_windowid) {
171 FSwindow = 0; 171 FSwindow = 0;
172 return; 172 return;
173 } 173 }
174 174
175 if (FSwindow && FSwindow != GR_ROOT_WINDOW_ID) { 175 if (FSwindow && FSwindow != GR_ROOT_WINDOW_ID) {
176 GrDestroyWindow (FSwindow); 176 GrDestroyWindow(FSwindow);
177 } 177 }
178 178
179 FSwindow = GrNewWindow (GR_ROOT_WINDOW_ID, 0, 0, 1, 1, 0, BLACK, BLACK); 179 FSwindow = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, 1, 1, 0, BLACK, BLACK);
180 props.flags = GR_WM_FLAGS_PROPS; 180 props.flags = GR_WM_FLAGS_PROPS;
181 props.props = GR_WM_PROPS_NODECORATE; 181 props.props = GR_WM_PROPS_NODECORATE;
182 GrSetWMProperties (FSwindow, &props); 182 GrSetWMProperties(FSwindow, &props);
183 183
184 GrSelectEvents (FSwindow, (GR_EVENT_MASK_EXPOSURE | 184 GrSelectEvents(FSwindow, (GR_EVENT_MASK_EXPOSURE |
185 GR_EVENT_MASK_BUTTON_DOWN | 185 GR_EVENT_MASK_BUTTON_DOWN |
186 GR_EVENT_MASK_BUTTON_UP | 186 GR_EVENT_MASK_BUTTON_UP |
187 GR_EVENT_MASK_FOCUS_IN | 187 GR_EVENT_MASK_FOCUS_IN |
188 GR_EVENT_MASK_FOCUS_OUT | 188 GR_EVENT_MASK_FOCUS_OUT |
189 GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP | 189 GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP |
190 GR_EVENT_MASK_MOUSE_ENTER | 190 GR_EVENT_MASK_MOUSE_ENTER |
191 GR_EVENT_MASK_MOUSE_EXIT | 191 GR_EVENT_MASK_MOUSE_EXIT |
192 GR_EVENT_MASK_MOUSE_MOTION | 192 GR_EVENT_MASK_MOUSE_MOTION |
193 GR_EVENT_MASK_UPDATE | 193 GR_EVENT_MASK_UPDATE |
194 GR_EVENT_MASK_CLOSE_REQ)); 194 GR_EVENT_MASK_CLOSE_REQ));
195 195
196 Dprintf ("leave create_aux_windows\n"); 196 Dprintf("leave create_aux_windows\n");
197 } 197 }
198 198
199 int 199 int
200 NX_VideoInit (_THIS, SDL_PixelFormat * vformat) 200 NX_VideoInit(_THIS, SDL_PixelFormat * vformat)
201 { 201 {
202 GR_SCREEN_INFO si; 202 GR_SCREEN_INFO si;
203 203
204 Dprintf ("enter NX_VideoInit\n"); 204 Dprintf("enter NX_VideoInit\n");
205 205
206 if (GrOpen () < 0) { 206 if (GrOpen() < 0) {
207 SDL_SetError ("GrOpen() fail"); 207 SDL_SetError("GrOpen() fail");
208 return -1; 208 return -1;
209 } 209 }
210 // use share memory to speed up 210 // use share memory to speed up
211 #ifdef NANOX_SHARE_MEMORY 211 #ifdef NANOX_SHARE_MEMORY
212 GrReqShmCmds (0xFFFF); 212 GrReqShmCmds(0xFFFF);
213 #endif 213 #endif
214 214
215 SDL_Window = 0; 215 SDL_Window = 0;
216 FSwindow = 0; 216 FSwindow = 0;
217 217
218 GammaRamp_R = NULL; 218 GammaRamp_R = NULL;
219 GammaRamp_G = NULL; 219 GammaRamp_G = NULL;
220 GammaRamp_B = NULL; 220 GammaRamp_B = NULL;
221 221
222 GrGetScreenInfo (&si); 222 GrGetScreenInfo(&si);
223 SDL_Visual.bpp = si.bpp; 223 SDL_Visual.bpp = si.bpp;
224 224
225 /* Determine the current screen size */ 225 /* Determine the current screen size */
226 this->info.current_w = si.cols; 226 this->info.current_w = si.cols;
227 this->info.current_h = si.rows; 227 this->info.current_h = si.rows;
228 228
229 // GetVideoMode 229 // GetVideoMode
230 SDL_modelist = (SDL_Rect **) SDL_malloc (sizeof (SDL_Rect *) * 2); 230 SDL_modelist = (SDL_Rect **) SDL_malloc(sizeof(SDL_Rect *) * 2);
231 if (SDL_modelist) { 231 if (SDL_modelist) {
232 SDL_modelist[0] = (SDL_Rect *) SDL_malloc (sizeof (SDL_Rect)); 232 SDL_modelist[0] = (SDL_Rect *) SDL_malloc(sizeof(SDL_Rect));
233 if (SDL_modelist[0]) { 233 if (SDL_modelist[0]) {
234 SDL_modelist[0]->x = 0; 234 SDL_modelist[0]->x = 0;
235 SDL_modelist[0]->y = 0; 235 SDL_modelist[0]->y = 0;
236 SDL_modelist[0]->w = si.cols; 236 SDL_modelist[0]->w = si.cols;
237 SDL_modelist[0]->h = si.rows; 237 SDL_modelist[0]->h = si.rows;
249 vformat->Rmask = SDL_Visual.red_mask; 249 vformat->Rmask = SDL_Visual.red_mask;
250 vformat->Gmask = SDL_Visual.green_mask; 250 vformat->Gmask = SDL_Visual.green_mask;
251 vformat->Bmask = SDL_Visual.blue_mask; 251 vformat->Bmask = SDL_Visual.blue_mask;
252 } 252 }
253 // See if we have been passed a window to use 253 // See if we have been passed a window to use
254 SDL_windowid = getenv ("SDL_WINDOWID"); 254 SDL_windowid = getenv("SDL_WINDOWID");
255 255
256 // Create the fullscreen (and managed windows : no implement) 256 // Create the fullscreen (and managed windows : no implement)
257 create_aux_windows (this); 257 create_aux_windows(this);
258 258
259 Dprintf ("leave NX_VideoInit\n"); 259 Dprintf("leave NX_VideoInit\n");
260 return 0; 260 return 0;
261 } 261 }
262 262
263 void 263 void
264 NX_VideoQuit (_THIS) 264 NX_VideoQuit(_THIS)
265 { 265 {
266 Dprintf ("enter NX_VideoQuit\n"); 266 Dprintf("enter NX_VideoQuit\n");
267 267
268 // Start shutting down the windows 268 // Start shutting down the windows
269 NX_DestroyImage (this, this->screen); 269 NX_DestroyImage(this, this->screen);
270 NX_DestroyWindow (this, this->screen); 270 NX_DestroyWindow(this, this->screen);
271 if (FSwindow && FSwindow != GR_ROOT_WINDOW_ID) { 271 if (FSwindow && FSwindow != GR_ROOT_WINDOW_ID) {
272 GrDestroyWindow (FSwindow); 272 GrDestroyWindow(FSwindow);
273 } 273 }
274 NX_FreeVideoModes (this); 274 NX_FreeVideoModes(this);
275 SDL_free (GammaRamp_R); 275 SDL_free(GammaRamp_R);
276 SDL_free (GammaRamp_G); 276 SDL_free(GammaRamp_G);
277 SDL_free (GammaRamp_B); 277 SDL_free(GammaRamp_B);
278 278
279 #ifdef ENABLE_NANOX_DIRECT_FB 279 #ifdef ENABLE_NANOX_DIRECT_FB
280 if (Clientfb) 280 if (Clientfb)
281 GrCloseClientFramebuffer (); 281 GrCloseClientFramebuffer();
282 #endif 282 #endif
283 GrClose (); 283 GrClose();
284 284
285 Dprintf ("leave NX_VideoQuit\n"); 285 Dprintf("leave NX_VideoQuit\n");
286 } 286 }
287 287
288 static void 288 static void
289 NX_DestroyWindow (_THIS, SDL_Surface * screen) 289 NX_DestroyWindow(_THIS, SDL_Surface * screen)
290 { 290 {
291 Dprintf ("enter NX_DestroyWindow\n"); 291 Dprintf("enter NX_DestroyWindow\n");
292 292
293 if (!SDL_windowid) { 293 if (!SDL_windowid) {
294 if (screen && (screen->flags & SDL_FULLSCREEN)) { 294 if (screen && (screen->flags & SDL_FULLSCREEN)) {
295 screen->flags &= ~SDL_FULLSCREEN; 295 screen->flags &= ~SDL_FULLSCREEN;
296 NX_LeaveFullScreen (this); 296 NX_LeaveFullScreen(this);
297 } 297 }
298 // Destroy the output window 298 // Destroy the output window
299 if (SDL_Window && SDL_Window != GR_ROOT_WINDOW_ID) { 299 if (SDL_Window && SDL_Window != GR_ROOT_WINDOW_ID) {
300 GrDestroyWindow (SDL_Window); 300 GrDestroyWindow(SDL_Window);
301 } 301 }
302 } 302 }
303 // Free the graphics context 303 // Free the graphics context
304 if (!SDL_GC) { 304 if (!SDL_GC) {
305 GrDestroyGC (SDL_GC); 305 GrDestroyGC(SDL_GC);
306 SDL_GC = 0; 306 SDL_GC = 0;
307 } 307 }
308 308
309 Dprintf ("leave NX_DestroyWindow\n"); 309 Dprintf("leave NX_DestroyWindow\n");
310 } 310 }
311 311
312 static int 312 static int
313 NX_CreateWindow (_THIS, SDL_Surface * screen, 313 NX_CreateWindow(_THIS, SDL_Surface * screen,
314 int w, int h, int bpp, Uint32 flags) 314 int w, int h, int bpp, Uint32 flags)
315 { 315 {
316 Dprintf ("enter NX_CreateWindow\n"); 316 Dprintf("enter NX_CreateWindow\n");
317 317
318 // If a window is already present, destroy it and start fresh 318 // If a window is already present, destroy it and start fresh
319 if (SDL_Window && SDL_Window != GR_ROOT_WINDOW_ID) { 319 if (SDL_Window && SDL_Window != GR_ROOT_WINDOW_ID) {
320 NX_DestroyWindow (this, screen); 320 NX_DestroyWindow(this, screen);
321 } 321 }
322 // See if we have been given a window id 322 // See if we have been given a window id
323 if (SDL_windowid) { 323 if (SDL_windowid) {
324 SDL_Window = SDL_strtol (SDL_windowid, NULL, 0); 324 SDL_Window = SDL_strtol(SDL_windowid, NULL, 0);
325 } else { 325 } else {
326 SDL_Window = 0; 326 SDL_Window = 0;
327 } 327 }
328 328
329 if (!SDL_ReallocFormat (screen, bpp, SDL_Visual.red_mask, 329 if (!SDL_ReallocFormat(screen, bpp, SDL_Visual.red_mask,
330 SDL_Visual.green_mask, SDL_Visual.blue_mask, 0)) 330 SDL_Visual.green_mask, SDL_Visual.blue_mask, 0))
331 return -1; 331 return -1;
332 332
333 // Create (or use) the nanox display window 333 // Create (or use) the nanox display window
334 if (!SDL_windowid) { 334 if (!SDL_windowid) {
335 335
336 SDL_Window = 336 SDL_Window =
337 GrNewWindow (GR_ROOT_WINDOW_ID, 0, 0, w, h, 0, BLACK, WHITE); 337 GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, w, h, 0, BLACK, WHITE);
338 338
339 GrSelectEvents (SDL_Window, (GR_EVENT_MASK_EXPOSURE | 339 GrSelectEvents(SDL_Window, (GR_EVENT_MASK_EXPOSURE |
340 GR_EVENT_MASK_BUTTON_DOWN | 340 GR_EVENT_MASK_BUTTON_DOWN |
341 GR_EVENT_MASK_BUTTON_UP | 341 GR_EVENT_MASK_BUTTON_UP |
342 GR_EVENT_MASK_FOCUS_IN | 342 GR_EVENT_MASK_FOCUS_IN |
343 GR_EVENT_MASK_FOCUS_OUT | 343 GR_EVENT_MASK_FOCUS_OUT |
344 GR_EVENT_MASK_KEY_DOWN | 344 GR_EVENT_MASK_KEY_DOWN |
345 GR_EVENT_MASK_KEY_UP | 345 GR_EVENT_MASK_KEY_UP |
346 GR_EVENT_MASK_MOUSE_ENTER | 346 GR_EVENT_MASK_MOUSE_ENTER |
347 GR_EVENT_MASK_MOUSE_EXIT | 347 GR_EVENT_MASK_MOUSE_EXIT |
348 GR_EVENT_MASK_MOUSE_MOTION | 348 GR_EVENT_MASK_MOUSE_MOTION |
349 GR_EVENT_MASK_UPDATE | 349 GR_EVENT_MASK_UPDATE |
350 GR_EVENT_MASK_CLOSE_REQ)); 350 GR_EVENT_MASK_CLOSE_REQ));
351 } 351 }
352 352
353 /* Create the graphics context here, once we have a window */ 353 /* Create the graphics context here, once we have a window */
354 SDL_GC = GrNewGC (); 354 SDL_GC = GrNewGC();
355 if (SDL_GC == 0) { 355 if (SDL_GC == 0) {
356 SDL_SetError ("Couldn't create graphics context"); 356 SDL_SetError("Couldn't create graphics context");
357 return (-1); 357 return (-1);
358 } 358 }
359 // Map them both and go fullscreen, if requested 359 // Map them both and go fullscreen, if requested
360 if (!SDL_windowid) { 360 if (!SDL_windowid) {
361 GrMapWindow (SDL_Window); 361 GrMapWindow(SDL_Window);
362 if (flags & SDL_FULLSCREEN) { 362 if (flags & SDL_FULLSCREEN) {
363 screen->flags |= SDL_FULLSCREEN; 363 screen->flags |= SDL_FULLSCREEN;
364 NX_EnterFullScreen (this); 364 NX_EnterFullScreen(this);
365 } else { 365 } else {
366 screen->flags &= ~SDL_FULLSCREEN; 366 screen->flags &= ~SDL_FULLSCREEN;
367 } 367 }
368 } 368 }
369 #ifdef ENABLE_NANOX_DIRECT_FB 369 #ifdef ENABLE_NANOX_DIRECT_FB
370 /* attempt allocating the client side framebuffer */ 370 /* attempt allocating the client side framebuffer */
371 Clientfb = GrOpenClientFramebuffer (); 371 Clientfb = GrOpenClientFramebuffer();
372 /* NULL return will default to using GrArea() */ 372 /* NULL return will default to using GrArea() */
373 #endif 373 #endif
374 374
375 Dprintf ("leave NX_CreateWindow\n"); 375 Dprintf("leave NX_CreateWindow\n");
376 return 0; 376 return 0;
377 } 377 }
378 378
379 SDL_Surface * 379 SDL_Surface *
380 NX_SetVideoMode (_THIS, SDL_Surface * current, 380 NX_SetVideoMode(_THIS, SDL_Surface * current,
381 int width, int height, int bpp, Uint32 flags) 381 int width, int height, int bpp, Uint32 flags)
382 { 382 {
383 Dprintf ("enter NX_SetVideoMode\n"); 383 Dprintf("enter NX_SetVideoMode\n");
384 384
385 // Lock the event thread, in multi-threading environments 385 // Lock the event thread, in multi-threading environments
386 SDL_Lock_EventThread (); 386 SDL_Lock_EventThread();
387 387
388 bpp = SDL_Visual.bpp; 388 bpp = SDL_Visual.bpp;
389 if (NX_CreateWindow (this, current, width, height, bpp, flags) < 0) { 389 if (NX_CreateWindow(this, current, width, height, bpp, flags) < 0) {
390 current = NULL; 390 current = NULL;
391 goto done; 391 goto done;
392 } 392 }
393 393
394 if (current->w != width || current->h != height) { 394 if (current->w != width || current->h != height) {
395 current->w = width; 395 current->w = width;
396 current->h = height; 396 current->h = height;
397 current->pitch = SDL_CalculatePitch (current); 397 current->pitch = SDL_CalculatePitch(current);
398 NX_ResizeImage (this, current, flags); 398 NX_ResizeImage(this, current, flags);
399 } 399 }
400 current->flags |= (flags & (SDL_RESIZABLE | SDL_NOFRAME)); 400 current->flags |= (flags & (SDL_RESIZABLE | SDL_NOFRAME));
401 401
402 done: 402 done:
403 SDL_Unlock_EventThread (); 403 SDL_Unlock_EventThread();
404 404
405 Dprintf ("leave NX_SetVideoMode\n"); 405 Dprintf("leave NX_SetVideoMode\n");
406 406
407 // We're done! 407 // We're done!
408 return current; 408 return current;
409 } 409 }
410 410
411 // ncolors <= 256 411 // ncolors <= 256
412 int 412 int
413 NX_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) 413 NX_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
414 { 414 {
415 int i; 415 int i;
416 GR_PALETTE pal; 416 GR_PALETTE pal;
417 417
418 Dprintf ("enter NX_SetColors\n"); 418 Dprintf("enter NX_SetColors\n");
419 419
420 if (ncolors > 256) 420 if (ncolors > 256)
421 return 0; 421 return 0;
422 422
423 pal.count = ncolors; 423 pal.count = ncolors;
424 for (i = 0; i < ncolors; ++i) { 424 for (i = 0; i < ncolors; ++i) {
425 pal.palette[i].r = colors[i].r; 425 pal.palette[i].r = colors[i].r;
426 pal.palette[i].g = colors[i].g; 426 pal.palette[i].g = colors[i].g;
427 pal.palette[i].b = colors[i].b; 427 pal.palette[i].b = colors[i].b;
428 } 428 }
429 GrSetSystemPalette (firstcolor, &pal); 429 GrSetSystemPalette(firstcolor, &pal);
430 430
431 Dprintf ("leave NX_SetColors\n"); 431 Dprintf("leave NX_SetColors\n");
432 return 1; 432 return 1;
433 } 433 }
434 434
435 static int 435 static int
436 NX_ToggleFullScreen (_THIS, int on) 436 NX_ToggleFullScreen(_THIS, int on)
437 { 437 {
438 SDL_Rect rect; 438 SDL_Rect rect;
439 Uint32 event_thread; 439 Uint32 event_thread;
440 440
441 Dprintf ("enter NX_ToggleFullScreen\n"); 441 Dprintf("enter NX_ToggleFullScreen\n");
442 442
443 // Don't switch if we don't own the window 443 // Don't switch if we don't own the window
444 if (SDL_windowid) 444 if (SDL_windowid)
445 return 0; 445 return 0;
446 446
447 // Don't lock if we are the event thread 447 // Don't lock if we are the event thread
448 event_thread = SDL_EventThreadID (); 448 event_thread = SDL_EventThreadID();
449 if (event_thread && (SDL_ThreadID () == event_thread)) { 449 if (event_thread && (SDL_ThreadID() == event_thread)) {
450 event_thread = 0; 450 event_thread = 0;
451 } 451 }
452 if (event_thread) { 452 if (event_thread) {
453 SDL_Lock_EventThread (); 453 SDL_Lock_EventThread();
454 } 454 }
455 455
456 if (on) { 456 if (on) {
457 NX_EnterFullScreen (this); 457 NX_EnterFullScreen(this);
458 } else { 458 } else {
459 this->screen->flags &= ~SDL_FULLSCREEN; 459 this->screen->flags &= ~SDL_FULLSCREEN;
460 NX_LeaveFullScreen (this); 460 NX_LeaveFullScreen(this);
461 } 461 }
462 462
463 rect.x = rect.y = 0; 463 rect.x = rect.y = 0;
464 rect.w = this->screen->w, rect.h = this->screen->h; 464 rect.w = this->screen->w, rect.h = this->screen->h;
465 NX_NormalUpdate (this, 1, &rect); 465 NX_NormalUpdate(this, 1, &rect);
466 466
467 if (event_thread) { 467 if (event_thread) {
468 SDL_Unlock_EventThread (); 468 SDL_Unlock_EventThread();
469 } 469 }
470 470
471 Dprintf ("leave NX_ToggleFullScreen\n"); 471 Dprintf("leave NX_ToggleFullScreen\n");
472 return 1; 472 return 1;
473 } 473 }
474 474
475 // Update the current mouse state and position 475 // Update the current mouse state and position
476 static void 476 static void
477 NX_UpdateMouse (_THIS) 477 NX_UpdateMouse(_THIS)
478 { 478 {
479 int x, y; 479 int x, y;
480 GR_WINDOW_INFO info; 480 GR_WINDOW_INFO info;
481 GR_SCREEN_INFO si; 481 GR_SCREEN_INFO si;
482 482
483 483
484 Dprintf ("enter NX_UpdateMouse\n"); 484 Dprintf("enter NX_UpdateMouse\n");
485 485
486 // Lock the event thread, in multi-threading environments 486 // Lock the event thread, in multi-threading environments
487 SDL_Lock_EventThread (); 487 SDL_Lock_EventThread();
488 488
489 GrGetScreenInfo (&si); 489 GrGetScreenInfo(&si);
490 GrGetWindowInfo (SDL_Window, &info); 490 GrGetWindowInfo(SDL_Window, &info);
491 x = si.xpos - info.x; 491 x = si.xpos - info.x;
492 y = si.ypos - info.y; 492 y = si.ypos - info.y;
493 if (x >= 0 && x <= info.width && y >= 0 && y <= info.height) { 493 if (x >= 0 && x <= info.width && y >= 0 && y <= info.height) {
494 SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS); 494 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
495 SDL_PrivateMouseMotion (0, 0, x, y); 495 SDL_PrivateMouseMotion(0, 0, x, y);
496 } else { 496 } else {
497 SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS); 497 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
498 } 498 }
499 499
500 SDL_Unlock_EventThread (); 500 SDL_Unlock_EventThread();
501 Dprintf ("leave NX_UpdateMouse\n"); 501 Dprintf("leave NX_UpdateMouse\n");
502 } 502 }
503 503
504 static int 504 static int
505 NX_SetGammaRamp (_THIS, Uint16 * ramp) 505 NX_SetGammaRamp(_THIS, Uint16 * ramp)
506 { 506 {
507 int i; 507 int i;
508 Uint16 *red, *green, *blue; 508 Uint16 *red, *green, *blue;
509 509
510 Dprintf ("enter NX_SetGammaRamp\n"); 510 Dprintf("enter NX_SetGammaRamp\n");
511 511
512 if (SDL_Visual.bpp != 32 && SDL_Visual.bpp != 24) 512 if (SDL_Visual.bpp != 32 && SDL_Visual.bpp != 24)
513 return -1; 513 return -1;
514 514
515 if (!GammaRamp_R) 515 if (!GammaRamp_R)
516 GammaRamp_R = (Uint16 *) SDL_malloc (sizeof (Uint16) * CI_SIZE); 516 GammaRamp_R = (Uint16 *) SDL_malloc(sizeof(Uint16) * CI_SIZE);
517 if (!GammaRamp_G) 517 if (!GammaRamp_G)
518 GammaRamp_G = (Uint16 *) SDL_malloc (sizeof (Uint16) * CI_SIZE); 518 GammaRamp_G = (Uint16 *) SDL_malloc(sizeof(Uint16) * CI_SIZE);
519 if (!GammaRamp_B) 519 if (!GammaRamp_B)
520 GammaRamp_B = (Uint16 *) SDL_malloc (sizeof (Uint16) * CI_SIZE); 520 GammaRamp_B = (Uint16 *) SDL_malloc(sizeof(Uint16) * CI_SIZE);
521 if ((!GammaRamp_R) || (!GammaRamp_G) || (!GammaRamp_B)) { 521 if ((!GammaRamp_R) || (!GammaRamp_G) || (!GammaRamp_B)) {
522 SDL_OutOfMemory (); 522 SDL_OutOfMemory();
523 return -1; 523 return -1;
524 } 524 }
525 525
526 for (i = 0; i < CI_SIZE; ++i) 526 for (i = 0; i < CI_SIZE; ++i)
527 GammaRamp_R[i] = GammaRamp_G[i] = GammaRamp_B[i] = i; 527 GammaRamp_R[i] = GammaRamp_G[i] = GammaRamp_B[i] = i;
533 for (i = 0; i < CI_SIZE; ++i) { 533 for (i = 0; i < CI_SIZE; ++i) {
534 GammaRamp_R[i] = red[i]; 534 GammaRamp_R[i] = red[i];
535 GammaRamp_G[i] = green[i]; 535 GammaRamp_G[i] = green[i];
536 GammaRamp_B[i] = blue[i]; 536 GammaRamp_B[i] = blue[i];
537 } 537 }
538 SDL_UpdateRect (this->screen, 0, 0, 0, 0); 538 SDL_UpdateRect(this->screen, 0, 0, 0, 0);
539 539
540 Dprintf ("leave NX_SetGammaRamp\n"); 540 Dprintf("leave NX_SetGammaRamp\n");
541 return 0; 541 return 0;
542 } 542 }
543 543
544 static int 544 static int
545 NX_GetGammaRamp (_THIS, Uint16 * ramp) 545 NX_GetGammaRamp(_THIS, Uint16 * ramp)
546 { 546 {
547 int i; 547 int i;
548 Uint16 *red, *green, *blue; 548 Uint16 *red, *green, *blue;
549 549
550 Dprintf ("enter NX_GetGammaRamp\n"); 550 Dprintf("enter NX_GetGammaRamp\n");
551 551
552 if (SDL_Visual.bpp != 32 && SDL_Visual.bpp != 24) 552 if (SDL_Visual.bpp != 32 && SDL_Visual.bpp != 24)
553 return -1; 553 return -1;
554 red = ramp; 554 red = ramp;
555 green = ramp + CI_SIZE; 555 green = ramp + CI_SIZE;
563 } else { 563 } else {
564 for (i = 0; i < CI_SIZE; ++i) 564 for (i = 0; i < CI_SIZE; ++i)
565 red[i] = green[i] = blue[i] = i; 565 red[i] = green[i] = blue[i] = i;
566 } 566 }
567 567
568 Dprintf ("leave NX_GetGammaRamp\n"); 568 Dprintf("leave NX_GetGammaRamp\n");
569 return 0; 569 return 0;
570 } 570 }
571 571
572 /* vi: set ts=4 sw=4 expandtab: */ 572 /* vi: set ts=4 sw=4 expandtab: */