Final rebuild brewpanel to SDL2

Sat, 16 Mar 2024 10:51:41 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 16 Mar 2024 10:51:41 +0100
changeset 638
186f0c2d3e76
parent 637
21e542c15832
child 639
276ee5b61348

Final rebuild brewpanel to SDL2

brewpanel/brewpanel.c file | annotate | diff | comparison | revisions
brewpanel/dlgBrew.c file | annotate | diff | comparison | revisions
brewpanel/sdlgui.c file | annotate | diff | comparison | revisions
brewpanel/sdlgui.h file | annotate | diff | comparison | revisions
--- a/brewpanel/brewpanel.c	Fri Mar 15 20:57:49 2024 +0100
+++ b/brewpanel/brewpanel.c	Sat Mar 16 10:51:41 2024 +0100
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Copyright (C) 2015-2019
+ * Copyright (C) 2015-2024
  *   
  * Michiel Broek <mbroek at mbse dot eu>
  *
@@ -228,7 +228,7 @@
 
 int main(int argc, char *argv[])
 {
-    fprintf(stderr, "brewpanel not compiled because SDL is missing.\n");
+    fprintf(stderr, "brewpanel not compiled because SDL2 is missing.\n");
     return 1;
 }
 
--- a/brewpanel/dlgBrew.c	Fri Mar 15 20:57:49 2024 +0100
+++ b/brewpanel/dlgBrew.c	Sat Mar 16 10:51:41 2024 +0100
@@ -97,8 +97,8 @@
     int nOldMouseX, nOldMouseY;
     int x, y, w, h, cols, rows, fd;
 
-    if (SDLGui_SetScreen(S_screen)) {
-	syslog(LOG_NOTICE, "SDLGui_SetScreen(S_screen) failed: %s", SDL_GetError());
+    if (SDLGui_SetScreen()) {
+	syslog(LOG_NOTICE, "SDLGui_SetScreen() failed");
 	return FALSE;
     }
 
--- a/brewpanel/sdlgui.c	Fri Mar 15 20:57:49 2024 +0100
+++ b/brewpanel/sdlgui.c	Sat Mar 16 10:51:41 2024 +0100
@@ -32,7 +32,8 @@
 #include "lcdfont10x16.h"
 
 
-static SDL_Surface	*pSdlGuiScrn;            	/* Pointer to the actual main SDL screen surface 	*/
+extern SDL_Surface	*S_screen;			/* Pointer to the actual main SDL screen surface 	*/
+extern SDL_Window	*S_window;			/* Pointer to the actual window				*/
 static SDL_Surface	*pFontGfx = NULL;        	/* The LCD font graphics 				*/
 static SDL_Surface	*pBgSurface;			/* Pointer to the application SDL screen surface	*/
 static SDL_Rect		dlgrect, bgrect;
@@ -44,7 +45,6 @@
 extern int		my_shutdown;
 extern int		debug;
 
-extern SDL_Window	*S_window;
 
 /*-----------------------------------------------------------------------*/
 /*
@@ -161,13 +161,10 @@
 
 
 /*
- * Inform the SDL-GUI about the actual SDL_Surface screen pointer and
- * prepare the font to suit the actual resolution.
+ * Prepare the font to suit the actual resolution.
  */
-int SDLGui_SetScreen(SDL_Surface *pScrn)
+int SDLGui_SetScreen(void)
 {
-    pSdlGuiScrn = pScrn;
-
     if (pFontGfx == NULL) {
 	syslog(LOG_NOTICE, "Error: A problem with the font occured!");
 	return -1;
@@ -189,8 +186,8 @@
  */
 void SDLGui_CenterDlg(SGOBJ *dlg)
 {
-    dlg[0].x = (pSdlGuiScrn->w/1-dlg[0].w)/2;
-    dlg[0].y = (pSdlGuiScrn->h/1-dlg[0].h)/2;
+    dlg[0].x = (S_screen->w/1-dlg[0].w)/2;
+    dlg[0].y = (S_screen->h/1-dlg[0].h)/2;
 }
 
 
@@ -207,7 +204,7 @@
     message = TTF_RenderText_Solid(pFont, txt, textColor);
     offset.x = x;
     offset.y = y;
-    SDL_BlitSurface(message, NULL, pSdlGuiScrn, &offset);
+    SDL_BlitSurface(message, NULL, S_screen, &offset);
     SDL_FreeSurface(message);
     message = NULL;
 }
@@ -234,7 +231,7 @@
 void SDLGui_Cursor(SGOBJ *dlg, int fd, int x, int y, int on, int blink)
 {
     SDL_Rect	dr;
-    Uint32      color = SDL_MapRGB(pSdlGuiScrn->format, 53, 59, 61);
+    Uint32      color = SDL_MapRGB(S_screen->format, 53, 59, 61);
 
     if (on) {
     	dr.x = x;
@@ -242,8 +239,8 @@
     	dr.w = fontwidth;
     	dr.h = 2;
 
-    	SDL_FillRect(pSdlGuiScrn, &dr, color);
-//    	SDL_UpdateRect(pSdlGuiScrn, x, y, fontwidth, fontheight);
+    	SDL_FillRect(S_screen, &dr, color);
+	SDL_UpdateWindowSurface(S_window);
     }
 }
 
@@ -288,9 +285,13 @@
 	i++;
     }
 
-//    SDL_SetColors(CGchar, blackWhiteColors, 0, 2);
+    SDL_SetPaletteColors(CGchar->format->palette, blackWhiteColors, 0, 2);
     SDL_SetColorKey(CGchar, SDL_RLEACCEL, 0);
-    bg = LCDbg0;
+    if (dlg[1].state & SG_SELECTED) {
+        bg = LCDbg1;
+    } else {
+        bg = LCDbg0;
+    }
 
     sr.x = sr.y = 0;
     dr.x = x;
@@ -298,9 +299,8 @@
     sr.w = dr.w = fontwidth;
     sr.h = dr.h = fontheight;
 
-    SDL_FillRect(pSdlGuiScrn, &dr, bg);
-    SDL_BlitSurface(CGchar, &sr, pSdlGuiScrn, &dr);
-    //SDL_UpdateRect(pSdlGuiScrn, x, y, fontwidth, fontheight);
+    SDL_FillRect(S_screen, &dr, bg);
+    SDL_BlitSurface(CGchar, &sr, S_screen, &dr);
     SDL_UpdateWindowSurface(S_window);
     SDL_FreeSurface(CGchar);
 }
@@ -315,11 +315,11 @@
     SDL_Rect    sr, dr;
     Uint32	bg;
 
-//    if (dlg[1].state & SG_SELECTED) {
-//	bg = LCDbg1;
-//    } else {
+    if (dlg[1].state & SG_SELECTED) {
+	bg = LCDbg1;
+    } else {
 	bg = LCDbg0;
-//    }
+    }
 
     sr.x=fontwidth*(c%16);
     sr.y=fontheight*(c/16);
@@ -330,9 +330,8 @@
     dr.w=fontwidth;
     dr.h=fontheight;
 
-    SDL_FillRect(pSdlGuiScrn, &dr, bg);
-    SDL_BlitSurface(pFontGfx, &sr, pSdlGuiScrn, &dr);
-//    SDL_UpdateRect(pSdlGuiScrn, x, y, fontwidth, fontheight);
+    SDL_FillRect(S_screen, &dr, bg);
+    SDL_BlitSurface(pFontGfx, &sr, S_screen, &dr);
     SDL_UpdateWindowSurface(S_window);
 }
 
@@ -357,7 +356,7 @@
 	dr.y=y;
 	dr.w=fontwidth;
 	dr.h=fontheight;
-	SDL_BlitSurface(pFontGfx, &sr, pSdlGuiScrn, &dr);
+	SDL_BlitSurface(pFontGfx, &sr, S_screen, &dr);
     }
 }
 
@@ -384,11 +383,11 @@
 {
     SDL_Rect    rect;
     int         x, y, w, h, offset, border = 4;
-    Uint32	bc  = SDL_MapRGB(pSdlGuiScrn->format, 32, 32, 32);
+    Uint32	bc  = SDL_MapRGB(S_screen->format, 32, 32, 32);
     Uint32      bg;
 
-    LCDbg0 = SDL_MapRGB(pSdlGuiScrn->format, 94,147, 69);
-    LCDbg1 = SDL_MapRGB(pSdlGuiScrn->format,156,235,  4);
+    LCDbg0 = SDL_MapRGB(S_screen->format, 94,147, 69);
+    LCDbg1 = SDL_MapRGB(S_screen->format,156,235,  4);
     /*
      * Width and height are given in character columns and rows,
      * so calculate the display size in pixels.
@@ -411,11 +410,11 @@
 	y += bdlg[0].y;
     }
 
-//    if (bdlg[objnum].state & SG_SELECTED) {
-//	bg = LCDbg1;
-//    } else {
+    if (bdlg[objnum].state & SG_SELECTED) {
+	bg = LCDbg1;
+    } else {
 	bg = LCDbg0;
-//    }
+    }
 
     /* The root box should be bigger than the screen, so we disable the offset there: */
     if (objnum != 0)
@@ -428,35 +427,35 @@
     rect.y = y;
     rect.w = w;
     rect.h = h;
-    SDL_FillRect(pSdlGuiScrn, &rect, bg);
+    SDL_FillRect(S_screen, &rect, bg);
 
     /* Draw upper border: */
     rect.x = x - offset;
     rect.y = y - offset;
     rect.w = w + offset + offset;
     rect.h = border;
-    SDL_FillRect(pSdlGuiScrn, &rect, bc);
+    SDL_FillRect(S_screen, &rect, bc);
 
     /* Draw left border: */
     rect.x = x - offset;
     rect.y = y;
     rect.w = border;
     rect.h = h;
-    SDL_FillRect(pSdlGuiScrn, &rect, bc);
+    SDL_FillRect(S_screen, &rect, bc);
 
     /* Draw bottom border: */
     rect.x = x - offset;
     rect.y = y + h - border + offset;
     rect.w = w + offset + offset;
     rect.h = border;
-    SDL_FillRect(pSdlGuiScrn, &rect, bc);
+    SDL_FillRect(S_screen, &rect, bc);
 
     /* Draw right border: */
     rect.x = x + w - border + offset;
     rect.y = y;
     rect.w = border;
     rect.h = h;
-    SDL_FillRect(pSdlGuiScrn, &rect, bc);
+    SDL_FillRect(S_screen, &rect, bc);
 }
 
 
@@ -468,7 +467,7 @@
 {
     SDL_Rect	rect;
     int		x, y, w, h, offset, shade = 2;
-    Uint32	grey = SDL_MapRGB(pSdlGuiScrn->format,192,192,192);
+    Uint32	grey = SDL_MapRGB(S_screen->format,192,192,192);
     Uint32	upleftc, downrightc;
 
     x = bdlg[objnum].x;
@@ -482,11 +481,11 @@
     h = bdlg[objnum].h;
 
     if (bdlg[objnum].state & SG_SELECTED) {
-	upleftc = SDL_MapRGB(pSdlGuiScrn->format,128,128,128);
-	downrightc = SDL_MapRGB(pSdlGuiScrn->format,255,255,255);
+	upleftc = SDL_MapRGB(S_screen->format,128,128,128);
+	downrightc = SDL_MapRGB(S_screen->format,255,255,255);
     } else {
-	upleftc = SDL_MapRGB(pSdlGuiScrn->format,255,255,255);
-	downrightc = SDL_MapRGB(pSdlGuiScrn->format,128,128,128);
+	upleftc = SDL_MapRGB(S_screen->format,255,255,255);
+	downrightc = SDL_MapRGB(S_screen->format,128,128,128);
     }
 
     /* The root box should be bigger than the screen, so we disable the offset there: */
@@ -500,35 +499,35 @@
     rect.y = y;
     rect.w = w;
     rect.h = h;
-    SDL_FillRect(pSdlGuiScrn, &rect, grey);
+    SDL_FillRect(S_screen, &rect, grey);
 
     /* Draw upper border: */
     rect.x = x;
     rect.y = y - offset;
     rect.w = w;
     rect.h = shade;
-    SDL_FillRect(pSdlGuiScrn, &rect, upleftc);
+    SDL_FillRect(S_screen, &rect, upleftc);
 
     /* Draw left border: */
     rect.x = x - offset;
     rect.y = y;
     rect.w = shade;
     rect.h = h;
-    SDL_FillRect(pSdlGuiScrn, &rect, upleftc);
+    SDL_FillRect(S_screen, &rect, upleftc);
 
     /* Draw bottom border: */
     rect.x = x;
     rect.y = y + h - shade + offset;
     rect.w = w;
     rect.h = shade;
-    SDL_FillRect(pSdlGuiScrn, &rect, downrightc);
+    SDL_FillRect(S_screen, &rect, downrightc);
 
     /* Draw right border: */
     rect.x = x + w - shade + offset;
     rect.y = y;
     rect.w = shade;
     rect.h = h;
-    SDL_FillRect(pSdlGuiScrn, &rect, downrightc);
+    SDL_FillRect(S_screen, &rect, downrightc);
 }
 
 
@@ -620,11 +619,11 @@
     Uint32	color;
 
     if (bdlg[objnum].state & SG_SELECTED) {
-	color = SDL_MapRGB(pSdlGuiScrn->format, 255, 64, 0);
+	color = SDL_MapRGB(S_screen->format, 255, 64, 0);
     } else {
-	color = SDL_MapRGB(pSdlGuiScrn->format, 128, 16, 0);
+	color = SDL_MapRGB(S_screen->format, 128, 16, 0);
     }
-    SDLGui_fill_circle(pSdlGuiScrn, bdlg[objnum].x, bdlg[objnum].y, bdlg[objnum].w, color);
+    SDLGui_fill_circle(S_screen, bdlg[objnum].x, bdlg[objnum].y, bdlg[objnum].w, color);
 }
 
 
@@ -634,11 +633,11 @@
     Uint32      color;
 
     if (bdlg[objnum].state & SG_SELECTED) {
-	color = SDL_MapRGB(pSdlGuiScrn->format, 64, 160, 255);
+	color = SDL_MapRGB(S_screen->format, 64, 160, 255);
     } else {
-	color = SDL_MapRGB(pSdlGuiScrn->format, 16, 48, 112);
+	color = SDL_MapRGB(S_screen->format, 16, 48, 112);
     }
-    SDLGui_fill_circle(pSdlGuiScrn, bdlg[objnum].x, bdlg[objnum].y, bdlg[objnum].w, color);
+    SDLGui_fill_circle(S_screen, bdlg[objnum].x, bdlg[objnum].y, bdlg[objnum].w, color);
 }
 
 
@@ -648,11 +647,11 @@
     Uint32      color;
 
     if (bdlg[objnum].state & SG_SELECTED) {
-	color = SDL_MapRGB(pSdlGuiScrn->format, 80, 240, 0);
+	color = SDL_MapRGB(S_screen->format, 80, 240, 0);
     } else {
-	color = SDL_MapRGB(pSdlGuiScrn->format, 32, 112, 0);
+	color = SDL_MapRGB(S_screen->format, 32, 112, 0);
     }
-    SDLGui_fill_circle(pSdlGuiScrn, bdlg[objnum].x, bdlg[objnum].y, bdlg[objnum].w, color);
+    SDLGui_fill_circle(S_screen, bdlg[objnum].x, bdlg[objnum].y, bdlg[objnum].w, color);
 }
 
 
@@ -662,11 +661,11 @@
     Uint32      color;
 
     if (bdlg[objnum].state & SG_SELECTED) {
-	color = SDL_MapRGB(pSdlGuiScrn->format, 255, 255, 0);
+	color = SDL_MapRGB(S_screen->format, 255, 255, 0);
     } else {
-	color = SDL_MapRGB(pSdlGuiScrn->format, 160, 144, 0);
+	color = SDL_MapRGB(S_screen->format, 160, 144, 0);
     }
-    SDLGui_fill_circle(pSdlGuiScrn, bdlg[objnum].x, bdlg[objnum].y, bdlg[objnum].w, color);
+    SDLGui_fill_circle(S_screen, bdlg[objnum].x, bdlg[objnum].y, bdlg[objnum].w, color);
 }
 
 
@@ -699,7 +698,6 @@
 				break;
 	    }
 	    SDL_UpdateWindowSurface(S_window);
-	    //SDL_UpdateRect(pSdlGuiScrn, dlg[i].x - dlg[i].w, dlg[i].y - dlg[i].w, dlg[i].w * 2, dlg[i].w * 2);
 	}
     }
 }
@@ -746,7 +744,6 @@
     }
 
     SDL_UpdateWindowSurface(S_window);
-  //  SDL_UpdateRect(pSdlGuiScrn, 0,0,0,0);
 }
 
 
@@ -783,7 +780,7 @@
  */
 int SDLGui_DoDialogInit(SGOBJ *dlg)
 {
-    if ((pSdlGuiScrn->h < dlg[0].h) && (pSdlGuiScrn->w < dlg[0].w)) {
+    if ((S_screen->h < dlg[0].h) && (S_screen->w < dlg[0].w)) {
 	syslog(LOG_NOTICE, "Screen size too small for dialog!");
 	return SDLGUI_ERROR;
     }
@@ -800,14 +797,14 @@
     /*
      * Save background
      */
-    pBgSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, dlgrect.w, dlgrect.h, pSdlGuiScrn->format->BitsPerPixel,
-	                                  pSdlGuiScrn->format->Rmask, pSdlGuiScrn->format->Gmask, pSdlGuiScrn->format->Bmask, pSdlGuiScrn->format->Amask);
-    if (pSdlGuiScrn->format->palette != NULL) {
-	SDL_SetPaletteColors(pBgSurface->format->palette, pSdlGuiScrn->format->palette->colors, 0, pSdlGuiScrn->format->palette->ncolors-1);
+    pBgSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, dlgrect.w, dlgrect.h, S_screen->format->BitsPerPixel,
+	                                  S_screen->format->Rmask, S_screen->format->Gmask, S_screen->format->Bmask, S_screen->format->Amask);
+    if (S_screen->format->palette != NULL) {
+	SDL_SetPaletteColors(pBgSurface->format->palette, S_screen->format->palette->colors, 0, S_screen->format->palette->ncolors-1);
     }
 
     if (pBgSurface != NULL) {
-	SDL_BlitSurface(pSdlGuiScrn,  &dlgrect, pBgSurface, &bgrect);
+	SDL_BlitSurface(S_screen,  &dlgrect, pBgSurface, &bgrect);
     } else {
 	syslog(LOG_NOTICE, "SDLGUI_DoDialog: CreateRGBSurface failed: %s", SDL_GetError());
     }
@@ -853,7 +850,7 @@
 					dlg[obj].state |= SG_SELECTED;
 					SDLGui_DrawButton(dlg, obj);
 					SDL_UpdateWindowSurface(S_window);
-					//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);
+					//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);
 					retbutton = obj + 1000;
 				    }
 				}
@@ -871,7 +868,7 @@
 					dlg[obj].state &= ~SG_SELECTED;
 					SDLGui_DrawButton(dlg, obj);
 					SDL_UpdateWindowSurface(S_window);
-					//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);
+					//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);
 					retbutton = obj;
 				    }
 				}
@@ -900,7 +897,7 @@
 {
     /* Restore background */
     if (pBgSurface) {
-	SDL_BlitSurface(pBgSurface, &bgrect, pSdlGuiScrn,  &dlgrect);
+	SDL_BlitSurface(pBgSurface, &bgrect, S_screen,  &dlgrect);
 	SDL_FreeSurface(pBgSurface);
     }
 }
--- a/brewpanel/sdlgui.h	Fri Mar 15 20:57:49 2024 +0100
+++ b/brewpanel/sdlgui.h	Sat Mar 16 10:51:41 2024 +0100
@@ -56,7 +56,7 @@
 void SDLGui_DrawLCD(SGOBJ *bdlg, int objnum);
 int  SDLGui_Init(void);
 int  SDLGui_UnInit(void);
-int  SDLGui_SetScreen(SDL_Surface *pScrn);
+int  SDLGui_SetScreen(void);
 void SDLGui_DrawDialog(SGOBJ *dlg);
 int  SDLGui_DoDialogInit(SGOBJ *dlg);
 int  SDLGui_DoDialogLoop(SGOBJ *dlg);

mercurial