encapsulate mouse translation in the menu code, make more stuff const

This commit is contained in:
Vas Crabb 2016-11-23 12:48:41 +11:00
parent 32c256eccc
commit 95254fb277
8 changed files with 150 additions and 125 deletions

View File

@ -1060,19 +1060,18 @@ void menu_palette_sel::draw(uint32_t flags)
auto line_height = ui().get_line_height(); auto line_height = ui().get_line_height();
auto lr_arrow_width = 0.4f * line_height * machine().render().ui_aspect(); auto lr_arrow_width = 0.4f * line_height * machine().render().ui_aspect();
auto ud_arrow_width = line_height * machine().render().ui_aspect(); auto ud_arrow_width = line_height * machine().render().ui_aspect();
auto gutter_width = lr_arrow_width * 1.3f; float const gutter_width = lr_arrow_width * 1.3f;
int itemnum, linenum;
if (&machine().system() == &GAME_NAME(___empty)) if (&machine().system() == &GAME_NAME(___empty))
draw_background(); draw_background();
// compute the width and height of the full menu // compute the width and height of the full menu
auto visible_width = 0.0f; float visible_width = 0.0f;
auto visible_main_menu_height = 0.0f; float visible_main_menu_height = 0.0f;
for (auto & pitem : item) for (auto &pitem : item)
{ {
// compute width of left hand side // compute width of left hand side
auto total_width = gutter_width + ui().get_string_width(pitem.text.c_str()) + gutter_width; float total_width = gutter_width + ui().get_string_width(pitem.text.c_str()) + gutter_width;
// add in width of right hand side // add in width of right hand side
if (!pitem.subtext.empty()) if (!pitem.subtext.empty())
@ -1087,7 +1086,7 @@ void menu_palette_sel::draw(uint32_t flags)
} }
// account for extra space at the top and bottom // account for extra space at the top and bottom
auto visible_extra_menu_height = get_customtop() + get_custombottom(); float const visible_extra_menu_height = get_customtop() + get_custombottom();
// add a little bit of slop for rounding // add a little bit of slop for rounding
visible_width += 0.01f; visible_width += 0.01f;
@ -1112,10 +1111,10 @@ void menu_palette_sel::draw(uint32_t flags)
visible_top += get_customtop(); visible_top += get_customtop();
// first add us a box // first add us a box
float x1 = visible_left - UI_BOX_LR_BORDER; float const x1 = visible_left - UI_BOX_LR_BORDER;
float y1 = visible_top - UI_BOX_TB_BORDER; float const y1 = visible_top - UI_BOX_TB_BORDER;
float x2 = visible_left + visible_width + UI_BOX_LR_BORDER; float const x2 = visible_left + visible_width + UI_BOX_LR_BORDER;
float y2 = visible_top + visible_main_menu_height + UI_BOX_TB_BORDER; float const y2 = visible_top + visible_main_menu_height + UI_BOX_TB_BORDER;
ui().draw_outlined_box(container(), x1, y1, x2, y2, UI_BACKGROUND_COLOR); ui().draw_outlined_box(container(), x1, y1, x2, y2, UI_BACKGROUND_COLOR);
// determine the first visible line based on the current selection // determine the first visible line based on the current selection
@ -1130,43 +1129,37 @@ void menu_palette_sel::draw(uint32_t flags)
float effective_left = visible_left + gutter_width; float effective_left = visible_left + gutter_width;
// locate mouse // locate mouse
mouse_hit = false; map_mouse();
mouse_button = false;
mouse_target = machine().ui_input().find_mouse(&mouse_target_x, &mouse_target_y, &mouse_button);
if (mouse_target != nullptr)
if (mouse_target->map_point_container(mouse_target_x, mouse_target_y, container(), mouse_x, mouse_y))
mouse_hit = true;
// loop over visible lines // loop over visible lines
hover = item.size() + 1; hover = item.size() + 1;
float line_x0 = x1 + 0.5f * UI_LINE_WIDTH; float const line_x0 = x1 + 0.5f * UI_LINE_WIDTH;
float line_x1 = x2 - 0.5f * UI_LINE_WIDTH; float const line_x1 = x2 - 0.5f * UI_LINE_WIDTH;
for (linenum = 0; linenum < visible_lines; linenum++) for (int linenum = 0; linenum < visible_lines; linenum++)
{ {
float line_y = visible_top + (float)linenum * line_height; float const line_y = visible_top + float(linenum) * line_height;
itemnum = top_line + linenum; int const itemnum = top_line + linenum;
const menu_item &pitem = item[itemnum]; menu_item const &pitem = item[itemnum];
const char *itemtext = pitem.text.c_str(); char const *const itemtext = pitem.text.c_str();
rgb_t fgcolor = UI_TEXT_COLOR; float const line_y0 = line_y;
rgb_t bgcolor = UI_TEXT_BG_COLOR; float const line_y1 = line_y + line_height;
float line_y0 = line_y;
float line_y1 = line_y + line_height;
// set the hover if this is our item // set the hover if this is our item
if (mouse_hit && line_x0 <= mouse_x && line_x1 > mouse_x && line_y0 <= mouse_y && line_y1 > mouse_y && is_selectable(pitem)) if (mouse_in_rect(line_x0, line_y0, line_x1, line_y1) && is_selectable(pitem))
hover = itemnum; hover = itemnum;
// if we're selected, draw with a different background rgb_t fgcolor = UI_TEXT_COLOR;
rgb_t bgcolor = UI_TEXT_BG_COLOR;
if (itemnum == selected) if (itemnum == selected)
{ {
// if we're selected, draw with a different background
fgcolor = UI_SELECTED_COLOR; fgcolor = UI_SELECTED_COLOR;
bgcolor = UI_SELECTED_BG_COLOR; bgcolor = UI_SELECTED_BG_COLOR;
} }
// else if the mouse is over this item, draw with a different background
else if (itemnum == hover) else if (itemnum == hover)
{ {
// else if the mouse is over this item, draw with a different background
fgcolor = UI_MOUSEOVER_COLOR; fgcolor = UI_MOUSEOVER_COLOR;
bgcolor = UI_MOUSEOVER_BG_COLOR; bgcolor = UI_MOUSEOVER_BG_COLOR;
} }
@ -1175,46 +1168,46 @@ void menu_palette_sel::draw(uint32_t flags)
if (bgcolor != UI_TEXT_BG_COLOR) if (bgcolor != UI_TEXT_BG_COLOR)
highlight(line_x0, line_y0, line_x1, line_y1, bgcolor); highlight(line_x0, line_y0, line_x1, line_y1, bgcolor);
// if we're on the top line, display the up arrow
if (linenum == 0 && top_line != 0) if (linenum == 0 && top_line != 0)
{ {
// if we're on the top line, display the up arrow
draw_arrow( draw_arrow(
0.5f * (x1 + x2) - 0.5f * ud_arrow_width, 0.5f * (x1 + x2) - 0.5f * ud_arrow_width,
line_y + 0.25f * line_height, line_y + 0.25f * line_height,
0.5f * (x1 + x2) + 0.5f * ud_arrow_width, 0.5f * (x1 + x2) + 0.5f * ud_arrow_width,
line_y + 0.75f * line_height, line_y + 0.75f * line_height,
fgcolor, fgcolor,
ROT0); ROT0);
if (hover == itemnum) if (hover == itemnum)
hover = HOVER_ARROW_UP; hover = HOVER_ARROW_UP;
} }
// if we're on the bottom line, display the down arrow
else if (linenum == visible_lines - 1 && itemnum != item.size() - 1) else if (linenum == visible_lines - 1 && itemnum != item.size() - 1)
{ {
// if we're on the bottom line, display the down arrow
draw_arrow( draw_arrow(
0.5f * (x1 + x2) - 0.5f * ud_arrow_width, 0.5f * (x1 + x2) - 0.5f * ud_arrow_width,
line_y + 0.25f * line_height, line_y + 0.25f * line_height,
0.5f * (x1 + x2) + 0.5f * ud_arrow_width, 0.5f * (x1 + x2) + 0.5f * ud_arrow_width,
line_y + 0.75f * line_height, line_y + 0.75f * line_height,
fgcolor, fgcolor,
ROT0 ^ ORIENTATION_FLIP_Y); ROT0 ^ ORIENTATION_FLIP_Y);
if (hover == itemnum) if (hover == itemnum)
hover = HOVER_ARROW_DOWN; hover = HOVER_ARROW_DOWN;
} }
// if we're just a divider, draw a line
else if (pitem.type == menu_item_type::SEPARATOR) else if (pitem.type == menu_item_type::SEPARATOR)
{
// if we're just a divider, draw a line
container().add_line(visible_left, line_y + 0.5f * line_height, visible_left + visible_width, line_y + 0.5f * line_height, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); container().add_line(visible_left, line_y + 0.5f * line_height, visible_left + visible_width, line_y + 0.5f * line_height, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
}
// if we don't have a subitem, just draw the string centered
else if (pitem.subtext.empty()) else if (pitem.subtext.empty())
{
// if we don't have a subitem, just draw the string centered
ui().draw_text_full(container(), itemtext, effective_left, line_y, effective_width, ui().draw_text_full(container(), itemtext, effective_left, line_y, effective_width,
ui::text_layout::CENTER, ui::text_layout::TRUNCATE, mame_ui_manager::NORMAL, fgcolor, bgcolor, nullptr, nullptr); ui::text_layout::CENTER, ui::text_layout::TRUNCATE, mame_ui_manager::NORMAL, fgcolor, bgcolor, nullptr, nullptr);
}
// otherwise, draw the item on the left and the subitem text on the right
else else
{ {
// otherwise, draw the item on the left and the subitem text on the right
const char *subitem_text = pitem.subtext.c_str(); const char *subitem_text = pitem.subtext.c_str();
rgb_t color = rgb_t((uint32_t)strtoul(subitem_text, nullptr, 16)); rgb_t color = rgb_t((uint32_t)strtoul(subitem_text, nullptr, 16));

View File

@ -151,7 +151,6 @@ void menu_dats_view::draw(uint32_t flags)
auto line_height = ui().get_line_height(); auto line_height = ui().get_line_height();
auto ud_arrow_width = line_height * machine().render().ui_aspect(); auto ud_arrow_width = line_height * machine().render().ui_aspect();
auto gutter_width = 0.52f * line_height * machine().render().ui_aspect(); auto gutter_width = 0.52f * line_height * machine().render().ui_aspect();
mouse_x = -1, mouse_y = -1;
float visible_width = 1.0f - 2.0f * UI_BOX_LR_BORDER; float visible_width = 1.0f - 2.0f * UI_BOX_LR_BORDER;
float visible_left = (1.0f - visible_width) * 0.5f; float visible_left = (1.0f - visible_width) * 0.5f;
@ -163,12 +162,7 @@ void menu_dats_view::draw(uint32_t flags)
float visible_extra_menu_height = get_customtop() + get_custombottom() + extra_height; float visible_extra_menu_height = get_customtop() + get_custombottom() + extra_height;
// locate mouse // locate mouse
mouse_hit = false; map_mouse();
mouse_button = false;
mouse_target = machine().ui_input().find_mouse(&mouse_target_x, &mouse_target_y, &mouse_button);
if (mouse_target != nullptr)
if (mouse_target->map_point_container(mouse_target_x, mouse_target_y, container(), mouse_x, mouse_y))
mouse_hit = true;
// account for extra space at the top and bottom // account for extra space at the top and bottom
float visible_main_menu_height = 1.0f - 2.0f * UI_BOX_TB_BORDER - visible_extra_menu_height; float visible_main_menu_height = 1.0f - 2.0f * UI_BOX_TB_BORDER - visible_extra_menu_height;
@ -219,7 +213,7 @@ void menu_dats_view::draw(uint32_t flags)
draw_arrow(0.5f * (x1 + x2) - 0.5f * ud_arrow_width, line_y + 0.25f * line_height, draw_arrow(0.5f * (x1 + x2) - 0.5f * ud_arrow_width, line_y + 0.25f * line_height,
0.5f * (x1 + x2) + 0.5f * ud_arrow_width, line_y + 0.75f * line_height, fgcolor, ROT0); 0.5f * (x1 + x2) + 0.5f * ud_arrow_width, line_y + 0.75f * line_height, fgcolor, ROT0);
if (mouse_hit && line_x0 <= mouse_x && line_x1 > mouse_x && line_y0 <= mouse_y && line_y1 > mouse_y) if (mouse_in_rect(line_x0, line_y0, line_x1, line_y1))
{ {
fgcolor = UI_MOUSEOVER_COLOR; fgcolor = UI_MOUSEOVER_COLOR;
bgcolor = UI_MOUSEOVER_BG_COLOR; bgcolor = UI_MOUSEOVER_BG_COLOR;
@ -233,7 +227,7 @@ void menu_dats_view::draw(uint32_t flags)
draw_arrow(0.5f * (x1 + x2) - 0.5f * ud_arrow_width, line_y + 0.25f * line_height, draw_arrow(0.5f * (x1 + x2) - 0.5f * ud_arrow_width, line_y + 0.25f * line_height,
0.5f * (x1 + x2) + 0.5f * ud_arrow_width, line_y + 0.75f * line_height, fgcolor, ROT0 ^ ORIENTATION_FLIP_Y); 0.5f * (x1 + x2) + 0.5f * ud_arrow_width, line_y + 0.75f * line_height, fgcolor, ROT0 ^ ORIENTATION_FLIP_Y);
if (mouse_hit && line_x0 <= mouse_x && line_x1 > mouse_x && line_y0 <= mouse_y && line_y1 > mouse_y) if (mouse_in_rect(line_x0, line_y0, line_x1, line_y1))
{ {
fgcolor = UI_MOUSEOVER_COLOR; fgcolor = UI_MOUSEOVER_COLOR;
bgcolor = UI_MOUSEOVER_BG_COLOR; bgcolor = UI_MOUSEOVER_BG_COLOR;
@ -261,7 +255,7 @@ void menu_dats_view::draw(uint32_t flags)
rgb_t fgcolor = UI_SELECTED_COLOR; rgb_t fgcolor = UI_SELECTED_COLOR;
rgb_t bgcolor = UI_SELECTED_BG_COLOR; rgb_t bgcolor = UI_SELECTED_BG_COLOR;
if (mouse_hit && line_x0 <= mouse_x && line_x1 > mouse_x && line_y0 <= mouse_y && line_y1 > mouse_y && is_selectable(pitem)) if (mouse_in_rect(line_x0, line_y0, line_x1, line_y1) && is_selectable(pitem))
hover = count; hover = count;
if (pitem.type == menu_item_type::SEPARATOR) if (pitem.type == menu_item_type::SEPARATOR)

View File

@ -89,8 +89,8 @@ void menu_file_selector::custom_render(void *selectedref, float top, float botto
y1 += UI_BOX_TB_BORDER; y1 += UI_BOX_TB_BORDER;
size_t hit_start = 0, hit_span = 0; size_t hit_start = 0, hit_span = 0;
if (mouse_hit if (is_mouse_hit()
&& layout.hit_test(mouse_x - x1, mouse_y - y1, hit_start, hit_span) && layout.hit_test(get_mouse_x() - x1, get_mouse_y() - y1, hit_start, hit_span)
&& m_current_directory.substr(hit_start, hit_span) != PATH_SEPARATOR) && m_current_directory.substr(hit_start, hit_span) != PATH_SEPARATOR)
{ {
// we're hovering over a directory! highlight it // we're hovering over a directory! highlight it

View File

@ -237,6 +237,10 @@ menu::menu(mame_ui_manager &mui, render_container &container)
, m_custombottom(0.0f) , m_custombottom(0.0f)
, m_resetpos(0) , m_resetpos(0)
, m_resetref(nullptr) , m_resetref(nullptr)
, m_mouse_hit(false)
, m_mouse_button(false)
, m_mouse_x(-1.0f)
, m_mouse_y(-1.0f)
{ {
assert(m_global_state); // not calling init is bad assert(m_global_state); // not calling init is bad
@ -602,16 +606,10 @@ void menu::draw(uint32_t flags)
float const effective_left = visible_left + gutter_width; float const effective_left = visible_left + gutter_width;
// locate mouse // locate mouse
mouse_hit = false;
mouse_button = false;
if (!customonly && !noinput) if (!customonly && !noinput)
{ map_mouse();
int32_t mouse_target_x, mouse_target_y; else
render_target *mouse_target = machine().ui_input().find_mouse(&mouse_target_x, &mouse_target_y, &mouse_button); ignore_mouse();
if (mouse_target != nullptr)
if (mouse_target->map_point_container(mouse_target_x, mouse_target_y, container(), mouse_x, mouse_y))
mouse_hit = true;
}
// loop over visible lines // loop over visible lines
hover = item.size() + 1; hover = item.size() + 1;
@ -633,7 +631,7 @@ void menu::draw(uint32_t flags)
float const line_y1 = line_y0 + line_height; float const line_y1 = line_y0 + line_height;
// set the hover if this is our item // set the hover if this is our item
if (mouse_hit && line_x0 <= mouse_x && line_x1 > mouse_x && line_y0 <= mouse_y && line_y1 > mouse_y && is_selectable(pitem)) if (mouse_in_rect(line_x0, line_y0, line_x1, line_y1) && is_selectable(pitem))
hover = itemnum; hover = itemnum;
// if we're selected, draw with a different background // if we're selected, draw with a different background
@ -861,6 +859,38 @@ void menu::draw_text_box()
} }
//-------------------------------------------------
// map_mouse - map mouse pointer location to menu
// coordinates
//-------------------------------------------------
void menu::map_mouse()
{
ignore_mouse();
int32_t mouse_target_x, mouse_target_y;
render_target *const mouse_target = machine().ui_input().find_mouse(&mouse_target_x, &mouse_target_y, &m_mouse_button);
if (mouse_target)
{
if (mouse_target->map_point_container(mouse_target_x, mouse_target_y, container(), m_mouse_x, m_mouse_y))
m_mouse_hit = true;
}
}
//-------------------------------------------------
// ignore_mouse - set members to ignore mouse
// input
//-------------------------------------------------
void menu::ignore_mouse()
{
m_mouse_hit = false;
m_mouse_button = false;
m_mouse_x = -1.0f;
m_mouse_y = -1.0f;
}
//------------------------------------------------- //-------------------------------------------------
// handle_events - generically handle // handle_events - generically handle
// input events for a menu // input events for a menu

View File

@ -97,13 +97,6 @@ private:
virtual void draw(uint32_t flags); virtual void draw(uint32_t flags);
void draw_text_box(); void draw_text_box();
public:
// mouse handling
bool mouse_hit, mouse_button;
render_target *mouse_target;
int32_t mouse_target_x, mouse_target_y;
float mouse_x, mouse_y;
protected: protected:
using cleanup_callback = std::function<void(running_machine &)>; using cleanup_callback = std::function<void(running_machine &)>;
using bitmap_ptr = widgets_manager::bitmap_ptr; using bitmap_ptr = widgets_manager::bitmap_ptr;
@ -211,6 +204,22 @@ protected:
// configure the menu for custom rendering // configure the menu for custom rendering
virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2); virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2);
// map mouse to menu coordinates
void map_mouse();
// clear the mouse position
void ignore_mouse();
bool is_mouse_hit() const { return m_mouse_hit; } // is mouse pointer inside menu's render container?
float get_mouse_x() const { return m_mouse_x; } // mouse x location in menu coordinates
float get_mouse_y() const { return m_mouse_y; } // mouse y location in menu coordinates
// mouse hit test - checks whether mouse_x is in [x0, x1) and mouse_y is in [y0, y1)
bool mouse_in_rect(float x0, float y0, float x1, float y1) const
{
return m_mouse_hit && (m_mouse_x >= x0) && (m_mouse_x < x1) && (m_mouse_y >= y0) && (m_mouse_y < y1);
}
// overridable event handling // overridable event handling
virtual void handle_events(uint32_t flags, event &ev); virtual void handle_events(uint32_t flags, event &ev);
virtual void handle_keys(uint32_t flags, int &iptkey); virtual void handle_keys(uint32_t flags, int &iptkey);
@ -313,6 +322,11 @@ private:
int m_resetpos; // reset position int m_resetpos; // reset position
void *m_resetref; // reset reference void *m_resetref; // reset reference
bool m_mouse_hit;
bool m_mouse_button;
float m_mouse_x;
float m_mouse_y;
static std::mutex s_global_state_guard; static std::mutex s_global_state_guard;
static global_state_map s_global_states; static global_state_map s_global_states;
}; };

View File

@ -1559,12 +1559,12 @@ float menu_select_game::draw_left_panel(float x1, float y1, float x2, float y2)
rgb_t bgcolor = UI_TEXT_BG_COLOR; rgb_t bgcolor = UI_TEXT_BG_COLOR;
rgb_t fgcolor = UI_TEXT_COLOR; rgb_t fgcolor = UI_TEXT_COLOR;
if (mouse_hit && x1 <= mouse_x && x2 > mouse_x && y1 <= mouse_y && y1 + line_height_max > mouse_y) if (mouse_in_rect(x1, y1, x2, y1 + line_height_max))
{ {
bgcolor = UI_MOUSEOVER_BG_COLOR; bgcolor = UI_MOUSEOVER_BG_COLOR;
fgcolor = UI_MOUSEOVER_COLOR; fgcolor = UI_MOUSEOVER_COLOR;
hover = phover + filter; hover = phover + filter;
menu::highlight(x1, y1, x2, y1+ line_height_max, bgcolor); menu::highlight(x1, y1, x2, y1 + line_height_max, bgcolor);
} }
if (highlight == filter && get_focus() == focused_menu::left) if (highlight == filter && get_focus() == focused_menu::left)
@ -1626,7 +1626,7 @@ float menu_select_game::draw_left_panel(float x1, float y1, float x2, float y2)
ui().draw_outlined_box(container(), x1, y1, x2, y2, rgb_t(0xEF, 0x12, 0x47, 0x7B)); ui().draw_outlined_box(container(), x1, y1, x2, y2, rgb_t(0xEF, 0x12, 0x47, 0x7B));
if (mouse_hit && x1 <= mouse_x && x2 > mouse_x && y1 <= mouse_y && y2 > mouse_y) if (mouse_in_rect(x1, y1, x2, y2))
{ {
fgcolor = UI_MOUSEOVER_COLOR; fgcolor = UI_MOUSEOVER_COLOR;
hover = HOVER_LPANEL_ARROW; hover = HOVER_LPANEL_ARROW;
@ -1649,7 +1649,7 @@ float menu_select_game::draw_left_panel(float x1, float y1, float x2, float y2)
ui().draw_outlined_box(container(), x1, y1, x2, y2, rgb_t(0xEF, 0x12, 0x47, 0x7B)); ui().draw_outlined_box(container(), x1, y1, x2, y2, rgb_t(0xEF, 0x12, 0x47, 0x7B));
if (mouse_hit && x1 <= mouse_x && x2 > mouse_x && y1 <= mouse_y && y2 > mouse_y) if (mouse_in_rect(x1, y1, x2, y2))
{ {
fgcolor = UI_MOUSEOVER_COLOR; fgcolor = UI_MOUSEOVER_COLOR;
hover = HOVER_LPANEL_ARROW; hover = HOVER_LPANEL_ARROW;

View File

@ -469,28 +469,28 @@ void menu_select_launch::draw_common_arrow(float origx1, float origy1, float ori
auto gutter_width = lr_arrow_width * 1.3f; auto gutter_width = lr_arrow_width * 1.3f;
// set left-right arrows dimension // set left-right arrows dimension
float ar_x0 = 0.5f * (origx2 + origx1) + 0.5f * title_size + gutter_width - lr_arrow_width; float const ar_x0 = 0.5f * (origx2 + origx1) + 0.5f * title_size + gutter_width - lr_arrow_width;
float ar_y0 = origy1 + 0.1f * line_height; float const ar_y0 = origy1 + 0.1f * line_height;
float ar_x1 = 0.5f * (origx2 + origx1) + 0.5f * title_size + gutter_width; float const ar_x1 = 0.5f * (origx2 + origx1) + 0.5f * title_size + gutter_width;
float ar_y1 = origy1 + 0.9f * line_height; float const ar_y1 = origy1 + 0.9f * line_height;
float al_x0 = 0.5f * (origx2 + origx1) - 0.5f * title_size - gutter_width; float const al_x0 = 0.5f * (origx2 + origx1) - 0.5f * title_size - gutter_width;
float al_y0 = origy1 + 0.1f * line_height; float const al_y0 = origy1 + 0.1f * line_height;
float al_x1 = 0.5f * (origx2 + origx1) - 0.5f * title_size - gutter_width + lr_arrow_width; float const al_x1 = 0.5f * (origx2 + origx1) - 0.5f * title_size - gutter_width + lr_arrow_width;
float al_y1 = origy1 + 0.9f * line_height; float const al_y1 = origy1 + 0.9f * line_height;
rgb_t fgcolor_right, fgcolor_left; rgb_t fgcolor_right, fgcolor_left;
fgcolor_right = fgcolor_left = UI_TEXT_COLOR; fgcolor_right = fgcolor_left = UI_TEXT_COLOR;
// set hover // set hover
if (mouse_hit && ar_x0 <= mouse_x && ar_x1 > mouse_x && ar_y0 <= mouse_y && ar_y1 > mouse_y && current != dmax) if (mouse_in_rect(ar_x0, ar_y0, ar_x1, ar_y1) && current != dmax)
{ {
ui().draw_textured_box(container(), ar_x0 + 0.01f, ar_y0, ar_x1 - 0.01f, ar_y1, UI_MOUSEOVER_BG_COLOR, rgb_t(43, 43, 43), ui().draw_textured_box(container(), ar_x0 + 0.01f, ar_y0, ar_x1 - 0.01f, ar_y1, UI_MOUSEOVER_BG_COLOR, rgb_t(43, 43, 43),
hilight_main_texture(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXWRAP(1)); hilight_main_texture(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXWRAP(1));
hover = HOVER_UI_RIGHT; hover = HOVER_UI_RIGHT;
fgcolor_right = UI_MOUSEOVER_COLOR; fgcolor_right = UI_MOUSEOVER_COLOR;
} }
else if (mouse_hit && al_x0 <= mouse_x && al_x1 > mouse_x && al_y0 <= mouse_y && al_y1 > mouse_y && current != dmin) else if (mouse_in_rect(al_x0, al_y0, al_x1, al_y1) && current != dmin)
{ {
ui().draw_textured_box(container(), al_x0 + 0.01f, al_y0, al_x1 - 0.01f, al_y1, UI_MOUSEOVER_BG_COLOR, rgb_t(43, 43, 43), ui().draw_textured_box(container(), al_x0 + 0.01f, al_y0, al_x1 - 0.01f, al_y1, UI_MOUSEOVER_BG_COLOR, rgb_t(43, 43, 43),
hilight_main_texture(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXWRAP(1)); hilight_main_texture(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXWRAP(1));
@ -522,7 +522,7 @@ void menu_select_launch::draw_info_arrow(int ub, float origx1, float origx2, flo
rgb_t fgcolor = UI_TEXT_COLOR; rgb_t fgcolor = UI_TEXT_COLOR;
uint32_t orientation = (!ub) ? ROT0 : ROT0 ^ ORIENTATION_FLIP_Y; uint32_t orientation = (!ub) ? ROT0 : ROT0 ^ ORIENTATION_FLIP_Y;
if (mouse_hit && origx1 <= mouse_x && origx2 > mouse_x && oy1 <= mouse_y && oy1 + (line_height * text_size) > mouse_y) if (mouse_in_rect(origx1, oy1, origx2, oy1 + (line_height * text_size)))
{ {
ui().draw_textured_box(container(), origx1 + 0.01f, oy1, origx2 - 0.01f, oy1 + (line_height * text_size), UI_MOUSEOVER_BG_COLOR, ui().draw_textured_box(container(), origx1 + 0.01f, oy1, origx2 - 0.01f, oy1 + (line_height * text_size), UI_MOUSEOVER_BG_COLOR,
rgb_t(43, 43, 43), hilight_main_texture(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXWRAP(1)); rgb_t(43, 43, 43), hilight_main_texture(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXWRAP(1));
@ -531,7 +531,7 @@ void menu_select_launch::draw_info_arrow(int ub, float origx1, float origx2, flo
} }
draw_arrow(0.5f * (origx1 + origx2) - 0.5f * (ud_arrow_width * text_size), oy1 + 0.25f * (line_height * text_size), draw_arrow(0.5f * (origx1 + origx2) - 0.5f * (ud_arrow_width * text_size), oy1 + 0.25f * (line_height * text_size),
0.5f * (origx1 + origx2) + 0.5f * (ud_arrow_width * text_size), oy1 + 0.75f * (line_height * text_size), fgcolor, orientation); 0.5f * (origx1 + origx2) + 0.5f * (ud_arrow_width * text_size), oy1 + 0.75f * (line_height * text_size), fgcolor, orientation);
} }
@ -565,7 +565,7 @@ void menu_select_launch::draw_toolbar(float x1, float y1, float x2, float y2)
if (t_bitmap[z] && t_bitmap[z]->valid()) if (t_bitmap[z] && t_bitmap[z]->valid())
{ {
rgb_t color(0xEFEFEFEF); rgb_t color(0xEFEFEFEF);
if (mouse_hit && x1 <= mouse_x && x2 > mouse_x && y1 <= mouse_y && y2 > mouse_y) if (mouse_in_rect(x1, y1, x2, y2))
{ {
hover = HOVER_B_FAV + z; hover = HOVER_B_FAV + z;
color = rgb_t::white(); color = rgb_t::white();
@ -981,19 +981,19 @@ void menu_select_launch::handle_keys(uint32_t flags, int &iptkey)
void menu_select_launch::handle_events(uint32_t flags, event &ev) void menu_select_launch::handle_events(uint32_t flags, event &ev)
{ {
auto stop = false; bool stop = false;
ui_event local_menu_event; ui_event local_menu_event;
if (m_pressed) if (m_pressed)
{ {
bool pressed = mouse_pressed(); bool const pressed = mouse_pressed();
int32_t m_target_x, m_target_y; int32_t target_x, target_y;
bool m_button; bool button;
auto mouse_target = machine().ui_input().find_mouse(&m_target_x, &m_target_y, &m_button); render_target *const mouse_target = machine().ui_input().find_mouse(&target_x, &target_y, &button);
if (mouse_target && m_button && (hover == HOVER_ARROW_DOWN || hover == HOVER_ARROW_UP)) if (mouse_target && button && (hover == HOVER_ARROW_DOWN || hover == HOVER_ARROW_UP))
{ {
if (pressed) if (pressed)
machine().ui_input().push_mouse_down_event(mouse_target, m_target_x, m_target_y); machine().ui_input().push_mouse_down_event(mouse_target, target_x, target_y);
} }
else else
reset_pressed(); reset_pressed();
@ -1190,7 +1190,6 @@ void menu_select_launch::draw(uint32_t flags)
float line_height = ui().get_line_height(); float line_height = ui().get_line_height();
float ud_arrow_width = line_height * machine().render().ui_aspect(); float ud_arrow_width = line_height * machine().render().ui_aspect();
float gutter_width = 0.52f * ud_arrow_width; float gutter_width = 0.52f * ud_arrow_width;
mouse_x = -1, mouse_y = -1;
float right_panel_size = (ui_globals::panels_status == HIDE_BOTH || ui_globals::panels_status == HIDE_RIGHT_PANEL) ? 2.0f * UI_BOX_LR_BORDER : 0.3f; float right_panel_size = (ui_globals::panels_status == HIDE_BOTH || ui_globals::panels_status == HIDE_RIGHT_PANEL) ? 2.0f * UI_BOX_LR_BORDER : 0.3f;
float visible_width = 1.0f - 4.0f * UI_BOX_LR_BORDER; float visible_width = 1.0f - 4.0f * UI_BOX_LR_BORDER;
float primary_left = (1.0f - visible_width) * 0.5f; float primary_left = (1.0f - visible_width) * 0.5f;
@ -1204,15 +1203,10 @@ void menu_select_launch::draw(uint32_t flags)
float visible_extra_menu_height = get_customtop() + get_custombottom() + extra_height; float visible_extra_menu_height = get_customtop() + get_custombottom() + extra_height;
// locate mouse // locate mouse
mouse_hit = false; if (noinput)
mouse_button = false; ignore_mouse();
if (!noinput) else
{ map_mouse();
mouse_target = machine().ui_input().find_mouse(&mouse_target_x, &mouse_target_y, &mouse_button);
if (mouse_target)
if (mouse_target->map_point_container(mouse_target_x, mouse_target_y, container(), mouse_x, mouse_y))
mouse_hit = true;
}
// account for extra space at the top and bottom // account for extra space at the top and bottom
float visible_main_menu_height = 1.0f - 2.0f * UI_BOX_TB_BORDER - visible_extra_menu_height; float visible_main_menu_height = 1.0f - 2.0f * UI_BOX_TB_BORDER - visible_extra_menu_height;
@ -1277,7 +1271,7 @@ void menu_select_launch::draw(uint32_t flags)
float line_y1 = line_y + line_height; float line_y1 = line_y + line_height;
// set the hover if this is our item // set the hover if this is our item
if (mouse_hit && line_x0 <= mouse_x && line_x1 > mouse_x && line_y0 <= mouse_y && line_y1 > mouse_y && is_selectable(pitem)) if (mouse_in_rect(line_x0, line_y0, line_x1, line_y1) && is_selectable(pitem))
hover = itemnum; hover = itemnum;
// if we're selected, draw with a different background // if we're selected, draw with a different background
@ -1368,7 +1362,7 @@ void menu_select_launch::draw(uint32_t flags)
rgb_t fgcolor = UI_TEXT_COLOR; rgb_t fgcolor = UI_TEXT_COLOR;
rgb_t bgcolor = UI_TEXT_BG_COLOR; rgb_t bgcolor = UI_TEXT_BG_COLOR;
if (mouse_hit && line_x0 <= mouse_x && line_x1 > mouse_x && line_y0 <= mouse_y && line_y1 > mouse_y && is_selectable(pitem)) if (mouse_in_rect(line_x0, line_y0, line_x1, line_y1) && is_selectable(pitem))
hover = count; hover = count;
// if we're selected, draw with a different background // if we're selected, draw with a different background
@ -1449,7 +1443,7 @@ void menu_select_launch::draw_right_panel(float origx1, float origy1, float orig
ui().draw_outlined_box(container(), origx1, origy1, origx2, origy2, rgb_t(0xEF, 0x12, 0x47, 0x7B)); ui().draw_outlined_box(container(), origx1, origy1, origx2, origy2, rgb_t(0xEF, 0x12, 0x47, 0x7B));
rgb_t fgcolor(UI_TEXT_COLOR); rgb_t fgcolor(UI_TEXT_COLOR);
if (mouse_hit && origx1 <= mouse_x && x2 > mouse_x && origy1 <= mouse_y && origy2 > mouse_y) if (mouse_in_rect(origx1, origy1, x2, origy2))
{ {
fgcolor = UI_MOUSEOVER_COLOR; fgcolor = UI_MOUSEOVER_COLOR;
hover = HOVER_RPANEL_ARROW; hover = HOVER_RPANEL_ARROW;
@ -1478,7 +1472,7 @@ void menu_select_launch::draw_right_panel(float origx1, float origy1, float orig
float menu_select_launch::draw_right_box_title(float x1, float y1, float x2, float y2) float menu_select_launch::draw_right_box_title(float x1, float y1, float x2, float y2)
{ {
auto line_height = ui().get_line_height(); auto line_height = ui().get_line_height();
float midl = (x2 - x1) * 0.5f; float const midl = (x2 - x1) * 0.5f;
// add outlined box for options // add outlined box for options
ui().draw_outlined_box(container(), x1, y1, x2, y2, UI_BACKGROUND_COLOR); ui().draw_outlined_box(container(), x1, y1, x2, y2, UI_BACKGROUND_COLOR);
@ -1504,7 +1498,7 @@ float menu_select_launch::draw_right_box_title(float x1, float y1, float x2, flo
rgb_t bgcolor = UI_TEXT_BG_COLOR; rgb_t bgcolor = UI_TEXT_BG_COLOR;
rgb_t fgcolor = UI_TEXT_COLOR; rgb_t fgcolor = UI_TEXT_COLOR;
if (mouse_hit && x1 <= mouse_x && x1 + midl > mouse_x && y1 <= mouse_y && y1 + line_height > mouse_y) if (mouse_in_rect(x1, y1, x1 + midl, y1 + line_height))
{ {
if (ui_globals::rpanel != cells) if (ui_globals::rpanel != cells)
{ {

View File

@ -1139,7 +1139,7 @@ float menu_select_software::draw_left_panel(float x1, float y1, float x2, float
rgb_t bgcolor = UI_TEXT_BG_COLOR; rgb_t bgcolor = UI_TEXT_BG_COLOR;
rgb_t fgcolor = UI_TEXT_COLOR; rgb_t fgcolor = UI_TEXT_COLOR;
if (mouse_hit && x1 <= mouse_x && x2 > mouse_x && y1 <= mouse_y && y1 + line_height > mouse_y) if (mouse_in_rect(x1, y1, x2, y1 + line_height))
{ {
bgcolor = UI_MOUSEOVER_BG_COLOR; bgcolor = UI_MOUSEOVER_BG_COLOR;
fgcolor = UI_MOUSEOVER_COLOR; fgcolor = UI_MOUSEOVER_COLOR;
@ -1209,7 +1209,7 @@ float menu_select_software::draw_left_panel(float x1, float y1, float x2, float
ui().draw_outlined_box(container(), x1, y1, x2, y2, rgb_t(0xEF, 0x12, 0x47, 0x7B)); ui().draw_outlined_box(container(), x1, y1, x2, y2, rgb_t(0xEF, 0x12, 0x47, 0x7B));
if (mouse_hit && x1 <= mouse_x && x2 > mouse_x && y1 <= mouse_y && y2 > mouse_y) if (mouse_in_rect(x1, y1, x2, y2))
{ {
fgcolor = UI_MOUSEOVER_COLOR; fgcolor = UI_MOUSEOVER_COLOR;
hover = HOVER_LPANEL_ARROW; hover = HOVER_LPANEL_ARROW;
@ -1232,7 +1232,7 @@ float menu_select_software::draw_left_panel(float x1, float y1, float x2, float
ui().draw_outlined_box(container(), x1, y1, x2, y2, rgb_t(0xEF, 0x12, 0x47, 0x7B)); ui().draw_outlined_box(container(), x1, y1, x2, y2, rgb_t(0xEF, 0x12, 0x47, 0x7B));
if (mouse_hit && x1 <= mouse_x && x2 > mouse_x && y1 <= mouse_y && y2 > mouse_y) if (mouse_in_rect(x1, y1, x2, y2))
{ {
fgcolor = UI_MOUSEOVER_COLOR; fgcolor = UI_MOUSEOVER_COLOR;
hover = HOVER_LPANEL_ARROW; hover = HOVER_LPANEL_ARROW;