From ad4b51b9039f16a4cc6aa5cbb502cff219f30f78 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 12 Sep 2021 19:27:12 +0200 Subject: [PATCH] Move cde from retroarch.c to input_driver.c --- input/input_driver.c | 76 ++++++++++++++++++++++++++++++++++++++++++ input/input_osk.h | 14 ++++++++ retroarch.c | 78 ++++---------------------------------------- 3 files changed, 96 insertions(+), 72 deletions(-) diff --git a/input/input_driver.c b/input/input_driver.c index 71cdf8d0a4..232d3a6fc6 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -19,10 +19,12 @@ #include #include +#include #include #include "input_driver.h" #include "input_keymaps.h" +#include "input_osk.h" #ifdef HAVE_NETWORKING #include @@ -2014,3 +2016,77 @@ void input_config_get_bind_string_joyaxis( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE)); } } + +void osk_update_last_codepoint( + unsigned *last_codepoint, + unsigned *last_codepoint_len, + const char *word) +{ + const char *letter = word; + const char *pos = letter; + + if (word[0] == 0) + { + *last_codepoint = 0; + *last_codepoint_len = 0; + return; + } + + for (;;) + { + unsigned codepoint = utf8_walk(&letter); + if (letter[0] == 0) + { + *last_codepoint = codepoint; + *last_codepoint_len = (unsigned)(letter - pos); + break; + } + pos = letter; + } +} + +void input_event_osk_append( + input_keyboard_line_t *keyboard_line, + enum osk_type *osk_idx, + unsigned *osk_last_codepoint, + unsigned *osk_last_codepoint_len, + int ptr, + bool show_symbol_pages, + const char *word) +{ +#ifdef HAVE_LANGEXTRA + if (string_is_equal(word, "\xe2\x87\xa6")) /* backspace character */ + input_keyboard_event(true, '\x7f', '\x7f', 0, RETRO_DEVICE_KEYBOARD); + else if (string_is_equal(word, "\xe2\x8f\x8e")) /* return character */ + input_keyboard_event(true, '\n', '\n', 0, RETRO_DEVICE_KEYBOARD); + else + if (string_is_equal(word, "\xe2\x87\xa7")) /* up arrow */ + *osk_idx = OSK_UPPERCASE_LATIN; + else if (string_is_equal(word, "\xe2\x87\xa9")) /* down arrow */ + *osk_idx = OSK_LOWERCASE_LATIN; + else if (string_is_equal(word,"\xe2\x8a\x95")) /* plus sign (next button) */ +#else + if (string_is_equal(word, "Bksp")) + input_keyboard_event(true, '\x7f', '\x7f', 0, RETRO_DEVICE_KEYBOARD); + else if (string_is_equal(word, "Enter")) + input_keyboard_event(true, '\n', '\n', 0, RETRO_DEVICE_KEYBOARD); + else + if (string_is_equal(word, "Upper")) + *osk_idx = OSK_UPPERCASE_LATIN; + else if (string_is_equal(word, "Lower")) + *osk_idx = OSK_LOWERCASE_LATIN; + else if (string_is_equal(word, "Next")) +#endif + if (*osk_idx < (show_symbol_pages ? OSK_TYPE_LAST - 1 : OSK_SYMBOLS_PAGE1)) + *osk_idx = (enum osk_type)(*osk_idx + 1); + else + *osk_idx = ((enum osk_type)(OSK_TYPE_UNKNOWN + 1)); + else + { + input_keyboard_line_append(keyboard_line, word); + osk_update_last_codepoint( + osk_last_codepoint, + osk_last_codepoint_len, + word); + } +} diff --git a/input/input_osk.h b/input/input_osk.h index fd898fa12a..e7f3f79bec 100644 --- a/input/input_osk.h +++ b/input/input_osk.h @@ -49,6 +49,20 @@ enum osk_type int input_event_get_osk_ptr(void); +void input_event_osk_append( + input_keyboard_line_t *keyboard_line, + enum osk_type *osk_idx, + unsigned *osk_last_codepoint, + unsigned *osk_last_codepoint_len, + int ptr, + bool show_symbol_pages, + const char *word); + +void osk_update_last_codepoint( + unsigned *last_codepoint, + unsigned *last_codepoint_len, + const char *word); + char **input_event_get_osk_grid(void); RETRO_END_DECLS diff --git a/retroarch.c b/retroarch.c index 738afa85b3..9402e88210 100644 --- a/retroarch.c +++ b/retroarch.c @@ -7578,33 +7578,6 @@ bool gfx_widgets_ready(void) #endif } -static void osk_update_last_codepoint( - unsigned *last_codepoint, - unsigned *last_codepoint_len, - const char *word) -{ - const char *letter = word; - const char *pos = letter; - - if (word[0] == 0) - { - *last_codepoint = 0; - *last_codepoint_len = 0; - return; - } - - for (;;) - { - unsigned codepoint = utf8_walk(&letter); - if (letter[0] == 0) - { - *last_codepoint = codepoint; - *last_codepoint_len = (unsigned)(letter - pos); - break; - } - pos = letter; - } -} #ifdef HAVE_MENU static void menu_input_search_cb(void *userdata, const char *str) @@ -19099,49 +19072,6 @@ static int16_t input_state(unsigned port, unsigned device, /* MENU INPUT */ #ifdef HAVE_MENU -static void input_event_osk_append( - struct rarch_state *p_rarch, - enum osk_type *osk_idx, int ptr, - bool show_symbol_pages, - const char *word) -{ -#ifdef HAVE_LANGEXTRA - if (string_is_equal(word, "\xe2\x87\xa6")) /* backspace character */ - input_keyboard_event(true, '\x7f', '\x7f', 0, RETRO_DEVICE_KEYBOARD); - else if (string_is_equal(word, "\xe2\x8f\x8e")) /* return character */ - input_keyboard_event(true, '\n', '\n', 0, RETRO_DEVICE_KEYBOARD); - else - if (string_is_equal(word, "\xe2\x87\xa7")) /* up arrow */ - *osk_idx = OSK_UPPERCASE_LATIN; - else if (string_is_equal(word, "\xe2\x87\xa9")) /* down arrow */ - *osk_idx = OSK_LOWERCASE_LATIN; - else if (string_is_equal(word,"\xe2\x8a\x95")) /* plus sign (next button) */ -#else - if (string_is_equal(word, "Bksp")) - input_keyboard_event(true, '\x7f', '\x7f', 0, RETRO_DEVICE_KEYBOARD); - else if (string_is_equal(word, "Enter")) - input_keyboard_event(true, '\n', '\n', 0, RETRO_DEVICE_KEYBOARD); - else - if (string_is_equal(word, "Upper")) - *osk_idx = OSK_UPPERCASE_LATIN; - else if (string_is_equal(word, "Lower")) - *osk_idx = OSK_LOWERCASE_LATIN; - else if (string_is_equal(word, "Next")) -#endif - if (*osk_idx < (show_symbol_pages ? OSK_TYPE_LAST - 1 : OSK_SYMBOLS_PAGE1)) - *osk_idx = (enum osk_type)(*osk_idx + 1); - else - *osk_idx = ((enum osk_type)(OSK_TYPE_UNKNOWN + 1)); - else - { - input_keyboard_line_append(&p_rarch->keyboard_line, word); - osk_update_last_codepoint( - &p_rarch->osk_last_codepoint, - &p_rarch->osk_last_codepoint_len, - word); - } -} - /* * This function gets called in order to process all input events * for the current frame. @@ -19467,8 +19397,10 @@ static unsigned menu_event( { if (p_rarch->osk_ptr >= 0) input_event_osk_append( - p_rarch, + &p_rarch->keyboard_line, &p_rarch->osk_idx, + &p_rarch->osk_last_codepoint, + &p_rarch->osk_last_codepoint_len, p_rarch->osk_ptr, show_osk_symbols, p_rarch->osk_grid[p_rarch->osk_ptr]); @@ -19923,8 +19855,10 @@ static int menu_input_pointer_post_iterate( p_rarch->osk_ptr = point.retcode; input_event_osk_append( - p_rarch, + &p_rarch->keyboard_line, &p_rarch->osk_idx, + &p_rarch->osk_last_codepoint, + &p_rarch->osk_last_codepoint_len, point.retcode, show_osk_symbols, p_rarch->osk_grid[p_rarch->osk_ptr]);