Feature #875 » 0022-sdl3-Update-to-SDL_KeyboardEvent-rearrangements.patch
client/gui-sdl3/gui_main.c | ||
---|---|---|
/**********************************************************************//**
|
||
Main handler for key presses
|
||
**************************************************************************/
|
||
static Uint16 main_key_down_handler(SDL_Keycode key, void *data)
|
||
static Uint16 main_key_down_handler(SDL_KeyboardEvent *key, void *data)
|
||
{
|
||
static struct widget *pwidget;
|
||
if ((pwidget = find_next_widget_for_key(NULL, key)) != NULL) {
|
||
return widget_pressed_action(pwidget);
|
||
} else {
|
||
if (key.sym == SDLK_TAB) {
|
||
/* input */
|
||
if (key->key == SDLK_TAB) {
|
||
/* Input */
|
||
popup_input_line();
|
||
} else {
|
||
if (map_event_handler(key)
|
||
&& C_S_RUNNING == client_state()) {
|
||
switch (key.sym) {
|
||
switch (key->key) {
|
||
case SDLK_RETURN:
|
||
case SDLK_KP_ENTER:
|
||
if (LSHIFT || RSHIFT) {
|
||
... | ... | |
/**********************************************************************//**
|
||
Main key release handler.
|
||
**************************************************************************/
|
||
static Uint16 main_key_up_handler(SDL_Keycode key, void *data)
|
||
static Uint16 main_key_up_handler(SDL_KeyboardEvent *key, void *data)
|
||
{
|
||
if (selected_widget) {
|
||
unselect_widget_action();
|
||
... | ... | |
**************************************************************************/
|
||
Uint16 gui_event_loop(void *data,
|
||
void (*loop_action)(void *data),
|
||
Uint16 (*key_down_handler)(SDL_Keycode key, void *data),
|
||
Uint16 (*key_up_handler)(SDL_Keycode key, void *data),
|
||
Uint16 (*key_down_handler)(SDL_KeyboardEvent *key, void *data),
|
||
Uint16 (*key_up_handler)(SDL_KeyboardEvent *key, void *data),
|
||
Uint16 (*textinput_handler)(char *text, void *data),
|
||
Uint16 (*finger_down_handler)(SDL_TouchFingerEvent *touch_event, void *data),
|
||
Uint16 (*finger_up_handler)(SDL_TouchFingerEvent *touch_event, void *data),
|
||
... | ... | |
break;
|
||
case SDL_EVENT_KEY_UP:
|
||
switch (main_data.event.key.keysym.sym) {
|
||
/* find if Shifts are released */
|
||
switch (main_data.event.key.key) {
|
||
/* Find if Shifts are released */
|
||
case SDLK_RSHIFT:
|
||
RSHIFT = FALSE;
|
||
break;
|
||
... | ... | |
break;
|
||
default:
|
||
if (key_up_handler) {
|
||
ID = key_up_handler(main_data.event.key.keysym, data);
|
||
ID = key_up_handler(&(main_data.event.key), data);
|
||
}
|
||
break;
|
||
}
|
||
break;
|
||
case SDL_EVENT_KEY_DOWN:
|
||
switch (main_data.event.key.keysym.sym) {
|
||
switch (main_data.event.key.key) {
|
||
#if 0
|
||
case SDLK_PRINT:
|
||
fc_snprintf(schot, sizeof(schot), "fc_%05d.bmp", schot_nr++);
|
||
... | ... | |
default:
|
||
if (key_down_handler) {
|
||
ID = key_down_handler(main_data.event.key.keysym, data);
|
||
ID = key_down_handler(&(main_data.event.key), data);
|
||
}
|
||
break;
|
||
}
|
client/gui-sdl3/gui_main.h | ||
---|---|---|
bool FilterMouseMotionEvents(void *data, SDL_Event *event);
|
||
Uint16 gui_event_loop(void *data, void (*loop_action)(void *data),
|
||
Uint16 (*key_down_handler)(SDL_Keycode key, void *data),
|
||
Uint16 (*key_up_handler)(SDL_Keycode key, void *data),
|
||
Uint16 (*key_down_handler)(SDL_KeyboardEvent *key, void *data),
|
||
Uint16 (*key_up_handler)(SDL_KeyboardEvent *key, void *data),
|
||
Uint16 (*textinput_handler)(char *text, void *data),
|
||
Uint16 (*finger_down_handler)(SDL_TouchFingerEvent *touch_event, void *data),
|
||
Uint16 (*finger_up_handler)(SDL_TouchFingerEvent *touch_event, void *data),
|
client/gui-sdl3/mapctrl.c | ||
---|---|---|
/**********************************************************************//**
|
||
Toggle map drawing stuff.
|
||
**************************************************************************/
|
||
bool map_event_handler(SDL_Keycode key)
|
||
bool map_event_handler(SDL_KeyboardEvent *key)
|
||
{
|
||
if (C_S_RUNNING == client_state()) {
|
||
enum direction8 movedir = DIR8_MAGIC_MAX;
|
||
switch (key.scancode) {
|
||
switch (key->scancode) {
|
||
case SDL_SCANCODE_KP_8:
|
||
movedir = DIR8_NORTH;
|
||
... | ... | |
return FALSE;
|
||
default:
|
||
switch (key.sym) {
|
||
switch (key->key) {
|
||
/* cancel action */
|
||
/* Cancel action */
|
||
case SDLK_ESCAPE:
|
||
key_cancel_action();
|
||
draw_goto_patrol_lines = FALSE;
|
client/gui-sdl3/mapctrl.h | ||
---|---|---|
void enable_and_redraw_revolution_button(void);
|
||
void enable_main_widgets(void);
|
||
void disable_main_widgets(void);
|
||
bool map_event_handler(SDL_Keycode key);
|
||
bool map_event_handler(SDL_KeyboardEvent *key);
|
||
void finger_down_on_map(struct finger_behavior *finger_behavior);
|
||
void finger_up_on_map(struct finger_behavior *finger_behavior);
|
client/gui-sdl3/widget.c | ||
---|---|---|
NOTE: This function ignores CapsLock and NumLock Keys.
|
||
**************************************************************************/
|
||
struct widget *find_next_widget_for_key(struct widget *start_widget,
|
||
SDL_Keycode key)
|
||
SDL_KeyboardEvent *key)
|
||
{
|
||
struct widget *pwidget;
|
||
pwidget = start_widget ? start_widget : begin_main_widget_list;
|
||
key.mod &= ~(SDL_KMOD_NUM | SDL_KMOD_CAPS);
|
||
key->mod &= ~(SDL_KMOD_NUM | SDL_KMOD_CAPS);
|
||
while (pwidget) {
|
||
if ((pwidget->key == key.sym
|
||
|| (pwidget->key == SDLK_RETURN && key.sym == SDLK_KP_ENTER)
|
||
|| (pwidget->key == SDLK_KP_ENTER && key.sym == SDLK_RETURN))
|
||
&& ((pwidget->mod & key.mod) || (pwidget->mod == key.mod))) {
|
||
if ((pwidget->key == key->key
|
||
|| (pwidget->key == SDLK_RETURN && key->key == SDLK_KP_ENTER)
|
||
|| (pwidget->key == SDLK_KP_ENTER && key->key == SDLK_RETURN))
|
||
&& ((pwidget->mod & key->mod) || (pwidget->mod == key->mod))) {
|
||
if (!((get_wstate(pwidget) == FC_WS_DISABLED)
|
||
|| ((get_wflags(pwidget) & WF_HIDDEN) == WF_HIDDEN))) {
|
||
return (struct widget *) pwidget;
|
client/gui-sdl3/widget.h | ||
---|---|---|
void del_main_list(void);
|
||
struct widget *find_next_widget_at_pos(struct widget *start_widget, int x, int y);
|
||
struct widget *find_next_widget_for_key(struct widget *start_widget, SDL_Keycode key);
|
||
struct widget *find_next_widget_for_key(struct widget *start_widget, SDL_KeyboardEvent *key);
|
||
struct widget *get_widget_pointer_from_id(const struct widget *gui_list,
|
||
Uint16 id,
|
client/gui-sdl3/widget_edit.c | ||
---|---|---|
NOTE: This functions can return NULL in 'edit_widget->string_utf8->text' but
|
||
never free 'edit_widget->string_utf8' struct.
|
||
**************************************************************************/
|
||
static Uint16 edit_key_down(SDL_Keycode key, void *data)
|
||
static Uint16 edit_key_down(SDL_KeyboardEvent *key, void *data)
|
||
{
|
||
struct text_edit *edt = (struct text_edit *)data;
|
||
struct utf8_char *input_chain_tmp;
|
||
bool redraw = FALSE;
|
||
/* find which key is pressed */
|
||
switch (key.sym) {
|
||
/* Find which key is pressed */
|
||
switch (key->key) {
|
||
case SDLK_ESCAPE:
|
||
/* exit from loop without changes */
|
||
/* Exit from loop without changes */
|
||
return ED_ESC;
|
||
case SDLK_RETURN:
|
||
case SDLK_KP_ENTER:
|
||
/* exit from loop */
|
||
/* Exit from loop */
|
||
return ED_RETURN;
|
||
/*
|
||
case SDLK_KP6:
|
||
if (key.mod & KMOD_NUM) {
|
||
if (key->mod & KMOD_NUM) {
|
||
goto INPUT;
|
||
}
|
||
*/
|
||
case SDLK_RIGHT:
|
||
{
|
||
/* move cursor right */
|
||
/* Move cursor right */
|
||
if (edt->input_chain->next) {
|
||
if (edt->input_chain_x >= (edt->pwidget->size.x + edt->bg->w - adj_size(10))) {
|
||
edt->start_x -= edt->input_chain->tsurf->w -
|
||
... | ... | |
break;
|
||
/*
|
||
case SDLK_KP4:
|
||
if (key.mod & KMOD_NUM) {
|
||
if (key->mod & KMOD_NUM) {
|
||
goto INPUT;
|
||
}
|
||
*/
|
||
case SDLK_LEFT:
|
||
{
|
||
/* move cursor left */
|
||
/* Move cursor left */
|
||
if (edt->input_chain->prev) {
|
||
edt->input_chain = edt->input_chain->prev;
|
||
if ((edt->input_chain_x <=
|
||
... | ... | |
break;
|
||
/*
|
||
case SDLK_KP7:
|
||
if (key.mod & KMOD_NUM) {
|
||
if (key->mod & KMOD_NUM) {
|
||
goto INPUT;
|
||
}
|
||
*/
|
||
case SDLK_HOME:
|
||
{
|
||
/* move cursor to begin of chain (and edit field) */
|
||
/* Move cursor to begin of chain (and edit field) */
|
||
edt->input_chain = edt->begin_text_chain;
|
||
redraw = TRUE;
|
||
edt->start_x = adj_size(5);
|
||
... | ... | |
break;
|
||
/*
|
||
case SDLK_KP1:
|
||
if (key.mod & KMOD_NUM) {
|
||
if (key->mod & KMOD_NUM) {
|
||
goto INPUT;
|
||
}
|
||
*/
|
||
... | ... | |
break;
|
||
case SDLK_BACKSPACE:
|
||
{
|
||
/* del element of chain (and move cursor left) */
|
||
/* Delete element of chain (and move cursor left) */
|
||
if (edt->input_chain->prev) {
|
||
if ((edt->input_chain_x <=
|
||
(edt->pwidget->size.x + adj_size(9))) && (edt->start_x != adj_size(5))) {
|
||
... | ... | |
break;
|
||
/*
|
||
case SDLK_KP_PERIOD:
|
||
if (key.mod & KMOD_NUM) {
|
||
if (key->mod & KMOD_NUM) {
|
||
goto INPUT;
|
||
}
|
||
*/
|
- « Previous
- 1
- 2
- Next »