diff options
Diffstat (limited to 'src/frontend/mame/ui/selmenu.cpp')
-rw-r--r-- | src/frontend/mame/ui/selmenu.cpp | 360 |
1 files changed, 312 insertions, 48 deletions
diff --git a/src/frontend/mame/ui/selmenu.cpp b/src/frontend/mame/ui/selmenu.cpp index 123be37cd1b..64b4855c967 100644 --- a/src/frontend/mame/ui/selmenu.cpp +++ b/src/frontend/mame/ui/selmenu.cpp @@ -13,6 +13,7 @@ #include "ui/selmenu.h" #include "ui/icorender.h" +#include "ui/inifile.h" #include "ui/utils.h" // these hold static bitmap images @@ -26,6 +27,7 @@ #include "drivenum.h" #include "emuopts.h" #include "rendutil.h" +#include "softlist.h" #include "uiinput.h" #include <algorithm> @@ -189,75 +191,264 @@ menu_select_launch::menu_select_launch(mame_ui_manager &mui, render_container &c //------------------------------------------------- -// draw right box title +// perform our special rendering //------------------------------------------------- -float menu_select_launch::draw_right_box_title(float x1, float y1, float x2, float y2) +void menu_select_launch::custom_render(void *selectedref, float top, float bottom, float origx1, float origy1, float origx2, float origy2) { - auto line_height = ui().get_line_height(); - float midl = (x2 - x1) * 0.5f; + std::string tempbuf[5]; - // add outlined box for options - ui().draw_outlined_box(container(), x1, y1, x2, y2, UI_BACKGROUND_COLOR); + // determine the text for the header + make_topbox_text(tempbuf[0], tempbuf[1], tempbuf[2]); - // add separator line - container().add_line(x1 + midl, y1, x1 + midl, y1 + line_height, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); - - std::string buffer[RP_LAST + 1]; - buffer[RP_IMAGES] = _("Images"); - buffer[RP_INFOS] = _("Infos"); + // get the size of the text + float maxwidth = origx2 - origx1; + for (int line = 0; line < 3; ++line) + { + float width; + ui().draw_text_full(container(), tempbuf[line].c_str(), 0.0f, 0.0f, 1.0f, ui::text_layout::CENTER, ui::text_layout::NEVER, + mame_ui_manager::NONE, rgb_t::white, rgb_t::black, &width, nullptr); + width += 2 * UI_BOX_LR_BORDER; + maxwidth = (std::max)(width, maxwidth); + } - // check size float text_size = 1.0f; - for (auto & elem : buffer) + if (maxwidth > origx2 - origx1) { - auto textlen = ui().get_string_width(elem.c_str()) + 0.01f; - float tmp_size = (textlen > midl) ? (midl / textlen) : 1.0f; - text_size = MIN(text_size, tmp_size); + text_size = (origx2 - origx1) / maxwidth; + maxwidth = origx2 - origx1; } - for (int cells = RP_FIRST; cells <= RP_LAST; ++cells) + // compute our bounds + float tbarspace = ui().get_line_height(); + float x1 = 0.5f - 0.5f * maxwidth; + float x2 = x1 + maxwidth; + float y1 = origy1 - top; + float y2 = origy1 - 3.0f * UI_BOX_TB_BORDER - tbarspace; + + // draw a box + ui().draw_outlined_box(container(), x1, y1, x2, y2, UI_BACKGROUND_COLOR); + + // take off the borders + x1 += UI_BOX_LR_BORDER; + x2 -= UI_BOX_LR_BORDER; + y1 += UI_BOX_TB_BORDER; + + // draw the text within it + for (int line = 0; line < 3; ++line) { - rgb_t bgcolor = UI_TEXT_BG_COLOR; - rgb_t fgcolor = UI_TEXT_COLOR; + ui().draw_text_full(container(), tempbuf[line].c_str(), x1, y1, x2 - x1, ui::text_layout::CENTER, ui::text_layout::NEVER, + mame_ui_manager::NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, nullptr, nullptr, text_size); + y1 += ui().get_line_height(); + } - if (mouse_hit && x1 <= mouse_x && x1 + midl > mouse_x && y1 <= mouse_y && y1 + line_height > mouse_y) + // determine the text to render below + ui_software_info const *swinfo; + game_driver const *driver; + get_selection(swinfo, driver); + + bool isstar = false; + rgb_t color = UI_BACKGROUND_COLOR; + if (swinfo && ((swinfo->startempty != 1) || !driver)) + { + isstar = mame_machine_manager::instance()->favorite().isgame_favorite(*swinfo); + + // first line is long name or system + tempbuf[0] = make_software_description(*swinfo); + + // next line is year, publisher + tempbuf[1] = string_format(_("%1$s, %2$-.100s"), swinfo->year, swinfo->publisher); + + // next line is parent/clone + if (!swinfo->parentname.empty()) + tempbuf[2] = string_format(_("Software is clone of: %1$-.100s"), !swinfo->parentlongname.empty() ? swinfo->parentlongname : swinfo->parentname); + else + tempbuf[2] = _("Software is parent"); + + // next line is supported status + if (swinfo->supported == SOFTWARE_SUPPORTED_NO) { - if (ui_globals::rpanel != cells) - { - bgcolor = UI_MOUSEOVER_BG_COLOR; - fgcolor = UI_MOUSEOVER_COLOR; - hover = HOVER_RP_FIRST + cells; - } + tempbuf[3] = _("Supported: No"); + color = UI_RED_COLOR; + } + else if (swinfo->supported == SOFTWARE_SUPPORTED_PARTIAL) + { + tempbuf[3] = _("Supported: Partial"); + color = UI_YELLOW_COLOR; + } + else + { + tempbuf[3] = _("Supported: Yes"); + color = UI_GREEN_COLOR; } - if (ui_globals::rpanel != cells) + // last line is romset name + tempbuf[4] = string_format(_("romset: %1$-.100s"), swinfo->shortname); + } + else if (driver) + { + isstar = mame_machine_manager::instance()->favorite().isgame_favorite(driver); + + // first line is game description/game name + tempbuf[0] = make_driver_description(*driver); + + // next line is year, manufacturer + tempbuf[1] = string_format(_("%1$s, %2$-.100s"), driver->year, driver->manufacturer); + + // next line is clone/parent status + int cloneof = driver_list::non_bios_clone(*driver); + + if (cloneof != -1) + tempbuf[2] = string_format(_("Driver is clone of: %1$-.100s"), driver_list::driver(cloneof).description); + else + tempbuf[2] = _("Driver is parent"); + + // next line is overall driver status + if (driver->flags & MACHINE_NOT_WORKING) + tempbuf[3] = _("Overall: NOT WORKING"); + else if (driver->flags & MACHINE_UNEMULATED_PROTECTION) + tempbuf[3] = _("Overall: Unemulated Protection"); + else + tempbuf[3] = _("Overall: Working"); + + // next line is graphics, sound status + if (driver->flags & (MACHINE_IMPERFECT_GRAPHICS | MACHINE_WRONG_COLORS | MACHINE_IMPERFECT_COLORS)) + tempbuf[4] = _("Graphics: Imperfect, "); + else + tempbuf[4] = _("Graphics: OK, "); + + if (driver->flags & MACHINE_NO_SOUND) + tempbuf[4].append(_("Sound: Unimplemented")); + else if (driver->flags & MACHINE_IMPERFECT_SOUND) + tempbuf[4].append(_("Sound: Imperfect")); + else + tempbuf[4].append(_("Sound: OK")); + + color = UI_GREEN_COLOR; + + if ((driver->flags & (MACHINE_IMPERFECT_GRAPHICS | MACHINE_WRONG_COLORS | MACHINE_IMPERFECT_COLORS + | MACHINE_NO_SOUND | MACHINE_IMPERFECT_SOUND)) != 0) + color = UI_YELLOW_COLOR; + + if ((driver->flags & (MACHINE_NOT_WORKING | MACHINE_UNEMULATED_PROTECTION)) != 0) + color = UI_RED_COLOR; + } + else + { + std::string copyright(emulator_info::get_copyright()); + size_t found = copyright.find("\n"); + + tempbuf[0].clear(); + tempbuf[1] = string_format(_("%1$s %2$s"), emulator_info::get_appname(), build_version); + tempbuf[2] = copyright.substr(0, found); + tempbuf[3] = copyright.substr(found + 1); + tempbuf[4].clear(); + } + + // compute our bounds + x1 = 0.5f - 0.5f * maxwidth; + x2 = x1 + maxwidth; + y1 = y2; + y2 = origy1 - UI_BOX_TB_BORDER; + + // draw toolbar + draw_toolbar(x1, y1, x2, y2); + + // get the size of the text + maxwidth = origx2 - origx1; + + for (auto &elem : tempbuf) + { + float width; + ui().draw_text_full(container(), elem.c_str(), 0.0f, 0.0f, 1.0f, ui::text_layout::CENTER, ui::text_layout::NEVER, + mame_ui_manager::NONE, rgb_t::white, rgb_t::black, &width, nullptr); + width += 2 * UI_BOX_LR_BORDER; + maxwidth = (std::max)(maxwidth, width); + } + + if (maxwidth > origx2 - origx1) + { + text_size = (origx2 - origx1) / maxwidth; + maxwidth = origx2 - origx1; + } + + // compute our bounds + x1 = 0.5f - 0.5f * maxwidth; + x2 = x1 + maxwidth; + y1 = origy2 + UI_BOX_TB_BORDER; + y2 = origy2 + bottom; + + // draw a box + ui().draw_outlined_box(container(), x1, y1, x2, y2, color); + + // take off the borders + x1 += UI_BOX_LR_BORDER; + x2 -= UI_BOX_LR_BORDER; + y1 += UI_BOX_TB_BORDER; + + // is favorite? draw the star + if (isstar) + draw_star(x1, y1); + + // draw all lines + for (auto &elem : tempbuf) + { + ui().draw_text_full(container(), elem.c_str(), x1, y1, x2 - x1, ui::text_layout::CENTER, ui::text_layout::NEVER, + mame_ui_manager::NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, nullptr, nullptr, text_size); + y1 += ui().get_line_height(); + } +} + + +void menu_select_launch::inkey_navigation() +{ + switch (get_focus()) + { + case focused_menu::main: + if (selected <= visible_items) { - container().add_line(x1, y1 + line_height, x1 + midl, y1 + line_height, UI_LINE_WIDTH, - UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); - if (fgcolor != UI_MOUSEOVER_COLOR) - fgcolor = UI_CLONE_COLOR; + m_prev_selected = item[selected].ref; + selected = visible_items + 1; } + else + { + if (ui_globals::panels_status != HIDE_LEFT_PANEL) + set_focus(focused_menu::left); - if (m_focus == focused_menu::righttop && ui_globals::rpanel == cells) + else if (ui_globals::panels_status == HIDE_BOTH) + { + for (int x = 0; x < item.size(); ++x) + if (item[x].ref == m_prev_selected) + selected = x; + } + else + { + set_focus(focused_menu::righttop); + } + } + break; + + case focused_menu::left: + if (ui_globals::panels_status != HIDE_RIGHT_PANEL) { - fgcolor = rgb_t(0xff, 0xff, 0x00); - bgcolor = rgb_t(0xff, 0xff, 0xff); - ui().draw_textured_box(container(), x1 + UI_LINE_WIDTH, y1 + UI_LINE_WIDTH, x1 + midl - UI_LINE_WIDTH, y1 + line_height, - bgcolor, rgb_t(43, 43, 43), hilight_main_texture(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXWRAP(TRUE)); + set_focus(focused_menu::righttop); } - else if (bgcolor == UI_MOUSEOVER_BG_COLOR) + else { - container().add_rect(x1 + UI_LINE_WIDTH, y1 + UI_LINE_WIDTH, x1 + midl - UI_LINE_WIDTH, y1 + line_height, - bgcolor, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXWRAP(TRUE)); + set_focus(focused_menu::main); + select_prev(); } + break; - ui().draw_text_full(container(), buffer[cells].c_str(), x1 + UI_LINE_WIDTH, y1, midl - UI_LINE_WIDTH, - ui::text_layout::CENTER, ui::text_layout::NEVER, mame_ui_manager::NORMAL, fgcolor, bgcolor, nullptr, nullptr, text_size); - x1 += midl; - } + case focused_menu::righttop: + set_focus(focused_menu::rightbottom); + break; - return (y1 + line_height + UI_LINE_WIDTH); + case focused_menu::rightbottom: + set_focus(focused_menu::main); + select_prev(); + break; + } } @@ -340,7 +531,7 @@ void menu_select_launch::draw_info_arrow(int ub, float origx1, float origx2, flo // draw toolbar //------------------------------------------------- -void menu_select_launch::draw_toolbar(float x1, float y1, float x2, float y2, bool software) +void menu_select_launch::draw_toolbar(float x1, float y1, float x2, float y2) { // draw a box ui().draw_outlined_box(container(), x1, y1, x2, y2, rgb_t(0xEF, 0x12, 0x47, 0x7B)); @@ -351,8 +542,8 @@ void menu_select_launch::draw_toolbar(float x1, float y1, float x2, float y2, bo y1 += UI_BOX_TB_BORDER; y2 -= UI_BOX_TB_BORDER; - texture_ptr_vector const &t_texture = software ? m_cache->sw_toolbar_texture() : m_cache->toolbar_texture(); - bitmap_ptr_vector const &t_bitmap = software ? m_cache->sw_toolbar_bitmap() : m_cache->toolbar_bitmap(); + texture_ptr_vector const &t_texture(m_is_swlist ? m_cache->sw_toolbar_texture() : m_cache->toolbar_texture()); + bitmap_ptr_vector const &t_bitmap(m_is_swlist ? m_cache->sw_toolbar_bitmap() : m_cache->toolbar_bitmap()); auto const num_valid(std::count_if(std::begin(t_bitmap), std::end(t_bitmap), [](bitmap_ptr const &e) { return e && e->valid(); })); @@ -1273,6 +1464,79 @@ void menu_select_launch::draw_right_panel(float origx1, float origy1, float orig //------------------------------------------------- +// draw right box title +//------------------------------------------------- + +float menu_select_launch::draw_right_box_title(float x1, float y1, float x2, float y2) +{ + auto line_height = ui().get_line_height(); + float midl = (x2 - x1) * 0.5f; + + // add outlined box for options + ui().draw_outlined_box(container(), x1, y1, x2, y2, UI_BACKGROUND_COLOR); + + // add separator line + container().add_line(x1 + midl, y1, x1 + midl, y1 + line_height, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); + + std::string buffer[RP_LAST + 1]; + buffer[RP_IMAGES] = _("Images"); + buffer[RP_INFOS] = _("Infos"); + + // check size + float text_size = 1.0f; + for (auto & elem : buffer) + { + auto textlen = ui().get_string_width(elem.c_str()) + 0.01f; + float tmp_size = (textlen > midl) ? (midl / textlen) : 1.0f; + text_size = MIN(text_size, tmp_size); + } + + for (int cells = RP_FIRST; cells <= RP_LAST; ++cells) + { + rgb_t bgcolor = UI_TEXT_BG_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 (ui_globals::rpanel != cells) + { + bgcolor = UI_MOUSEOVER_BG_COLOR; + fgcolor = UI_MOUSEOVER_COLOR; + hover = HOVER_RP_FIRST + cells; + } + } + + if (ui_globals::rpanel != cells) + { + container().add_line(x1, y1 + line_height, x1 + midl, y1 + line_height, UI_LINE_WIDTH, + UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); + if (fgcolor != UI_MOUSEOVER_COLOR) + fgcolor = UI_CLONE_COLOR; + } + + if (m_focus == focused_menu::righttop && ui_globals::rpanel == cells) + { + fgcolor = rgb_t(0xff, 0xff, 0x00); + bgcolor = rgb_t(0xff, 0xff, 0xff); + ui().draw_textured_box(container(), x1 + UI_LINE_WIDTH, y1 + UI_LINE_WIDTH, x1 + midl - UI_LINE_WIDTH, y1 + line_height, + bgcolor, rgb_t(43, 43, 43), hilight_main_texture(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXWRAP(TRUE)); + } + else if (bgcolor == UI_MOUSEOVER_BG_COLOR) + { + container().add_rect(x1 + UI_LINE_WIDTH, y1 + UI_LINE_WIDTH, x1 + midl - UI_LINE_WIDTH, y1 + line_height, + bgcolor, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXWRAP(TRUE)); + } + + ui().draw_text_full(container(), buffer[cells].c_str(), x1 + UI_LINE_WIDTH, y1, midl - UI_LINE_WIDTH, + ui::text_layout::CENTER, ui::text_layout::NEVER, mame_ui_manager::NORMAL, fgcolor, bgcolor, nullptr, nullptr, text_size); + x1 += midl; + } + + return (y1 + line_height + UI_LINE_WIDTH); +} + + +//------------------------------------------------- // perform our special rendering //------------------------------------------------- |