diff options
author | pauldubois <pauldubois@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-04-07 06:20:32 +0000 |
---|---|---|
committer | pauldubois <pauldubois@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-04-07 06:20:32 +0000 |
commit | 2f63d14e46fcb39b0021fb209f85207cddf7b404 (patch) | |
tree | 9bb9d77a3394ff6b159397308aeb2f8651ecb468 /crawl-ref/source/format.cc | |
parent | 149c6fb2d95c12bcd27c067929da23c8a8335f33 (diff) | |
download | crawl-ref-2f63d14e46fcb39b0021fb209f85207cddf7b404.tar.gz crawl-ref-2f63d14e46fcb39b0021fb209f85207cddf7b404.zip |
For David. Menu's draw_title_suffix can now accept a formatted_string
instead of a string. See example in StashSearchMenu::draw_title. If
you want everything in cyan, you might want to figure out who sets the
StashSearchMenu's title->color and change that, too.
Added formatted_string::substr(). Lightly tested, seems to work fine.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@4091 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/format.cc')
-rw-r--r-- | crawl-ref/source/format.cc | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/crawl-ref/source/format.cc b/crawl-ref/source/format.cc index ea97f21b4d..f9cc90a28f 100644 --- a/crawl-ref/source/format.cc +++ b/crawl-ref/source/format.cc @@ -406,6 +406,62 @@ int formatted_string::find_last_colour() const return (LIGHTGREY); } +formatted_string formatted_string::substr(size_t start, size_t substr_length) const +{ + const unsigned int NONE = (unsigned int)-1; + unsigned int last_FSOP_COLOUR = NONE; + unsigned int last_FSOP_CURSOR = NONE; + + // Find the first string to copy + unsigned int i; + for (i=0; i<ops.size(); ++i) + { + const fs_op& op = ops[i]; + if (op.type == FSOP_COLOUR) + last_FSOP_CURSOR = i; + else if (op.type == FSOP_CURSOR) + last_FSOP_CURSOR = i; + else if (op.type == FSOP_TEXT) + if (op.text.length() > start) + break; + else + start -= op.text.length(); + } + + if (i == ops.size()) + return formatted_string(); + + formatted_string result; + // set up the state + if (last_FSOP_COLOUR != NONE) + result.ops.push_back(ops[last_FSOP_COLOUR]); + if (last_FSOP_CURSOR != NONE) + result.ops.push_back(ops[last_FSOP_CURSOR]); + + // Copy the text + for ( ; i<ops.size(); i++) + { + const fs_op& op = ops[i]; + if (op.type == FSOP_TEXT) + { + result.ops.push_back(op); + std::string& new_string = result.ops[result.ops.size()-1].text; + if (start > 0 || op.text.length() > substr_length) + new_string = new_string.substr(start, substr_length); + + substr_length -= new_string.length(); + if (substr_length == 0) + break; + } + else + { + result.ops.push_back(op); + } + } + + return result; +} + void formatted_string::add_glyph(const item_def *item) { const int last_col = find_last_colour(); |