Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 70 additions & 47 deletions input/input_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1635,27 +1635,29 @@ void input_keyboard_line_free(input_driver_state_t *input_st)
input_keyboard_line_t *kb_line = (input_keyboard_line_t*)&input_st->keyboard_line;
if (kb_line->buffer)
free(kb_line->buffer);
kb_line->buffer = NULL;
kb_line->ptr = 0;
kb_line->size = 0;
kb_line->capacity = 0;
kb_line->cb = NULL;
kb_line->userdata = NULL;
kb_line->enabled = false;
kb_line->buffer = NULL;
kb_line->ptr = 0;
kb_line->size = 0;
kb_line->capacity = 0;
kb_line->cb = NULL;
kb_line->userdata = NULL;
kb_line->enabled = false;
input_st->osk_textbox_focus = false;
}

const char **input_keyboard_start_line(
void *userdata,
struct input_keyboard_line *kb_line,
input_keyboard_line_complete_t cb)
{
kb_line->buffer = NULL;
kb_line->ptr = 0;
kb_line->size = 0;
kb_line->capacity = 0;
kb_line->cb = cb;
kb_line->userdata = userdata;
kb_line->enabled = true;
kb_line->buffer = NULL;
kb_line->ptr = 0;
kb_line->size = 0;
kb_line->capacity = 0;
kb_line->cb = cb;
kb_line->userdata = userdata;
kb_line->enabled = true;
input_driver_st.osk_textbox_focus = false;

return (const char**)&kb_line->buffer;
}
Expand Down Expand Up @@ -8244,13 +8246,15 @@ void input_driver_collect_system_input(input_driver_state_t *input_st,
else if (display_kb && input && input->input_state)
{
/* OSK grid navigation from keyboard / TV remote D-pad, plus
* page switches and Escape to clear/close. Return confirms the
* highlighted OSK character (same as menu OK). */
* page switches and Escape to clear/close. Return and LCTRL/RCTRL
* confirm the highlighted OSK character (same as menu OK) */
unsigned i;
bool swap_ok_cancel_buttons = settings->bools.input_menu_swap_ok_cancel_buttons;
unsigned ids[][2] =
{
{RETROK_RETURN, RETRO_DEVICE_ID_JOYPAD_A },
{RETROK_LCTRL, RETRO_DEVICE_ID_JOYPAD_A },
{RETROK_RCTRL, RETRO_DEVICE_ID_JOYPAD_A },
{RETROK_UP, RETRO_DEVICE_ID_JOYPAD_UP },
{RETROK_DOWN, RETRO_DEVICE_ID_JOYPAD_DOWN },
{RETROK_LEFT, RETRO_DEVICE_ID_JOYPAD_LEFT },
Expand All @@ -8265,6 +8269,16 @@ void input_driver_collect_system_input(input_driver_state_t *input_st,

for (i = 0; i < ARRAY_SIZE(ids); i++)
{
if ( swap_ok_cancel_buttons
&& (ids[i][0] == RETROK_LCTRL || ids[i][0] == RETROK_RCTRL))
ids[i][1] = RETRO_DEVICE_ID_JOYPAD_B;

if ( input_st->osk_textbox_focus
&& ids[i][1] != RETRO_DEVICE_ID_JOYPAD_L
&& ids[i][1] != RETRO_DEVICE_ID_JOYPAD_R
&& ids[i][1] != RETRO_DEVICE_ID_JOYPAD_SELECT)
continue;

if (ids[i][0] && input->input_state(
input_st->current_data,
joypad,
Expand Down Expand Up @@ -8500,42 +8514,51 @@ void input_keyboard_event(bool down, unsigned code,
if (!down)
return;

switch (code)
if (code == RETROK_TAB)
{
case RETROK_LEFT:
if (line->ptr && line->buffer)
{
line->ptr--;
while (line->ptr && IS_UTF8_CONTINUATION(line->buffer[line->ptr]))
line->ptr--;
input_st->osk_textbox_focus = !input_st->osk_textbox_focus;
return;
}

if (mod & RETROKMOD_CTRL)
while (line->ptr &&
(ISSPACE(line->buffer[line->ptr]) || !ISSPACE(line->buffer[line->ptr - 1])))
if (input_st->osk_textbox_focus)
{
switch (code)
{
case RETROK_LEFT:
if (line->ptr && line->buffer)
{
line->ptr--;
while (line->ptr && IS_UTF8_CONTINUATION(line->buffer[line->ptr]))
line->ptr--;
}
return;
case RETROK_RIGHT:
if (line->buffer && line->ptr < line->size)
{
line->ptr++;
while (line->ptr < line->size && IS_UTF8_CONTINUATION(line->buffer[line->ptr]))
line->ptr++;

if (mod & RETROKMOD_CTRL)
while (line->ptr < line->size &&
(ISSPACE(line->buffer[line->ptr]) || !ISSPACE(line->buffer[line->ptr - 1])))
if (mod & RETROKMOD_CTRL)
while (line->ptr &&
(ISSPACE(line->buffer[line->ptr]) || !ISSPACE(line->buffer[line->ptr - 1])))
line->ptr--;
}
return;
case RETROK_RIGHT:
if (line->buffer && line->ptr < line->size)
{
line->ptr++;
while (line->ptr < line->size && IS_UTF8_CONTINUATION(line->buffer[line->ptr]))
line->ptr++;
}
return;
case RETROK_UP:
line->ptr = 0;
return;
case RETROK_DOWN:
line->ptr = line->size;
return;
default:
break;

if (mod & RETROKMOD_CTRL)
while (line->ptr < line->size &&
(ISSPACE(line->buffer[line->ptr]) || !ISSPACE(line->buffer[line->ptr - 1])))
line->ptr++;
}
return;
case RETROK_UP:
line->ptr = 0;
return;
case RETROK_DOWN:
line->ptr = line->size;
return;
default:
break;
}
}

if (!input_keyboard_line_event(input_st, line, character))
Expand Down
1 change: 1 addition & 0 deletions input/input_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ typedef struct
#endif
#endif
int osk_ptr;
bool osk_textbox_focus;
turbo_buttons_t turbo_btns; /* int32_t alignment */
hold_buttons_t hold_btns; /* int32_t alignment */

Expand Down
70 changes: 67 additions & 3 deletions menu/drivers/materialui.c
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,10 @@ typedef struct materialui_handle
/* Scrollbar parameters */
materialui_scrollbar_t scrollbar; /* int alignment */
int cursor_size;
int osk_textbox_x;
int osk_textbox_y;
int osk_textbox_w;
int osk_textbox_h;
/* Cached system bar data */
materialui_sys_bar_cache_t sys_bar_cache; /* int alignment */
float last_scale_factor;
Expand Down Expand Up @@ -2831,6 +2835,7 @@ static void materialui_render_messagebox(
int y_centre,
const char *msg,
bool draw_caret,
bool draw_focus,
math_matrix_4x4 *mymat)
{
int i;
Expand Down Expand Up @@ -2976,6 +2981,14 @@ static void materialui_render_messagebox(
if (confirm_dialog)
slice_h += (mui->font_data.list.line_height + mui->margin) * 2;

if (draw_focus)
{
mui->osk_textbox_x = slice_x;
mui->osk_textbox_y = slice_y;
mui->osk_textbox_w = slice_w;
mui->osk_textbox_h = slice_h;
}

/* Draw message box background */
gfx_display_set_alpha(
mui->colors.surface_background, mui->transition_alpha);
Expand All @@ -2992,6 +3005,36 @@ static void materialui_render_messagebox(
video_height,
mui->colors.surface_background,
NULL);

if (draw_focus && input_state_get_ptr()->osk_textbox_focus)
{
int cursor_s = ((int)(mui->last_scale_factor * 4.0f) < 3)
? 3 : (int)(mui->last_scale_factor * 4.0f);
unsigned j;

for (j = 0; j < 4; j++)
{
int cursor_x = (j == 3) ? slice_x + slice_w - cursor_s : slice_x;
int cursor_y = (j == 1) ? slice_y + slice_h - cursor_s : slice_y;
int cursor_w = (j < 2) ? slice_w : cursor_s;
int cursor_h = (j < 2) ? cursor_s : slice_h;

gfx_display_draw_quad(
p_disp,
userdata,
video_width,
video_height,
cursor_x,
cursor_y,
cursor_w,
cursor_h,
video_width,
video_height,
mui->colors.list_icon,
NULL);
}
}

/* Print each line of the message */
for (i = 0; i < line_count; i++)
{
Expand Down Expand Up @@ -3171,6 +3214,26 @@ static void materialui_render_messagebox(
}
}

static bool materialui_osk_pointer_over_textbox(
void *data,
int x,
int y,
unsigned width,
unsigned height)
{
materialui_handle_t *mui = (materialui_handle_t*)data;

if ( mui
&& menu_input_dialog_get_display_kb()
&& x > mui->osk_textbox_x
&& x < mui->osk_textbox_x + mui->osk_textbox_w
&& y > mui->osk_textbox_y
&& y < mui->osk_textbox_y + mui->osk_textbox_h)
return true;

return false;
}

/* Initialises scrollbar parameters (width/height) */
static void materialui_scrollbar_init(
materialui_handle_t* mui,
Expand Down Expand Up @@ -8533,7 +8596,7 @@ static void materialui_frame(void *data, video_frame_info_t *video_info)
materialui_render_messagebox(mui,
p_disp,
userdata, video_width, video_height,
video_height / 4, msg, true,
video_height / 4, msg, true, true,
&mymat);

/* Draw onscreen keyboard */
Expand All @@ -8546,7 +8609,7 @@ static void materialui_frame(void *data, video_frame_info_t *video_info)
tex_list[MUI_TEXTURE_KEY_HOVER],
mui->font_data.list.font,
input_st->osk_grid,
input_st->osk_ptr,
input_st->osk_textbox_focus ? 44 : input_st->osk_ptr,
0xFFFFFFFF);
}

Expand Down Expand Up @@ -8576,7 +8639,7 @@ static void materialui_frame(void *data, video_frame_info_t *video_info)
materialui_render_messagebox(mui,
p_disp,
userdata, video_width, video_height,
video_height / 2, mui->msgbox, false,
video_height / 2, mui->msgbox, false, false,
&mymat);
mui->msgbox[0] = '\0';

Expand Down Expand Up @@ -12713,6 +12776,7 @@ menu_ctx_driver_t menu_ctx_mui = {
materialui_refresh_thumbnail_image,
NULL,
gfx_display_osk_ptr_at_pos,
materialui_osk_pointer_over_textbox,
materialui_update_savestate_thumbnail_path,
materialui_update_savestate_thumbnail_image,
materialui_pointer_down,
Expand Down
65 changes: 64 additions & 1 deletion menu/drivers/ozone.c
Original file line number Diff line number Diff line change
Expand Up @@ -7356,6 +7356,42 @@ OZONE_NOINLINE static void ozone_draw_osk(
text_color = ozone_theme_light.text_sublabel_rgba;
}

if (input_st->osk_textbox_focus)
{
float cursor_color[16];
int cursor_s = ozone->dimensions.spacer_5px;
int cursor_x = margin;
int cursor_y = margin;
int cursor_w = video_width - (margin * 2);
int cursor_h = bottom_end - (margin * 2);
unsigned j;

memcpy(cursor_color, ozone->theme_dynamic.cursor_border, sizeof(cursor_color));
gfx_display_set_alpha(cursor_color, 1.0f);

for (j = 0; j < 4; j++)
{
int rect_x = (j == 3) ? cursor_x + cursor_w - cursor_s : cursor_x;
int rect_y = (j == 1) ? cursor_y + cursor_h - cursor_s : cursor_y;
int rect_w = (j < 2) ? cursor_w : cursor_s;
int rect_h = (j < 2) ? cursor_s : cursor_h;

gfx_display_draw_quad(
p_disp,
userdata,
video_width,
video_height,
rect_x,
rect_y,
rect_w,
rect_h,
video_width,
video_height,
cursor_color,
NULL);
}
}

if (!draw_placeholder && input_st->keyboard_line.buffer)
{
char cursor_message[2048];
Expand Down Expand Up @@ -7471,11 +7507,37 @@ OZONE_NOINLINE static void ozone_draw_osk(
: ozone->textures[OZONE_TEXTURE_CURSOR_BORDER],
ozone->fonts.entries_label.font,
input_st->osk_grid,
input_st->osk_ptr,
input_st->osk_textbox_focus ? 44 : input_st->osk_ptr,
ozone->theme->text_rgba);
}
}

static bool ozone_osk_pointer_over_textbox(
void *data,
int x,
int y,
unsigned width,
unsigned height)
{
ozone_handle_t *ozone = (ozone_handle_t*)data;

if (ozone && menu_input_dialog_get_display_kb())
{
unsigned margin = 75 * ozone->last_scale_factor;
unsigned bottom_end = height / 2;

if ( width > (margin * 2)
&& bottom_end > (margin * 2)
&& (unsigned)x > margin
&& (unsigned)x < width - margin
&& (unsigned)y > margin
&& (unsigned)y < bottom_end - margin)
return true;
}

return false;
}

OZONE_NOINLINE static void ozone_draw_messagebox(
ozone_handle_t *ozone,
gfx_display_t *p_disp,
Expand Down Expand Up @@ -13835,6 +13897,7 @@ menu_ctx_driver_t menu_ctx_ozone = {
ozone_refresh_thumbnail_image,
ozone_set_thumbnail_content,
gfx_display_osk_ptr_at_pos,
ozone_osk_pointer_over_textbox,
ozone_update_savestate_thumbnail_path,
ozone_update_savestate_thumbnail_image,
NULL, /* pointer_down */
Expand Down
Loading
Loading