rnd-20030801-1-src
[rocksndiamonds.git] / src / screens.c
index f04ca586fe1eb26e7613bddf157bd16d10616f4a..65708d2409bcd94ee0fad82907cee07c8349388f 100644 (file)
@@ -127,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)
@@ -515,7 +527,7 @@ static int helpscreen_action[] =
 
   IMG_INVISIBLE_WALL,                  -1,                     HA_NEXT,
 
-  IMG_WALL_CRUMBLED,                   -1,                     HA_NEXT,
+  IMG_WALL_SLIPPERY,                   -1,                     HA_NEXT,
 
   IMG_FONT_GAME_INFO,                  -1,                     HA_NEXT,
 
@@ -906,11 +918,15 @@ void DrawHelpScreenElAction(int start)
     i++;
   }
 
+#if 1
+  redraw_mask |= REDRAW_FIELD;
+#else
   for(i=2; i<16; i++)
   {
     MarkTileDirty(0, i);
     MarkTileDirty(1, i);
   }
+#endif
 
   FrameCounter++;
 }
@@ -1181,6 +1197,10 @@ void HandleTypeName(int newxpos, Key key)
 static void DrawChooseTree(TreeInfo **ti_ptr)
 {
   UnmapAllGadgets();
+
+  FreeScreenGadgets();
+  CreateScreenGadgets();
+
   CloseDoor(DOOR_CLOSE_2);
 
   ClearWindow();
@@ -1205,6 +1225,7 @@ static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
     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);
 }
 
@@ -1298,21 +1319,36 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
   int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
   int num_entries = numTreeInfoInGroup(ti);
   int num_page_entries;
+  int last_game_status = game_status;  /* save current game status */
+
+  /* force LEVELS draw offset on choose level and artwork setup screen */
+  game_status = GAME_MODE_LEVELS;
 
   if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
     num_page_entries = num_entries;
   else
     num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
 
+  game_status = last_game_status;      /* restore current game status */
+
   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 */
@@ -1323,7 +1359,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)
@@ -1348,8 +1385,15 @@ 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 or scrollbar/scrollbutton input */
   {
@@ -1377,7 +1421,7 @@ 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);
        AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
                                  ti->cl_first, ti);
       }
@@ -1391,7 +1435,7 @@ 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);
        AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
                                  ti->cl_first, ti);
       }
@@ -1417,6 +1461,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;
     }
   }
@@ -1424,6 +1469,7 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
   {
     *ti_ptr = ti->node_parent;
     DrawChooseTree(ti_ptr);
+
     return;
   }
 
@@ -1433,8 +1479,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;
       }
@@ -1570,6 +1616,7 @@ void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
     first_entry = 0;
     highlight_position = mx;
     drawHallOfFameList(first_entry, highlight_position);
+
     return;
   }
 
@@ -1585,6 +1632,7 @@ void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
        first_entry = 0;
 
       drawHallOfFameList(first_entry, highlight_position);
+
       return;
     }
   }
@@ -1597,6 +1645,7 @@ void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
        first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
 
       drawHallOfFameList(first_entry, highlight_position);
+
       return;
     }
   }
@@ -1663,13 +1712,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;
@@ -2804,7 +2853,7 @@ static struct
 #else
     IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
 #endif
-    SX + SC_SCROLL_VERTICAL_XPOS, SY + SC_SCROLL_VERTICAL_YPOS,
+    SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
     SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
     GD_TYPE_SCROLLBAR_VERTICAL,
     SCREEN_CTRL_ID_SCROLL_VERTICAL,
@@ -2826,16 +2875,17 @@ static void CreateScreenScrollbuttons()
     int gd_x1, gd_x2, gd_y1, gd_y2;
     int id = scrollbutton_info[i].gadget_id;
 
-    x = scrollbutton_info[i].x;
-    y = scrollbutton_info[i].y;
-
     event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
 
-    x += SX;
-    y += SY;
+    x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
+    y = mSY + scrollbutton_info[i].y;
     width = SC_SCROLLBUTTON_XSIZE;
     height = SC_SCROLLBUTTON_YSIZE;
 
+    if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
+      y = mSY + (SC_SCROLL_VERTICAL_YPOS +
+                (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
+
     gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
     gfx_pressed   = scrollbutton_info[i].gfx_pressed;
     gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
@@ -2877,6 +2927,7 @@ static void CreateScreenScrollbars()
 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
     int gfx_unpressed, gfx_pressed;
 #endif
+    int x, y, width, height;
     int gd_x1, gd_x2, gd_y1, gd_y2;
     struct GadgetInfo *gi;
     int items_max, items_visible, item_position;
@@ -2884,12 +2935,20 @@ static void CreateScreenScrollbars()
     int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
     int id = scrollbar_info[i].gadget_id;
 
+    event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
+
+    x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
+    y = mSY + scrollbar_info[i].y;
+    width  = scrollbar_info[i].width;
+    height = scrollbar_info[i].height;
+
+    if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
+      height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
+
     items_max = num_page_entries;
     items_visible = num_page_entries;
     item_position = 0;
 
-    event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
-
 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
     gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
     gd_bitmap_pressed   = *scrollbar_info[i].gfx_pressed;
@@ -2911,10 +2970,10 @@ static void CreateScreenScrollbars()
     gi = CreateGadget(GDI_CUSTOM_ID, id,
                      GDI_CUSTOM_TYPE_ID, i,
                      GDI_INFO_TEXT, scrollbar_info[i].infotext,
-                     GDI_X, scrollbar_info[i].x,
-                     GDI_Y, scrollbar_info[i].y,
-                     GDI_WIDTH, scrollbar_info[i].width,
-                     GDI_HEIGHT, scrollbar_info[i].height,
+                     GDI_X, x,
+                     GDI_Y, y,
+                     GDI_WIDTH, width,
+                     GDI_HEIGHT, height,
                      GDI_TYPE, scrollbar_info[i].type,
                      GDI_SCROLLBAR_ITEMS_MAX, items_max,
                      GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
@@ -2936,6 +2995,8 @@ static void CreateScreenScrollbars()
 
 void CreateScreenGadgets()
 {
+  int last_game_status = game_status;  /* save current game status */
+
 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
   int i;
 
@@ -2957,8 +3018,13 @@ void CreateScreenGadgets()
   }
 #endif
 
+  /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
+  game_status = GAME_MODE_LEVELS;
+
   CreateScreenScrollbuttons();
   CreateScreenScrollbars();
+
+  game_status = last_game_status;      /* restore current game status */
 }
 
 void FreeScreenGadgets()