summaryrefslogtreecommitdiffstatshomepage
path: root/src/frontend/mame/ui
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2017-09-15 19:04:22 -0400
committer AJR <ajrhacker@users.noreply.github.com>2017-09-15 19:04:22 -0400
commit98d3ff017559dca74323291d1473e30aacb6ab27 (patch)
tree03635ca95713e18e717ab5eecf7d437bb2f8dc97 /src/frontend/mame/ui
parent971335373540157f9d9a67db272fcc84cd9aa628 (diff)
Use std::unique_ptr to manage instances of slider_state (nw)
Diffstat (limited to 'src/frontend/mame/ui')
-rw-r--r--src/frontend/mame/ui/slider.h2
-rw-r--r--src/frontend/mame/ui/ui.cpp59
-rw-r--r--src/frontend/mame/ui/ui.h4
3 files changed, 33 insertions, 32 deletions
diff --git a/src/frontend/mame/ui/slider.h b/src/frontend/mame/ui/slider.h
index 75f2bd3336e..5e0613743aa 100644
--- a/src/frontend/mame/ui/slider.h
+++ b/src/frontend/mame/ui/slider.h
@@ -32,7 +32,7 @@ struct slider_state
int32_t maxval; /* maximum value */
int32_t incval; /* increment value */
int id;
- char description[1]; /* textual description */
+ std::string description; /* textual description */
};
#endif // __UI_SLIDER__
diff --git a/src/frontend/mame/ui/ui.cpp b/src/frontend/mame/ui/ui.cpp
index a7434c6df54..b64ef909033 100644
--- a/src/frontend/mame/ui/ui.cpp
+++ b/src/frontend/mame/ui/ui.cpp
@@ -1332,10 +1332,9 @@ std::vector<ui::menu_item>& mame_ui_manager::get_slider_list(void)
// slider_alloc - allocate a new slider entry
//-------------------------------------------------
-slider_state* mame_ui_manager::slider_alloc(running_machine &machine, int id, const char *title, int32_t minval, int32_t defval, int32_t maxval, int32_t incval, void *arg)
+std::unique_ptr<slider_state> mame_ui_manager::slider_alloc(running_machine &machine, int id, const char *title, int32_t minval, int32_t defval, int32_t maxval, int32_t incval, void *arg)
{
- int size = sizeof(slider_state) + strlen(title);
- slider_state *state = (slider_state *)auto_alloc_array_clear(machine, uint8_t, size);
+ auto state = make_unique_clear<slider_state>();
state->minval = minval;
state->defval = defval;
@@ -1347,7 +1346,7 @@ slider_state* mame_ui_manager::slider_alloc(running_machine &machine, int id, co
state->arg = arg;
state->id = id;
- strcpy(state->description, title);
+ state->description = title;
return state;
}
@@ -1360,10 +1359,10 @@ slider_state* mame_ui_manager::slider_alloc(running_machine &machine, int id, co
std::vector<ui::menu_item> mame_ui_manager::slider_init(running_machine &machine)
{
- std::vector<slider_state *> sliders;
+ m_sliders.clear();
// add overall volume
- sliders.push_back(slider_alloc(machine, SLIDER_ID_VOLUME, _("Master Volume"), -32, 0, 0, 1, nullptr));
+ m_sliders.push_back(slider_alloc(machine, SLIDER_ID_VOLUME, _("Master Volume"), -32, 0, 0, 1, nullptr));
// add per-channel volume
mixer_input info;
@@ -1373,7 +1372,7 @@ std::vector<ui::menu_item> mame_ui_manager::slider_init(running_machine &machine
int32_t defval = 1000;
std::string str = string_format(_("%1$s Volume"), info.stream->input_name(info.inputnum));
- sliders.push_back(slider_alloc(machine, SLIDER_ID_MIXERVOL + item, str.c_str(), 0, defval, maxval, 20, (void *)(uintptr_t)item));
+ m_sliders.push_back(slider_alloc(machine, SLIDER_ID_MIXERVOL + item, str.c_str(), 0, defval, maxval, 20, (void *)(uintptr_t)item));
}
// add analog adjusters
@@ -1384,7 +1383,7 @@ std::vector<ui::menu_item> mame_ui_manager::slider_init(running_machine &machine
{
if (field.type() == IPT_ADJUSTER)
{
- sliders.push_back(slider_alloc(machine, SLIDER_ID_ADJUSTER + slider_index++, field.name(), field.minval(), field.defvalue(), field.maxval(), 1, (void *)&field));
+ m_sliders.push_back(slider_alloc(machine, SLIDER_ID_ADJUSTER + slider_index++, field.name(), field.minval(), field.defvalue(), field.maxval(), 1, (void *)&field));
}
}
}
@@ -1397,7 +1396,7 @@ std::vector<ui::menu_item> mame_ui_manager::slider_init(running_machine &machine
{
void *param = (void *)&exec.device();
std::string str = string_format(_("Overclock CPU %1$s"), exec.device().tag());
- sliders.push_back(slider_alloc(machine, SLIDER_ID_OVERCLOCK + slider_index++, str.c_str(), 10, 1000, 2000, 1, param));
+ m_sliders.push_back(slider_alloc(machine, SLIDER_ID_OVERCLOCK + slider_index++, str.c_str(), 10, 1000, 2000, 1, param));
}
for (device_sound_interface &snd : sound_interface_iterator(machine.root_device()))
{
@@ -1406,7 +1405,7 @@ std::vector<ui::menu_item> mame_ui_manager::slider_init(running_machine &machine
{
void *param = (void *)&snd.device();
std::string str = string_format(_("Overclock %1$s sound"), snd.device().tag());
- sliders.push_back(slider_alloc(machine, SLIDER_ID_OVERCLOCK + slider_index++, str.c_str(), 10, 1000, 2000, 1, param));
+ m_sliders.push_back(slider_alloc(machine, SLIDER_ID_OVERCLOCK + slider_index++, str.c_str(), 10, 1000, 2000, 1, param));
}
}
}
@@ -1427,26 +1426,26 @@ std::vector<ui::menu_item> mame_ui_manager::slider_init(running_machine &machine
if (machine.options().cheat())
{
std::string str = string_format(_("%1$s Refresh Rate"), screen_desc);
- sliders.push_back(slider_alloc(machine, SLIDER_ID_REFRESH + slider_index, str.c_str(), -10000, 0, 10000, 1000, param));
+ m_sliders.push_back(slider_alloc(machine, SLIDER_ID_REFRESH + slider_index, str.c_str(), -10000, 0, 10000, 1000, param));
}
// add standard brightness/contrast/gamma controls per-screen
std::string str = string_format(_("%1$s Brightness"), screen_desc);
- sliders.push_back(slider_alloc(machine, SLIDER_ID_BRIGHTNESS + slider_index, str.c_str(), 100, 1000, 2000, 10, param));
+ m_sliders.push_back(slider_alloc(machine, SLIDER_ID_BRIGHTNESS + slider_index, str.c_str(), 100, 1000, 2000, 10, param));
str = string_format(_("%1$s Contrast"), screen_desc);
- sliders.push_back(slider_alloc(machine, SLIDER_ID_CONTRAST + slider_index, str.c_str(), 100, 1000, 2000, 50, param));
+ m_sliders.push_back(slider_alloc(machine, SLIDER_ID_CONTRAST + slider_index, str.c_str(), 100, 1000, 2000, 50, param));
str = string_format(_("%1$s Gamma"), screen_desc);
- sliders.push_back(slider_alloc(machine, SLIDER_ID_GAMMA + slider_index, str.c_str(), 100, 1000, 3000, 50, param));
+ m_sliders.push_back(slider_alloc(machine, SLIDER_ID_GAMMA + slider_index, str.c_str(), 100, 1000, 3000, 50, param));
// add scale and offset controls per-screen
str = string_format(_("%1$s Horiz Stretch"), screen_desc);
- sliders.push_back(slider_alloc(machine, SLIDER_ID_XSCALE + slider_index, str.c_str(), 500, defxscale, 1500, 2, param));
+ m_sliders.push_back(slider_alloc(machine, SLIDER_ID_XSCALE + slider_index, str.c_str(), 500, defxscale, 1500, 2, param));
str = string_format(_("%1$s Horiz Position"), screen_desc);
- sliders.push_back(slider_alloc(machine, SLIDER_ID_XOFFSET + slider_index, str.c_str(), -500, defxoffset, 500, 2, param));
+ m_sliders.push_back(slider_alloc(machine, SLIDER_ID_XOFFSET + slider_index, str.c_str(), -500, defxoffset, 500, 2, param));
str = string_format(_("%1$s Vert Stretch"), screen_desc);
- sliders.push_back(slider_alloc(machine, SLIDER_ID_YSCALE + slider_index, str.c_str(), 500, defyscale, 1500, 2, param));
+ m_sliders.push_back(slider_alloc(machine, SLIDER_ID_YSCALE + slider_index, str.c_str(), 500, defyscale, 1500, 2, param));
str = string_format(_("%1$s Vert Position"), screen_desc);
- sliders.push_back(slider_alloc(machine, SLIDER_ID_YOFFSET + slider_index, str.c_str(), -500, defyoffset, 500, 2, param));
+ m_sliders.push_back(slider_alloc(machine, SLIDER_ID_YOFFSET + slider_index, str.c_str(), -500, defyoffset, 500, 2, param));
slider_index++;
}
@@ -1465,13 +1464,13 @@ std::vector<ui::menu_item> mame_ui_manager::slider_init(running_machine &machine
// add scale and offset controls per-overlay
std::string str = string_format(_("Laserdisc '%1$s' Horiz Stretch"), laserdisc.tag());
- sliders.push_back(slider_alloc(machine, SLIDER_ID_OVERLAY_XSCALE + slider_index, str.c_str(), 500, (defxscale == 0) ? 1000 : defxscale, 1500, 2, param));
+ m_sliders.push_back(slider_alloc(machine, SLIDER_ID_OVERLAY_XSCALE + slider_index, str.c_str(), 500, (defxscale == 0) ? 1000 : defxscale, 1500, 2, param));
str = string_format(_("Laserdisc '%1$s' Horiz Position"), laserdisc.tag());
- sliders.push_back(slider_alloc(machine, SLIDER_ID_OVERLAY_YSCALE + slider_index, str.c_str(), -500, defxoffset, 500, 2, param));
+ m_sliders.push_back(slider_alloc(machine, SLIDER_ID_OVERLAY_YSCALE + slider_index, str.c_str(), -500, defxoffset, 500, 2, param));
str = string_format(_("Laserdisc '%1$s' Vert Stretch"), laserdisc.tag());
- sliders.push_back(slider_alloc(machine, SLIDER_ID_OVERLAY_XOFFSET + slider_index, str.c_str(), 500, (defyscale == 0) ? 1000 : defyscale, 1500, 2, param));
+ m_sliders.push_back(slider_alloc(machine, SLIDER_ID_OVERLAY_XOFFSET + slider_index, str.c_str(), 500, (defyscale == 0) ? 1000 : defyscale, 1500, 2, param));
str = string_format(_("Laserdisc '%1$s' Vert Position"), laserdisc.tag());
- sliders.push_back(slider_alloc(machine, SLIDER_ID_OVERLAY_YOFFSET + slider_index, str.c_str(), -500, defyoffset, 500, 2, param));
+ m_sliders.push_back(slider_alloc(machine, SLIDER_ID_OVERLAY_YOFFSET + slider_index, str.c_str(), -500, defyoffset, 500, 2, param));
slider_index++;
}
}
@@ -1482,10 +1481,10 @@ std::vector<ui::menu_item> mame_ui_manager::slider_init(running_machine &machine
if (screen.screen_type() == SCREEN_TYPE_VECTOR)
{
// add vector control
- sliders.push_back(slider_alloc(machine, SLIDER_ID_FLICKER + slider_index, _("Vector Flicker"), 0, 0, 1000, 10, nullptr));
- sliders.push_back(slider_alloc(machine, SLIDER_ID_BEAM_WIDTH_MIN + slider_index, _("Beam Width Minimum"), 100, 100, 1000, 1, nullptr));
- sliders.push_back(slider_alloc(machine, SLIDER_ID_BEAM_WIDTH_MAX + slider_index, _("Beam Width Maximum"), 100, 100, 1000, 1, nullptr));
- sliders.push_back(slider_alloc(machine, SLIDER_ID_BEAM_INTENSITY + slider_index, _("Beam Intensity Weight"), -1000, 0, 1000, 10, nullptr));
+ m_sliders.push_back(slider_alloc(machine, SLIDER_ID_FLICKER + slider_index, _("Vector Flicker"), 0, 0, 1000, 10, nullptr));
+ m_sliders.push_back(slider_alloc(machine, SLIDER_ID_BEAM_WIDTH_MIN + slider_index, _("Beam Width Minimum"), 100, 100, 1000, 1, nullptr));
+ m_sliders.push_back(slider_alloc(machine, SLIDER_ID_BEAM_WIDTH_MAX + slider_index, _("Beam Width Maximum"), 100, 100, 1000, 1, nullptr));
+ m_sliders.push_back(slider_alloc(machine, SLIDER_ID_BEAM_INTENSITY + slider_index, _("Beam Intensity Weight"), -1000, 0, 1000, 10, nullptr));
slider_index++;
break;
}
@@ -1501,22 +1500,22 @@ std::vector<ui::menu_item> mame_ui_manager::slider_init(running_machine &machine
if (field.crosshair_axis() != CROSSHAIR_AXIS_NONE && field.player() == 0)
{
std::string str = string_format(_("Crosshair Scale %1$s"), (field.crosshair_axis() == CROSSHAIR_AXIS_X) ? _("X") : _("Y"));
- sliders.push_back(slider_alloc(machine, SLIDER_ID_CROSSHAIR_SCALE + slider_index, str.c_str(), -3000, 1000, 3000, 100, (void *)&field));
+ m_sliders.push_back(slider_alloc(machine, SLIDER_ID_CROSSHAIR_SCALE + slider_index, str.c_str(), -3000, 1000, 3000, 100, (void *)&field));
str = string_format(_("Crosshair Offset %1$s"), (field.crosshair_axis() == CROSSHAIR_AXIS_X) ? _("X") : _("Y"));
- sliders.push_back(slider_alloc(machine, SLIDER_ID_CROSSHAIR_OFFSET + slider_index, str.c_str(), -3000, 0, 3000, 100, (void *)&field));
+ m_sliders.push_back(slider_alloc(machine, SLIDER_ID_CROSSHAIR_OFFSET + slider_index, str.c_str(), -3000, 0, 3000, 100, (void *)&field));
}
}
}
#endif
std::vector<ui::menu_item> items;
- for (slider_state *slider : sliders)
+ for (auto &slider : m_sliders)
{
ui::menu_item item;
item.text = slider->description;
item.subtext = "";
item.flags = 0;
- item.ref = slider;
+ item.ref = slider.get();
item.type = ui::menu_item_type::SLIDER;
items.push_back(item);
}
diff --git a/src/frontend/mame/ui/ui.h b/src/frontend/mame/ui/ui.h
index 02695a56bf3..e7fa657a879 100644
--- a/src/frontend/mame/ui/ui.h
+++ b/src/frontend/mame/ui/ui.h
@@ -266,7 +266,7 @@ private:
// private methods
void exit();
- slider_state* slider_alloc(running_machine &machine, int id, const char *title, int32_t minval, int32_t defval, int32_t maxval, int32_t incval, void *arg);
+ std::unique_ptr<slider_state> slider_alloc(running_machine &machine, int id, const char *title, int32_t minval, int32_t defval, int32_t maxval, int32_t incval, void *arg);
// slider controls
virtual int32_t slider_changed(running_machine &machine, void *arg, int id, std::string *str, int32_t newval) override;
@@ -296,6 +296,8 @@ private:
int32_t slider_crossscale(running_machine &machine, void *arg, int id, std::string *str, int32_t newval);
int32_t slider_crossoffset(running_machine &machine, void *arg, int id, std::string *str, int32_t newval);
#endif
+
+ std::vector<std::unique_ptr<slider_state>> m_sliders;
};