summaryrefslogtreecommitdiffstatshomepage
path: root/src/frontend/mame/ui/confswitch.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/mame/ui/confswitch.cpp')
-rw-r--r--src/frontend/mame/ui/confswitch.cpp74
1 files changed, 42 insertions, 32 deletions
diff --git a/src/frontend/mame/ui/confswitch.cpp b/src/frontend/mame/ui/confswitch.cpp
index 946062b9a1d..cf69bb7cfbb 100644
--- a/src/frontend/mame/ui/confswitch.cpp
+++ b/src/frontend/mame/ui/confswitch.cpp
@@ -11,6 +11,8 @@
#include "emu.h"
#include "ui/confswitch.h"
+#include "uiinput.h"
+
#include <algorithm>
#include <cstring>
@@ -73,6 +75,7 @@ menu_confswitch::menu_confswitch(mame_ui_manager &mui, render_container &contain
, m_switch_groups()
, m_active_switch_groups(0U)
, m_type(type)
+ , m_changed(false)
{
}
@@ -173,10 +176,18 @@ void menu_confswitch::populate()
bool menu_confswitch::handle(event const *ev)
{
- if (!ev || !ev->itemref)
- return false;
-
- if (uintptr_t(ev->itemref) == 1U)
+ bool const was_changed(std::exchange(m_changed, false));
+ bool need_update(false);
+ if (ev && (IPT_CUSTOM == ev->iptkey))
+ {
+ // clicked a switch
+ m_changed = true;
+ }
+ else if (!ev || !ev->itemref)
+ {
+ // no user input
+ }
+ else if (uintptr_t(ev->itemref) == 1U)
{
// reset
if (ev->iptkey == IPT_UI_SELECT)
@@ -186,21 +197,20 @@ bool menu_confswitch::handle(event const *ev)
{
// actual settings
ioport_field &field(*reinterpret_cast<ioport_field *>(ev->itemref));
- bool changed(false);
switch (ev->iptkey)
{
// left goes to previous setting
case IPT_UI_LEFT:
field.select_previous_setting();
- changed = true;
+ m_changed = true;
break;
// right goes to next setting
case IPT_UI_SELECT:
case IPT_UI_RIGHT:
field.select_next_setting();
- changed = true;
+ m_changed = true;
break;
// if cleared, reset to default value
@@ -212,7 +222,7 @@ bool menu_confswitch::handle(event const *ev)
{
settings.value = field.defvalue();
field.set_user_settings(settings);
- changed = true;
+ m_changed = true;
}
}
break;
@@ -233,7 +243,8 @@ bool menu_confswitch::handle(event const *ev)
{
set_selected_index(current);
set_top_line(current - 1);
- return true;
+ need_update = true;
+ break;
}
else
{
@@ -255,7 +266,7 @@ bool menu_confswitch::handle(event const *ev)
{
set_selected_index(current + 1);
set_top_line(current);
- return true;
+ need_update = true;
}
break;
}
@@ -263,14 +274,12 @@ bool menu_confswitch::handle(event const *ev)
}
break;
}
-
- // if anything changed, rebuild the menu, trying to stay on the same field
- if (changed)
- reset(reset_options::REMEMBER_REF);
}
// changing settings triggers an item rebuild because it can affect whether things are enabled
- return false;
+ if (m_changed || was_changed)
+ reset(reset_options::REMEMBER_REF);
+ return need_update;
}
@@ -339,16 +348,15 @@ void menu_settings_dip_switches::recompute_metrics(uint32_t width, uint32_t heig
}
-void menu_settings_dip_switches::custom_render(void *selectedref, float top, float bottom, float x1, float y1, float x2, float y2)
+void menu_settings_dip_switches::custom_render(uint32_t flags, void *selectedref, float top, float bottom, float origx1, float origy1, float origx2, float origy2)
{
// catch if no DIP locations have to be drawn
if (!m_visible_switch_groups)
return;
// calculate optimal width
- float const aspect(machine().render().ui_aspect(&container()));
float const maxwidth(1.0f - (lr_border() * 2.0f));
- m_single_width = (line_height() * SINGLE_TOGGLE_SWITCH_FIELD_WIDTH * aspect);
+ m_single_width = (line_height() * SINGLE_TOGGLE_SWITCH_FIELD_WIDTH * x_aspect());
float width(0.0f);
unsigned maxswitches(0U);
for (switch_group_descriptor const &group : switch_groups())
@@ -358,24 +366,24 @@ void menu_settings_dip_switches::custom_render(void *selectedref, float top, flo
maxswitches = (std::max)(group.switch_count(), maxswitches);
float const namewidth(get_string_width(group.name));
float const switchwidth(m_single_width * maxswitches);
- width = (std::min)((std::max)(namewidth + switchwidth + (line_height() * aspect), width), maxwidth);
+ width = (std::min)((std::max)(namewidth + switchwidth + (line_height() * x_aspect()), width), maxwidth);
}
}
// draw extra menu area
- float const boxwidth((std::max)(width + (lr_border() * 2.0f), x2 - x1));
+ float const boxwidth((std::max)(width + (lr_border() * 2.0f), origx2 - origx1));
float const boxleft((1.0f - boxwidth) * 0.5f);
- ui().draw_outlined_box(container(), boxleft, y2 + tb_border(), boxleft + boxwidth, y2 + bottom, ui().colors().background_color());
+ ui().draw_outlined_box(container(), boxleft, origy2 + tb_border(), boxleft + boxwidth, origy2 + bottom, ui().colors().background_color());
// calculate centred layout
float const nameleft((1.0f - width) * 0.5f);
float const switchleft(nameleft + width - (m_single_width * maxswitches));
- float const namewidth(width - (m_single_width * maxswitches) - (line_height() * aspect));
+ float const namewidth(width - (m_single_width * maxswitches) - (line_height() * x_aspect()));
// iterate over switch groups
ioport_field *const field((uintptr_t(selectedref) != 1U) ? reinterpret_cast<ioport_field *>(selectedref) : nullptr);
float const nubheight(line_height() * SINGLE_TOGGLE_SWITCH_HEIGHT);
- m_nub_width = line_height() * SINGLE_TOGGLE_SWITCH_WIDTH * aspect;
+ m_nub_width = line_height() * SINGLE_TOGGLE_SWITCH_WIDTH * x_aspect();
float const ygap(line_height() * ((DIP_SWITCH_HEIGHT * 0.5f) - SINGLE_TOGGLE_SWITCH_HEIGHT) * 0.5f);
float const xgap((m_single_width + (UI_LINE_WIDTH * 0.5f) - m_nub_width) * 0.5f);
m_first_nub = switchleft + xgap;
@@ -396,7 +404,7 @@ void menu_settings_dip_switches::custom_render(void *selectedref, float top, flo
}
// draw the name
- float const liney(y2 + (tb_border() * 2.0f) + (line_height() * (DIP_SWITCH_HEIGHT + DIP_SWITCH_SPACING) * line));
+ float const liney(origy2 + (tb_border() * 2.0f) + (line_height() * (DIP_SWITCH_HEIGHT + DIP_SWITCH_SPACING) * line));
draw_text_normal(
group.name,
nameleft, liney + (line_height() * (DIP_SWITCH_HEIGHT - 1.0f) / 2.0f), namewidth,
@@ -449,13 +457,16 @@ void menu_settings_dip_switches::custom_render(void *selectedref, float top, flo
}
-bool menu_settings_dip_switches::custom_mouse_down()
+std::tuple<int, bool, bool> menu_settings_dip_switches::custom_pointer_updated(bool changed, ui_event const &uievt)
{
- if (!m_visible_switch_groups || (get_mouse_x() < m_first_nub))
- return false;
+ if (!m_visible_switch_groups || !(uievt.pointer_pressed & 0x01) || (uievt.pointer_buttons & ~u32(0x01)))
+ return std::make_tuple(IPT_INVALID, false, false);
+
+ auto const [cx, y] = pointer_location();
+ if (cx < m_first_nub)
+ return std::make_tuple(IPT_INVALID, false, false);
- float const x(get_mouse_x() - m_first_nub);
- float const y(get_mouse_y());
+ float const x(cx - m_first_nub);
for (unsigned n = 0U, line = 0U; (switch_groups().size() > n) && (m_visible_switch_groups > line); ++n)
{
switch_group_descriptor const &group(switch_groups()[n]);
@@ -476,8 +487,7 @@ bool menu_settings_dip_switches::custom_mouse_down()
group.toggles[i].field->get_user_settings(settings);
settings.value ^= group.toggles[i].mask;
group.toggles[i].field->set_user_settings(settings);
- reset(reset_options::REMEMBER_REF);
- return true;
+ return std::make_tuple(IPT_CUSTOM, true, true);
}
}
}
@@ -485,7 +495,7 @@ bool menu_settings_dip_switches::custom_mouse_down()
}
}
- return false;
+ return std::make_tuple(IPT_INVALID, false, false);
}