From c3b7a9e470b8a8675e2c14a6aad1e56eb431cac9 Mon Sep 17 00:00:00 2001 From: Nathan Woods Date: Sat, 18 Jun 2016 10:07:48 -0400 Subject: [PATCH] word_wrapping::TRUNCATE was completely broken; this fixes it --- src/frontend/mame/ui/text.cpp | 17 ++++++++++------- src/frontend/mame/ui/text.h | 1 + 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/frontend/mame/ui/text.cpp b/src/frontend/mame/ui/text.cpp index c029c410ff4..e4d61dc1238 100644 --- a/src/frontend/mame/ui/text.cpp +++ b/src/frontend/mame/ui/text.cpp @@ -78,7 +78,7 @@ 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_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) { } @@ -90,7 +90,7 @@ 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_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_current_line(that.m_current_line), m_last_break(that.m_last_break), m_text_position(that.m_text_position), m_truncating(false) { } @@ -162,7 +162,7 @@ void text_layout::add_text(const char *text, const char_style &style) update_maximum_line_width(); m_current_line = nullptr; } - else + else if (!m_truncating) { // if we hit a space, remember the location and width *without* the space if (is_space_character(ch)) @@ -250,6 +250,7 @@ void text_layout::start_new_line(text_layout::text_justify justify, float height update_maximum_line_width(); m_current_line = new_line.get(); m_last_break = 0; + m_truncating = false; // append it m_lines.push_back(std::move(new_line)); @@ -272,6 +273,8 @@ float text_layout::get_char_width(unicode_char ch, float size) void text_layout::truncate_wrap() { + const unicode_char elipsis = 0x2026; + // for now, lets assume that we're only truncating the last character size_t truncate_position = m_current_line->character_count() - 1; const auto& truncate_char = m_current_line->character(truncate_position); @@ -285,7 +288,7 @@ void text_layout::truncate_wrap() source.span = 0; // figure out how wide an elipsis is - float elipsis_width = 3 * get_char_width('.', style.size); + float elipsis_width = get_char_width(elipsis, style.size); // where should we really truncate from? while (truncate_position > 0 && m_current_line->character(truncate_position).xoffset + elipsis_width < width()) @@ -295,10 +298,10 @@ void text_layout::truncate_wrap() m_current_line->truncate(truncate_position); // and append the elipsis - m_current_line->add_character('.', style, source); + m_current_line->add_character(elipsis, style, source); - // finally start a new line - start_new_line(m_current_line->justify(), style.size); + // take note that we are truncating; supress new characters + m_truncating = true; } diff --git a/src/frontend/mame/ui/text.h b/src/frontend/mame/ui/text.h index 791aff9b112..d39f40bd4e0 100644 --- a/src/frontend/mame/ui/text.h +++ b/src/frontend/mame/ui/text.h @@ -145,6 +145,7 @@ private: line *m_current_line; size_t m_last_break; size_t m_text_position; + bool m_truncating; // methods void add_text(const char *text, const char_style &style);