Project

General

Profile

Feature #1529 » 0033-sdl-Add-widget_id-type.patch

S3_2 - Marko Lindqvist, 06/20/2025 10:16 AM

View differences:

client/gui-sdl2/cma_fe.c
/**********************************************************************//**
User released mouse button while in scrollbar.
**************************************************************************/
static Uint16 scroll_mouse_button_up(SDL_MouseButtonEvent *button_event,
void *data)
static widget_id scroll_mouse_button_up(SDL_MouseButtonEvent *button_event,
void *data)
{
return (Uint16)ID_SCROLLBAR;
return (widget_id)ID_SCROLLBAR;
}
/**********************************************************************//**
User moved mouse while holding scrollbar.
**************************************************************************/
static Uint16 scroll_mouse_motion_handler(SDL_MouseMotionEvent *motion_event,
void *data)
static widget_id scroll_mouse_motion_handler(SDL_MouseMotionEvent *motion_event,
void *data)
{
struct hmove *motion = (struct hmove *)data;
char cbuf[4];
......
*(int *)motion->pscroll_bar->data.ptr);
copy_chars_to_utf8_str(motion->pscroll_bar->next->string_utf8, cbuf);
/* redraw label */
/* Redraw label */
widget_redraw(motion->pscroll_bar->next);
widget_mark_dirty(motion->pscroll_bar->next);
/* redraw scrollbar */
/* Redraw scrollbar */
if (get_wflags(motion->pscroll_bar) & WF_RESTORE_BACKGROUND) {
refresh_widget_background(motion->pscroll_bar);
}
client/gui-sdl2/gui_main.c
/**********************************************************************//**
Main handler for key presses
**************************************************************************/
static Uint16 main_key_down_handler(SDL_Keysym key, void *data)
static widget_id main_key_down_handler(SDL_Keysym key, void *data)
{
static struct widget *pwidget;
......
return widget_pressed_action(pwidget);
} else {
if (key.sym == SDLK_TAB) {
/* input */
/* Input */
popup_input_line();
} else {
if (map_event_handler(key)
......
/**********************************************************************//**
Main key release handler.
**************************************************************************/
static Uint16 main_key_up_handler(SDL_Keysym key, void *data)
static widget_id main_key_up_handler(SDL_Keysym key, void *data)
{
if (selected_widget) {
unselect_widget_action();
......
/**********************************************************************//**
Main finger down handler.
**************************************************************************/
static Uint16 main_finger_down_handler(SDL_TouchFingerEvent *touch_event,
void *data)
static widget_id main_finger_down_handler(SDL_TouchFingerEvent *touch_event,
void *data)
{
struct widget *pwidget;
/* Touch event coordinates are normalized (0...1). */
......
finger_behavior.ptile = canvas_pos_to_tile(x, y, mouse_zoom);
}
}
return ID_ERROR;
}
/**********************************************************************//**
Main finger release handler.
**************************************************************************/
static Uint16 main_finger_up_handler(SDL_TouchFingerEvent *touch_event,
void *data)
static widget_id main_finger_up_handler(SDL_TouchFingerEvent *touch_event,
void *data)
{
/* Touch event coordinates are normalized (0...1). */
int x = touch_event->x * main_window_width();
int y = touch_event->y * main_window_height();
/* Screen wasn't pressed over a widget. */
if (finger_behavior.finger_down_ticks
&& !find_next_widget_at_pos(NULL, x, y)) {
......
/**********************************************************************//**
Main mouse click handler.
**************************************************************************/
static Uint16 main_mouse_button_down_handler(SDL_MouseButtonEvent *button_event,
void *data)
static widget_id main_mouse_button_down_handler(SDL_MouseButtonEvent *button_event,
void *data)
{
struct widget *pwidget;
......
return widget_pressed_action(pwidget);
}
} else {
/* no visible widget at this position -> map click */
/* No visible widget at this position -> map click */
#ifdef UNDER_CE
if (!check_scroll_area(button_event->x, button_event->y)) {
#endif
if (!button_behavior.counting) {
/* start counting */
/* Start counting */
button_behavior.counting = TRUE;
button_behavior.button_down_ticks = SDL_GetTicks();
*button_behavior.event = *button_event;
......
/**********************************************************************//**
Main mouse button release handler.
**************************************************************************/
static Uint16 main_mouse_button_up_handler(SDL_MouseButtonEvent *button_event,
void *data)
static widget_id main_mouse_button_up_handler(SDL_MouseButtonEvent *button_event,
void *data)
{
if (button_behavior.button_down_ticks /* button wasn't pressed over a widget */
if (button_behavior.button_down_ticks /* Button wasn't pressed over a widget */
&& !find_next_widget_at_pos(NULL, button_event->x, button_event->y)) {
*button_behavior.event = *button_event;
button_up_on_map(&button_behavior);
......
/**********************************************************************//**
Main handler for mouse movement handling.
**************************************************************************/
static Uint16 main_mouse_motion_handler(SDL_MouseMotionEvent *motion_event,
void *data)
static widget_id main_mouse_motion_handler(SDL_MouseMotionEvent *motion_event,
void *data)
{
static struct widget *pwidget;
struct tile *ptile;
/* stop evaluating button hold time when moving to another tile in medium
/* Stop evaluating button hold time when moving to another tile in medium
* hold state or above */
if (button_behavior.counting && (button_behavior.hold_state >= MB_HOLD_MEDIUM)) {
ptile = canvas_pos_to_tile(motion_event->x, motion_event->y,
......
/**********************************************************************//**
SDL2-client main loop.
**************************************************************************/
Uint16 gui_event_loop(void *data,
void (*loop_action)(void *data),
Uint16 (*key_down_handler)(SDL_Keysym key, void *data),
Uint16 (*key_up_handler)(SDL_Keysym key, void *data),
Uint16 (*textinput_handler)(const char *text, void *data),
Uint16 (*finger_down_handler)(SDL_TouchFingerEvent *touch_event, void *data),
Uint16 (*finger_up_handler)(SDL_TouchFingerEvent *touch_event, void *data),
Uint16 (*finger_motion_handler)(SDL_TouchFingerEvent *touch_event,
void *data),
Uint16 (*mouse_button_down_handler)(SDL_MouseButtonEvent *button_event,
widget_id gui_event_loop(void *data,
void (*loop_action)(void *data),
widget_id (*key_down_handler)(SDL_Keysym key, void *data),
widget_id (*key_up_handler)(SDL_Keysym key, void *data),
widget_id (*textinput_handler)(const char *text, void *data),
widget_id (*finger_down_handler)(SDL_TouchFingerEvent *touch_event,
void *data),
Uint16 (*mouse_button_up_handler)(SDL_MouseButtonEvent *button_event,
widget_id (*finger_up_handler)(SDL_TouchFingerEvent *touch_event,
void *data),
Uint16 (*mouse_motion_handler)(SDL_MouseMotionEvent *motion_event,
void *data))
widget_id (*finger_motion_handler)(SDL_TouchFingerEvent *touch_event,
void *data),
widget_id (*mouse_button_down_handler)(SDL_MouseButtonEvent *button_event,
void *data),
widget_id (*mouse_button_up_handler)(SDL_MouseButtonEvent *button_event,
void *data),
widget_id (*mouse_motion_handler)(SDL_MouseMotionEvent *motion_event,
void *data))
{
Uint16 ID;
static fc_timeval tv;
client/gui-sdl2/gui_main.h
|| ((event).type == SDL_MOUSEBUTTONDOWN \
&& (event).button.button == SDL_BUTTON_LEFT))
typedef Uint16 widget_id;
enum mouse_button_hold_state {
MB_HOLD_SHORT,
MB_HOLD_MEDIUM,
......
extern int MOVE_STEP_X, MOVE_STEP_Y;
int FilterMouseMotionEvents(void *data, SDL_Event *event);
Uint16 gui_event_loop(void *data, void (*loop_action)(void *data),
Uint16 (*key_down_handler)(SDL_Keysym key, void *data),
Uint16 (*key_up_handler)(SDL_Keysym key, void *data),
Uint16 (*textinput_handler)(const char *text, void *data),
Uint16 (*finger_down_handler)(SDL_TouchFingerEvent *touch_event, void *data),
Uint16 (*finger_up_handler)(SDL_TouchFingerEvent *touch_event, void *data),
Uint16 (*finger_motion_handler)(SDL_TouchFingerEvent *touch_event,
void *data),
Uint16 (*mouse_button_down_handler)(SDL_MouseButtonEvent *button_event,
widget_id gui_event_loop(void *data, void (*loop_action)(void *data),
widget_id (*key_down_handler)(SDL_Keysym key, void *data),
widget_id (*key_up_handler)(SDL_Keysym key, void *data),
widget_id (*textinput_handler)(const char *text, void *data),
widget_id (*finger_down_handler)(SDL_TouchFingerEvent *touch_event,
void *data),
Uint16 (*mouse_button_up_handler)(SDL_MouseButtonEvent *button_event,
widget_id (*finger_up_handler)(SDL_TouchFingerEvent *touch_event,
void *data),
Uint16 (*mouse_motion_handler)(SDL_MouseMotionEvent *motion_event,
void *data));
widget_id (*finger_motion_handler)(SDL_TouchFingerEvent *touch_event,
void *data),
widget_id (*mouse_button_down_handler)(SDL_MouseButtonEvent *button_event,
void *data),
widget_id (*mouse_button_up_handler)(SDL_MouseButtonEvent *button_event,
void *data),
widget_id (*mouse_motion_handler)(SDL_MouseMotionEvent *motion_event,
void *data));
unsigned default_font_size(struct theme *act_theme);
void update_font_from_theme(int theme_font_size);
client/gui-sdl2/repodlgs.c
/**********************************************************************//**
User released mouse button while adjusting rates.
**************************************************************************/
static Uint16 report_scroll_mouse_button_up(SDL_MouseButtonEvent *button_event,
void *data)
static widget_id report_scroll_mouse_button_up(SDL_MouseButtonEvent *button_event,
void *data)
{
return (Uint16)ID_SCROLLBAR;
return (widget_id)ID_SCROLLBAR;
}
/**********************************************************************//**
User moved a mouse while adjusting rates.
**************************************************************************/
static Uint16 report_scroll_mouse_motion_handler(SDL_MouseMotionEvent *motion_event,
void *data)
static widget_id report_scroll_mouse_motion_handler(SDL_MouseMotionEvent *motion_event,
void *data)
{
struct rates_move *motion = (struct rates_move *)data;
struct widget *tax_label = economy_dlg->end_widget_list->prev->prev;
......
&& (motion_event->x >= motion->min)
&& (motion_event->x <= motion->max)) {
/* set up directions */
/* Set up directions */
if (motion_event->xrel > 0) {
dir = 15;
inc = 10;
......
inc = -10;
}
/* make checks */
/* Make checks */
x = motion->horiz_src->size.x;
if (((x + dir) <= motion->max) && ((x + dir) >= motion->min)) {
/* src in range */
......
}
}
/* undraw scrollbars */
/* Undraw scrollbars */
widget_undraw(motion->horiz_src);
widget_mark_dirty(motion->horiz_src);
......
fc_snprintf(cbuf, sizeof(cbuf), "%d%%", *motion->dst_rate);
copy_chars_to_utf8_str(motion->label_dst->string_utf8, cbuf);
/* redraw label */
/* Redraw label */
widget_redraw(motion->label_src);
widget_mark_dirty(motion->label_src);
widget_redraw(motion->label_dst);
widget_mark_dirty(motion->label_dst);
/* redraw scrollbar */
/* Redraw scrollbar */
if (get_wflags(motion->horiz_src) & WF_RESTORE_BACKGROUND) {
refresh_widget_background(motion->horiz_src);
}
client/gui-sdl2/widget.c
/**********************************************************************//**
Add Widget to Main widgets list ( begin_widget_list )
**************************************************************************/
void add_to_gui_list(Uint16 id, struct widget *gui)
void add_to_gui_list(widget_id id, struct widget *gui)
{
if (begin_main_widget_list != NULL) {
gui->next = begin_main_widget_list;
client/gui-sdl2/widget.h
SDL_Keycode key; /* key aliased with this widget */
Uint16 mod; /* SHIFT, CTRL, ALT, etc */
Uint16 id; /* id in widget list */
widget_id id; /* id in widget list */
int (*action) (struct widget *); /* default callback action */
......
SCAN_BACKWARD
};
void add_to_gui_list(Uint16 id, struct widget *gui);
void add_to_gui_list(widget_id id, struct widget *gui);
void del_widget_pointer_from_gui_list(struct widget *gui);
void widget_add_as_prev(struct widget *new_widget, struct widget *add_dock);
client/gui-sdl2/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_Keysym key, void *data)
static widget_id edit_key_down(SDL_Keysym 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 */
/* Find which key is pressed */
switch (key.sym) {
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:
......
break;
default:
break;
} /* key pressed switch */
} /* Key pressed switch */
if (redraw) {
redraw_edit_chain(edt);
......
/**********************************************************************//**
Handle textinput strings coming to the edit widget
**************************************************************************/
static Uint16 edit_textinput(const char *text, void *data)
static widget_id edit_textinput(const char *text, void *data)
{
struct text_edit *edt = (struct text_edit *)data;
struct utf8_char *input_chain_tmp;
......
/**********************************************************************//**
Handle mouse down events on edit widget.
**************************************************************************/
static Uint16 edit_mouse_button_down(SDL_MouseButtonEvent *button_event,
void *data)
static widget_id edit_mouse_button_down(SDL_MouseButtonEvent *button_event,
void *data)
{
struct text_edit *edt = (struct text_edit *)data;
......
&& button_event->x < edt->pwidget->size.x + edt->bg->w
&& button_event->y >= edt->pwidget->size.y
&& button_event->y < edt->pwidget->size.y + edt->bg->h)) {
/* exit from loop */
return (Uint16)ED_MOUSE;
/* Exit from loop */
return (widget_id)ED_MOUSE;
}
}
return (Uint16)ID_ERROR;
return (widget_id)ID_ERROR;
}
/**********************************************************************//**
......
edt.end_text_chain->next = NULL;
edt.end_text_chain->prev = NULL;
/* set font style (if any ) */
/* Set font style (if any ) */
if (!((edit_widget->string_utf8->style & 0x0F) & TTF_STYLE_NORMAL)) {
TTF_SetFontStyle(edit_widget->string_utf8->font,
(edit_widget->string_utf8->style & 0x0F));
......
edt.end_text_chain->chr,
edit_widget->string_utf8->fgcol);
/* create surface for each font in chain and find chain length */
/* Create surface for each font in chain and find chain length */
if (edt.begin_text_chain) {
input_chain_tmp = edt.begin_text_chain;
......
set_wstate(edit_widget, FC_WS_PRESSED);
{
/* local loop */
Uint16 rety = gui_event_loop((void *)&edt, NULL,
edit_key_down, NULL, edit_textinput, NULL, NULL, NULL,
edit_mouse_button_down, NULL, NULL);
/* Local loop */
widget_id rety = gui_event_loop((void *)&edt, NULL,
edit_key_down, NULL, edit_textinput, NULL, NULL, NULL,
edit_mouse_button_down, NULL, NULL);
if (edt.begin_text_chain == edt.end_text_chain) {
edt.begin_text_chain = NULL;
client/gui-sdl2/widget_scrollbar.c
/**********************************************************************//**
Handle mouse motion events of the vertical scrollbar event loop.
**************************************************************************/
static Uint16 scroll_mouse_motion_handler(SDL_MouseMotionEvent *motion_event,
void *data)
static widget_id scroll_mouse_motion_handler(SDL_MouseMotionEvent *motion_event,
void *data)
{
struct UP_DOWN *motion = (struct UP_DOWN *)data;
int yrel;
......
/**********************************************************************//**
Callback for scrollbar event loops' mouse up events.
**************************************************************************/
static Uint16 scroll_mouse_button_up(SDL_MouseButtonEvent *button_event,
void *data)
static widget_id scroll_mouse_button_up(SDL_MouseButtonEvent *button_event,
void *data)
{
return (Uint16)ID_SCROLLBAR;
return (widget_id)ID_SCROLLBAR;
}
/**********************************************************************//**
client/gui-sdl2/widget_window.c
/**********************************************************************//**
Move window as event instructs.
**************************************************************************/
static Uint16 move_window_motion(SDL_MouseMotionEvent *motion_event,
void *data)
static widget_id move_window_motion(SDL_MouseMotionEvent *motion_event,
void *data)
{
struct move *pmove = (struct move *)data;
int xrel, yrel;
......
/**********************************************************************//**
Button up event handler for the window moving event loop.
**************************************************************************/
static Uint16 move_window_button_up(SDL_MouseButtonEvent *button_event,
void *data)
static widget_id move_window_button_up(SDL_MouseButtonEvent *button_event,
void *data)
{
struct move *pmove = (struct move *)data;
if (pmove && pmove->moved) {
return (Uint16)ID_MOVED_WINDOW;
return (widget_id)ID_MOVED_WINDOW;
}
return (Uint16)ID_WINDOW;
return (widget_id)ID_WINDOW;
}
/**********************************************************************//**
client/gui-sdl3/cma_fe.c
/**********************************************************************//**
User released mouse button while in scrollbar.
**************************************************************************/
static Uint16 scroll_mouse_button_up(SDL_MouseButtonEvent *button_event,
void *data)
static widget_id scroll_mouse_button_up(SDL_MouseButtonEvent *button_event,
void *data)
{
return (Uint16)ID_SCROLLBAR;
return (widget_id)ID_SCROLLBAR;
}
/**********************************************************************//**
User moved mouse while holding scrollbar.
**************************************************************************/
static Uint16 scroll_mouse_motion_handler(SDL_MouseMotionEvent *motion_event,
void *data)
static widget_id scroll_mouse_motion_handler(SDL_MouseMotionEvent *motion_event,
void *data)
{
struct hmove *motion = (struct hmove *)data;
char cbuf[4];
......
*(int *)motion->pscroll_bar->data.ptr);
copy_chars_to_utf8_str(motion->pscroll_bar->next->string_utf8, cbuf);
/* redraw label */
/* Redraw label */
widget_redraw(motion->pscroll_bar->next);
widget_mark_dirty(motion->pscroll_bar->next);
/* redraw scrollbar */
/* Redraw scrollbar */
if (get_wflags(motion->pscroll_bar) & WF_RESTORE_BACKGROUND) {
refresh_widget_background(motion->pscroll_bar);
}
client/gui-sdl3/gui_main.c
/**********************************************************************//**
Main handler for key presses
**************************************************************************/
static Uint16 main_key_down_handler(SDL_KeyboardEvent *key, void *data)
static widget_id main_key_down_handler(SDL_KeyboardEvent *key, void *data)
{
static struct widget *pwidget;
......
/**********************************************************************//**
Main key release handler.
**************************************************************************/
static Uint16 main_key_up_handler(SDL_KeyboardEvent *key, void *data)
static widget_id main_key_up_handler(SDL_KeyboardEvent *key, void *data)
{
if (selected_widget) {
unselect_widget_action();
......
/**********************************************************************//**
Main finger down handler.
**************************************************************************/
static Uint16 main_finger_down_handler(SDL_TouchFingerEvent *touch_event,
void *data)
static widget_id main_finger_down_handler(SDL_TouchFingerEvent *touch_event,
void *data)
{
struct widget *pwidget;
/* Touch event coordinates are normalized (0...1). */
......
/**********************************************************************//**
Main finger release handler.
**************************************************************************/
static Uint16 main_finger_up_handler(SDL_TouchFingerEvent *touch_event,
void *data)
static widget_id main_finger_up_handler(SDL_TouchFingerEvent *touch_event,
void *data)
{
/* Touch event coordinates are normalized (0...1). */
int x = touch_event->x * main_window_width();
int y = touch_event->y * main_window_height();
/* Screen wasn't pressed over a widget. */
if (finger_behavior.finger_down_ticks
&& !find_next_widget_at_pos(NULL, x, y)) {
......
/**********************************************************************//**
Main mouse click handler.
**************************************************************************/
static Uint16 main_mouse_button_down_handler(SDL_MouseButtonEvent *button_event,
void *data)
static widget_id main_mouse_button_down_handler(SDL_MouseButtonEvent *button_event,
void *data)
{
struct widget *pwidget;
......
return widget_pressed_action(pwidget);
}
} else {
/* no visible widget at this position -> map click */
/* No visible widget at this position -> map click */
#ifdef UNDER_CE
if (!check_scroll_area(button_event->x, button_event->y)) {
#endif
if (!button_behavior.counting) {
/* start counting */
/* Start counting */
button_behavior.counting = TRUE;
button_behavior.button_down_ticks = SDL_GetTicks();
*button_behavior.event = *button_event;
......
/**********************************************************************//**
Main mouse button release handler.
**************************************************************************/
static Uint16 main_mouse_button_up_handler(SDL_MouseButtonEvent *button_event,
void *data)
static widget_id main_mouse_button_up_handler(SDL_MouseButtonEvent *button_event,
void *data)
{
if (button_behavior.button_down_ticks /* button wasn't pressed over a widget */
if (button_behavior.button_down_ticks /* Button wasn't pressed over a widget */
&& !find_next_widget_at_pos(NULL, button_event->x, button_event->y)) {
*button_behavior.event = *button_event;
button_up_on_map(&button_behavior);
......
/**********************************************************************//**
Main handler for mouse movement handling.
**************************************************************************/
static Uint16 main_mouse_motion_handler(SDL_MouseMotionEvent *motion_event,
void *data)
static widget_id main_mouse_motion_handler(SDL_MouseMotionEvent *motion_event,
void *data)
{
static struct widget *pwidget;
struct tile *ptile;
/* stop evaluating button hold time when moving to another tile in medium
/* Stop evaluating button hold time when moving to another tile in medium
* hold state or above */
if (button_behavior.counting && (button_behavior.hold_state >= MB_HOLD_MEDIUM)) {
ptile = canvas_pos_to_tile(motion_event->x, motion_event->y,
......
/**********************************************************************//**
SDL3-client main loop.
**************************************************************************/
Uint16 gui_event_loop(void *data,
void (*loop_action)(void *data),
Uint16 (*key_down_handler)(SDL_KeyboardEvent *key, void *data),
Uint16 (*key_up_handler)(SDL_KeyboardEvent *key, void *data),
Uint16 (*textinput_handler)(const char *text, void *data),
Uint16 (*finger_down_handler)(SDL_TouchFingerEvent *touch_event, void *data),
Uint16 (*finger_up_handler)(SDL_TouchFingerEvent *touch_event, void *data),
Uint16 (*finger_motion_handler)(SDL_TouchFingerEvent *touch_event,
void *data),
Uint16 (*mouse_button_down_handler)(SDL_MouseButtonEvent *button_event,
widget_id gui_event_loop(void *data,
void (*loop_action)(void *data),
widget_id (*key_down_handler)(SDL_KeyboardEvent *key, void *data),
widget_id (*key_up_handler)(SDL_KeyboardEvent *key, void *data),
widget_id (*textinput_handler)(const char *text, void *data),
widget_id (*finger_down_handler)(SDL_TouchFingerEvent *touch_event,
void *data),
Uint16 (*mouse_button_up_handler)(SDL_MouseButtonEvent *button_event,
widget_id (*finger_up_handler)(SDL_TouchFingerEvent *touch_event,
void *data),
Uint16 (*mouse_motion_handler)(SDL_MouseMotionEvent *motion_event,
void *data))
widget_id (*finger_motion_handler)(SDL_TouchFingerEvent *touch_event,
void *data),
widget_id (*mouse_button_down_handler)(SDL_MouseButtonEvent *button_event,
void *data),
widget_id (*mouse_button_up_handler)(SDL_MouseButtonEvent *button_event,
void *data),
widget_id (*mouse_motion_handler)(SDL_MouseMotionEvent *motion_event,
void *data))
{
Uint16 ID;
static fc_timeval tv;
client/gui-sdl3/gui_main.h
|| ((event).type == SDL_EVENT_MOUSE_BUTTON_DOWN \
&& (event).button.button == SDL_BUTTON_LEFT))
typedef Uint16 widget_id;
enum mouse_button_hold_state {
MB_HOLD_SHORT,
MB_HOLD_MEDIUM,
......
extern int MOVE_STEP_X, MOVE_STEP_Y;
bool FilterMouseMotionEvents(void *data, SDL_Event *event);
Uint16 gui_event_loop(void *data, void (*loop_action)(void *data),
Uint16 (*key_down_handler)(SDL_KeyboardEvent *key, void *data),
Uint16 (*key_up_handler)(SDL_KeyboardEvent *key, void *data),
Uint16 (*textinput_handler)(const char *text, void *data),
Uint16 (*finger_down_handler)(SDL_TouchFingerEvent *touch_event, void *data),
Uint16 (*finger_up_handler)(SDL_TouchFingerEvent *touch_event, void *data),
Uint16 (*finger_motion_handler)(SDL_TouchFingerEvent *touch_event,
void *data),
Uint16 (*mouse_button_down_handler)(SDL_MouseButtonEvent *button_event,
widget_id gui_event_loop(void *data, void (*loop_action)(void *data),
widget_id (*key_down_handler)(SDL_KeyboardEvent *key, void *data),
widget_id (*key_up_handler)(SDL_KeyboardEvent *key, void *data),
widget_id (*textinput_handler)(const char *text, void *data),
widget_id (*finger_down_handler)(SDL_TouchFingerEvent *touch_event,
void *data),
Uint16 (*mouse_button_up_handler)(SDL_MouseButtonEvent *button_event,
widget_id (*finger_up_handler)(SDL_TouchFingerEvent *touch_event,
void *data),
Uint16 (*mouse_motion_handler)(SDL_MouseMotionEvent *motion_event,
void *data));
widget_id (*finger_motion_handler)(SDL_TouchFingerEvent *touch_event,
void *data),
widget_id (*mouse_button_down_handler)(SDL_MouseButtonEvent *button_event,
void *data),
widget_id (*mouse_button_up_handler)(SDL_MouseButtonEvent *button_event,
void *data),
widget_id (*mouse_motion_handler)(SDL_MouseMotionEvent *motion_event,
void *data));
unsigned default_font_size(struct theme *act_theme);
void update_font_from_theme(int theme_font_size);
client/gui-sdl3/repodlgs.c
/**********************************************************************//**
User released mouse button while adjusting rates.
**************************************************************************/
static Uint16 report_scroll_mouse_button_up(SDL_MouseButtonEvent *button_event,
void *data)
static widget_id report_scroll_mouse_button_up(SDL_MouseButtonEvent *button_event,
void *data)
{
return (Uint16)ID_SCROLLBAR;
return (widget_id)ID_SCROLLBAR;
}
/**********************************************************************//**
User moved a mouse while adjusting rates.
**************************************************************************/
static Uint16 report_scroll_mouse_motion_handler(SDL_MouseMotionEvent *motion_event,
void *data)
static widget_id report_scroll_mouse_motion_handler(SDL_MouseMotionEvent *motion_event,
void *data)
{
struct rates_move *motion = (struct rates_move *)data;
struct widget *tax_label = economy_dlg->end_widget_list->prev->prev;
......
&& (motion_event->x >= motion->min)
&& (motion_event->x <= motion->max)) {
/* set up directions */
/* Set up directions */
if (motion_event->xrel > 0) {
dir = 15;
inc = 10;
......
inc = -10;
}
/* make checks */
/* Make checks */
x = motion->horiz_src->size.x;
if (((x + dir) <= motion->max) && ((x + dir) >= motion->min)) {
/* src in range */
......
}
}
/* undraw scrollbars */
/* Undraw scrollbars */
widget_undraw(motion->horiz_src);
widget_mark_dirty(motion->horiz_src);
......
fc_snprintf(cbuf, sizeof(cbuf), "%d%%", *motion->dst_rate);
copy_chars_to_utf8_str(motion->label_dst->string_utf8, cbuf);
/* redraw label */
/* Redraw label */
widget_redraw(motion->label_src);
widget_mark_dirty(motion->label_src);
widget_redraw(motion->label_dst);
widget_mark_dirty(motion->label_dst);
/* redraw scrollbar */
/* Redraw scrollbar */
if (get_wflags(motion->horiz_src) & WF_RESTORE_BACKGROUND) {
refresh_widget_background(motion->horiz_src);
}
client/gui-sdl3/widget.c
/**********************************************************************//**
Add Widget to Main widgets list ( begin_widget_list )
**************************************************************************/
void add_to_gui_list(Uint16 id, struct widget *gui)
void add_to_gui_list(widget_id id, struct widget *gui)
{
if (begin_main_widget_list != NULL) {
gui->next = begin_main_widget_list;
client/gui-sdl3/widget.h
SDL_Keycode key; /* key aliased with this widget */
Uint16 mod; /* SHIFT, CTRL, ALT, etc */
Uint16 id; /* id in widget list */
widget_id id; /* id in widget list */
int (*action) (struct widget *); /* default callback action */
......
SCAN_BACKWARD
};
void add_to_gui_list(Uint16 id, struct widget *gui);
void add_to_gui_list(widget_id id, struct widget *gui);
void del_widget_pointer_from_gui_list(struct widget *gui);
void widget_add_as_prev(struct widget *new_widget, struct widget *add_dock);
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_KeyboardEvent *key, void *data)
static widget_id edit_key_down(SDL_KeyboardEvent *key, void *data)
{
struct text_edit *edt = (struct text_edit *)data;
struct utf8_char *input_chain_tmp;
......
break;
default:
break;
} /* key pressed switch */
} /* Key pressed switch */
if (redraw) {
redraw_edit_chain(edt);
......
/**********************************************************************//**
Handle textinput strings coming to the edit widget
**************************************************************************/
static Uint16 edit_textinput(const char *text, void *data)
static widget_id edit_textinput(const char *text, void *data)
{
struct text_edit *edt = (struct text_edit *)data;
struct utf8_char *input_chain_tmp;
......
/**********************************************************************//**
Handle mouse down events on edit widget.
**************************************************************************/
static Uint16 edit_mouse_button_down(SDL_MouseButtonEvent *button_event,
void *data)
static widget_id edit_mouse_button_down(SDL_MouseButtonEvent *button_event,
void *data)
{
struct text_edit *edt = (struct text_edit *)data;
......
&& button_event->x < edt->pwidget->size.x + edt->bg->w
&& button_event->y >= edt->pwidget->size.y
&& button_event->y < edt->pwidget->size.y + edt->bg->h)) {
/* exit from loop */
return (Uint16)ED_MOUSE;
/* Exit from loop */
return (widget_id)ED_MOUSE;
}
}
return (Uint16)ID_ERROR;
return (widget_id)ID_ERROR;
}
/**********************************************************************//**
......
edt.end_text_chain->next = NULL;
edt.end_text_chain->prev = NULL;
/* set font style (if any ) */
/* Set font style (if any ) */
if (!((edit_widget->string_utf8->style & 0x0F) & TTF_STYLE_NORMAL)) {
TTF_SetFontStyle(edit_widget->string_utf8->font,
(edit_widget->string_utf8->style & 0x0F));
......
edt.end_text_chain->chr, 0,
edit_widget->string_utf8->fgcol);
/* create surface for each font in chain and find chain length */
/* Create surface for each font in chain and find chain length */
if (edt.begin_text_chain) {
input_chain_tmp = edt.begin_text_chain;
......
set_wstate(edit_widget, FC_WS_PRESSED);
{
/* local loop */
Uint16 rety = gui_event_loop((void *)&edt, NULL,
edit_key_down, NULL, edit_textinput, NULL, NULL, NULL,
edit_mouse_button_down, NULL, NULL);
/* Local loop */
widget_id rety = gui_event_loop((void *)&edt, NULL,
edit_key_down, NULL, edit_textinput, NULL, NULL, NULL,
edit_mouse_button_down, NULL, NULL);
if (edt.begin_text_chain == edt.end_text_chain) {
edt.begin_text_chain = NULL;
client/gui-sdl3/widget_scrollbar.c
/**********************************************************************//**
Handle mouse motion events of the vertical scrollbar event loop.
**************************************************************************/
static Uint16 scroll_mouse_motion_handler(SDL_MouseMotionEvent *motion_event,
void *data)
static widget_id scroll_mouse_motion_handler(SDL_MouseMotionEvent *motion_event,
void *data)
{
struct up_down *motion = (struct up_down *)data;
int yrel;
......
/**********************************************************************//**
Callback for scrollbar event loops' mouse up events.
**************************************************************************/
static Uint16 scroll_mouse_button_up(SDL_MouseButtonEvent *button_event,
void *data)
static widget_id scroll_mouse_button_up(SDL_MouseButtonEvent *button_event,
void *data)
{
return (Uint16)ID_SCROLLBAR;
return (widget_id)ID_SCROLLBAR;
}
/**********************************************************************//**
client/gui-sdl3/widget_window.c
/**********************************************************************//**
Move window as event instructs.
**************************************************************************/
static Uint16 move_window_motion(SDL_MouseMotionEvent *motion_event,
void *data)
static widget_id move_window_motion(SDL_MouseMotionEvent *motion_event,
void *data)
{
struct move *pmove = (struct move *)data;
int xrel, yrel;
......
/**********************************************************************//**
Button up event handler for the window moving event loop.
**************************************************************************/
static Uint16 move_window_button_up(SDL_MouseButtonEvent *button_event,
void *data)
static widget_id move_window_button_up(SDL_MouseButtonEvent *button_event,
void *data)
{
struct move *pmove = (struct move *)data;
if (pmove && pmove->moved) {
return (Uint16)ID_MOVED_WINDOW;
return (widget_id)ID_MOVED_WINDOW;
}
return (Uint16)ID_WINDOW;
return (widget_id)ID_WINDOW;
}
/**********************************************************************//**
(2-2/2)