moved code to get font for "choose tree" screen to separate function
[rocksndiamonds.git] / src / screens.c
index 750aaae4c57819939d5f5a92fc4ae00fcbf9a3e7..49f390f973f643616266c0e1a78cfce6d6a432ce 100644 (file)
@@ -4862,6 +4862,14 @@ static void DrawChooseTree(TreeInfo **ti_ptr)
   FadeIn(fade_mask);
 }
 
+static int getChooseTreeFont(TreeInfo *node, boolean active)
+{
+  int font_color = MENU_CHOOSE_TREE_COLOR(node, active);
+  int font_nr = MENU_CHOOSE_TREE_FONT(font_color);
+
+  return font_nr;
+}
+
 static void drawChooseTreeText(int y, boolean active, TreeInfo *ti)
 {
   int num_entries = numTreeInfoInGroup(ti);
@@ -4872,8 +4880,7 @@ static void drawChooseTreeText(int y, boolean active, TreeInfo *ti)
   int entry_pos = first_entry + y;
   TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
   TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
-  int font_color = MENU_CHOOSE_TREE_COLOR(node, active);
-  int font_nr = MENU_CHOOSE_TREE_FONT(font_color);
+  int font_nr = getChooseTreeFont(node, active);
   int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
   int xpos = MENU_SCREEN_START_XPOS;
   int ypos = MENU_SCREEN_START_YPOS + y;
@@ -4972,6 +4979,18 @@ static void drawChooseTreeCursorAndText(int y, boolean active, TreeInfo *ti)
   drawChooseTreeText(y, active, ti);
 }
 
+static void drawChooseTreeScreen(TreeInfo *ti)
+{
+  int num_entries = numTreeInfoInGroup(ti);
+  int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
+
+  drawChooseTreeList(ti->cl_first, num_page_entries, ti);
+  drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
+  drawChooseTreeCursorAndText(ti->cl_cursor, TRUE, ti);
+
+  AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, ti->cl_first, ti);
+}
+
 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
                             TreeInfo **ti_ptr)
 {
@@ -5013,13 +5032,8 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
 
     if (position_set_by_scrollbar)
       ti->cl_first = dy;
-    else
-      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);
-    drawChooseTreeCursorAndText(ti->cl_cursor, TRUE, ti);
+    drawChooseTreeScreen(ti);
 
     return;
   }
@@ -5127,14 +5141,7 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
       }
 
       if (redraw)
-      {
-       drawChooseTreeList(ti->cl_first, num_page_entries, ti);
-       drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
-       drawChooseTreeCursorAndText(ti->cl_cursor, TRUE, ti);
-
-       AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
-                                 ti->cl_first, ti);
-      }
+       drawChooseTreeScreen(ti);
 
       return;
     }