Fixed not load for some INI files in the category filter.

Removed use of strcmp for menu separators.
Modernized and cleaned up some part of code.
This commit is contained in:
dankan1890 2016-06-08 23:46:25 +02:00
parent 72dfab6b11
commit 51adfcc66b
14 changed files with 185 additions and 337 deletions

View File

@ -145,7 +145,10 @@ void menu_cheat::populate()
{
UINT32 flags;
curcheat->menu_text(text, subtext, flags);
item_append(text.c_str(), subtext.c_str(), flags, curcheat.get());
if (text == MENU_SEPARATOR_ITEM)
item_append(menu_item_type::SEPARATOR);
else
item_append(text.c_str(), subtext.c_str(), flags, curcheat.get());
}
/* add a separator */

View File

@ -55,55 +55,25 @@ std::string datfile_manager::m_story_rev;
std::string datfile_manager::m_ginit_rev;
bool datfile_manager::first_run = true;
#define opendatsfile(f) if (parseopen(#f".dat")) { init_##f(); parseclose(); }
//-------------------------------------------------
// ctor
//-------------------------------------------------
datfile_manager::datfile_manager(running_machine &machine, ui_options &moptions) : m_machine(machine), m_options(moptions)
datfile_manager::datfile_manager(running_machine &machine, ui_options &moptions)
: m_machine(machine)
, m_options(moptions)
{
if (m_options.enabled_dats() && first_run)
{
first_run = false;
if (parseopen("mameinfo.dat"))
{
init_mameinfo();
parseclose();
}
if (parseopen("command.dat"))
{
init_command();
parseclose();
}
if (parseopen("story.dat"))
{
init_storyinfo();
parseclose();
}
if (parseopen("messinfo.dat"))
{
init_messinfo();
parseclose();
}
if (parseopen("sysinfo.dat"))
{
init_sysinfo();
parseclose();
}
if (parseopen("history.dat"))
{
init_history();
parseclose();
}
if (parseopen("gameinit.dat"))
{
init_gameinit();
parseclose();
}
opendatsfile(mameinfo);
opendatsfile(command);
opendatsfile(story);
opendatsfile(messinfo);
opendatsfile(sysinfo);
opendatsfile(history);
opendatsfile(gameinit);
}
}
@ -113,7 +83,7 @@ datfile_manager::datfile_manager(running_machine &machine, ui_options &moptions)
void datfile_manager::init_sysinfo()
{
int swcount = 0;
int count = index_datafile(m_sysidx, swcount);
auto count = index_datafile(m_sysidx, swcount);
osd_printf_verbose("Sysinfo.dat games found = %i\n", count);
osd_printf_verbose("Rev = %s\n", m_sysinfo_rev.c_str());
}
@ -121,10 +91,10 @@ void datfile_manager::init_sysinfo()
//-------------------------------------------------
// initialize story.dat index
//-------------------------------------------------
void datfile_manager::init_storyinfo()
void datfile_manager::init_story()
{
int swcount = 0;
int count = index_datafile(m_storyidx, swcount);
auto count = index_datafile(m_storyidx, swcount);
osd_printf_verbose("Story.dat games found = %i\n", count);
}
@ -134,7 +104,7 @@ void datfile_manager::init_storyinfo()
void datfile_manager::init_history()
{
int swcount = 0;
int count = index_datafile(m_histidx, swcount);
auto count = index_datafile(m_histidx, swcount);
osd_printf_verbose("History.dat systems found = %i\n", count);
osd_printf_verbose("History.dat software packages found = %i\n", swcount);
osd_printf_verbose("Rev = %s\n", m_history_rev.c_str());
@ -147,7 +117,7 @@ void datfile_manager::init_gameinit()
{
int swcount = 0;
drvindex tmp;
int count = index_mame_mess_info(m_ginitidx, tmp, swcount);
auto count = index_mame_mess_info(m_ginitidx, tmp, swcount);
osd_printf_verbose("Gameinit.dat games found = %i\n", count);
osd_printf_verbose("Rev = %s\n", m_ginit_rev.c_str());
}
@ -158,7 +128,7 @@ void datfile_manager::init_gameinit()
void datfile_manager::init_mameinfo()
{
int drvcount = 0;
int count = index_mame_mess_info(m_mameidx, m_drvidx, drvcount);
auto count = index_mame_mess_info(m_mameidx, m_drvidx, drvcount);
osd_printf_verbose("Mameinfo.dat games found = %i\n", count);
osd_printf_verbose("Mameinfo.dat drivers found = %d\n", drvcount);
osd_printf_verbose("Rev = %s\n", m_mame_rev.c_str());
@ -170,7 +140,7 @@ void datfile_manager::init_mameinfo()
void datfile_manager::init_messinfo()
{
int drvcount = 0;
int count = index_mame_mess_info(m_messidx, m_messdrvidx, drvcount);
auto count = index_mame_mess_info(m_messidx, m_messdrvidx, drvcount);
osd_printf_verbose("Messinfo.dat games found = %i\n", count);
osd_printf_verbose("Messinfo.dat drivers found = %d\n", drvcount);
osd_printf_verbose("Rev = %s\n", m_mess_rev.c_str());
@ -182,7 +152,7 @@ void datfile_manager::init_messinfo()
void datfile_manager::init_command()
{
int swcount = 0;
int count = index_datafile(m_cmdidx, swcount);
auto count = index_datafile(m_cmdidx, swcount);
osd_printf_verbose("Command.dat games found = %i\n", count);
}
@ -213,7 +183,7 @@ void datfile_manager::load_software_info(std::string &softlist, std::string &buf
if (!has_software(softlist, softname, parentname))
return;
long s_offset = (*m_itemsiter).second;
auto s_offset = m_itemsiter->second;
char rbuf[64 * 1024];
fseek(fp, s_offset, SEEK_SET);
std::string readbuf;
@ -302,19 +272,19 @@ void datfile_manager::load_data_text(const game_driver *drv, std::string &buffer
dataindex::iterator itemsiter = idx.find(drv);
if (itemsiter == idx.end())
{
int cloneof = driver_list::non_bios_clone(*drv);
auto cloneof = driver_list::non_bios_clone(*drv);
if (cloneof == -1)
return;
else
{
const game_driver *c_drv = &driver_list::driver(cloneof);
auto c_drv = &driver_list::driver(cloneof);
itemsiter = idx.find(c_drv);
if (itemsiter == idx.end())
return;
}
}
long s_offset = (*itemsiter).second;
auto s_offset = itemsiter->second;
fseek(fp, s_offset, SEEK_SET);
char rbuf[64 * 1024];
std::string readbuf;
@ -349,7 +319,7 @@ void datfile_manager::load_driver_text(const game_driver *drv, std::string &buff
return;
buffer.append("\n--- DRIVER INFO ---\n").append("Driver: ").append(s).append("\n\n");
long s_offset = (*index).second;
auto s_offset = index->second;
fseek(fp, s_offset, SEEK_SET);
char rbuf[64 * 1024];
std::string readbuf;
@ -378,10 +348,10 @@ int datfile_manager::index_mame_mess_info(dataindex &index, drvindex &index_drv,
{
std::string name;
size_t foundtag;
size_t t_mame = TAG_MAMEINFO_R.size();
size_t t_mess = TAG_MESSINFO_R.size();
size_t t_ginit = TAG_GAMEINIT_R.size();
size_t t_info = TAG_INFO.size();
auto t_mame = TAG_MAMEINFO_R.size();
auto t_mess = TAG_MESSINFO_R.size();
auto t_ginit = TAG_GAMEINIT_R.size();
auto t_info = TAG_INFO.size();
char rbuf[64 * 1024];
std::string readbuf, xid;
@ -390,17 +360,17 @@ int datfile_manager::index_mame_mess_info(dataindex &index, drvindex &index_drv,
readbuf = chartrimcarriage(rbuf);
if (m_mame_rev.empty() && readbuf.compare(0, t_mame, TAG_MAMEINFO_R) == 0)
{
size_t found = readbuf.find(" ", t_mame + 1);
auto found = readbuf.find(" ", t_mame + 1);
m_mame_rev = readbuf.substr(t_mame + 1, found - t_mame);
}
else if (m_mess_rev.empty() && (foundtag = readbuf.find(TAG_MESSINFO_R)) != std::string::npos)
{
size_t found = readbuf.find(" ", foundtag + t_mess + 1);
auto found = readbuf.find(" ", foundtag + t_mess + 1);
m_mess_rev = readbuf.substr(foundtag + t_mess + 1, found - t_mess - foundtag);
}
else if (m_ginit_rev.empty() && readbuf.compare(0, t_ginit, TAG_GAMEINIT_R) == 0)
{
size_t found = readbuf.find(" ", t_ginit + 1);
auto found = readbuf.find(" ", t_ginit + 1);
m_ginit_rev = readbuf.substr(t_ginit + 1, found - t_ginit);
}
else if (readbuf.compare(0, t_info, TAG_INFO) == 0)
@ -412,7 +382,7 @@ int datfile_manager::index_mame_mess_info(dataindex &index, drvindex &index_drv,
if (xid == TAG_MAME)
{
// validate driver
int game_index = driver_list::find(name.c_str());
auto game_index = driver_list::find(name.c_str());
if (game_index != -1)
index.emplace(&driver_list::driver(game_index), ftell(fp));
}
@ -432,12 +402,12 @@ int datfile_manager::index_mame_mess_info(dataindex &index, drvindex &index_drv,
//-------------------------------------------------
int datfile_manager::index_datafile(dataindex &index, int &swcount)
{
std::string readbuf, name;
size_t t_hist = TAG_HISTORY_R.size();
size_t t_story = TAG_STORY_R.size();
size_t t_sysinfo = TAG_SYSINFO_R.size();
size_t t_info = TAG_INFO.size();
size_t t_bio = TAG_BIO.size();
std::string readbuf;
auto t_hist = TAG_HISTORY_R.size();
auto t_story = TAG_STORY_R.size();
auto t_sysinfo = TAG_SYSINFO_R.size();
auto t_info = TAG_INFO.size();
auto t_bio = TAG_BIO.size();
char rbuf[64 * 1024];
while (fgets(rbuf, 64 * 1024, fp) != nullptr)
{
@ -445,124 +415,43 @@ int datfile_manager::index_datafile(dataindex &index, int &swcount)
if (m_history_rev.empty() && readbuf.compare(0, t_hist, TAG_HISTORY_R) == 0)
{
size_t found = readbuf.find(" ", t_hist + 1);
auto found = readbuf.find(" ", t_hist + 1);
m_history_rev = readbuf.substr(t_hist + 1, found - t_hist);
}
else if (m_sysinfo_rev.empty() && readbuf.compare(0, t_sysinfo, TAG_SYSINFO_R) == 0)
{
size_t found = readbuf.find(".", t_sysinfo + 1);
auto found = readbuf.find(".", t_sysinfo + 1);
m_sysinfo_rev = readbuf.substr(t_sysinfo + 1, found - t_sysinfo);
}
else if (m_story_rev.empty() && readbuf.compare(0, t_story, TAG_STORY_R) == 0)
m_story_rev = readbuf.substr(t_story + 1);
else if (readbuf.compare(0, t_info, TAG_INFO) == 0)
{
int curpoint = t_info + 1;
int ends = readbuf.size();
while (curpoint < ends)
// search for game info
auto rd = readbuf.substr(t_info + 1);
std::vector<std::string> gamelist = tokenize(rd, ',');
for (auto & e : gamelist)
{
// search for comma
size_t found = readbuf.find(",", curpoint);
// found it
if (found != std::string::npos)
{
// copy data and validate driver
name = readbuf.substr(curpoint, found - curpoint);
// validate driver
int game_index = driver_list::find(name.c_str());
if (game_index != -1)
index.emplace(&driver_list::driver(game_index), ftell(fp));
// update current point
curpoint = ++found;
}
// if comma not found, copy data while until reach the end of string
else if (curpoint < ends)
{
name = readbuf.substr(curpoint);
int game_index = driver_list::find(name.c_str());
if (game_index != -1)
index.emplace(&driver_list::driver(game_index), ftell(fp));
// update current point
curpoint = ends;
}
auto game_index = driver_list::find(e.c_str());
if (game_index != -1)
index.emplace(&driver_list::driver(game_index), ftell(fp));
}
}
// search for software info
else if (!readbuf.empty() && readbuf[0] == DATAFILE_TAG[0])
{
// search for software info
fgets(rbuf, 64 * 1024, fp);
std::string readbuf_2(chartrimcarriage(rbuf));
// TAG_BIO identifies software list
if (readbuf_2.compare(0, t_bio, TAG_BIO) == 0)
{
size_t eq_sign = readbuf.find("=");
auto eq_sign = readbuf.find('=');
std::string s_list(readbuf.substr(1, eq_sign - 1));
std::string s_roms(readbuf.substr(eq_sign + 1));
int ends = s_list.size();
int curpoint = 0;
while (curpoint < ends)
{
size_t found = s_list.find(",", curpoint);
// found it
if (found != std::string::npos)
{
name = s_list.substr(curpoint, found - curpoint);
curpoint = ++found;
}
else
{
name = s_list.substr(curpoint);
curpoint = ends;
}
// search for a software list in the index, if not found then allocates
std::string lname(name);
int cpoint = 0;
int cends = s_roms.size();
while (cpoint < cends)
{
// search for comma
size_t comma_found = s_roms.find(",", cpoint);
// found it
if (comma_found != std::string::npos)
{
// copy data
name = s_roms.substr(cpoint, comma_found - cpoint);
// add a SoftwareItem
m_swindex[lname].emplace(name, ftell(fp));
// update current point
cpoint = ++comma_found;
swcount++;
}
else
{
// if reach the end, bail out
if (s_roms[cpoint] == '\r' || s_roms[cpoint] == '\n')
break;
// copy data
name = s_roms.substr(cpoint);
// add a SoftwareItem
m_swindex[lname].emplace(name, ftell(fp));
// update current point
cpoint = cends;
swcount++;
}
}
}
std::vector<std::string> token_list = tokenize(s_list, ',');
std::vector<std::string> token_roms = tokenize(s_roms, ',');
for (auto & li : token_list)
for (auto & ro : token_roms)
m_swindex[li].emplace(ro, ftell(fp));
}
}
}
@ -574,9 +463,6 @@ int datfile_manager::index_datafile(dataindex &index, int &swcount)
//---------------------------------------------------------
bool datfile_manager::parseopen(const char *filename)
{
// MAME core file parsing functions fail in recognizing UNICODE chars in UTF-8 without BOM,
// so it's better and faster use standard C fileio functions.
emu_file file(m_options.history_path(), OPEN_FLAG_READ);
if (file.open(filename) != osd_file::error::NONE)
return false;
@ -598,22 +484,21 @@ void datfile_manager::index_menuidx(const game_driver *drv, dataindex &idx, drvi
dataindex::iterator itemsiter = idx.find(drv);
if (itemsiter == idx.end())
{
int cloneof = driver_list::non_bios_clone(*drv);
auto cloneof = driver_list::non_bios_clone(*drv);
if (cloneof == -1)
return;
else
{
const game_driver *c_drv = &driver_list::driver(cloneof);
itemsiter = idx.find(c_drv);
if (itemsiter == idx.end())
auto c_drv = &driver_list::driver(cloneof);
if ((itemsiter = idx.find(c_drv)) == idx.end())
return;
}
}
// seek to correct point in datafile
long s_offset = (*itemsiter).second;
auto s_offset = itemsiter->second;
fseek(fp, s_offset, SEEK_SET);
size_t tinfo = TAG_INFO.size();
auto tinfo = TAG_INFO.size();
char rbuf[64 * 1024];
std::string readbuf;
while (fgets(rbuf, 64 * 1024, fp) != nullptr)
@ -641,7 +526,7 @@ void datfile_manager::load_command_info(std::string &buffer, std::string &sel)
if (parseopen("command.dat"))
{
// open and seek to correct point in datafile
long offset = m_menuidx.at(sel);
auto offset = m_menuidx.at(sel);
fseek(fp, offset, SEEK_SET);
char rbuf[64 * 1024];
std::string readbuf;

View File

@ -71,7 +71,7 @@ private:
void init_messinfo();
void init_command();
void init_sysinfo();
void init_storyinfo();
void init_story();
void init_gameinit();
// file open/close/seek

View File

@ -111,7 +111,7 @@ void menu_dats_view::populate()
(m_issoft == true) ? get_data_sw() : get_data();
item_append(MENU_SEPARATOR_ITEM, nullptr, (FLAG_UI_DATS | FLAG_LEFT_ARROW | FLAG_RIGHT_ARROW), nullptr);
item_append(menu_item_type::SEPARATOR);
customtop = 2.0f * ui().get_line_height() + 4.0f * UI_BOX_TB_BORDER;
custombottom = ui().get_line_height() + 3.0f * UI_BOX_TB_BORDER;

View File

@ -108,7 +108,7 @@ menu_confirm_save_as::~menu_confirm_save_as()
void menu_confirm_save_as::populate()
{
item_append(_("File Already Exists - Override?"), nullptr, FLAG_DISABLE, nullptr);
item_append(MENU_SEPARATOR_ITEM, nullptr, FLAG_DISABLE, nullptr);
item_append(menu_item_type::SEPARATOR);
item_append(_("No"), nullptr, 0, ITEMREF_NO);
item_append(_("Yes"), nullptr, 0, ITEMREF_YES);
}

View File

@ -25,7 +25,8 @@ UINT16 inifile_manager::c_file = 0;
//-------------------------------------------------
inifile_manager::inifile_manager(running_machine &machine, ui_options &moptions)
: m_machine(machine), m_options(moptions)
: m_machine(machine)
, m_options(moptions)
{
ini_index.clear();
directory_scan();
@ -37,28 +38,15 @@ inifile_manager::inifile_manager(running_machine &machine, ui_options &moptions)
void inifile_manager::directory_scan()
{
// open extra INIs folder
file_enumerator path(m_options.extraini_path());
const osd_directory_entry *dir;
// loop into folder's file
while ((dir = path.next()) != nullptr)
{
int length = strlen(dir->name);
std::string filename(dir->name);
// check .ini file ending
if ((length > 4) && dir->name[length - 4] == '.' && tolower((UINT8)dir->name[length - 3]) == 'i' &&
tolower((UINT8)dir->name[length - 2]) == 'n' && tolower((UINT8)dir->name[length - 1]) == 'i')
if (core_filename_ends_with(dir->name, ".ini") && parseopen(dir->name))
{
// try to open file and indexing
if (parseopen(filename.c_str()))
{
init_category(filename);
parseclose();
}
init_category(std::string(dir->name));
parseclose();
}
}
// sort
std::stable_sort(ini_index.begin(), ini_index.end());
@ -68,30 +56,25 @@ void inifile_manager::directory_scan()
// initialize category
//-------------------------------------------------
void inifile_manager::init_category(std::string &filename)
void inifile_manager::init_category(std::string filename)
{
categoryindex index;
char rbuf[MAX_CHAR_INFO];
std::string readbuf, name;
std::string readbuf;
while (fgets(rbuf, MAX_CHAR_INFO, fp) != nullptr)
{
readbuf = rbuf;
if (readbuf[0] == '[')
if (rbuf[0] == '[')
{
size_t found = readbuf.find("]");
name = readbuf.substr(1, found - 1);
if (name == "FOLDER_SETTINGS" || name == "ROOT_FOLDER")
continue;
else
index.emplace_back(name, ftell(fp));
readbuf = rbuf;
auto name = readbuf.substr(1, readbuf.find("]") - 1);
if (name == "FOLDER_SETTINGS") continue;
index.emplace_back(name, ftell(fp));
}
}
// sort
std::stable_sort(index.begin(), index.end());
if (!index.empty())
ini_index.emplace_back(filename, index);
ini_index.emplace_back(strmakelower(filename), index);
}
//-------------------------------------------------
@ -103,17 +86,16 @@ void inifile_manager::load_ini_category(std::vector<int> &temp_filter)
if (ini_index.empty())
return;
bool search_clones = false;
auto search_clones = false;
std::string filename(ini_index[c_file].first);
long offset = ini_index[c_file].second[c_cat].second;
auto offset = ini_index[c_file].second[c_cat].second;
if (!core_stricmp(filename.c_str(), "category.ini") || !core_stricmp(filename.c_str(), "alltime.ini"))
if (filename == "category.ini" || filename == "alltime.ini")
search_clones = true;
if (parseopen(filename.c_str()))
{
fseek(fp, offset, SEEK_SET);
int num_game = driver_list::total();
char rbuf[MAX_CHAR_INFO];
std::string readbuf;
while (fgets(rbuf, MAX_CHAR_INFO, fp) != nullptr)
@ -123,20 +105,15 @@ void inifile_manager::load_ini_category(std::vector<int> &temp_filter)
if (readbuf.empty() || readbuf[0] == '[')
break;
int dfind = driver_list::find(readbuf.c_str());
if (dfind != -1 && search_clones)
auto dfind = driver_list::find(readbuf.c_str());
if (dfind != -1)
{
temp_filter.push_back(dfind);
int clone_of = driver_list::non_bios_clone(dfind);
if (clone_of == -1)
{
for (int x = 0; x < num_game; x++)
if (search_clones && driver_list::non_bios_clone(dfind) == -1)
for (int x = 0; x < driver_list::total(); x++)
if (readbuf == driver_list::driver(x).parent && readbuf != driver_list::driver(x).name)
temp_filter.push_back(x);
}
}
else if (dfind != -1)
temp_filter.push_back(dfind);
}
parseclose();
}
@ -148,9 +125,6 @@ void inifile_manager::load_ini_category(std::vector<int> &temp_filter)
bool inifile_manager::parseopen(const char *filename)
{
// MAME core file parsing functions fail in recognizing UNICODE chars in UTF-8 without BOM,
// so it's better and faster use standard C fileio functions.
emu_file file(m_options.extraini_path(), OPEN_FLAG_READ);
if (file.open(filename) != osd_file::error::NONE)
return false;
@ -173,7 +147,8 @@ bool inifile_manager::parseopen(const char *filename)
//-------------------------------------------------
favorite_manager::favorite_manager(running_machine &machine, ui_options &moptions)
: m_machine(machine), m_options(moptions)
: m_machine(machine)
, m_options(moptions)
{
m_current = -1;
parse_favorite();
@ -211,13 +186,13 @@ void favorite_manager::add_favorite_game()
return;
}
bool software_avail = false;
auto software_avail = false;
for (device_image_interface &image : image_interface_iterator(machine().root_device()))
{
if (image.exists() && image.software_entry())
{
const software_info *swinfo = image.software_entry();
const software_part *part = image.part_entry();
auto swinfo = image.software_entry();
auto part = image.part_entry();
ui_software_info tmpmatches;
tmpmatches.shortname = strensure(swinfo->shortname());
tmpmatches.longname = strensure(image.longname());
@ -234,7 +209,7 @@ void favorite_manager::add_favorite_game()
tmpmatches.parentlongname.clear();
if (swinfo->parentname())
{
software_list_device *swlist = software_list_device::find_by_name(machine().config(), image.software_list_name());
auto swlist = software_list_device::find_by_name(machine().config(), image.software_list_name());
for (software_info &c_swinfo : swlist->get_info())
{
std::string c_parent(c_swinfo.parentname());
@ -292,7 +267,7 @@ bool favorite_manager::isgame_favorite()
if ((machine().system().flags & MACHINE_TYPE_ARCADE) != 0)
return isgame_favorite(&machine().system());
bool image_loaded = false;
auto image_loaded = false;
for (device_image_interface &image : image_interface_iterator(machine().root_device()))
{
@ -384,7 +359,7 @@ void favorite_manager::parse_favorite()
tmpmatches.part = chartrimcarriage(readbuf);
file.gets(readbuf, 1024);
chartrimcarriage(readbuf);
int dx = driver_list::find(readbuf);
auto dx = driver_list::find(readbuf);
if (dx == -1) continue;
tmpmatches.driver = &driver_list::driver(dx);
file.gets(readbuf, 1024);

View File

@ -55,7 +55,7 @@ private:
std::vector<std::pair<std::string, categoryindex>> ini_index;
// init category index
void init_category(std::string &filename);
void init_category(std::string filename);
// init file index
void directory_scan();

View File

@ -37,12 +37,7 @@ namespace ui {
#define UI_MENU_POOL_SIZE 65536
#define MAX_ICONS_RENDER 40
struct arts_info
{
const char *title, *path;
};
static const arts_info arts_info[] =
static std::vector<std::pair<const char *, const char *>> arts_info =
{
{ __("Snapshots"), OPTION_SNAPSHOT_DIRECTORY },
{ __("Cabinets"), OPTION_CABINETS_PATH },
@ -61,7 +56,6 @@ static const arts_info arts_info[] =
{ __("Select"), OPTION_SELECT_PATH },
{ __("Marquees"), OPTION_MARQUEES_PATH },
{ __("Covers"), OPTION_COVER_PATH },
{ nullptr }
};
static const char *hover_msg[] = {
@ -90,10 +84,10 @@ std::unique_ptr<bitmap_argb32> menu::snapx_bitmap;
std::unique_ptr<bitmap_argb32> menu::no_avail_bitmap;
std::unique_ptr<bitmap_argb32> menu::star_bitmap;
std::unique_ptr<bitmap_argb32> menu::bgrnd_bitmap;
bitmap_argb32 *menu::icons_bitmap[MAX_ICONS_RENDER];
std::vector<std::unique_ptr<bitmap_argb32>> menu::icons_bitmap;
std::unique_ptr<bitmap_rgb32> menu::hilight_main_bitmap;
bitmap_argb32 *menu::toolbar_bitmap[UI_TOOLBAR_BUTTONS];
bitmap_argb32 *menu::sw_toolbar_bitmap[UI_TOOLBAR_BUTTONS];
std::vector<std::shared_ptr<bitmap_argb32>> menu::toolbar_bitmap;
std::vector<std::shared_ptr<bitmap_argb32>> menu::sw_toolbar_bitmap;
/***************************************************************************
INLINE FUNCTIONS
@ -106,7 +100,7 @@ bitmap_argb32 *menu::sw_toolbar_bitmap[UI_TOOLBAR_BUTTONS];
inline bool is_selectable(menu_item const &item)
{
return ((item.flags & (menu::FLAG_MULTILINE | menu::FLAG_DISABLE)) == 0 && strcmp(item.text, MENU_SEPARATOR_ITEM) != 0);
return ((item.flags & (menu::FLAG_MULTILINE | menu::FLAG_DISABLE)) == 0 && item.type != menu_item_type::SEPARATOR);
}
@ -322,7 +316,7 @@ void menu::item_append(menu_item item)
void menu::item_append(menu_item_type type)
{
if (type == menu_item_type::SEPARATOR)
item_append(MENU_SEPARATOR_ITEM, nullptr, 0, nullptr);
item_append(MENU_SEPARATOR_ITEM, nullptr, 0, nullptr, menu_item_type::SEPARATOR);
}
//-------------------------------------------------
@ -725,7 +719,7 @@ void menu::draw(UINT32 flags, float origx0, float origy0)
}
// if we're just a divider, draw a line
else if (strcmp(itemtext, MENU_SEPARATOR_ITEM) == 0)
else if (pitem.type == menu_item_type::SEPARATOR)
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
@ -1409,7 +1403,7 @@ void menu::init_ui(running_machine &machine, ui_options &mopt)
// allocate icons
for (int i = 0; i < MAX_ICONS_RENDER; i++)
{
icons_bitmap[i] = auto_alloc(machine, bitmap_argb32);
icons_bitmap.emplace_back(std::make_unique<bitmap_argb32>());
icons_texture[i] = mrender.texture_alloc();
}
@ -1436,28 +1430,28 @@ void menu::init_ui(running_machine &machine, ui_options &mopt)
// create a texture for toolbar
for (int x = 0; x < UI_TOOLBAR_BUTTONS; ++x)
{
toolbar_bitmap[x] = auto_alloc(machine, bitmap_argb32(32, 32));
sw_toolbar_bitmap[x] = auto_alloc(machine, bitmap_argb32(32, 32));
toolbar_bitmap.emplace_back(std::make_shared<bitmap_argb32>(32, 32));
sw_toolbar_bitmap.emplace_back(std::make_shared<bitmap_argb32>(32, 32));
toolbar_texture[x] = mrender.texture_alloc();
sw_toolbar_texture[x] = mrender.texture_alloc();
UINT32 *texture_dst = &toolbar_bitmap[x]->pix32(0);
UINT32 *texture_dst = &toolbar_bitmap.back()->pix32(0);
memcpy(texture_dst, toolbar_bitmap_bmp[x], 32 * 32 * sizeof(UINT32));
if (toolbar_bitmap[x]->valid())
toolbar_texture[x]->set_bitmap(*toolbar_bitmap[x], toolbar_bitmap[x]->cliprect(), TEXFORMAT_ARGB32);
if (toolbar_bitmap.back()->valid())
toolbar_texture[x]->set_bitmap(*toolbar_bitmap.back(), toolbar_bitmap.back()->cliprect(), TEXFORMAT_ARGB32);
else
toolbar_bitmap[x]->reset();
toolbar_bitmap.back()->reset();
if (x == 0 || x == 2)
{
texture_dst = &sw_toolbar_bitmap[x]->pix32(0);
memcpy(texture_dst, toolbar_bitmap_bmp[x], 32 * 32 * sizeof(UINT32));
if (sw_toolbar_bitmap[x]->valid())
sw_toolbar_texture[x]->set_bitmap(*sw_toolbar_bitmap[x], sw_toolbar_bitmap[x]->cliprect(), TEXFORMAT_ARGB32);
if (sw_toolbar_bitmap.back()->valid())
sw_toolbar_texture[x]->set_bitmap(*sw_toolbar_bitmap.back(), sw_toolbar_bitmap.back()->cliprect(), TEXFORMAT_ARGB32);
else
sw_toolbar_bitmap[x]->reset();
sw_toolbar_bitmap.back()->reset();
}
else
sw_toolbar_bitmap[x]->reset();
sw_toolbar_bitmap.back()->reset();
}
}
@ -1610,9 +1604,10 @@ void menu::draw_select_game(UINT32 flags)
hover = HOVER_ARROW_DOWN;
}
// if we're just a divider, draw a line
else if (strcmp(itemtext, MENU_SEPARATOR_ITEM) == 0)
else if (pitem.type == menu_item_type::SEPARATOR)
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_TEXT_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
// draw the item centered
else if (pitem.subtext == nullptr)
{
@ -1686,7 +1681,7 @@ void menu::draw_select_game(UINT32 flags)
highlight(container, line_x0, line_y0, line_x1, line_y1, bgcolor);
}
if (strcmp(itemtext, MENU_SEPARATOR_ITEM) == 0)
if (pitem.type == menu_item_type::SEPARATOR)
container->add_line(visible_left, line + 0.5f * line_height, visible_left + visible_width, line + 0.5f * line_height,
UI_LINE_WIDTH, UI_TEXT_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
else
@ -1731,21 +1726,21 @@ void menu::draw_select_game(UINT32 flags)
void menu::get_title_search(std::string &snaptext, std::string &searchstr)
{
// get arts title text
snaptext.assign(_(arts_info[ui_globals::curimage_view].title));
snaptext.assign(_(arts_info[ui_globals::curimage_view].first));
// get search path
std::string addpath;
if (ui_globals::curimage_view == SNAPSHOT_VIEW)
{
emu_options moptions;
searchstr = machine().options().value(arts_info[ui_globals::curimage_view].path);
addpath = moptions.value(arts_info[ui_globals::curimage_view].path);
searchstr = machine().options().value(arts_info[ui_globals::curimage_view].second);
addpath = moptions.value(arts_info[ui_globals::curimage_view].second);
}
else
{
ui_options moptions;
searchstr = ui().options().value(arts_info[ui_globals::curimage_view].path);
addpath = moptions.value(arts_info[ui_globals::curimage_view].path);
searchstr = ui().options().value(arts_info[ui_globals::curimage_view].second);
addpath = moptions.value(arts_info[ui_globals::curimage_view].second);
}
std::string tmp(searchstr);
@ -2266,7 +2261,7 @@ std::string menu::arts_render_common(float origx1, float origy1, float origx2, f
// apply title to right panel
for (int x = FIRST_VIEW; x < LAST_VIEW; x++)
{
ui().draw_text_full(container, _(arts_info[x].title), origx1, origy1, origx2 - origx1, JUSTIFY_CENTER,
ui().draw_text_full(container, _(arts_info[x].first), origx1, origy1, origx2 - origx1, JUSTIFY_CENTER,
WRAP_TRUNCATE, DRAW_NONE, rgb_t::white, rgb_t::black, &txt_lenght, nullptr);
txt_lenght += 0.01f;
title_size = MAX(txt_lenght, title_size);
@ -2320,16 +2315,11 @@ void menu::draw_toolbar(float x1, float y1, float x2, float y2, bool software)
y2 -= UI_BOX_TB_BORDER;
render_texture **t_texture = (software) ? sw_toolbar_texture : toolbar_texture;
bitmap_argb32 **t_bitmap = (software) ? sw_toolbar_bitmap : toolbar_bitmap;
auto t_bitmap = (software) ? sw_toolbar_bitmap : toolbar_bitmap;
int m_valid = 0;
for (int x = 0; x < UI_TOOLBAR_BUTTONS; ++x)
{
if (t_bitmap[x]->valid())
{
m_valid++;
}
}
for (auto & e : t_bitmap)
if (e->valid()) m_valid++;
float space_x = (y2 - y1) * container->manager().ui_aspect();
float total = (m_valid * space_x) + ((m_valid - 1) * 0.001f);
@ -2337,7 +2327,6 @@ void menu::draw_toolbar(float x1, float y1, float x2, float y2, bool software)
x2 = x1 + space_x;
for (int z = 0; z < UI_TOOLBAR_BUTTONS; ++z)
{
if (t_bitmap[z]->valid())
{
rgb_t color(0xEFEFEFEF);
@ -2353,7 +2342,6 @@ void menu::draw_toolbar(float x1, float y1, float x2, float y2, bool software)
x1 += space_x + ((z < UI_TOOLBAR_BUTTONS - 1) ? 0.001f : 0.0f);
x2 = x1 + space_x;
}
}
}
@ -2390,11 +2378,11 @@ void menu::arts_render_images(bitmap_argb32 *tmp_bitmap, float origx1, float ori
int panel_height_pixel = panel_height * screen_height;
// Calculate resize ratios for resizing
float ratioW = (float)panel_width_pixel / tmp_bitmap->width();
float ratioH = (float)panel_height_pixel / tmp_bitmap->height();
float ratioI = (float)tmp_bitmap->height() / tmp_bitmap->width();
int dest_xPixel = tmp_bitmap->width();
int dest_yPixel = tmp_bitmap->height();
auto ratioW = (float)panel_width_pixel / tmp_bitmap->width();
auto ratioH = (float)panel_height_pixel / tmp_bitmap->height();
auto ratioI = (float)tmp_bitmap->height() / tmp_bitmap->width();
auto dest_xPixel = tmp_bitmap->width();
auto dest_yPixel = tmp_bitmap->height();
// force 4:3 ratio min
if (ui().options().forced_4x3_snapshot() && ratioI < 0.75f && ui_globals::curimage_view == SNAPSHOT_VIEW)
@ -2451,9 +2439,9 @@ void menu::arts_render_images(bitmap_argb32 *tmp_bitmap, float origx1, float ori
void menu::draw_common_arrow(float origx1, float origy1, float origx2, float origy2, int current, int dmin, int dmax, float title_size)
{
float line_height = ui().get_line_height();
float lr_arrow_width = 0.4f * line_height * machine().render().ui_aspect();
float gutter_width = lr_arrow_width * 1.3f;
auto line_height = ui().get_line_height();
auto lr_arrow_width = 0.4f * line_height * machine().render().ui_aspect();
auto gutter_width = lr_arrow_width * 1.3f;
// set left-right arrows dimension
float ar_x0 = 0.5f * (origx2 + origx1) + 0.5f * title_size + gutter_width - lr_arrow_width;
@ -2504,9 +2492,9 @@ void menu::draw_common_arrow(float origx1, float origy1, float origx2, float ori
void menu::draw_icon(int linenum, void *selectedref, float x0, float y0)
{
static const game_driver *olddriver[MAX_ICONS_RENDER] = { nullptr };
float x1 = x0 + ui().get_line_height() * container->manager().ui_aspect(container);
float y1 = y0 + ui().get_line_height();
const game_driver *driver = (const game_driver *)selectedref;
auto x1 = x0 + ui().get_line_height() * container->manager().ui_aspect(container);
auto y1 = y0 + ui().get_line_height();
auto driver = (const game_driver *)selectedref;
if (olddriver[linenum] != driver || ui_globals::redraw_icon)
{
@ -2516,7 +2504,7 @@ void menu::draw_icon(int linenum, void *selectedref, float x0, float y0)
bool cloneof = strcmp(driver->parent, "0");
if (cloneof)
{
int cx = driver_list::find(driver->parent);
auto cx = driver_list::find(driver->parent);
if (cx != -1 && ((driver_list::driver(cx).flags & MACHINE_IS_BIOS_ROOT) != 0))
cloneof = false;
}
@ -2545,8 +2533,8 @@ void menu::draw_icon(int linenum, void *selectedref, float x0, float y0)
{
float panel_width = x1 - x0;
float panel_height = y1 - y0;
int screen_width = machine().render().ui_target().width();
int screen_height = machine().render().ui_target().height();
auto screen_width = machine().render().ui_target().width();
auto screen_height = machine().render().ui_target().height();
if (machine().render().ui_target().orientation() & ORIENTATION_SWAP_XY)
std::swap(screen_height, screen_width);
@ -2555,10 +2543,10 @@ void menu::draw_icon(int linenum, void *selectedref, float x0, float y0)
int panel_height_pixel = panel_height * screen_height;
// Calculate resize ratios for resizing
float ratioW = (float)panel_width_pixel / tmp->width();
float ratioH = (float)panel_height_pixel / tmp->height();
int dest_xPixel = tmp->width();
int dest_yPixel = tmp->height();
auto ratioW = (float)panel_width_pixel / tmp->width();
auto ratioH = (float)panel_height_pixel / tmp->height();
auto dest_xPixel = tmp->width();
auto dest_yPixel = tmp->height();
if (ratioW < 1 || ratioH < 1)
{
@ -2629,24 +2617,22 @@ void menu::info_arrow(int ub, float origx1, float origx2, float oy1, float line_
void menu::draw_palette_menu()
{
float line_height = ui().get_line_height();
float lr_arrow_width = 0.4f * line_height * machine().render().ui_aspect();
float ud_arrow_width = line_height * machine().render().ui_aspect();
float gutter_width = lr_arrow_width * 1.3f;
auto line_height = ui().get_line_height();
auto lr_arrow_width = 0.4f * line_height * machine().render().ui_aspect();
auto ud_arrow_width = line_height * machine().render().ui_aspect();
auto gutter_width = lr_arrow_width * 1.3f;
int itemnum, linenum;
if (ui().options().use_background_image() && &machine().system() == &GAME_NAME(___empty) && bgrnd_bitmap->valid())
container->add_quad(0.0f, 0.0f, 1.0f, 1.0f, rgb_t::white, bgrnd_texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
// compute the width and height of the full menu
float visible_width = 0;
float visible_main_menu_height = 0;
for (itemnum = 0; itemnum < item.size(); itemnum++)
auto visible_width = 0.0f;
auto visible_main_menu_height = 0.0f;
for (auto & pitem : item)
{
const menu_item &pitem = item[itemnum];
// compute width of left hand side
float total_width = gutter_width + ui().get_string_width(pitem.text) + gutter_width;
auto total_width = gutter_width + ui().get_string_width(pitem.text) + gutter_width;
// add in width of right hand side
if (pitem.subtext)
@ -2661,7 +2647,7 @@ void menu::draw_palette_menu()
}
// account for extra space at the top and bottom
float visible_extra_menu_height = customtop + custombottom;
auto visible_extra_menu_height = customtop + custombottom;
// add a little bit of slop for rounding
visible_width += 0.01f;
@ -2778,13 +2764,13 @@ void menu::draw_palette_menu()
}
// if we're just a divider, draw a line
else if (strcmp(itemtext, MENU_SEPARATOR_ITEM) == 0)
else if (pitem.type == menu_item_type::SEPARATOR)
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 == nullptr)
ui().draw_text_full(container, itemtext, effective_left, line_y, effective_width,
JUSTIFY_CENTER, WRAP_TRUNCATE, DRAW_NORMAL, fgcolor, bgcolor, nullptr, nullptr);
JUSTIFY_CENTER, WRAP_TRUNCATE, DRAW_NORMAL, fgcolor, bgcolor, nullptr, nullptr);
// otherwise, draw the item on the left and the subitem text on the right
else
@ -2817,9 +2803,9 @@ void menu::draw_palette_menu()
void menu::draw_dats_menu()
{
float line_height = ui().get_line_height();
float ud_arrow_width = line_height * machine().render().ui_aspect();
float gutter_width = 0.52f * line_height * machine().render().ui_aspect();
auto line_height = ui().get_line_height();
auto ud_arrow_width = 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_left = (1.0f - visible_width) * 0.5f;
@ -2938,7 +2924,7 @@ void menu::draw_dats_menu()
if (mouse_hit && line_x0 <= mouse_x && line_x1 > mouse_x && line_y0 <= mouse_y && line_y1 > mouse_y && is_selectable(pitem))
hover = count;
if (strcmp(itemtext, MENU_SEPARATOR_ITEM) == 0)
if (pitem.type == menu_item_type::SEPARATOR)
container->add_line(visible_left, line + 0.5f * line_height, visible_left + visible_width, line + 0.5f * line_height,
UI_LINE_WIDTH, UI_TEXT_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
else
@ -2973,7 +2959,7 @@ void menu::extra_text_draw_box(float origx1, float origx2, float origy, float ys
{
float text_width, text_height;
float width, maxwidth;
float x1, y1, x2, y2, temp;
float x1, y1, x2, y2;
// get the size of the text
ui().draw_text_full(container,text, 0.0f, 0.0f, 1.0f, JUSTIFY_LEFT, WRAP_WORD,
@ -2988,11 +2974,7 @@ void menu::extra_text_draw_box(float origx1, float origx2, float origy, float ys
y2 = origy + (UI_BOX_TB_BORDER * direction);
if (y1 > y2)
{
temp = y1;
y1 = y2;
y2 = temp;
}
std::swap(y1, y2);
// draw a box
ui().draw_outlined_box(container,x1, y1, x2, y2, UI_BACKGROUND_COLOR);
@ -3003,7 +2985,7 @@ void menu::extra_text_draw_box(float origx1, float origx2, float origy, float ys
// draw the text within it
ui().draw_text_full(container,text, x1, y1, text_width, JUSTIFY_LEFT, WRAP_WORD,
DRAW_NORMAL, rgb_t::white, rgb_t::black, nullptr, nullptr);
DRAW_NORMAL, rgb_t::white, rgb_t::black, nullptr, nullptr);
}
@ -3012,9 +2994,7 @@ void menu::extra_text_draw_box(float origx1, float origx2, float origy, float ys
// and footer text
//-------------------------------------------------
void menu::extra_text_render(float top, float bottom,
float origx1, float origy1, float origx2, float origy2,
const char *header, const char *footer)
void menu::extra_text_render(float top, float bottom, float origx1, float origy1, float origx2, float origy2, const char *header, const char *footer)
{
header = ((header != nullptr) && (header[0] != '\0')) ? header : nullptr;
footer = ((footer != nullptr) && (footer[0] != '\0')) ? footer : nullptr;

View File

@ -312,7 +312,7 @@ private:
static std::unique_ptr<bitmap_argb32> no_avail_bitmap, bgrnd_bitmap, star_bitmap;
static render_texture *bgrnd_texture, *star_texture;
static bitmap_argb32 *icons_bitmap[];
static std::vector<std::unique_ptr<bitmap_argb32>> icons_bitmap;
static render_texture *icons_texture[];
// request the specific handling of the game selection main menu
@ -322,7 +322,7 @@ private:
static void stack_push(std::unique_ptr<menu> &&menu);
// toolbar
static bitmap_argb32 *toolbar_bitmap[], *sw_toolbar_bitmap[];
static std::vector<std::shared_ptr<bitmap_argb32>> toolbar_bitmap, sw_toolbar_bitmap;
static render_texture *toolbar_texture[], *sw_toolbar_texture[];
// draw game list

View File

@ -450,12 +450,7 @@ void menu_crosshair::populate()
int length = strlen(dir->name);
/* look for files ending in .png with a name not larger then 9 chars*/
if ((length > 4) && (length <= CROSSHAIR_PIC_NAME_LENGTH + 4) &&
dir->name[length - 4] == '.' &&
tolower((UINT8)dir->name[length - 3]) == 'p' &&
tolower((UINT8)dir->name[length - 2]) == 'n' &&
tolower((UINT8)dir->name[length - 1]) == 'g')
if ((length > 4) && (length <= CROSSHAIR_PIC_NAME_LENGTH + 4) && core_filename_ends_with(dir->name, ".png"))
{
/* remove .png from length */
length -= 4;

View File

@ -590,7 +590,7 @@ void menu_select_game::populate()
}
}
item_append(MENU_SEPARATOR_ITEM, nullptr, FLAG_UI, nullptr);
item_append(menu_item_type::SEPARATOR);
// add special items
if (menu::stack_has_special_main_menu())

View File

@ -493,7 +493,7 @@ void menu_select_software::populate()
(void *)m_searchlist[curitem]);
}
item_append(MENU_SEPARATOR_ITEM, nullptr, flags_ui, nullptr);
item_append(menu_item_type::SEPARATOR);
// configure the custom rendering
customtop = 4.0f * ui().get_line_height() + 5.0f * UI_BOX_TB_BORDER;

View File

@ -92,6 +92,21 @@ int getprecisionchr(const char* s)
return precision;
}
std::vector<std::string> tokenize(const std::string &text, char sep)
{
std::vector<std::string> tokens;
std::size_t start = 0, end = 0;
while ((end = text.find(sep, start)) != std::string::npos)
{
std::string temp = text.substr(start, end - start);
if (!temp.empty()) tokens.push_back(temp);
start = end + 1;
}
std::string temp = text.substr(start);
if (!temp.empty()) tokens.push_back(temp);
return tokens;
}
//-------------------------------------------------
// search a substring with even partial matching
//-------------------------------------------------

View File

@ -242,15 +242,10 @@ struct sw_custfltr
};
// GLOBAL FUNCTIONS
// advanced search function
int fuzzy_substring(std::string needle, std::string haystack);
// trim carriage return
char* chartrimcarriage(char str[]);
const char* strensure(const char* s);
int getprecisionchr(const char* s);
std::vector<std::string> tokenize(const std::string &text, char sep);
#endif /* __UI_UTILS_H__ */