moved code to draw "choose tree" screen to separate function
authorHolger Schemel <info@artsoft.org>
Tue, 15 Feb 2022 18:33:26 +0000 (19:33 +0100)
committerHolger Schemel <info@artsoft.org>
Tue, 15 Feb 2022 18:33:26 +0000 (19:33 +0100)
src/screens.c

index 750aaae4c57819939d5f5a92fc4ae00fcbf9a3e7..6f18bf310babc9be7551832c40abfde657ddb345 100644 (file)
@@ -4972,6 +4972,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 +5025,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 +5134,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;
     }