From 46f47615625e1a81d15df96d4ccfe5ac6f697888 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Fri, 25 Jan 2008 11:45:39 +0000 Subject: Fixed mutation menu miscolouring mutations. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3332 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/menu.cc | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'crawl-ref/source/menu.cc') diff --git a/crawl-ref/source/menu.cc b/crawl-ref/source/menu.cc index 81a16be254..58a3b1d450 100644 --- a/crawl-ref/source/menu.cc +++ b/crawl-ref/source/menu.cc @@ -51,19 +51,35 @@ Menu::Menu( const formatted_string &fs ) colour = op.x; break; case FSOP_TEXT: + { line += op.text; - if (op.text.find_first_not_of(" \t\r\n") != std::string::npos) + + const std::string::size_type nonblankp = + op.text.find_first_not_of(" \t\r\n"); + const bool nonblank = nonblankp != std::string::npos; + const std::string::size_type eolp = op.text.find(EOL); + const bool starts_with_eol = + nonblank && eolp != std::string::npos + && eolp < nonblankp; + + if (nonblank && !starts_with_eol) + last_text_colour = colour; + + check_add_formatted_line(last_text_colour, colour, line, true); + + if (nonblank && starts_with_eol) last_text_colour = colour; - check_add_formatted_line(last_text_colour, line, true); break; + } default: break; } } - check_add_formatted_line(colour, line, false); + check_add_formatted_line(last_text_colour, colour, line, false); } -void Menu::check_add_formatted_line(int col, std::string &line, bool check_eol) +void Menu::check_add_formatted_line(int firstcol, int nextcol, + std::string &line, bool check_eol) { if (line.empty()) return; @@ -81,8 +97,8 @@ void Menu::check_add_formatted_line(int col, std::string &line, bool check_eol) line = lines[--size]; else line.clear(); - - for (int i = 0; i < size; ++i) + + for (int i = 0, col = firstcol; i < size; ++i, col = nextcol) { std::string &s(lines[i]); -- cgit v1.2.3-54-g00ecf