brewpanel/sdlgui.c

changeset 637
21e542c15832
parent 605
e00f8ff4de9a
child 638
186f0c2d3e76
equal deleted inserted replaced
636:80967361f257 637:21e542c15832
1 /***************************************************************************** 1 /*****************************************************************************
2 * Copyright (C) 2015-2020 2 * Copyright (C) 2015-2024
3 * 3 *
4 * Michiel Broek <mbroek at mbse dot eu> 4 * Michiel Broek <mbroek at mbse dot eu>
5 * 5 *
6 * This file is part of the mbsePi-apps emulator 6 * This file is part of the mbsePi-apps emulator
7 * 7 *
25 25
26 #include "brewpanel.h" 26 #include "brewpanel.h"
27 #include "sdlgui.h" 27 #include "sdlgui.h"
28 #include "sockio.h" 28 #include "sockio.h"
29 29
30 #ifdef HAVE_SDL_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 static SDL_Surface *pSdlGuiScrn; /* Pointer to the actual main SDL screen surface */
42 static Uint32 LCDbg1 = 0; /* LCD background light */ 42 static Uint32 LCDbg1 = 0; /* LCD background light */
43 43
44 extern int my_shutdown; 44 extern int my_shutdown;
45 extern int debug; 45 extern int debug;
46 46
47 extern SDL_Window *S_window;
47 48
48 /*-----------------------------------------------------------------------*/ 49 /*-----------------------------------------------------------------------*/
49 /* 50 /*
50 * Load an 1 plane XBM into a 8 planes SDL_Surface. 51 * Load an 1 plane XBM into a 8 planes SDL_Surface.
51 */ 52 */
102 syslog(LOG_NOTICE, "Error: Can not init font graphics!"); 103 syslog(LOG_NOTICE, "Error: Can not init font graphics!");
103 return -1; 104 return -1;
104 } 105 }
105 106
106 /* Set color palette of the LCD font graphics: */ 107 /* Set color palette of the LCD font graphics: */
107 SDL_SetColors(pFontGfx, blackWhiteColors, 0, 2); 108 SDL_SetPaletteColors(pFontGfx->format->palette, blackWhiteColors, 0, 2);
108 109
109 /* Set font color 0 as transparent: */ 110 /* Set font color 0 as transparent: */
110 SDL_SetColorKey(pFontGfx, (SDL_SRCCOLORKEY|SDL_RLEACCEL), 0); 111 SDL_SetColorKey(pFontGfx, SDL_RLEACCEL, 0);
111 112
112 if (TTF_Init() == -1) { 113 if (TTF_Init() == -1) {
113 syslog(LOG_NOTICE, "Could not init SDL_ttf"); 114 syslog(LOG_NOTICE, "Could not init SDL_ttf");
114 return -1; 115 return -1;
115 } 116 }
240 dr.y = y + fontheight - 2; 241 dr.y = y + fontheight - 2;
241 dr.w = fontwidth; 242 dr.w = fontwidth;
242 dr.h = 2; 243 dr.h = 2;
243 244
244 SDL_FillRect(pSdlGuiScrn, &dr, color); 245 SDL_FillRect(pSdlGuiScrn, &dr, color);
245 SDL_UpdateRect(pSdlGuiScrn, x, y, fontwidth, fontheight); 246 // SDL_UpdateRect(pSdlGuiScrn, x, y, fontwidth, fontheight);
246 } 247 }
247 } 248 }
248 249
249 250
250 251
285 dstbits += dstpitch; 286 dstbits += dstpitch;
286 } 287 }
287 i++; 288 i++;
288 } 289 }
289 290
290 SDL_SetColors(CGchar, blackWhiteColors, 0, 2); 291 // SDL_SetColors(CGchar, blackWhiteColors, 0, 2);
291 SDL_SetColorKey(CGchar, (SDL_SRCCOLORKEY|SDL_RLEACCEL), 0); 292 SDL_SetColorKey(CGchar, SDL_RLEACCEL, 0);
292 bg = LCDbg0; 293 bg = LCDbg0;
293 294
294 sr.x = sr.y = 0; 295 sr.x = sr.y = 0;
295 dr.x = x; 296 dr.x = x;
296 dr.y = y; 297 dr.y = y;
297 sr.w = dr.w = fontwidth; 298 sr.w = dr.w = fontwidth;
298 sr.h = dr.h = fontheight; 299 sr.h = dr.h = fontheight;
299 300
300 SDL_FillRect(pSdlGuiScrn, &dr, bg); 301 SDL_FillRect(pSdlGuiScrn, &dr, bg);
301 SDL_BlitSurface(CGchar, &sr, pSdlGuiScrn, &dr); 302 SDL_BlitSurface(CGchar, &sr, pSdlGuiScrn, &dr);
302 SDL_UpdateRect(pSdlGuiScrn, x, y, fontwidth, fontheight); 303 //SDL_UpdateRect(pSdlGuiScrn, x, y, fontwidth, fontheight);
304 SDL_UpdateWindowSurface(S_window);
303 SDL_FreeSurface(CGchar); 305 SDL_FreeSurface(CGchar);
304 } 306 }
305 307
306 308
307 309
328 dr.w=fontwidth; 330 dr.w=fontwidth;
329 dr.h=fontheight; 331 dr.h=fontheight;
330 332
331 SDL_FillRect(pSdlGuiScrn, &dr, bg); 333 SDL_FillRect(pSdlGuiScrn, &dr, bg);
332 SDL_BlitSurface(pFontGfx, &sr, pSdlGuiScrn, &dr); 334 SDL_BlitSurface(pFontGfx, &sr, pSdlGuiScrn, &dr);
333 SDL_UpdateRect(pSdlGuiScrn, x, y, fontwidth, fontheight); 335 // SDL_UpdateRect(pSdlGuiScrn, x, y, fontwidth, fontheight);
336 SDL_UpdateWindowSurface(S_window);
334 } 337 }
335 338
336 339
337 340
338 /* 341 /*
693 break; 696 break;
694 case SGLEDYELLOW: 697 case SGLEDYELLOW:
695 SDLGUI_DrawLEDYellow(dlg, i); 698 SDLGUI_DrawLEDYellow(dlg, i);
696 break; 699 break;
697 } 700 }
698 SDL_UpdateRect(pSdlGuiScrn, dlg[i].x - dlg[i].w, dlg[i].y - dlg[i].w, dlg[i].w * 2, dlg[i].w * 2); 701 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);
699 } 703 }
700 } 704 }
701 } 705 }
702 706
703 707
739 SDLGUI_DrawLEDYellow(dlg, i); 743 SDLGUI_DrawLEDYellow(dlg, i);
740 break; 744 break;
741 } 745 }
742 } 746 }
743 747
744 SDL_UpdateRect(pSdlGuiScrn, 0,0,0,0); 748 SDL_UpdateWindowSurface(S_window);
749 // SDL_UpdateRect(pSdlGuiScrn, 0,0,0,0);
745 } 750 }
746 751
747 752
748 753
749 /* 754 /*
796 * Save background 801 * Save background
797 */ 802 */
798 pBgSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, dlgrect.w, dlgrect.h, pSdlGuiScrn->format->BitsPerPixel, 803 pBgSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, dlgrect.w, dlgrect.h, pSdlGuiScrn->format->BitsPerPixel,
799 pSdlGuiScrn->format->Rmask, pSdlGuiScrn->format->Gmask, pSdlGuiScrn->format->Bmask, pSdlGuiScrn->format->Amask); 804 pSdlGuiScrn->format->Rmask, pSdlGuiScrn->format->Gmask, pSdlGuiScrn->format->Bmask, pSdlGuiScrn->format->Amask);
800 if (pSdlGuiScrn->format->palette != NULL) { 805 if (pSdlGuiScrn->format->palette != NULL) {
801 SDL_SetColors(pBgSurface, pSdlGuiScrn->format->palette->colors, 0, pSdlGuiScrn->format->palette->ncolors-1); 806 SDL_SetPaletteColors(pBgSurface->format->palette, pSdlGuiScrn->format->palette->colors, 0, pSdlGuiScrn->format->palette->ncolors-1);
802 } 807 }
803 808
804 if (pBgSurface != NULL) { 809 if (pBgSurface != NULL) {
805 SDL_BlitSurface(pSdlGuiScrn, &dlgrect, pBgSurface, &bgrect); 810 SDL_BlitSurface(pSdlGuiScrn, &dlgrect, pBgSurface, &bgrect);
806 } else { 811 } else {
845 obj = SDLGui_FindObj(dlg, sdlEvent.button.x, sdlEvent.button.y); 850 obj = SDLGui_FindObj(dlg, sdlEvent.button.x, sdlEvent.button.y);
846 if (obj > 0) { 851 if (obj > 0) {
847 if (dlg[obj].type == SGBUTTON) { 852 if (dlg[obj].type == SGBUTTON) {
848 dlg[obj].state |= SG_SELECTED; 853 dlg[obj].state |= SG_SELECTED;
849 SDLGui_DrawButton(dlg, obj); 854 SDLGui_DrawButton(dlg, obj);
850 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); 855 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);
851 retbutton = obj + 1000; 857 retbutton = obj + 1000;
852 } 858 }
853 } 859 }
854 break; 860 break;
855 861
862 obj = SDLGui_FindObj(dlg, sdlEvent.button.x, sdlEvent.button.y); 868 obj = SDLGui_FindObj(dlg, sdlEvent.button.x, sdlEvent.button.y);
863 if (obj > 0) { 869 if (obj > 0) {
864 if (dlg[obj].type == SGBUTTON) { 870 if (dlg[obj].type == SGBUTTON) {
865 dlg[obj].state &= ~SG_SELECTED; 871 dlg[obj].state &= ~SG_SELECTED;
866 SDLGui_DrawButton(dlg, obj); 872 SDLGui_DrawButton(dlg, obj);
867 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); 873 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);
868 retbutton = obj; 875 retbutton = obj;
869 } 876 }
870 } 877 }
871 break; 878 break;
872 879

mercurial