summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-01-03 20:54:20 +0000
committerrubidium <rubidium@openttd.org>2011-01-03 20:54:20 +0000
commit80591d73c1d0827f1f20685ae7c93172a7fea217 (patch)
tree3f4c2ca5afcad2534afeb73da95a9e4ffb4f28d0 /src
parentb68d37f2aa6479d9988aca2fe53af09701b7cd58 (diff)
downloadopenttd-80591d73c1d0827f1f20685ae7c93172a7fea217.tar.xz
(svn r21707) -Fix [FS#4371]: bit too strict assertion on validness of console colours
Diffstat (limited to 'src')
-rw-r--r--src/console_func.h2
-rw-r--r--src/console_gui.cpp21
-rw-r--r--src/console_type.h6
3 files changed, 23 insertions, 6 deletions
diff --git a/src/console_func.h b/src/console_func.h
index aa220a998..6f58bdf54 100644
--- a/src/console_func.h
+++ b/src/console_func.h
@@ -32,4 +32,6 @@ void IConsoleError(const char *string);
/* Parser */
void IConsoleCmdExec(const char *cmdstr);
+bool IsValidConsoleColour(TextColour c);
+
#endif /* CONSOLE_FUNC_H */
diff --git a/src/console_gui.cpp b/src/console_gui.cpp
index 875e78d05..dd3f065ef 100644
--- a/src/console_gui.cpp
+++ b/src/console_gui.cpp
@@ -494,3 +494,24 @@ void IConsoleGUIPrint(TextColour colour_code, char *str)
new IConsoleLine(str, colour_code);
SetWindowDirty(WC_CONSOLE, 0);
}
+
+
+/**
+ * Check whether the given TextColour is valid for console usage.
+ * @param c The text colour to compare to.
+ * @return true iff the TextColour is valid for console usage.
+ */
+bool IsValidConsoleColour(TextColour c)
+{
+ /* A normal text colour is used. */
+ if (!(c & TC_IS_PALETTE_COLOUR)) return TC_BEGIN <= c && c < TC_END;
+
+ /* A text colour from the palette is used; must be the company
+ * colour gradient, so it must be one of those. */
+ c &= ~TC_IS_PALETTE_COLOUR;
+ for (uint i = TC_BEGIN; i < TC_END; i++) {
+ if (_colour_gradient[i][4] == c) return true;
+ }
+
+ return false;
+}
diff --git a/src/console_type.h b/src/console_type.h
index 2a99a7038..b62d5d9c4 100644
--- a/src/console_type.h
+++ b/src/console_type.h
@@ -30,10 +30,4 @@ static const TextColour CC_DEBUG = TC_LIGHT_BROWN; ///< Colour for debug outpu
static const TextColour CC_COMMAND = TC_GOLD; ///< Colour for the console's commands.
static const TextColour CC_WHITE = TC_WHITE; ///< White console lines for various things such as the welcome.
-static inline bool IsValidConsoleColour(uint c)
-{
- return c == CC_DEFAULT || c == CC_ERROR || c == CC_WARNING || c == CC_INFO ||
- c == CC_DEBUG || c == CC_COMMAND || c == CC_WHITE;
-}
-
#endif /* CONSOLE_TYPE_H */