Create menu_input_dialog

This commit is contained in:
twinaphex 2016-09-15 19:23:32 +02:00
parent 760d4811e0
commit 8fd5c5817a
8 changed files with 203 additions and 142 deletions

View File

@ -510,6 +510,7 @@ ifeq ($(HAVE_MENU_COMMON), 1)
menu/menu_setting.o \
menu/menu_shader.o \
menu/widgets/menu_dialog.o \
menu/widgets/menu_input_dialog.o \
menu/widgets/menu_entry.o \
menu/widgets/menu_list.o \
menu/menu_cbs.o \

View File

@ -894,6 +894,7 @@ MENU
#include "../menu/menu_content.c"
#include "../menu/widgets/menu_entry.c"
#include "../menu/widgets/menu_dialog.c"
#include "../menu/widgets/menu_input_dialog.c"
#include "../menu/widgets/menu_list.c"
#include "../menu/cbs/menu_cbs_ok.c"
#include "../menu/cbs/menu_cbs_cancel.c"

View File

@ -32,6 +32,7 @@
#include "../menu_shader.h"
#include "../menu_navigation.h"
#include "../widgets/menu_dialog.h"
#include "../widgets/menu_input_dialog.h"
#include "../menu_content.h"
#include "../../core.h"

View File

@ -40,6 +40,7 @@
#include "menu_animation.h"
#include "menu_display.h"
#include "widgets/menu_entry.h"
#include "widgets/menu_input_dialog.h"
#include "menu_setting.h"
#include "menu_shader.h"
#include "menu_navigation.h"
@ -132,24 +133,6 @@ static menu_input_t *menu_input_get_ptr(void)
return &menu_input_state;
}
static void menu_input_search_cb(void *userdata, const char *str)
{
size_t idx = 0;
file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0);
if (!selection_buf)
return;
if (str && *str && file_list_search(selection_buf, str, &idx))
{
bool scroll = true;
menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx);
menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll);
}
menu_input_dialog_end();
}
void menu_input_st_uint_cb(void *userdata, const char *str)
{
if (str && *str)
@ -674,101 +657,6 @@ bool menu_input_ctl(enum menu_input_ctl_state state, void *data)
return true;
}
static const char **menu_input_dialog_keyboard_buffer;
static bool menu_input_dialog_keyboard_display = false;
static unsigned menu_input_dialog_keyboard_type = 0;
static unsigned menu_input_dialog_keyboard_idx = 0;
static char menu_input_dialog_keyboard_label_setting[256] = {0};
static char menu_input_dialog_keyboard_label[256] = {0};
const char *menu_input_dialog_get_label_buffer(void)
{
return menu_input_dialog_keyboard_label;
}
const char *menu_input_dialog_get_label_setting_buffer(void)
{
return menu_input_dialog_keyboard_label_setting;
}
void menu_input_dialog_end(void)
{
menu_input_dialog_keyboard_type = 0;
menu_input_dialog_keyboard_idx = 0;
menu_input_dialog_keyboard_display = false;
menu_input_dialog_keyboard_label[0] = '\0';
menu_input_dialog_keyboard_label_setting[0] = '\0';
/* Avoid triggering states on pressing return. */
input_driver_set_flushing_input();
}
const char *menu_input_dialog_get_buffer(void)
{
if (!(*menu_input_dialog_keyboard_buffer))
return "";
return *menu_input_dialog_keyboard_buffer;
}
unsigned menu_input_dialog_get_kb_type(void)
{
return menu_input_dialog_keyboard_type;
}
bool menu_input_dialog_get_display_kb(void)
{
return menu_input_dialog_keyboard_display;
}
void menu_input_dialog_display_kb(void)
{
menu_input_dialog_keyboard_display = true;
}
void menu_input_dialog_hide_kb(void)
{
menu_input_dialog_keyboard_display = false;
}
bool menu_input_dialog_start_search(void)
{
menu_handle_t *menu = NULL;
if (!menu_driver_ctl(
RARCH_MENU_CTL_DRIVER_DATA_GET, &menu))
return false;
menu_input_dialog_display_kb();
strlcpy(menu_input_dialog_keyboard_label, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SEARCH),
sizeof(menu_input_dialog_keyboard_label));
menu_input_dialog_keyboard_buffer =
input_keyboard_start_line(menu, menu_input_search_cb);
return true;
}
bool menu_input_dialog_start(menu_input_ctx_line_t *line)
{
menu_handle_t *menu = NULL;
if (!line)
return false;
if (!menu_driver_ctl(RARCH_MENU_CTL_DRIVER_DATA_GET, &menu))
return false;
menu_input_dialog_display_kb();
strlcpy(menu_input_dialog_keyboard_label, line->label,
sizeof(menu_input_dialog_keyboard_label));
strlcpy(menu_input_dialog_keyboard_label_setting,
line->label_setting, sizeof(menu_input_dialog_keyboard_label_setting));
menu_input_dialog_keyboard_type = line->type;
menu_input_dialog_keyboard_idx = line->idx;
menu_input_dialog_keyboard_buffer =
input_keyboard_start_line(menu, line->cb);
return true;
}
static int menu_input_pointer(unsigned *action)
{
const struct retro_keybind *binds[MAX_USERS] = {NULL};

View File

@ -98,35 +98,6 @@ typedef struct menu_input_ctx_bind
size_t len;
} menu_input_ctx_bind_t;
typedef struct menu_input_ctx_line
{
const char *label;
const char *label_setting;
unsigned type;
unsigned idx;
input_keyboard_line_complete_t cb;
} menu_input_ctx_line_t;
const char *menu_input_dialog_get_label_setting_buffer(void);
const char *menu_input_dialog_get_label_buffer(void);
const char *menu_input_dialog_get_buffer(void);
unsigned menu_input_dialog_get_kb_type(void);
bool menu_input_dialog_start_search(void);
void menu_input_dialog_hide_kb(void);
void menu_input_dialog_display_kb(void);
bool menu_input_dialog_get_display_kb(void);
bool menu_input_dialog_start(menu_input_ctx_line_t *line);
void menu_input_dialog_end(void);
typedef struct menu_input_ctx_bind_limits
{
unsigned min;

View File

@ -0,0 +1,136 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2016 - 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 <compat/strl.h>
#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};
static bool menu_input_dialog_keyboard_display = false;
static unsigned menu_input_dialog_keyboard_type = 0;
static unsigned menu_input_dialog_keyboard_idx = 0;
static char menu_input_dialog_keyboard_label_setting[256] = {0};
static char menu_input_dialog_keyboard_label[256] = {0};
static void menu_input_search_cb(void *userdata, const char *str)
{
size_t idx = 0;
file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0);
if (!selection_buf)
return;
if (str && *str && file_list_search(selection_buf, str, &idx))
{
bool scroll = true;
menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx);
menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll);
}
menu_input_dialog_end();
}
const char *menu_input_dialog_get_label_buffer(void)
{
return menu_input_dialog_keyboard_label;
}
const char *menu_input_dialog_get_label_setting_buffer(void)
{
return menu_input_dialog_keyboard_label_setting;
}
void menu_input_dialog_end(void)
{
menu_input_dialog_keyboard_type = 0;
menu_input_dialog_keyboard_idx = 0;
menu_input_dialog_keyboard_display = false;
menu_input_dialog_keyboard_label[0] = '\0';
menu_input_dialog_keyboard_label_setting[0] = '\0';
/* Avoid triggering states on pressing return. */
input_driver_set_flushing_input();
}
const char *menu_input_dialog_get_buffer(void)
{
if (!(*menu_input_dialog_keyboard_buffer))
return "";
return *menu_input_dialog_keyboard_buffer;
}
unsigned menu_input_dialog_get_kb_type(void)
{
return menu_input_dialog_keyboard_type;
}
bool menu_input_dialog_get_display_kb(void)
{
return menu_input_dialog_keyboard_display;
}
void menu_input_dialog_display_kb(void)
{
menu_input_dialog_keyboard_display = true;
}
void menu_input_dialog_hide_kb(void)
{
menu_input_dialog_keyboard_display = false;
}
bool menu_input_dialog_start_search(void)
{
menu_handle_t *menu = NULL;
if (!menu_driver_ctl(
RARCH_MENU_CTL_DRIVER_DATA_GET, &menu))
return false;
menu_input_dialog_display_kb();
strlcpy(menu_input_dialog_keyboard_label, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SEARCH),
sizeof(menu_input_dialog_keyboard_label));
menu_input_dialog_keyboard_buffer =
input_keyboard_start_line(menu, menu_input_search_cb);
return true;
}
bool menu_input_dialog_start(menu_input_ctx_line_t *line)
{
menu_handle_t *menu = NULL;
if (!line)
return false;
if (!menu_driver_ctl(RARCH_MENU_CTL_DRIVER_DATA_GET, &menu))
return false;
menu_input_dialog_display_kb();
strlcpy(menu_input_dialog_keyboard_label, line->label,
sizeof(menu_input_dialog_keyboard_label));
strlcpy(menu_input_dialog_keyboard_label_setting,
line->label_setting, sizeof(menu_input_dialog_keyboard_label_setting));
menu_input_dialog_keyboard_type = line->type;
menu_input_dialog_keyboard_idx = line->idx;
menu_input_dialog_keyboard_buffer =
input_keyboard_start_line(menu, line->cb);
return true;
}

View File

@ -0,0 +1,62 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2016 - 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_INPUT_DIALOG_H
#define _MENU_INPUT_DIALOG_H
#include <stdint.h>
#include <stdlib.h>
#include <boolean.h>
#include <retro_common_api.h>
#include "../../input/input_keyboard.h"
RETRO_BEGIN_DECLS
typedef struct menu_input_ctx_line
{
const char *label;
const char *label_setting;
unsigned type;
unsigned idx;
input_keyboard_line_complete_t cb;
} menu_input_ctx_line_t;
const char *menu_input_dialog_get_label_setting_buffer(void);
const char *menu_input_dialog_get_label_buffer(void);
const char *menu_input_dialog_get_buffer(void);
unsigned menu_input_dialog_get_kb_type(void);
bool menu_input_dialog_start_search(void);
void menu_input_dialog_hide_kb(void);
void menu_input_dialog_display_kb(void);
bool menu_input_dialog_get_display_kb(void);
bool menu_input_dialog_start(menu_input_ctx_line_t *line);
void menu_input_dialog_end(void);
RETRO_END_DECLS
#endif

View File

@ -25,6 +25,7 @@
#ifdef HAVE_MENU
#include "menu/menu_driver.h"
#include "menu/widgets/menu_input_dialog.h"
#endif
#include "configuration.h"