brewpanel/sdlgui.c

changeset 638
186f0c2d3e76
parent 637
21e542c15832
equal deleted inserted replaced
637:21e542c15832 638:186f0c2d3e76
30 #ifdef HAVE_SDL2_SDL_H 30 #ifdef HAVE_SDL2_SDL_H
31 31
32 #include "lcdfont10x16.h" 32 #include "lcdfont10x16.h"
33 33
34 34
35 static SDL_Surface *pSdlGuiScrn; /* Pointer to the actual main SDL screen surface */ 35 extern SDL_Surface *S_screen; /* Pointer to the actual main SDL screen surface */
36 extern SDL_Window *S_window; /* Pointer to the actual window */
36 static SDL_Surface *pFontGfx = NULL; /* The LCD font graphics */ 37 static SDL_Surface *pFontGfx = NULL; /* The LCD font graphics */
37 static SDL_Surface *pBgSurface; /* Pointer to the application SDL screen surface */ 38 static SDL_Surface *pBgSurface; /* Pointer to the application SDL screen surface */
38 static SDL_Rect dlgrect, bgrect; 39 static SDL_Rect dlgrect, bgrect;
39 static int fontwidth, fontheight; /* Width & height of the actual font */ 40 static int fontwidth, fontheight; /* Width & height of the actual font */
40 TTF_Font *pFont = NULL; /* TTF font for buttons etc. */ 41 TTF_Font *pFont = NULL; /* TTF font for buttons etc. */
42 static Uint32 LCDbg1 = 0; /* LCD background light */ 43 static Uint32 LCDbg1 = 0; /* LCD background light */
43 44
44 extern int my_shutdown; 45 extern int my_shutdown;
45 extern int debug; 46 extern int debug;
46 47
47 extern SDL_Window *S_window;
48 48
49 /*-----------------------------------------------------------------------*/ 49 /*-----------------------------------------------------------------------*/
50 /* 50 /*
51 * Load an 1 plane XBM into a 8 planes SDL_Surface. 51 * Load an 1 plane XBM into a 8 planes SDL_Surface.
52 */ 52 */
159 } 159 }
160 160
161 161
162 162
163 /* 163 /*
164 * Inform the SDL-GUI about the actual SDL_Surface screen pointer and 164 * Prepare the font to suit the actual resolution.
165 * prepare the font to suit the actual resolution. 165 */
166 */ 166 int SDLGui_SetScreen(void)
167 int SDLGui_SetScreen(SDL_Surface *pScrn) 167 {
168 {
169 pSdlGuiScrn = pScrn;
170
171 if (pFontGfx == NULL) { 168 if (pFontGfx == NULL) {
172 syslog(LOG_NOTICE, "Error: A problem with the font occured!"); 169 syslog(LOG_NOTICE, "Error: A problem with the font occured!");
173 return -1; 170 return -1;
174 } 171 }
175 172
187 * Note: We only store the coordinates in the root box of the dialog, 184 * Note: We only store the coordinates in the root box of the dialog,
188 * all other objects in the dialog are positioned relatively to this one. 185 * all other objects in the dialog are positioned relatively to this one.
189 */ 186 */
190 void SDLGui_CenterDlg(SGOBJ *dlg) 187 void SDLGui_CenterDlg(SGOBJ *dlg)
191 { 188 {
192 dlg[0].x = (pSdlGuiScrn->w/1-dlg[0].w)/2; 189 dlg[0].x = (S_screen->w/1-dlg[0].w)/2;
193 dlg[0].y = (pSdlGuiScrn->h/1-dlg[0].h)/2; 190 dlg[0].y = (S_screen->h/1-dlg[0].h)/2;
194 } 191 }
195 192
196 193
197 194
198 /* 195 /*
205 SDL_Surface* message = NULL; 202 SDL_Surface* message = NULL;
206 203
207 message = TTF_RenderText_Solid(pFont, txt, textColor); 204 message = TTF_RenderText_Solid(pFont, txt, textColor);
208 offset.x = x; 205 offset.x = x;
209 offset.y = y; 206 offset.y = y;
210 SDL_BlitSurface(message, NULL, pSdlGuiScrn, &offset); 207 SDL_BlitSurface(message, NULL, S_screen, &offset);
211 SDL_FreeSurface(message); 208 SDL_FreeSurface(message);
212 message = NULL; 209 message = NULL;
213 } 210 }
214 211
215 212
232 * Draw the cursor 229 * Draw the cursor
233 */ 230 */
234 void SDLGui_Cursor(SGOBJ *dlg, int fd, int x, int y, int on, int blink) 231 void SDLGui_Cursor(SGOBJ *dlg, int fd, int x, int y, int on, int blink)
235 { 232 {
236 SDL_Rect dr; 233 SDL_Rect dr;
237 Uint32 color = SDL_MapRGB(pSdlGuiScrn->format, 53, 59, 61); 234 Uint32 color = SDL_MapRGB(S_screen->format, 53, 59, 61);
238 235
239 if (on) { 236 if (on) {
240 dr.x = x; 237 dr.x = x;
241 dr.y = y + fontheight - 2; 238 dr.y = y + fontheight - 2;
242 dr.w = fontwidth; 239 dr.w = fontwidth;
243 dr.h = 2; 240 dr.h = 2;
244 241
245 SDL_FillRect(pSdlGuiScrn, &dr, color); 242 SDL_FillRect(S_screen, &dr, color);
246 // SDL_UpdateRect(pSdlGuiScrn, x, y, fontwidth, fontheight); 243 SDL_UpdateWindowSurface(S_window);
247 } 244 }
248 } 245 }
249 246
250 247
251 248
286 dstbits += dstpitch; 283 dstbits += dstpitch;
287 } 284 }
288 i++; 285 i++;
289 } 286 }
290 287
291 // SDL_SetColors(CGchar, blackWhiteColors, 0, 2); 288 SDL_SetPaletteColors(CGchar->format->palette, blackWhiteColors, 0, 2);
292 SDL_SetColorKey(CGchar, SDL_RLEACCEL, 0); 289 SDL_SetColorKey(CGchar, SDL_RLEACCEL, 0);
293 bg = LCDbg0; 290 if (dlg[1].state & SG_SELECTED) {
291 bg = LCDbg1;
292 } else {
293 bg = LCDbg0;
294 }
294 295
295 sr.x = sr.y = 0; 296 sr.x = sr.y = 0;
296 dr.x = x; 297 dr.x = x;
297 dr.y = y; 298 dr.y = y;
298 sr.w = dr.w = fontwidth; 299 sr.w = dr.w = fontwidth;
299 sr.h = dr.h = fontheight; 300 sr.h = dr.h = fontheight;
300 301
301 SDL_FillRect(pSdlGuiScrn, &dr, bg); 302 SDL_FillRect(S_screen, &dr, bg);
302 SDL_BlitSurface(CGchar, &sr, pSdlGuiScrn, &dr); 303 SDL_BlitSurface(CGchar, &sr, S_screen, &dr);
303 //SDL_UpdateRect(pSdlGuiScrn, x, y, fontwidth, fontheight);
304 SDL_UpdateWindowSurface(S_window); 304 SDL_UpdateWindowSurface(S_window);
305 SDL_FreeSurface(CGchar); 305 SDL_FreeSurface(CGchar);
306 } 306 }
307 307
308 308
313 void SDLGui_Char(SGOBJ *dlg, int fd, int x, int y, Uint8 c) 313 void SDLGui_Char(SGOBJ *dlg, int fd, int x, int y, Uint8 c)
314 { 314 {
315 SDL_Rect sr, dr; 315 SDL_Rect sr, dr;
316 Uint32 bg; 316 Uint32 bg;
317 317
318 // if (dlg[1].state & SG_SELECTED) { 318 if (dlg[1].state & SG_SELECTED) {
319 // bg = LCDbg1; 319 bg = LCDbg1;
320 // } else { 320 } else {
321 bg = LCDbg0; 321 bg = LCDbg0;
322 // } 322 }
323 323
324 sr.x=fontwidth*(c%16); 324 sr.x=fontwidth*(c%16);
325 sr.y=fontheight*(c/16); 325 sr.y=fontheight*(c/16);
326 sr.w=fontwidth; 326 sr.w=fontwidth;
327 sr.h=fontheight; 327 sr.h=fontheight;
328 dr.x=x; 328 dr.x=x;
329 dr.y=y; 329 dr.y=y;
330 dr.w=fontwidth; 330 dr.w=fontwidth;
331 dr.h=fontheight; 331 dr.h=fontheight;
332 332
333 SDL_FillRect(pSdlGuiScrn, &dr, bg); 333 SDL_FillRect(S_screen, &dr, bg);
334 SDL_BlitSurface(pFontGfx, &sr, pSdlGuiScrn, &dr); 334 SDL_BlitSurface(pFontGfx, &sr, S_screen, &dr);
335 // SDL_UpdateRect(pSdlGuiScrn, x, y, fontwidth, fontheight);
336 SDL_UpdateWindowSurface(S_window); 335 SDL_UpdateWindowSurface(S_window);
337 } 336 }
338 337
339 338
340 339
355 sr.h=fontheight; 354 sr.h=fontheight;
356 dr.x=x+i*(fontwidth+2); 355 dr.x=x+i*(fontwidth+2);
357 dr.y=y; 356 dr.y=y;
358 dr.w=fontwidth; 357 dr.w=fontwidth;
359 dr.h=fontheight; 358 dr.h=fontheight;
360 SDL_BlitSurface(pFontGfx, &sr, pSdlGuiScrn, &dr); 359 SDL_BlitSurface(pFontGfx, &sr, S_screen, &dr);
361 } 360 }
362 } 361 }
363 362
364 363
365 364
382 */ 381 */
383 void SDLGui_DrawLCD(SGOBJ *bdlg, int objnum) 382 void SDLGui_DrawLCD(SGOBJ *bdlg, int objnum)
384 { 383 {
385 SDL_Rect rect; 384 SDL_Rect rect;
386 int x, y, w, h, offset, border = 4; 385 int x, y, w, h, offset, border = 4;
387 Uint32 bc = SDL_MapRGB(pSdlGuiScrn->format, 32, 32, 32); 386 Uint32 bc = SDL_MapRGB(S_screen->format, 32, 32, 32);
388 Uint32 bg; 387 Uint32 bg;
389 388
390 LCDbg0 = SDL_MapRGB(pSdlGuiScrn->format, 94,147, 69); 389 LCDbg0 = SDL_MapRGB(S_screen->format, 94,147, 69);
391 LCDbg1 = SDL_MapRGB(pSdlGuiScrn->format,156,235, 4); 390 LCDbg1 = SDL_MapRGB(S_screen->format,156,235, 4);
392 /* 391 /*
393 * Width and height are given in character columns and rows, 392 * Width and height are given in character columns and rows,
394 * so calculate the display size in pixels. 393 * so calculate the display size in pixels.
395 */ 394 */
396 w = bdlg[objnum].w * (fontwidth + 2) + 10; 395 w = bdlg[objnum].w * (fontwidth + 2) + 10;
409 /* we have to look for it now here and only */ 408 /* we have to look for it now here and only */
410 x += bdlg[0].x; /* add its absolute coordinates if we need to */ 409 x += bdlg[0].x; /* add its absolute coordinates if we need to */
411 y += bdlg[0].y; 410 y += bdlg[0].y;
412 } 411 }
413 412
414 // if (bdlg[objnum].state & SG_SELECTED) { 413 if (bdlg[objnum].state & SG_SELECTED) {
415 // bg = LCDbg1; 414 bg = LCDbg1;
416 // } else { 415 } else {
417 bg = LCDbg0; 416 bg = LCDbg0;
418 // } 417 }
419 418
420 /* The root box should be bigger than the screen, so we disable the offset there: */ 419 /* The root box should be bigger than the screen, so we disable the offset there: */
421 if (objnum != 0) 420 if (objnum != 0)
422 offset = border; 421 offset = border;
423 else 422 else
426 /* Draw background: */ 425 /* Draw background: */
427 rect.x = x; 426 rect.x = x;
428 rect.y = y; 427 rect.y = y;
429 rect.w = w; 428 rect.w = w;
430 rect.h = h; 429 rect.h = h;
431 SDL_FillRect(pSdlGuiScrn, &rect, bg); 430 SDL_FillRect(S_screen, &rect, bg);
432 431
433 /* Draw upper border: */ 432 /* Draw upper border: */
434 rect.x = x - offset; 433 rect.x = x - offset;
435 rect.y = y - offset; 434 rect.y = y - offset;
436 rect.w = w + offset + offset; 435 rect.w = w + offset + offset;
437 rect.h = border; 436 rect.h = border;
438 SDL_FillRect(pSdlGuiScrn, &rect, bc); 437 SDL_FillRect(S_screen, &rect, bc);
439 438
440 /* Draw left border: */ 439 /* Draw left border: */
441 rect.x = x - offset; 440 rect.x = x - offset;
442 rect.y = y; 441 rect.y = y;
443 rect.w = border; 442 rect.w = border;
444 rect.h = h; 443 rect.h = h;
445 SDL_FillRect(pSdlGuiScrn, &rect, bc); 444 SDL_FillRect(S_screen, &rect, bc);
446 445
447 /* Draw bottom border: */ 446 /* Draw bottom border: */
448 rect.x = x - offset; 447 rect.x = x - offset;
449 rect.y = y + h - border + offset; 448 rect.y = y + h - border + offset;
450 rect.w = w + offset + offset; 449 rect.w = w + offset + offset;
451 rect.h = border; 450 rect.h = border;
452 SDL_FillRect(pSdlGuiScrn, &rect, bc); 451 SDL_FillRect(S_screen, &rect, bc);
453 452
454 /* Draw right border: */ 453 /* Draw right border: */
455 rect.x = x + w - border + offset; 454 rect.x = x + w - border + offset;
456 rect.y = y; 455 rect.y = y;
457 rect.w = border; 456 rect.w = border;
458 rect.h = h; 457 rect.h = h;
459 SDL_FillRect(pSdlGuiScrn, &rect, bc); 458 SDL_FillRect(S_screen, &rect, bc);
460 } 459 }
461 460
462 461
463 462
464 /* 463 /*
466 */ 465 */
467 static void SDLGui_DrawBox(const SGOBJ *bdlg, int objnum) 466 static void SDLGui_DrawBox(const SGOBJ *bdlg, int objnum)
468 { 467 {
469 SDL_Rect rect; 468 SDL_Rect rect;
470 int x, y, w, h, offset, shade = 2; 469 int x, y, w, h, offset, shade = 2;
471 Uint32 grey = SDL_MapRGB(pSdlGuiScrn->format,192,192,192); 470 Uint32 grey = SDL_MapRGB(S_screen->format,192,192,192);
472 Uint32 upleftc, downrightc; 471 Uint32 upleftc, downrightc;
473 472
474 x = bdlg[objnum].x; 473 x = bdlg[objnum].x;
475 y = bdlg[objnum].y; 474 y = bdlg[objnum].y;
476 if (objnum > 0) { /* Since the root object is a box, too, */ 475 if (objnum > 0) { /* Since the root object is a box, too, */
480 } 479 }
481 w = bdlg[objnum].w; 480 w = bdlg[objnum].w;
482 h = bdlg[objnum].h; 481 h = bdlg[objnum].h;
483 482
484 if (bdlg[objnum].state & SG_SELECTED) { 483 if (bdlg[objnum].state & SG_SELECTED) {
485 upleftc = SDL_MapRGB(pSdlGuiScrn->format,128,128,128); 484 upleftc = SDL_MapRGB(S_screen->format,128,128,128);
486 downrightc = SDL_MapRGB(pSdlGuiScrn->format,255,255,255); 485 downrightc = SDL_MapRGB(S_screen->format,255,255,255);
487 } else { 486 } else {
488 upleftc = SDL_MapRGB(pSdlGuiScrn->format,255,255,255); 487 upleftc = SDL_MapRGB(S_screen->format,255,255,255);
489 downrightc = SDL_MapRGB(pSdlGuiScrn->format,128,128,128); 488 downrightc = SDL_MapRGB(S_screen->format,128,128,128);
490 } 489 }
491 490
492 /* The root box should be bigger than the screen, so we disable the offset there: */ 491 /* The root box should be bigger than the screen, so we disable the offset there: */
493 if (objnum != 0) 492 if (objnum != 0)
494 offset = shade; 493 offset = shade;
498 /* Draw background: */ 497 /* Draw background: */
499 rect.x = x; 498 rect.x = x;
500 rect.y = y; 499 rect.y = y;
501 rect.w = w; 500 rect.w = w;
502 rect.h = h; 501 rect.h = h;
503 SDL_FillRect(pSdlGuiScrn, &rect, grey); 502 SDL_FillRect(S_screen, &rect, grey);
504 503
505 /* Draw upper border: */ 504 /* Draw upper border: */
506 rect.x = x; 505 rect.x = x;
507 rect.y = y - offset; 506 rect.y = y - offset;
508 rect.w = w; 507 rect.w = w;
509 rect.h = shade; 508 rect.h = shade;
510 SDL_FillRect(pSdlGuiScrn, &rect, upleftc); 509 SDL_FillRect(S_screen, &rect, upleftc);
511 510
512 /* Draw left border: */ 511 /* Draw left border: */
513 rect.x = x - offset; 512 rect.x = x - offset;
514 rect.y = y; 513 rect.y = y;
515 rect.w = shade; 514 rect.w = shade;
516 rect.h = h; 515 rect.h = h;
517 SDL_FillRect(pSdlGuiScrn, &rect, upleftc); 516 SDL_FillRect(S_screen, &rect, upleftc);
518 517
519 /* Draw bottom border: */ 518 /* Draw bottom border: */
520 rect.x = x; 519 rect.x = x;
521 rect.y = y + h - shade + offset; 520 rect.y = y + h - shade + offset;
522 rect.w = w; 521 rect.w = w;
523 rect.h = shade; 522 rect.h = shade;
524 SDL_FillRect(pSdlGuiScrn, &rect, downrightc); 523 SDL_FillRect(S_screen, &rect, downrightc);
525 524
526 /* Draw right border: */ 525 /* Draw right border: */
527 rect.x = x + w - shade + offset; 526 rect.x = x + w - shade + offset;
528 rect.y = y; 527 rect.y = y;
529 rect.w = shade; 528 rect.w = shade;
530 rect.h = h; 529 rect.h = h;
531 SDL_FillRect(pSdlGuiScrn, &rect, downrightc); 530 SDL_FillRect(S_screen, &rect, downrightc);
532 } 531 }
533 532
534 533
535 534
536 /* 535 /*
618 static void SDLGUI_DrawLEDRed(const SGOBJ *bdlg, int objnum) 617 static void SDLGUI_DrawLEDRed(const SGOBJ *bdlg, int objnum)
619 { 618 {
620 Uint32 color; 619 Uint32 color;
621 620
622 if (bdlg[objnum].state & SG_SELECTED) { 621 if (bdlg[objnum].state & SG_SELECTED) {
623 color = SDL_MapRGB(pSdlGuiScrn->format, 255, 64, 0); 622 color = SDL_MapRGB(S_screen->format, 255, 64, 0);
624 } else { 623 } else {
625 color = SDL_MapRGB(pSdlGuiScrn->format, 128, 16, 0); 624 color = SDL_MapRGB(S_screen->format, 128, 16, 0);
626 } 625 }
627 SDLGui_fill_circle(pSdlGuiScrn, bdlg[objnum].x, bdlg[objnum].y, bdlg[objnum].w, color); 626 SDLGui_fill_circle(S_screen, bdlg[objnum].x, bdlg[objnum].y, bdlg[objnum].w, color);
628 } 627 }
629 628
630 629
631 630
632 static void SDLGUI_DrawLEDBlue(const SGOBJ *bdlg, int objnum) 631 static void SDLGUI_DrawLEDBlue(const SGOBJ *bdlg, int objnum)
633 { 632 {
634 Uint32 color; 633 Uint32 color;
635 634
636 if (bdlg[objnum].state & SG_SELECTED) { 635 if (bdlg[objnum].state & SG_SELECTED) {
637 color = SDL_MapRGB(pSdlGuiScrn->format, 64, 160, 255); 636 color = SDL_MapRGB(S_screen->format, 64, 160, 255);
638 } else { 637 } else {
639 color = SDL_MapRGB(pSdlGuiScrn->format, 16, 48, 112); 638 color = SDL_MapRGB(S_screen->format, 16, 48, 112);
640 } 639 }
641 SDLGui_fill_circle(pSdlGuiScrn, bdlg[objnum].x, bdlg[objnum].y, bdlg[objnum].w, color); 640 SDLGui_fill_circle(S_screen, bdlg[objnum].x, bdlg[objnum].y, bdlg[objnum].w, color);
642 } 641 }
643 642
644 643
645 644
646 static void SDLGUI_DrawLEDGreen(const SGOBJ *bdlg, int objnum) 645 static void SDLGUI_DrawLEDGreen(const SGOBJ *bdlg, int objnum)
647 { 646 {
648 Uint32 color; 647 Uint32 color;
649 648
650 if (bdlg[objnum].state & SG_SELECTED) { 649 if (bdlg[objnum].state & SG_SELECTED) {
651 color = SDL_MapRGB(pSdlGuiScrn->format, 80, 240, 0); 650 color = SDL_MapRGB(S_screen->format, 80, 240, 0);
652 } else { 651 } else {
653 color = SDL_MapRGB(pSdlGuiScrn->format, 32, 112, 0); 652 color = SDL_MapRGB(S_screen->format, 32, 112, 0);
654 } 653 }
655 SDLGui_fill_circle(pSdlGuiScrn, bdlg[objnum].x, bdlg[objnum].y, bdlg[objnum].w, color); 654 SDLGui_fill_circle(S_screen, bdlg[objnum].x, bdlg[objnum].y, bdlg[objnum].w, color);
656 } 655 }
657 656
658 657
659 658
660 static void SDLGUI_DrawLEDYellow(const SGOBJ *bdlg, int objnum) 659 static void SDLGUI_DrawLEDYellow(const SGOBJ *bdlg, int objnum)
661 { 660 {
662 Uint32 color; 661 Uint32 color;
663 662
664 if (bdlg[objnum].state & SG_SELECTED) { 663 if (bdlg[objnum].state & SG_SELECTED) {
665 color = SDL_MapRGB(pSdlGuiScrn->format, 255, 255, 0); 664 color = SDL_MapRGB(S_screen->format, 255, 255, 0);
666 } else { 665 } else {
667 color = SDL_MapRGB(pSdlGuiScrn->format, 160, 144, 0); 666 color = SDL_MapRGB(S_screen->format, 160, 144, 0);
668 } 667 }
669 SDLGui_fill_circle(pSdlGuiScrn, bdlg[objnum].x, bdlg[objnum].y, bdlg[objnum].w, color); 668 SDLGui_fill_circle(S_screen, bdlg[objnum].x, bdlg[objnum].y, bdlg[objnum].w, color);
670 } 669 }
671 670
672 671
673 672
674 void SDLGui_LED(SGOBJ *dlg, int fd, int LED, int on) 673 void SDLGui_LED(SGOBJ *dlg, int fd, int LED, int on)
697 case SGLEDYELLOW: 696 case SGLEDYELLOW:
698 SDLGUI_DrawLEDYellow(dlg, i); 697 SDLGUI_DrawLEDYellow(dlg, i);
699 break; 698 break;
700 } 699 }
701 SDL_UpdateWindowSurface(S_window); 700 SDL_UpdateWindowSurface(S_window);
702 //SDL_UpdateRect(pSdlGuiScrn, dlg[i].x - dlg[i].w, dlg[i].y - dlg[i].w, dlg[i].w * 2, dlg[i].w * 2);
703 } 701 }
704 } 702 }
705 } 703 }
706 704
707 705
744 break; 742 break;
745 } 743 }
746 } 744 }
747 745
748 SDL_UpdateWindowSurface(S_window); 746 SDL_UpdateWindowSurface(S_window);
749 // SDL_UpdateRect(pSdlGuiScrn, 0,0,0,0);
750 } 747 }
751 748
752 749
753 750
754 /* 751 /*
781 /* 778 /*
782 * Show dialog. 779 * Show dialog.
783 */ 780 */
784 int SDLGui_DoDialogInit(SGOBJ *dlg) 781 int SDLGui_DoDialogInit(SGOBJ *dlg)
785 { 782 {
786 if ((pSdlGuiScrn->h < dlg[0].h) && (pSdlGuiScrn->w < dlg[0].w)) { 783 if ((S_screen->h < dlg[0].h) && (S_screen->w < dlg[0].w)) {
787 syslog(LOG_NOTICE, "Screen size too small for dialog!"); 784 syslog(LOG_NOTICE, "Screen size too small for dialog!");
788 return SDLGUI_ERROR; 785 return SDLGUI_ERROR;
789 } 786 }
790 787
791 dlgrect.x = dlg[0].x; 788 dlgrect.x = dlg[0].x;
798 bgrect.h = dlgrect.h; 795 bgrect.h = dlgrect.h;
799 796
800 /* 797 /*
801 * Save background 798 * Save background
802 */ 799 */
803 pBgSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, dlgrect.w, dlgrect.h, pSdlGuiScrn->format->BitsPerPixel, 800 pBgSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, dlgrect.w, dlgrect.h, S_screen->format->BitsPerPixel,
804 pSdlGuiScrn->format->Rmask, pSdlGuiScrn->format->Gmask, pSdlGuiScrn->format->Bmask, pSdlGuiScrn->format->Amask); 801 S_screen->format->Rmask, S_screen->format->Gmask, S_screen->format->Bmask, S_screen->format->Amask);
805 if (pSdlGuiScrn->format->palette != NULL) { 802 if (S_screen->format->palette != NULL) {
806 SDL_SetPaletteColors(pBgSurface->format->palette, pSdlGuiScrn->format->palette->colors, 0, pSdlGuiScrn->format->palette->ncolors-1); 803 SDL_SetPaletteColors(pBgSurface->format->palette, S_screen->format->palette->colors, 0, S_screen->format->palette->ncolors-1);
807 } 804 }
808 805
809 if (pBgSurface != NULL) { 806 if (pBgSurface != NULL) {
810 SDL_BlitSurface(pSdlGuiScrn, &dlgrect, pBgSurface, &bgrect); 807 SDL_BlitSurface(S_screen, &dlgrect, pBgSurface, &bgrect);
811 } else { 808 } else {
812 syslog(LOG_NOTICE, "SDLGUI_DoDialog: CreateRGBSurface failed: %s", SDL_GetError()); 809 syslog(LOG_NOTICE, "SDLGUI_DoDialog: CreateRGBSurface failed: %s", SDL_GetError());
813 } 810 }
814 811
815 /* (Re-)draw the dialog */ 812 /* (Re-)draw the dialog */
851 if (obj > 0) { 848 if (obj > 0) {
852 if (dlg[obj].type == SGBUTTON) { 849 if (dlg[obj].type == SGBUTTON) {
853 dlg[obj].state |= SG_SELECTED; 850 dlg[obj].state |= SG_SELECTED;
854 SDLGui_DrawButton(dlg, obj); 851 SDLGui_DrawButton(dlg, obj);
855 SDL_UpdateWindowSurface(S_window); 852 SDL_UpdateWindowSurface(S_window);
856 //SDL_UpdateRect(pSdlGuiScrn, dlg[0].x + dlg[obj].x - 2, dlg[0].y + dlg[obj].y - 2, dlg[obj].w + 4, dlg[obj].h + 4); 853 //SDL_UpdateRect(S_screen, dlg[0].x + dlg[obj].x - 2, dlg[0].y + dlg[obj].y - 2, dlg[obj].w + 4, dlg[obj].h + 4);
857 retbutton = obj + 1000; 854 retbutton = obj + 1000;
858 } 855 }
859 } 856 }
860 break; 857 break;
861 858
869 if (obj > 0) { 866 if (obj > 0) {
870 if (dlg[obj].type == SGBUTTON) { 867 if (dlg[obj].type == SGBUTTON) {
871 dlg[obj].state &= ~SG_SELECTED; 868 dlg[obj].state &= ~SG_SELECTED;
872 SDLGui_DrawButton(dlg, obj); 869 SDLGui_DrawButton(dlg, obj);
873 SDL_UpdateWindowSurface(S_window); 870 SDL_UpdateWindowSurface(S_window);
874 //SDL_UpdateRect(pSdlGuiScrn, dlg[0].x + dlg[obj].x - 2, dlg[0].y + dlg[obj].y - 2, dlg[obj].w + 4, dlg[obj].h + 4); 871 //SDL_UpdateRect(S_screen, dlg[0].x + dlg[obj].x - 2, dlg[0].y + dlg[obj].y - 2, dlg[obj].w + 4, dlg[obj].h + 4);
875 retbutton = obj; 872 retbutton = obj;
876 } 873 }
877 } 874 }
878 break; 875 break;
879 876
898 895
899 void SDLGui_DoDialogEnd(void) 896 void SDLGui_DoDialogEnd(void)
900 { 897 {
901 /* Restore background */ 898 /* Restore background */
902 if (pBgSurface) { 899 if (pBgSurface) {
903 SDL_BlitSurface(pBgSurface, &bgrect, pSdlGuiScrn, &dlgrect); 900 SDL_BlitSurface(pBgSurface, &bgrect, S_screen, &dlgrect);
904 SDL_FreeSurface(pBgSurface); 901 SDL_FreeSurface(pBgSurface);
905 } 902 }
906 } 903 }
907 904
908 905

mercurial