summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2010-07-02 13:44:36 +0000
committeralberth <alberth@openttd.org>2010-07-02 13:44:36 +0000
commit3d329beb1b9a882fbc6530817a169ab6588e646f (patch)
treecfff91897c251647d1526145f9bd6443b64d4821
parentd7a6ba47810f3b283eb57f4efec4e8ee64325304 (diff)
downloadopenttd-3d329beb1b9a882fbc6530817a169ab6588e646f.tar.xz
(svn r20042) -Codechange: Add set methods to DrawStringParams.
-rw-r--r--src/gfx.cpp35
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);
}