From d131ce057a429833e086b60cebeda46e062d07a1 Mon Sep 17 00:00:00 2001 From: haranp Date: Sun, 26 Nov 2006 14:54:48 +0000 Subject: New overview screen (the 'O' screen.) This involves changes in quite a few things, so the major savefile version is now 1, and old savefiles *will not load*! Lots of conditional loading code has therefore been removed. Minor savefile version dropped to 0 in everything. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@495 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/menu.cc | 75 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) (limited to 'crawl-ref/source/menu.cc') diff --git a/crawl-ref/source/menu.cc b/crawl-ref/source/menu.cc index c804c5343b..204ffc5b3a 100644 --- a/crawl-ref/source/menu.cc +++ b/crawl-ref/source/menu.cc @@ -1017,9 +1017,9 @@ void formatted_string::display(int s, int e) const { int size = ops.size(); if (!size) - return ; + return; - cap(s, size); + cap(s, size); cap(e, size); for (int i = s; i <= e && i < size; ++i) @@ -1205,3 +1205,74 @@ void column_composer::compose_formatted_column( flines[f] += lines[i]; } } + +formatted_scroller::formatted_scroller(int _flags, const std::string& s) : + Menu(_flags) +{ + size_t eolpos = 0; + while ( true ) + { + const size_t newpos = s.find( EOL, eolpos ); + add_entry(new MenuEntry(std::string(s, eolpos, newpos-eolpos))); + if ( newpos == std::string::npos ) + break; + else + eolpos = newpos + strlen(EOL); + } +} + +void formatted_scroller::draw_item(int index, const MenuEntry *me) const +{ + formatted_string::parse_string(me->text).display(); +} + +int linebreak_string( std::string& s, int wrapcol, int maxcol ) +{ + size_t loc = 0; + int xpos = 0; + int breakcount = 0; + while ( loc < s.size() ) + { + if ( s[loc] == '<' ) // tag + { + // << escape + if ( loc + 1 < s.size() && s[loc+1] == '<' ) + { + ++xpos; + loc += 2; + // Um, we never break on <<. That's a feature. Right. + continue; + } + // skip tag + while ( loc < s.size() && s[loc] != '>' ) + ++loc; + ++loc; + } + else + { + // user-forced newline + if ( s[loc] == '\n' ) + xpos = 0; + // soft linebreak + else if ( s[loc] == ' ' && xpos > wrapcol ) + { + s.replace(loc, 1, EOL); + xpos = 0; + ++breakcount; + } + // hard linebreak + else if ( xpos > maxcol ) + { + s.insert(loc, EOL); + xpos = 0; + ++breakcount; + } + // bog-standard + else + ++xpos; + + ++loc; + } + } + return breakcount; +} -- cgit v1.2.3-54-g00ecf