Split up menu OSK code to separate file - menu/widgets/menu_osk.c

This commit is contained in:
twinaphex 2017-01-12 11:31:24 +01:00
parent 24dc890b78
commit ef974086aa
11 changed files with 252 additions and 156 deletions

View File

@ -527,6 +527,7 @@ ifeq ($(HAVE_MENU_COMMON), 1)
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 \
menu/cbs/menu_cbs_cancel.o \

View File

@ -945,6 +945,7 @@ MENU
#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"
#include "../menu/cbs/menu_cbs_select.c"

View File

@ -48,6 +48,7 @@
#include "../menu_event.h"
#include "../widgets/menu_input_dialog.h"
#include "../widgets/menu_osk.h"
#include "../../core_info.h"
#include "../../core.h"

View File

@ -49,6 +49,7 @@
#include "../widgets/menu_entry.h"
#include "../widgets/menu_list.h"
#include "../widgets/menu_input_dialog.h"
#include "../widgets/menu_osk.h"
#include "../menu_event.h"

View File

@ -228,7 +228,7 @@ static void menu_input_key_event(bool down, unsigned keycode,
RARCH_LOG("down: %d, keycode: %d, mod: %d, character: %d\n", down, keycode, mod, character);
#endif
menu_event_keyboard_set(down, (enum retro_key)keycode);
menu_event_kb_set(down, (enum retro_key)keycode);
}
static void menu_driver_toggle(bool on)

View File

@ -24,11 +24,11 @@
#include "../config.h"
#endif
#include <encodings/utf.h>
#include <string/stdstring.h>
#include "widgets/menu_entry.h"
#include "widgets/menu_input_dialog.h"
#include "widgets/menu_osk.h"
#include "menu_event.h"
@ -42,104 +42,8 @@
#include "../configuration.h"
#include "../runloop.h"
#if defined(_MSC_VER) && !defined(_XBOX)
/* https://support.microsoft.com/en-us/kb/980263 */
#pragma execution_character_set("utf-8")
#endif
#define OSK_CHARS_PER_LINE 11
static unsigned char menu_keyboard_key_state[RETROK_LAST];
enum osk_type
{
OSK_TYPE_UNKNOWN = 0U,
OSK_LOWERCASE_LATIN,
OSK_UPPERCASE_LATIN,
OSK_HIRAGANA_PAGE1,
OSK_HIRAGANA_PAGE2,
OSK_KATAKANA_PAGE1,
OSK_KATAKANA_PAGE2,
OSK_TYPE_LAST
};
static int osk_ptr = 0;
static enum osk_type osk_idx = OSK_LOWERCASE_LATIN;
static const char *osk_grid[45];
static const char *uppercase_grid[] = {
"!","@","#","$","%","^","&","*","(",")","",
"Q","W","E","R","T","Y","U","I","O","P","",
"A","S","D","F","G","H","J","K","L",":","",
"Z","X","C","V","B","N","M"," ","<",">",""};
static const char *lowercase_grid[] = {
"1","2","3","4","5","6","7","8","9","0","",
"q","w","e","r","t","y","u","i","o","p","",
"a","s","d","f","g","h","j","k","l",";","",
"z","x","c","v","b","n","m"," ",",",".",""};
static const char *hiragana_page1_grid[] = {
"","","","","","","","","","","",
"","","","","","","","","","","",
"","","","","","","","","","","",
"","","","","","","","","","",""};
static const char *hiragana_page2_grid[] = {
"","","","","","","","","","","",
"","","","","","","","","","","",
"","","","","","","","","","","",
"","","","","","","","","","",""};
static const char *katakana_page1_grid[] = {
"","","","","","","","","","","",
"","","","","","","","","","","",
"","","","","","","","","","","",
"","","","","","","","","","",""};
static const char *katakana_page2_grid[] = {
"","","","","","","","","","","",
"","","","","","","","","","","",
"","","","","","","","","","","",
"","","","","","","","","","",""};
int menu_event_get_osk_ptr(void)
{
return osk_ptr;
}
void menu_event_set_osk_ptr(int i)
{
osk_ptr = i;
}
void menu_event_osk_append(int ptr)
{
if (ptr < 0)
return;
if (string_is_equal(osk_grid[ptr],""))
input_keyboard_event(true, '\x7f', '\x7f', 0, RETRO_DEVICE_KEYBOARD);
else if (string_is_equal(osk_grid[ptr],""))
input_keyboard_event(true, '\n', '\n', 0, RETRO_DEVICE_KEYBOARD);
else if (string_is_equal(osk_grid[ptr],""))
osk_idx = OSK_UPPERCASE_LATIN;
else if (string_is_equal(osk_grid[ptr],""))
osk_idx = OSK_LOWERCASE_LATIN;
else if (string_is_equal(osk_grid[ptr],""))
if (osk_idx < OSK_TYPE_LAST - 1)
osk_idx = (enum osk_type)(osk_idx + 1);
else
osk_idx = (enum osk_type)(OSK_TYPE_UNKNOWN + 1);
else
input_keyboard_line_append(osk_grid[ptr]);
}
const char** menu_event_get_osk_grid(void)
{
return osk_grid;
}
static int menu_event_pointer(unsigned *action)
{
rarch_joypad_info_t joypad_info;
@ -182,22 +86,27 @@ static int menu_event_pointer(unsigned *action)
return 0;
}
unsigned char menu_event_keyboard_is_set(enum retro_key key)
unsigned char menu_event_kb_is_set(enum retro_key key)
{
return menu_keyboard_key_state[key];
}
void menu_event_keyboard_set(bool down, enum retro_key key)
void menu_event_kb_set_internal(unsigned idx, unsigned char key)
{
menu_keyboard_key_state[idx] = key;
}
void menu_event_kb_set(bool down, enum retro_key key)
{
if (key == RETROK_UNKNOWN)
{
unsigned i;
for (i = 0; i < RETROK_LAST; i++)
menu_keyboard_key_state[i] = (menu_keyboard_key_state[i] & 1) << 1;
menu_event_kb_set_internal(i, (menu_event_kb_is_set(i) & 1) << 1);
}
else
menu_keyboard_key_state[key] = ((menu_keyboard_key_state[key] & 1) << 1) | down;
menu_event_kb_set_internal(key, ((menu_event_kb_is_set(key) & 1) << 1) | down);
}
unsigned menu_event(uint64_t input, uint64_t trigger_input)
@ -279,73 +188,52 @@ unsigned menu_event(uint64_t input, uint64_t trigger_input)
if (menu_input_dialog_get_display_kb())
{
switch (osk_idx)
{
case OSK_HIRAGANA_PAGE1:
memcpy(osk_grid, hiragana_page1_grid, sizeof(hiragana_page1_grid));
break;
case OSK_HIRAGANA_PAGE2:
memcpy(osk_grid, hiragana_page2_grid, sizeof(hiragana_page2_grid));
break;
case OSK_KATAKANA_PAGE1:
memcpy(osk_grid, katakana_page1_grid, sizeof(katakana_page1_grid));
break;
case OSK_KATAKANA_PAGE2:
memcpy(osk_grid, katakana_page2_grid, sizeof(katakana_page2_grid));
break;
case OSK_UPPERCASE_LATIN:
memcpy(osk_grid, uppercase_grid, sizeof(uppercase_grid));
break;
case OSK_LOWERCASE_LATIN:
default:
memcpy(osk_grid, lowercase_grid, sizeof(lowercase_grid));
break;
}
menu_event_osk_iterate();
if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN))
{
if (osk_ptr < 33)
osk_ptr = osk_ptr + OSK_CHARS_PER_LINE;
if (menu_event_get_osk_ptr() < 33)
menu_event_set_osk_ptr(menu_event_get_osk_ptr() + OSK_CHARS_PER_LINE);
}
if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP))
{
if (osk_ptr >= OSK_CHARS_PER_LINE)
osk_ptr = osk_ptr - OSK_CHARS_PER_LINE;
if (menu_event_get_osk_ptr() >= OSK_CHARS_PER_LINE)
menu_event_set_osk_ptr(menu_event_get_osk_ptr() - OSK_CHARS_PER_LINE);
}
if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_RIGHT))
{
if (osk_ptr < 43)
osk_ptr = osk_ptr + 1;
if (menu_event_get_osk_ptr() < 43)
menu_event_set_osk_ptr(menu_event_get_osk_ptr() + 1);
}
if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT))
{
if (osk_ptr >= 1)
osk_ptr = osk_ptr - 1;
if (menu_event_get_osk_ptr() >= 1)
menu_event_set_osk_ptr(menu_event_get_osk_ptr() - 1);
}
if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L))
{
if (osk_idx > OSK_TYPE_UNKNOWN + 1)
osk_idx = (enum osk_type)(osk_idx - 1);
if (menu_event_get_osk_idx() > OSK_TYPE_UNKNOWN + 1)
menu_event_set_osk_idx((enum osk_type)(menu_event_get_osk_idx() - 1));
else
osk_idx = (enum osk_type)(OSK_TYPE_LAST - 1);
menu_event_set_osk_idx((enum osk_type)(OSK_TYPE_LAST - 1));
}
if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R))
{
if (osk_idx < OSK_TYPE_LAST - 1)
osk_idx = (enum osk_type)(osk_idx + 1);
if (menu_event_get_osk_idx() < OSK_TYPE_LAST - 1)
menu_event_set_osk_idx((enum osk_type)(menu_event_get_osk_idx() + 1));
else
osk_idx = (enum osk_type)(OSK_TYPE_UNKNOWN + 1);
menu_event_set_osk_idx((enum osk_type)(OSK_TYPE_UNKNOWN + 1));
}
if (trigger_input & (UINT64_C(1) << menu_ok_btn))
{
if (osk_ptr >= 0)
menu_event_osk_append(osk_ptr);
if (menu_event_get_osk_ptr() >= 0)
menu_event_osk_append(menu_event_get_osk_ptr());
}
if (trigger_input & (UINT64_C(1) << menu_cancel_btn))
@ -388,10 +276,10 @@ unsigned menu_event(uint64_t input, uint64_t trigger_input)
else if (trigger_input & (UINT64_C(1) << RARCH_MENU_TOGGLE))
ret = MENU_ACTION_TOGGLE;
if (menu_keyboard_key_state[RETROK_F11])
if (menu_event_kb_is_set(RETROK_F11))
{
command_event(CMD_EVENT_GRAB_MOUSE_TOGGLE, NULL);
menu_keyboard_key_state[RETROK_F11] = false;
menu_event_kb_set_internal(RETROK_F11, 0);
}
if (runloop_cmd_press(trigger_input, RARCH_QUIT_KEY))

View File

@ -21,7 +21,6 @@
#include <compat/strl.h>
#include <retro_common_api.h>
#include <libretro.h>
RETRO_BEGIN_DECLS
@ -35,17 +34,11 @@ RETRO_BEGIN_DECLS
*/
unsigned menu_event(uint64_t input, uint64_t trigger_state);
void menu_event_keyboard_set(bool down, enum retro_key key);
void menu_event_kb_set(bool down, enum retro_key key);
unsigned char menu_event_keyboard_is_set(enum retro_key key);
unsigned char menu_event_kb_is_set(enum retro_key key);
int menu_event_get_osk_ptr(void);
void menu_event_set_osk_ptr(int a);
void menu_event_osk_append(int a);
const char** menu_event_get_osk_grid(void);
void menu_event_kb_set_internal(unsigned idx, unsigned char key);
RETRO_END_DECLS

View File

@ -25,6 +25,7 @@
#include "widgets/menu_input_dialog.h"
#include "widgets/menu_input_bind_dialog.h"
#include "widgets/menu_osk.h"
#include "menu_driver.h"
#include "menu_input.h"

151
menu/widgets/menu_osk.c Normal file
View File

@ -0,0 +1,151 @@
/* RetroArch - A frontend for libretro.
* 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 <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <libretro.h>
#include <string/stdstring.h>
#ifdef HAVE_CONFIG_H
#include "../../config.h"
#endif
#include <encodings/utf.h>
#include "menu_osk.h"
#include "../../input/input_keyboard.h"
#if defined(_MSC_VER) && !defined(_XBOX)
/* https://support.microsoft.com/en-us/kb/980263 */
#pragma execution_character_set("utf-8")
#endif
static const char *osk_grid[45] = {NULL};
static int osk_ptr = 0;
static enum osk_type osk_idx = OSK_LOWERCASE_LATIN;
static const char *uppercase_grid[] = {
"!","@","#","$","%","^","&","*","(",")","",
"Q","W","E","R","T","Y","U","I","O","P","",
"A","S","D","F","G","H","J","K","L",":","",
"Z","X","C","V","B","N","M"," ","<",">",""};
static const char *lowercase_grid[] = {
"1","2","3","4","5","6","7","8","9","0","",
"q","w","e","r","t","y","u","i","o","p","",
"a","s","d","f","g","h","j","k","l",";","",
"z","x","c","v","b","n","m"," ",",",".",""};
static const char *hiragana_page1_grid[] = {
"","","","","","","","","","","",
"","","","","","","","","","","",
"","","","","","","","","","","",
"","","","","","","","","","",""};
static const char *hiragana_page2_grid[] = {
"","","","","","","","","","","",
"","","","","","","","","","","",
"","","","","","","","","","","",
"","","","","","","","","","",""};
static const char *katakana_page1_grid[] = {
"","","","","","","","","","","",
"","","","","","","","","","","",
"","","","","","","","","","","",
"","","","","","","","","","",""};
static const char *katakana_page2_grid[] = {
"","","","","","","","","","","",
"","","","","","","","","","","",
"","","","","","","","","","","",
"","","","","","","","","","",""};
void menu_event_set_osk_idx(enum osk_type idx)
{
osk_idx = idx;
}
enum osk_type menu_event_get_osk_idx(void)
{
return osk_idx;
}
int menu_event_get_osk_ptr(void)
{
return osk_ptr;
}
void menu_event_set_osk_ptr(int i)
{
osk_ptr = i;
}
void menu_event_osk_append(int ptr)
{
if (ptr < 0)
return;
if (string_is_equal(osk_grid[ptr],""))
input_keyboard_event(true, '\x7f', '\x7f', 0, RETRO_DEVICE_KEYBOARD);
else if (string_is_equal(osk_grid[ptr],""))
input_keyboard_event(true, '\n', '\n', 0, RETRO_DEVICE_KEYBOARD);
else if (string_is_equal(osk_grid[ptr],""))
menu_event_set_osk_idx(OSK_UPPERCASE_LATIN);
else if (string_is_equal(osk_grid[ptr],""))
menu_event_set_osk_idx(OSK_LOWERCASE_LATIN);
else if (string_is_equal(osk_grid[ptr],""))
if (menu_event_get_osk_idx() < OSK_TYPE_LAST - 1)
menu_event_set_osk_idx((enum osk_type)(menu_event_get_osk_idx() + 1));
else
menu_event_set_osk_idx((enum osk_type)(OSK_TYPE_UNKNOWN + 1));
else
input_keyboard_line_append(osk_grid[ptr]);
}
void menu_event_osk_iterate(void)
{
switch (menu_event_get_osk_idx())
{
case OSK_HIRAGANA_PAGE1:
memcpy(osk_grid, hiragana_page1_grid, sizeof(hiragana_page1_grid));
break;
case OSK_HIRAGANA_PAGE2:
memcpy(osk_grid, hiragana_page2_grid, sizeof(hiragana_page2_grid));
break;
case OSK_KATAKANA_PAGE1:
memcpy(osk_grid, katakana_page1_grid, sizeof(katakana_page1_grid));
break;
case OSK_KATAKANA_PAGE2:
memcpy(osk_grid, katakana_page2_grid, sizeof(katakana_page2_grid));
break;
case OSK_UPPERCASE_LATIN:
memcpy(osk_grid, uppercase_grid, sizeof(uppercase_grid));
break;
case OSK_LOWERCASE_LATIN:
default:
memcpy(osk_grid, lowercase_grid, sizeof(lowercase_grid));
break;
}
}
const char** menu_event_get_osk_grid(void)
{
return osk_grid;
}

59
menu/widgets/menu_osk.h Normal file
View File

@ -0,0 +1,59 @@
/* 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_WIDGETS_OSK_H
#define _MENU_WIDGETS_OSK_H
#include <stdint.h>
#include <stdlib.h>
#include <boolean.h>
#include <retro_common_api.h>
#define OSK_CHARS_PER_LINE 11
RETRO_BEGIN_DECLS
enum osk_type
{
OSK_TYPE_UNKNOWN = 0U,
OSK_LOWERCASE_LATIN,
OSK_UPPERCASE_LATIN,
OSK_HIRAGANA_PAGE1,
OSK_HIRAGANA_PAGE2,
OSK_KATAKANA_PAGE1,
OSK_KATAKANA_PAGE2,
OSK_TYPE_LAST
};
enum osk_type menu_event_get_osk_idx(void);
void menu_event_set_osk_idx(enum osk_type idx);
int menu_event_get_osk_ptr(void);
void menu_event_set_osk_ptr(int a);
void menu_event_osk_append(int a);
void menu_event_osk_iterate(void);
const char** menu_event_get_osk_grid(void);
RETRO_END_DECLS
#endif

View File

@ -789,7 +789,7 @@ static enum runloop_state runloop_check_state(
command_event(CMD_EVENT_GAME_FOCUS_TOGGLE, (void*)(intptr_t)0);
#ifdef HAVE_MENU
if (menu_event_keyboard_is_set(RETROK_F1) == 1)
if (menu_event_kb_is_set(RETROK_F1) == 1)
{
if (menu_driver_ctl(RARCH_MENU_CTL_IS_ALIVE, NULL))
{
@ -797,11 +797,11 @@ static enum runloop_state runloop_check_state(
!rarch_ctl(RARCH_CTL_IS_DUMMY_CORE, NULL))
{
rarch_ctl(RARCH_CTL_MENU_RUNNING_FINISHED, NULL);
menu_event_keyboard_set(false, RETROK_F1);
menu_event_kb_set(false, RETROK_F1);
}
}
}
else if ((!menu_event_keyboard_is_set(RETROK_F1) &&
else if ((!menu_event_kb_is_set(RETROK_F1) &&
runloop_cmd_triggered(trigger_input, RARCH_MENU_TOGGLE)) ||
rarch_ctl(RARCH_CTL_IS_DUMMY_CORE, NULL))
{
@ -818,7 +818,7 @@ static enum runloop_state runloop_check_state(
}
}
else
menu_event_keyboard_set(false, RETROK_F1);
menu_event_kb_set(false, RETROK_F1);
if (menu_driver_ctl(RARCH_MENU_CTL_IS_ALIVE, NULL))
{