diff options
author | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2006-11-29 18:12:52 +0000 |
---|---|---|
committer | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2006-11-29 18:12:52 +0000 |
commit | 61b0a568e4ac1a1c2c7fb8d038144488c0cd14d2 (patch) | |
tree | 1fb3a52208649aad9190b3640726ed0d0cb56dec /crawl-ref/source/menu.cc | |
parent | 828402203ba5dabe03082ad8a0768a4b6a66e542 (diff) | |
download | crawl-ref-61b0a568e4ac1a1c2c7fb8d038144488c0cd14d2.tar.gz crawl-ref-61b0a568e4ac1a1c2c7fb8d038144488c0cd14d2.zip |
Redid how the resists screen works (both in-game and in-dump.)
Minor notes refactoring.
Added a basic notes browser on '_'.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@528 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/menu.cc')
-rw-r--r-- | crawl-ref/source/menu.cc | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/crawl-ref/source/menu.cc b/crawl-ref/source/menu.cc index 47a3e6a653..df4c012930 100644 --- a/crawl-ref/source/menu.cc +++ b/crawl-ref/source/menu.cc @@ -1276,21 +1276,50 @@ void column_composer::compose_formatted_column( formatted_scroller::formatted_scroller(int _flags, const std::string& s) : Menu(_flags) { + add_text(s); +} + +void formatted_scroller::add_text(const std::string& s) +{ size_t eolpos = 0; while ( true ) { - const size_t newpos = s.find( EOL, eolpos ); - add_entry(new MenuEntry(std::string(s, eolpos, newpos-eolpos))); + const size_t newpos = s.find( "\n", eolpos ); + add_item_formatted_string(formatted_string::parse_string(std::string(s, eolpos, newpos-eolpos))); if ( newpos == std::string::npos ) break; else - eolpos = newpos + strlen(EOL); - } + eolpos = newpos + 1; + } +} + +void formatted_scroller::add_item_formatted_string(const formatted_string& fs) +{ + MenuEntry* me = new MenuEntry; + me->data = new formatted_string(fs); + add_entry(me); +} + +void formatted_scroller::add_item_string(const std::string& s) +{ + add_entry( new MenuEntry(s) ); } void formatted_scroller::draw_index_item(int index, const MenuEntry *me) const { - formatted_string::parse_string(me->text).display(); + if ( me->data == NULL ) + Menu::draw_index_item(index, me); + else + static_cast<formatted_string*>(me->data)->display(); +} + +formatted_scroller::~formatted_scroller() +{ + // very important: this destructor is called *before* the + // base (Menu) class destructor...which is at it should be. + for ( unsigned i = 0; i < items.size(); ++i ) + if ( items[i]->data != NULL ) + delete static_cast<formatted_string*>(items[i]->data); } int linebreak_string( std::string& s, int wrapcol, int maxcol ) @@ -1323,14 +1352,14 @@ int linebreak_string( std::string& s, int wrapcol, int maxcol ) // soft linebreak else if ( s[loc] == ' ' && xpos > wrapcol ) { - s.replace(loc, 1, EOL); + s.replace(loc, 1, "\n"); xpos = 0; ++breakcount; } // hard linebreak else if ( xpos > maxcol ) { - s.insert(loc, EOL); + s.insert(loc, "\n"); xpos = 0; ++breakcount; } |