Combine menu_list and menu_entries

This commit is contained in:
twinaphex 2018-02-25 00:39:20 +01:00
parent 2a6af87d23
commit 36f9d359c2
12 changed files with 223 additions and 301 deletions

View File

@ -767,7 +767,6 @@ ifeq ($(HAVE_MENU_COMMON), 1)
menu/widgets/menu_input_dialog.o \
menu/widgets/menu_input_bind_dialog.o \
menu/widgets/menu_entry.o \
menu/widgets/menu_list.o \
menu/widgets/menu_osk.o \
menu/menu_cbs.o \
menu/cbs/menu_cbs_ok.o \

View File

@ -1136,7 +1136,6 @@ MENU
#include "../menu/widgets/menu_dialog.c"
#include "../menu/widgets/menu_input_dialog.c"
#include "../menu/widgets/menu_input_bind_dialog.c"
#include "../menu/widgets/menu_list.c"
#include "../menu/widgets/menu_osk.c"
#include "../menu/cbs/menu_cbs_ok.c"
#include "../menu/cbs/menu_cbs_cancel.c"

View File

@ -24,13 +24,12 @@
#include "../menu_content.h"
#include "../menu_driver.h"
#include "../menu_entries.h"
#include "../menu_cbs.h"
#include "../menu_input.h"
#include "../menu_setting.h"
#include "../menu_shader.h"
#include "../widgets/menu_list.h"
#include "../../configuration.h"
#include "../../core.h"
#include "../../core_info.h"

View File

@ -24,13 +24,12 @@
#include "../menu_content.h"
#include "../menu_driver.h"
#include "../menu_entries.h"
#include "../menu_cbs.h"
#include "../menu_input.h"
#include "../menu_setting.h"
#include "../menu_shader.h"
#include "../widgets/menu_list.h"
#include "../../configuration.h"
#include "../../core.h"
#include "../../core_info.h"

View File

@ -45,8 +45,8 @@
#include "../../core_info.h"
#include "../../core.h"
#include "../menu_entries.h"
#include "../widgets/menu_entry.h"
#include "../widgets/menu_list.h"
#include "../widgets/menu_input_dialog.h"
#include "../widgets/menu_osk.h"
#include "../widgets/menu_filebrowser.h"

View File

@ -51,14 +51,14 @@
#include "../frontend/drivers/platform_unix.h"
#endif
#include "menu_cbs.h"
#include "menu_content.h"
#include "menu_driver.h"
#include "menu_entries.h"
#include "menu_shader.h"
#include "menu_networking.h"
#include "widgets/menu_dialog.h"
#include "widgets/menu_list.h"
#include "widgets/menu_filebrowser.h"
#include "menu_cbs.h"
#include "../audio/audio_driver.h"
#include "../configuration.h"

View File

@ -39,8 +39,8 @@
#include "menu_driver.h"
#include "menu_cbs.h"
#include "menu_event.h"
#include "menu_entries.h"
#include "widgets/menu_dialog.h"
#include "widgets/menu_list.h"
#include "menu_shader.h"
#include "../config.def.h"

View File

@ -23,8 +23,6 @@
#include "menu_driver.h"
#include "menu_cbs.h"
#include "widgets/menu_list.h"
#include "../core.h"
#include "../retroarch.h"
#include "../version.h"
@ -36,6 +34,197 @@ static size_t menu_entries_begin = 0;
static rarch_setting_t *menu_entries_list_settings = NULL;
static menu_list_t *menu_entries_list = NULL;
struct menu_list
{
size_t menu_stack_size;
size_t selection_buf_size;
file_list_t **menu_stack;
file_list_t **selection_buf;
};
static void menu_list_free_list(file_list_t *list)
{
unsigned i;
for (i = 0; i < list->size; i++)
{
menu_ctx_list_t list_info;
list_info.list = list;
list_info.idx = i;
list_info.list_size = list->size;
menu_driver_ctl(RARCH_MENU_CTL_LIST_FREE, &list_info);
}
file_list_free(list);
}
static void menu_list_free(menu_list_t *menu_list)
{
unsigned i;
if (!menu_list)
return;
for (i = 0; i < menu_list->menu_stack_size; i++)
{
if (!menu_list->menu_stack[i])
continue;
menu_list_free_list(menu_list->menu_stack[i]);
menu_list->menu_stack[i] = NULL;
}
for (i = 0; i < menu_list->selection_buf_size; i++)
{
if (!menu_list->selection_buf[i])
continue;
menu_list_free_list(menu_list->selection_buf[i]);
menu_list->selection_buf[i] = NULL;
}
free(menu_list->menu_stack);
free(menu_list->selection_buf);
free(menu_list);
}
static menu_list_t *menu_list_new(void)
{
unsigned i;
menu_list_t *list = (menu_list_t*)malloc(sizeof(*list));
if (!list)
return NULL;
list->menu_stack_size = 1;
list->selection_buf_size = 1;
list->selection_buf = NULL;
list->menu_stack = (file_list_t**)
calloc(list->menu_stack_size, sizeof(*list->menu_stack));
if (!list->menu_stack)
goto error;
list->selection_buf = (file_list_t**)
calloc(list->selection_buf_size, sizeof(*list->selection_buf));
if (!list->selection_buf)
goto error;
for (i = 0; i < list->menu_stack_size; i++)
list->menu_stack[i] = (file_list_t*)
calloc(1, sizeof(*list->menu_stack[i]));
for (i = 0; i < list->selection_buf_size; i++)
list->selection_buf[i] = (file_list_t*)
calloc(1, sizeof(*list->selection_buf[i]));
return list;
error:
menu_list_free(list);
return NULL;
}
static file_list_t *menu_list_get(menu_list_t *list, unsigned idx)
{
if (!list)
return NULL;
return list->menu_stack[idx];
}
static file_list_t *menu_list_get_selection(menu_list_t *list, unsigned idx)
{
if (!list)
return NULL;
return list->selection_buf[idx];
}
static size_t menu_list_get_stack_size(menu_list_t *list, size_t idx)
{
if (!list)
return 0;
return file_list_get_size(list->menu_stack[idx]);
}
static int menu_list_flush_stack_type(const char *needle, const char *label,
unsigned type, unsigned final_type)
{
return needle ? !string_is_equal(needle, label) : (type != final_type);
}
static bool menu_list_pop_stack(menu_list_t *list,
size_t idx, size_t *directory_ptr, bool animate)
{
menu_ctx_list_t list_info;
bool refresh = false;
file_list_t *menu_list = menu_list_get(list, (unsigned)idx);
if (!list)
return false;
if (menu_list_get_stack_size(list, idx) <= 1)
return false;
list_info.type = MENU_LIST_PLAIN;
list_info.action = 0;
if (animate)
menu_driver_ctl(RARCH_MENU_CTL_LIST_CACHE, &list_info);
if (menu_list->size != 0)
{
menu_ctx_list_t list_info;
list_info.list = menu_list;
list_info.idx = menu_list->size - 1;
list_info.list_size = menu_list->size - 1;
menu_driver_ctl(RARCH_MENU_CTL_LIST_FREE, &list_info);
}
file_list_pop(menu_list, directory_ptr);
menu_driver_ctl(RARCH_MENU_CTL_LIST_SET_SELECTION, menu_list);
if (animate)
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
return true;
}
static void menu_list_flush_stack(menu_list_t *list,
size_t idx, const char *needle, unsigned final_type)
{
bool refresh = false;
const char *path = NULL;
const char *label = NULL;
unsigned type = 0;
size_t entry_idx = 0;
file_list_t *menu_list = menu_list_get(list, (unsigned)idx);
if (!list)
return;
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
file_list_get_last(menu_list,
&path, &label, &type, &entry_idx);
while (menu_list_flush_stack_type(
needle, label, type, final_type) != 0)
{
size_t new_selection_ptr = menu_navigation_get_selection();
if (!menu_list_pop_stack(list, idx, &new_selection_ptr, 1))
break;
menu_navigation_set_selection(new_selection_ptr);
menu_list = menu_list_get(list, (unsigned)idx);
file_list_get_last(menu_list,
&path, &label, &type, &entry_idx);
}
}
void menu_entries_get_at_offset(const file_list_t *list, size_t idx,
const char **path, const char **label, unsigned *file_type,
size_t *entry_idx, const char **alt)

View File

@ -22,7 +22,7 @@
#include <boolean.h>
#include <retro_common_api.h>
#include "widgets/menu_list.h"
#include <lists/file_list.h>
#include "menu_setting.h"
#include "menu_displaylist.h"
@ -52,6 +52,31 @@ enum menu_entries_ctl_state
MENU_ENTRIES_CTL_SHOW_BACK
};
enum menu_list_type
{
MENU_LIST_PLAIN = 0,
MENU_LIST_HORIZONTAL,
MENU_LIST_TABS
};
typedef struct menu_list menu_list_t;
typedef struct menu_ctx_list
{
enum menu_list_type type;
const char *path;
char *fullpath;
const char *label;
unsigned entry_type;
unsigned action;
size_t idx;
size_t selection;
size_t size;
size_t list_size;
void *entry;
file_list_t *list;
} menu_ctx_list_t;
typedef struct menu_file_list_cbs
{
enum msg_hash_enums enum_idx;

View File

@ -33,7 +33,6 @@
#include "menu_networking.h"
#include "menu_cbs.h"
#include "menu_entries.h"
#include "widgets/menu_list.h"
#include "../core_info.h"
#include "../configuration.h"

View File

@ -1,212 +0,0 @@
/* RetroArch - A frontend for libretro.
* 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 <string.h>
#include <string/stdstring.h>
#include "menu_list.h"
#include "../menu_driver.h"
struct menu_list
{
size_t menu_stack_size;
size_t selection_buf_size;
file_list_t **menu_stack;
file_list_t **selection_buf;
};
void menu_list_free_list(file_list_t *list)
{
unsigned i;
for (i = 0; i < list->size; i++)
{
menu_ctx_list_t list_info;
list_info.list = list;
list_info.idx = i;
list_info.list_size = list->size;
menu_driver_ctl(RARCH_MENU_CTL_LIST_FREE, &list_info);
}
file_list_free(list);
}
void menu_list_free(menu_list_t *menu_list)
{
unsigned i;
if (!menu_list)
return;
for (i = 0; i < menu_list->menu_stack_size; i++)
{
if (!menu_list->menu_stack[i])
continue;
menu_list_free_list(menu_list->menu_stack[i]);
menu_list->menu_stack[i] = NULL;
}
for (i = 0; i < menu_list->selection_buf_size; i++)
{
if (!menu_list->selection_buf[i])
continue;
menu_list_free_list(menu_list->selection_buf[i]);
menu_list->selection_buf[i] = NULL;
}
free(menu_list->menu_stack);
free(menu_list->selection_buf);
free(menu_list);
}
menu_list_t *menu_list_new(void)
{
unsigned i;
menu_list_t *list = (menu_list_t*)malloc(sizeof(*list));
if (!list)
return NULL;
list->menu_stack_size = 1;
list->selection_buf_size = 1;
list->selection_buf = NULL;
list->menu_stack = (file_list_t**)
calloc(list->menu_stack_size, sizeof(*list->menu_stack));
if (!list->menu_stack)
goto error;
list->selection_buf = (file_list_t**)
calloc(list->selection_buf_size, sizeof(*list->selection_buf));
if (!list->selection_buf)
goto error;
for (i = 0; i < list->menu_stack_size; i++)
list->menu_stack[i] = (file_list_t*)
calloc(1, sizeof(*list->menu_stack[i]));
for (i = 0; i < list->selection_buf_size; i++)
list->selection_buf[i] = (file_list_t*)
calloc(1, sizeof(*list->selection_buf[i]));
return list;
error:
menu_list_free(list);
return NULL;
}
file_list_t *menu_list_get(menu_list_t *list, unsigned idx)
{
if (!list)
return NULL;
return list->menu_stack[idx];
}
file_list_t *menu_list_get_selection(menu_list_t *list, unsigned idx)
{
if (!list)
return NULL;
return list->selection_buf[idx];
}
size_t menu_list_get_stack_size(menu_list_t *list, size_t idx)
{
if (!list)
return 0;
return file_list_get_size(list->menu_stack[idx]);
}
static int menu_list_flush_stack_type(const char *needle, const char *label,
unsigned type, unsigned final_type)
{
return needle ? !string_is_equal(needle, label) : (type != final_type);
}
void menu_list_flush_stack(menu_list_t *list,
size_t idx, const char *needle, unsigned final_type)
{
bool refresh = false;
const char *path = NULL;
const char *label = NULL;
unsigned type = 0;
size_t entry_idx = 0;
file_list_t *menu_list = menu_list_get(list, (unsigned)idx);
if (!list)
return;
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
file_list_get_last(menu_list,
&path, &label, &type, &entry_idx);
while (menu_list_flush_stack_type(
needle, label, type, final_type) != 0)
{
size_t new_selection_ptr = menu_navigation_get_selection();
if (!menu_list_pop_stack(list, idx, &new_selection_ptr, 1))
break;
menu_navigation_set_selection(new_selection_ptr);
menu_list = menu_list_get(list, (unsigned)idx);
file_list_get_last(menu_list,
&path, &label, &type, &entry_idx);
}
}
bool menu_list_pop_stack(menu_list_t *list,
size_t idx, size_t *directory_ptr, bool animate)
{
menu_ctx_list_t list_info;
bool refresh = false;
file_list_t *menu_list = menu_list_get(list, (unsigned)idx);
if (!list)
return false;
if (menu_list_get_stack_size(list, idx) <= 1)
return false;
list_info.type = MENU_LIST_PLAIN;
list_info.action = 0;
if (animate)
menu_driver_ctl(RARCH_MENU_CTL_LIST_CACHE, &list_info);
if (menu_list->size != 0)
{
menu_ctx_list_t list_info;
list_info.list = menu_list;
list_info.idx = menu_list->size - 1;
list_info.list_size = menu_list->size - 1;
menu_driver_ctl(RARCH_MENU_CTL_LIST_FREE, &list_info);
}
file_list_pop(menu_list, directory_ptr);
menu_driver_ctl(RARCH_MENU_CTL_LIST_SET_SELECTION, menu_list);
if (animate)
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
return true;
}

View File

@ -1,75 +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_WIDGETS_LIST_H
#define _MENU_WIDGETS_LIST_H
#include <stdint.h>
#include <stdlib.h>
#include <boolean.h>
#include <retro_common_api.h>
#include <lists/file_list.h>
RETRO_BEGIN_DECLS
enum menu_list_type
{
MENU_LIST_PLAIN = 0,
MENU_LIST_HORIZONTAL,
MENU_LIST_TABS
};
typedef struct menu_ctx_list
{
enum menu_list_type type;
const char *path;
char *fullpath;
const char *label;
unsigned entry_type;
unsigned action;
size_t idx;
size_t selection;
size_t size;
size_t list_size;
void *entry;
file_list_t *list;
} menu_ctx_list_t;
typedef struct menu_list menu_list_t;
void menu_list_free_list(file_list_t *list);
void menu_list_free(menu_list_t *menu_list);
menu_list_t *menu_list_new(void);
file_list_t *menu_list_get(menu_list_t *list, unsigned idx);
file_list_t *menu_list_get_selection(menu_list_t *list, unsigned idx);
size_t menu_list_get_stack_size(menu_list_t *list, size_t idx);
void menu_list_flush_stack(menu_list_t *list,
size_t idx, const char *needle, unsigned final_type);
bool menu_list_pop_stack(menu_list_t *list,
size_t idx, size_t *directory_ptr, bool animate);
RETRO_END_DECLS
#endif