From 1fae8fb411f1ef9b0ecb2ed0c1b4c2fb87c0d993 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sat, 24 Jun 2023 09:35:22 +0300
Subject: [PATCH 25/25] sdl2: Add GUI_SDL_OPTION() macros

See osdn #48281

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 client/gui-gtk-3.22/gui_main.c |  6 +++---
 client/gui-gtk-4.0/gui_main.c  |  5 +++--
 client/gui-sdl2/graphics.c     |  2 +-
 client/gui-sdl2/gui_main.c     | 29 ++++++++++++++++-------------
 client/gui-sdl2/gui_main.h     |  3 +++
 client/gui-sdl2/gui_mouse.c    | 26 ++++++++++++++------------
 client/gui-sdl2/themes.c       |  3 ++-
 client/gui-sdl2/themespec.c    | 30 +++++++++++++++++-------------
 8 files changed, 59 insertions(+), 45 deletions(-)

diff --git a/client/gui-gtk-3.22/gui_main.c b/client/gui-gtk-3.22/gui_main.c
index 10292b7ba2..39943071f8 100644
--- a/client/gui-gtk-3.22/gui_main.c
+++ b/client/gui-gtk-3.22/gui_main.c
@@ -2498,14 +2498,14 @@ static void apply_reqtree_text_font(struct option *poption)
 **************************************************************************/
 void options_extra_init(void)
 {
-
   struct option *poption;
 
 #define option_var_set_callback(var, callback)                              \
-  if ((poption = optset_option_by_name(client_optset, GUI_GTK_OPTION_STR(var)))) { \
+  if ((poption = optset_option_by_name(client_optset,                       \
+                                       GUI_GTK_OPTION_STR(var)))) {         \
     option_set_changed_callback(poption, callback);                         \
   } else {                                                                  \
-    log_error("Didn't find option %s!", GUI_GTK_OPTION_STR(var));      \
+    log_error("Didn't find option %s!", GUI_GTK_OPTION_STR(var));           \
   }
 
   option_var_set_callback(allied_chat_only,
diff --git a/client/gui-gtk-4.0/gui_main.c b/client/gui-gtk-4.0/gui_main.c
index e730326569..f2b4f56bfe 100644
--- a/client/gui-gtk-4.0/gui_main.c
+++ b/client/gui-gtk-4.0/gui_main.c
@@ -2503,10 +2503,11 @@ void options_extra_init(void)
   struct option *poption;
 
 #define option_var_set_callback(var, callback)                              \
-  if ((poption = optset_option_by_name(client_optset, GUI_GTK_OPTION_STR(var)))) { \
+  if ((poption = optset_option_by_name(client_optset,                       \
+                                       GUI_GTK_OPTION_STR(var)))) {         \
     option_set_changed_callback(poption, callback);                         \
   } else {                                                                  \
-    log_error("Didn't find option %s!", GUI_GTK_OPTION_STR(var));      \
+    log_error("Didn't find option %s!", GUI_GTK_OPTION_STR(var));           \
   }
 
   option_var_set_callback(allied_chat_only,
diff --git a/client/gui-sdl2/graphics.c b/client/gui-sdl2/graphics.c
index 219feba8bf..6936d91051 100644
--- a/client/gui-sdl2/graphics.c
+++ b/client/gui-sdl2/graphics.c
@@ -580,7 +580,7 @@ bool create_surfaces(int width, int height)
     return FALSE;
   }
 
-  if (gui_options.gui_sdl2_swrenderer
+  if (GUI_SDL_OPTION(swrenderer)
       || (sdl2_client_flags & CF_SWRENDERER)) {
     flags = SDL_RENDERER_SOFTWARE;
   } else {
diff --git a/client/gui-sdl2/gui_main.c b/client/gui-sdl2/gui_main.c
index 2b190322fc..1e120f60af 100644
--- a/client/gui-sdl2/gui_main.c
+++ b/client/gui-sdl2/gui_main.c
@@ -187,14 +187,15 @@ static void parse_options(int argc, char **argv)
       print_usage();
       exit(EXIT_SUCCESS);
     } else if (is_option("--fullscreen", argv[i])) {
-      gui_options.gui_sdl2_fullscreen = TRUE;
+      GUI_SDL_OPTION(fullscreen) = TRUE;
     } else if (is_option("--swrenderer", argv[i])) {
       sdl2_client_flags |= CF_SWRENDERER;
     } else if ((option = get_option_malloc("--theme", argv, &i, argc, FALSE))) {
-      sz_strlcpy(gui_options.gui_sdl2_default_theme_name, option);
+      sz_strlcpy(GUI_SDL_OPTION(default_theme_name), option);
       free(option);
     } else {
       fc_fprintf(stderr, _("Unrecognized option: \"%s\"\n"), argv[i]);
+
       exit(EXIT_FAILURE);
     }
 
@@ -430,7 +431,7 @@ static Uint16 main_mouse_motion_handler(SDL_MouseMotionEvent *motion_event,
   }
 
 #ifndef UNDER_CE
-  if (gui_options.gui_sdl2_fullscreen) {
+  if (GUI_SDL_OPTION(fullscreen)) {
     check_scroll_area(motion_event->x, motion_event->y);
   }
 #endif /* UNDER_CE */
@@ -909,7 +910,7 @@ static void fullscreen_callback(struct option *poption)
 {
   SDL_DisplayMode mode;
 
-  if (gui_options.gui_sdl2_fullscreen) {
+  if (GUI_SDL_OPTION(fullscreen)) {
     SDL_SetWindowFullscreen(main_data.screen, SDL_WINDOW_FULLSCREEN_DESKTOP);
   } else {
     SDL_SetWindowFullscreen(main_data.screen, 0);
@@ -919,7 +920,7 @@ static void fullscreen_callback(struct option *poption)
 
   if (!create_surfaces(mode.w, mode.h)) {
     /* Try to revert */
-    if (!gui_options.gui_sdl2_fullscreen) {
+    if (!GUI_SDL_OPTION(fullscreen)) {
       SDL_SetWindowFullscreen(main_data.screen, SDL_WINDOW_FULLSCREEN_DESKTOP);
     } else {
       SDL_SetWindowFullscreen(main_data.screen, 0);
@@ -938,14 +939,15 @@ void options_extra_init(void)
   struct option *poption;
 
 #define option_var_set_callback(var, callback)                              \
-  if ((poption = optset_option_by_name(client_optset, #var))) {             \
+  if ((poption = optset_option_by_name(client_optset,                       \
+                                       GUI_SDL_OPTION_STR(var)))) {         \
     option_set_changed_callback(poption, callback);                         \
   } else {                                                                  \
-    log_error("Didn't find option %s!", #var);                              \
+    log_error("Didn't find option %s!", GUI_SDL_OPTION_STR(var));           \
   }
 
-  option_var_set_callback(gui_sdl2_fullscreen, fullscreen_callback);
-  option_var_set_callback(gui_sdl2_screen, resize_window_callback);
+  option_var_set_callback(fullscreen, fullscreen_callback);
+  option_var_set_callback(screen, resize_window_callback);
 #undef option_var_set_callback
 }
 
@@ -957,7 +959,7 @@ static void clear_double_messages_call(void)
 {
   int i;
 
-  /* clear double call */
+  /* Clear double call */
   for (i = 0; i <= event_type_max(); i++) {
     if (messages_where[i] & MW_MESSAGES) {
       messages_where[i] &= ~MW_OUTPUT;
@@ -1014,14 +1016,15 @@ int ui_main(int argc, char *argv[])
     migrate_options_from_sdl();
   }
 
-  if (gui_options.gui_sdl2_fullscreen) {
+  if (GUI_SDL_OPTION(fullscreen)) {
     flags |= SDL_WINDOW_FULLSCREEN;
   } else {
     flags &= ~SDL_WINDOW_FULLSCREEN;
   }
+
   log_normal(_("Using Video Output: %s"), SDL_GetCurrentVideoDriver());
-  if (!set_video_mode(gui_options.gui_sdl2_screen.width,
-                      gui_options.gui_sdl2_screen.height,
+  if (!set_video_mode(GUI_SDL_OPTION(screen.width),
+                      GUI_SDL_OPTION(screen.height),
                       flags)) {
     return EXIT_FAILURE;
   }
diff --git a/client/gui-sdl2/gui_main.h b/client/gui-sdl2/gui_main.h
index f7be12da7f..2f4fc5e0c3 100644
--- a/client/gui-sdl2/gui_main.h
+++ b/client/gui-sdl2/gui_main.h
@@ -32,6 +32,9 @@
 /* client/include */
 #include "gui_main_g.h"
 
+#define GUI_SDL_OPTION(optname) gui_options.gui_sdl2_##optname
+#define GUI_SDL_OPTION_STR(optname) "gui_sdl2_" #optname
+
 /* Enable this to adjust sizes for 320x240 resolution */
 /* #define GUI_SDL2_SMALL_SCREEN */
 
diff --git a/client/gui-sdl2/gui_mouse.c b/client/gui-sdl2/gui_mouse.c
index f0feac5b96..5c879666d5 100644
--- a/client/gui-sdl2/gui_mouse.c
+++ b/client/gui-sdl2/gui_mouse.c
@@ -103,8 +103,8 @@ void draw_mouse_cursor(void)
   int cursor_y = 0;
   static SDL_Rect area = {0, 0, 0, 0};
 
-  if (gui_options.gui_sdl2_use_color_cursors) {
-    /* restore background */
+  if (GUI_SDL_OPTION(use_color_cursors)) {
+    /* Restore background */
     if (area.w != 0) {
       flush_rect(&area, TRUE);
     }
@@ -116,9 +116,9 @@ void draw_mouse_cursor(void)
       area.w = current_color_cursor.cursor->w;
       area.h = current_color_cursor.cursor->h;
 
-      /* show cursor */
+      /* Show cursor */
       screen_blit(current_color_cursor.cursor, NULL, &area, 255);
-      /* update screen */
+      /* Update screen */
       update_main_screen();
 #if 0
       SDL_UpdateRect(main_data.screen, area.x, area.y, area.w, area.h);
@@ -188,16 +188,18 @@ void animate_mouse_cursor(void)
   }
 
   if (mouse_cursor_type != CURSOR_DEFAULT) {
-    if (!gui_options.gui_sdl2_do_cursor_animation
+    if (!GUI_SDL_OPTION(do_cursor_animation)
         || (cursor_frame == NUM_CURSOR_FRAMES)) {
       cursor_frame = 0;
     }
 
-    if (gui_options.gui_sdl2_use_color_cursors) {
-      current_color_cursor.cursor = GET_SURF(get_cursor_sprite(tileset,
-                                    mouse_cursor_type,
-                                    &current_color_cursor.hot_x,
-                                    &current_color_cursor.hot_y, cursor_frame));
+    if (GUI_SDL_OPTION(use_color_cursors)) {
+      current_color_cursor.cursor
+        = GET_SURF(get_cursor_sprite(tileset,
+                                     mouse_cursor_type,
+                                     &current_color_cursor.hot_x,
+                                     &current_color_cursor.hot_y,
+                                     cursor_frame));
     } else {
       SDL_SetCursor(fc_cursors[mouse_cursor_type][cursor_frame]);
     }
@@ -219,12 +221,12 @@ void update_mouse_cursor(enum cursor_type new_cursor_type)
 
   if (mouse_cursor_type == CURSOR_DEFAULT) {
     SDL_SetCursor(std_cursor);
-    if (gui_options.gui_sdl2_use_color_cursors) {
+    if (GUI_SDL_OPTION(use_color_cursors)) {
       current_color_cursor.cursor = NULL;
     }
     mouse_cursor_changed = FALSE;
   } else {
-    if (gui_options.gui_sdl2_use_color_cursors) {
+    if (GUI_SDL_OPTION(use_color_cursors)) {
       SDL_SetCursor(disabled_cursor);
     }
     mouse_cursor_changed = TRUE;
diff --git a/client/gui-sdl2/themes.c b/client/gui-sdl2/themes.c
index 768d62e99d..95b6ca1ccf 100644
--- a/client/gui-sdl2/themes.c
+++ b/client/gui-sdl2/themes.c
@@ -65,10 +65,11 @@ void gui_load_theme(const char *directory, const char *theme_name)
 *****************************************************************************/
 void gui_clear_theme(void)
 {
-  if (!load_theme(gui_options.gui_sdl2_default_theme_name)) {
+  if (!load_theme(GUI_SDL_OPTION(default_theme_name))) {
     /* TRANS: No full stop after the URL, could cause confusion. */
     log_fatal(_("No Sdl2-client theme was found. For instructions on how to "
                 "get one, please visit %s"), HOMEPAGE_URL);
+
     exit(EXIT_FAILURE);
   }
 }
diff --git a/client/gui-sdl2/themespec.c b/client/gui-sdl2/themespec.c
index a30fd911d9..f424ca3f9a 100644
--- a/client/gui-sdl2/themespec.c
+++ b/client/gui-sdl2/themespec.c
@@ -351,21 +351,24 @@ void themespec_try_read(const char *theme_name)
 
     if (active_theme == NULL) {
       log_fatal(_("No usable default theme found, aborting!"));
+
       exit(EXIT_FAILURE);
     }
 
     log_verbose("Trying theme \"%s\".", active_theme->name);
   }
-/*  sz_strlcpy(gui_sdl2_default_theme_name, theme_get_name(theme));*/
+
+  /*  sz_strlcpy(GUI_SDL_OPTION(default_theme_name),
+                 theme_get_name(theme)); */
 }
 
 /************************************************************************//**
   Read a new themespec in from scratch.
 
   Unlike the initial reading code, which reads pieces one at a time,
-  this gets rid of the old data and reads in the new all at once.  If the
-  new theme fails to load the old theme may be reloaded; otherwise the
-  client will exit.  If a NULL name is given the current theme will be
+  this gets rid of the old data and reads in the new all at once.
+  If the new theme fails to load the old theme may be reloaded; otherwise
+  the client will exit. If a NULL name is given the current theme will be
   reread.
 
   It will also call the necessary functions to redraw the graphics.
@@ -398,7 +401,7 @@ void themespec_reread(const char *new_theme_name)
 
   /* Step 2:  Read.
    *
-   * We read in the new theme.  This should be pretty straightforward.
+   * We read in the new theme. This should be pretty straightforward.
    */
   if (!(active_theme = theme_read_toplevel(theme_name))) {
     if (!(active_theme = theme_read_toplevel(old_name))) {
@@ -407,21 +410,22 @@ void themespec_reread(const char *new_theme_name)
                          "Failed to re-read the currently loaded theme.");
     }
   }
-/*  sz_strlcpy(gui_sdl2_default_theme_name, theme->name);*/
+  /* sz_strlcpy(GUI_SDL_OPTION(default_theme_name), theme->name); */
+
   theme_load_sprites(active_theme);
 
   /* Step 3: Setup
    *
-   * This is a seriously sticky problem.  On startup, we build a hash
+   * This is a seriously sticky problem. On startup, we build a hash
    * from all the sprite data. Then, when we connect to a server, the
    * server sends us ruleset data a piece at a time and we use this data
-   * to assemble the sprite structures.  But if we change while connected
-   *  we have to reassemble all of these.  This should just involve
-   * calling themespec_setup_*** on everything.  But how do we tell what
+   * to assemble the sprite structures. But if we change while connected
+   *  we have to reassemble all of these. This should just involve
+   * calling themespec_setup_*** on everything. But how do we tell what
    * "everything" is?
    *
    * The below code just does things straightforwardly, by setting up
-   * each possible sprite again.  Hopefully it catches everything, and
+   * each possible sprite again. Hopefully it catches everything, and
    * doesn't mess up too badly if we change themes while not connected
    * to a server.
    */
@@ -439,8 +443,8 @@ void themespec_reread(const char *new_theme_name)
 /*  theme_changed();*/
   can_slide = FALSE;
   center_tile_mapcanvas(center_tile);
-  /* update_map_canvas_visible forces a full redraw.  Otherwise with fast
-   * drawing we might not get one.  Of course this is slower. */
+  /* update_map_canvas_visible() forces a full redraw. Otherwise with fast
+   * drawing we might not get one. Of course this is slower. */
   update_map_canvas_visible();
   can_slide = TRUE;
 }
-- 
2.40.1