mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-17 01:12:39 +01:00
Codechange: Add distinct type to hold pixel drawing colour. (#14457)
This is used for individual pixels as well as line drawing.
This commit is contained in:
@@ -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) {{}, 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() {{}, 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() {{}, 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({}, 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<uint8_t>(_heightmap_schemes[_settings_client.gui.smallmap_land_colour].height_colours[_legend_land_contours[i].height]);
|
||||
_legend_land_contours[i].colour = PixelColour{static_cast<uint8_t>(_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<uint8_t>(_heightmap_schemes[_settings_client.gui.smallmap_land_colour].default_colour);
|
||||
_legend_land_owners[1].colour = PixelColour{static_cast<uint8_t>(_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<StringParameter, 2> params{};
|
||||
switch (this->map_type) {
|
||||
|
||||
Reference in New Issue
Block a user