Combine menu_driver.c and menu_navigation.c

This commit is contained in:
twinaphex 2017-05-17 03:00:32 +02:00
parent 5072de4c0f
commit ee8dc151a3
30 changed files with 233 additions and 314 deletions

View File

@ -556,7 +556,6 @@ ifeq ($(HAVE_MENU_COMMON), 1)
menu/menu_input.o \
menu/menu_event.o \
menu/menu_entries.o \
menu/menu_navigation.o \
menu/menu_setting.o \
menu/menu_shader.o \
menu/widgets/menu_filebrowser.o \

View File

@ -980,7 +980,6 @@ MENU
#include "../menu/cbs/menu_cbs_down.c"
#include "../menu/cbs/menu_cbs_contentlist_switch.c"
#include "../menu/menu_shader.c"
#include "../menu/menu_navigation.c"
#include "../menu/menu_display.c"
#include "../menu/menu_displaylist.c"
#include "../menu/menu_animation.c"

View File

@ -17,7 +17,6 @@
#include <string/stdstring.h>
#include "../menu_driver.h"
#include "../menu_navigation.h"
#include "../menu_cbs.h"
#include "../../msg_hash.h"

View File

@ -14,7 +14,6 @@
*/
#include "../menu_driver.h"
#include "../menu_navigation.h"
#include "../menu_cbs.h"
#ifndef BIND_ACTION_DOWN

View File

@ -16,7 +16,6 @@
#include <compat/strl.h>
#include "../menu_driver.h"
#include "../menu_navigation.h"
#include "../menu_cbs.h"
#include "../widgets/menu_dialog.h"

View File

@ -28,7 +28,6 @@
#include "../menu_input.h"
#include "../menu_setting.h"
#include "../menu_shader.h"
#include "../menu_navigation.h"
#include "../widgets/menu_list.h"

View File

@ -31,7 +31,6 @@
#include "../menu_display.h"
#include "../menu_setting.h"
#include "../menu_shader.h"
#include "../menu_navigation.h"
#include "../widgets/menu_dialog.h"
#include "../widgets/menu_filebrowser.h"
#include "../widgets/menu_input_dialog.h"

View File

@ -28,7 +28,6 @@
#include "../menu_input.h"
#include "../menu_setting.h"
#include "../menu_shader.h"
#include "../menu_navigation.h"
#include "../widgets/menu_list.h"

View File

@ -15,7 +15,6 @@
#include "../menu_driver.h"
#include "../menu_cbs.h"
#include "../menu_navigation.h"
#ifndef BIND_ACTION_UP
#define BIND_ACTION_UP(cbs, name) \

View File

@ -43,7 +43,6 @@
#include "../menu_driver.h"
#include "../menu_animation.h"
#include "../menu_navigation.h"
#include "../menu_display.h"
#include "../menu_event.h"

View File

@ -23,7 +23,6 @@
#include "../menu_driver.h"
#include "../menu_display.h"
#include "../menu_navigation.h"
#include "../widgets/menu_dialog.h"
#include "../widgets/menu_input_bind_dialog.h"

View File

@ -37,7 +37,6 @@
#include "../menu_driver.h"
#include "../menu_animation.h"
#include "../menu_navigation.h"
#include "../menu_display.h"
#include "../../core.h"

View File

@ -41,7 +41,6 @@
#include "../menu_driver.h"
#include "../menu_animation.h"
#include "../menu_display.h"
#include "../menu_navigation.h"
#include "../widgets/menu_input_dialog.h"

View File

@ -44,7 +44,6 @@
#include "../menu_driver.h"
#include "../menu_animation.h"
#include "../menu_display.h"
#include "../menu_navigation.h"
#include "../widgets/menu_entry.h"
#include "../widgets/menu_list.h"

View File

@ -35,7 +35,6 @@
#include "../widgets/menu_entry.h"
#include "../menu_entries.h"
#include "../menu_input.h"
#include "../menu_navigation.h"
#include "../menu_setting.h"
#include "../menu_display.h"
#include "../widgets/menu_input_dialog.h"

View File

@ -43,7 +43,6 @@
#include "../menu_animation.h"
#include "../widgets/menu_entry.h"
#include "../menu_display.h"
#include "../menu_navigation.h"
#include "../../retroarch.h"
#include "../../gfx/font_driver.h"

View File

@ -52,7 +52,6 @@
#include "menu_content.h"
#include "menu_driver.h"
#include "menu_navigation.h"
#include "menu_shader.h"
#include "widgets/menu_dialog.h"
#include "widgets/menu_list.h"

View File

@ -30,7 +30,6 @@
#include "menu_cbs.h"
#include "menu_display.h"
#include "menu_event.h"
#include "menu_navigation.h"
#include "widgets/menu_dialog.h"
#include "widgets/menu_list.h"
#include "menu_shader.h"
@ -84,6 +83,7 @@ static playlist_t *menu_driver_playlist = NULL;
static menu_handle_t *menu_driver_data = NULL;
static const menu_ctx_driver_t *menu_driver_ctx = NULL;
static void *menu_userdata = NULL;
static size_t menu_driver_selection_ptr = 0;
bool menu_driver_is_binding_state(void)
{
@ -993,3 +993,212 @@ bool menu_driver_ctl(enum rarch_menu_ctl_state state, void *data)
return true;
}
size_t menu_navigation_get_selection(void)
{
return menu_driver_selection_ptr;
}
void menu_navigation_set_selection(size_t val)
{
menu_driver_selection_ptr = val;
}
#define SCROLL_INDEX_SIZE (2 * (26 + 2) + 1)
bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data)
{
unsigned i;
/* Quick jumping indices with L/R.
* Rebuilt when parsing directory. */
static size_t scroll_index_list[SCROLL_INDEX_SIZE];
static unsigned scroll_index_size = 0;
static unsigned scroll_acceleration = 0;
switch (state)
{
case MENU_NAVIGATION_CTL_DEINIT:
{
scroll_acceleration = 0;
menu_driver_selection_ptr = 0;
scroll_index_size = 0;
for (i = 0; i < SCROLL_INDEX_SIZE; i++)
scroll_index_list[i] = 0;
}
break;
case MENU_NAVIGATION_CTL_CLEAR:
{
menu_navigation_set_selection(0);
menu_driver_navigation_set(true);
menu_driver_ctl(RARCH_MENU_CTL_NAVIGATION_CLEAR, data);
}
break;
case MENU_NAVIGATION_CTL_INCREMENT:
{
settings_t *settings = config_get_ptr();
unsigned *scroll_speed = (unsigned*)data;
size_t menu_list_size = menu_entries_get_size();
bool wraparound_enable = settings->bools.menu_navigation_wraparound_enable;
if (!scroll_speed)
return false;
if (menu_driver_selection_ptr >= menu_list_size - 1
&& !wraparound_enable)
return false;
if ((menu_driver_selection_ptr + (*scroll_speed)) < menu_list_size)
{
size_t idx = menu_driver_selection_ptr + (*scroll_speed);
menu_navigation_set_selection(idx);
menu_driver_navigation_set(true);
menu_navigation_ctl(MENU_NAVIGATION_CTL_INCREMENT, NULL);
}
else
{
if (wraparound_enable)
{
bool pending_push = false;
menu_navigation_ctl(MENU_NAVIGATION_CTL_CLEAR, &pending_push);
}
else
{
if (menu_list_size > 0)
{
menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_LAST, NULL);
menu_navigation_ctl(MENU_NAVIGATION_CTL_INCREMENT, NULL);
}
}
}
menu_driver_increment_navigation();
}
break;
case MENU_NAVIGATION_CTL_DECREMENT:
{
size_t idx = 0;
settings_t *settings = config_get_ptr();
unsigned *scroll_speed = (unsigned*)data;
size_t menu_list_size = menu_entries_get_size();
bool wraparound_enable = settings->bools.menu_navigation_wraparound_enable;
if (!scroll_speed)
return false;
if (menu_driver_selection_ptr == 0 && !wraparound_enable)
return false;
if (menu_driver_selection_ptr >= *scroll_speed)
idx = menu_driver_selection_ptr - *scroll_speed;
else
{
idx = menu_list_size - 1;
if (!wraparound_enable)
idx = 0;
}
menu_navigation_set_selection(idx);
menu_driver_navigation_set(true);
menu_navigation_ctl(MENU_NAVIGATION_CTL_DECREMENT, NULL);
menu_driver_decrement_navigation();
}
break;
case MENU_NAVIGATION_CTL_SET_LAST:
{
size_t menu_list_size = menu_entries_get_size();
size_t new_selection = menu_list_size - 1;
menu_navigation_set_selection(new_selection);
menu_driver_ctl(RARCH_MENU_CTL_NAVIGATION_SET_LAST, NULL);
}
break;
case MENU_NAVIGATION_CTL_ASCEND_ALPHABET:
{
size_t ptr;
size_t i = 0;
size_t *ptr_out = (size_t*)&menu_driver_selection_ptr;
size_t menu_list_size = menu_entries_get_size();
if (!scroll_index_size || !ptr_out)
return false;
ptr = *ptr_out;
if (ptr == scroll_index_list[scroll_index_size - 1])
{
*ptr_out = menu_list_size - 1;
menu_driver_ctl(RARCH_MENU_CTL_NAVIGATION_ASCEND_ALPHABET, ptr_out);
return true;
}
while (i < scroll_index_size - 1
&& scroll_index_list[i + 1] <= ptr)
i++;
*ptr_out = scroll_index_list[i + 1];
if (*ptr_out >= menu_list_size)
*ptr_out = menu_list_size - 1;
menu_driver_ctl(RARCH_MENU_CTL_NAVIGATION_ASCEND_ALPHABET, ptr_out);
}
break;
case MENU_NAVIGATION_CTL_DESCEND_ALPHABET:
{
size_t ptr;
size_t i = 0;
size_t *ptr_out = (size_t*)&menu_driver_selection_ptr;
if (!scroll_index_size || !ptr_out)
return false;
ptr = *ptr_out;
if (ptr == 0)
return false;
i = scroll_index_size - 1;
while (i && scroll_index_list[i - 1] >= ptr)
i--;
*ptr_out = scroll_index_list[i - 1];
menu_driver_ctl(
RARCH_MENU_CTL_NAVIGATION_DESCEND_ALPHABET, ptr_out);
}
break;
case MENU_NAVIGATION_CTL_CLEAR_SCROLL_INDICES:
scroll_index_size = 0;
break;
case MENU_NAVIGATION_CTL_ADD_SCROLL_INDEX:
{
size_t *sel = (size_t*)data;
if (!sel)
return false;
scroll_index_list[scroll_index_size++] = *sel;
}
break;
case MENU_NAVIGATION_CTL_GET_SCROLL_ACCEL:
{
size_t *sel = (size_t*)data;
if (!sel)
return false;
*sel = scroll_acceleration;
}
break;
case MENU_NAVIGATION_CTL_SET_SCROLL_ACCEL:
{
size_t *sel = (size_t*)data;
if (!sel)
return false;
scroll_acceleration = (unsigned)(*sel);
}
break;
case MENU_NAVIGATION_CTL_NONE:
break;
}
return true;
}

View File

@ -202,6 +202,22 @@ enum menu_settings_type
MENU_SETTINGS_LAST
};
enum menu_navigation_ctl_state
{
MENU_NAVIGATION_CTL_NONE = 0,
MENU_NAVIGATION_CTL_CLEAR,
MENU_NAVIGATION_CTL_DEINIT,
MENU_NAVIGATION_CTL_INCREMENT,
MENU_NAVIGATION_CTL_DECREMENT,
MENU_NAVIGATION_CTL_SET_LAST,
MENU_NAVIGATION_CTL_DESCEND_ALPHABET,
MENU_NAVIGATION_CTL_ASCEND_ALPHABET,
MENU_NAVIGATION_CTL_CLEAR_SCROLL_INDICES,
MENU_NAVIGATION_CTL_ADD_SCROLL_INDEX,
MENU_NAVIGATION_CTL_SET_SCROLL_ACCEL,
MENU_NAVIGATION_CTL_GET_SCROLL_ACCEL
};
typedef struct
{
char deferred_path[PATH_MAX_LENGTH];
@ -409,6 +425,12 @@ bool menu_driver_push_list(menu_ctx_displaylist_t *disp_list);
bool menu_driver_init(bool video_is_threaded);
size_t menu_navigation_get_selection(void);
void menu_navigation_set_selection(size_t val);
bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data);
extern menu_ctx_driver_t menu_ctx_xui;
extern menu_ctx_driver_t menu_ctx_rgui;
extern menu_ctx_driver_t menu_ctx_mui;

View File

@ -22,7 +22,6 @@
#include "menu_driver.h"
#include "menu_cbs.h"
#include "menu_navigation.h"
#include "widgets/menu_list.h"

View File

@ -32,7 +32,6 @@
#include "menu_driver.h"
#include "menu_animation.h"
#include "menu_display.h"
#include "menu_navigation.h"
#include "../configuration.h"
#include "../retroarch.h"

View File

@ -30,7 +30,6 @@
#include "menu_driver.h"
#include "menu_input.h"
#include "menu_animation.h"
#include "menu_navigation.h"
#include "menu_event.h"
#include "../configuration.h"

View File

@ -1,236 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <boolean.h>
#include "../configuration.h"
#include "menu_driver.h"
#include "menu_navigation.h"
static size_t selection_ptr = 0;
size_t menu_navigation_get_selection(void)
{
return selection_ptr;
}
void menu_navigation_set_selection(size_t val)
{
selection_ptr = val;
}
#define SCROLL_INDEX_SIZE (2 * (26 + 2) + 1)
bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data)
{
unsigned i;
/* Quick jumping indices with L/R.
* Rebuilt when parsing directory. */
static size_t scroll_index_list[SCROLL_INDEX_SIZE];
static unsigned scroll_index_size = 0;
static unsigned scroll_acceleration = 0;
switch (state)
{
case MENU_NAVIGATION_CTL_DEINIT:
{
scroll_acceleration = 0;
selection_ptr = 0;
scroll_index_size = 0;
for (i = 0; i < SCROLL_INDEX_SIZE; i++)
scroll_index_list[i] = 0;
}
break;
case MENU_NAVIGATION_CTL_CLEAR:
{
menu_navigation_set_selection(0);
menu_driver_navigation_set(true);
menu_driver_ctl(RARCH_MENU_CTL_NAVIGATION_CLEAR, data);
}
break;
case MENU_NAVIGATION_CTL_INCREMENT:
{
settings_t *settings = config_get_ptr();
unsigned *scroll_speed = (unsigned*)data;
size_t menu_list_size = menu_entries_get_size();
bool wraparound_enable = settings->bools.menu_navigation_wraparound_enable;
if (!scroll_speed)
return false;
if (selection_ptr >= menu_list_size - 1
&& !wraparound_enable)
return false;
if ((selection_ptr + (*scroll_speed)) < menu_list_size)
{
size_t idx = selection_ptr + (*scroll_speed);
menu_navigation_set_selection(idx);
menu_driver_navigation_set(true);
menu_navigation_ctl(MENU_NAVIGATION_CTL_INCREMENT, NULL);
}
else
{
if (wraparound_enable)
{
bool pending_push = false;
menu_navigation_ctl(MENU_NAVIGATION_CTL_CLEAR, &pending_push);
}
else
{
if (menu_list_size > 0)
{
menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_LAST, NULL);
menu_navigation_ctl(MENU_NAVIGATION_CTL_INCREMENT, NULL);
}
}
}
menu_driver_increment_navigation();
}
break;
case MENU_NAVIGATION_CTL_DECREMENT:
{
size_t idx = 0;
settings_t *settings = config_get_ptr();
unsigned *scroll_speed = (unsigned*)data;
size_t menu_list_size = menu_entries_get_size();
bool wraparound_enable = settings->bools.menu_navigation_wraparound_enable;
if (!scroll_speed)
return false;
if (selection_ptr == 0 && !wraparound_enable)
return false;
if (selection_ptr >= *scroll_speed)
idx = selection_ptr - *scroll_speed;
else
{
idx = menu_list_size - 1;
if (!wraparound_enable)
idx = 0;
}
menu_navigation_set_selection(idx);
menu_driver_navigation_set(true);
menu_navigation_ctl(MENU_NAVIGATION_CTL_DECREMENT, NULL);
menu_driver_decrement_navigation();
}
break;
case MENU_NAVIGATION_CTL_SET_LAST:
{
size_t menu_list_size = menu_entries_get_size();
size_t new_selection = menu_list_size - 1;
menu_navigation_set_selection(new_selection);
menu_driver_ctl(RARCH_MENU_CTL_NAVIGATION_SET_LAST, NULL);
}
break;
case MENU_NAVIGATION_CTL_ASCEND_ALPHABET:
{
size_t i = 0, ptr;
size_t *ptr_out = (size_t*)&selection_ptr;
size_t menu_list_size = menu_entries_get_size();
if (!scroll_index_size || !ptr_out)
return false;
ptr = *ptr_out;
if (ptr == scroll_index_list[scroll_index_size - 1])
{
*ptr_out = menu_list_size - 1;
menu_driver_ctl(RARCH_MENU_CTL_NAVIGATION_ASCEND_ALPHABET, ptr_out);
return true;
}
while (i < scroll_index_size - 1
&& scroll_index_list[i + 1] <= ptr)
i++;
*ptr_out = scroll_index_list[i + 1];
if (*ptr_out >= menu_list_size)
*ptr_out = menu_list_size - 1;
menu_driver_ctl(RARCH_MENU_CTL_NAVIGATION_ASCEND_ALPHABET, ptr_out);
}
break;
case MENU_NAVIGATION_CTL_DESCEND_ALPHABET:
{
size_t i = 0, ptr;
size_t *ptr_out = (size_t*)&selection_ptr;
if (!scroll_index_size || !ptr_out)
return false;
ptr = *ptr_out;
if (ptr == 0)
return false;
i = scroll_index_size - 1;
while (i && scroll_index_list[i - 1] >= ptr)
i--;
*ptr_out = scroll_index_list[i - 1];
menu_driver_ctl(
RARCH_MENU_CTL_NAVIGATION_DESCEND_ALPHABET, ptr_out);
}
break;
case MENU_NAVIGATION_CTL_CLEAR_SCROLL_INDICES:
scroll_index_size = 0;
break;
case MENU_NAVIGATION_CTL_ADD_SCROLL_INDEX:
{
size_t *sel = (size_t*)data;
if (!sel)
return false;
scroll_index_list[scroll_index_size++] = *sel;
}
break;
case MENU_NAVIGATION_CTL_GET_SCROLL_ACCEL:
{
size_t *sel = (size_t*)data;
if (!sel)
return false;
*sel = scroll_acceleration;
}
break;
case MENU_NAVIGATION_CTL_SET_SCROLL_ACCEL:
{
size_t *sel = (size_t*)data;
if (!sel)
return false;
scroll_acceleration = (unsigned)(*sel);
}
break;
case MENU_NAVIGATION_CTL_NONE:
break;
}
return true;
}

View File

@ -1,51 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _MENU_NAVIGATION_H
#define _MENU_NAVIGATION_H
#include <stddef.h>
#include <boolean.h>
#include <retro_common_api.h>
RETRO_BEGIN_DECLS
enum menu_navigation_ctl_state
{
MENU_NAVIGATION_CTL_NONE = 0,
MENU_NAVIGATION_CTL_CLEAR,
MENU_NAVIGATION_CTL_DEINIT,
MENU_NAVIGATION_CTL_INCREMENT,
MENU_NAVIGATION_CTL_DECREMENT,
MENU_NAVIGATION_CTL_SET_LAST,
MENU_NAVIGATION_CTL_DESCEND_ALPHABET,
MENU_NAVIGATION_CTL_ASCEND_ALPHABET,
MENU_NAVIGATION_CTL_CLEAR_SCROLL_INDICES,
MENU_NAVIGATION_CTL_ADD_SCROLL_INDEX,
MENU_NAVIGATION_CTL_SET_SCROLL_ACCEL,
MENU_NAVIGATION_CTL_GET_SCROLL_ACCEL
};
size_t menu_navigation_get_selection(void);
void menu_navigation_set_selection(size_t val);
bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data);
RETRO_END_DECLS
#endif

View File

@ -56,7 +56,6 @@
#include "menu_animation.h"
#include "menu_display.h"
#include "menu_input.h"
#include "menu_navigation.h"
#include "../core.h"
#include "../configuration.h"

View File

@ -21,7 +21,6 @@
#include "menu_input_dialog.h"
#include "../menu_driver.h"
#include "../menu_navigation.h"
/* This file provides an abstraction of the currently displayed
* menu.

View File

@ -21,7 +21,6 @@
#include "menu_input_bind_dialog.h"
#include "../menu_driver.h"
#include "../menu_navigation.h"
#include "../../input/input_config.h"

View File

@ -19,7 +19,6 @@
#include "menu_input_dialog.h"
#include "../menu_driver.h"
#include "../menu_navigation.h"
#include "../../input/input_driver.h"
static const char **menu_input_dialog_keyboard_buffer = {NULL};

View File

@ -20,7 +20,6 @@
#include "menu_list.h"
#include "../menu_driver.h"
#include "../menu_navigation.h"
struct menu_list
{

View File

@ -34,7 +34,7 @@
#ifdef HAVE_MENU
#include "../../../menu/widgets/menu_entry.h"
#include "../../../menu/menu_navigation.h"
#include "../../../menu/menu_driver.h"
#include "../../../menu/drivers/menu_generic.h"
#endif