diff options
author | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2006-11-26 14:54:48 +0000 |
---|---|---|
committer | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2006-11-26 14:54:48 +0000 |
commit | d131ce057a429833e086b60cebeda46e062d07a1 (patch) | |
tree | 44e28d6b6eaa360a454c6ef5cadd9ffcaaa1af88 /crawl-ref/source/menu.cc | |
parent | f278a501a1598647a72dae0a086d8c7221e34727 (diff) | |
download | crawl-ref-d131ce057a429833e086b60cebeda46e062d07a1.tar.gz crawl-ref-d131ce057a429833e086b60cebeda46e062d07a1.zip |
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
Diffstat (limited to 'crawl-ref/source/menu.cc')
-rw-r--r-- | crawl-ref/source/menu.cc | 75 |
1 files changed, 73 insertions, 2 deletions
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; +} |