brewpanel/brewpanel.c

changeset 637
21e542c15832
parent 574
362c4700937e
child 638
186f0c2d3e76
--- a/brewpanel/brewpanel.c	Thu Mar 14 19:37:53 2024 +0100
+++ b/brewpanel/brewpanel.c	Fri Mar 15 20:57:49 2024 +0100
@@ -24,7 +24,7 @@
 #include "sdlgui.h"
 #include "dlgBrew.h"
 
-#ifdef HAVE_SDL_SDL_H
+#ifdef HAVE_SDL2_SDL_H
 
 int			debug = FALSE;			/* Console debugging		*/
 static pid_t		pgrp, mypid;
@@ -36,8 +36,8 @@
 int			LCD_fcol;			/* LCD foreground color		*/
 int			LCD_bcol;			/* LCD background color		*/
 
-SDL_Surface		*PAN_surface = NULL;		/* Main surface			*/
-
+SDL_Surface		*S_screen = NULL;		/* Main screen			*/
+SDL_Window		*S_window;			/* Main window			*/
 
 int server(void);
 
@@ -172,7 +172,6 @@
 
 int server(void)
 {
-    SDL_Rect    **modes;
     char        title[81];
 
     /* 
@@ -182,27 +181,33 @@
 	syslog(LOG_NOTICE, "[main] could not initialize SDL: %s", SDL_GetError());
 	exit(-1);
     }
+    if ((TTF_Init() < 0)) {
+        syslog(LOG_NOTICE, "[main] SDL_ttf could not initialize! SDL_ttf Error: %s", TTF_GetError());
+        exit(-1);
+    }
+    SDLGui_Init();
 
-    modes = SDL_ListModes(NULL, SDL_FULLSCREEN);
-    if (modes != (SDL_Rect **)0) {
-	/* Check if our resolution is restricted */
-	if (modes == (SDL_Rect **)-1) {
-	    syslog(LOG_NOTICE, "SDL all resolutions available.\n");
-	}
+    /*
+     * Get available fullscreen modes, so we will get the effective screensize
+     */
+    SDL_DisplayMode modes = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 };
+    if (SDL_GetDisplayMode(0, 0, &modes) != 0) {
+        syslog(LOG_NOTICE, "[main] SDL_GetDisplayMode failed: %s", SDL_GetError());
+        exit(-1);
     }
 
     PAN_x = 384;
     PAN_y = 480;
 
-    PAN_surface = SDL_SetVideoMode( PAN_x, PAN_y, 32, SDL_SWSURFACE|SDL_DOUBLEBUF );
-    if (PAN_surface == NULL) {
-	syslog(LOG_NOTICE, "Could not create main surface: %s", SDL_GetError());
+    snprintf(title, 80, "brewpanel v%s", VERSION);
+    S_window = SDL_CreateWindow(title, 0, 0, PAN_x, PAN_y, SDL_WINDOW_OPENGL);
+
+    S_screen = SDL_GetWindowSurface(S_window);
+    if (S_screen == NULL) {
+	syslog(LOG_NOTICE, "Could not create S_screen: %s", SDL_GetError());
 	exit(-1);
     }
 
-    SDLGui_Init();
-    snprintf(title, 80, "brewpanel v%s", VERSION);
-    SDL_WM_SetCaption(title, NULL);
 
     syslog(LOG_NOTICE, "Starting mainloop");
     if (strlen(Paneltype) && !strcmp(Paneltype, (char *)"ferm") ) {
@@ -213,7 +218,7 @@
     syslog(LOG_NOTICE, "Out of mainloop, cleanup");
 
     SDLGui_UnInit();
-    SDL_FreeSurface(PAN_surface);
+    SDL_FreeSurface(S_screen);
     SDL_Quit();
 
     return 0;

mercurial