rnd-20140117-2-src
[rocksndiamonds.git] / src / screens.c
index 2392bcf0a159648444733d651b82ce164d379e61..23950185c844134ff1c5927f43f3337762cc2e0c 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
 /* sub-screens on the setup screen (specific) */
 #define SETUP_MODE_CHOOSE_GAME_SPEED   15
 #define SETUP_MODE_CHOOSE_SCREEN_MODE  16
-#define SETUP_MODE_CHOOSE_SCROLL_DELAY 17
-#define SETUP_MODE_CHOOSE_GRAPHICS     18
-#define SETUP_MODE_CHOOSE_SOUNDS       19
-#define SETUP_MODE_CHOOSE_MUSIC                20
-#define SETUP_MODE_CHOOSE_VOLUME_SIMPLE        21
-#define SETUP_MODE_CHOOSE_VOLUME_LOOPS 22
-#define SETUP_MODE_CHOOSE_VOLUME_MUSIC 23
+#define SETUP_MODE_CHOOSE_WINDOW_SIZE  17
+#define SETUP_MODE_CHOOSE_SCROLL_DELAY 18
+#define SETUP_MODE_CHOOSE_GRAPHICS     19
+#define SETUP_MODE_CHOOSE_SOUNDS       20
+#define SETUP_MODE_CHOOSE_MUSIC                21
+#define SETUP_MODE_CHOOSE_VOLUME_SIMPLE        22
+#define SETUP_MODE_CHOOSE_VOLUME_LOOPS 23
+#define SETUP_MODE_CHOOSE_VOLUME_MUSIC 24
 
-#define MAX_SETUP_MODES                        24
+#define MAX_SETUP_MODES                        25
 
 /* for input setup functions */
 #define SETUPINPUT_SCREEN_POS_START    0
@@ -174,6 +177,9 @@ static int setup_mode = SETUP_MODE_MAIN;
 static TreeInfo *screen_modes = NULL;
 static TreeInfo *screen_mode_current = NULL;
 
+static TreeInfo *window_sizes = NULL;
+static TreeInfo *window_size_current = NULL;
+
 static TreeInfo *scroll_delays = NULL;
 static TreeInfo *scroll_delay_current = NULL;
 
@@ -192,6 +198,28 @@ static TreeInfo *volume_music_current = NULL;
 static TreeInfo *level_number = NULL;
 static TreeInfo *level_number_current = NULL;
 
+static struct
+{
+  int value;
+  char *text;
+} window_sizes_list[] =
+{
+  {    50,     "50 %"                          },
+  {    80,     "80 %"                          },
+  {    90,     "90 %"                          },
+  {    100,    "100 % (Default)"               },
+  {    110,    "110 %"                         },
+  {    120,    "120 %"                         },
+  {    130,    "130 %"                         },
+  {    140,    "140 %"                         },
+  {    150,    "150 %"                         },
+  {    200,    "200 %"                         },
+  {    250,    "250 %"                         },
+  {    300,    "300 %"                         },
+
+  {    -1,     NULL                            },
+};
+
 static struct
 {
   int value;
@@ -1289,6 +1317,8 @@ void DrawMainMenuExt(int fade_mask, boolean do_fading)
   static LevelDirTree *leveldir_last_valid = NULL;
   boolean levelset_has_changed = FALSE;
 
+  LimitScreenUpdates(FALSE);
+
   FadeSetLeaveScreen();
 
   /* do not fade out here -- function may continue and fade on editor screen */
@@ -1316,7 +1346,8 @@ void DrawMainMenuExt(int fade_mask, boolean do_fading)
   }
 
   /* needed if last screen was the setup screen and fullscreen state changed */
-  ToggleFullscreenIfNeeded();
+  // (moved to "execSetupGraphics()" to change fullscreen state directly)
+  // ToggleFullscreenOrChangeWindowScalingIfNeeded();
 
   /* leveldir_current may be invalid (level group, parent link) */
   if (!validLevelSeries(leveldir_current))
@@ -1390,7 +1421,7 @@ void DrawMainMenuExt(int fade_mask, boolean do_fading)
   InitializeMainControls();
 
   DrawCursorAndText_Main(-1, FALSE);
-  DrawPreviewLevel(TRUE);
+  DrawPreviewLevelInitial();
 
   HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
 
@@ -1729,13 +1760,13 @@ void HandleMainMenu_SelectLevel(int step, int direction)
             mci->pos_text->font);
 
     LoadLevel(level_nr);
-    DrawPreviewLevel(TRUE);
+    DrawPreviewLevelInitial();
 
     TapeErase();
     LoadTape(level_nr);
     DrawCompleteVideoDisplay();
 
-    /* needed because DrawPreviewLevel() takes some time */
+    /* needed because DrawPreviewLevelInitial() takes some time */
     BackToFront();
     SyncDisplay();
   }
@@ -1898,11 +1929,13 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
     }
   }
 
+#if 0
   if (game_status == GAME_MODE_MAIN)
   {
-    DrawPreviewLevel(FALSE);
+    DrawPreviewLevelAnimation();
     DoAnimation();
   }
+#endif
 }
 
 
@@ -2964,19 +2997,17 @@ void DrawInfoScreen_Version()
   int ystart1 = mSY - SY + 100;
   int ystart2 = mSY - SY + 150;
   int ybottom = mSY - SY + SYSIZE - 20;
-  int xstart1 = mSX + 2 * xstep;
-  int xstart2 = mSX + 19 * xstep;
+  int xstart1 = mSX - SX + 2 * xstep;
+  int xstart2 = mSX - SX + 18 * xstep;
 #if defined(TARGET_SDL)
-  int xstart3 = mSX + 29 * xstep;
+  int xstart3 = mSX - SX + 28 * xstep;
   SDL_version sdl_version_compiled;
-#if defined(TARGET_SDL2)
-  SDL_version sdl_version_linked_ext;
-#endif
   const SDL_version *sdl_version_linked;
+  int driver_name_len = 10;
 #if defined(TARGET_SDL2)
+  SDL_version sdl_version_linked_ext;
   const char *driver_name = NULL;
 #else
-  int driver_name_len = 8;
   char driver_name[driver_name_len];
 #endif
 #endif
@@ -3084,7 +3115,7 @@ void DrawInfoScreen_Version()
   DrawTextF(xstart3, ystart2, font_header, "Used");
 
 #if defined(TARGET_SDL2)
-  driver_name = SDL_GetVideoDriver(0);
+  driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
 #else
   SDL_VideoDriverName(driver_name, driver_name_len);
 #endif
@@ -3095,7 +3126,7 @@ void DrawInfoScreen_Version()
   DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
 
 #if defined(TARGET_SDL2)
-  driver_name = SDL_GetAudioDriver(0);
+  driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
 #else
   SDL_AudioDriverName(driver_name, driver_name_len);
 #endif
@@ -3277,7 +3308,9 @@ void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
   else
     HandleInfoScreen_Main(mx, my, dx, dy, button);
 
+#if 0
   DoAnimation();
+#endif
 }
 
 
@@ -3590,6 +3623,7 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
       if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
        execSetupGame();
       else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
+              setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
               setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
        execSetupGraphics();
       else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
@@ -3760,7 +3794,11 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
       }
       else
       {
+#if 1
+       FadeSetEnterMenu();
+#else
        FadeSetEnterScreen();
+#endif
 
        node_cursor->cl_first = ti->cl_first;
        node_cursor->cl_cursor = ti->cl_cursor;
@@ -3780,6 +3818,7 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
          if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
            execSetupGame();
          else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
+                  setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
                   setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
            execSetupGraphics();
          else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
@@ -3817,7 +3856,9 @@ void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
 {
   HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
 
+#if 0
   DoAnimation();
+#endif
 }
 
 void DrawChooseLevelNr()
@@ -3888,7 +3929,9 @@ void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
   HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
 #endif
 
+#if 0
   DoAnimation();
+#endif
 }
 
 void DrawHallOfFame(int highlight_position)
@@ -4034,7 +4077,9 @@ void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
   if (game_status == GAME_MODE_SCORES)
     PlayMenuSoundIfLoop();
 
+#if 0
   DoAnimation();
+#endif
 }
 
 
@@ -4046,6 +4091,7 @@ static struct TokenInfo *setup_info;
 static int num_setup_info;
 
 static char *screen_mode_text;
+static char *window_size_text;
 static char *scroll_delay_text;
 static char *game_speed_text;
 static char *graphics_set_name;
@@ -4130,9 +4176,95 @@ static void execSetupEditor()
   DrawSetupScreen();
 }
 
-static void execSetupGraphics()
+static void execSetupGraphics_setWindowSizes(boolean update_list)
+{
+  if (window_sizes != NULL && update_list)
+  {
+    freeTreeInfo(window_sizes);
+
+    window_sizes = NULL;
+  }
+
+  if (window_sizes == NULL)
+  {
+    boolean current_window_size_found = FALSE;
+    int i;
+
+    for (i = 0; window_sizes_list[i].value != -1; i++)
+    {
+      TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
+      char identifier[32], name[32];
+      int value = window_sizes_list[i].value;
+      char *text = window_sizes_list[i].text;
+
+      ti->node_top = &window_sizes;
+      ti->sort_priority = value;
+
+      sprintf(identifier, "%d", value);
+      sprintf(name, "%s", text);
+
+      setString(&ti->identifier, identifier);
+      setString(&ti->name, name);
+      setString(&ti->name_sorting, name);
+      setString(&ti->infotext, "Window Scaling");
+
+      pushTreeInfo(&window_sizes, ti);
+
+      if (value == setup.window_scaling_percent)
+       current_window_size_found = TRUE;
+    }
+
+    if (!current_window_size_found)
+    {
+      // add entry for non-preset window scaling value
+
+      TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
+      char identifier[32], name[32];
+      int value = setup.window_scaling_percent;
+
+      ti->node_top = &window_sizes;
+      ti->sort_priority = value;
+
+      sprintf(identifier, "%d", value);
+      sprintf(name, "%d %% (Current)", value);
+
+      setString(&ti->identifier, identifier);
+      setString(&ti->name, name);
+      setString(&ti->name_sorting, name);
+      setString(&ti->infotext, "Window Scaling");
+
+      pushTreeInfo(&window_sizes, ti);
+    }
+
+    /* sort window size values to start with lowest window size value */
+    sortTreeInfo(&window_sizes);
+
+    /* 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;
+}
+
+static void execSetupGraphics_setScreenModes()
 {
-  if (video.fullscreen_available && screen_modes == NULL)
+  // if (screen_modes == NULL && video.fullscreen_available)
+  if (screen_modes == NULL && video.fullscreen_modes != NULL)
   {
     int i;
 
@@ -4180,15 +4312,18 @@ static void execSetupGraphics()
       video.fullscreen_available = FALSE;
   }
 
-  if (video.fullscreen_available)
+  // if (video.fullscreen_available)
+  if (screen_mode_current != NULL)
   {
     setup.fullscreen_mode = screen_mode_current->identifier;
 
     /* needed for displaying screen mode name instead of identifier */
     screen_mode_text = screen_mode_current->name;
   }
+}
 
-#if 1
+static void execSetupGraphics_setScrollDelays()
+{
   if (scroll_delays == NULL)
   {
     int i;
@@ -4235,14 +4370,40 @@ static void execSetupGraphics()
 
   /* needed for displaying scroll delay text instead of identifier */
   scroll_delay_text = scroll_delay_current->name;
-#endif
+}
+
+static void execSetupGraphics()
+{
+  // update "setup.window_scaling_percent" from list selection
+  execSetupGraphics_setWindowSizes(FALSE);
+  // maybe remove non-preset value (if standard value was selected)
+  execSetupGraphics_setWindowSizes(TRUE);
+
+  execSetupGraphics_setScreenModes();
+  execSetupGraphics_setScrollDelays();
 
   setup_mode = SETUP_MODE_GRAPHICS;
 
   DrawSetupScreen();
+
+  // window scaling may have changed at this point
+  ToggleFullscreenOrChangeWindowScalingIfNeeded();
 }
 
-#if !defined(TARGET_SDL2)
+#if !defined(PLATFORM_ANDROID)
+#if defined(TARGET_SDL2)
+static void execSetupChooseWindowSize()
+{
+#if 0
+  if (!video.window_scaling_available)
+    return;
+#endif
+
+  setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
+
+  DrawSetupScreen();
+}
+#else
 static void execSetupChooseScreenMode()
 {
   if (!video.fullscreen_available)
@@ -4253,6 +4414,7 @@ static void execSetupChooseScreenMode()
   DrawSetupScreen();
 }
 #endif
+#endif
 
 static void execSetupChooseScrollDelay()
 {
@@ -4602,11 +4764,16 @@ static struct TokenInfo setup_info_editor[] =
 
 static struct TokenInfo setup_info_graphics[] =
 {
+#if !defined(PLATFORM_ANDROID)
   { TYPE_SWITCH,       &setup.fullscreen,      "Fullscreen:"           },
-#if !defined(TARGET_SDL2)
+#if defined(TARGET_SDL2)
+  { TYPE_ENTER_LIST,   execSetupChooseWindowSize, "Window Scaling:"    },
+  { TYPE_STRING,       &window_size_text,      ""                      },
+#else
   { TYPE_ENTER_LIST,   execSetupChooseScreenMode, "Fullscreen Mode:"   },
   { TYPE_STRING,       &screen_mode_text,      ""                      },
 #endif
+#endif
 #if 0
   { TYPE_SWITCH,       &setup.scroll_delay,    "Scroll Delay:"         },
 #endif
@@ -5003,6 +5170,10 @@ static void changeSetupValue(int pos, int dx)
   }
 
   drawSetupValue(pos);
+
+  // fullscreen state may have changed at this point
+  if (setup_info[pos].value == &setup.fullscreen)
+    ToggleFullscreenOrChangeWindowScalingIfNeeded();
 }
 
 static void DrawCursorAndText_Setup(int pos, boolean active)
@@ -5127,7 +5298,8 @@ static void DrawSetupScreen_Generic()
        (value_ptr == &setup.sound_loops  && !audio.loops_available) ||
        (value_ptr == &setup.sound_music  && !audio.music_available) ||
        (value_ptr == &setup.fullscreen   && !video.fullscreen_available) ||
-       (value_ptr == &screen_mode_text   && !video.fullscreen_available))
+       (value_ptr == &screen_mode_text   && !video.fullscreen_available) ||
+       (value_ptr == &window_size_text   && !video.window_scaling_available))
       setup_info[i].type |= TYPE_GHOSTED;
 
     if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
@@ -5963,6 +6135,8 @@ void DrawSetupScreen()
     DrawChooseTree(&game_speed_current);
   else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
     DrawChooseTree(&screen_mode_current);
+  else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
+    DrawChooseTree(&window_size_current);
   else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
     DrawChooseTree(&scroll_delay_current);
   else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
@@ -5986,8 +6160,19 @@ void DrawSetupScreen()
 
 void RedrawSetupScreenAfterFullscreenToggle()
 {
+#if 1
+  if (setup_mode == SETUP_MODE_GRAPHICS ||
+      setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
+  {
+    // update "setup.window_scaling_percent" from list selection
+    execSetupGraphics_setWindowSizes(TRUE);
+
+    DrawSetupScreen();
+  }
+#else
   if (setup_mode == SETUP_MODE_GRAPHICS)
     DrawSetupScreen();
+#endif
 }
 
 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
@@ -5998,6 +6183,8 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
     HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
   else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
     HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
+  else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
+    HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
   else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
     HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
   else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
@@ -6015,7 +6202,9 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
   else
     HandleSetupScreen_Generic(mx, my, dx, dy, button);
 
+#if 0
   DoAnimation();
+#endif
 }
 
 void HandleGameActions()