rnd-20140108-1-src
authorHolger Schemel <info@artsoft.org>
Wed, 8 Jan 2014 00:06:28 +0000 (01:06 +0100)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 09:00:32 +0000 (11:00 +0200)
* fixed problems related to fullscreen switching and window scaling
* fixed inconsistent custom artwork contant numbering in src/main.h,
  src/screen.c and src/conf_gfx.c (this really should be cleaned up)
  (this bug caused custom artwork definition to set wrong variable)

14 files changed:
ChangeLog
src/conf_gfx.c
src/conf_var.c
src/conftime.h
src/events.c
src/events.h
src/init.c
src/libgame/sdl.c
src/libgame/sdl.h
src/libgame/system.c
src/libgame/system.h
src/main.h
src/screens.c
src/tools.c

index 161577373a3678d7313b6580eee99cff265653a0..e04626b79bbb645ff3ae35f55ec3293f56eda66a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2014-01-07
+       * fixed problems related to fullscreen switching and window scaling
+
+2014-01-06
+       * fixed inconsistent custom artwork contant numbering in src/main.h,
+         src/screen.c and src/conf_gfx.c (this really should be cleaned up)
+         (this bug caused custom artwork definition to set wrong variable)
+
 2014-01-05
        * fixed using fullscreen mode on Android instead of pseudo-window mode
        * fixed keeping desktop fullscreen mode when changing viewport size
index c9fe38cd22a7d03356bf8e355905d250b0eb8a29..5e81ef42181a0b217bbdad23c43d859029799b65 100644 (file)
@@ -5611,6 +5611,8 @@ struct ConfigInfo image_config[] =
   { "menu.draw_yoffset.SETUP[SHORTCUTS_3]",    "0"                     },
   { "menu.draw_xoffset.SETUP[SHORTCUTS_4]",    "0"                     },
   { "menu.draw_yoffset.SETUP[SHORTCUTS_4]",    "0"                     },
+  { "menu.draw_xoffset.SETUP[SHORTCUTS_5]",    "0"                     },
+  { "menu.draw_yoffset.SETUP[SHORTCUTS_5]",    "0"                     },
   { "menu.draw_xoffset.SETUP[CHOOSE_ARTWORK]", "0"                     },
   { "menu.draw_yoffset.SETUP[CHOOSE_ARTWORK]", "0"                     },
   { "menu.draw_xoffset.SETUP[CHOOSE_OTHER]",   "0"                     },
index 059f3db6c20221ad6d1c12127394278051c6af05..e09bb0ff3653109438fff1d05e2bf4d63a60ce78 100644 (file)
@@ -1340,6 +1340,14 @@ struct TokenIntPtrInfo image_config_vars[] =
     "menu.draw_yoffset.SETUP[SHORTCUTS_4]",
     &menu.draw_yoffset_setup[GFX_SPECIAL_ARG_SETUP_SHORTCUTS_4]
   },
+  {
+    "menu.draw_xoffset.SETUP[SHORTCUTS_5]",
+    &menu.draw_xoffset_setup[GFX_SPECIAL_ARG_SETUP_SHORTCUTS_5]
+  },
+  {
+    "menu.draw_yoffset.SETUP[SHORTCUTS_5]",
+    &menu.draw_yoffset_setup[GFX_SPECIAL_ARG_SETUP_SHORTCUTS_5]
+  },
   {
     "menu.draw_xoffset.SETUP[CHOOSE_ARTWORK]",
     &menu.draw_xoffset_setup[GFX_SPECIAL_ARG_SETUP_CHOOSE_ARTWORK]
index 4a66c3900651d024fd2eb8bab9400c70d640ec97..2227c40afcd426c756887871b57f9d59b98004e7 100644 (file)
@@ -1 +1 @@
-#define COMPILE_DATE_STRING "2014-01-05 22:41"
+#define COMPILE_DATE_STRING "2014-01-08 00:59"
index ed910e64d924b89bd826ddecfabeed0207213f69..4bbd8a523c37a5913c49d466111d3757c99b862b 100644 (file)
@@ -162,6 +162,10 @@ void EventLoop(void)
            break;
 
 #if defined(TARGET_SDL2)
+         case SDL_WINDOWEVENT:
+           HandleWindowEvent((WindowEvent *) &event);
+           break;
+
          case EVENT_FINGERPRESS:
          case EVENT_FINGERRELEASE:
          case EVENT_FINGERMOTION:
@@ -388,13 +392,115 @@ void HandleMotionEvent(MotionEvent *event)
 
   motion_status = TRUE;
 
+#if DEBUG_EVENTS
   Error(ERR_DEBUG, "MOTION EVENT: button %d moved, x/y %d/%d\n",
        button_status, event->x, event->y);
+#endif
 
   HandleButton(event->x, event->y, button_status, button_status);
 }
 
 #if defined(TARGET_SDL2)
+void HandleWindowEvent(WindowEvent *event)
+{
+  int subtype = event->event;
+
+  char *event_name =
+    (subtype == SDL_WINDOWEVENT_SHOWN ? "SDL_WINDOWEVENT_SHOWN" :
+     subtype == SDL_WINDOWEVENT_HIDDEN ? "SDL_WINDOWEVENT_HIDDEN" :
+     subtype == SDL_WINDOWEVENT_EXPOSED ? "SDL_WINDOWEVENT_EXPOSED" :
+     subtype == SDL_WINDOWEVENT_MOVED ? "SDL_WINDOWEVENT_MOVED" :
+     subtype == SDL_WINDOWEVENT_SIZE_CHANGED ? "SDL_WINDOWEVENT_SIZE_CHANGED" :
+     subtype == SDL_WINDOWEVENT_RESIZED ? "SDL_WINDOWEVENT_RESIZED" :
+     subtype == SDL_WINDOWEVENT_MINIMIZED ? "SDL_WINDOWEVENT_MINIMIZED" :
+     subtype == SDL_WINDOWEVENT_MAXIMIZED ? "SDL_WINDOWEVENT_MAXIMIZED" :
+     subtype == SDL_WINDOWEVENT_RESTORED ? "SDL_WINDOWEVENT_RESTORED" :
+     subtype == SDL_WINDOWEVENT_ENTER ? "SDL_WINDOWEVENT_ENTER" :
+     subtype == SDL_WINDOWEVENT_LEAVE ? "SDL_WINDOWEVENT_LEAVE" :
+     subtype == SDL_WINDOWEVENT_FOCUS_GAINED ? "SDL_WINDOWEVENT_FOCUS_GAINED" :
+     subtype == SDL_WINDOWEVENT_FOCUS_LOST ? "SDL_WINDOWEVENT_FOCUS_LOST" :
+     subtype == SDL_WINDOWEVENT_CLOSE ? "SDL_WINDOWEVENT_CLOSE" :
+     "(UNKNOWN)");
+
+  Error(ERR_DEBUG, "WINDOW EVENT: '%s', %ld, %ld",
+       event_name, event->data1, event->data2);
+
+  if (event->event == SDL_WINDOWEVENT_EXPOSED)
+    SDLRedrawWindow();
+
+#if 0
+  if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED)
+  {
+    // if game started in fullscreen mode, window will also get fullscreen size
+    if (!video.fullscreen_enabled && video.fullscreen_initial)
+    {
+      SDLSetWindowScaling(setup.window_scaling_percent);
+
+      // only do this correction once
+      video.fullscreen_initial = FALSE;
+    }
+  }
+#endif
+
+  if (event->event == SDL_WINDOWEVENT_RESIZED && !video.fullscreen_enabled)
+  {
+#if 1
+    int new_window_width  = event->data1;
+    int new_window_height = event->data2;
+
+    printf("::: RESIZED from %d, %d to %d, %d\n",
+          video.window_width, video.window_height,
+          new_window_width, new_window_height);
+
+    // if window size has changed after resizing, calculate new scaling factor
+    if (new_window_width  != video.window_width ||
+       new_window_height != video.window_height)
+    {
+      int new_xpercent = (100 * new_window_width  / video.width);
+      int new_ypercent = (100 * new_window_height / video.height);
+
+      setup.window_scaling_percent = video.window_scaling_percent =
+       MIN(MAX(MIN_WINDOW_SCALING_PERCENT, MIN(new_xpercent, new_ypercent)),
+           MAX_WINDOW_SCALING_PERCENT);
+
+      video.window_width  = new_window_width;
+      video.window_height = new_window_height;
+
+      printf("::: setup.window_scaling_percent set to %d\n",
+            setup.window_scaling_percent);
+    }
+#else
+    // prevent slightly wrong scaling factor due to rounding differences
+    float scaling_factor = (float)setup.window_scaling_percent / 100;
+    int old_xsize = (int)(scaling_factor * video.width);
+    int old_ysize = (int)(scaling_factor * video.height);
+    int new_xsize = event->data1;
+    int new_ysize = event->data2;
+
+    // window size is unchanged when going from fullscreen to window mode,
+    // but reverse calculation of scaling factor might result in a scaling
+    // factor that is slightly different due to rounding differences;
+    // therefore compare old/new window size and not old/new scaling factor
+    if (old_xsize != new_xsize ||
+       old_ysize != new_ysize)
+    {
+      int new_xpercent = (100 * new_xsize / video.width);
+      int new_ypercent = (100 * new_ysize / video.height);
+
+      setup.window_scaling_percent = MIN(new_xpercent, new_ypercent);
+
+      if (setup.window_scaling_percent < MIN_WINDOW_SCALING_PERCENT)
+       setup.window_scaling_percent = MIN_WINDOW_SCALING_PERCENT;
+      else if (setup.window_scaling_percent > MAX_WINDOW_SCALING_PERCENT)
+       setup.window_scaling_percent = MAX_WINDOW_SCALING_PERCENT;
+
+      printf("::: setup.window_scaling_percent set to %d\n",
+            setup.window_scaling_percent);
+    }
+#endif
+  }
+}
+
 void HandleFingerEvent(FingerEvent *event)
 {
 #if 0
@@ -640,7 +746,9 @@ void HandleButton(int mx, int my, int button, int button_nr)
   if (IS_WHEEL_BUTTON(button_nr))
     return;
 
+#if 0
   Error(ERR_DEBUG, "::: game_status == %d", game_status);
+#endif
 
   switch (game_status)
   {
@@ -984,6 +1092,31 @@ void HandleKey(Key key, int key_status)
   {
     setup.fullscreen = !setup.fullscreen;
 
+    printf("::: %d\n", setup.window_scaling_percent);
+
+    ToggleFullscreenIfNeeded();
+
+    if (game_status == GAME_MODE_SETUP)
+      RedrawSetupScreenAfterFullscreenToggle();
+
+    return;
+  }
+
+  if ((key == KSYM_minus || key == KSYM_plus || key == KSYM_0) &&
+      (GetKeyModState() & KMOD_Control) && video.window_scaling_available &&
+      !video.fullscreen_enabled)
+  {
+    if (key == KSYM_0)
+      setup.window_scaling_percent = STD_WINDOW_SCALING_PERCENT;
+    else
+      setup.window_scaling_percent +=
+       (key == KSYM_minus ? -1 : +1) * STEP_WINDOW_SCALING_PERCENT;
+
+    if (setup.window_scaling_percent < MIN_WINDOW_SCALING_PERCENT)
+      setup.window_scaling_percent = MIN_WINDOW_SCALING_PERCENT;
+    else if (setup.window_scaling_percent > MAX_WINDOW_SCALING_PERCENT)
+      setup.window_scaling_percent = MAX_WINDOW_SCALING_PERCENT;
+
     ToggleFullscreenIfNeeded();
 
     if (game_status == GAME_MODE_SETUP)
index 7a6a7cb0029c24129749687d74783c797deef2ad..eb19b650e707c8171a20c4192ab82fb786252c5f 100644 (file)
@@ -32,6 +32,7 @@ void HandleExposeEvent(ExposeEvent *);
 void HandleButtonEvent(ButtonEvent *);
 void HandleMotionEvent(MotionEvent *);
 #if defined(TARGET_SDL2)
+void HandleWindowEvent(WindowEvent *);
 void HandleFingerEvent(FingerEvent *);
 void HandleTextEvent(TextEvent *);
 #endif
index ae154457308a300dfd0d161605ca6ed4532379e6..723f8af0e2597b1a5924c86104ed4e365cb0b5f6 100644 (file)
@@ -6316,10 +6316,6 @@ void OpenAll()
 
   InitSetup();
 
-#if 1
-  Error(ERR_INFO, "::: MARK 1: setup.fullscreen == %d", setup.fullscreen);
-#endif
-
   print_timestamp_time("[init setup/config stuff (1)]");
 
   InitGameInfo();
@@ -6344,10 +6340,6 @@ void OpenAll()
 
   print_timestamp_time("[init setup/config stuff]");
 
-#if 1
-  Error(ERR_INFO, "::: MARK 2: setup.fullscreen == %d", setup.fullscreen);
-#endif
-
   InitVideoDisplay();
   InitVideoBuffer(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, setup.fullscreen);
 
index fbac750141434b8f2dbaebbc54056fd53f7de85f..a9fd895907da1116f0c2af362c91c439fabd3ea8 100644 (file)
@@ -393,9 +393,8 @@ static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer,
   SDL_Surface *new_surface = NULL;
   static boolean fullscreen_enabled = FALSE;
 
-  int surface_flags_window = SURFACE_FLAGS;
 #if defined(TARGET_SDL2)
-
+  int surface_flags_window = SURFACE_FLAGS | SDL_WINDOW_RESIZABLE;
 #if USE_DESKTOP_FULLSCREEN
   int surface_flags_fullscreen = SURFACE_FLAGS | SDL_WINDOW_FULLSCREEN_DESKTOP;
 #else
@@ -403,6 +402,7 @@ static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer,
 #endif
 
 #else
+  int surface_flags_window = SURFACE_FLAGS;
   int surface_flags_fullscreen = SURFACE_FLAGS | SDL_FULLSCREEN;
 #endif
 
@@ -411,12 +411,27 @@ static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer,
   int surface_flags = (fullscreen ? surface_flags_fullscreen :
                       surface_flags_window);
 
+  // default window size is unscaled
+  video.window_width  = video.width;
+  video.window_height = video.height;
+
 #if defined(TARGET_SDL2)
 
+  // store if initial screen mode on game start is fullscreen mode
+  if (sdl_window == NULL)
+  {
+    printf("::: GAME STARTS WITH FULLSCREEN %d\n", fullscreen);
+
+    video.fullscreen_initial = fullscreen;
+  }
+
 #if USE_RENDERER
   float window_scaling_factor = (float)setup.window_scaling_percent / 100;
   float screen_scaling_factor = (fullscreen ? 1 : window_scaling_factor);
 
+  video.window_width  = window_scaling_factor * width;
+  video.window_height = window_scaling_factor * height;
+
 #if 1
   printf("::: use window scaling factor %f\n", screen_scaling_factor);
 #endif
@@ -448,18 +463,25 @@ static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer,
     }
   }
 
+#if 0
   Error(ERR_INFO, "::: checking 'sdl_window' ...");
 
   if (sdl_window == NULL)
     Error(ERR_INFO, "::: calling SDL_CreateWindow() [%d, %d, %d] ...",
          setup.fullscreen, fullscreen, fullscreen_enabled);
+#endif
 
   if (sdl_window == NULL)
     sdl_window = SDL_CreateWindow(program.window_title,
                                  SDL_WINDOWPOS_CENTERED,
                                  SDL_WINDOWPOS_CENTERED,
+#if USE_DESKTOP_FULLSCREEN
+                                 video.window_width,
+                                 video.window_height,
+#else
                                  (int)(screen_scaling_factor * width),
                                  (int)(screen_scaling_factor * height),
+#endif
                                  surface_flags);
 
   if (sdl_window != NULL)
@@ -748,7 +770,8 @@ boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen)
   }
 
 #if defined(TARGET_SDL2)
-  UpdateScreen(NULL);          // map window
+  SDLRedrawWindow();                   // map window
+  // UpdateScreen(NULL);               // map window
 #endif
 
 #if 1
@@ -772,6 +795,63 @@ boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen)
   return success;
 }
 
+#if defined(TARGET_SDL2)
+void SDLSetWindowScaling(int window_scaling_percent)
+{
+  if (sdl_window == NULL)
+    return;
+
+  float window_scaling_factor = (float)window_scaling_percent / 100;
+  int new_window_width  = (int)(window_scaling_factor * video.width);
+  int new_window_height = (int)(window_scaling_factor * video.height);
+
+  Error(ERR_DEBUG, "::: SDLSetWindowScaling(%d) ...", window_scaling_percent);
+
+  SDL_SetWindowSize(sdl_window, new_window_width, new_window_height);
+
+  video.window_scaling_percent = window_scaling_percent;
+  video.window_width  = new_window_width;
+  video.window_height = new_window_height;
+}
+
+void SDLSetWindowFullscreen(boolean fullscreen)
+{
+  if (sdl_window == NULL)
+    return;
+
+#if USE_DESKTOP_FULLSCREEN
+  int flags = (fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
+#else
+  int flags = (fullscreen ? SDL_WINDOW_FULLSCREEN : 0);
+#endif
+
+  Error(ERR_DEBUG, "::: SDL_SetWindowFullscreen(%d) ...", fullscreen);
+
+  if (SDL_SetWindowFullscreen(sdl_window, flags) == 0)
+    video.fullscreen_enabled = fullscreen;
+
+  printf("::: SDLSetWindowFullscreen: %d, %d\n",
+        fullscreen, video.fullscreen_initial);
+
+#if 1
+  // if game started in fullscreen mode, window will also get fullscreen size
+  if (!fullscreen && video.fullscreen_initial)
+  {
+    SDLSetWindowScaling(setup.window_scaling_percent);
+    SDL_SetWindowPosition(sdl_window,
+                         SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
+
+    video.fullscreen_initial = FALSE;
+  }
+#endif
+}
+
+void SDLRedrawWindow()
+{
+  UpdateScreen(NULL);
+}
+#endif
+
 void SDLCreateBitmapContent(Bitmap *new_bitmap, int width, int height,
                            int depth)
 {
index 244544d8237311709626b39b6db49c3470d136c6..05ddfed6ac406c974bb368e6bfbbd390d095239e 100644 (file)
@@ -86,6 +86,7 @@ typedef SDL_MouseMotionEvent  MotionEvent;
 #if defined(TARGET_SDL2)
 typedef SDL_TouchFingerEvent   FingerEvent;
 typedef SDL_TextInputEvent     TextEvent;
+typedef SDL_WindowEvent                WindowEvent;
 #endif
 typedef SDL_KeyboardEvent      KeyEvent;
 typedef SDL_Event              ExposeEvent;
@@ -436,6 +437,9 @@ struct MouseCursorInfo
 
 #if defined(TARGET_SDL2)
 SDL_Surface *SDL_DisplayFormat(SDL_Surface *);
+void SDLSetWindowScaling(int);
+void SDLSetWindowFullscreen(boolean);
+void SDLRedrawWindow();
 #endif
 
 void SDLInitVideoDisplay(void);
index 59e5fd61c27c711c46e7a6cd07603505e8c26bc4..b6cdf649725b3fd08feccd44f152430e4a3069ca 100644 (file)
@@ -438,9 +438,7 @@ void CloseVideoDisplay(void)
 
 void InitVideoBuffer(int width, int height, int depth, boolean fullscreen)
 {
-#if 0
-  static boolean initialized = FALSE;
-#endif
+  printf("::: InitVideoBuffer\n");
 
   video.width = width;
   video.height = height;
@@ -448,6 +446,7 @@ void InitVideoBuffer(int width, int height, int depth, boolean fullscreen)
 
   video.fullscreen_available = FULLSCREEN_STATUS;
   video.fullscreen_enabled = FALSE;
+  // video.fullscreen_initial = FALSE;
 #if 0
   video.fullscreen_mode_current = NULL;
   video.fullscreen_modes = NULL;
@@ -455,13 +454,6 @@ void InitVideoBuffer(int width, int height, int depth, boolean fullscreen)
 
   video.window_scaling_available = WINDOW_SCALING_STATUS;
 
-#if 0
-#if defined(PLATFORM_ANDROID)
-  if (!initialized)
-    video.fullscreen_enabled = TRUE;
-#endif
-#endif
-
 #if defined(TARGET_SDL)
   SDLInitVideoBuffer(&backbuffer, &window, fullscreen);
 #else
@@ -469,10 +461,6 @@ void InitVideoBuffer(int width, int height, int depth, boolean fullscreen)
 #endif
 
   drawto = backbuffer;
-
-#if 0
-  initialized = TRUE;
-#endif
 }
 
 inline static void FreeBitmapPointers(Bitmap *bitmap)
index b9f65d149e19f77bffcc2b2aefc5ccc982ec461d..dfa7a4f73cd1af11b0cffa925416f02e14ba9b19 100644 (file)
 #define WINDOW_SCALING_NOT_AVAILABLE   FALSE
 #define WINDOW_SCALING_AVAILABLE       TRUE
 
-#define MIN_WINDOW_SCALING_PERCENT     10
+#define MIN_WINDOW_SCALING_PERCENT     50
 #define STD_WINDOW_SCALING_PERCENT     100
 #define MAX_WINDOW_SCALING_PERCENT     300
+#define STEP_WINDOW_SCALING_PERCENT    10
 
 /* default input keys */
 #define DEFAULT_KEY_LEFT               KSYM_Left
@@ -732,9 +733,11 @@ struct VideoSystemInfo
 {
   int default_depth;
   int width, height, depth;
+  int window_width, window_height;
 
   boolean fullscreen_available;
   boolean fullscreen_enabled;
+  boolean fullscreen_initial;
   struct ScreenModeInfo *fullscreen_modes;
   char *fullscreen_mode_current;
 
index 2bdefb22840470d4259f6e790a6f633ee877b769..ab6d8933ebe6f9aadc2ce57ad71477a9e4b458d1 100644 (file)
 #define NUM_SPECIAL_GFX_INFO_ARGS      8
 
 /* these additional definitions are currently only used for draw offsets */
+/* (must match SETUP_MODE_* values as defined in src/screens.c) */
+/* (should also match corresponding entries in src/conf_gfx.c) */
 #define GFX_SPECIAL_ARG_SETUP_MAIN             0
 #define GFX_SPECIAL_ARG_SETUP_GAME             1
 #define GFX_SPECIAL_ARG_SETUP_EDITOR           2
 #define GFX_SPECIAL_ARG_SETUP_SHORTCUTS_2      9
 #define GFX_SPECIAL_ARG_SETUP_SHORTCUTS_3      10
 #define GFX_SPECIAL_ARG_SETUP_SHORTCUTS_4      11
-#define GFX_SPECIAL_ARG_SETUP_CHOOSE_ARTWORK   12
-#define GFX_SPECIAL_ARG_SETUP_CHOOSE_OTHER     13
+#define GFX_SPECIAL_ARG_SETUP_SHORTCUTS_5      12
+#define GFX_SPECIAL_ARG_SETUP_CHOOSE_ARTWORK   13
+#define GFX_SPECIAL_ARG_SETUP_CHOOSE_OTHER     14
 
-#define NUM_SPECIAL_GFX_SETUP_ARGS             14
+#define NUM_SPECIAL_GFX_SETUP_ARGS             15
 
 
 /* values for image configuration suffixes */
index 3c9d2386f165c1d4166f1f00360ff314ea245db9..1a37d1882977e562bf661b8e2600f97b5bd79a2a 100644 (file)
@@ -38,6 +38,8 @@
 #define MAX_INFO_MODES                 8
 
 /* screens on the setup screen */
+/* (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h) */
+/* (should also match corresponding entries in src/conf_gfx.c) */
 #define SETUP_MODE_MAIN                        0
 #define SETUP_MODE_GAME                        1
 #define SETUP_MODE_EDITOR              2
@@ -6088,8 +6090,39 @@ void DrawSetupScreen()
 
 void RedrawSetupScreenAfterFullscreenToggle()
 {
+#if 0
+  if (setup_mode == SETUP_MODE_GRAPHICS ||
+      setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
+  {
+    if (window_sizes != NULL)
+    {
+      /* set current window size value to configured window size value */
+      window_size_current =
+       getTreeInfoFromIdentifier(window_sizes,
+                                 i_to_a(setup.window_scaling_percent));
+
+      /* if that fails, set current window size to reliable default value */
+      if (window_size_current == NULL)
+       window_size_current =
+         getTreeInfoFromIdentifier(window_sizes,
+                                   i_to_a(STD_WINDOW_SCALING_PERCENT));
+
+      /* if that also fails, set current window size to first available value */
+      if (window_size_current == NULL)
+       window_size_current = window_sizes;
+    }
+
+    setup.window_scaling_percent = atoi(window_size_current->identifier);
+
+    /* needed for displaying window size text instead of identifier */
+    window_size_text = window_size_current->name;
+
+    DrawSetupScreen();
+  }
+#else
   if (setup_mode == SETUP_MODE_GRAPHICS)
     DrawSetupScreen();
+#endif
 }
 
 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
index eefc5cb6152368a04e4f2c29877827c56983c99c..f71aacbdfbf3ffac0001deb2bb9e58100fd3b13c 100644 (file)
@@ -9000,6 +9000,24 @@ void ToggleFullscreenIfNeeded()
   if (!change_window_scaling_percent && !video.fullscreen_available)
     return;
 
+#if defined(TARGET_SDL2)
+  if (change_window_scaling_percent)
+  {
+    SDLSetWindowScaling(setup.window_scaling_percent);
+
+    return;
+  }
+  else if (change_fullscreen)
+  {
+    SDLSetWindowFullscreen(setup.fullscreen);
+
+    /* set setup value according to successfully changed fullscreen mode */
+    setup.fullscreen = video.fullscreen_enabled;
+
+    return;
+  }
+#endif
+
   if (change_fullscreen ||
       change_fullscreen_mode ||
       change_window_scaling_percent)
@@ -9024,7 +9042,7 @@ void ToggleFullscreenIfNeeded()
     /* toggle fullscreen */
     ChangeVideoModeIfNeeded(setup.fullscreen);
 
-    /* set setup value according to successfully enabled fullscreen mode */
+    /* set setup value according to successfully changed fullscreen mode */
     setup.fullscreen = video.fullscreen_enabled;
 
     /* restore backbuffer content from temporary backbuffer backup bitmap */