UI menu refactoring: [Vas Crabb]

* Eliminate some function statics
* Move another launch menu specific member out of base class
* Move some common code from selgame and selsoft into selmenu
* Tighten up const and casts
This commit is contained in:
Vas Crabb 2016-07-14 23:15:47 +10:00
parent bb6369ab0d
commit 46e374e7bf
8 changed files with 324 additions and 488 deletions

View File

@ -100,8 +100,6 @@ private:
void draw_text_box();
public:
void *m_prev_selected;
// mouse handling
bool mouse_hit, mouse_button;
render_target *mouse_target;

View File

@ -174,7 +174,7 @@ menu_select_game::~menu_select_game()
void menu_select_game::handle()
{
if (m_prev_selected == nullptr)
if (!m_prev_selected)
m_prev_selected = item[0].ref;
bool check_filter = false;
@ -231,11 +231,19 @@ void menu_select_game::handle()
{
// handle IPT_CUSTOM (mouse right click)
if (!isfavorite())
menu::stack_push<menu_machine_configure>(ui(), container(), (const game_driver *)m_prev_selected, menu_event->mouse.x0, menu_event->mouse.y0);
{
menu::stack_push<menu_machine_configure>(
ui(), container(),
reinterpret_cast<const game_driver *>(m_prev_selected),
menu_event->mouse.x0, menu_event->mouse.y0);
}
else
{
ui_software_info *sw = (ui_software_info *)m_prev_selected;
menu::stack_push<menu_machine_configure>(ui(), container(), (const game_driver *)sw->driver, menu_event->mouse.x0, menu_event->mouse.y0);
ui_software_info *sw = reinterpret_cast<ui_software_info *>(m_prev_selected);
menu::stack_push<menu_machine_configure>(
ui(), container(),
(const game_driver *)sw->driver,
menu_event->mouse.x0, menu_event->mouse.y0);
}
}
else if (menu_event->iptkey == IPT_UI_LEFT)
@ -746,7 +754,6 @@ void menu_select_game::build_available_list()
void menu_select_game::custom_render(void *selectedref, float top, float bottom, float origx1, float origy1, float origx2, float origy2)
{
const game_driver *driver = nullptr;
ui_software_info *swinfo = nullptr;
float width, maxwidth = origx2 - origx1;
std::string tempbuf[5];
@ -828,16 +835,19 @@ void menu_select_game::custom_render(void *selectedref, float top, float bottom,
}
// determine the text to render below
const game_driver *driver = nullptr;
if (!isfavorite())
driver = ((FPTR)selectedref > skip_main_items) ? (const game_driver *)selectedref : ((m_prev_selected != nullptr) ? (const game_driver *)m_prev_selected : nullptr);
{
driver = (FPTR(selectedref) > skip_main_items) ? (const game_driver *)selectedref : reinterpret_cast<const game_driver *>(m_prev_selected);
}
else
{
swinfo = ((FPTR)selectedref > skip_main_items) ? (ui_software_info *)selectedref : ((m_prev_selected != nullptr) ? (ui_software_info *)m_prev_selected : nullptr);
swinfo = (FPTR(selectedref) > skip_main_items) ? (ui_software_info *)selectedref : reinterpret_cast<ui_software_info *>(m_prev_selected);
if (swinfo != nullptr && swinfo->startempty == 1)
driver = swinfo->driver;
}
if (driver != nullptr)
if (driver)
{
isstar = mame_machine_manager::instance()->favorite().isgame_favorite(driver);
@ -885,7 +895,6 @@ void menu_select_game::custom_render(void *selectedref, float top, float bottom,
if ((driver->flags & (MACHINE_NOT_WORKING | MACHINE_UNEMULATED_PROTECTION)) != 0)
color = UI_RED_COLOR;
}
else if (swinfo != nullptr)
{
isstar = mame_machine_manager::instance()->favorite().isgame_favorite(*swinfo);
@ -1021,10 +1030,10 @@ void menu_select_game::inkey_select(const event *menu_event)
menu::stack_push<menu_game_options>(ui(), container());
// special case for configure machine
else if ((FPTR)driver == CONF_MACHINE)
else if (FPTR(driver) == CONF_MACHINE)
{
if (m_prev_selected != nullptr)
menu::stack_push<menu_machine_configure>(ui(), container(), (const game_driver *)m_prev_selected);
if (m_prev_selected)
menu::stack_push<menu_machine_configure>(ui(), container(), reinterpret_cast<const game_driver *>(m_prev_selected));
return;
}
@ -1086,22 +1095,24 @@ void menu_select_game::inkey_select_favorite(const event *menu_event)
ui_software_info *ui_swinfo = (ui_software_info *)menu_event->itemref;
ui_options &mopt = ui().options();
// special case for configure options
if ((FPTR)ui_swinfo == CONF_OPTS)
{
// special case for configure options
menu::stack_push<menu_game_options>(ui(), container());
// special case for configure machine
}
else if ((FPTR)ui_swinfo == CONF_MACHINE)
{
if (m_prev_selected != nullptr)
// special case for configure machine
if (m_prev_selected)
{
ui_software_info *swinfo = (ui_software_info *)m_prev_selected;
ui_software_info *swinfo = reinterpret_cast<ui_software_info *>(m_prev_selected);
menu::stack_push<menu_machine_configure>(ui(), container(), (const game_driver *)swinfo->driver);
}
return;
}
// special case for configure plugins
else if ((FPTR)ui_swinfo == CONF_PLUGINS)
{
// special case for configure plugins
menu::stack_push<menu_plugins_configure>(ui(), container());
}
else if (ui_swinfo->startempty == 1)
@ -1112,9 +1123,9 @@ void menu_select_game::inkey_select_favorite(const event *menu_event)
media_auditor auditor(enumerator);
media_auditor::summary summary = auditor.audit_media(AUDIT_VALIDATE_FAST);
// if everything looks good, schedule the new driver
if (summary == media_auditor::CORRECT || summary == media_auditor::BEST_AVAILABLE || summary == media_auditor::NONE_NEEDED)
{
// if everything looks good, schedule the new driver
s_bios biosname;
if (!mopt.skip_bios_menu() && has_multiple_bios(ui_swinfo->driver, biosname))
menu::stack_push<bios_selection>(ui(), container(), biosname, (void *)ui_swinfo->driver, false, false);
@ -1129,10 +1140,9 @@ void menu_select_game::inkey_select_favorite(const event *menu_event)
stack_reset();
}
}
// otherwise, display an error
else
{
// otherwise, display an error
reset(reset_options::REMEMBER_REF);
m_ui_error = true;
}
@ -1269,7 +1279,7 @@ void menu_select_game::inkey_navigation()
else
{
set_focus(focused_menu::main);
if (m_prev_selected == nullptr)
if (!m_prev_selected)
{
selected = 0;
return;
@ -1287,7 +1297,7 @@ void menu_select_game::inkey_navigation()
case focused_menu::rightbottom:
set_focus(focused_menu::main);
if (m_prev_selected == nullptr)
if (!m_prev_selected)
{
selected = 0;
return;
@ -1954,7 +1964,7 @@ float menu_select_game::draw_left_panel(float x1, float y1, float x2, float y2)
// draw infos
//-------------------------------------------------
void menu_select_game::infos_render(void *selectedref, float origx1, float origy1, float origx2, float origy2)
void menu_select_game::infos_render(float origx1, float origy1, float origx2, float origy2)
{
float line_height = ui().get_line_height();
static std::string buffer;
@ -1971,7 +1981,7 @@ void menu_select_game::infos_render(void *selectedref, float origx1, float origy
if (is_favorites)
{
soft = ((FPTR)selectedref > skip_main_items) ? (ui_software_info *)selectedref : ((m_prev_selected != nullptr) ? (ui_software_info *)m_prev_selected : nullptr);
soft = reinterpret_cast<ui_software_info *>(get_selection_ptr());
if (soft && soft->startempty == 1)
{
driver = soft->driver;
@ -1982,7 +1992,7 @@ void menu_select_game::infos_render(void *selectedref, float origx1, float origy
}
else
{
driver = ((FPTR)selectedref > skip_main_items) ? (const game_driver *)selectedref : ((m_prev_selected != nullptr) ? (const game_driver *)m_prev_selected : nullptr);
driver = reinterpret_cast<const game_driver *>(get_selection_ptr());
oldsoft = nullptr;
}
@ -2272,226 +2282,22 @@ void menu_select_game::infos_render(void *selectedref, float origx1, float origy
}
}
//-------------------------------------------------
// draw right panel
// get selected software and/or driver
//-------------------------------------------------
void menu_select_game::draw_right_panel(void *selectedref, float origx1, float origy1, float origx2, float origy2)
void menu_select_game::get_selection(ui_software_info const *&software, game_driver const *&driver) const
{
rgb_t fgcolor = UI_TEXT_COLOR;
bool hide = (ui_globals::panels_status == HIDE_RIGHT_PANEL || ui_globals::panels_status == HIDE_BOTH);
float x2 = (hide) ? origx2 : origx1 + 2.0f * UI_BOX_LR_BORDER;
float space = x2 - origx1;
float lr_arrow_width = 0.4f * space * machine().render().ui_aspect();
// set left-right arrows dimension
float ar_x0 = 0.5f * (x2 + origx1) - 0.5f * lr_arrow_width;
float ar_y0 = 0.5f * (origy2 + origy1) + 0.1f * space;
float ar_x1 = ar_x0 + lr_arrow_width;
float ar_y1 = 0.5f * (origy2 + origy1) + 0.9f * space;
ui().draw_outlined_box(container(), origx1, origy1, origx2, origy2, rgb_t(0xEF, 0x12, 0x47, 0x7B));
if (mouse_hit && origx1 <= mouse_x && x2 > mouse_x && origy1 <= mouse_y && origy2 > mouse_y)
if (item[0].flags & FLAG_UI_FAVORITE) // TODO: work out why this doesn't use isfavorite()
{
fgcolor = UI_MOUSEOVER_COLOR;
hover = HOVER_RPANEL_ARROW;
}
if (hide)
{
draw_arrow(ar_x0, ar_y0, ar_x1, ar_y1, fgcolor, ROT90 ^ ORIENTATION_FLIP_X);
return;
}
draw_arrow(ar_x0, ar_y0, ar_x1, ar_y1, fgcolor, ROT90);
origx1 = x2;
origy1 = draw_right_box_title(origx1, origy1, origx2, origy2);
if (ui_globals::rpanel == RP_IMAGES)
arts_render(selectedref, origx1, origy1, origx2, origy2);
else
infos_render(selectedref, origx1, origy1, origx2, origy2);
}
//-------------------------------------------------
// perform our special rendering
//-------------------------------------------------
void menu_select_game::arts_render(void *selectedref, float origx1, float origy1, float origx2, float origy2)
{
bool is_favorites = ((item[0].flags & FLAG_UI_FAVORITE) != 0);
static ui_software_info *oldsoft = nullptr;
static const game_driver *olddriver = nullptr;
const game_driver *driver = nullptr;
ui_software_info *soft = nullptr;
if (is_favorites)
{
soft = ((FPTR)selectedref > skip_main_items) ? (ui_software_info *)selectedref : ((m_prev_selected != nullptr) ? (ui_software_info *)m_prev_selected : nullptr);
if (soft && soft->startempty == 1)
{
driver = soft->driver;
oldsoft = nullptr;
}
else
olddriver = nullptr;
software = reinterpret_cast<ui_software_info const *>(get_selection_ptr());
driver = software ? software->driver : nullptr;
}
else
{
driver = ((FPTR)selectedref > skip_main_items) ? (const game_driver *)selectedref : ((m_prev_selected != nullptr) ? (const game_driver *)m_prev_selected : nullptr);
oldsoft = nullptr;
}
if (driver != nullptr)
{
if (ui_globals::default_image)
((driver->flags & MACHINE_TYPE_ARCADE) == 0) ? ui_globals::curimage_view = CABINETS_VIEW : ui_globals::curimage_view = SNAPSHOT_VIEW;
std::string searchstr;
searchstr = arts_render_common(origx1, origy1, origx2, origy2);
// loads the image if necessary
if (driver != olddriver || !snapx_valid() || ui_globals::switch_image)
{
emu_file snapfile(searchstr.c_str(), OPEN_FLAG_READ);
snapfile.set_restrict_to_mediapath(true);
bitmap_argb32 *tmp_bitmap;
tmp_bitmap = auto_alloc(machine(), bitmap_argb32);
// try to load snapshot first from saved "0000.png" file
std::string fullname(driver->name);
render_load_png(*tmp_bitmap, snapfile, fullname.c_str(), "0000.png");
if (!tmp_bitmap->valid())
render_load_jpeg(*tmp_bitmap, snapfile, fullname.c_str(), "0000.jpg");
// if fail, attemp to load from standard file
if (!tmp_bitmap->valid())
{
fullname.assign(driver->name).append(".png");
render_load_png(*tmp_bitmap, snapfile, nullptr, fullname.c_str());
if (!tmp_bitmap->valid())
{
fullname.assign(driver->name).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, nullptr, fullname.c_str());
}
}
// if fail again, attemp to load from parent file
if (!tmp_bitmap->valid())
{
// set clone status
bool cloneof = strcmp(driver->parent, "0");
if (cloneof)
{
int cx = driver_list::find(driver->parent);
if (cx != -1 && ((driver_list::driver(cx).flags & MACHINE_IS_BIOS_ROOT) != 0))
cloneof = false;
}
if (cloneof)
{
fullname.assign(driver->parent).append(".png");
render_load_png(*tmp_bitmap, snapfile, nullptr, fullname.c_str());
if (!tmp_bitmap->valid())
{
fullname.assign(driver->parent).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, nullptr, fullname.c_str());
}
}
}
olddriver = driver;
ui_globals::switch_image = false;
arts_render_images(tmp_bitmap, origx1, origy1, origx2, origy2);
auto_free(machine(), tmp_bitmap);
}
// if the image is available, loaded and valid, display it
draw_snapx(origx1, origy1, origx2, origy2);
}
else if (soft != nullptr)
{
std::string fullname, pathname;
if (ui_globals::default_image)
(soft->startempty == 0) ? ui_globals::curimage_view = SNAPSHOT_VIEW : ui_globals::curimage_view = CABINETS_VIEW;
// arts title and searchpath
std::string searchstr;
searchstr = arts_render_common(origx1, origy1, origx2, origy2);
// loads the image if necessary
if (soft != oldsoft || !snapx_valid() || ui_globals::switch_image)
{
emu_file snapfile(searchstr.c_str(), OPEN_FLAG_READ);
bitmap_argb32 *tmp_bitmap;
tmp_bitmap = auto_alloc(machine(), bitmap_argb32);
if (soft->startempty == 1)
{
// Load driver snapshot
fullname.assign(soft->driver->name).append(".png");
render_load_png(*tmp_bitmap, snapfile, nullptr, fullname.c_str());
if (!tmp_bitmap->valid())
{
fullname.assign(soft->driver->name).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, nullptr, fullname.c_str());
}
}
else if (ui_globals::curimage_view == TITLES_VIEW)
{
// First attempt from name list
pathname.assign(soft->listname).append("_titles");
fullname.assign(soft->shortname).append(".png");
render_load_png(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
if (!tmp_bitmap->valid())
{
fullname.assign(soft->shortname).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
}
}
else
{
// First attempt from name list
pathname = soft->listname;
fullname.assign(soft->shortname).append(".png");
render_load_png(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
if (!tmp_bitmap->valid())
{
fullname.assign(soft->shortname).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
}
if (!tmp_bitmap->valid())
{
// Second attempt from driver name + part name
pathname.assign(soft->driver->name).append(soft->part);
fullname.assign(soft->shortname).append(".png");
render_load_png(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
if (!tmp_bitmap->valid())
{
fullname.assign(soft->shortname).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
}
}
}
oldsoft = soft;
ui_globals::switch_image = false;
arts_render_images(tmp_bitmap, origx1, origy1, origx2, origy2);
auto_free(machine(), tmp_bitmap);
}
// if the image is available, loaded and valid, display it
draw_snapx(origx1, origy1, origx2, origy2);
software = nullptr;
driver = reinterpret_cast<game_driver const *>(get_selection_ptr());
}
}

View File

@ -56,8 +56,8 @@ private:
// draw left panel
virtual float draw_left_panel(float x1, float y1, float x2, float y2) override;
// draw right panel
virtual void draw_right_panel(void *selectedref, float origx1, float origy1, float origx2, float origy2) override;
// get selected software and/or driver
virtual void get_selection(ui_software_info const *&software, game_driver const *&driver) const override;
// internal methods
void build_custom();
@ -71,11 +71,16 @@ private:
bool load_available_machines();
void load_custom_filters();
void *get_selection_ptr() const
{
void *const selected_ref(get_selection_ref());
return (FPTR(selected_ref) > skip_main_items) ? selected_ref : m_prev_selected;
}
// General info
void general_info(const game_driver *driver, std::string &buffer);
void arts_render(void *selectedref, float x1, float y1, float x2, float y2);
void infos_render(void *selectedref, float x1, float y1, float x2, float y2);
virtual void infos_render(float x1, float y1, float x2, float y2) override;
// handlers
void inkey_select(const event *menu_event);

View File

@ -145,6 +145,7 @@ menu_select_launch::~menu_select_launch()
menu_select_launch::menu_select_launch(mame_ui_manager &mui, render_container &container, bool is_swlist)
: menu(mui, container)
, m_prev_selected(nullptr)
, m_total_lines(0)
, m_topline_datsview(0)
, m_ui_error(false)
@ -153,6 +154,8 @@ menu_select_launch::menu_select_launch(mame_ui_manager &mui, render_container &c
, m_focus(focused_menu::main)
, m_pressed(false)
, m_repeat(0)
, m_old_driver(nullptr)
, m_old_software(nullptr)
{
// set up persistent cache for machine run
{
@ -258,36 +261,200 @@ float menu_select_launch::draw_right_box_title(float x1, float y1, float x2, flo
}
//-------------------------------------------------
// perform our special rendering
//-------------------------------------------------
void menu_select_launch::arts_render(float origx1, float origy1, float origx2, float origy2)
{
ui_software_info const *software;
game_driver const *driver;
get_selection(software, driver);
if (software && ((software->startempty != 1) || !driver))
{
m_old_driver = nullptr;
if (ui_globals::default_image)
(software->startempty == 0) ? ui_globals::curimage_view = SNAPSHOT_VIEW : ui_globals::curimage_view = CABINETS_VIEW;
// arts title and searchpath
std::string const searchstr = arts_render_common(origx1, origy1, origx2, origy2);
// loads the image if necessary
if ((software != m_old_software) || !snapx_valid() || ui_globals::switch_image)
{
emu_file snapfile(searchstr.c_str(), OPEN_FLAG_READ);
bitmap_argb32 *tmp_bitmap;
tmp_bitmap = auto_alloc(machine(), bitmap_argb32);
if (software->startempty == 1)
{
// Load driver snapshot
std::string fullname = std::string(software->driver->name) + ".png";
render_load_png(*tmp_bitmap, snapfile, nullptr, fullname.c_str());
if (!tmp_bitmap->valid())
{
fullname.assign(software->driver->name).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, nullptr, fullname.c_str());
}
}
else if (ui_globals::curimage_view == TITLES_VIEW)
{
// First attempt from name list
std::string const pathname = software->listname + "_titles";
std::string fullname = software->shortname + ".png";
render_load_png(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
if (!tmp_bitmap->valid())
{
fullname.assign(software->shortname).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
}
}
else
{
// First attempt from name list
std::string pathname = software->listname;
std::string fullname = software->shortname + ".png";
render_load_png(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
if (!tmp_bitmap->valid())
{
fullname.assign(software->shortname).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
}
if (!tmp_bitmap->valid())
{
// Second attempt from driver name + part name
pathname.assign(software->driver->name).append(software->part);
fullname.assign(software->shortname).append(".png");
render_load_png(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
if (!tmp_bitmap->valid())
{
fullname.assign(software->shortname).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
}
}
}
m_old_software = software;
ui_globals::switch_image = false;
arts_render_images(tmp_bitmap, origx1, origy1, origx2, origy2);
auto_free(machine(), tmp_bitmap);
}
// if the image is available, loaded and valid, display it
draw_snapx(origx1, origy1, origx2, origy2);
}
else if (driver)
{
m_old_software = nullptr;
if (ui_globals::default_image)
((driver->flags & MACHINE_TYPE_ARCADE) == 0) ? ui_globals::curimage_view = CABINETS_VIEW : ui_globals::curimage_view = SNAPSHOT_VIEW;
std::string const searchstr = arts_render_common(origx1, origy1, origx2, origy2);
// loads the image if necessary
if ((driver != m_old_driver) || !snapx_valid() || ui_globals::switch_image)
{
emu_file snapfile(searchstr.c_str(), OPEN_FLAG_READ);
snapfile.set_restrict_to_mediapath(true);
bitmap_argb32 *tmp_bitmap;
tmp_bitmap = auto_alloc(machine(), bitmap_argb32);
// try to load snapshot first from saved "0000.png" file
std::string fullname(driver->name);
render_load_png(*tmp_bitmap, snapfile, fullname.c_str(), "0000.png");
if (!tmp_bitmap->valid())
render_load_jpeg(*tmp_bitmap, snapfile, fullname.c_str(), "0000.jpg");
// if fail, attemp to load from standard file
if (!tmp_bitmap->valid())
{
fullname.assign(driver->name).append(".png");
render_load_png(*tmp_bitmap, snapfile, nullptr, fullname.c_str());
if (!tmp_bitmap->valid())
{
fullname.assign(driver->name).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, nullptr, fullname.c_str());
}
}
// if fail again, attemp to load from parent file
if (!tmp_bitmap->valid())
{
// set clone status
bool cloneof = strcmp(driver->parent, "0");
if (cloneof)
{
int cx = driver_list::find(driver->parent);
if (cx != -1 && ((driver_list::driver(cx).flags & MACHINE_IS_BIOS_ROOT) != 0))
cloneof = false;
}
if (cloneof)
{
fullname.assign(driver->parent).append(".png");
render_load_png(*tmp_bitmap, snapfile, nullptr, fullname.c_str());
if (!tmp_bitmap->valid())
{
fullname.assign(driver->parent).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, nullptr, fullname.c_str());
}
}
}
m_old_driver = driver;
ui_globals::switch_image = false;
arts_render_images(tmp_bitmap, origx1, origy1, origx2, origy2);
auto_free(machine(), tmp_bitmap);
}
// if the image is available, loaded and valid, display it
draw_snapx(origx1, origy1, origx2, origy2);
}
}
//-------------------------------------------------
// common function for images render
//-------------------------------------------------
std::string menu_select_launch::arts_render_common(float origx1, float origy1, float origx2, float origy2)
{
auto line_height = ui().get_line_height();
std::string snaptext, searchstr;
auto title_size = 0.0f;
auto txt_lenght = 0.0f;
auto gutter_width = 0.4f * line_height * machine().render().ui_aspect() * 1.3f;
float const line_height = ui().get_line_height();
float const gutter_width = 0.4f * line_height * machine().render().ui_aspect() * 1.3f;
std::string snaptext, searchstr;
get_title_search(snaptext, searchstr);
// apply title to right panel
float title_size = 0.0f;
for (int x = FIRST_VIEW; x < LAST_VIEW; x++)
{
ui().draw_text_full(container(), _(arts_info[x].first), origx1, origy1, origx2 - origx1, ui::text_layout::CENTER,
ui::text_layout::TRUNCATE, mame_ui_manager::NONE, rgb_t::white, rgb_t::black, &txt_lenght, nullptr);
txt_lenght += 0.01f;
title_size = MAX(txt_lenght, title_size);
float text_length;
ui().draw_text_full(container(),
_(arts_info[x].first), origx1, origy1, origx2 - origx1,
ui::text_layout::CENTER, ui::text_layout::TRUNCATE, mame_ui_manager::NONE, rgb_t::white, rgb_t::black,
&text_length, nullptr);
title_size = (std::max)(text_length + 0.01f, title_size);
}
rgb_t fgcolor = (m_focus == focused_menu::rightbottom) ? rgb_t(0xff, 0xff, 0x00) : UI_TEXT_COLOR;
rgb_t bgcolor = (m_focus == focused_menu::rightbottom) ? rgb_t(0xff, 0xff, 0xff) : UI_TEXT_BG_COLOR;
float middle = origx2 - origx1;
rgb_t const fgcolor = (m_focus == focused_menu::rightbottom) ? rgb_t(0xff, 0xff, 0x00) : UI_TEXT_COLOR;
rgb_t const bgcolor = (m_focus == focused_menu::rightbottom) ? rgb_t(0xff, 0xff, 0xff) : UI_TEXT_BG_COLOR;
float const middle = origx2 - origx1;
// check size
float sc = title_size + 2.0f * gutter_width;
float tmp_size = (sc > middle) ? ((middle - 2.0f * gutter_width) / sc) : 1.0f;
float const sc = title_size + 2.0f * gutter_width;
float const tmp_size = (sc > middle) ? ((middle - 2.0f * gutter_width) / sc) : 1.0f;
title_size *= tmp_size;
if (bgcolor != UI_TEXT_BG_COLOR)
@ -296,8 +463,10 @@ std::string menu_select_launch::arts_render_common(float origx1, float origy1, f
origy1 + line_height, bgcolor, rgb_t(43, 43, 43), hilight_main_texture(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXWRAP(TRUE));
}
ui().draw_text_full(container(), snaptext.c_str(), origx1, origy1, origx2 - origx1, ui::text_layout::CENTER, ui::text_layout::TRUNCATE,
mame_ui_manager::NORMAL, fgcolor, bgcolor, nullptr, nullptr, tmp_size);
ui().draw_text_full(container(),
snaptext.c_str(), origx1, origy1, origx2 - origx1,
ui::text_layout::CENTER, ui::text_layout::TRUNCATE, mame_ui_manager::NORMAL, fgcolor, bgcolor,
nullptr, nullptr, tmp_size);
draw_common_arrow(origx1, origy1, origx2, origy2, ui_globals::curimage_view, FIRST_VIEW, LAST_VIEW, title_size);
@ -1219,7 +1388,7 @@ void menu_select_launch::draw(UINT32 flags)
float effective_width = visible_width - 2.0f * gutter_width;
float effective_left = visible_left + gutter_width;
if (m_prev_selected != nullptr && m_focus == focused_menu::main && selected < visible_items)
if ((m_focus == focused_menu::main) && (selected < visible_items))
m_prev_selected = nullptr;
int const n_loop = (std::min)(m_visible_lines, visible_items);
@ -1364,7 +1533,7 @@ void menu_select_launch::draw(UINT32 flags)
x1 = x2;
x2 += right_panel_size;
draw_right_panel(get_selection_ref(), x1, y1, x2, y2);
draw_right_panel(x1, y1, x2, y2);
x1 = primary_left - UI_BOX_LR_BORDER;
x2 = primary_left + primary_width + UI_BOX_LR_BORDER;
@ -1390,6 +1559,48 @@ void menu_select_launch::draw(UINT32 flags)
}
//-------------------------------------------------
// draw right panel
//-------------------------------------------------
void menu_select_launch::draw_right_panel(float origx1, float origy1, float origx2, float origy2)
{
bool const hide((ui_globals::panels_status == HIDE_RIGHT_PANEL) || (ui_globals::panels_status == HIDE_BOTH));
float const x2(hide ? origx2 : (origx1 + 2.0f * UI_BOX_LR_BORDER));
float const space(x2 - origx1);
float const lr_arrow_width(0.4f * space * machine().render().ui_aspect());
// set left-right arrows dimension
float const ar_x0(0.5f * (x2 + origx1) - 0.5f * lr_arrow_width);
float const ar_y0(0.5f * (origy2 + origy1) + 0.1f * space);
float const ar_x1(ar_x0 + lr_arrow_width);
float const ar_y1(0.5f * (origy2 + origy1) + 0.9f * space);
ui().draw_outlined_box(container(), origx1, origy1, origx2, origy2, rgb_t(0xEF, 0x12, 0x47, 0x7B));
rgb_t fgcolor(UI_TEXT_COLOR);
if (mouse_hit && origx1 <= mouse_x && x2 > mouse_x && origy1 <= mouse_y && origy2 > mouse_y)
{
fgcolor = UI_MOUSEOVER_COLOR;
hover = HOVER_RPANEL_ARROW;
}
if (hide)
{
draw_arrow(ar_x0, ar_y0, ar_x1, ar_y1, fgcolor, ROT90 ^ ORIENTATION_FLIP_X);
return;
}
draw_arrow(ar_x0, ar_y0, ar_x1, ar_y1, fgcolor, ROT90);
origy1 = draw_right_box_title(x2, origy1, origx2, origy2);
if (ui_globals::rpanel == RP_IMAGES)
arts_render(x2, origy1, origx2, origy2);
else
infos_render(x2, origy1, origx2, origy2);
}
void menu_select_launch::exit(running_machine &machine)
{
std::lock_guard<std::mutex> guard(s_cache_guard);

View File

@ -21,6 +21,8 @@
#include <vector>
struct ui_software_info;
namespace ui {
class menu_select_launch : public menu
{
@ -48,6 +50,7 @@ protected:
float draw_right_box_title(float x1, float y1, float x2, float y2);
// images render
void arts_render(float origx1, float origy1, float origx2, float origy2);
std::string arts_render_common(float origx1, float origy1, float origx2, float origy2);
void arts_render_images(bitmap_argb32 *bitmap, float origx1, float origy1, float origx2, float origy2);
@ -66,6 +69,7 @@ protected:
bool snapx_valid() const { return m_cache->snapx_bitmap().valid(); }
int visible_items;
void *m_prev_selected;
int m_total_lines;
int m_topline_datsview; // right box top line
bool m_ui_error;
@ -114,8 +118,11 @@ private:
// draw left panel
virtual float draw_left_panel(float x1, float y1, float x2, float y2) = 0;
// draw right panel
virtual void draw_right_panel(void *selectedref, float origx1, float origy1, float origx2, float origy2) = 0;
// draw infos
virtual void infos_render(float x1, float y1, float x2, float y2) = 0;
// get selected software and/or driver
virtual void get_selection(ui_software_info const *&software, game_driver const *&driver) const = 0;
float draw_icon(int linenum, void *selectedref, float x1, float y1);
@ -130,18 +137,24 @@ private:
// draw game list
virtual void draw(UINT32 flags) override;
// draw right panel
void draw_right_panel(float origx1, float origy1, float origx2, float origy2);
// cleanup function
static void exit(running_machine &machine);
cache_ptr m_cache;
bool m_is_swlist;
focused_menu m_focus;
bool m_pressed; // mouse button held down
osd_ticks_t m_repeat;
cache_ptr m_cache;
bool m_is_swlist;
focused_menu m_focus;
bool m_pressed; // mouse button held down
osd_ticks_t m_repeat;
render_texture *m_icons_texture[MAX_ICONS_RENDER];
bitmap_ptr m_icons_bitmap[MAX_ICONS_RENDER];
game_driver const *m_old_icons[MAX_ICONS_RENDER];
game_driver const *m_old_driver; // driver/software for previously displayed artwork
ui_software_info const *m_old_software;
render_texture *m_icons_texture[MAX_ICONS_RENDER];
bitmap_ptr m_icons_bitmap[MAX_ICONS_RENDER];
game_driver const *m_old_icons[MAX_ICONS_RENDER];
static std::mutex s_cache_guard;
static cache_ptr_map s_caches;

View File

@ -1551,14 +1551,14 @@ float menu_select_software::draw_left_panel(float x1, float y1, float x2, float
// draw infos
//-------------------------------------------------
void menu_select_software::infos_render(void *selectedref, float origx1, float origy1, float origx2, float origy2)
void menu_select_software::infos_render(float origx1, float origy1, float origx2, float origy2)
{
float line_height = ui().get_line_height();
static std::string buffer;
std::vector<int> xstart;
std::vector<int> xend;
float text_size = ui().options().infos_size();
ui_software_info *soft = (selectedref != nullptr) ? (ui_software_info *)selectedref : ((m_prev_selected != nullptr) ? (ui_software_info *)m_prev_selected : nullptr);
ui_software_info *soft = (get_selection_ref() != nullptr) ? (ui_software_info *)get_selection_ref() : ((m_prev_selected != nullptr) ? (ui_software_info *)m_prev_selected : nullptr);
static ui_software_info *oldsoft = nullptr;
static int old_sw_view = -1;
@ -1690,214 +1690,7 @@ void menu_select_software::infos_render(void *selectedref, float origx1, float o
right_visible_lines = r_visible_lines - (m_topline_datsview != 0) - (m_topline_datsview + r_visible_lines != m_total_lines);
}
//-------------------------------------------------
// perform our special rendering
//-------------------------------------------------
void menu_select_software::arts_render(void *selectedref, float origx1, float origy1, float origx2, float origy2)
{
static ui_software_info *oldsoft = nullptr;
static const game_driver *olddriver = nullptr;
const game_driver *driver = nullptr;
ui_software_info *soft = (selectedref != nullptr) ? (ui_software_info *)selectedref : ((m_prev_selected != nullptr) ? (ui_software_info *)m_prev_selected : nullptr);
if (soft != nullptr && soft->startempty == 1)
{
driver = soft->driver;
oldsoft = nullptr;
}
else
olddriver = nullptr;
if (driver != nullptr)
{
if (ui_globals::default_image)
((driver->flags & MACHINE_TYPE_ARCADE) == 0) ? ui_globals::curimage_view = CABINETS_VIEW : ui_globals::curimage_view = SNAPSHOT_VIEW;
std::string searchstr;
searchstr = arts_render_common(origx1, origy1, origx2, origy2);
// loads the image if necessary
if (driver != olddriver || !snapx_valid() || ui_globals::switch_image)
{
emu_file snapfile(searchstr.c_str(), OPEN_FLAG_READ);
snapfile.set_restrict_to_mediapath(true);
bitmap_argb32 *tmp_bitmap;
tmp_bitmap = auto_alloc(machine(), bitmap_argb32);
// try to load snapshot first from saved "0000.png" file
std::string fullname(driver->name);
render_load_png(*tmp_bitmap, snapfile, fullname.c_str(), "0000.png");
if (!tmp_bitmap->valid())
render_load_jpeg(*tmp_bitmap, snapfile, fullname.c_str(), "0000.jpg");
// if fail, attemp to load from standard file
if (!tmp_bitmap->valid())
{
fullname.assign(driver->name).append(".png");
render_load_png(*tmp_bitmap, snapfile, nullptr, fullname.c_str());
if (!tmp_bitmap->valid())
{
fullname.assign(driver->name).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, nullptr, fullname.c_str());
}
}
// if fail again, attemp to load from parent file
if (!tmp_bitmap->valid())
{
// set clone status
bool cloneof = strcmp(driver->parent, "0");
if (cloneof)
{
int cx = driver_list::find(driver->parent);
if (cx != -1 && ((driver_list::driver(cx).flags & MACHINE_IS_BIOS_ROOT) != 0))
cloneof = false;
}
if (cloneof)
{
fullname.assign(driver->parent).append(".png");
render_load_png(*tmp_bitmap, snapfile, nullptr, fullname.c_str());
if (!tmp_bitmap->valid())
{
fullname.assign(driver->parent).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, nullptr, fullname.c_str());
}
}
}
olddriver = driver;
ui_globals::switch_image = false;
arts_render_images(tmp_bitmap, origx1, origy1, origx2, origy2);
auto_free(machine(), tmp_bitmap);
}
// if the image is available, loaded and valid, display it
draw_snapx(origx1, origy1, origx2, origy2);
}
else if (soft != nullptr)
{
std::string fullname, pathname;
if (ui_globals::default_image)
(soft->startempty == 0) ? ui_globals::curimage_view = SNAPSHOT_VIEW : ui_globals::curimage_view = CABINETS_VIEW;
// arts title and searchpath
std::string searchstr;
searchstr = arts_render_common(origx1, origy1, origx2, origy2);
// loads the image if necessary
if (soft != oldsoft || !snapx_valid() || ui_globals::switch_image)
{
emu_file snapfile(searchstr.c_str(), OPEN_FLAG_READ);
bitmap_argb32 *tmp_bitmap;
tmp_bitmap = auto_alloc(machine(), bitmap_argb32);
if (soft->startempty == 1)
{
// Load driver snapshot
fullname.assign(soft->driver->name).append(".png");
render_load_png(*tmp_bitmap, snapfile, nullptr, fullname.c_str());
if (!tmp_bitmap->valid())
{
fullname.assign(soft->driver->name).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, nullptr, fullname.c_str());
}
}
else if (ui_globals::curimage_view == TITLES_VIEW)
{
// First attempt from name list
pathname.assign(soft->listname).append("_titles");
fullname.assign(soft->shortname).append(".png");
render_load_png(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
if (!tmp_bitmap->valid())
{
fullname.assign(soft->shortname).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
}
}
else
{
// First attempt from name list
pathname = soft->listname;
fullname.assign(soft->shortname).append(".png");
render_load_png(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
if (!tmp_bitmap->valid())
{
fullname.assign(soft->shortname).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
}
if (!tmp_bitmap->valid())
{
// Second attempt from driver name + part name
pathname.assign(soft->driver->name).append(soft->part);
fullname.assign(soft->shortname).append(".png");
render_load_png(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
if (!tmp_bitmap->valid())
{
fullname.assign(soft->shortname).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
}
}
}
oldsoft = soft;
ui_globals::switch_image = false;
arts_render_images(tmp_bitmap, origx1, origy1, origx2, origy2);
auto_free(machine(), tmp_bitmap);
}
// if the image is available, loaded and valid, display it
draw_snapx(origx1, origy1, origx2, origy2);
}
}
void menu_select_software::draw_right_panel(void *selectedref, float origx1, float origy1, float origx2, float origy2)
{
rgb_t fgcolor = UI_TEXT_COLOR;
bool hide = (ui_globals::panels_status == HIDE_RIGHT_PANEL || ui_globals::panels_status == HIDE_BOTH);
float x2 = (hide) ? origx2 : origx1 + 2.0f * UI_BOX_LR_BORDER;
float space = x2 - origx1;
float lr_arrow_width = 0.4f * space * machine().render().ui_aspect();
// set left-right arrows dimension
float ar_x0 = 0.5f * (x2 + origx1) - 0.5f * lr_arrow_width;
float ar_y0 = 0.5f * (origy2 + origy1) + 0.1f * space;
float ar_x1 = ar_x0 + lr_arrow_width;
float ar_y1 = 0.5f * (origy2 + origy1) + 0.9f * space;
ui().draw_outlined_box(container(), origx1, origy1, origx2, origy2, rgb_t(0xEF, 0x12, 0x47, 0x7B));
if (mouse_hit && origx1 <= mouse_x && x2 > mouse_x && origy1 <= mouse_y && origy2 > mouse_y)
{
fgcolor = UI_MOUSEOVER_COLOR;
hover = HOVER_RPANEL_ARROW;
}
if (hide)
{
draw_arrow(ar_x0, ar_y0, ar_x1, ar_y1, fgcolor, ROT90 ^ ORIENTATION_FLIP_X);
return;
}
draw_arrow(ar_x0, ar_y0, ar_x1, ar_y1, fgcolor, ROT90);
origx1 = x2;
origy1 = draw_right_box_title(origx1, origy1, origx2, origy2);
if (ui_globals::rpanel == RP_IMAGES)
arts_render(selectedref, origx1, origy1, origx2, origy2);
else
infos_render(selectedref, origx1, origy1, origx2, origy2);
}
//-------------------------------------------------
// ctor
@ -2136,4 +1929,15 @@ void bios_selection::custom_render(void *selectedref, float top, float bottom, f
mame_ui_manager::NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, nullptr, nullptr);
}
//-------------------------------------------------
// get selected software and/or driver
//-------------------------------------------------
void menu_select_software::get_selection(ui_software_info const *&software, game_driver const *&driver) const
{
software = reinterpret_cast<ui_software_info const *>(get_selection_ref());
driver = software ? software->driver : nullptr;
}
} // namespace ui

View File

@ -44,8 +44,8 @@ private:
// draw left panel
virtual float draw_left_panel(float x1, float y1, float x2, float y2) override;
// draw right panel
virtual void draw_right_panel(void *selectedref, float origx1, float origy1, float origx2, float origy2) override;
// get selected software and/or driver
virtual void get_selection(ui_software_info const *&software, game_driver const *&driver) const override;
ui_software_info *m_searchlist[VISIBLE_GAMES_IN_SEARCH + 1];
std::vector<ui_software_info *> m_displaylist, m_tmp, m_sortedlist;
@ -57,8 +57,7 @@ private:
void find_matches(const char *str, int count);
void load_sw_custom_filters();
void arts_render(void *selectedref, float x1, float y1, float x2, float y2);
void infos_render(void *selectedref, float x1, float y1, float x2, float y2);
virtual void infos_render(float x1, float y1, float x2, float y2) override;
// handlers
void inkey_select(const event *menu_event);

View File

@ -565,10 +565,10 @@ void mame_ui_manager::draw_text_full(render_container &container, const char *or
// append text to it
layout.add_text(
origs,
fgcolor,
draw == OPAQUE_ ? bgcolor : rgb_t::transparent,
text_size);
origs,
fgcolor,
draw == OPAQUE_ ? bgcolor : rgb_t::transparent,
text_size);
// and emit it (if we are asked to do so)
if (draw != NONE)