Merge pull request #936 from npwoods/fix_sliders_issue

Fix sliders issue
This commit is contained in:
Vas Crabb 2016-06-07 11:54:30 +10:00
commit e93f50f25e
3 changed files with 49 additions and 49 deletions

View File

@ -27,19 +27,19 @@ menu_sliders::~menu_sliders()
{ {
} }
/*------------------------------------------------- //-------------------------------------------------
menu_sliders - handle the sliders menu // menu_sliders - handle the sliders menu
-------------------------------------------------*/ //-------------------------------------------------
void menu_sliders::handle() void menu_sliders::handle()
{ {
const event *menu_event; const event *menu_event;
/* process the menu */ // process the menu
menu_event = process(PROCESS_LR_REPEAT | (m_hidden ? PROCESS_CUSTOM_ONLY : 0)); menu_event = process(PROCESS_LR_REPEAT | (m_hidden ? PROCESS_CUSTOM_ONLY : 0));
if (menu_event != nullptr) if (menu_event != nullptr)
{ {
/* handle keys if there is a valid item selected */ // handle keys if there is a valid item selected
if (menu_event->itemref != nullptr && menu_event->type == menu_item_type::SLIDER) if (menu_event->itemref != nullptr && menu_event->type == menu_item_type::SLIDER)
{ {
const slider_state *slider = (const slider_state *)menu_event->itemref; const slider_state *slider = (const slider_state *)menu_event->itemref;
@ -51,7 +51,7 @@ void menu_sliders::handle()
switch (menu_event->iptkey) switch (menu_event->iptkey)
{ {
/* toggle visibility */ // toggle visibility
case IPT_UI_ON_SCREEN_DISPLAY: case IPT_UI_ON_SCREEN_DISPLAY:
if (m_menuless_mode) if (m_menuless_mode)
menu::stack_pop(machine()); menu::stack_pop(machine());
@ -59,7 +59,7 @@ void menu_sliders::handle()
m_hidden = !m_hidden; m_hidden = !m_hidden;
break; break;
/* decrease value */ // decrease value
case IPT_UI_LEFT: case IPT_UI_LEFT:
if (alt_pressed && shift_pressed) if (alt_pressed && shift_pressed)
increment = -1; increment = -1;
@ -73,7 +73,7 @@ void menu_sliders::handle()
increment = -slider->incval; increment = -slider->incval;
break; break;
/* increase value */ // increase value
case IPT_UI_RIGHT: case IPT_UI_RIGHT:
if (alt_pressed && shift_pressed) if (alt_pressed && shift_pressed)
increment = 1; increment = 1;
@ -87,40 +87,40 @@ void menu_sliders::handle()
increment = slider->incval; increment = slider->incval;
break; break;
/* restore default */ // restore default
case IPT_UI_SELECT: case IPT_UI_SELECT:
increment = slider->defval - curvalue; increment = slider->defval - curvalue;
break; break;
} }
/* handle any changes */ // handle any changes
if (increment != 0) if (increment != 0)
{ {
INT32 newvalue = curvalue + increment; INT32 newvalue = curvalue + increment;
/* clamp within bounds */ // clamp within bounds
if (newvalue < slider->minval) if (newvalue < slider->minval)
newvalue = slider->minval; newvalue = slider->minval;
if (newvalue > slider->maxval) if (newvalue > slider->maxval)
newvalue = slider->maxval; newvalue = slider->maxval;
/* update the slider and recompute the menu */ // update the slider and recompute the menu
slider->update(machine(), slider->arg, slider->id, nullptr, newvalue); slider->update(machine(), slider->arg, slider->id, nullptr, newvalue);
reset(reset_options::REMEMBER_REF); reset(reset_options::REMEMBER_REF);
} }
} }
/* if we are selecting an invalid item and we are hidden, skip to the next one */ // if we are selecting an invalid item and we are hidden, skip to the next one
else if (m_hidden) else if (m_hidden)
{ {
/* if we got here via up or page up, select the previous item */ // if we got here via up or page up, select the previous item
if (menu_event->iptkey == IPT_UI_UP || menu_event->iptkey == IPT_UI_PAGE_UP) if (menu_event->iptkey == IPT_UI_UP || menu_event->iptkey == IPT_UI_PAGE_UP)
{ {
selected = (selected + item.size() - 1) % item.size(); selected = (selected + item.size() - 1) % item.size();
validate_selection(-1); validate_selection(-1);
} }
/* otherwise select the next item */ // otherwise select the next item
else if (menu_event->iptkey == IPT_UI_DOWN || menu_event->iptkey == IPT_UI_PAGE_DOWN) else if (menu_event->iptkey == IPT_UI_DOWN || menu_event->iptkey == IPT_UI_PAGE_DOWN)
{ {
selected = (selected + 1) % item.size(); selected = (selected + 1) % item.size();
@ -131,16 +131,16 @@ void menu_sliders::handle()
} }
/*------------------------------------------------- //-------------------------------------------------
menu_sliders_populate - populate the sliders // menu_sliders_populate - populate the sliders
menu // menu
-------------------------------------------------*/ //-------------------------------------------------
void menu_sliders::populate() void menu_sliders::populate()
{ {
std::string tempstring; std::string tempstring;
/* add UI sliders */ // add UI sliders
std::vector<menu_item> ui_sliders = ui().get_slider_list(); std::vector<menu_item> ui_sliders = ui().get_slider_list();
for (menu_item item : ui_sliders) for (menu_item item : ui_sliders)
{ {
@ -163,7 +163,7 @@ void menu_sliders::populate()
item_append(menu_item_type::SEPARATOR); item_append(menu_item_type::SEPARATOR);
/* add OSD options */ // add OSD options
std::vector<menu_item> osd_sliders = machine().osd().get_slider_list(); std::vector<menu_item> osd_sliders = machine().osd().get_slider_list();
for (menu_item item : osd_sliders) for (menu_item item : osd_sliders)
{ {
@ -187,10 +187,10 @@ void menu_sliders::populate()
custombottom = 2.0f * ui().get_line_height() + 2.0f * UI_BOX_TB_BORDER; custombottom = 2.0f * ui().get_line_height() + 2.0f * UI_BOX_TB_BORDER;
} }
/*------------------------------------------------- //-------------------------------------------------
menu_sliders_custom_render - perform our special // menu_sliders_custom_render - perform our special
rendering // rendering
-------------------------------------------------*/ //-------------------------------------------------
void menu_sliders::custom_render(void *selectedref, float top, float bottom, float x1, float y1, float x2, float y2) void menu_sliders::custom_render(void *selectedref, float top, float bottom, float x1, float y1, float x2, float y2)
{ {
@ -204,78 +204,78 @@ void menu_sliders::custom_render(void *selectedref, float top, float bottom, flo
float text_height; float text_height;
INT32 curval; INT32 curval;
/* determine the current value and text */ // determine the current value and text
curval = curslider->update(machine(), curslider->arg, curslider->id, &tempstring, SLIDER_NOCHANGE); curval = curslider->update(machine(), curslider->arg, curslider->id, &tempstring, SLIDER_NOCHANGE);
/* compute the current and default percentages */ // compute the current and default percentages
percentage = (float)(curval - curslider->minval) / (float)(curslider->maxval - curslider->minval); percentage = (float)(curval - curslider->minval) / (float)(curslider->maxval - curslider->minval);
default_percentage = (float)(curslider->defval - curslider->minval) / (float)(curslider->maxval - curslider->minval); default_percentage = (float)(curslider->defval - curslider->minval) / (float)(curslider->maxval - curslider->minval);
/* assemble the text */ // assemble the text
tempstring.insert(0, " ").insert(0, curslider->description); tempstring.insert(0, " ").insert(0, curslider->description);
/* move us to the bottom of the screen, and expand to full width */ // move us to the bottom of the screen, and expand to full width
y2 = 1.0f - UI_BOX_TB_BORDER; y2 = 1.0f - UI_BOX_TB_BORDER;
y1 = y2 - bottom; y1 = y2 - bottom;
x1 = UI_BOX_LR_BORDER; x1 = UI_BOX_LR_BORDER;
x2 = 1.0f - UI_BOX_LR_BORDER; x2 = 1.0f - UI_BOX_LR_BORDER;
/* draw extra menu area */ // draw extra menu area
ui().draw_outlined_box(container, x1, y1, x2, y2, UI_BACKGROUND_COLOR); ui().draw_outlined_box(container, x1, y1, x2, y2, UI_BACKGROUND_COLOR);
y1 += UI_BOX_TB_BORDER; y1 += UI_BOX_TB_BORDER;
/* determine the text height */ // determine the text height
ui().draw_text_full(container, tempstring.c_str(), 0, 0, x2 - x1 - 2.0f * UI_BOX_LR_BORDER, ui().draw_text_full(container, tempstring.c_str(), 0, 0, x2 - x1 - 2.0f * UI_BOX_LR_BORDER,
JUSTIFY_CENTER, WRAP_TRUNCATE, DRAW_NONE, rgb_t::white, rgb_t::black, nullptr, &text_height); JUSTIFY_CENTER, WRAP_TRUNCATE, DRAW_NONE, rgb_t::white, rgb_t::black, nullptr, &text_height);
/* draw the thermometer */ // draw the thermometer
bar_left = x1 + UI_BOX_LR_BORDER; bar_left = x1 + UI_BOX_LR_BORDER;
bar_area_top = y1; bar_area_top = y1;
bar_width = x2 - x1 - 2.0f * UI_BOX_LR_BORDER; bar_width = x2 - x1 - 2.0f * UI_BOX_LR_BORDER;
bar_area_height = line_height; bar_area_height = line_height;
/* compute positions */ // compute positions
bar_top = bar_area_top + 0.125f * bar_area_height; bar_top = bar_area_top + 0.125f * bar_area_height;
bar_bottom = bar_area_top + 0.875f * bar_area_height; bar_bottom = bar_area_top + 0.875f * bar_area_height;
default_x = bar_left + bar_width * default_percentage; default_x = bar_left + bar_width * default_percentage;
current_x = bar_left + bar_width * percentage; current_x = bar_left + bar_width * percentage;
/* fill in the percentage */ // fill in the percentage
container->add_rect(bar_left, bar_top, current_x, bar_bottom, UI_SLIDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); container->add_rect(bar_left, bar_top, current_x, bar_bottom, UI_SLIDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
/* draw the top and bottom lines */ // draw the top and bottom lines
container->add_line(bar_left, bar_top, bar_left + bar_width, bar_top, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); container->add_line(bar_left, bar_top, bar_left + bar_width, bar_top, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
container->add_line(bar_left, bar_bottom, bar_left + bar_width, bar_bottom, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); container->add_line(bar_left, bar_bottom, bar_left + bar_width, bar_bottom, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
/* draw default marker */ // draw default marker
container->add_line(default_x, bar_area_top, default_x, bar_top, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); container->add_line(default_x, bar_area_top, default_x, bar_top, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
container->add_line(default_x, bar_bottom, default_x, bar_area_top + bar_area_height, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); container->add_line(default_x, bar_bottom, default_x, bar_area_top + bar_area_height, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
/* draw the actual text */ // draw the actual text
ui().draw_text_full(container, tempstring.c_str(), x1 + UI_BOX_LR_BORDER, y1 + line_height, x2 - x1 - 2.0f * UI_BOX_LR_BORDER, ui().draw_text_full(container, tempstring.c_str(), x1 + UI_BOX_LR_BORDER, y1 + line_height, x2 - x1 - 2.0f * UI_BOX_LR_BORDER,
JUSTIFY_CENTER, WRAP_WORD, DRAW_NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, nullptr, &text_height); JUSTIFY_CENTER, WRAP_WORD, DRAW_NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, nullptr, &text_height);
} }
} }
/*------------------------------------------------- //-------------------------------------------------
slider_ui_handler - pushes the slider // slider_ui_handler - pushes the slider
menu on the stack and hands off to the // menu on the stack and hands off to the
standard menu handler // standard menu handler
-------------------------------------------------*/ //-------------------------------------------------
UINT32 menu_sliders::ui_handler(render_container *container, mame_ui_manager &mui, bool state) UINT32 menu_sliders::ui_handler(render_container *container, mame_ui_manager &mui)
{ {
UINT32 result; UINT32 result;
/* if this is the first call, push the sliders menu */ // if this is the first call, push the sliders menu
if (state) if (topmost_menu<menu_sliders>() == nullptr)
menu::stack_push<menu_sliders>(mui, container, true); menu::stack_push<menu_sliders>(mui, container, true);
/* handle standard menus */ // handle standard menus
result = menu::ui_handler(container, mui); result = menu::ui_handler(container, mui);
/* if we are cancelled, pop the sliders menu */ // if we are cancelled, pop the sliders menu
if (result == UI_HANDLER_CANCEL) if (result == UI_HANDLER_CANCEL)
menu::stack_pop(mui.machine()); menu::stack_pop(mui.machine());

View File

@ -27,7 +27,7 @@ public:
virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2) override; virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2) override;
static UINT32 ui_handler(render_container *container, mame_ui_manager &mui, bool state); static UINT32 ui_handler(render_container *container, mame_ui_manager &mui);
private: private:
enum { enum {

View File

@ -1572,7 +1572,7 @@ UINT32 mame_ui_manager::handler_ingame(render_container *container)
// if the on-screen display isn't up and the user has toggled it, turn it on // if the on-screen display isn't up and the user has toggled it, turn it on
if ((machine().debug_flags & DEBUG_FLAG_ENABLED) == 0 && machine().ui_input().pressed(IPT_UI_ON_SCREEN_DISPLAY)) if ((machine().debug_flags & DEBUG_FLAG_ENABLED) == 0 && machine().ui_input().pressed(IPT_UI_ON_SCREEN_DISPLAY))
{ {
set_handler<mame_ui_manager&, bool>(UI_CALLBACK_TYPE_GENERAL, ui::menu_sliders::ui_handler, *this, true); set_handler<mame_ui_manager&>(UI_CALLBACK_TYPE_MENU, ui::menu_sliders::ui_handler, *this);
return 1; return 1;
} }