rnd-20030722-1-src
[rocksndiamonds.git] / src / screens.c
index 1b8d27b414011d5c3db6cb14c731fbe9349c5a2a..1a239518c74c6d216363d259198c88725cfd2556 100644 (file)
@@ -78,6 +78,10 @@ static int setup_mode = SETUP_MODE_MAIN;
                   game_status <= GAME_MODE_SETUP ?     \
                   menu.draw_yoffset[game_status] : menu.draw_yoffset_default))
 
+#define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ?  \
+                                   menu.list_size[game_status] :       \
+                                   MAX_MENU_ENTRIES_ON_SCREEN)
+
 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
 #define NUM_SCROLLBAR_BITMAPS          2
 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
@@ -123,6 +127,18 @@ static void drawCursorXY(int xpos, int ypos, int graphic)
   drawCursorExt(xpos, ypos, -1, graphic);
 }
 
+static void drawChooseTreeCursor(int ypos, int color)
+{
+  int last_game_status = game_status;  /* save current game status */
+
+  /* force LEVELS draw offset on artwork setup screen */
+  game_status = GAME_MODE_LEVELS;
+
+  drawCursorExt(0, ypos, color, 0);
+
+  game_status = last_game_status;      /* restore current game status */
+}
+
 static void PlaySound_Menu_Start(int sound)
 {
   if (sound_info[sound].loop)
@@ -298,10 +314,10 @@ static void gotoTopLevelDir()
       int num_page_entries;
       int cl_first, cl_cursor;
 
-      if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
+      if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
        num_page_entries = num_leveldirs;
       else
-       num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
+       num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
 
       cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
       cl_cursor = leveldir_pos - cl_first;
@@ -840,7 +856,6 @@ void DrawHelpScreenElAction(int start)
   int graphic;
   int frame_count;
   int sync_frame;
-  int frame;
 
   while (helpscreen_action[j] != HA_END)
   {
@@ -888,10 +903,17 @@ void DrawHelpScreenElAction(int start)
     }
     j++;
 
+#if 1
+    ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
+                              TILEX, TILEY);
+    DrawGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
+                           graphic, sync_frame, USE_MASKING);
+#else
     frame = getGraphicAnimationFrame(graphic, sync_frame);
 
     DrawGraphicExt(drawto, xstart, ystart + (i-start) * ystep,
                   graphic, frame);
+#endif
 
     i++;
   }
@@ -1188,13 +1210,14 @@ static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
   int items_max, items_visible, item_position;
 
   items_max = numTreeInfoInGroup(ti);
-  items_visible = MAX_MENU_ENTRIES_ON_SCREEN - 1;
+  items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
   item_position = first_entry;
 
   if (item_position > items_max - items_visible)
     item_position = items_max - items_visible;
 
   ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
+              GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
               GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
 }
 
@@ -1204,10 +1227,9 @@ static void drawChooseTreeList(int first_entry, int num_page_entries,
   int i;
   char buffer[SCR_FIELDX * 2];
   int max_buffer_len = (SCR_FIELDX - 2) * 2;
-  int num_entries = numTreeInfoInGroup(ti);
   char *title_string = NULL;
   int xoffset_setup = 16;
-  int yoffset_setup = 0;
+  int yoffset_setup = 16;
   int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : xoffset_setup);
   int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : yoffset_setup);
   int last_game_status = game_status;  /* save current game status */
@@ -1248,24 +1270,6 @@ static void drawChooseTreeList(int first_entry, int num_page_entries,
       initCursor(i, IMG_MENU_BUTTON);
   }
 
-  if (first_entry > 0)
-  {
-    int ypos = 1;
-
-    DrawBackground(mSX, mSY + ypos * TILEY, TILEX, TILEY);
-    DrawGraphicThruMaskExt(drawto, mSX, mSY + ypos * TILEY,
-                          IMG_MENU_BUTTON_UP, 0);
-  }
-
-  if (first_entry + num_page_entries < num_entries)
-  {
-    int ypos = MAX_MENU_ENTRIES_ON_SCREEN + 1;
-
-    DrawBackground(mSX, mSY + ypos * TILEY, TILEX, TILEY);
-    DrawGraphicThruMaskExt(drawto, mSX, mSY + ypos * TILEY,
-                          IMG_MENU_BUTTON_DOWN, 0);
-  }
-
   game_status = last_game_status;      /* restore current game status */
 }
 
@@ -1301,7 +1305,6 @@ static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
                             TreeInfo **ti_ptr)
 {
-  static unsigned long choose_delay = 0;
   TreeInfo *ti = *ti_ptr;
   int x = 0;
   int y = ti->cl_cursor;
@@ -1309,20 +1312,29 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
   int num_entries = numTreeInfoInGroup(ti);
   int num_page_entries;
 
-  if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
+  if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
     num_page_entries = num_entries;
   else
-    num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
+    num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
 
   if (button == MB_MENU_INITIALIZE)
   {
+    int num_entries = numTreeInfoInGroup(ti);
     int entry_pos = posTreeInfo(ti);
 
     if (ti->cl_first == -1)
     {
+      /* only on initialization */
       ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
-      ti->cl_cursor =
-       entry_pos - ti->cl_first;
+      ti->cl_cursor = entry_pos - ti->cl_first;
+    }
+    else if (ti->cl_cursor >= num_page_entries ||
+            (num_entries > num_page_entries &&
+             num_entries - ti->cl_first < num_page_entries))
+    {
+      /* only after change of list size (by custom graphic configuration) */
+      ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
+      ti->cl_cursor = entry_pos - ti->cl_first;
     }
 
     if (dx == 999)     /* first entry is set by scrollbar position */
@@ -1333,7 +1345,8 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
 
     drawChooseTreeList(ti->cl_first, num_page_entries, ti);
     drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
-    drawCursor(ti->cl_cursor, FC_RED);
+    drawChooseTreeCursor(ti->cl_cursor, FC_RED);
+
     return;
   }
   else if (button == MB_MENU_LEAVE)
@@ -1358,55 +1371,66 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
 
   if (mx || my)                /* mouse input */
   {
+    int last_game_status = game_status;        /* save current game status */
+
+    /* force LEVELS draw offset on artwork setup screen */
+    game_status = GAME_MODE_LEVELS;
+
     x = (mx - mSX) / 32;
     y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
+
+    game_status = last_game_status;    /* restore current game status */
   }
-  else if (dx || dy)   /* keyboard input */
+  else if (dx || dy)   /* keyboard or scrollbar/scrollbutton input */
   {
-    if (dy)
-      y = ti->cl_cursor + dy;
+    /* move cursor instead of scrolling when already at start/end of list */
+    if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
+      dy = -1;
+    else if (dy == +1 * SCROLL_LINE &&
+            ti->cl_first + num_page_entries == num_entries)
+      dy = 1;
 
-    if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
+    /* handle scrolling screen one line or page */
+    if (ti->cl_cursor + dy < 0 ||
+       ti->cl_cursor + dy > num_page_entries - 1)
     {
-      dy = SIGN(dy);
-      step = num_page_entries - 1;
-      y = (dy < 0 ? -1 : num_page_entries);
-    }
-  }
+      if (ABS(dy) == SCROLL_PAGE)
+       step = num_page_entries - 1;
 
-  if (x == 0 && y == -1)
-  {
-    if (ti->cl_first > 0 &&
-       (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
-    {
-      ti->cl_first -= step;
-      if (ti->cl_first < 0)
-       ti->cl_first = 0;
+      if (dy < 0 && ti->cl_first > 0)
+      {
+       /* scroll page/line up */
 
-      drawChooseTreeList(ti->cl_first, num_page_entries, ti);
-      drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
-      drawCursor(ti->cl_cursor, FC_RED);
-      AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
-                               ti->cl_first, ti);
-      return;
-    }
-  }
-  else if (x == 0 && y > num_page_entries - 1)
-  {
-    if (ti->cl_first + num_page_entries < num_entries &&
-       (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
-    {
-      ti->cl_first += step;
-      if (ti->cl_first + num_page_entries > num_entries)
-       ti->cl_first = MAX(0, num_entries - num_page_entries);
+       ti->cl_first -= step;
+       if (ti->cl_first < 0)
+         ti->cl_first = 0;
+
+       drawChooseTreeList(ti->cl_first, num_page_entries, ti);
+       drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
+       drawChooseTreeCursor(ti->cl_cursor, FC_RED);
+       AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
+                                 ti->cl_first, ti);
+      }
+      else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
+      {
+       /* scroll page/line down */
+
+       ti->cl_first += step;
+       if (ti->cl_first + num_page_entries > num_entries)
+         ti->cl_first = MAX(0, num_entries - num_page_entries);
+
+       drawChooseTreeList(ti->cl_first, num_page_entries, ti);
+       drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
+       drawChooseTreeCursor(ti->cl_cursor, FC_RED);
+       AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
+                                 ti->cl_first, ti);
+      }
 
-      drawChooseTreeList(ti->cl_first, num_page_entries, ti);
-      drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
-      drawCursor(ti->cl_cursor, FC_RED);
-      AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
-                               ti->cl_first, ti);
       return;
     }
+
+    /* handle moving cursor one line */
+    y = ti->cl_cursor + dy;
   }
 
   if (dx == 1)
@@ -1423,6 +1447,7 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
       node_cursor->cl_cursor = ti->cl_cursor;
       *ti_ptr = node_cursor->node_group;
       DrawChooseTree(ti_ptr);
+
       return;
     }
   }
@@ -1430,6 +1455,7 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
   {
     *ti_ptr = ti->node_parent;
     DrawChooseTree(ti_ptr);
+
     return;
   }
 
@@ -1439,8 +1465,8 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
     {
       if (y != ti->cl_cursor)
       {
-       drawCursor(y, FC_RED);
-       drawCursor(ti->cl_cursor, FC_BLUE);
+       drawChooseTreeCursor(y, FC_RED);
+       drawChooseTreeCursor(ti->cl_cursor, FC_BLUE);
        drawChooseTreeInfo(ti->cl_first + y, ti);
        ti->cl_cursor = y;
       }
@@ -1542,7 +1568,7 @@ static void drawHallOfFameList(int first_entry, int highlight_position)
   DrawText(mSX + 80, mSY + 8, "Hall Of Fame", FONT_TITLE_1);
   DrawTextFCentered(46, FONT_TITLE_2, "HighScores of Level %d", level_nr);
 
-  for(i=0; i<MAX_MENU_ENTRIES_ON_SCREEN; i++)
+  for(i=0; i<NUM_MENU_ENTRIES_ON_SCREEN; i++)
   {
     int entry = first_entry + i;
     boolean active = (entry == highlight_position);
@@ -1576,11 +1602,12 @@ void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
     first_entry = 0;
     highlight_position = mx;
     drawHallOfFameList(first_entry, highlight_position);
+
     return;
   }
 
-  if (ABS(dy) == SCR_FIELDY)   /* handle KSYM_Page_Up, KSYM_Page_Down */
-    step = MAX_MENU_ENTRIES_ON_SCREEN - 1;
+  if (ABS(dy) == SCROLL_PAGE)          /* handle scrolling one page */
+    step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
 
   if (dy < 0)
   {
@@ -1591,18 +1618,20 @@ void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
        first_entry = 0;
 
       drawHallOfFameList(first_entry, highlight_position);
+
       return;
     }
   }
   else if (dy > 0)
   {
-    if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
+    if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
     {
       first_entry += step;
-      if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
-       first_entry = MAX(0, MAX_SCORE_ENTRIES - MAX_MENU_ENTRIES_ON_SCREEN);
+      if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
+       first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
 
       drawHallOfFameList(first_entry, highlight_position);
+
       return;
     }
   }
@@ -1669,13 +1698,13 @@ static void execSetupSound()
 
 static void execSetupArtwork()
 {
-  /* needed if last screen (setup choice) changed graphics, sounds or music */
-  ReloadCustomArtwork();
-
   setup.graphics_set = artwork.gfx_current->identifier;
   setup.sounds_set = artwork.snd_current->identifier;
   setup.music_set = artwork.mus_current->identifier;
 
+  /* needed if last screen (setup choice) changed graphics, sounds or music */
+  ReloadCustomArtwork();
+
   /* needed for displaying artwork name instead of artwork identifier */
   graphics_set_name = artwork.gfx_current->name;
   sounds_set_name = artwork.snd_current->name;
@@ -1909,9 +1938,11 @@ static void drawSetupValue(int pos)
     if (strlen(value_string) > max_value_len)
       value_string[max_value_len] = '\0';
   }
-  else if (setup_info[pos].type & TYPE_BOOLEAN_STYLE &&
-          !*(boolean *)(setup_info[pos].value))
-    font_nr = FONT_OPTION_OFF;
+  else if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
+  {
+    font_nr = (*(boolean *)(setup_info[pos].value) ? FONT_OPTION_ON :
+              FONT_OPTION_OFF);
+  }
 
   DrawText(mSX + xpos * 32, mSY + ypos * 32,
           (xpos == 3 ? "              " : "   "), font_nr);
@@ -1989,7 +2020,7 @@ static void DrawSetupScreen_Generic()
   DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
 
   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++)
   {
     void *value_ptr = setup_info[i].value;
     int ypos = MENU_SCREEN_START_YPOS + i;
@@ -2749,17 +2780,20 @@ void HandleGameActions()
 /* ---------- new screen button stuff -------------------------------------- */
 
 /* graphic position and size values for buttons and scrollbars */
-#define SC_SCROLLBUTTON_XSIZE          32
-#define SC_SCROLLBUTTON_YSIZE          32
+#define SC_SCROLLBUTTON_XSIZE          TILEX
+#define SC_SCROLLBUTTON_YSIZE          TILEY
 
+#define SC_SCROLL_VERTICAL_XSIZE       SC_SCROLLBUTTON_XSIZE
+#define SC_SCROLL_VERTICAL_YSIZE       ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
+                                        SC_SCROLLBUTTON_YSIZE)
 #define SC_SCROLL_UP_XPOS              (SXSIZE - SC_SCROLLBUTTON_XSIZE)
-#define SC_SCROLL_UP_YPOS              SC_SCROLLBUTTON_YSIZE
-#define SC_SCROLL_DOWN_XPOS            SC_SCROLL_UP_XPOS
-#define SC_SCROLL_DOWN_YPOS            (SYSIZE - SC_SCROLLBUTTON_YSIZE)
+#define SC_SCROLL_UP_YPOS              (2 * SC_SCROLLBUTTON_YSIZE)
 #define SC_SCROLL_VERTICAL_XPOS                SC_SCROLL_UP_XPOS
-#define SC_SCROLL_VERTICAL_YPOS          (SC_SCROLL_UP_YPOS + SC_SCROLLBUTTON_YSIZE)
-#define SC_SCROLL_VERTICAL_XSIZE       SC_SCROLLBUTTON_XSIZE
-#define SC_SCROLL_VERTICAL_YSIZE       (SYSIZE - 3 * SC_SCROLLBUTTON_YSIZE)
+#define SC_SCROLL_VERTICAL_YPOS                (SC_SCROLL_UP_YPOS + \
+                                        SC_SCROLLBUTTON_YSIZE)
+#define SC_SCROLL_DOWN_XPOS            SC_SCROLL_UP_XPOS
+#define SC_SCROLL_DOWN_YPOS            (SC_SCROLL_VERTICAL_YPOS + \
+                                        SC_SCROLL_VERTICAL_YSIZE)
 
 #define SC_BORDER_SIZE                 14
 
@@ -2882,7 +2916,7 @@ static void CreateScreenScrollbars()
     struct GadgetInfo *gi;
     int items_max, items_visible, item_position;
     unsigned long event_mask;
-    int num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
+    int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
     int id = scrollbar_info[i].gadget_id;
 
     items_max = num_page_entries;
@@ -2986,7 +3020,7 @@ void MapChooseTreeGadgets(TreeInfo *ti)
   int num_entries = numTreeInfoInGroup(ti);
   int i;
 
-  if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
+  if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
     return;
 
   for (i=0; i<NUM_SCREEN_GADGETS; i++)
@@ -3012,16 +3046,16 @@ static void HandleScreenGadgets(struct GadgetInfo *gi)
   {
     case SCREEN_CTRL_ID_SCROLL_UP:
       if (game_status == GAME_MODE_LEVELS)
-       HandleChooseLevel(mSX,mSY + 32, 0,0, MB_MENU_MARK);
+       HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
       else if (game_status == GAME_MODE_SETUP)
-       HandleSetupScreen(mSX,mSY + 32, 0,0, MB_MENU_MARK);
+       HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
       break;
 
     case SCREEN_CTRL_ID_SCROLL_DOWN:
       if (game_status == GAME_MODE_LEVELS)
-       HandleChooseLevel(mSX,mSY + SYSIZE - 32, 0,0, MB_MENU_MARK);
+       HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
       else if (game_status == GAME_MODE_SETUP)
-       HandleSetupScreen(mSX,mSY + SYSIZE - 32, 0,0, MB_MENU_MARK);
+       HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
       break;
 
     case SCREEN_CTRL_ID_SCROLL_VERTICAL: