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. */ |
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 |
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; |
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) |
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 */ |