diff options
author | alberth <alberth@openttd.org> | 2010-07-02 13:44:36 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2010-07-02 13:44:36 +0000 |
commit | 3d329beb1b9a882fbc6530817a169ab6588e646f (patch) | |
tree | cfff91897c251647d1526145f9bd6443b64d4821 /src | |
parent | d7a6ba47810f3b283eb57f4efec4e8ee64325304 (diff) | |
download | openttd-3d329beb1b9a882fbc6530817a169ab6588e646f.tar.xz |
(svn r20042) -Codechange: Add set methods to DrawStringParams.
Diffstat (limited to 'src')
-rw-r--r-- | src/gfx.cpp | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp index a16a1bbfa..a151d3676 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -62,12 +62,36 @@ static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode, /** * Text drawing parameters, which can change while drawing a line, but are kept between multiple parts * of the same text, e.g. on line breaks. - **/ + */ struct DrawStringParams { FontSize fontsize; TextColour cur_colour, prev_colour; DrawStringParams(TextColour colour) : fontsize(FS_NORMAL), cur_colour(colour), prev_colour(colour) {} + + /** Switch to new colour \a c. + * @param c New colour to use. + */ + FORCEINLINE void SetColour(TextColour c) + { + assert(c >= TC_BLUE && c <= TC_BLACK); + this->prev_colour = this->cur_colour; + this->cur_colour = c; + } + + /** Switch to previous colour. */ + FORCEINLINE void SetPreviousColour() + { + Swap(this->cur_colour, this->prev_colour); + } + + /** Switch to using a new font \a f. + * @param f New font to use. + */ + FORCEINLINE void SetFontSize(FontSize f) + { + this->fontsize = f; + } }; static ReusableBuffer<uint8> _cursor_backup; @@ -988,19 +1012,18 @@ skip_cont:; y += GetCharacterHeight(params.fontsize); goto check_bounds; } else if (c >= SCC_BLUE && c <= SCC_BLACK) { // change colour? - params.prev_colour = params.cur_colour; - params.cur_colour = (TextColour)(c - SCC_BLUE); + params.SetColour((TextColour)(c - SCC_BLUE)); goto switch_colour; } else if (c == SCC_PREVIOUS_COLOUR) { // revert to the previous colour - Swap(params.cur_colour, params.prev_colour); + params.SetPreviousColour(); goto switch_colour; } else if (c == SCC_SETX || c == SCC_SETXY) { // {SETX}/{SETXY} /* The characters are handled before calling this. */ NOT_REACHED(); } else if (c == SCC_TINYFONT) { // {TINYFONT} - params.fontsize = FS_SMALL; + params.SetFontSize(FS_SMALL); } else if (c == SCC_BIGFONT) { // {BIGFONT} - params.fontsize = FS_LARGE; + params.SetFontSize(FS_LARGE); } else { DEBUG(misc, 0, "[utf8] unknown string command character %d", c); } |