added functions to redraw and unmap screen gadgets
[rocksndiamonds.git] / src / screens.c
index e669a7ddd247badd51ba935fd5d9e0caf10e42d9..62eb2979cd59bbc752c5ff95d8e1e8f206ab9c63 100644 (file)
@@ -277,10 +277,13 @@ static void HandleInfoScreen_Version(int);
 static void ModifyGameSpeedIfNeeded(void);
 static void DisableVsyncIfNeeded(void);
 
+static void RedrawScreenMenuGadgets(int);
 static void MapScreenMenuGadgets(int);
 static void UnmapScreenMenuGadgets(int);
 static void MapScreenGadgets(int);
+static void UnmapScreenGadgets(void);
 static void MapScreenTreeGadgets(TreeInfo *);
+static void UnmapScreenTreeGadgets(void);
 
 static void UpdateScreenMenuGadgets(int, boolean);
 
@@ -1403,10 +1406,10 @@ static void AdjustScrollbar(int id, int items_max, int items_visible,
               GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
 }
 
-static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
+static void AdjustChooseTreeScrollbar(TreeInfo *ti, int id)
 {
   AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
-                 first_entry);
+                 ti->cl_first);
 }
 
 static void clearMenuListArea(void)
@@ -4882,7 +4885,7 @@ static int getChooseTreeFont(TreeInfo *node, boolean active)
     return MENU_CHOOSE_TREE_FONT(MENU_CHOOSE_TREE_COLOR(node, active));
 }
 
-static void drawChooseTreeText(int y, boolean active, TreeInfo *ti)
+static void drawChooseTreeText(TreeInfo *ti, int y, boolean active)
 {
   int num_entries = numTreeInfoInGroup(ti);
   boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
@@ -4969,9 +4972,11 @@ static void drawChooseTreeHead(TreeInfo *ti)
   drawChooseTreeHeadExt(ti->type, ti->infotext);
 }
 
-static void drawChooseTreeList(int first_entry, int num_page_entries,
-                              TreeInfo *ti)
+static void drawChooseTreeList(TreeInfo *ti)
 {
+  int first_entry = ti->cl_first;
+  int num_entries = numTreeInfoInGroup(ti);
+  int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
   int i;
 
   clearMenuListArea();
@@ -4984,7 +4989,7 @@ static void drawChooseTreeList(int first_entry, int num_page_entries,
     node_first = getTreeInfoFirstGroupEntry(ti);
     node = getTreeInfoFromPos(node_first, entry_pos);
 
-    drawChooseTreeText(i, FALSE, ti);
+    drawChooseTreeText(ti, i, FALSE);
 
     if (node->parent_link)
       initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
@@ -5003,12 +5008,13 @@ static void drawChooseTreeList(int first_entry, int num_page_entries,
   redraw_mask |= REDRAW_FIELD;
 }
 
-static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
+static void drawChooseTreeInfo(TreeInfo *ti)
 {
-  TreeInfo *node, *node_first;
-  int x, last_redraw_mask = redraw_mask;
+  int entry_pos = ti->cl_first + ti->cl_cursor;
+  int last_redraw_mask = redraw_mask;
   int ypos = MENU_TITLE2_YPOS;
   int font_nr = FONT_TITLE_2;
+  int x;
 
   if (ti->type == TREE_TYPE_LEVEL_NR)
     DrawTextFCentered(ypos, font_nr, leveldir_current->name);
@@ -5020,8 +5026,8 @@ static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
   if (ti->type != TREE_TYPE_LEVEL_DIR)
     return;
 
-  node_first = getTreeInfoFirstGroupEntry(ti);
-  node = getTreeInfoFromPos(node_first, entry_pos);
+  TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
+  TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
 
   DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
 
@@ -5042,23 +5048,20 @@ static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
     MarkTileDirty(x, 1);
 }
 
-static void drawChooseTreeCursorAndText(int y, boolean active, TreeInfo *ti)
+static void drawChooseTreeCursorAndText(TreeInfo *ti, boolean active)
 {
-  drawChooseTreeCursor(y, active);
-  drawChooseTreeText(y, active, ti);
+  drawChooseTreeCursor(ti->cl_cursor, active);
+  drawChooseTreeText(ti, ti->cl_cursor, active);
 }
 
 static void drawChooseTreeScreen(TreeInfo *ti)
 {
-  int num_entries = numTreeInfoInGroup(ti);
-  int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
-
   drawChooseTreeHead(ti);
-  drawChooseTreeList(ti->cl_first, num_page_entries, ti);
-  drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
-  drawChooseTreeCursorAndText(ti->cl_cursor, TRUE, ti);
+  drawChooseTreeList(ti);
+  drawChooseTreeInfo(ti);
+  drawChooseTreeCursorAndText(ti, TRUE);
 
-  AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, ti->cl_first, ti);
+  AdjustChooseTreeScrollbar(ti, SCREEN_CTRL_ID_SCROLL_VERTICAL);
 
   // scroll bar and buttons may just have been added after reloading scores
   if (game_status == GAME_MODE_SCORES)
@@ -5367,11 +5370,13 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
       {
        PlaySound(SND_MENU_ITEM_ACTIVATING);
 
-       drawChooseTreeCursorAndText(ti->cl_cursor, FALSE, ti);
-       drawChooseTreeCursorAndText(y, TRUE, ti);
-       drawChooseTreeInfo(ti->cl_first + y, ti);
+       drawChooseTreeCursorAndText(ti, FALSE);
 
        ti->cl_cursor = y;
+
+       drawChooseTreeCursorAndText(ti, TRUE);
+
+       drawChooseTreeInfo(ti);
       }
       else if (dx < 0)
       {
@@ -10059,6 +10064,15 @@ void FreeScreenGadgets(void)
     FreeGadget(screen_gadget[i]);
 }
 
+static void RedrawScreenMenuGadgets(int screen_mask)
+{
+  int i;
+
+  for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
+    if (screen_mask & menubutton_info[i].screen_mask)
+      RedrawGadget(screen_gadget[menubutton_info[i].gadget_id]);
+}
+
 static void MapScreenMenuGadgets(int screen_mask)
 {
   int i;
@@ -10109,11 +10123,27 @@ static void MapScreenGadgets(int num_entries)
     MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
 }
 
+static void UnmapScreenGadgets()
+{
+  int i;
+
+  for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
+    UnmapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
+
+  for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
+    UnmapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
+}
+
 static void MapScreenTreeGadgets(TreeInfo *ti)
 {
   MapScreenGadgets(numTreeInfoInGroup(ti));
 }
 
+static void UnmapScreenTreeGadgets(void)
+{
+  UnmapScreenGadgets();
+}
+
 static void HandleScreenGadgets(struct GadgetInfo *gi)
 {
   int id = gi->custom_id;