summaryrefslogtreecommitdiff
path: root/src/gfx_layout.h
diff options
context:
space:
mode:
authorPeterN <peter@fuzzle.org>2018-04-19 19:33:21 +0100
committerGitHub <noreply@github.com>2018-04-19 19:33:21 +0100
commit3b32075e8a3440c9bca8764289c0b1e3c2f4c28d (patch)
treecc5dde691f49ec264e0f932bb2ad56a689dc3c80 /src/gfx_layout.h
parentf4f9e18790b23862239164721dba831756ae24d7 (diff)
downloadopenttd-3b32075e8a3440c9bca8764289c0b1e3c2f4c28d.tar.xz
Add: {PUSH_COLOUR} and {POP_COLOUR} control codes to handle switching colours. (#6737)
This replaces the internal SCC_PREVIOUS_COLOUR swap.
Diffstat (limited to 'src/gfx_layout.h')
-rw-r--r--src/gfx_layout.h29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/gfx_layout.h b/src/gfx_layout.h
index 0a21d9b0c..45d79ae47 100644
--- a/src/gfx_layout.h
+++ b/src/gfx_layout.h
@@ -18,6 +18,7 @@
#include <map>
#include <string>
+#include <stack>
#ifdef WITH_ICU_LAYOUT
#include "layout/ParagraphLayout.h"
@@ -33,10 +34,11 @@
struct FontState {
FontSize fontsize; ///< Current font size.
TextColour cur_colour; ///< Current text colour.
- TextColour prev_colour; ///< Text colour from before the last colour switch.
- FontState() : fontsize(FS_END), cur_colour(TC_INVALID), prev_colour(TC_INVALID) {}
- FontState(TextColour colour, FontSize fontsize) : fontsize(fontsize), cur_colour(colour), prev_colour(colour) {}
+ std::stack<TextColour> colour_stack; ///< Stack of colours to assist with colour switching.
+
+ FontState() : fontsize(FS_END), cur_colour(TC_INVALID) {}
+ FontState(TextColour colour, FontSize fontsize) : fontsize(fontsize), cur_colour(colour) {}
/**
* Switch to new colour \a c.
@@ -45,14 +47,25 @@ struct FontState {
inline 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. */
- inline void SetPreviousColour()
+ /**
+ * Switch to and pop the last saved colour on the stack.
+ */
+ inline void PopColour()
+ {
+ if (colour_stack.empty()) return;
+ SetColour(colour_stack.top());
+ colour_stack.pop();
+ }
+
+ /**
+ * Push the current colour on to the stack.
+ */
+ inline void PushColour()
{
- Swap(this->cur_colour, this->prev_colour);
+ colour_stack.push(this->cur_colour);
}
/**
@@ -149,7 +162,7 @@ class Layouter : public AutoDeleteSmallVector<const ParagraphLayouter::Line *, 4
{
if (this->state_before.fontsize != other.state_before.fontsize) return this->state_before.fontsize < other.state_before.fontsize;
if (this->state_before.cur_colour != other.state_before.cur_colour) return this->state_before.cur_colour < other.state_before.cur_colour;
- if (this->state_before.prev_colour != other.state_before.prev_colour) return this->state_before.prev_colour < other.state_before.prev_colour;
+ if (this->state_before.colour_stack != other.state_before.colour_stack) return this->state_before.colour_stack < other.state_before.colour_stack;
return this->str < other.str;
}
};