summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-02-09 02:09:47 +0000
committerrubidium <rubidium@openttd.org>2009-02-09 02:09:47 +0000
commit8dae160d0f1065ff40ecddc518b3905820f77f7a (patch)
tree36a060def733fe274859ec2afcbf3478faf2e63c /src
parent861e9cefb3c31f1cab46ddb068af7a3648f45b4a (diff)
downloadopenttd-8dae160d0f1065ff40ecddc518b3905820f77f7a.tar.xz
(svn r15425) -Codechange: some color->colour changes and type safety.
Diffstat (limited to 'src')
-rw-r--r--src/ai/ai_gui.cpp2
-rw-r--r--src/airport_gui.cpp2
-rw-r--r--src/console_gui.cpp14
-rw-r--r--src/gfx.cpp170
-rw-r--r--src/gfx_func.h30
-rw-r--r--src/gfx_type.h7
-rw-r--r--src/network/network.cpp14
-rw-r--r--src/network/network_chat_gui.cpp8
-rw-r--r--src/network/network_func.h3
-rw-r--r--src/news_gui.cpp6
-rw-r--r--src/table/palettes.h2
-rw-r--r--src/toolbar_gui.cpp2
-rw-r--r--src/town_gui.cpp2
-rw-r--r--src/viewport.cpp4
-rw-r--r--src/widget.cpp2
15 files changed, 134 insertions, 134 deletions
diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp
index 8827601bc..5fd9d87db 100644
--- a/src/ai/ai_gui.cpp
+++ b/src/ai/ai_gui.cpp
@@ -674,7 +674,7 @@ struct AIDebugWindow : public Window {
uint pos = (log->count + log->pos - i) % log->count;
if (log->lines[pos] == NULL) break;
- uint colour;
+ TextColour colour;
switch (log->type[pos]) {
case AILog::LOG_SQ_INFO: colour = TC_BLACK; break;
case AILog::LOG_SQ_ERROR: colour = TC_RED; break;
diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp
index 43fc6e78a..a7cd7f120 100644
--- a/src/airport_gui.cpp
+++ b/src/airport_gui.cpp
@@ -228,7 +228,7 @@ public:
if (_settings_game.economy.station_noise_level) {
/* show the noise of the selected airport */
SetDParam(0, airport->noise_level);
- DrawString(2, 206, STR_STATION_NOISE, 0);
+ DrawString(2, 206, STR_STATION_NOISE, TC_FROMSTRING);
y_noise_offset = 10;
}
diff --git a/src/console_gui.cpp b/src/console_gui.cpp
index c80c9d7c1..30de4f58b 100644
--- a/src/console_gui.cpp
+++ b/src/console_gui.cpp
@@ -31,16 +31,16 @@ struct IConsoleLine {
static int size; ///< The amount of items in the backlog
IConsoleLine *previous; ///< The previous console message.
- char *buffer; ///< The data to store.
- uint16 colour; ///< The colour of the line.
- uint16 time; ///< The amount of time the line is in the backlog.
+ char *buffer; ///< The data to store.
+ TextColour colour; ///< The colour of the line.
+ uint16 time; ///< The amount of time the line is in the backlog.
/**
* Initialize the console line.
* @param buffer the data to print.
* @param colour the colour of the line.
*/
- IConsoleLine(char *buffer, uint16 colour) :
+ IConsoleLine(char *buffer, TextColour colour) :
previous(IConsoleLine::front),
buffer(buffer),
colour(colour),
@@ -172,11 +172,11 @@ struct IConsoleWindow : Window
/* If the text is longer than the window, don't show the starting ']' */
int delta = this->width - 10 - _iconsole_cmdline.width - ICON_RIGHT_BORDERWIDTH;
if (delta > 0) {
- DoDrawString("]", 5, this->height - ICON_LINE_HEIGHT, CC_COMMAND);
+ DoDrawString("]", 5, this->height - ICON_LINE_HEIGHT, (TextColour)CC_COMMAND);
delta = 0;
}
- DoDrawString(_iconsole_cmdline.buf, 10 + delta, this->height - ICON_LINE_HEIGHT, CC_COMMAND);
+ DoDrawString(_iconsole_cmdline.buf, 10 + delta, this->height - ICON_LINE_HEIGHT, (TextColour)CC_COMMAND);
if (_focused_window == this && _iconsole_cmdline.caret) {
DoDrawString("_", 10 + delta + _iconsole_cmdline.caretxoffs, this->height - ICON_LINE_HEIGHT, TC_WHITE);
@@ -442,6 +442,6 @@ static void IConsoleHistoryNavigate(int direction)
*/
void IConsoleGUIPrint(ConsoleColour color_code, char *str)
{
- new IConsoleLine(str, color_code);
+ new IConsoleLine(str, (TextColour)color_code);
SetWindowDirty(FindWindowById(WC_CONSOLE, 0));
}
diff --git a/src/gfx.cpp b/src/gfx.cpp
index af699c665..18bdb5d20 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -47,7 +47,7 @@ DrawPixelInfo *_cur_dpi;
byte _colour_gradient[COLOUR_END][8];
static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub = NULL);
-static int ReallyDoDrawString(const char *string, int x, int y, uint16 real_colour, bool parse_string_also_when_clipped = false);
+static int ReallyDoDrawString(const char *string, int x, int y, TextColour colour, bool parse_string_also_when_clipped = false);
FontSize _cur_fontsize;
static FontSize _last_fontsize;
@@ -61,8 +61,8 @@ static uint8 _cursor_backup[64 * 64 * 4];
* @ingroup dirty
*/
static Rect _invalid_rect;
-static const byte *_color_remap_ptr;
-static byte _string_colorremap[3];
+static const byte *_colour_remap_ptr;
+static byte _string_colourremap[3];
enum {
DIRTY_BLOCK_HEIGHT = 8,
@@ -97,13 +97,13 @@ void GfxScroll(int left, int top, int width, int height, int xo, int yo)
* @param top Minimum Y (inclusive)
* @param right Maximum X (inclusive)
* @param bottom Maximum Y (inclusive)
- * @param color A 8 bit palette index (FILLRECT_OPAQUE and FILLRECT_CHECKER) or a recolor spritenumber (FILLRECT_RECOLOR)
+ * @param colour A 8 bit palette index (FILLRECT_OPAQUE and FILLRECT_CHECKER) or a recolour spritenumber (FILLRECT_RECOLOR)
* @param mode
- * FILLRECT_OPAQUE: Fill the rectangle with the specified color
+ * FILLRECT_OPAQUE: Fill the rectangle with the specified colour
* FILLRECT_CHECKER: Like FILLRECT_OPAQUE, but only draw every second pixel (used to grey out things)
- * FILLRECT_RECOLOR: Apply a recolor sprite to every pixel in the rectangle currently on screen
+ * FILLRECT_RECOLOR: Apply a recolour sprite to every pixel in the rectangle currently on screen
*/
-void GfxFillRect(int left, int top, int right, int bottom, int color, FillRectMode mode)
+void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
{
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
const DrawPixelInfo *dpi = _cur_dpi;
@@ -132,17 +132,17 @@ void GfxFillRect(int left, int top, int right, int bottom, int color, FillRectMo
switch (mode) {
default: // FILLRECT_OPAQUE
- blitter->DrawRect(dst, right, bottom, (uint8)color);
+ blitter->DrawRect(dst, right, bottom, (uint8)colour);
break;
case FILLRECT_RECOLOR:
- blitter->DrawColorMappingRect(dst, right, bottom, GB(color, 0, PALETTE_WIDTH));
+ blitter->DrawColorMappingRect(dst, right, bottom, GB(colour, 0, PALETTE_WIDTH));
break;
case FILLRECT_CHECKER: {
byte bo = (oleft - left + dpi->left + otop - top + dpi->top) & 1;
do {
- for (int i = (bo ^= 1); i < right; i += 2) blitter->SetPixel(dst, i, 0, (uint8)color);
+ for (int i = (bo ^= 1); i < right; i += 2) blitter->SetPixel(dst, i, 0, (uint8)colour);
dst = blitter->MoveTo(dst, 0, 1);
} while (--bottom > 0);
break;
@@ -150,7 +150,7 @@ void GfxFillRect(int left, int top, int right, int bottom, int color, FillRectMo
}
}
-void GfxDrawLine(int x, int y, int x2, int y2, int color)
+void GfxDrawLine(int x, int y, int x2, int y2, int colour)
{
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
DrawPixelInfo *dpi = _cur_dpi;
@@ -166,10 +166,10 @@ void GfxDrawLine(int x, int y, int x2, int y2, int color)
if (x > dpi->width && x2 > dpi->width) return;
if (y > dpi->height && y2 > dpi->height) return;
- blitter->DrawLine(dpi->dst_ptr, x, y, x2, y2, dpi->width, dpi->height, color);
+ blitter->DrawLine(dpi->dst_ptr, x, y, x2, y2, dpi->width, dpi->height, colour);
}
-void GfxDrawLineUnscaled(int x, int y, int x2, int y2, int color)
+void GfxDrawLineUnscaled(int x, int y, int x2, int y2, int colour)
{
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
DrawPixelInfo *dpi = _cur_dpi;
@@ -187,7 +187,7 @@ void GfxDrawLineUnscaled(int x, int y, int x2, int y2, int color)
blitter->DrawLine(dpi->dst_ptr, UnScaleByZoom(x, dpi->zoom), UnScaleByZoom(y, dpi->zoom),
UnScaleByZoom(x2, dpi->zoom), UnScaleByZoom(y2, dpi->zoom),
- UnScaleByZoom(dpi->width, dpi->zoom), UnScaleByZoom(dpi->height, dpi->zoom), color);
+ UnScaleByZoom(dpi->width, dpi->zoom), UnScaleByZoom(dpi->height, dpi->zoom), colour);
}
/**
@@ -220,18 +220,18 @@ void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3)
* ....V.
*/
- static const byte color = 255;
+ static const byte colour = 255;
- GfxDrawLineUnscaled(x, y, x + dx1, y + dy1, color);
- GfxDrawLineUnscaled(x, y, x + dx2, y + dy2, color);
- GfxDrawLineUnscaled(x, y, x + dx3, y + dy3, color);
+ GfxDrawLineUnscaled(x, y, x + dx1, y + dy1, colour);
+ GfxDrawLineUnscaled(x, y, x + dx2, y + dy2, colour);
+ GfxDrawLineUnscaled(x, y, x + dx3, y + dy3, colour);
- GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx2, y + dy1 + dy2, color);
- GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx3, y + dy1 + dy3, color);
- GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx1, y + dy2 + dy1, color);
- GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx3, y + dy2 + dy3, color);
- GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx1, y + dy3 + dy1, color);
- GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx2, y + dy3 + dy2, color);
+ GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx2, y + dy1 + dy2, colour);
+ GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx3, y + dy1 + dy3, colour);
+ GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx1, y + dy2 + dy1, colour);
+ GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx3, y + dy2 + dy3, colour);
+ GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx1, y + dy3 + dy1, colour);
+ GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx2, y + dy3 + dy2, colour);
}
@@ -378,17 +378,17 @@ static inline int TruncateStringID(StringID src, char *dest, int maxw, const cha
* @param x X position to start drawing
* @param y Y position to start drawing
* @param str String to draw
- * @param color Color used for drawing the string, see DoDrawString() for details
+ * @param colour Colour used for drawing the string, see DoDrawString() for details
*
* @return Horizontal coordinate after drawing the string
*/
-int DrawString(int x, int y, StringID str, uint16 color)
+int DrawString(int x, int y, StringID str, TextColour colour)
{
char buffer[DRAW_STRING_BUFFER];
GetString(buffer, str, lastof(buffer));
HandleBiDiAndArabicShapes(buffer, lastof(buffer));
- return ReallyDoDrawString(buffer, x, y, color);
+ return ReallyDoDrawString(buffer, x, y, colour);
}
/**
@@ -397,17 +397,17 @@ int DrawString(int x, int y, StringID str, uint16 color)
* @param x X position to start drawing
* @param y Y position to start drawing
* @param str String to draw
- * @param color Color used for drawing the string, see DoDrawString() for details
+ * @param colour Colour used for drawing the string, see DoDrawString() for details
* @param maxw Maximal width of the string
*
* @return Horizontal coordinate after drawing the (possibly truncated) string
*/
-int DrawStringTruncated(int x, int y, StringID str, uint16 color, uint maxw)
+int DrawStringTruncated(int x, int y, StringID str, TextColour colour, uint maxw)
{
char buffer[DRAW_STRING_BUFFER];
TruncateStringID(str, buffer, maxw, lastof(buffer));
HandleBiDiAndArabicShapes(buffer, lastof(buffer));
- return ReallyDoDrawString(buffer, x, y, color);
+ return ReallyDoDrawString(buffer, x, y, colour);
}
/**
@@ -416,11 +416,11 @@ int DrawStringTruncated(int x, int y, StringID str, uint16 color, uint maxw)
* @param x Right-most x position of the string
* @param y Y position of the string
* @param str String to draw
- * @param color Color used for drawing the string, see DoDrawString() for details
+ * @param colour Colour used for drawing the string, see DoDrawString() for details
*
* @return Width of drawn string in pixels
*/
-int DrawStringRightAligned(int x, int y, StringID str, uint16 color)
+int DrawStringRightAligned(int x, int y, StringID str, TextColour colour)
{
char buffer[DRAW_STRING_BUFFER];
int w;
@@ -429,7 +429,7 @@ int DrawStringRightAligned(int x, int y, StringID str, uint16 color)
HandleBiDiAndArabicShapes(buffer, lastof(buffer));
w = GetStringBoundingBox(buffer).width;
- ReallyDoDrawString(buffer, x - w, y, color);
+ ReallyDoDrawString(buffer, x - w, y, colour);
return w;
}
@@ -440,16 +440,16 @@ int DrawStringRightAligned(int x, int y, StringID str, uint16 color)
* @param x Right-most x position to start drawing
* @param y Y position to start drawing
* @param str String to draw
- * @param color Color used for drawing the string, see DoDrawString() for details
+ * @param colour Colour used for drawing the string, see DoDrawString() for details
* @param maxw Maximal width of the string
*/
-void DrawStringRightAlignedTruncated(int x, int y, StringID str, uint16 color, uint maxw)
+void DrawStringRightAlignedTruncated(int x, int y, StringID str, TextColour colour, uint maxw)
{
char buffer[DRAW_STRING_BUFFER];
TruncateStringID(str, buffer, maxw, lastof(buffer));
HandleBiDiAndArabicShapes(buffer, lastof(buffer));
- ReallyDoDrawString(buffer, x - GetStringBoundingBox(buffer).width, y, color);
+ ReallyDoDrawString(buffer, x - GetStringBoundingBox(buffer).width, y, colour);
}
/**
@@ -458,12 +458,12 @@ void DrawStringRightAlignedTruncated(int x, int y, StringID str, uint16 color, u
* @param x Right-most x position of the string
* @param y Y position of the string
* @param str String to draw
- * @param color Color used for drawing the string, see DoDrawString() for details
+ * @param colour Colour used for drawing the string, see DoDrawString() for details
*/
-void DrawStringRightAlignedUnderline(int x, int y, StringID str, uint16 color)
+void DrawStringRightAlignedUnderline(int x, int y, StringID str, TextColour colour)
{
- int w = DrawStringRightAligned(x, y, str, color);
- GfxFillRect(x - w, y + 10, x, y + 10, _string_colorremap[1]);
+ int w = DrawStringRightAligned(x, y, str, colour);
+ GfxFillRect(x - w, y + 10, x, y + 10, _string_colourremap[1]);
}
/**
@@ -472,11 +472,11 @@ void DrawStringRightAlignedUnderline(int x, int y, StringID str, uint16 color)
* @param x X position of center of the string
* @param y Y position of center of the string
* @param str String to draw
- * @param color Color used for drawing the string, see DoDrawString() for details
+ * @param colour Colour used for drawing the string, see DoDrawString() for details
*
* @return Width of the drawn string in pixels
*/
-int DrawStringCentered(int x, int y, StringID str, uint16 color)
+int DrawStringCentered(int x, int y, StringID str, TextColour colour)
{
char buffer[DRAW_STRING_BUFFER];
int w;
@@ -485,7 +485,7 @@ int DrawStringCentered(int x, int y, StringID str, uint16 color)
HandleBiDiAndArabicShapes(buffer, lastof(buffer));
w = GetStringBoundingBox(buffer).width;
- ReallyDoDrawString(buffer, x - w / 2, y, color);
+ ReallyDoDrawString(buffer, x - w / 2, y, colour);
return w;
}
@@ -497,18 +497,18 @@ int DrawStringCentered(int x, int y, StringID str, uint16 color)
* @param xr Right-most x position
* @param y Y position of the string
* @param str String to draw
- * @param color Color used for drawing the string, see DoDrawString() for details
+ * @param colour Colour used for drawing the string, see DoDrawString() for details
*
* @return Right-most coordinate of the (possibly truncated) drawn string
*/
-int DrawStringCenteredTruncated(int xl, int xr, int y, StringID str, uint16 color)
+int DrawStringCenteredTruncated(int xl, int xr, int y, StringID str, TextColour colour)
{
char buffer[DRAW_STRING_BUFFER];
TruncateStringID(str, buffer, xr - xl, lastof(buffer));
HandleBiDiAndArabicShapes(buffer, lastof(buffer));
int w = GetStringBoundingBox(buffer).width;
- return ReallyDoDrawString(buffer, (xl + xr - w) / 2, y, color);
+ return ReallyDoDrawString(buffer, (xl + xr - w) / 2, y, colour);
}
/**
@@ -517,18 +517,18 @@ int DrawStringCenteredTruncated(int xl, int xr, int y, StringID str, uint16 colo
* @param x X position of center of the string
* @param y Y position of center of the string
* @param str String to draw
- * @param color Color used for drawing the string, see DoDrawString() for details
+ * @param colour Colour used for drawing the string, see DoDrawString() for details
*
* @return Width of the drawn string in pixels
*/
-int DoDrawStringCentered(int x, int y, const char *str, uint16 color)
+int DoDrawStringCentered(int x, int y, const char *str, TextColour colour)
{
char buffer[DRAW_STRING_BUFFER];
strecpy(buffer, str, lastof(buffer));
HandleBiDiAndArabicShapes(buffer, lastof(buffer));
int w = GetStringBoundingBox(buffer).width;
- ReallyDoDrawString(buffer, x - w / 2, y, color);
+ ReallyDoDrawString(buffer, x - w / 2, y, colour);
return w;
}
@@ -538,12 +538,12 @@ int DoDrawStringCentered(int x, int y, const char *str, uint16 color)
* @param x X position of center of the string
* @param y Y position of center of the string
* @param str String to draw
- * @param color Color used for drawing the string, see DoDrawString() for details
+ * @param colour Colour used for drawing the string, see DoDrawString() for details
*/
-void DrawStringCenterUnderline(int x, int y, StringID str, uint16 color)
+void DrawStringCenterUnderline(int x, int y, StringID str, TextColour colour)
{
- int w = DrawStringCentered(x, y, str, color);
- GfxFillRect(x - (w >> 1), y + 10, x - (w >> 1) + w, y + 10, _string_colorremap[1]);
+ int w = DrawStringCentered(x, y, str, colour);
+ GfxFillRect(x - (w >> 1), y + 10, x - (w >> 1) + w, y + 10, _string_colourremap[1]);
}
/**
@@ -553,12 +553,12 @@ void DrawStringCenterUnderline(int x, int y, StringID str, uint16 color)
* @param xr Right x position of the string
* @param y Y position of center of the string
* @param str String to draw
- * @param color Color used for drawing the string, see DoDrawString() for details
+ * @param colour Colour used for drawing the string, see DoDrawString() for details
*/
-void DrawStringCenterUnderlineTruncated(int xl, int xr, int y, StringID str, uint16 color)
+void DrawStringCenterUnderlineTruncated(int xl, int xr, int y, StringID str, TextColour colour)
{
- int w = DrawStringCenteredTruncated(xl, xr, y, str, color);
- GfxFillRect((xl + xr - w) / 2, y + 10, (xl + xr + w) / 2, y + 10, _string_colorremap[1]);
+ int w = DrawStringCenteredTruncated(xl, xr, y, str, colour);
+ GfxFillRect((xl + xr - w) / 2, y + 10, (xl + xr + w) / 2, y + 10, _string_colourremap[1]);
}
/**
@@ -711,7 +711,7 @@ void DrawStringMultiCenter(int x, int y, StringID str, int maxw)
strecpy(buf2, src, lastof(buf2));
HandleBiDiAndArabicShapes(buf2, lastof(buf2));
int w = GetStringBoundingBox(buf2).width;
- ReallyDoDrawString(buf2, x - (w >> 1), y, 0xFE, true);
+ ReallyDoDrawString(buf2, x - (w >> 1), y, TC_FROMSTRING, true);
_cur_fontsize = _last_fontsize;
for (;;) {
@@ -764,7 +764,7 @@ uint DrawStringMultiLine(int x, int y, StringID str, int maxw, int maxh)
char buf2[DRAW_STRING_BUFFER];
strecpy(buf2, src, lastof(buf2));
HandleBiDiAndArabicShapes(buf2, lastof(buf2));
- ReallyDoDrawString(buf2, x, y, 0xFE, true);
+ ReallyDoDrawString(buf2, x, y, TC_FROMSTRING, true);
_cur_fontsize = _last_fontsize;
for (;;) {
@@ -833,17 +833,18 @@ Dimension GetStringBoundingBox(const char *str)
* @param c Character (glyph) to draw
* @param x X position to draw character
* @param y Y position to draw character
- * @param real_color Colour to use, see DoDrawString() for details
+ * @param real_colour Colour to use, see DoDrawString() for details
*/
-void DrawCharCentered(WChar c, int x, int y, uint16 real_color)
+void DrawCharCentered(WChar c, int x, int y, TextColour colour)
{
FontSize size = FS_NORMAL;
- byte color = real_color & 0xFF;
+ assert(colour & IS_PALETTE_COLOR);
+ colour &= ~IS_PALETTE_COLOR;
int w = GetCharacterWidth(size, c);
- _string_colorremap[1] = _string_colormap[_use_palette][color].text;
- _string_colorremap[2] = _string_colormap[_use_palette][color].shadow;
- _color_remap_ptr = _string_colorremap;
+ _string_colourremap[1] = _string_colourmap[_use_palette][colour].text;
+ _string_colourremap[2] = _string_colourmap[_use_palette][colour].shadow;
+ _colour_remap_ptr = _string_colourremap;
GfxMainBlitter(GetGlyph(size, c), x - w / 2, y, BM_COLOUR_REMAP);
}
@@ -854,7 +855,7 @@ void DrawCharCentered(WChar c, int x, int y, uint16 real_color)
* @param string The string to draw. This is not yet bidi reordered.
* @param x Offset from left side of the screen
* @param y Offset from top side of the screen
- * @param real_colour Colour of the string, see _string_colormap in
+ * @param colour Colour of the string, see _string_colourmap in
* table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h
* @param parse_string_also_when_clipped
* By default, always test the available space where to draw the string.
@@ -865,13 +866,13 @@ void DrawCharCentered(WChar c, int x, int y, uint16 real_color)
* @return the x-coordinates where the drawing has finished.
* If nothing is drawn, the originally passed x-coordinate is returned
*/
-int DoDrawString(const char *string, int x, int y, uint16 real_colour, bool parse_string_also_when_clipped)
+int DoDrawString(const char *string, int x, int y, TextColour colour, bool parse_string_also_when_clipped)
{
char buffer[DRAW_STRING_BUFFER];
strecpy(buffer, string, lastof(buffer));
HandleBiDiAndArabicShapes(buffer, lastof(buffer));
- return ReallyDoDrawString(buffer, x, y, real_colour, parse_string_also_when_clipped);
+ return ReallyDoDrawString(buffer, x, y, colour, parse_string_also_when_clipped);
}
/** Draw a string at the given coordinates with the given colour.
@@ -880,7 +881,7 @@ int DoDrawString(const char *string, int x, int y, uint16 real_colour, bool pars
* @param string The string to draw. This is already bidi reordered.
* @param x Offset from left side of the screen
* @param y Offset from top side of the screen
- * @param real_colour Colour of the string, see _string_colormap in
+ * @param colour Colour of the string, see _string_colourmap in
* table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h
* @param parse_string_also_when_clipped
* By default, always test the available space where to draw the string.
@@ -891,15 +892,14 @@ int DoDrawString(const char *string, int x, int y, uint16 real_colour, bool pars
* @return the x-coordinates where the drawing has finished.
* If nothing is drawn, the originally passed x-coordinate is returned
*/
-static int ReallyDoDrawString(const char *string, int x, int y, uint16 real_colour, bool parse_string_also_when_clipped)
+static int ReallyDoDrawString(const char *string, int x, int y, TextColour colour, bool parse_string_also_when_clipped)
{
DrawPixelInfo *dpi = _cur_dpi;
FontSize size = _cur_fontsize;
WChar c;
int xo = x, yo = y;
- byte colour = real_colour & 0xFF; // extract the 8 bits colour index that is required for the mapping
- byte previous_colour = colour;
+ TextColour previous_colour = colour;
if (!parse_string_also_when_clipped) {
/* in "mode multiline", the available space have been verified. Not in regular one.
@@ -908,14 +908,14 @@ static int ReallyDoDrawString(const char *string, int x, int y, uint16 real_colo
if (colour != TC_INVALID) { // the invalid colour flag test should not really occur. But better be safe
switch_colour:;
- if (real_colour & IS_PALETTE_COLOR) {
- _string_colorremap[1] = colour;
- _string_colorremap[2] = (_use_palette == PAL_DOS) ? 1 : 215;
+ if (colour & IS_PALETTE_COLOR) {
+ _string_colourremap[1] = colour & ~IS_PALETTE_COLOR;
+ _string_colourremap[2] = (_use_palette == PAL_DOS) ? 1 : 215;
} else {
- _string_colorremap[1] = _string_colormap[_use_palette][colour].text;
- _string_colorremap[2] = _string_colormap[_use_palette][colour].shadow;
+ _string_colourremap[1] = _string_colourmap[_use_palette][colour].text;
+ _string_colourremap[2] = _string_colourmap[_use_palette][colour].shadow;
}
- _color_remap_ptr = _string_colorremap;
+ _colour_remap_ptr = _string_colourremap;
}
}
@@ -947,7 +947,7 @@ skip_cont:;
goto check_bounds;
} else if (c >= SCC_BLUE && c <= SCC_BLACK) { // change colour?
previous_colour = colour;
- colour = (byte)(c - SCC_BLUE);
+ colour = (TextColour)(c - SCC_BLUE);
goto switch_colour;
} else if (c == SCC_PREVIOUS_COLOUR) { // revert to the previous colour
Swap(colour, previous_colour);
@@ -974,17 +974,17 @@ skip_cont:;
* @param str Character buffer containing the string
* @param x Left-most x coordinate to start drawing
* @param y Y coordinate to draw the string
- * @param color Colour to use, see DoDrawString() for details.
+ * @param colour Colour to use, see DoDrawString() for details.
* @param maxw Maximal width in pixels that may be used for drawing
*
* @return Right-most x position after drawing the (possibly truncated) string
*/
-int DoDrawStringTruncated(const char *str, int x, int y, uint16 color, uint maxw)
+int DoDrawStringTruncated(const char *str, int x, int y, TextColour colour, uint maxw)
{
char buffer[DRAW_STRING_BUFFER];
strecpy(buffer, str, lastof(buffer));
TruncateString(buffer, maxw);
- return DoDrawString(buffer, x, y, color);
+ return DoDrawString(buffer, x, y, colour);
}
/**
@@ -998,10 +998,10 @@ int DoDrawStringTruncated(const char *str, int x, int y, uint16 color, uint maxw
void DrawSprite(SpriteID img, SpriteID pal, int x, int y, const SubSprite *sub)
{
if (HasBit(img, PALETTE_MODIFIER_TRANSPARENT)) {
- _color_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
+ _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH), ST_NORMAL), x, y, BM_TRANSPARENT, sub);
} else if (pal != PAL_NONE) {
- _color_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
+ _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH), ST_NORMAL), x, y, BM_COLOUR_REMAP, sub);
} else {
GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH), ST_NORMAL), x, y, BM_NORMAL, sub);
@@ -1042,7 +1042,7 @@ static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode,
bp.dst = dpi->dst_ptr;
bp.pitch = dpi->pitch;
- bp.remap = _color_remap_ptr;
+ bp.remap = _colour_remap_ptr;
assert(sprite->width > 0);
assert(sprite->height > 0);
diff --git a/src/gfx_func.h b/src/gfx_func.h
index b6a7a91ad..eedf34604 100644
--- a/src/gfx_func.h
+++ b/src/gfx_func.h
@@ -85,27 +85,27 @@ void GfxScroll(int left, int top, int width, int height, int xo, int yo);
void DrawSprite(SpriteID img, SpriteID pal, int x, int y, const SubSprite *sub = NULL);
-int DrawStringCentered(int x, int y, StringID str, uint16 color);
-int DrawStringCenteredTruncated(int xl, int xr, int y, StringID str, uint16 color);
-int DoDrawStringCentered(int x, int y, const char *str, uint16 color);
+int DrawStringCentered(int x, int y, StringID str, TextColour colour);
+int DrawStringCenteredTruncated(int xl, int xr, int y, StringID str, TextColour colour);
+int DoDrawStringCentered(int x, int y, const char *str, TextColour colour);
-int DrawString(int x, int y, StringID str, uint16 color);
-int DrawStringTruncated(int x, int y, StringID str, uint16 color, uint maxw);
+int DrawString(int x, int y, StringID str, TextColour colour);
+int DrawStringTruncated(int x, int y, StringID str, TextColour colour, uint maxw);
-int DoDrawString(const char *string, int x, int y, uint16 real_colour, bool parse_string_also_when_clipped = false);
-int DoDrawStringTruncated(const char *str, int x, int y, uint16 color, uint maxw);
+int DoDrawString(const char *string, int x, int y, TextColour colour, bool parse_string_also_when_clipped = false);
+int DoDrawStringTruncated(const char *str, int x, int y, TextColour colour, uint maxw);
-void DrawStringCenterUnderline(int x, int y, StringID str, uint16 color);
-void DrawStringCenterUnderlineTruncated(int xl, int xr, int y, StringID str, uint16 color);
+void DrawStringCenterUnderline(int x, int y, StringID str, TextColour colour);
+void DrawStringCenterUnderlineTruncated(int xl, int xr, int y, StringID str, TextColour colour);
-int DrawStringRightAligned(int x, int y, StringID str, uint16 color);
-void DrawStringRightAlignedTruncated(int x, int y, StringID str, uint16 color, uint maxw);
-void DrawStringRightAlignedUnderline(int x, int y, StringID str, uint16 color);
+int DrawStringRightAligned(int x, int y, StringID str, TextColour colour);
+void DrawStringRightAlignedTruncated(int x, int y, StringID str, TextColour colour, uint maxw);
+void DrawStringRightAlignedUnderline(int x, int y, StringID str, TextColour colour);
-void DrawCharCentered(uint32 c, int x, int y, uint16 color);
+void DrawCharCentered(uint32 c, int x, int y, TextColour colour);
-void GfxFillRect(int left, int top, int right, int bottom, int color, FillRectMode mode = FILLRECT_OPAQUE);
-void GfxDrawLine(int left, int top, int right, int bottom, int color);
+void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode = FILLRECT_OPAQUE);
+void GfxDrawLine(int left, int top, int right, int bottom, int colour);
void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3);
Dimension GetStringBoundingBox(const char *str);
diff --git a/src/gfx_type.h b/src/gfx_type.h
index 20b5019a0..835015a8b 100644
--- a/src/gfx_type.h
+++ b/src/gfx_type.h
@@ -206,7 +206,10 @@ enum TextColour {
TC_DARK_BLUE = 0x0F,
TC_BLACK = 0x10,
TC_INVALID = 0xFF,
+
+ IS_PALETTE_COLOR = 0x100, ///< colour value is already a real palette colour index, not an index of a StringColour
};
+DECLARE_ENUM_AS_BIT_SET(TextColour);
/** Defines a few values that are related to animations using palette changes */
enum PaletteAnimationSizes {
@@ -215,10 +218,6 @@ enum PaletteAnimationSizes {
PALETTE_ANIM_SIZE_START = 217, ///< Index in the _palettes array from which all animations are taking places (table/palettes.h)
};
-enum StringColorFlags {
- IS_PALETTE_COLOR = 0x100, ///< color value is already a real palette color index, not an index of a StringColor
-};
-
/** Define the operation GfxFillRect performs */
enum FillRectMode {
FILLRECT_OPAQUE, ///< Fill rectangle with a single color
diff --git a/src/network/network.cpp b/src/network/network.cpp
index 99b63cf4a..02121b347 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -189,7 +189,7 @@ bool NetworkCompanyIsPassworded(CompanyID company_id)
// This puts a text-message to the console, or in the future, the chat-box,
// (to keep it all a bit more general)
// If 'self_send' is true, this is the client who is sending the message
-void NetworkTextMessage(NetworkAction action, ConsoleColour color, bool self_send, const char *name, const char *str, int64 data)
+void NetworkTextMessage(NetworkAction action, ConsoleColour colour, bool self_send, const char *name, const char *str, int64 data)
{
const int duration = 10; // Game days the messages stay visible
@@ -200,19 +200,19 @@ void NetworkTextMessage(NetworkAction action, ConsoleColour color, bool self_sen
if (data >= NETWORK_SERVER_MESSAGE_END) return;
strid = STR_NETWORK_SERVER_MESSAGE;
- color = CC_DEFAULT;
+ colour = CC_DEFAULT;
data = STR_NETWORK_SERVER_MESSAGE_GAME_PAUSED_PLAYERS + data;
break;
case NETWORK_ACTION_COMPANY_SPECTATOR:
- color = CC_DEFAULT;
+ colour = CC_DEFAULT;
strid = STR_NETWORK_CLIENT_COMPANY_SPECTATE;
break;
case NETWORK_ACTION_COMPANY_JOIN:
- color = CC_DEFAULT;
+ colour = CC_DEFAULT;
strid = STR_NETWORK_CLIENT_COMPANY_JOIN;
break;
case NETWORK_ACTION_COMPANY_NEW:
- color = CC_DEFAULT;
+ colour = CC_DEFAULT;
strid = STR_NETWORK_CLIENT_COMPANY_NEW;
break;
case NETWORK_ACTION_JOIN: strid = STR_NETWORK_CLIENT_JOINED; break;
@@ -231,8 +231,8 @@ void NetworkTextMessage(NetworkAction action, ConsoleColour color, bool self_sen
GetString(message, strid, lastof(message));
DEBUG(desync, 1, "msg: %d; %d; %s\n", _date, _date_fract, message);
- IConsolePrintF(color, "%s", message);
- NetworkAddChatMessage(color, duration, "%s", message);
+ IConsolePrintF(colour, "%s", message);
+ NetworkAddChatMessage((TextColour)colour, duration, "%s", message);
}
// Calculate the frame-lag of a client
diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp
index a5336c126..948aa5942 100644
--- a/src/network/network_chat_gui.cpp
+++ b/src/network/network_chat_gui.cpp
@@ -32,7 +32,7 @@ enum {
struct ChatMessage {
char message[DRAW_STRING_BUFFER];
- uint16 color;
+ TextColour colour;
Date end_date;
};
@@ -64,7 +64,7 @@ static inline uint GetChatMessageCount()
* @param duration The duration of the chat message in game-days
* @param message message itself in printf() style
*/
-void CDECL NetworkAddChatMessage(uint16 color, uint8 duration, const char *message, ...)
+void CDECL NetworkAddChatMessage(TextColour colour, uint8 duration, const char *message, ...)
{
char buf[DRAW_STRING_BUFFER];
const char *bufp;
@@ -96,7 +96,7 @@ void CDECL NetworkAddChatMessage(uint16 color, uint8 duration, const char *messa
/* The default colour for a message is company colour. Replace this with
* white for any additional lines */
- cmsg->color = (bufp == buf && color & IS_PALETTE_COLOR) ? color : (0x1D - 15) | IS_PALETTE_COLOR;
+ cmsg->colour = (bufp == buf && colour & IS_PALETTE_COLOR) ? colour : (TextColour)(0x1D - 15) | IS_PALETTE_COLOR;
cmsg->end_date = _date + duration;
bufp += strlen(bufp) + 1; // jump to 'next line' in the formatted string
@@ -237,7 +237,7 @@ void NetworkDrawChatMessage()
/* Paint the chat messages starting with the lowest at the bottom */
for (uint y = NETWORK_CHAT_LINE_HEIGHT; count-- != 0; y += NETWORK_CHAT_LINE_HEIGHT) {
- DoDrawString(_chatmsg_list[count].message, _chatmsg_box.x + 3, _screen.height - _chatmsg_box.y - y + 1, _chatmsg_list[count].color);
+ DoDrawString(_chatmsg_list[count].message, _chatmsg_box.x + 3, _screen.height - _chatmsg_box.y - y + 1, _chatmsg_list[count].colour);
}
/* Make sure the data is updated next flush */
diff --git a/src/network/network_func.h b/src/network/network_func.h
index 70bc96ff0..af8f4cbd6 100644
--- a/src/network/network_func.h
+++ b/src/network/network_func.h
@@ -10,6 +10,7 @@
#include "core/address.h"
#include "network_type.h"
#include "../console_type.h"
+#include "../gfx_type.h"
extern NetworkServerGameInfo _network_game_info;
extern NetworkCompanyState *_network_company_states;
@@ -69,7 +70,7 @@ void NetworkServerSendError(ClientID client_id, NetworkErrorCode error);
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const char *msg, ClientID from_id, int64 data = 0);
void NetworkInitChatMessage();
-void CDECL NetworkAddChatMessage(uint16 color, uint8 duration, const char *message, ...);
+void CDECL NetworkAddChatMessage(TextColour colour, uint8 duration, const char *message, ...);
void NetworkUndrawChatMessage();
void NetworkChatMessageDailyLoop();
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index 06273e127..edc04aa6f 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -662,11 +662,11 @@ void ShowLastNewsMessage()
* Draw an unformatted news message truncated to a maximum length. If
* length exceeds maximum length it will be postfixed by '...'
* @param x,y position of the string
- * @param color the color the string will be shown in
+ * @param colour the colour the string will be shown in
* @param *ni NewsItem being printed
* @param maxw maximum width of string in pixels
*/
-static void DrawNewsString(int x, int y, uint16 color, const NewsItem *ni, uint maxw)
+static void DrawNewsString(int x, int y, TextColour colour, const NewsItem *ni, uint maxw)
{
char buffer[512], buffer2[512];
StringID str;
@@ -698,7 +698,7 @@ static void DrawNewsString(int x, int y, uint16 color, const NewsItem *ni, uint
*dest = '\0';
/* Truncate and show string; postfixed by '...' if neccessary */
- DoDrawStringTruncated(buffer2, x, y, color, maxw);
+ DoDrawStringTruncated(buffer2, x, y, colour, maxw);
}
diff --git a/src/table/palettes.h b/src/table/palettes.h
index d129f4191..98a9baefc 100644
--- a/src/table/palettes.h
+++ b/src/table/palettes.h
@@ -200,7 +200,7 @@ struct StringColor {
byte shadow;
};
-static const StringColor _string_colormap[][17] = {
+static const StringColor _string_colourmap[][17] = {
{ /* DOS palette. */
{ 150, 1 }, // TC_BLUE
{ 12, 1 }, // TC_SILVER
diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp
index c6f11e0d9..a70a79128 100644
--- a/src/toolbar_gui.cpp
+++ b/src/toolbar_gui.cpp
@@ -171,7 +171,7 @@ public:
SetDParam(0, company);
SetDParam(1, company);
- int col;
+ TextColour col;
if (this->greyed) {
col = TC_GREY;
} else {
diff --git a/src/town_gui.cpp b/src/town_gui.cpp
index b4833ab3b..0a5f24ad0 100644
--- a/src/town_gui.cpp
+++ b/src/town_gui.cpp
@@ -286,7 +286,7 @@ public:
if (_settings_game.economy.station_noise_level) {
SetDParam(0, this->town->noise_reached);
SetDParam(1, this->town->MaxTownNoise());
- DrawString(2, 137, STR_NOISE_IN_TOWN, 0);
+ DrawString(2, 137, STR_NOISE_IN_TOWN, TC_FROMSTRING);
}
}
diff --git a/src/viewport.cpp b/src/viewport.cpp
index 579f65205..1cab2da6b 100644
--- a/src/viewport.cpp
+++ b/src/viewport.cpp
@@ -1418,7 +1418,7 @@ static void ViewportDrawStrings(DrawPixelInfo *dpi, const StringSpriteToDrawVect
const StringSpriteToDraw *ssend = sstdv->End();
for (const StringSpriteToDraw *ss = sstdv->Begin(); ss != ssend; ++ss) {
- uint16 colour;
+ TextColour colour;
if (ss->width != 0) {
/* Do not draw signs nor station names if they are set invisible */
@@ -1453,7 +1453,7 @@ static void ViewportDrawStrings(DrawPixelInfo *dpi, const StringSpriteToDrawVect
if (IsTransparencySet(TO_SIGNS) && ss->string != STR_2806 && ss->width != 0) {
/* Real colors need the IS_PALETTE_COLOR flag
* otherwise colors from _string_colormap are assumed. */
- colour = _colour_gradient[ss->color][6] | IS_PALETTE_COLOR;
+ colour = (TextColour)_colour_gradient[ss->color][6] | IS_PALETTE_COLOR;
} else {
colour = TC_BLACK;
}
diff --git a/src/widget.cpp b/src/widget.cpp
index 285fc9920..45c928c8f 100644
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -257,7 +257,7 @@ void Window::DrawWidgets() const
case WWT_TEXT: {
const StringID str = wi->data;
- if (str != STR_NULL) DrawStringTruncated(r.left, r.top, str, wi->colour, r.right - r.left);
+ if (str != STR_NULL) DrawStringTruncated(r.left, r.top, str, (TextColour)wi->colour, r.right - r.left);
break;
}