31 #include "lcdfont10x16.h" |
31 #include "lcdfont10x16.h" |
32 |
32 |
33 |
33 |
34 static SDL_Surface *pSdlGuiScrn; /* Pointer to the actual main SDL screen surface */ |
34 static SDL_Surface *pSdlGuiScrn; /* Pointer to the actual main SDL screen surface */ |
35 static SDL_Surface *pFontGfx = NULL; /* The LCD font graphics */ |
35 static SDL_Surface *pFontGfx = NULL; /* The LCD font graphics */ |
|
36 static SDL_Surface *pBgSurface; /* Pointer to the application SDL screen surface */ |
|
37 static SDL_Rect dlgrect, bgrect; |
36 static int fontwidth, fontheight; /* Width & height of the actual font */ |
38 static int fontwidth, fontheight; /* Width & height of the actual font */ |
37 TTF_Font *pFont = NULL; /* TTF font for buttons etc. */ |
39 TTF_Font *pFont = NULL; /* TTF font for buttons etc. */ |
38 |
40 |
39 extern int my_shutdown; |
41 extern int my_shutdown; |
40 |
42 |
217 } |
219 } |
218 |
220 |
219 |
221 |
220 |
222 |
221 /* |
223 /* |
|
224 * Draw the cursor |
|
225 */ |
|
226 void SDLGui_Cursor(int x, int y) |
|
227 { |
|
228 SDL_Rect dr; |
|
229 Uint32 color = SDL_MapRGB(pSdlGuiScrn->format, 53, 59, 61); |
|
230 |
|
231 dr.x=x; |
|
232 dr.y=y; |
|
233 dr.w=fontwidth; |
|
234 dr.h=fontheight; |
|
235 |
|
236 SDL_FillRect(pSdlGuiScrn, &dr, color); |
|
237 SDL_UpdateRect(pSdlGuiScrn, x, y, fontwidth, fontheight); |
|
238 } |
|
239 |
|
240 |
|
241 |
|
242 /* |
|
243 * Draw a text character |
|
244 */ |
|
245 void SDLGui_Char(int x, int y, Uint8 c, int bLight) |
|
246 { |
|
247 SDL_Rect sr, dr; |
|
248 Uint32 bg; |
|
249 |
|
250 if (bLight) |
|
251 bg = SDL_MapRGB(pSdlGuiScrn->format,156,235, 4); |
|
252 else |
|
253 bg = SDL_MapRGB(pSdlGuiScrn->format, 94,147, 69); |
|
254 |
|
255 sr.x=fontwidth*(c%16); |
|
256 sr.y=fontheight*(c/16); |
|
257 sr.w=fontwidth; |
|
258 sr.h=fontheight; |
|
259 dr.x=x; |
|
260 dr.y=y; |
|
261 dr.w=fontwidth; |
|
262 dr.h=fontheight; |
|
263 |
|
264 SDL_FillRect(pSdlGuiScrn, &dr, bg); |
|
265 SDL_BlitSurface(pFontGfx, &sr, pSdlGuiScrn, &dr); |
|
266 SDL_UpdateRect(pSdlGuiScrn, x, y, fontwidth, fontheight); |
|
267 } |
|
268 |
|
269 |
|
270 |
|
271 /* |
222 * Draw a text string. |
272 * Draw a text string. |
223 */ |
273 */ |
224 static void SDLGui_Text(int x, int y, const char *txt) |
274 static void SDLGui_Text(int x, int y, const char *txt) |
225 { |
275 { |
226 int i; |
276 int i; |
227 char c; |
277 Uint8 c; |
228 SDL_Rect sr, dr; |
278 SDL_Rect sr, dr; |
229 |
279 |
230 for (i=0; txt[i]!=0; i++) { |
280 for (i=0; txt[i]!=0; i++) { |
231 c = txt[i]; |
281 c = txt[i] & 0xff; |
232 sr.x=fontwidth*(c%16); |
282 sr.x=fontwidth*(c%16); |
233 sr.y=fontheight*(c/16); |
283 sr.y=fontheight*(c/16); |
234 sr.w=fontwidth; |
284 sr.w=fontwidth; |
235 sr.h=fontheight; |
285 sr.h=fontheight; |
236 dr.x=x+i*(fontwidth+2); |
286 dr.x=x+i*(fontwidth+2); |
517 } |
567 } |
518 |
568 |
519 |
569 |
520 |
570 |
521 /* |
571 /* |
522 * Show and process a dialog. Returns the button number that has been |
572 * Show dialog. |
523 * pressed or SDLGUI_UNKNOWNEVENT if an unsupported event occured (will be |
573 */ |
524 * stored in parameter pEventOut). |
574 int SDLGui_DoDialogInit(SGOBJ *dlg) |
525 */ |
575 { |
526 int SDLGui_DoDialog(SGOBJ *dlg, SDL_Event *pEventOut) |
576 if ((pSdlGuiScrn->h < dlg[0].h) && (pSdlGuiScrn->w < dlg[0].w)) { |
527 { |
577 syslog(LOG_NOTICE, "Screen size too small for dialog!"); |
528 int obj = 0, oldbutton = 0, retbutton = 0, i, j, b; |
578 return SDLGUI_ERROR; |
529 SDL_Event sdlEvent; |
579 } |
530 SDL_Surface *pBgSurface; |
|
531 SDL_Rect dlgrect, bgrect; |
|
532 |
|
533 // if (pSdlGuiScrn->h / fontheight < dlg[0].h) |
|
534 // { |
|
535 // syslog(LOG_NOTICE, "Screen size too small for dialog!"); |
|
536 // return SDLGUI_ERROR; |
|
537 // } |
|
538 |
580 |
539 dlgrect.x = dlg[0].x; |
581 dlgrect.x = dlg[0].x; |
540 dlgrect.y = dlg[0].y; |
582 dlgrect.y = dlg[0].y; |
541 dlgrect.w = dlg[0].w; |
583 dlgrect.w = dlg[0].w; |
542 dlgrect.h = dlg[0].h; |
584 dlgrect.h = dlg[0].h; |
626 } |
676 } |
627 } |
677 } |
628 if (oldbutton > 0) { |
678 if (oldbutton > 0) { |
629 dlg[oldbutton].state &= ~SG_SELECTED; |
679 dlg[oldbutton].state &= ~SG_SELECTED; |
630 SDLGui_DrawButton(dlg, oldbutton); |
680 SDLGui_DrawButton(dlg, oldbutton); |
631 SDL_UpdateRect(pSdlGuiScrn, (dlg[0].x+dlg[oldbutton].x)*fontwidth-2, (dlg[0].y+dlg[oldbutton].y)*fontheight-2, |
681 SDL_UpdateRect(pSdlGuiScrn, dlg[0].x+dlg[oldbutton].x-2, dlg[0].y+dlg[oldbutton].y-2, dlg[oldbutton].w+4, dlg[oldbutton].h+4); |
632 dlg[oldbutton].w*fontwidth+4, dlg[oldbutton].h*fontheight+4); |
|
633 oldbutton = 0; |
682 oldbutton = 0; |
634 } |
683 } |
635 if (obj >= 0 && (dlg[obj].flags & SG_EXIT)) { |
684 if (obj >= 0 && (dlg[obj].flags & SG_EXIT)) { |
636 retbutton = obj; |
685 retbutton = obj; |
637 } |
686 } |
638 break; |
687 break; |
639 |
688 |
640 case SDL_MOUSEMOTION: |
689 case SDL_MOUSEMOTION: |
641 break; |
690 break; |
642 |
691 |
643 case SDL_KEYDOWN: /* Key pressed */ |
692 case SDL_KEYDOWN: /* Key pressed */ |
644 if (sdlEvent.key.keysym.sym == SDLK_RETURN || sdlEvent.key.keysym.sym == SDLK_KP_ENTER) { |
693 if (sdlEvent.key.keysym.sym == SDLK_RETURN || sdlEvent.key.keysym.sym == SDLK_KP_ENTER) { |
645 retbutton = SDLGui_SearchFlaggedButton(dlg, SG_DEFAULT); |
694 retbutton = SDLGui_SearchFlaggedButton(dlg, SG_DEFAULT); |
646 } else if (sdlEvent.key.keysym.sym == SDLK_ESCAPE) { |
695 } else if (sdlEvent.key.keysym.sym == SDLK_ESCAPE) { |
647 retbutton = SDLGui_SearchFlaggedButton(dlg, SG_CANCEL); |
696 retbutton = SDLGui_SearchFlaggedButton(dlg, SG_CANCEL); |
648 } else if (pEventOut) { |
|
649 retbutton = SDLGUI_UNKNOWNEVENT; |
|
650 } |
697 } |
651 break; |
698 break; |
652 |
|
653 default: |
|
654 if (pEventOut) |
|
655 retbutton = SDLGUI_UNKNOWNEVENT; |
|
656 break; |
|
657 } |
699 } |
658 } |
700 } |
659 |
701 |
|
702 if (retbutton == SDLGUI_QUIT) |
|
703 my_shutdown = TRUE; |
|
704 |
|
705 return retbutton; |
|
706 } |
|
707 |
|
708 |
|
709 |
|
710 void SDLGui_DoDialogEnd(void) |
|
711 { |
660 /* Restore background */ |
712 /* Restore background */ |
661 if (pBgSurface) { |
713 if (pBgSurface) { |
662 SDL_BlitSurface(pBgSurface, &bgrect, pSdlGuiScrn, &dlgrect); |
714 SDL_BlitSurface(pBgSurface, &bgrect, pSdlGuiScrn, &dlgrect); |
663 SDL_FreeSurface(pBgSurface); |
715 SDL_FreeSurface(pBgSurface); |
664 } |
716 } |
665 |
717 } |
666 /* Copy event data of unsupported events if caller wants to have it */ |
718 |
667 if (retbutton == SDLGUI_UNKNOWNEVENT && pEventOut) |
719 |
668 memcpy(pEventOut, &sdlEvent, sizeof(SDL_Event)); |
720 |
669 |
721 /* |
670 if (retbutton == SDLGUI_QUIT) |
722 * Initialize a LCD object. Set the coordinates and dimenstions. Return index. |
671 my_shutdown = TRUE; |
723 */ |
672 |
724 int SDLGui_LCDinit(SGOBJ *dlg, int *x, int *y, int *w, int *h, int *cols, int *rows, int lcdindex) |
673 return retbutton; |
725 { |
674 } |
726 int i, index; |
675 |
727 |
676 |
728 /* |
677 |
729 * Search the LCD display |
|
730 */ |
|
731 *x = *y = *w = *h = *cols = *rows = i = index = 0; |
|
732 for (;;) { |
|
733 if (dlg[i].type == -1) { |
|
734 syslog(LOG_NOTICE, "SDLGui_LCDinit() lcdindex=%d not found", lcdindex); |
|
735 return -1; |
|
736 } |
|
737 if (dlg[i].type == SGLCD) { |
|
738 if (index == lcdindex) |
|
739 break; |
|
740 index++; |
|
741 } |
|
742 i++; |
|
743 } |
|
744 fprintf(stdout, "SDLGui_LCDinit=%d LCD=%dx%d %dx%d\n", i, dlg[i].x, dlg[i].y, dlg[i].w, dlg[i].h); |
|
745 |
|
746 *cols = dlg[i].w; |
|
747 *rows = dlg[i].h; |
|
748 *w = dlg[i].w * (fontwidth + 2) + 10; |
|
749 *h = dlg[i].h * (fontheight + 2) + 4; |
|
750 if (dlg[i].x == -1) { |
|
751 *x = (dlg[0].w - *w) / 2; |
|
752 } else { |
|
753 *x = dlg[i].x; |
|
754 } |
|
755 *y = dlg[i].y; |
|
756 |
|
757 return lcdindex; |
|
758 } |
|
759 |
|
760 |
|
761 /* |
678 void SDLGui_LCDwrite(SGOBJ *dlg, int x, int y, Uint8 c, int lcdindex) |
762 void SDLGui_LCDwrite(SGOBJ *dlg, int x, int y, Uint8 c, int lcdindex) |
679 { |
763 { |
680 int i, index; |
764 int i, index; |
681 |
765 |
682 fprintf(stdout, "SDLGui_LCDwrite( , %d, %d, %c, %d)\n", x, y, c, lcdindex); |
766 fprintf(stdout, "SDLGui_LCDwrite( , %d, %d, %c, %d)\n", x, y, c, lcdindex); |