From 8b569e0443d0242f2c52bdfb6d54b18e750c028f Mon Sep 17 00:00:00 2001
From: twinaphex <libretro@gmail.com>
Date: Fri, 25 Sep 2015 15:42:31 +0200
Subject: [PATCH] Refactor away menu_navigation_set

---
 menu/cbs/menu_cbs_left.c  |  7 ++++++-
 menu/cbs/menu_cbs_right.c |  7 ++++++-
 menu/menu_displaylist.c   |  7 ++++++-
 menu/menu_input.c         | 20 +++++++++++++++++---
 menu/menu_navigation.c    | 40 +++++++++++++++++----------------------
 menu/menu_navigation.h    |  9 ---------
 6 files changed, 52 insertions(+), 38 deletions(-)

diff --git a/menu/cbs/menu_cbs_left.c b/menu/cbs/menu_cbs_left.c
index d252648cad..86152008f8 100644
--- a/menu/cbs/menu_cbs_left.c
+++ b/menu/cbs/menu_cbs_left.c
@@ -103,7 +103,12 @@ static int action_left_scroll(unsigned type, const char *label,
    fast_scroll_speed = 4 + 4 * scroll_speed;
 
    if (selection > fast_scroll_speed)
-      menu_navigation_set(nav, selection - fast_scroll_speed, true);
+   {
+      size_t idx  = selection - fast_scroll_speed;
+      bool scroll = true;
+      menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx);
+      menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll);
+   }
    else
    {
       bool pending_push = false;
diff --git a/menu/cbs/menu_cbs_right.c b/menu/cbs/menu_cbs_right.c
index b1c2a56c62..2d9f0ce182 100644
--- a/menu/cbs/menu_cbs_right.c
+++ b/menu/cbs/menu_cbs_right.c
@@ -131,7 +131,12 @@ static int action_right_scroll(unsigned type, const char *label,
    fast_scroll_speed = 4 + 4 * scroll_speed;
 
    if (selection  + fast_scroll_speed < (menu_list_get_size(menu_list)))
-      menu_navigation_set(nav, selection + fast_scroll_speed, true);
+   {
+      size_t idx  = selection + fast_scroll_speed;
+      bool scroll = true;
+      menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx);
+      menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll);
+   }
    else
    {
       if ((menu_list_get_size(menu_list) > 0))
diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c
index 2bdf091898..06309c0531 100644
--- a/menu/menu_displaylist.c
+++ b/menu/menu_displaylist.c
@@ -220,7 +220,12 @@ static void menu_list_refresh(file_list_t *list)
    list_size = menu_list_get_size(menu_list);
 
    if ((nav->selection_ptr >= list_size) && list_size)
-      menu_navigation_set(nav, list_size - 1, true);
+   {
+      size_t idx  = list_size - 1;
+      bool scroll = true;
+      menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx);
+      menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll);
+   }
    else if (!list_size)
    {
       bool pending_push = true;
diff --git a/menu/menu_input.c b/menu/menu_input.c
index c1f6261506..4096d624c2 100644
--- a/menu/menu_input.c
+++ b/menu/menu_input.c
@@ -278,7 +278,11 @@ static void menu_input_search_callback(void *userdata, const char *str)
       return;
 
    if (str && *str && file_list_search(menu_list->selection_buf, str, &idx))
-         menu_navigation_set(nav, idx, true);
+   {
+      bool scroll = true;
+      menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx);
+      menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll);
+   }
 
    menu_input_key_end_line();
 }
@@ -895,7 +899,12 @@ static int menu_input_mouse_frame(
          return menu_entry_action(entry, nav->selection_ptr, MENU_ACTION_SELECT);
 
       if (BIT64_GET(input_mouse, MOUSE_ACTION_BUTTON_L_SET_NAVIGATION))
-         menu_navigation_set(nav, menu_input->mouse.ptr, false);
+      {
+         size_t idx  = menu_input->mouse.ptr;
+         bool scroll = false;
+         menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx);
+         menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll);
+      }
    }
 
    if (BIT64_GET(input_mouse, MOUSE_ACTION_BUTTON_R))
@@ -1003,7 +1012,12 @@ static int pointer_tap(menu_file_list_cbs_t *cbs,
          && cbs && cbs->action_select)
       return menu_entry_action(entry, nav->selection_ptr, MENU_ACTION_SELECT);
    else
-      menu_navigation_set(nav, menu_input->pointer.ptr, false);
+   {
+      size_t idx  = menu_input->pointer.ptr;
+      bool scroll = false;
+      menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx);
+      menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll);
+   }
 
    return 0;
 }
diff --git a/menu/menu_navigation.c b/menu/menu_navigation.c
index 759807a8b8..9709fc0b48 100644
--- a/menu/menu_navigation.c
+++ b/menu/menu_navigation.c
@@ -39,12 +39,15 @@ bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data)
    {
       case MENU_NAVIGATION_CTL_CLEAR:
          {
+            size_t idx         = 0;
+            bool scroll        = true;
             bool *pending_push = (bool*)data;
 
             if (!pending_push)
                return false;
 
-            menu_navigation_set(nav, 0, true);
+            menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx);
+            menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll);
             if (driver->navigation_clear)
                driver->navigation_clear(*pending_push);
          }
@@ -59,7 +62,10 @@ bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data)
 
             if ((selection + (*scroll_speed)) < (menu_list_get_size(menu_list)))
             {
-               menu_navigation_set(nav, selection + (*scroll_speed), true);
+               size_t idx  = selection + (*scroll_speed);
+               bool scroll = true;
+               menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx);
+               menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll);
                menu_navigation_ctl(MENU_NAVIGATION_CTL_INCREMENT, NULL);
             }
             else
@@ -84,6 +90,8 @@ bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data)
          return true;
       case MENU_NAVIGATION_CTL_DECREMENT:
          {
+            size_t idx             = 0;
+            bool scroll            = true;
             size_t selection       = nav->selection_ptr;
             unsigned *scroll_speed = (unsigned*)data;
 
@@ -91,17 +99,17 @@ bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data)
                return false;
 
             if (selection >= *scroll_speed)
-               menu_navigation_set(nav, selection - *scroll_speed, true);
+               idx = selection - *scroll_speed;
             else
             {
-               if (settings->menu.navigation.wraparound.vertical_enable)
-                  menu_navigation_set(nav, 
-                        menu_list_get_size(menu_list) - 1, true);
-               else
-                  menu_navigation_set(nav, 0, true);
+               idx  = menu_list_get_size(menu_list) - 1;
+               if (!settings->menu.navigation.wraparound.vertical_enable)
+                  idx = 0;
             }
-
+            menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx);
+            menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll);
             menu_navigation_ctl(MENU_NAVIGATION_CTL_DECREMENT, NULL);
+
             if (driver->navigation_decrement)
                driver->navigation_decrement();
          }
@@ -165,20 +173,6 @@ bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data)
    return false;
 }
 
-/**
- * menu_navigation_set:      
- * @idx                   : index to set navigation pointer to.
- * @scroll                : should we scroll when needed?
- *
- * Sets navigation pointer to index @idx.
- **/
-void menu_navigation_set(menu_navigation_t *nav,
-      size_t idx, bool scroll)
-{
-   menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx);
-   menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll);
-}
-
 /**
  * menu_navigation_descend_alphabet:
  * @ptr_out               : Amount of indices to 'scroll' to get
diff --git a/menu/menu_navigation.h b/menu/menu_navigation.h
index cbfc4bdbe6..d2c3bb5626 100644
--- a/menu/menu_navigation.h
+++ b/menu/menu_navigation.h
@@ -57,15 +57,6 @@ enum menu_navigation_ctl_state
    MENU_NAVIGATION_CTL_GET_SELECTION
 };
 
-/**
- * menu_navigation_set:      
- * @idx                   : index to set navigation pointer to.
- * @scroll                : should we scroll when needed?
- *
- * Sets navigation pointer to index @idx.
- **/
-void menu_navigation_set(menu_navigation_t *nav, size_t i, bool scroll);
-
 /**
  * menu_navigation_descend_alphabet:
  * @ptr_out               : Amount of indices to 'scroll' to get