Rename ui_radio_do to UI_GADGET_RADIO::event_handler
This commit is contained in:
parent
43c30bd6b3
commit
9280187833
|
@ -132,6 +132,7 @@ struct UI_GADGET_INPUTBOX : UI_GADGET
|
|||
struct UI_GADGET_RADIO : UI_GADGET
|
||||
{
|
||||
static constexpr auto s_kind = std::integral_constant<uint8_t, 4>{};
|
||||
window_event_result event_handler(UI_DIALOG &dlg, const d_event &event);
|
||||
RAIIdmem<char[]> 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_GADGET_RADIO> 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 );
|
||||
|
|
|
@ -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<UI_GADGET_SCROLLBAR *>(g)->event_handler(*dlg, event);
|
||||
case UI_GADGET_RADIO::s_kind:
|
||||
return ui_radio_do(dlg, static_cast<UI_GADGET_RADIO *>(g), event);
|
||||
return static_cast<UI_GADGET_RADIO *>(g)->event_handler(*dlg, event);
|
||||
case UI_GADGET_CHECKBOX::s_kind:
|
||||
return ui_checkbox_do(dlg, static_cast<UI_GADGET_CHECKBOX *>(g), event);
|
||||
case UI_GADGET_INPUTBOX::s_kind:
|
||||
|
|
|
@ -80,66 +80,57 @@ std::unique_ptr<UI_GADGET_RADIO> 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<UI_GADGET_RADIO *>(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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue