From ea7bc5dd72ef330dd8e73b45c6bf039209cf013e Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Thu, 27 Jul 2017 13:19:12 +1000 Subject: don't use hairline spaces for alingment in the info box --- src/frontend/mame/ui/selgame.cpp | 86 ++++++++++++++++------------------------ src/frontend/mame/ui/selmenu.cpp | 77 +++++++++++++++++++++++++++++------ src/frontend/mame/ui/text.cpp | 15 +++++-- src/frontend/mame/ui/ui.cpp | 2 +- 4 files changed, 112 insertions(+), 68 deletions(-) diff --git a/src/frontend/mame/ui/selgame.cpp b/src/frontend/mame/ui/selgame.cpp index 06a1ec8ec59..93f39d19810 100644 --- a/src/frontend/mame/ui/selgame.cpp +++ b/src/frontend/mame/ui/selgame.cpp @@ -1188,50 +1188,52 @@ void menu_select_game::general_info(const game_driver *driver, std::string &buff { std::ostringstream str; - util::stream_format(str, _("Romset: %1$-.100s\n"), driver->name); - util::stream_format(str, _("Year: %1$s\n"), driver->year); - util::stream_format(str, _("Manufacturer: %1$-.100s\n"), driver->manufacturer); + str << "#j2\n"; + + util::stream_format(str, _("Romset\t%1$-.100s\n"), driver->name); + util::stream_format(str, _("Year\t%1$s\n"), driver->year); + util::stream_format(str, _("Manufacturer\t%1$-.100s\n"), driver->manufacturer); int cloneof = driver_list::non_bios_clone(*driver); if (cloneof != -1) - util::stream_format(str, _("Driver is Clone of: %1$-.100s\n"), driver_list::driver(cloneof).type.fullname()); + util::stream_format(str, _("Driver is Clone of\t%1$-.100s\n"), driver_list::driver(cloneof).type.fullname()); else - str << _("Driver is Parent:\n"); + str << _("Driver is Parent\t\n"); if (driver->flags & machine_flags::NOT_WORKING) - str << _("Overall: NOT WORKING\n"); + str << _("Overall\tNOT WORKING\n"); else if ((driver->type.unemulated_features() | driver->type.imperfect_features()) & device_t::feature::PROTECTION) - str << _("Overall: Unemulated Protection\n"); + str << _("Overall\tUnemulated Protection\n"); else - str << _("Overall: Working\n"); + str << _("Overall\tWorking\n"); if (driver->type.unemulated_features() & device_t::feature::GRAPHICS) - str << _("Graphics: Unimplemented\n"); + str << _("Graphics\tUnimplemented\n"); else if (driver->type.unemulated_features() & device_t::feature::PALETTE) - str << ("Graphics: Wrong Colors\n"); + str << ("Graphics\tWrong Colors\n"); else if (driver->type.imperfect_features() & device_t::feature::PALETTE) - str << _("Graphics: Imperfect Colors\n"); + str << _("Graphics\tImperfect Colors\n"); else if (driver->type.imperfect_features() & device_t::feature::GRAPHICS) - str << _("Graphics: Imperfect\n"); + str << _("Graphics\tImperfect\n"); else - str << _("Graphics: OK\n"); + str << _("Graphics\tOK\n"); if (driver->flags & machine_flags::NO_SOUND_HW) - str << _("Sound: None\n"); + str << _("Sound\tNone\n"); else if (driver->type.unemulated_features() & device_t::feature::SOUND) - str << _("Sound: Unimplemented\n"); + str << _("Sound\tUnimplemented\n"); else if (driver->type.imperfect_features() & device_t::feature::SOUND) - str << _("Sound: Imperfect\n"); + str << _("Sound\tImperfect\n"); else - str << _("Sound: OK\n"); - - util::stream_format(str, _("Game is Mechanical: %1$s\n"), ((driver->flags & machine_flags::MECHANICAL) ? _("Yes") : _("No"))); - util::stream_format(str, _("Requires Artwork: %1$s\n"), ((driver->flags & machine_flags::REQUIRES_ARTWORK) ? _("Yes") : _("No"))); - util::stream_format(str, _("Requires Clickable Artwork: %1$s\n"), ((driver->flags & machine_flags::CLICKABLE_ARTWORK) ? _("Yes") : _("No"))); - util::stream_format(str, _("Support Cocktail: %1$s\n"), ((driver->flags & machine_flags::NO_COCKTAIL) ? _("Yes") : _("No"))); - util::stream_format(str, _("Driver is Bios: %1$s\n"), ((driver->flags & machine_flags::IS_BIOS_ROOT) ? _("Yes") : _("No"))); - util::stream_format(str, _("Support Save: %1$s\n"), ((driver->flags & machine_flags::SUPPORTS_SAVE) ? _("Yes") : _("No"))); - util::stream_format(str, _("Screen Orientation: %1$s\n"), ((driver->flags & ORIENTATION_SWAP_XY) ? _("Vertical") : _("Horizontal"))); + str << _("Sound\tOK\n"); + + util::stream_format(str, _("Game is Mechanical\t%1$s\n"), ((driver->flags & machine_flags::MECHANICAL) ? _("Yes") : _("No"))); + util::stream_format(str, _("Requires Artwork\t%1$s\n"), ((driver->flags & machine_flags::REQUIRES_ARTWORK) ? _("Yes") : _("No"))); + util::stream_format(str, _("Requires Clickable Artwork\t%1$s\n"), ((driver->flags & machine_flags::CLICKABLE_ARTWORK) ? _("Yes") : _("No"))); + util::stream_format(str, _("Support Cocktail\t%1$s\n"), ((driver->flags & machine_flags::NO_COCKTAIL) ? _("Yes") : _("No"))); + util::stream_format(str, _("Driver is Bios\t%1$s\n"), ((driver->flags & machine_flags::IS_BIOS_ROOT) ? _("Yes") : _("No"))); + util::stream_format(str, _("Support Save\t%1$s\n"), ((driver->flags & machine_flags::SUPPORTS_SAVE) ? _("Yes") : _("No"))); + util::stream_format(str, _("Screen Orientation\t%1$s\n"), ((driver->flags & ORIENTATION_SWAP_XY) ? _("Vertical") : _("Horizontal"))); bool found = false; auto entries = rom_build_entries(driver->rom); for (const rom_entry &rom : entries) @@ -1240,7 +1242,7 @@ void menu_select_game::general_info(const game_driver *driver, std::string &buff found = true; break; } - util::stream_format(str, _("Requires CHD: %1$s\n"), found ? _("Yes") : _("No")); + util::stream_format(str, _("Requires CHD\t%1$s\n"), found ? _("Yes") : _("No")); // audit the game first to see if we're going to work if (ui().options().info_audit()) @@ -1253,38 +1255,20 @@ void menu_select_game::general_info(const game_driver *driver, std::string &buff // if everything looks good, schedule the new driver if (summary == media_auditor::CORRECT || summary == media_auditor::BEST_AVAILABLE || summary == media_auditor::NONE_NEEDED) - str << _("Roms Audit Pass: OK\n"); + str << _("Roms Audit Pass\tOK\n"); else - str << _("Roms Audit Pass: BAD\n"); + str << _("Roms Audit Pass\tBAD\n"); if (summary_samples == media_auditor::NONE_NEEDED) - str << _("Samples Audit Pass: None Needed\n"); + str << _("Samples Audit Pass\tNone Needed\n"); else if (summary_samples == media_auditor::CORRECT || summary_samples == media_auditor::BEST_AVAILABLE) - str << _("Samples Audit Pass: OK\n"); + str << _("Samples Audit Pass\tOK\n"); else - str << _("Samples Audit Pass: BAD\n"); + str << _("Samples Audit Pass\tBAD\n"); } else - str << _("Roms Audit Pass: Disabled\nSamples Audit Pass: Disabled\n"); - - std::istringstream istr(str.str()); - std::string line; - float spacewid = ui().get_char_width(0x200a); - str.clear(); - str.seekp(0); - str << "#jp\n"; - while(std::getline(istr, line)) - { - int nspace = floor((0.35 - ui().get_string_width(line.c_str())) / spacewid); - if(nspace < 5) - nspace = 5; - std::string newstr; - newstr.reserve((nspace * 3) + line.length()); - newstr.append(line.substr(0, line.find(':'))); - for(int i = 0; i < nspace; i++) - newstr.append("\xE2\x80\x8A"); - str << newstr.append(line.substr(line.find(':') + 1, line.npos)).append("\n"); - } + str << _("Roms Audit Pass\tDisabled\nSamples Audit Pass\tDisabled\n"); + buffer = str.str(); } diff --git a/src/frontend/mame/ui/selmenu.cpp b/src/frontend/mame/ui/selmenu.cpp index 09e001a972c..02deadc09e7 100644 --- a/src/frontend/mame/ui/selmenu.cpp +++ b/src/frontend/mame/ui/selmenu.cpp @@ -2452,9 +2452,21 @@ void menu_select_launch::infos_render(float origx1, float origy1, float origx2, draw_common_arrow(origx1, origy1, origx2, origy2, m_info_view, 0, total - 1, title_size); if (justify == 'f') - m_total_lines = ui().wrap_text(container(), m_info_buffer.c_str(), 0.0f, 0.0f, 1.0f - (2.0f * gutter_width), xstart, xend, text_size); + { + m_total_lines = ui().wrap_text( + container(), m_info_buffer.c_str(), + 0.0f, 0.0f, 1.0f - (2.0f * gutter_width), + xstart, xend, + text_size); + } else - m_total_lines = ui().wrap_text(container(), m_info_buffer.c_str(), origx1, origy1, origx2 - origx1 - (2.0f * gutter_width), xstart, xend, text_size); + { + m_total_lines = ui().wrap_text( + container(), m_info_buffer.c_str(), + origx1, origy1, origx2 - origx1 - (2.0f * gutter_width), + xstart, xend, + text_size); + } int r_visible_lines = floor((origy2 - oy1) / (line_height * text_size)); if (m_total_lines < r_visible_lines) @@ -2468,28 +2480,69 @@ void menu_select_launch::infos_render(float origx1, float origy1, float origx2, for (int r = 0; r < r_visible_lines; ++r) { int itemline = r + m_topline_datsview; - std::string tempbuf(m_info_buffer.substr(xstart[itemline], xend[itemline] - xstart[itemline])); + std::string const tempbuf(m_info_buffer.substr(xstart[itemline], xend[itemline] - xstart[itemline])); if (tempbuf[0] == '#') continue; - // up arrow - if (r == 0 && m_topline_datsview != 0) + if (r == 0 && m_topline_datsview != 0) // up arrow + { draw_info_arrow(0, origx1, origx2, oy1, line_height, text_size, ud_arrow_width); - // bottom arrow - else if (r == r_visible_lines - 1 && itemline != m_total_lines - 1) + } + else if (r == r_visible_lines - 1 && itemline != m_total_lines - 1) // bottom arrow + { draw_info_arrow(1, origx1, origx2, oy1, line_height, text_size, ud_arrow_width); + } + else if (justify == '2') // two-column layout + { + // split at first tab + std::string::size_type const splitpos(tempbuf.find('\t')); + std::string const leftcol(tempbuf.substr(0, (std::string::npos == splitpos) ? 0U : splitpos)); + std::string const rightcol(tempbuf.substr((std::string::npos == splitpos) ? 0U : (splitpos + 1U))); + + // measure space needed, condense if necessary + float const leftlen(ui().get_string_width(leftcol.c_str(), text_size)); + float const rightlen(ui().get_string_width(rightcol.c_str(), text_size)); + float const textlen(leftlen + rightlen); + float const tmp_size3((textlen > sc) ? (text_size * (sc / textlen)) : text_size); + + // draw in two parts + ui().draw_text_full( + container(), leftcol.c_str(), + origx1 + gutter_width, oy1, sc, + ui::text_layout::LEFT, ui::text_layout::TRUNCATE, + mame_ui_manager::NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, + nullptr, nullptr, + tmp_size3); + ui().draw_text_full( + container(), rightcol.c_str(), + origx1 + gutter_width, oy1, sc, + ui::text_layout::RIGHT, ui::text_layout::TRUNCATE, + mame_ui_manager::NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, + nullptr, nullptr, + tmp_size3); + } else if (justify == 'f' || justify == 'p') // full or partial justify { // check size - float textlen = ui().get_string_width(tempbuf.c_str(), text_size); + float const textlen = ui().get_string_width(tempbuf.c_str(), text_size); float tmp_size3 = (textlen > sc) ? text_size * (sc / textlen) : text_size; - ui().draw_text_full(container(), tempbuf.c_str(), origx1 + gutter_width, oy1, origx2 - origx1, ui::text_layout::LEFT, - ui::text_layout::TRUNCATE, mame_ui_manager::NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, nullptr, nullptr, tmp_size3); + ui().draw_text_full( + container(), tempbuf.c_str(), + origx1 + gutter_width, oy1, origx2 - origx1, + ui::text_layout::LEFT, ui::text_layout::TRUNCATE, + mame_ui_manager::NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, + nullptr, nullptr, + tmp_size3); } else { - ui().draw_text_full(container(), tempbuf.c_str(), origx1 + gutter_width, oy1, origx2 - origx1, ui::text_layout::LEFT, - ui::text_layout::TRUNCATE, mame_ui_manager::NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, nullptr, nullptr, text_size); + ui().draw_text_full( + container(), tempbuf.c_str(), + origx1 + gutter_width, oy1, origx2 - origx1, + ui::text_layout::LEFT, ui::text_layout::TRUNCATE, + mame_ui_manager::NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, + nullptr, nullptr, + text_size); } oy1 += (line_height * text_size); diff --git a/src/frontend/mame/ui/text.cpp b/src/frontend/mame/ui/text.cpp index f345fa7321d..6df9ff29049 100644 --- a/src/frontend/mame/ui/text.cpp +++ b/src/frontend/mame/ui/text.cpp @@ -18,6 +18,7 @@ namespace ui { + /*************************************************************************** INLINE FUNCTIONS ***************************************************************************/ @@ -82,8 +83,11 @@ CORE IMPLEMENTATION //------------------------------------------------- text_layout::text_layout(render_font &font, float xscale, float yscale, float width, text_layout::text_justify justify, text_layout::word_wrapping wrap) - : m_font(font), m_xscale(xscale), m_yscale(yscale), m_width(width), m_justify(justify), m_wrap(wrap), m_current_line(nullptr), m_last_break(0), m_text_position(0), m_truncating(false) - + : m_font(font) + , m_xscale(xscale), m_yscale(yscale) + , m_width(width) + , m_justify(justify), m_wrap(wrap) + , m_current_line(nullptr), m_last_break(0), m_text_position(0), m_truncating(false) { invalidate_calculated_actual_width(); } @@ -94,8 +98,11 @@ text_layout::text_layout(render_font &font, float xscale, float yscale, float wi //------------------------------------------------- text_layout::text_layout(text_layout &&that) - : m_font(that.m_font), m_xscale(that.m_xscale), m_yscale(that.m_yscale), m_width(that.m_width), m_calculated_actual_width(that.m_calculated_actual_width), m_justify(that.m_justify), m_wrap(that.m_wrap), m_lines(std::move(that.m_lines)), - m_current_line(that.m_current_line), m_last_break(that.m_last_break), m_text_position(that.m_text_position), m_truncating(false) + : m_font(that.m_font) + , m_xscale(that.m_xscale), m_yscale(that.m_yscale) + , m_width(that.m_width), m_calculated_actual_width(that.m_calculated_actual_width) + , m_justify(that.m_justify), m_wrap(that.m_wrap) + , m_lines(std::move(that.m_lines)), m_current_line(that.m_current_line), m_last_break(that.m_last_break), m_text_position(that.m_text_position), m_truncating(false) { that.invalidate_calculated_actual_width(); } diff --git a/src/frontend/mame/ui/ui.cpp b/src/frontend/mame/ui/ui.cpp index 28708a1d041..04a03f7fc44 100644 --- a/src/frontend/mame/ui/ui.cpp +++ b/src/frontend/mame/ui/ui.cpp @@ -2019,7 +2019,7 @@ int32_t mame_ui_manager::slider_crossoffset(running_machine &machine, void *arg, //------------------------------------------------- -// wrap_text +// create_layout //------------------------------------------------- ui::text_layout mame_ui_manager::create_layout(render_container &container, float width, ui::text_layout::text_justify justify, ui::text_layout::word_wrapping wrap) -- cgit v1.2.3