diff --git a/src/blitter/32bpp_anim.cpp b/src/blitter/32bpp_anim.cpp index 5006305789..797b0db738 100644 --- a/src/blitter/32bpp_anim.cpp +++ b/src/blitter/32bpp_anim.cpp @@ -321,19 +321,19 @@ void Blitter_32bppAnim::DrawColourMappingRect(void *dst, int width, int height, Debug(misc, 0, "32bpp blitter doesn't know how to draw this colour table ('{}')", pal); } -void Blitter_32bppAnim::SetPixel(void *video, int x, int y, uint8_t colour) +void Blitter_32bppAnim::SetPixel(void *video, int x, int y, PixelColour colour) { - *((Colour *)video + x + y * _screen.pitch) = LookupColourInPalette(colour); + *((Colour *)video + x + y * _screen.pitch) = LookupColourInPalette(colour.p); /* Set the colour in the anim-buffer too, if we are rendering to the screen */ if (_screen_disable_anim) return; - this->anim_buf[this->ScreenToAnimOffset((uint32_t *)video) + x + y * this->anim_buf_pitch] = colour | (DEFAULT_BRIGHTNESS << 8); + this->anim_buf[this->ScreenToAnimOffset((uint32_t *)video) + x + y * this->anim_buf_pitch] = colour.p | (DEFAULT_BRIGHTNESS << 8); } -void Blitter_32bppAnim::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash) +void Blitter_32bppAnim::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, PixelColour colour, int width, int dash) { - const Colour c = LookupColourInPalette(colour); + const Colour c = LookupColourInPalette(colour.p); if (_screen_disable_anim) { this->DrawLineGeneric(x, y, x2, y2, screen_width, screen_height, width, dash, [&](int x, int y) { @@ -341,7 +341,7 @@ void Blitter_32bppAnim::DrawLine(void *video, int x, int y, int x2, int y2, int }); } else { uint16_t * const offset_anim_buf = this->anim_buf + this->ScreenToAnimOffset((uint32_t *)video); - const uint16_t anim_colour = colour | (DEFAULT_BRIGHTNESS << 8); + const uint16_t anim_colour = colour.p | (DEFAULT_BRIGHTNESS << 8); this->DrawLineGeneric(x, y, x2, y2, screen_width, screen_height, width, dash, [&](int x, int y) { *((Colour *)video + x + y * _screen.pitch) = c; offset_anim_buf[x + y * this->anim_buf_pitch] = anim_colour; @@ -349,7 +349,7 @@ void Blitter_32bppAnim::DrawLine(void *video, int x, int y, int x2, int y2, int } } -void Blitter_32bppAnim::DrawRect(void *video, int width, int height, uint8_t colour) +void Blitter_32bppAnim::DrawRect(void *video, int width, int height, PixelColour colour) { if (_screen_disable_anim) { /* This means our output is not to the screen, so we can't be doing any animation stuff, so use our parent DrawRect() */ @@ -357,7 +357,7 @@ void Blitter_32bppAnim::DrawRect(void *video, int width, int height, uint8_t col return; } - Colour colour32 = LookupColourInPalette(colour); + Colour colour32 = LookupColourInPalette(colour.p); uint16_t *anim_line = this->ScreenToAnimOffset((uint32_t *)video) + this->anim_buf; do { @@ -367,7 +367,7 @@ void Blitter_32bppAnim::DrawRect(void *video, int width, int height, uint8_t col for (int i = width; i > 0; i--) { *dst = colour32; /* Set the colour in the anim-buffer too */ - *anim = colour | (DEFAULT_BRIGHTNESS << 8); + *anim = colour.p | (DEFAULT_BRIGHTNESS << 8); dst++; anim++; } diff --git a/src/blitter/32bpp_anim.hpp b/src/blitter/32bpp_anim.hpp index acc911ffe0..b8b89e6106 100644 --- a/src/blitter/32bpp_anim.hpp +++ b/src/blitter/32bpp_anim.hpp @@ -34,9 +34,9 @@ public: void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override; void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override; - void SetPixel(void *video, int x, int y, uint8_t colour) override; - void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash) override; - void DrawRect(void *video, int width, int height, uint8_t colour) override; + void SetPixel(void *video, int x, int y, PixelColour colour) override; + void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, PixelColour colour, int width, int dash) override; + void DrawRect(void *video, int width, int height, PixelColour colour) override; void CopyFromBuffer(void *video, const void *src, int width, int height) override; void CopyToBuffer(const void *video, void *dst, int width, int height) override; void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) override; diff --git a/src/blitter/32bpp_base.cpp b/src/blitter/32bpp_base.cpp index 5c25d4185f..fdf780b982 100644 --- a/src/blitter/32bpp_base.cpp +++ b/src/blitter/32bpp_base.cpp @@ -18,22 +18,22 @@ void *Blitter_32bppBase::MoveTo(void *video, int x, int y) return (uint32_t *)video + x + y * _screen.pitch; } -void Blitter_32bppBase::SetPixel(void *video, int x, int y, uint8_t colour) +void Blitter_32bppBase::SetPixel(void *video, int x, int y, PixelColour colour) { - *((Colour *)video + x + y * _screen.pitch) = LookupColourInPalette(colour); + *((Colour *)video + x + y * _screen.pitch) = LookupColourInPalette(colour.p); } -void Blitter_32bppBase::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash) +void Blitter_32bppBase::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, PixelColour colour, int width, int dash) { - const Colour c = LookupColourInPalette(colour); + const Colour c = LookupColourInPalette(colour.p); this->DrawLineGeneric(x, y, x2, y2, screen_width, screen_height, width, dash, [=](int x, int y) { *((Colour *)video + x + y * _screen.pitch) = c; }); } -void Blitter_32bppBase::DrawRect(void *video, int width, int height, uint8_t colour) +void Blitter_32bppBase::DrawRect(void *video, int width, int height, PixelColour colour) { - Colour colour32 = LookupColourInPalette(colour); + Colour colour32 = LookupColourInPalette(colour.p); do { Colour *dst = (Colour *)video; diff --git a/src/blitter/32bpp_base.hpp b/src/blitter/32bpp_base.hpp index c3378b47c3..4b7e8c7c5b 100644 --- a/src/blitter/32bpp_base.hpp +++ b/src/blitter/32bpp_base.hpp @@ -19,9 +19,9 @@ class Blitter_32bppBase : public Blitter { public: uint8_t GetScreenDepth() override { return 32; } void *MoveTo(void *video, int x, int y) override; - void SetPixel(void *video, int x, int y, uint8_t colour) override; - void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash) override; - void DrawRect(void *video, int width, int height, uint8_t colour) override; + void SetPixel(void *video, int x, int y, PixelColour colour) override; + void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, PixelColour colour, int width, int dash) override; + void DrawRect(void *video, int width, int height, PixelColour colour) override; void CopyFromBuffer(void *video, const void *src, int width, int height) override; void CopyToBuffer(const void *video, void *dst, int width, int height) override; void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) override; diff --git a/src/blitter/40bpp_anim.cpp b/src/blitter/40bpp_anim.cpp index 7ef8cd4ba8..6e6d1233fa 100644 --- a/src/blitter/40bpp_anim.cpp +++ b/src/blitter/40bpp_anim.cpp @@ -27,7 +27,7 @@ static FBlitter_40bppAnim iFBlitter_40bppAnim; static const Colour _black_colour(0, 0, 0); -void Blitter_40bppAnim::SetPixel(void *video, int x, int y, uint8_t colour) +void Blitter_40bppAnim::SetPixel(void *video, int x, int y, PixelColour colour) { if (_screen_disable_anim) { Blitter_32bppOptimized::SetPixel(video, x, y, colour); @@ -35,11 +35,11 @@ void Blitter_40bppAnim::SetPixel(void *video, int x, int y, uint8_t colour) size_t y_offset = static_cast(y) * _screen.pitch; *((Colour *)video + x + y_offset) = _black_colour; - VideoDriver::GetInstance()->GetAnimBuffer()[((uint32_t *)video - (uint32_t *)_screen.dst_ptr) + x + y_offset] = colour; + VideoDriver::GetInstance()->GetAnimBuffer()[((uint32_t *)video - (uint32_t *)_screen.dst_ptr) + x + y_offset] = colour.p; } } -void Blitter_40bppAnim::DrawRect(void *video, int width, int height, uint8_t colour) +void Blitter_40bppAnim::DrawRect(void *video, int width, int height, PixelColour colour) { if (_screen_disable_anim) { /* This means our output is not to the screen, so we can't be doing any animation stuff, so use our parent DrawRect() */ @@ -56,7 +56,7 @@ void Blitter_40bppAnim::DrawRect(void *video, int width, int height, uint8_t col for (int i = width; i > 0; i--) { *dst = _black_colour; - *anim = colour; + *anim = colour.p; dst++; anim++; } @@ -65,7 +65,7 @@ void Blitter_40bppAnim::DrawRect(void *video, int width, int height, uint8_t col } while (--height); } -void Blitter_40bppAnim::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash) +void Blitter_40bppAnim::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, PixelColour colour, int width, int dash) { if (_screen_disable_anim) { /* This means our output is not to the screen, so we can't be doing any animation stuff, so use our parent DrawRect() */ @@ -78,7 +78,7 @@ void Blitter_40bppAnim::DrawLine(void *video, int x, int y, int x2, int y2, int this->DrawLineGeneric(x, y, x2, y2, screen_width, screen_height, width, dash, [=](int x, int y) { *((Colour *)video + x + y * _screen.pitch) = _black_colour; - *(anim + x + y * _screen.pitch) = colour; + *(anim + x + y * _screen.pitch) = colour.p; }); } diff --git a/src/blitter/40bpp_anim.hpp b/src/blitter/40bpp_anim.hpp index 66990bae4e..55e3a0664b 100644 --- a/src/blitter/40bpp_anim.hpp +++ b/src/blitter/40bpp_anim.hpp @@ -18,9 +18,9 @@ class Blitter_40bppAnim : public Blitter_32bppOptimized { public: - void SetPixel(void *video, int x, int y, uint8_t colour) override; - void DrawRect(void *video, int width, int height, uint8_t colour) override; - void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash) override; + void SetPixel(void *video, int x, int y, PixelColour colour) override; + void DrawRect(void *video, int width, int height, PixelColour colour) override; + void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, PixelColour colour, int width, int dash) override; void CopyFromBuffer(void *video, const void *src, int width, int height) override; void CopyToBuffer(const void *video, void *dst, int width, int height) override; void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) override; diff --git a/src/blitter/8bpp_base.cpp b/src/blitter/8bpp_base.cpp index db4e18b3fe..ae7858a17f 100644 --- a/src/blitter/8bpp_base.cpp +++ b/src/blitter/8bpp_base.cpp @@ -29,23 +29,23 @@ void *Blitter_8bppBase::MoveTo(void *video, int x, int y) return (uint8_t *)video + x + y * _screen.pitch; } -void Blitter_8bppBase::SetPixel(void *video, int x, int y, uint8_t colour) +void Blitter_8bppBase::SetPixel(void *video, int x, int y, PixelColour colour) { - *((uint8_t *)video + x + y * _screen.pitch) = colour; + *((uint8_t *)video + x + y * _screen.pitch) = colour.p; } -void Blitter_8bppBase::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash) +void Blitter_8bppBase::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, PixelColour colour, int width, int dash) { this->DrawLineGeneric(x, y, x2, y2, screen_width, screen_height, width, dash, [=](int x, int y) { - *((uint8_t *)video + x + y * _screen.pitch) = colour; + *((uint8_t *)video + x + y * _screen.pitch) = colour.p; }); } -void Blitter_8bppBase::DrawRect(void *video, int width, int height, uint8_t colour) +void Blitter_8bppBase::DrawRect(void *video, int width, int height, PixelColour colour) { std::byte *p = static_cast(video); do { - std::fill_n(p, width, static_cast(colour)); + std::fill_n(p, width, static_cast(colour.p)); p += _screen.pitch; } while (--height); } diff --git a/src/blitter/8bpp_base.hpp b/src/blitter/8bpp_base.hpp index 5a76d79521..197b1f3a49 100644 --- a/src/blitter/8bpp_base.hpp +++ b/src/blitter/8bpp_base.hpp @@ -18,9 +18,9 @@ public: uint8_t GetScreenDepth() override { return 8; } void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override; void *MoveTo(void *video, int x, int y) override; - void SetPixel(void *video, int x, int y, uint8_t colour) override; - void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash) override; - void DrawRect(void *video, int width, int height, uint8_t colour) override; + void SetPixel(void *video, int x, int y, PixelColour colour) override; + void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, PixelColour colour, int width, int dash) override; + void DrawRect(void *video, int width, int height, PixelColour colour) override; void CopyFromBuffer(void *video, const void *src, int width, int height) override; void CopyToBuffer(const void *video, void *dst, int width, int height) override; void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) override; diff --git a/src/blitter/base.hpp b/src/blitter/base.hpp index 2a31d1d0b0..361cee3642 100644 --- a/src/blitter/base.hpp +++ b/src/blitter/base.hpp @@ -95,18 +95,18 @@ public: * @param video The destination pointer (video-buffer). * @param x The x position within video-buffer. * @param y The y position within video-buffer. - * @param colour A 8bpp mapping colour. + * @param colour A pixel colour. */ - virtual void SetPixel(void *video, int x, int y, uint8_t colour) = 0; + virtual void SetPixel(void *video, int x, int y, PixelColour colour) = 0; /** * Make a single horizontal line in a single colour on the video-buffer. * @param video The destination pointer (video-buffer). * @param width The length of the line. * @param height The height of the line. - * @param colour A 8bpp mapping colour. + * @param colour A pixel colour. */ - virtual void DrawRect(void *video, int width, int height, uint8_t colour) = 0; + virtual void DrawRect(void *video, int width, int height, PixelColour colour) = 0; /** * Draw a line with a given colour. @@ -117,11 +117,11 @@ public: * @param y2 The y coordinate to where the lines goes. * @param screen_width The width of the screen you are drawing in (to avoid buffer-overflows). * @param screen_height The height of the screen you are drawing in (to avoid buffer-overflows). - * @param colour A 8bpp mapping colour. + * @param colour A pixel colour. * @param width Line width. * @param dash Length of dashes for dashed lines. 0 means solid line. */ - virtual void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash = 0) = 0; + virtual void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, PixelColour colour, int width, int dash = 0) = 0; /** * Copy from a buffer to the screen. diff --git a/src/blitter/null.hpp b/src/blitter/null.hpp index 8e90ca9af8..336cb7c770 100644 --- a/src/blitter/null.hpp +++ b/src/blitter/null.hpp @@ -20,9 +20,9 @@ public: void DrawColourMappingRect(void *, int, int, PaletteID) override {}; Sprite *Encode(SpriteType sprite_type, const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override; void *MoveTo(void *, int, int) override { return nullptr; }; - void SetPixel(void *, int, int, uint8_t) override {}; - void DrawRect(void *, int, int, uint8_t) override {}; - void DrawLine(void *, int, int, int, int, int, int, uint8_t, int, int) override {}; + void SetPixel(void *, int, int, PixelColour) override {}; + void DrawRect(void *, int, int, PixelColour) override {}; + void DrawLine(void *, int, int, int, int, int, int, PixelColour, int, int) override {}; void CopyFromBuffer(void *, const void *, int, int) override {}; void CopyToBuffer(const void *, void *, int, int) override {}; void CopyImageToBuffer(const void *, void *, int, int, int) override {}; diff --git a/src/bootstrap_gui.cpp b/src/bootstrap_gui.cpp index 8d9897b51d..80620f303b 100644 --- a/src/bootstrap_gui.cpp +++ b/src/bootstrap_gui.cpp @@ -60,8 +60,8 @@ public: void DrawWidget(const Rect &r, WidgetID) const override { - GfxFillRect(r.left, r.top, r.right, r.bottom, 4, FILLRECT_OPAQUE); - GfxFillRect(r.left, r.top, r.right, r.bottom, 0, FILLRECT_CHECKER); + GfxFillRect(r.left, r.top, r.right, r.bottom, PixelColour{4}, FILLRECT_OPAQUE); + GfxFillRect(r.left, r.top, r.right, r.bottom, PixelColour{0}, FILLRECT_CHECKER); } }; @@ -385,10 +385,10 @@ bool HandleBootstrap() /* Initialise the palette. The biggest step is 'faking' some recolour sprites. * This way the mauve and gray colours work and we can show the user interface. */ GfxInitPalettes(); - static const int offsets[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x80, 0, 0, 0, 0x04, 0x08 }; + static const uint8_t offsets[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x80, 0, 0, 0, 0x04, 0x08 }; for (Colours i = COLOUR_BEGIN; i != COLOUR_END; i++) { for (ColourShade j = SHADE_BEGIN; j < SHADE_END; j++) { - SetColourGradient(i, j, offsets[i] + j); + SetColourGradient(i, j, PixelColour(offsets[i] + j)); } } diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index d77ea2126c..1e76cfb8b1 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -956,7 +956,7 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li int sprite_right = GetVehicleImageCellSize(type, EIT_PURCHASE).extend_right; int sprite_width = sprite_left + sprite_right; int circle_width = std::max(GetScaledSpriteSize(SPR_CIRCLE_FOLDED).width, GetScaledSpriteSize(SPR_CIRCLE_UNFOLDED).width); - int linecolour = GetColourGradient(COLOUR_ORANGE, SHADE_NORMAL); + PixelColour linecolour = GetColourGradient(COLOUR_ORANGE, SHADE_NORMAL); auto badge_column_widths = badge_classes.GetColumnWidths(); diff --git a/src/cargotype.h b/src/cargotype.h index 3ca15bfcae..444f1f5b76 100644 --- a/src/cargotype.h +++ b/src/cargotype.h @@ -74,8 +74,8 @@ static const uint TOWN_PRODUCTION_DIVISOR = 256; struct CargoSpec { CargoLabel label; ///< Unique label of the cargo type. uint8_t bitnum = INVALID_CARGO_BITNUM; ///< Cargo bit number, is #INVALID_CARGO_BITNUM for a non-used spec. - uint8_t legend_colour; - uint8_t rating_colour; + PixelColour legend_colour; + PixelColour rating_colour; uint8_t weight; ///< Weight of a single unit of this cargo type in 1/16 ton (62.5 kg). uint16_t multiplier = 0x100; ///< Capacity multiplier for vehicles. (8 fractional bits) CargoClasses classes; ///< Classes of this cargo type. @see CargoClass diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 3f48937794..6b7d21f0c3 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -150,8 +150,8 @@ void SetLocalCompany(CompanyID new_company) */ TextColour GetDrawStringCompanyColour(CompanyID company) { - if (!Company::IsValidID(company)) return (TextColour)GetColourGradient(COLOUR_WHITE, SHADE_NORMAL) | TC_IS_PALETTE_COLOUR; - return (TextColour)GetColourGradient(_company_colours[company], SHADE_NORMAL) | TC_IS_PALETTE_COLOUR; + if (!Company::IsValidID(company)) return GetColourGradient(COLOUR_WHITE, SHADE_NORMAL).ToTextColour(); + return GetColourGradient(_company_colours[company], SHADE_NORMAL).ToTextColour(); } /** diff --git a/src/console_gui.cpp b/src/console_gui.cpp index def783bbb7..db8831f259 100644 --- a/src/console_gui.cpp +++ b/src/console_gui.cpp @@ -544,7 +544,7 @@ bool IsValidConsoleColour(TextColour c) * colour gradient, so it must be one of those. */ c &= ~TC_IS_PALETTE_COLOUR; for (Colours i = COLOUR_BEGIN; i < COLOUR_END; i++) { - if (GetColourGradient(i, SHADE_NORMAL) == c) return true; + if (GetColourGradient(i, SHADE_NORMAL).p == c) return true; } return false; diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index ce738a0ad1..c1f5963542 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -413,7 +413,7 @@ struct DepotWindow : Window { */ if (this->type == VEH_TRAIN && _consistent_train_width != 0) { int w = ScaleSpriteTrad(2 * _consistent_train_width); - int col = GetColourGradient(wid->colour, SHADE_NORMAL); + PixelColour col = GetColourGradient(wid->colour, SHADE_NORMAL); Rect image = ir.Indent(this->header_width, rtl).Indent(this->count_width, !rtl); int first_line = w + (-this->hscroll->GetPosition()) % w; if (rtl) { diff --git a/src/dropdown_common_type.h b/src/dropdown_common_type.h index 21f0a01865..80362f6712 100644 --- a/src/dropdown_common_type.h +++ b/src/dropdown_common_type.h @@ -37,8 +37,8 @@ public: void Draw(const Rect &full, const Rect &, bool, int, Colours bg_colour) const override { - uint8_t c1 = GetColourGradient(bg_colour, SHADE_DARK); - uint8_t c2 = GetColourGradient(bg_colour, SHADE_LIGHTEST); + PixelColour c1 = GetColourGradient(bg_colour, SHADE_DARK); + PixelColour c2 = GetColourGradient(bg_colour, SHADE_LIGHTEST); int mid = CentreBounds(full.top, full.bottom, 0); GfxFillRect(full.left, mid - WidgetDimensions::scaled.bevel.bottom, full.right, mid - 1, c1); diff --git a/src/framerate_gui.cpp b/src/framerate_gui.cpp index 2667a473b6..72c0aa2f97 100644 --- a/src/framerate_gui.cpp +++ b/src/framerate_gui.cpp @@ -867,9 +867,9 @@ struct FrametimeGraphWindow : Window { const int x_max = r.right; const int y_zero = r.top + (int)this->graph_size.height; const int y_max = r.top; - const int c_grid = PC_DARK_GREY; - const int c_lines = PC_BLACK; - const int c_peak = PC_DARK_RED; + const PixelColour c_grid = PC_DARK_GREY; + const PixelColour c_lines = PC_BLACK; + const PixelColour c_peak = PC_DARK_RED; const TimingMeasurement draw_horz_scale = (TimingMeasurement)this->horizontal_scale * TIMESTAMP_PRECISION / 2; const TimingMeasurement draw_vert_scale = (TimingMeasurement)this->vertical_scale; @@ -959,7 +959,7 @@ struct FrametimeGraphWindow : Window { /* If the peak value is significantly larger than the average, mark and label it */ if (points_drawn > 0 && peak_value > TIMESTAMP_PRECISION / 100 && 2 * peak_value > 3 * value_sum / points_drawn) { - TextColour tc_peak = (TextColour)(TC_IS_PALETTE_COLOUR | c_peak); + TextColour tc_peak = c_peak.ToTextColour(); GfxFillRect(peak_point.x - 1, peak_point.y - 1, peak_point.x + 1, peak_point.y + 1, c_peak); uint64_t value = peak_value * 1000 / TIMESTAMP_PRECISION; int label_y = std::max(y_max, peak_point.y - GetCharacterHeight(FS_SMALL)); diff --git a/src/gfx.cpp b/src/gfx.cpp index 762a5c47d2..d2fbe83325 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -113,7 +113,7 @@ void GfxScroll(int left, int top, int width, int height, int xo, int yo) * FILLRECT_CHECKER: Like FILLRECT_OPAQUE, but only draw every second pixel (used to grey out things) * FILLRECT_RECOLOUR: Apply a recolour sprite to every pixel in the rectangle currently on screen */ -void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode) +void GfxFillRect(int left, int top, int right, int bottom, const std::variant &colour, FillRectMode mode) { Blitter *blitter = BlitterFactory::GetCurrentBlitter(); const DrawPixelInfo *dpi = _cur_dpi; @@ -142,17 +142,18 @@ void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectM switch (mode) { default: // FILLRECT_OPAQUE - blitter->DrawRect(dst, right, bottom, (uint8_t)colour); + blitter->DrawRect(dst, right, bottom, std::get(colour)); break; case FILLRECT_RECOLOUR: - blitter->DrawColourMappingRect(dst, right, bottom, GB(colour, 0, PALETTE_WIDTH)); + blitter->DrawColourMappingRect(dst, right, bottom, GB(std::get(colour), 0, PALETTE_WIDTH)); break; case FILLRECT_CHECKER: { uint8_t bo = (oleft - left + dpi->left + otop - top + dpi->top) & 1; + PixelColour pc = std::get(colour); do { - for (int i = (bo ^= 1); i < right; i += 2) blitter->SetPixel(dst, i, 0, (uint8_t)colour); + for (int i = (bo ^= 1); i < right; i += 2) blitter->SetPixel(dst, i, 0, pc); dst = blitter->MoveTo(dst, 0, 1); } while (--bottom > 0); break; @@ -209,7 +210,7 @@ static std::vector MakePolygonSegments(std::span shape * FILLRECT_CHECKER: Fill every other pixel with the specified colour, in a checkerboard pattern. * FILLRECT_RECOLOUR: Apply a recolour sprite to every pixel in the polygon. */ -void GfxFillPolygon(std::span shape, int colour, FillRectMode mode) +void GfxFillPolygon(std::span shape, const std::variant &colour, FillRectMode mode) { Blitter *blitter = BlitterFactory::GetCurrentBlitter(); const DrawPixelInfo *dpi = _cur_dpi; @@ -278,18 +279,20 @@ void GfxFillPolygon(std::span shape, int colour, FillRectMode mode) void *dst = blitter->MoveTo(dpi->dst_ptr, x1, y); switch (mode) { default: // FILLRECT_OPAQUE - blitter->DrawRect(dst, x2 - x1, 1, (uint8_t)colour); + blitter->DrawRect(dst, x2 - x1, 1, std::get(colour)); break; case FILLRECT_RECOLOUR: - blitter->DrawColourMappingRect(dst, x2 - x1, 1, GB(colour, 0, PALETTE_WIDTH)); + blitter->DrawColourMappingRect(dst, x2 - x1, 1, GB(std::get(colour), 0, PALETTE_WIDTH)); break; - case FILLRECT_CHECKER: + case FILLRECT_CHECKER: { /* Fill every other pixel, offset such that the sum of filled pixels' X and Y coordinates is odd. * This creates a checkerboard effect. */ + PixelColour pc = std::get(colour); for (int x = (x1 + y) & 1; x < x2 - x1; x += 2) { - blitter->SetPixel(dst, x, 0, (uint8_t)colour); + blitter->SetPixel(dst, x, 0, pc); } break; + } } } @@ -312,7 +315,7 @@ void GfxFillPolygon(std::span shape, int colour, FillRectMode mode) * @param width Width of the line. * @param dash Length of dashes for dashed lines. 0 means solid line. */ -static inline void GfxDoDrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash = 0) +static inline void GfxDoDrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, PixelColour colour, int width, int dash = 0) { Blitter *blitter = BlitterFactory::GetCurrentBlitter(); @@ -385,7 +388,7 @@ static inline bool GfxPreprocessLine(DrawPixelInfo *dpi, int &x, int &y, int &x2 return true; } -void GfxDrawLine(int x, int y, int x2, int y2, int colour, int width, int dash) +void GfxDrawLine(int x, int y, int x2, int y2, PixelColour colour, int width, int dash) { DrawPixelInfo *dpi = _cur_dpi; if (GfxPreprocessLine(dpi, x, y, x2, y2, width)) { @@ -393,7 +396,7 @@ void GfxDrawLine(int x, int y, int x2, int y2, int colour, int width, int dash) } } -void GfxDrawLineUnscaled(int x, int y, int x2, int y2, int colour) +void GfxDrawLineUnscaled(int x, int y, int x2, int y2, PixelColour colour) { DrawPixelInfo *dpi = _cur_dpi; if (GfxPreprocessLine(dpi, x, y, x2, y2, 1)) { @@ -434,7 +437,7 @@ void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3) * ....V. */ - static const uint8_t colour = PC_WHITE; + static constexpr PixelColour colour = PC_WHITE; GfxDrawLineUnscaled(x, y, x + dx1, y + dy1, colour); GfxDrawLineUnscaled(x, y, x + dx2, y + dy2, colour); @@ -455,7 +458,7 @@ void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3) * @param width Width of the outline. * @param dash Length of dashes for dashed lines. 0 means solid lines. */ -void DrawRectOutline(const Rect &r, int colour, int width, int dash) +void DrawRectOutline(const Rect &r, PixelColour colour, int width, int dash) { GfxDrawLine(r.left, r.top, r.right, r.top, colour, width, dash); GfxDrawLine(r.left, r.top, r.left, r.bottom, colour, width, dash); @@ -477,7 +480,7 @@ static void SetColourRemap(TextColour colour) bool raw_colour = (colour & TC_IS_PALETTE_COLOUR) != 0; colour &= ~(TC_NO_SHADE | TC_IS_PALETTE_COLOUR | TC_FORCED); - _string_colourremap[1] = raw_colour ? (uint8_t)colour : _string_colourmap[colour]; + _string_colourremap[1] = raw_colour ? (uint8_t)colour : _string_colourmap[colour].p; _string_colourremap[2] = no_shade ? 0 : 1; _colour_remap_ptr = _string_colourremap; } @@ -639,7 +642,7 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left, } if (underline) { - GfxFillRect(left, y + h, right, y + h + WidgetDimensions::scaled.bevel.top - 1, _string_colourremap[1]); + GfxFillRect(left, y + h, right, y + h + WidgetDimensions::scaled.bevel.top - 1, PixelColour{_string_colourremap[1]}); } return (align & SA_HOR_MASK) == SA_RIGHT ? left : right; diff --git a/src/gfx_func.h b/src/gfx_func.h index edd5b03d82..885f72ccf9 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -103,11 +103,11 @@ bool DrawStringMultiLineWithClipping(int left, int right, int top, int bottom, s void DrawCharCentered(char32_t c, const Rect &r, TextColour colour); -void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode = FILLRECT_OPAQUE); -void GfxFillPolygon(std::span shape, int colour, FillRectMode mode = FILLRECT_OPAQUE); -void GfxDrawLine(int left, int top, int right, int bottom, int colour, int width = 1, int dash = 0); +void GfxFillRect(int left, int top, int right, int bottom, const std::variant &colour, FillRectMode mode = FILLRECT_OPAQUE); +void GfxFillPolygon(std::span shape, const std::variant &colour, FillRectMode mode = FILLRECT_OPAQUE); +void GfxDrawLine(int left, int top, int right, int bottom, PixelColour colour, int width = 1, int dash = 0); void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3); -void DrawRectOutline(const Rect &r, int colour, int width = 1, int dash = 0); +void DrawRectOutline(const Rect &r, PixelColour colour, int width = 1, int dash = 0); /* Versions of DrawString/DrawStringMultiLine that accept a Rect instead of separate left, right, top and bottom parameters. */ inline int DrawString(const Rect &r, std::string_view str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL) @@ -135,7 +135,7 @@ inline bool DrawStringMultiLineWithClipping(const Rect &r, std::string_view str, return DrawStringMultiLineWithClipping(r.left, r.right, r.top, r.bottom, str, colour, align, underline, fontsize); } -inline void GfxFillRect(const Rect &r, int colour, FillRectMode mode = FILLRECT_OPAQUE) +inline void GfxFillRect(const Rect &r, const std::variant &colour, FillRectMode mode = FILLRECT_OPAQUE) { GfxFillRect(r.left, r.top, r.right, r.bottom, colour, mode); } diff --git a/src/gfx_type.h b/src/gfx_type.h index 718f7a455d..4434690bdd 100644 --- a/src/gfx_type.h +++ b/src/gfx_type.h @@ -245,7 +245,6 @@ using Colour = std::conditional_t(this->p) | TC_IS_PALETTE_COLOUR; } +}; + #endif /* GFX_TYPE_H */ diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index 3e744f5670..cbd76d8ea0 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -165,11 +165,11 @@ struct ValuesInterval { struct BaseGraphWindow : Window { protected: static const int GRAPH_MAX_DATASETS = 64; - static const int GRAPH_BASE_COLOUR = GREY_SCALE(2); - static const int GRAPH_GRID_COLOUR = GREY_SCALE(3); - static const int GRAPH_AXIS_LINE_COLOUR = GREY_SCALE(1); - static const int GRAPH_ZERO_LINE_COLOUR = GREY_SCALE(8); - static const int GRAPH_YEAR_LINE_COLOUR = GREY_SCALE(5); + static constexpr PixelColour GRAPH_BASE_COLOUR = GREY_SCALE(2); + static constexpr PixelColour GRAPH_GRID_COLOUR = GREY_SCALE(3); + static constexpr PixelColour GRAPH_AXIS_LINE_COLOUR = GREY_SCALE(1); + static constexpr PixelColour GRAPH_ZERO_LINE_COLOUR = GREY_SCALE(8); + static constexpr PixelColour GRAPH_YEAR_LINE_COLOUR = GREY_SCALE(5); static const int GRAPH_NUM_MONTHS = 24; ///< Number of months displayed in the graph. static const int GRAPH_PAYMENT_RATE_STEPS = 20; ///< Number of steps on Payment rate graph. static const int PAYMENT_GRAPH_X_STEP_DAYS = 10; ///< X-axis step label for cargo payment rates "Days in transit". @@ -203,7 +203,7 @@ protected: struct DataSet { std::array values; - uint8_t colour; + PixelColour colour; uint8_t exclude_bit; uint8_t range_bit; uint8_t dash; @@ -390,7 +390,7 @@ protected: /* Draw the grid lines. */ int gridline_width = WidgetDimensions::scaled.bevel.top; - int grid_colour = GRAPH_GRID_COLOUR; + PixelColour grid_colour = GRAPH_GRID_COLOUR; /* Don't draw the first line, as that's where the axis will be. */ if (rtl) { @@ -516,7 +516,7 @@ protected: uint pointoffs1 = pointwidth / 2; uint pointoffs2 = pointwidth - pointoffs1; - auto draw_dataset = [&](const DataSet &dataset, uint8_t colour) { + auto draw_dataset = [&](const DataSet &dataset, PixelColour colour) { if (HasBit(this->excluded_data, dataset.exclude_bit)) return; if (HasBit(this->excluded_range, dataset.range_bit)) return; @@ -1208,7 +1208,7 @@ struct BaseCargoGraphWindow : BaseGraphWindow { /* Cargo-colour box with outline */ const Rect cargo = text.WithWidth(this->legend_width, rtl); GfxFillRect(cargo, PC_BLACK); - uint8_t pc = cs->legend_colour; + PixelColour pc = cs->legend_colour; if (this->highlight_data == cs->Index()) pc = this->highlight_state ? PC_WHITE : PC_BLACK; GfxFillRect(cargo.Shrink(WidgetDimensions::scaled.bevel), pc); @@ -1485,8 +1485,8 @@ struct PerformanceRatingDetailWindow : Window { ScoreID score_type = (ScoreID)(widget - WID_PRD_SCORE_FIRST); /* The colours used to show how the progress is going */ - int colour_done = GetColourGradient(COLOUR_GREEN, SHADE_NORMAL); - int colour_notdone = GetColourGradient(COLOUR_RED, SHADE_NORMAL); + PixelColour colour_done = GetColourGradient(COLOUR_GREEN, SHADE_NORMAL); + PixelColour colour_notdone = GetColourGradient(COLOUR_RED, SHADE_NORMAL); /* Draw all the score parts */ int64_t val = _score_part[company][score_type]; diff --git a/src/group_gui.cpp b/src/group_gui.cpp index e94844f02f..df081be946 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -305,7 +305,7 @@ private: const int offset = (rtl ? -(int)this->column_size[VGC_FOLD].width : (int)this->column_size[VGC_FOLD].width) / 2; const int level_width = rtl ? -WidgetDimensions::scaled.hsep_indent : WidgetDimensions::scaled.hsep_indent; - const int linecolour = GetColourGradient(COLOUR_ORANGE, SHADE_NORMAL); + const PixelColour linecolour = GetColourGradient(COLOUR_ORANGE, SHADE_NORMAL); if (indent > 0) { /* Draw tree continuation lines. */ diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 6119c486dd..d9140e8cb9 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -2005,8 +2005,8 @@ struct CargoesField { static Dimension cargo_space; static Dimension cargo_stub; - static const int INDUSTRY_LINE_COLOUR; - static const int CARGO_LINE_COLOUR; + static const PixelColour INDUSTRY_LINE_COLOUR; + static const PixelColour CARGO_LINE_COLOUR; static int small_height, normal_height; static int cargo_field_width; @@ -2414,8 +2414,8 @@ int CargoesField::vert_inter_industry_space; ///< Amount of space between two in int CargoesField::blob_distance; ///< Distance of the industry legend colour from the edge of the industry box. -const int CargoesField::INDUSTRY_LINE_COLOUR = PC_YELLOW; ///< Line colour of the industry type box. -const int CargoesField::CARGO_LINE_COLOUR = PC_YELLOW; ///< Line colour around the cargo. +const PixelColour CargoesField::INDUSTRY_LINE_COLOUR = PC_YELLOW; ///< Line colour of the industry type box. +const PixelColour CargoesField::CARGO_LINE_COLOUR = PC_YELLOW; ///< Line colour around the cargo. /** A single row of #CargoesField. */ struct CargoesRow { diff --git a/src/industrytype.h b/src/industrytype.h index 1f06ab64e6..74e33e26a7 100644 --- a/src/industrytype.h +++ b/src/industrytype.h @@ -119,7 +119,7 @@ struct IndustrySpec { IndustryLifeTypes life_type; ///< This is also known as Industry production flag, in newgrf specs LandscapeTypes climate_availability; ///< Bitmask, giving landscape enums as bit position IndustryBehaviours behaviour; ///< How this industry will behave, and how others entities can use it - uint8_t map_colour; ///< colour used for the small map + PixelColour map_colour; ///< colour used for the small map StringID name; ///< Displayed name of the industry StringID new_industry_text; ///< Message appearing when the industry is built StringID closure_text; ///< Message appearing when the industry closes diff --git a/src/linkgraph/linkgraph_gui.cpp b/src/linkgraph/linkgraph_gui.cpp index 57ab1dfaf0..5cb9320b41 100644 --- a/src/linkgraph/linkgraph_gui.cpp +++ b/src/linkgraph/linkgraph_gui.cpp @@ -30,26 +30,26 @@ * Colours for the various "load" states of links. Ordered from "unused" to * "overloaded". */ -const uint8_t LinkGraphOverlay::LINK_COLOURS[][12] = { +const PixelColour LinkGraphOverlay::LINK_COLOURS[][12] = { { - 0x0f, 0xd1, 0xd0, 0x57, - 0x55, 0x53, 0xbf, 0xbd, - 0xba, 0xb9, 0xb7, 0xb5 + PixelColour{0x0f}, PixelColour{0xd1}, PixelColour{0xd0}, PixelColour{0x57}, + PixelColour{0x55}, PixelColour{0x53}, PixelColour{0xbf}, PixelColour{0xbd}, + PixelColour{0xba}, PixelColour{0xb9}, PixelColour{0xb7}, PixelColour{0xb5} }, { - 0x0f, 0xd1, 0xd0, 0x57, - 0x55, 0x53, 0x96, 0x95, - 0x94, 0x93, 0x92, 0x91 + PixelColour{0x0f}, PixelColour{0xd1}, PixelColour{0xd0}, PixelColour{0x57}, + PixelColour{0x55}, PixelColour{0x53}, PixelColour{0x96}, PixelColour{0x95}, + PixelColour{0x94}, PixelColour{0x93}, PixelColour{0x92}, PixelColour{0x91} }, { - 0x0f, 0x0b, 0x09, 0x07, - 0x05, 0x03, 0xbf, 0xbd, - 0xba, 0xb9, 0xb7, 0xb5 + PixelColour{0x0f}, PixelColour{0x0b}, PixelColour{0x09}, PixelColour{0x07}, + PixelColour{0x05}, PixelColour{0x03}, PixelColour{0xbf}, PixelColour{0xbd}, + PixelColour{0xba}, PixelColour{0xb9}, PixelColour{0xb7}, PixelColour{0xb5} }, { - 0x0f, 0x0b, 0x0a, 0x09, - 0x08, 0x07, 0x06, 0x05, - 0x04, 0x03, 0x02, 0x01 + PixelColour{0x0f}, PixelColour{0x0b}, PixelColour{0x0a}, PixelColour{0x09}, + PixelColour{0x08}, PixelColour{0x07}, PixelColour{0x06}, PixelColour{0x05}, + PixelColour{0x04}, PixelColour{0x03}, PixelColour{0x02}, PixelColour{0x01} } }; @@ -297,7 +297,7 @@ void LinkGraphOverlay::DrawLinks(const DrawPixelInfo *dpi) const void LinkGraphOverlay::DrawContent(Point pta, Point ptb, const LinkProperties &cargo) const { uint usage_or_plan = std::min(cargo.capacity * 2 + 1, cargo.Usage()); - int colour = LinkGraphOverlay::LINK_COLOURS[_settings_client.gui.linkgraph_colours][usage_or_plan * lengthof(LinkGraphOverlay::LINK_COLOURS[0]) / (cargo.capacity * 2 + 2)]; + PixelColour colour = LinkGraphOverlay::LINK_COLOURS[_settings_client.gui.linkgraph_colours][usage_or_plan * lengthof(LinkGraphOverlay::LINK_COLOURS[0]) / (cargo.capacity * 2 + 2)]; int width = ScaleGUITrad(this->scale); int dash = cargo.shared ? width * 4 : 0; @@ -345,7 +345,7 @@ void LinkGraphOverlay::DrawStationDots(const DrawPixelInfo *dpi) const * @param colour Colour with which the vertex will be filled. * @param border_colour Colour for the border of the vertex. */ -/* static */ void LinkGraphOverlay::DrawVertex(int x, int y, int size, int colour, int border_colour) +/* static */ void LinkGraphOverlay::DrawVertex(int x, int y, int size, PixelColour colour, PixelColour border_colour) { size--; int w1 = size / 2; @@ -607,7 +607,7 @@ void LinkGraphLegendWindow::DrawWidget(const Rect &r, WidgetID widget) const DrawCompanyIcon(cid, CentreBounds(br.left, br.right, sprite_size.width), CentreBounds(br.top, br.bottom, sprite_size.height)); } if (IsInsideMM(widget, WID_LGL_SATURATION_FIRST, WID_LGL_SATURATION_LAST + 1)) { - uint8_t colour = LinkGraphOverlay::LINK_COLOURS[_settings_client.gui.linkgraph_colours][widget - WID_LGL_SATURATION_FIRST]; + PixelColour colour = LinkGraphOverlay::LINK_COLOURS[_settings_client.gui.linkgraph_colours][widget - WID_LGL_SATURATION_FIRST]; GfxFillRect(br, colour); StringID str = STR_NULL; if (widget == WID_LGL_SATURATION_FIRST) { diff --git a/src/linkgraph/linkgraph_gui.h b/src/linkgraph/linkgraph_gui.h index 1f0a828cdb..2df5ca25aa 100644 --- a/src/linkgraph/linkgraph_gui.h +++ b/src/linkgraph/linkgraph_gui.h @@ -44,7 +44,7 @@ public: typedef std::map LinkMap; typedef std::vector > StationSupplyList; - static const uint8_t LINK_COLOURS[][12]; + static const PixelColour LINK_COLOURS[][12]; /** * Create a link graph overlay for the specified window. @@ -95,7 +95,7 @@ protected: void RebuildCache(); static void AddStats(CargoType new_cargo, uint new_cap, uint new_usg, uint new_flow, uint32_t time, bool new_shared, LinkProperties &cargo); - static void DrawVertex(int x, int y, int size, int colour, int border_colour); + static void DrawVertex(int x, int y, int size, PixelColour colour, PixelColour border_colour); }; void ShowLinkGraphLegend(); diff --git a/src/main_gui.cpp b/src/main_gui.cpp index f58f759867..57e991b3ad 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -556,7 +556,7 @@ void SetupColoursAndInitialWindow() const uint8_t *b = GetNonSprite(GetColourPalette(i), SpriteType::Recolour) + 1; assert(b != nullptr); for (ColourShade j = SHADE_BEGIN; j < SHADE_END; j++) { - SetColourGradient(i, j, b[0xC6 + j]); + SetColourGradient(i, j, PixelColour{b[0xC6 + j]}); } } diff --git a/src/newgrf/newgrf_act0_cargo.cpp b/src/newgrf/newgrf_act0_cargo.cpp index c5794a2874..6c8be8c7d1 100644 --- a/src/newgrf/newgrf_act0_cargo.cpp +++ b/src/newgrf/newgrf_act0_cargo.cpp @@ -97,11 +97,11 @@ static ChangeInfoResult CargoReserveInfo(uint first, uint last, int prop, ByteRe break; case 0x13: // Colour for station rating bars - cs->rating_colour = buf.ReadByte(); + cs->rating_colour = PixelColour{buf.ReadByte()}; break; case 0x14: // Colour for cargo graph - cs->legend_colour = buf.ReadByte(); + cs->legend_colour = PixelColour{buf.ReadByte()}; break; case 0x15: // Freight status diff --git a/src/newgrf/newgrf_act0_industries.cpp b/src/newgrf/newgrf_act0_industries.cpp index f1bd06c880..b01668400f 100644 --- a/src/newgrf/newgrf_act0_industries.cpp +++ b/src/newgrf/newgrf_act0_industries.cpp @@ -565,7 +565,7 @@ static ChangeInfoResult IndustriesChangeInfo(uint first, uint last, int prop, By break; case 0x19: // Map colour - indsp->map_colour = buf.ReadByte(); + indsp->map_colour = PixelColour{buf.ReadByte()}; break; case 0x1A: // Special industry flags to define special behavior diff --git a/src/newgrf/newgrf_act0_railtypes.cpp b/src/newgrf/newgrf_act0_railtypes.cpp index fe9e52132d..9db6f6c7b5 100644 --- a/src/newgrf/newgrf_act0_railtypes.cpp +++ b/src/newgrf/newgrf_act0_railtypes.cpp @@ -121,7 +121,7 @@ static ChangeInfoResult RailTypeChangeInfo(uint first, uint last, int prop, Byte break; case 0x16: // Map colour - rti->map_colour = buf.ReadByte(); + rti->map_colour = PixelColour{buf.ReadByte()}; break; case 0x17: // Introduction date diff --git a/src/newgrf/newgrf_act0_roadtypes.cpp b/src/newgrf/newgrf_act0_roadtypes.cpp index f6b6f48926..d655c99b7e 100644 --- a/src/newgrf/newgrf_act0_roadtypes.cpp +++ b/src/newgrf/newgrf_act0_roadtypes.cpp @@ -109,7 +109,7 @@ static ChangeInfoResult RoadTypeChangeInfo(uint first, uint last, int prop, Byte break; case 0x16: // Map colour - rti->map_colour = buf.ReadByte(); + rti->map_colour = PixelColour{buf.ReadByte()}; break; case 0x17: // Introduction date diff --git a/src/palette.cpp b/src/palette.cpp index 84fed51898..b22ac326ea 100644 --- a/src/palette.cpp +++ b/src/palette.cpp @@ -358,9 +358,9 @@ void DoPaletteAnimations() * @param threshold Background colour brightness threshold below which the background is considered dark and TC_WHITE is returned, range: 0 - 255, default 128. * @return TC_BLACK or TC_WHITE depending on what gives a better contrast. */ -TextColour GetContrastColour(uint8_t background, uint8_t threshold) +TextColour GetContrastColour(PixelColour background, uint8_t threshold) { - Colour c = _cur_palette.palette[background]; + Colour c = _cur_palette.palette[background.p]; /* Compute brightness according to http://www.w3.org/TR/AERT#color-contrast. * The following formula computes 1000 * brightness^2, with brightness being in range 0 to 255. */ uint sq1000_brightness = c.r * c.r * 299 + c.g * c.g * 587 + c.b * c.b * 114; @@ -374,7 +374,7 @@ TextColour GetContrastColour(uint8_t background, uint8_t threshold) */ struct ColourGradients { - using ColourGradient = std::array; + using ColourGradient = std::array; static inline std::array gradient{}; }; @@ -385,7 +385,7 @@ struct ColourGradients * @param shade Shade level from 1 to 7. * @returns palette index of colour. */ -uint8_t GetColourGradient(Colours colour, ColourShade shade) +PixelColour GetColourGradient(Colours colour, ColourShade shade) { return ColourGradients::gradient[colour % COLOUR_END][shade % SHADE_END]; } @@ -396,7 +396,7 @@ uint8_t GetColourGradient(Colours colour, ColourShade shade) * @param shade Shade level from 1 to 7. * @param palette_index Palette index to set. */ -void SetColourGradient(Colours colour, ColourShade shade, uint8_t palette_index) +void SetColourGradient(Colours colour, ColourShade shade, PixelColour palette_index) { assert(colour < COLOUR_END); assert(shade < SHADE_END); diff --git a/src/palette_func.h b/src/palette_func.h index eba770b9d5..a5e7dda44c 100644 --- a/src/palette_func.h +++ b/src/palette_func.h @@ -67,7 +67,7 @@ inline bool IsValidColours(Colours colours) return colours < COLOUR_END; } -TextColour GetContrastColour(uint8_t background, uint8_t threshold = 128); +TextColour GetContrastColour(PixelColour background, uint8_t threshold = 128); enum ColourShade : uint8_t { SHADE_BEGIN = 0, @@ -83,45 +83,45 @@ enum ColourShade : uint8_t { }; DECLARE_INCREMENT_DECREMENT_OPERATORS(ColourShade) -uint8_t GetColourGradient(Colours colour, ColourShade shade); -void SetColourGradient(Colours colour, ColourShade shade, uint8_t palette_colour); +PixelColour GetColourGradient(Colours colour, ColourShade shade); +void SetColourGradient(Colours colour, ColourShade shade, PixelColour palette_colour); /** * Return the colour for a particular greyscale level. * @param level Intensity, 0 = black, 15 = white * @return colour */ -constexpr uint8_t GREY_SCALE(uint8_t level) { return level; } +inline constexpr PixelColour GREY_SCALE(uint8_t level) { return PixelColour{level}; } -static const uint8_t PC_BLACK = GREY_SCALE(1); ///< Black palette colour. -static const uint8_t PC_DARK_GREY = GREY_SCALE(6); ///< Dark grey palette colour. -static const uint8_t PC_GREY = GREY_SCALE(10); ///< Grey palette colour. -static const uint8_t PC_WHITE = GREY_SCALE(15); ///< White palette colour. +static constexpr PixelColour PC_BLACK {GREY_SCALE(1)}; ///< Black palette colour. +static constexpr PixelColour PC_DARK_GREY {GREY_SCALE(6)}; ///< Dark grey palette colour. +static constexpr PixelColour PC_GREY {GREY_SCALE(10)}; ///< Grey palette colour. +static constexpr PixelColour PC_WHITE {GREY_SCALE(15)}; ///< White palette colour. -static const uint8_t PC_VERY_DARK_RED = 0xB2; ///< Almost-black red palette colour. -static const uint8_t PC_DARK_RED = 0xB4; ///< Dark red palette colour. -static const uint8_t PC_RED = 0xB8; ///< Red palette colour. +static constexpr PixelColour PC_VERY_DARK_RED {0xB2}; ///< Almost-black red palette colour. +static constexpr PixelColour PC_DARK_RED {0xB4}; ///< Dark red palette colour. +static constexpr PixelColour PC_RED {0xB8}; ///< Red palette colour. -static const uint8_t PC_VERY_DARK_BROWN = 0x56; ///< Almost-black brown palette colour. +static constexpr PixelColour PC_VERY_DARK_BROWN {0x56}; ///< Almost-black brown palette colour. -static const uint8_t PC_ORANGE = 0xC2; ///< Orange palette colour. +static constexpr PixelColour PC_ORANGE {0xC2}; ///< Orange palette colour. -static const uint8_t PC_YELLOW = 0xBF; ///< Yellow palette colour. -static const uint8_t PC_LIGHT_YELLOW = 0x44; ///< Light yellow palette colour. -static const uint8_t PC_VERY_LIGHT_YELLOW = 0x45; ///< Almost-white yellow palette colour. +static constexpr PixelColour PC_YELLOW {0xBF}; ///< Yellow palette colour. +static constexpr PixelColour PC_LIGHT_YELLOW {0x44}; ///< Light yellow palette colour. +static constexpr PixelColour PC_VERY_LIGHT_YELLOW {0x45}; ///< Almost-white yellow palette colour. -static const uint8_t PC_GREEN = 0xD0; ///< Green palette colour. +static constexpr PixelColour PC_GREEN {0xD0}; ///< Green palette colour. -static const uint8_t PC_VERY_DARK_BLUE = 0x9A; ///< Almost-black blue palette colour. -static const uint8_t PC_DARK_BLUE = 0x9D; ///< Dark blue palette colour. -static const uint8_t PC_LIGHT_BLUE = 0x98; ///< Light blue palette colour. +static constexpr PixelColour PC_VERY_DARK_BLUE {0x9A}; ///< Almost-black blue palette colour. +static constexpr PixelColour PC_DARK_BLUE {0x9D}; ///< Dark blue palette colour. +static constexpr PixelColour PC_LIGHT_BLUE {0x98}; ///< Light blue palette colour. -static const uint8_t PC_ROUGH_LAND = 0x52; ///< Dark green palette colour for rough land. -static const uint8_t PC_GRASS_LAND = 0x54; ///< Dark green palette colour for grass land. -static const uint8_t PC_BARE_LAND = 0x37; ///< Brown palette colour for bare land. -static const uint8_t PC_RAINFOREST = 0x5C; ///< Pale green palette colour for rainforest. -static const uint8_t PC_FIELDS = 0x25; ///< Light brown palette colour for fields. -static const uint8_t PC_TREES = 0x57; ///< Green palette colour for trees. -static const uint8_t PC_WATER = 0xC9; ///< Dark blue palette colour for water. +static constexpr PixelColour PC_ROUGH_LAND {0x52}; ///< Dark green palette colour for rough land. +static constexpr PixelColour PC_GRASS_LAND {0x54}; ///< Dark green palette colour for grass land. +static constexpr PixelColour PC_BARE_LAND {0x37}; ///< Brown palette colour for bare land. +static constexpr PixelColour PC_RAINFOREST {0x5C}; ///< Pale green palette colour for rainforest. +static constexpr PixelColour PC_FIELDS {0x25}; ///< Light brown palette colour for fields. +static constexpr PixelColour PC_TREES {0x57}; ///< Green palette colour for trees. +static constexpr PixelColour PC_WATER {0xC9}; ///< Dark blue palette colour for water. #endif /* PALETTE_FUNC_H */ diff --git a/src/rail.h b/src/rail.h index 323dd00c24..e4bc280437 100644 --- a/src/rail.h +++ b/src/rail.h @@ -234,7 +234,7 @@ public: /** * Colour on mini-map */ - uint8_t map_colour; + PixelColour map_colour; /** * Introduction date. diff --git a/src/road.h b/src/road.h index 68c1aefdcf..98482d6462 100644 --- a/src/road.h +++ b/src/road.h @@ -145,7 +145,7 @@ public: /** * Colour on mini-map */ - uint8_t map_colour; + PixelColour map_colour; /** * Introduction date. diff --git a/src/settingentry_gui.cpp b/src/settingentry_gui.cpp index fcc408adb3..1aece65330 100644 --- a/src/settingentry_gui.cpp +++ b/src/settingentry_gui.cpp @@ -99,7 +99,7 @@ uint BaseSettingEntry::Draw(GameSettings *settings_ptr, int left, int right, int int x = rtl ? right : left; if (cur_row >= first_row) { - int colour = GetColourGradient(COLOUR_ORANGE, SHADE_NORMAL); + PixelColour colour = GetColourGradient(COLOUR_ORANGE, SHADE_NORMAL); y += (cur_row - first_row) * SETTING_HEIGHT; // Compute correct y start position /* Draw vertical for parent nesting levels */ diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 3e9353d488..8aedbb0fd9 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1849,7 +1849,7 @@ void ShowGameOptions() */ void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right) { - int colour = GetColourGradient(button_colour, SHADE_DARKER); + PixelColour colour = GetColourGradient(button_colour, SHADE_DARKER); Dimension dim = NWidgetScrollbar::GetHorizontalDimension(); Rect lr = {x, y, x + (int)dim.width - 1, y + (int)dim.height - 1}; @@ -1881,7 +1881,7 @@ void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool c */ void DrawUpDownButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_up, bool clickable_down) { - int colour = GetColourGradient(button_colour, SHADE_DARKER); + PixelColour colour = GetColourGradient(button_colour, SHADE_DARKER); Rect r = {x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1}; Rect ur = r.WithWidth(SETTING_BUTTON_WIDTH / 2, (_current_text_dir == TD_RTL)); @@ -1907,7 +1907,7 @@ void DrawUpDownButtons(int x, int y, Colours button_colour, uint8_t state, bool */ void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable) { - int colour = GetColourGradient(button_colour, SHADE_DARKER); + PixelColour colour = GetColourGradient(button_colour, SHADE_DARKER); Rect r = {x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1}; diff --git a/src/slider.cpp b/src/slider.cpp index 32b8223cdc..92963b6c5e 100644 --- a/src/slider.cpp +++ b/src/slider.cpp @@ -45,9 +45,9 @@ void DrawSliderWidget(Rect r, Colours wedge_colour, Colours handle_colour, TextC int wx1 = r.left + sw / 2; int wx2 = r.right - sw / 2; if (_current_text_dir == TD_RTL) std::swap(wx1, wx2); - const uint shadow = GetColourGradient(wedge_colour, SHADE_DARK); - const uint fill = GetColourGradient(wedge_colour, SHADE_LIGHTER); - const uint light = GetColourGradient(wedge_colour, SHADE_LIGHTEST); + const PixelColour shadow = GetColourGradient(wedge_colour, SHADE_DARK); + const PixelColour fill = GetColourGradient(wedge_colour, SHADE_LIGHTER); + const PixelColour light = GetColourGradient(wedge_colour, SHADE_LIGHTEST); const std::array wedge{ Point{wx1, r.bottom - ha}, Point{wx2, r.top + ha}, Point{wx2, r.bottom - ha} }; GfxFillPolygon(wedge, fill); GfxDrawLine(wedge[0].x, wedge[0].y, wedge[2].x, wedge[2].y, light, t); diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index 827b654fe9..1bdf8d6686 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -44,7 +44,7 @@ static int _smallmap_cargo_count; ///< Number of cargos in the link stats leg /** Structure for holding relevant data for legends in small map */ struct LegendAndColour { - uint8_t colour; ///< Colour of the item on the map. + PixelColour colour; ///< Colour of the item on the map. StringID legend; ///< String corresponding to the coloured item. IndustryType type; ///< Type of industry. Only valid for industry entries. uint8_t height; ///< Height in tiles. Only valid for height legend entries. @@ -63,16 +63,16 @@ static const int NUM_NO_COMPANY_ENTRIES = 4; ///< Number of entries in the owner #define MK(a, b) {a, b, IT_INVALID, 0, CompanyID::Invalid(), true, false, false} /** Macro for a height legend entry with configurable colour. */ -#define MC(col_break) {0, STR_TINY_BLACK_HEIGHT, IT_INVALID, 0, CompanyID::Invalid(), true, false, col_break} +#define MC(col_break) {PC_BLACK, STR_TINY_BLACK_HEIGHT, IT_INVALID, 0, CompanyID::Invalid(), true, false, col_break} /** Macro for non-company owned property entry of LegendAndColour */ #define MO(a, b) {a, b, IT_INVALID, 0, CompanyID::Invalid(), true, false, false} /** Macro used for forcing a rebuild of the owner legend the first time it is used. */ -#define MOEND() {0, STR_NULL, IT_INVALID, 0, OWNER_NONE, true, true, false} +#define MOEND() {PC_BLACK, STR_NULL, IT_INVALID, 0, OWNER_NONE, true, true, false} /** Macro for end of list marker in arrays of LegendAndColour */ -#define MKEND() {0, STR_NULL, IT_INVALID, 0, CompanyID::Invalid(), true, true, false} +#define MKEND() {PC_BLACK, STR_NULL, IT_INVALID, 0, CompanyID::Invalid(), true, true, false} /** * Macro for break marker in arrays of LegendAndColour. @@ -149,7 +149,7 @@ static const LegendAndColour _legend_vegetation[] = { static LegendAndColour _legend_land_owners[NUM_NO_COMPANY_ENTRIES + MAX_COMPANIES + 1] = { MO(PC_WATER, STR_SMALLMAP_LEGENDA_WATER), - MO(0x00, STR_SMALLMAP_LEGENDA_NO_OWNER), // This colour will vary depending on settings. + MO(PC_BLACK, STR_SMALLMAP_LEGENDA_NO_OWNER), // This colour will vary depending on settings. MO(PC_DARK_RED, STR_SMALLMAP_LEGENDA_TOWNS), MO(PC_DARK_GREY, STR_SMALLMAP_LEGENDA_INDUSTRIES), /* The legend will be terminated the first time it is used. */ @@ -258,15 +258,15 @@ static const LegendAndColour * const _legend_table[] = { #define MKCOLOUR(x) TO_LE32(x) -#define MKCOLOUR_XXXX(x) (MKCOLOUR(0x01010101) * (uint)(x)) -#define MKCOLOUR_0XX0(x) (MKCOLOUR(0x00010100) * (uint)(x)) -#define MKCOLOUR_X00X(x) (MKCOLOUR(0x01000001) * (uint)(x)) +#define MKCOLOUR_XXXX(x) (MKCOLOUR(0x01010101) * (uint)(x.p)) +#define MKCOLOUR_0XX0(x) (MKCOLOUR(0x00010100) * (uint)(x.p)) +#define MKCOLOUR_X00X(x) (MKCOLOUR(0x01000001) * (uint)(x.p)) #define MKCOLOUR_XYYX(x, y) (MKCOLOUR_X00X(x) | MKCOLOUR_0XX0(y)) -#define MKCOLOUR_0000 MKCOLOUR_XXXX(0x00) -#define MKCOLOUR_F00F MKCOLOUR_X00X(0xFF) -#define MKCOLOUR_FFFF MKCOLOUR_XXXX(0xFF) +#define MKCOLOUR_0000 MKCOLOUR_XXXX(PixelColour{0x00}) +#define MKCOLOUR_F00F MKCOLOUR_X00X(PixelColour{0xFF}) +#define MKCOLOUR_FFFF MKCOLOUR_XXXX(PixelColour{0xFF}) #include "table/heightmap_colours.h" @@ -279,9 +279,9 @@ struct SmallMapColourScheme { /** Available colour schemes for height maps. */ static SmallMapColourScheme _heightmap_schemes[] = { - {{}, _green_map_heights, MKCOLOUR_XXXX(0x54)}, ///< Green colour scheme. - {{}, _dark_green_map_heights, MKCOLOUR_XXXX(0x62)}, ///< Dark green colour scheme. - {{}, _violet_map_heights, MKCOLOUR_XXXX(0x81)}, ///< Violet colour scheme. + {{}, _green_map_heights, MKCOLOUR_XXXX(PixelColour{0x54})}, ///< Green colour scheme. + {{}, _dark_green_map_heights, MKCOLOUR_XXXX(PixelColour{0x62})}, ///< Dark green colour scheme. + {{}, _violet_map_heights, MKCOLOUR_XXXX(PixelColour{0x81})}, ///< Violet colour scheme. }; /** @@ -329,7 +329,7 @@ void BuildLandLegend() _legend_land_contours[i].col_break = j % rows == 0; _legend_land_contours[i].end = false; _legend_land_contours[i].height = j * delta; - _legend_land_contours[i].colour = static_cast(_heightmap_schemes[_settings_client.gui.smallmap_land_colour].height_colours[_legend_land_contours[i].height]); + _legend_land_contours[i].colour = PixelColour{static_cast(_heightmap_schemes[_settings_client.gui.smallmap_land_colour].height_colours[_legend_land_contours[i].height])}; j++; } _legend_land_contours[i].end = true; @@ -340,7 +340,7 @@ void BuildLandLegend() */ void BuildOwnerLegend() { - _legend_land_owners[1].colour = static_cast(_heightmap_schemes[_settings_client.gui.smallmap_land_colour].default_colour); + _legend_land_owners[1].colour = PixelColour{static_cast(_heightmap_schemes[_settings_client.gui.smallmap_land_colour].default_colour)}; int i = NUM_NO_COMPANY_ENTRIES; for (const Company *c : Company::Iterate()) { @@ -607,7 +607,7 @@ uint32_t GetSmallMapOwnerPixels(TileIndex tile, TileType t, IncludeHeightmap inc } /** Vehicle colours in #SMT_VEHICLES mode. Indexed by #VehicleType. */ -static const uint8_t _vehicle_type_colours[6] = { +static const PixelColour _vehicle_type_colours[6] = { PC_RED, PC_YELLOW, PC_LIGHT_BLUE, PC_WHITE, PC_BLACK, PC_RED }; @@ -935,7 +935,7 @@ protected: uint8_t *val8 = (uint8_t *)&val; int idx = std::max(0, -start_pos); for (int pos = std::max(0, start_pos); pos < end_pos; pos++) { - blitter->SetPixel(dst, idx, 0, val8[idx]); + blitter->SetPixel(dst, idx, 0, PixelColour{val8[idx]}); idx++; } /* Switch to next tile in the column */ @@ -973,7 +973,7 @@ protected: } /* Calculate pointer to pixel and the colour */ - uint8_t colour = (this->map_type == SMT_VEHICLES) ? _vehicle_type_colours[v->type] : PC_WHITE; + PixelColour colour = (this->map_type == SMT_VEHICLES) ? _vehicle_type_colours[v->type] : PC_WHITE; /* And draw either one or two pixels depending on clipping */ blitter->SetPixel(dpi->dst_ptr, x, y, colour); @@ -1348,7 +1348,7 @@ protected: if (type == _smallmap_industry_highlight) { if (_smallmap_industry_highlight_state) return MKCOLOUR_XXXX(PC_WHITE); } else { - return GetIndustrySpec(type)->map_colour * 0x01010101; + return GetIndustrySpec(type)->map_colour.p * 0x01010101; } } /* Otherwise make it disappear */ @@ -1644,7 +1644,7 @@ public: i = 1; } - uint8_t legend_colour = tbl->colour; + PixelColour legend_colour = tbl->colour; std::array params{}; switch (this->map_type) { diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 4f0979ec86..f3b1b1aacd 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -225,7 +225,7 @@ static void StationsWndShowStationRating(int left, int right, int y, CargoType c int padding = ScaleGUITrad(1); int width = right - left; - int colour = cs->rating_colour; + PixelColour colour = cs->rating_colour; TextColour tc = GetContrastColour(colour); uint w = std::min(amount + 5, units_full) * width / units_full; diff --git a/src/table/build_industry.h b/src/table/build_industry.h index b86484e28d..0fb3e00f91 100644 --- a/src/table/build_industry.h +++ b/src/table/build_industry.h @@ -1134,7 +1134,7 @@ enum IndustryTypes : uint8_t { {r1, r2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, m, \ {INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO}, \ {{im1, 0}, {im2, 0}, {im3, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, \ - pr, clim, bev, col, in, intx, s1, s2, s3, STR_UNDEFINED, {ai1, ai2, ai3, ai4}, {ag1, ag2, ag3, ag4}, \ + pr, clim, bev, PixelColour{col}, in, intx, s1, s2, s3, STR_UNDEFINED, {ai1, ai2, ai3, ai4}, {ag1, ag2, ag3, ag4}, \ IndustryCallbackMasks{}, true, SubstituteGRFFileProps(IT_INVALID), snd, {}, \ {{p1, p2}}, {{a1, a2, a3}}} /* Format: diff --git a/src/table/cargo_const.h b/src/table/cargo_const.h index 13880539a6..34013f64d3 100644 --- a/src/table/cargo_const.h +++ b/src/table/cargo_const.h @@ -49,7 +49,7 @@ * @param classes Classes of this cargo type. @see CargoClass */ #define MK(bt, label, colour, weight, mult, ip, td1, td2, freight, tae, str_plural, str_singular, str_volume, classes) \ - {label, bt, colour, colour, weight, mult, classes, ip, {td1, td2}, freight, tae, INVALID_TPE, TOWN_PRODUCTION_DIVISOR, CargoCallbackMasks{}, \ + {label, bt, PixelColour{colour}, PixelColour{colour}, weight, mult, classes, ip, {td1, td2}, freight, tae, INVALID_TPE, TOWN_PRODUCTION_DIVISOR, CargoCallbackMasks{}, \ MK_STR_CARGO_PLURAL(str_plural), MK_STR_CARGO_SINGULAR(str_singular), str_volume, MK_STR_QUANTITY(str_plural), MK_STR_ABBREV(str_plural), \ MK_SPRITE(str_plural), nullptr, nullptr, 0} diff --git a/src/table/railtypes.h b/src/table/railtypes.h index 3f687545bb..7ea62899a4 100644 --- a/src/table/railtypes.h +++ b/src/table/railtypes.h @@ -98,7 +98,7 @@ static const RailTypeInfo _original_railtypes[] = { RailTypeLabelList(), /* map colour */ - 0x0A, + PC_GREY, /* introduction date */ CalendarTime::INVALID_DATE, @@ -200,7 +200,7 @@ static const RailTypeInfo _original_railtypes[] = { RailTypeLabelList(), /* map colour */ - 0x0A, + PC_GREY, /* introduction date */ CalendarTime::INVALID_DATE, @@ -298,7 +298,7 @@ static const RailTypeInfo _original_railtypes[] = { RailTypeLabelList(), /* map colour */ - 0x0A, + PC_GREY, /* introduction date */ CalendarTime::INVALID_DATE, @@ -396,7 +396,7 @@ static const RailTypeInfo _original_railtypes[] = { RailTypeLabelList(), /* map colour */ - 0x0A, + PC_GREY, /* introduction date */ CalendarTime::INVALID_DATE, diff --git a/src/table/roadtypes.h b/src/table/roadtypes.h index f77c34dc74..eba40d3ad0 100644 --- a/src/table/roadtypes.h +++ b/src/table/roadtypes.h @@ -81,7 +81,7 @@ static const RoadTypeInfo _original_roadtypes[] = { RoadTypeLabelList(), /* map colour */ - 0x01, + PC_BLACK, /* introduction date */ CalendarTime::MIN_DATE, @@ -162,7 +162,7 @@ static const RoadTypeInfo _original_roadtypes[] = { RoadTypeLabelList(), /* map colour */ - 0x01, + PC_BLACK, /* introduction date */ CalendarTime::INVALID_DATE, diff --git a/src/table/string_colours.h b/src/table/string_colours.h index cc6347d56b..7d18459dbc 100644 --- a/src/table/string_colours.h +++ b/src/table/string_colours.h @@ -8,22 +8,22 @@ /** @file string_colours.h The colour translation of GRF's strings. */ /** Colour mapping for #TextColour. */ -static const uint8_t _string_colourmap[17] = { - 150, // TC_BLUE - 12, // TC_SILVER - 189, // TC_GOLD - 184, // TC_RED - 174, // TC_PURPLE - 30, // TC_LIGHT_BROWN - 195, // TC_ORANGE - 209, // TC_GREEN - 68, // TC_YELLOW - 95, // TC_DARK_GREEN - 79, // TC_CREAM - 116, // TC_BROWN - 15, // TC_WHITE - 152, // TC_LIGHT_BLUE - 6, // TC_GREY - 133, // TC_DARK_BLUE - 1, // TC_BLACK +static constexpr PixelColour _string_colourmap[17] = { + PixelColour{150}, // TC_BLUE + PixelColour{ 12}, // TC_SILVER + PixelColour{189}, // TC_GOLD + PixelColour{184}, // TC_RED + PixelColour{174}, // TC_PURPLE + PixelColour{ 30}, // TC_LIGHT_BROWN + PixelColour{195}, // TC_ORANGE + PixelColour{209}, // TC_GREEN + PixelColour{ 68}, // TC_YELLOW + PixelColour{ 95}, // TC_DARK_GREEN + PixelColour{ 79}, // TC_CREAM + PixelColour{116}, // TC_BROWN + PixelColour{ 15}, // TC_WHITE + PixelColour{152}, // TC_LIGHT_BLUE + PixelColour{ 6}, // TC_GREY + PixelColour{133}, // TC_DARK_BLUE + PixelColour{ 1}, // TC_BLACK }; diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 6727ed5796..344911ac76 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -697,7 +697,7 @@ static void DrawVehicleRefitWindow(const RefitOptions &refits, const RefitOption bool rtl = _current_text_dir == TD_RTL; uint iconwidth = std::max(GetSpriteSize(SPR_CIRCLE_FOLDED).width, GetSpriteSize(SPR_CIRCLE_UNFOLDED).width); uint iconheight = GetSpriteSize(SPR_CIRCLE_FOLDED).height; - int linecolour = GetColourGradient(COLOUR_ORANGE, SHADE_NORMAL); + PixelColour linecolour = GetColourGradient(COLOUR_ORANGE, SHADE_NORMAL); int iconleft = rtl ? ir.right - iconwidth : ir.left; int iconcenter = rtl ? ir.right - iconwidth / 2 : ir.left + iconwidth / 2; diff --git a/src/viewport.cpp b/src/viewport.cpp index 4699990cce..b2f61909b2 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -1732,13 +1732,13 @@ static void ViewportDrawDirtyBlocks() int right = UnScaleByZoom(dpi->width, dpi->zoom); int bottom = UnScaleByZoom(dpi->height, dpi->zoom); - int colour = _string_colourmap[_dirty_block_colour & 0xF]; + PixelColour colour = _string_colourmap[_dirty_block_colour & 0xF]; dst = dpi->dst_ptr; uint8_t bo = UnScaleByZoom(dpi->left + dpi->top, dpi->zoom) & 1; do { - for (int i = (bo ^= 1); i < right; i += 2) blitter->SetPixel(dst, i, 0, (uint8_t)colour); + for (int i = (bo ^= 1); i < right; i += 2) blitter->SetPixel(dst, i, 0, colour); dst = blitter->MoveTo(dst, 0, 1); } while (--bottom > 0); } @@ -1761,7 +1761,7 @@ static void ViewportDrawStrings(ZoomLevel zoom, const StringSpriteToDrawVector * } if (ss.flags.Test(ViewportStringFlag::TextColour)) { - if (ss.colour != INVALID_COLOUR) colour = static_cast(GetColourGradient(ss.colour, SHADE_LIGHTER) | TC_IS_PALETTE_COLOUR); + if (ss.colour != INVALID_COLOUR) colour = GetColourGradient(ss.colour, SHADE_LIGHTER).ToTextColour(); } int left = x + WidgetDimensions::scaled.fullbevel.left; diff --git a/src/widget.cpp b/src/widget.cpp index e60a265b01..034c289ea4 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -302,11 +302,11 @@ void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, Fra } else { assert(colour < COLOUR_END); - const uint dark = GetColourGradient(colour, SHADE_DARK); - const uint medium_dark = GetColourGradient(colour, SHADE_LIGHT); - const uint medium_light = GetColourGradient(colour, SHADE_LIGHTER); - const uint light = GetColourGradient(colour, SHADE_LIGHTEST); - uint interior; + const PixelColour dark = GetColourGradient(colour, SHADE_DARK); + const PixelColour medium_dark = GetColourGradient(colour, SHADE_LIGHT); + const PixelColour medium_light = GetColourGradient(colour, SHADE_LIGHTER); + const PixelColour light = GetColourGradient(colour, SHADE_LIGHTEST); + PixelColour interior; Rect outer = {left, top, right, bottom}; // Outside rectangle Rect inner = outer.Shrink(WidgetDimensions::scaled.bevel); // Inside rectangle @@ -469,7 +469,7 @@ static inline void DrawMatrix(const Rect &r, Colours colour, bool clicked, uint3 row_height = r.Height() / num_rows; } - int col = GetColourGradient(colour, SHADE_LIGHTER); + PixelColour col = GetColourGradient(colour, SHADE_LIGHTER); int x = r.left; for (int ctr = num_columns; ctr > 1; ctr--) { @@ -515,8 +515,8 @@ static inline void DrawVerticalScrollbar(const Rect &r, Colours colour, bool up_ DrawImageButtons(r.WithHeight(height, false), NWID_VSCROLLBAR, colour, up_clicked, SPR_ARROW_UP, SA_CENTER); DrawImageButtons(r.WithHeight(height, true), NWID_VSCROLLBAR, colour, down_clicked, SPR_ARROW_DOWN, SA_CENTER); - int c1 = GetColourGradient(colour, SHADE_DARK); - int c2 = GetColourGradient(colour, SHADE_LIGHTEST); + PixelColour c1 = GetColourGradient(colour, SHADE_DARK); + PixelColour c2 = GetColourGradient(colour, SHADE_LIGHTEST); /* draw "shaded" background */ GfxFillRect(r.left, r.top + height, r.right, r.bottom - height, c2); @@ -554,8 +554,8 @@ static inline void DrawHorizontalScrollbar(const Rect &r, Colours colour, bool l DrawImageButtons(r.WithWidth(width, false), NWID_HSCROLLBAR, colour, left_clicked, SPR_ARROW_LEFT, SA_CENTER); DrawImageButtons(r.WithWidth(width, true), NWID_HSCROLLBAR, colour, right_clicked, SPR_ARROW_RIGHT, SA_CENTER); - int c1 = GetColourGradient(colour, SHADE_DARK); - int c2 = GetColourGradient(colour, SHADE_LIGHTEST); + PixelColour c1 = GetColourGradient(colour, SHADE_DARK); + PixelColour c2 = GetColourGradient(colour, SHADE_LIGHTEST); /* draw "shaded" background */ GfxFillRect(r.left + width, r.top, r.right - width, r.bottom, c2); @@ -593,8 +593,8 @@ static inline void DrawFrame(const Rect &r, Colours colour, TextColour text_colo if (!str.empty()) x2 = DrawString(r.left + WidgetDimensions::scaled.frametext.left, r.right - WidgetDimensions::scaled.frametext.right, r.top, str, text_colour, align, false, fs); - int c1 = GetColourGradient(colour, SHADE_DARK); - int c2 = GetColourGradient(colour, SHADE_LIGHTEST); + PixelColour c1 = GetColourGradient(colour, SHADE_DARK); + PixelColour c2 = GetColourGradient(colour, SHADE_LIGHTEST); /* If the frame has text, adjust the top bar to fit half-way through */ Rect inner = r.Shrink(ScaleGUITrad(1)); @@ -791,7 +791,7 @@ void Window::DrawWidgets() const Rect outer = widget->GetCurrentRect(); Rect inner = outer.Shrink(WidgetDimensions::scaled.bevel).Expand(1); - int colour = _string_colourmap[_window_highlight_colour ? widget->GetHighlightColour() : TC_WHITE]; + PixelColour colour = _string_colourmap[_window_highlight_colour ? widget->GetHighlightColour() : TC_WHITE]; GfxFillRect(outer.left, outer.top, inner.left, inner.bottom, colour); GfxFillRect(inner.left + 1, outer.top, inner.right - 1, inner.top, colour);