fixed menu display and key navigation bugs
[rocksndiamonds.git] / src / screens.c
index 61cb7106041aa68ad59b2af9b755d9d807d11c3e..9113105623bb2c561b841b6445cba65e6266b5d0 100644 (file)
@@ -411,6 +411,9 @@ static struct
                                    menu.list_size[game_status] :       \
                                    MAX_MENU_ENTRIES_ON_SCREEN)
 
+#define IN_VIS_MENU(x, y)      IN_FIELD(x, y, SCR_FIELDX,              \
+                                        NUM_MENU_ENTRIES_ON_SCREEN)
+
 
 /* title display and control definitions */
 
@@ -2046,7 +2049,7 @@ void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
       y += dy;
   }
 
-  if (IN_VIS_FIELD(x, y) &&
+  if (IN_VIS_MENU(x, y) &&
       y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
   {
     if (button)
@@ -2620,7 +2623,7 @@ static void DrawInfoScreen_CreditsScreen(int screen_nr)
     DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
                      "and");
     DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
-                     "Jürgen Bonhagen");
+                     "J\xfcrgen Bonhagen");
     DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
                      "for the continuous creation");
     DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
@@ -2674,7 +2677,7 @@ static void DrawInfoScreen_CreditsScreen(int screen_nr)
     DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
                      "Thanks to");
     DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
-                     "Karl Hörnell");
+                     "Karl H\xf6rnell");
     DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
                      "for some additional toons");
   }
@@ -3159,6 +3162,10 @@ void HandleTypeName(int newxpos, Key key)
     strcpy(last_player_name, setup.player_name);
 
     xpos = newxpos;
+
+#if defined(TARGET_SDL2)
+    SDL_StartTextInput();
+#endif
   }
   else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
   {
@@ -3204,6 +3211,10 @@ void HandleTypeName(int newxpos, Key key)
     startx = mSX + ALIGNED_TEXT_XPOS(pos);
 
     DrawText(startx, starty, setup.player_name, font_nr);
+
+#if defined(TARGET_SDL2)
+    SDL_StopTextInput();
+#endif
   }
 }
 
@@ -3252,6 +3263,19 @@ static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
                  first_entry);
 }
 
+static void clearMenuListArea()
+{
+  int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
+
+  /* correct scrollbar position if placed outside menu (playfield) area */
+  if (scrollbar_xpos > SC_SCROLLBAR_XPOS)
+    scrollbar_xpos = SC_SCROLLBAR_XPOS;
+
+  /* clear menu list area, but not title or scrollbar */
+  DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
+                 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
+}
+
 static void drawChooseTreeList(int first_entry, int num_page_entries,
                               TreeInfo *ti)
 {
@@ -3267,10 +3291,7 @@ static void drawChooseTreeList(int first_entry, int num_page_entries,
 
   DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
 
-  /* clear tree list area, but not title or scrollbar */
-  DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
-                SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
-                NUM_MENU_ENTRIES_ON_SCREEN * 32);
+  clearMenuListArea();
 
   for (i = 0; i < num_page_entries; i++)
   {
@@ -3540,7 +3561,7 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
   }
 
   if (!anyScrollbarGadgetActive() &&
-      IN_VIS_FIELD(x, y) &&
+      IN_VIS_MENU(x, y) &&
       mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
       y >= 0 && y < num_page_entries)
   {
@@ -3763,7 +3784,7 @@ static void drawHallOfFameList(int first_entry, int highlight_position)
     int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
     int dx1 = 3 * getFontWidth(font_nr1);
     int dx2 = dx1 + getFontWidth(font_nr1);
-    int dx3 = SXSIZE - 5 * getFontWidth(font_nr4);
+    int dx3 = SXSIZE - 2 * (mSX - SX) - 5 * getFontWidth(font_nr4);
     int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
     int sy = mSY + 64 + i * 32;
 
@@ -4638,12 +4659,14 @@ static void execSetupChooseMusic()
   DrawSetupScreen();
 }
 
+#if !defined(PLATFORM_ANDROID)
 static void execSetupInput()
 {
   setup_mode = SETUP_MODE_INPUT;
 
   DrawSetupScreen();
 }
+#endif
 
 static void execSetupShortcuts()
 {
@@ -5221,10 +5244,7 @@ static void drawSetupInfoList(struct TokenInfo *setup_info,
   if (first_entry + num_page_entries > max_setup_info)
     first_entry = 0;
 
-  /* clear tree list area, but not title or scrollbar */
-  DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
-                 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
-                 NUM_MENU_ENTRIES_ON_SCREEN * 32);
+  clearMenuListArea();
 
   for (i = 0; i < num_page_entries; i++)
   {
@@ -5344,10 +5364,12 @@ static void DrawSetupScreen_Generic()
 
   DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
 
+  // determine maximal number of setup entries that can be displayed on screen
   num_setup_info = 0;
-  for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
+  for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
     num_setup_info++;
 
+  // determine maximal number of setup entries available for this setup screen
   max_setup_info = 0;
   for (i = 0; setup_info[i].type != 0; i++)
     max_setup_info++;
@@ -5541,7 +5563,7 @@ void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
           setup_info[first_entry + y].type & TYPE_SKIP_ENTRY)
       y += dy;
 
-    if (!IN_VIS_FIELD(x, y))
+    if (!IN_VIS_MENU(x, y))
     {
       choice += y - y_old;
 
@@ -5575,7 +5597,7 @@ void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
   }
 
   if (!anyScrollbarGadgetActive() &&
-      IN_VIS_FIELD(x, y) &&
+      IN_VIS_MENU(x, y) &&
       mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
       y >= 0 && y < num_page_entries)
   {
@@ -5838,7 +5860,7 @@ void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
   {
     HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
   }
-  else if (IN_VIS_FIELD(x, y) &&
+  else if (IN_VIS_FIELD(x, y) &&       // (does not use "IN_VIS_MENU()" yet)
           y >= pos_start && y <= pos_end &&
           !(y >= pos_empty1 && y <= pos_empty2))
   {
@@ -6533,6 +6555,10 @@ static void CreateScreenScrollbuttons()
     width = SC_SCROLLBUTTON_XSIZE;
     height = SC_SCROLLBUTTON_YSIZE;
 
+    /* correct scrollbar position if placed outside menu (playfield) area */
+    if (x > SC_SCROLL_UP_XPOS)
+      x = SC_SCROLL_UP_XPOS;
+
     if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
       y = mSY + (SC_SCROLL_VERTICAL_YPOS +
                 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
@@ -6598,6 +6624,10 @@ static void CreateScreenScrollbars()
     width  = scrollbar_info[i].width;
     height = scrollbar_info[i].height;
 
+    /* correct scrollbar position if placed outside menu (playfield) area */
+    if (x > SC_SCROLL_VERTICAL_XPOS)
+      x = SC_SCROLL_VERTICAL_XPOS;
+
     if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
       height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;