From 928018783348b852cd5476f191899f121d2f380e Mon Sep 17 00:00:00 2001 From: Kp Date: Mon, 12 Oct 2020 03:28:26 +0000 Subject: [PATCH] Rename ui_radio_do to UI_GADGET_RADIO::event_handler --- common/include/ui.h | 2 +- common/ui/gadget.cpp | 2 +- common/ui/radio.cpp | 53 ++++++++++++++++++-------------------------- 3 files changed, 24 insertions(+), 33 deletions(-) diff --git a/common/include/ui.h b/common/include/ui.h index 04b3e80bc..f8d4723a7 100644 --- a/common/include/ui.h +++ b/common/include/ui.h @@ -132,6 +132,7 @@ struct UI_GADGET_INPUTBOX : UI_GADGET struct UI_GADGET_RADIO : UI_GADGET { static constexpr auto s_kind = std::integral_constant{}; + window_event_result event_handler(UI_DIALOG &dlg, const d_event &event); RAIIdmem text; short width, height; short position; @@ -316,7 +317,6 @@ extern void ui_dprintf_at( UI_DIALOG * dlg, short x, short y, const char * forma extern void ui_draw_radio( UI_DIALOG *dlg, UI_GADGET_RADIO * radio ); __attribute_warn_unused_result std::unique_ptr ui_add_gadget_radio(UI_DIALOG * dlg, short x, short y, short w, short h, short group, const char * text); -window_event_result ui_radio_do( UI_DIALOG *dlg, UI_GADGET_RADIO * radio, const d_event &event ); extern void ui_radio_set_value(UI_GADGET_RADIO *radio, int value); extern void ui_draw_checkbox( UI_DIALOG *dlg, UI_GADGET_CHECKBOX * checkbox ); diff --git a/common/ui/gadget.cpp b/common/ui/gadget.cpp index 25c1fef67..c8f8f8011 100644 --- a/common/ui/gadget.cpp +++ b/common/ui/gadget.cpp @@ -171,7 +171,7 @@ static window_event_result ui_gadget_do(UI_DIALOG *dlg, UI_GADGET *g,const d_eve case UI_GADGET_SCROLLBAR::s_kind: return static_cast(g)->event_handler(*dlg, event); case UI_GADGET_RADIO::s_kind: - return ui_radio_do(dlg, static_cast(g), event); + return static_cast(g)->event_handler(*dlg, event); case UI_GADGET_CHECKBOX::s_kind: return ui_checkbox_do(dlg, static_cast(g), event); case UI_GADGET_INPUTBOX::s_kind: diff --git a/common/ui/radio.cpp b/common/ui/radio.cpp index 48f278948..f167e44d0 100644 --- a/common/ui/radio.cpp +++ b/common/ui/radio.cpp @@ -80,66 +80,57 @@ std::unique_ptr ui_add_gadget_radio(UI_DIALOG * dlg, short x, s return radio; } -window_event_result ui_radio_do( UI_DIALOG *dlg, UI_GADGET_RADIO * radio,const d_event &event ) +window_event_result UI_GADGET_RADIO::event_handler(UI_DIALOG &dlg, const d_event &event) { - UI_GADGET * tmp; - radio->oldposition = radio->position; - radio->pressed = 0; + oldposition = position; + pressed = 0; window_event_result rval = window_event_result::ignored; if (event.type == EVENT_MOUSE_BUTTON_DOWN || event.type == EVENT_MOUSE_BUTTON_UP) { - const auto OnMe = ui_mouse_on_gadget(*radio); + const auto OnMe = ui_mouse_on_gadget(*this); if ( B1_JUST_PRESSED && OnMe) { - radio->position = 1; + position = 1; rval = window_event_result::handled; } else if (B1_JUST_RELEASED) { - if ((radio->position==1) && OnMe) - radio->pressed = 1; + if ((position==1) && OnMe) + pressed = 1; - radio->position = 0; + position = 0; } } if (event.type == EVENT_KEY_COMMAND) { - int key; - - key = event_key_get(event); - - if ((dlg->keyboard_focus_gadget==radio) && ((key==KEY_SPACEBAR) || (key==KEY_ENTER)) ) + const auto key = event_key_get(event); + if (dlg.keyboard_focus_gadget == this && (key == KEY_SPACEBAR || key==KEY_ENTER)) { - radio->position = 2; + position = 2; rval = window_event_result::handled; } } else if (event.type == EVENT_KEY_RELEASE) { - int key; - - key = event_key_get(event); - - radio->position = 0; - - if ((dlg->keyboard_focus_gadget==radio) && ((key==KEY_SPACEBAR) || (key==KEY_ENTER)) ) - radio->pressed = 1; + const auto key = event_key_get(event); + position = 0; + if (dlg.keyboard_focus_gadget == this && (key == KEY_SPACEBAR || key == KEY_ENTER)) + pressed = 1; } - - if ((radio->pressed == 1) && (radio->flag==0)) + if (pressed == 1 && flag == 0) { - tmp = radio->next; + auto tmp = next; - while (tmp != radio ) + while (tmp != this) { if (tmp->kind==UI_GADGET_RADIO::s_kind) { auto tmpr = static_cast(tmp); - if ((tmpr->group == radio->group ) && (tmpr->flag) ) + if ((tmpr->group == group ) && (tmpr->flag) ) { tmpr->flag = 0; tmpr->status = 1; @@ -148,14 +139,14 @@ window_event_result ui_radio_do( UI_DIALOG *dlg, UI_GADGET_RADIO * radio,const d } tmp = tmp->next; } - radio->flag = 1; - rval = ui_gadget_send_event(*dlg, EVENT_UI_GADGET_PRESSED, *radio); + flag = 1; + rval = ui_gadget_send_event(dlg, EVENT_UI_GADGET_PRESSED, *this); if (rval == window_event_result::ignored) rval = window_event_result::handled; } if (event.type == EVENT_WINDOW_DRAW) - ui_draw_radio( dlg, radio ); + ui_draw_radio(&dlg, this); return rval; }