OpenTTD Source 20241224-master-gf74b0cf984
palette_func.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10#ifndef PALETTE_FUNC_H
11#define PALETTE_FUNC_H
12
13#include "core/enum_type.hpp"
14#include "gfx_type.h"
15#include "strings_type.h"
16#include "string_type.h"
17
18extern Palette _cur_palette;
19
20bool CopyPalette(Palette &local_palette, bool force_copy = false);
21void GfxInitPalettes();
22
23uint8_t GetNearestColourIndex(uint8_t r, uint8_t g, uint8_t b);
24
25inline uint8_t GetNearestColourIndex(const Colour colour)
26{
27 return GetNearestColourIndex(colour.r, colour.g, colour.b);
28}
29
36inline bool IsValidColours(Colours colours)
37{
38 return colours < COLOUR_END;
39}
40
41TextColour GetContrastColour(uint8_t background, uint8_t threshold = 128);
42
43enum ColourShade : uint8_t {
44 SHADE_BEGIN = 0,
45 SHADE_DARKEST = SHADE_BEGIN,
46 SHADE_DARKER,
47 SHADE_DARK,
48 SHADE_NORMAL,
49 SHADE_LIGHT,
50 SHADE_LIGHTER,
51 SHADE_LIGHTEST,
52 SHADE_LIGHTEREST,
53 SHADE_END,
54};
56
57uint8_t GetColourGradient(Colours colour, ColourShade shade);
58void SetColourGradient(Colours colour, ColourShade shade, uint8_t palette_colour);
59
65#define GREY_SCALE(level) (level)
66
67static const uint8_t PC_BLACK = GREY_SCALE(1);
68static const uint8_t PC_DARK_GREY = GREY_SCALE(6);
69static const uint8_t PC_GREY = GREY_SCALE(10);
70static const uint8_t PC_WHITE = GREY_SCALE(15);
71
72static const uint8_t PC_VERY_DARK_RED = 0xB2;
73static const uint8_t PC_DARK_RED = 0xB4;
74static const uint8_t PC_RED = 0xB8;
75
76static const uint8_t PC_VERY_DARK_BROWN = 0x56;
77
78static const uint8_t PC_ORANGE = 0xC2;
79
80static const uint8_t PC_YELLOW = 0xBF;
81static const uint8_t PC_LIGHT_YELLOW = 0x44;
82static const uint8_t PC_VERY_LIGHT_YELLOW = 0x45;
83
84static const uint8_t PC_GREEN = 0xD0;
85
86static const uint8_t PC_VERY_DARK_BLUE = 0x9A;
87static const uint8_t PC_DARK_BLUE = 0x9D;
88static const uint8_t PC_LIGHT_BLUE = 0x98;
89
90static const uint8_t PC_ROUGH_LAND = 0x52;
91static const uint8_t PC_GRASS_LAND = 0x54;
92static const uint8_t PC_BARE_LAND = 0x37;
93static const uint8_t PC_RAINFOREST = 0x5C;
94static const uint8_t PC_FIELDS = 0x25;
95static const uint8_t PC_TREES = 0x57;
96static const uint8_t PC_WATER = 0xC9;
97
98#endif /* PALETTE_FUNC_H */
Type (helpers) for enums.
#define DECLARE_POSTFIX_INCREMENT(enum_type)
Some enums need to have allowed incrementing (i.e.
Definition enum_type.hpp:18
Types related to the graphics and/or input devices.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:260
static const uint8_t PC_VERY_DARK_RED
Almost-black red palette colour.
static const uint8_t PC_LIGHT_YELLOW
Light yellow palette colour.
static const uint8_t PC_TREES
Green palette colour for trees.
static const uint8_t PC_GREY
Grey palette colour.
static const uint8_t PC_GREEN
Green palette colour.
static const uint8_t PC_WHITE
White palette colour.
bool CopyPalette(Palette &local_palette, bool force_copy=false)
Copy the current palette if the palette was updated.
Definition palette.cpp:152
static const uint8_t PC_DARK_GREY
Dark grey palette colour.
static const uint8_t PC_WATER
Dark blue palette colour for water.
static const uint8_t PC_LIGHT_BLUE
Light blue palette colour.
uint8_t GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
Definition palette.cpp:314
static const uint8_t PC_FIELDS
Light brown palette colour for fields.
bool IsValidColours(Colours colours)
Checks if a Colours value is valid.
static const uint8_t PC_DARK_BLUE
Dark blue palette colour.
static const uint8_t PC_BLACK
Black palette colour.
static const uint8_t PC_DARK_RED
Dark red palette colour.
static const uint8_t PC_ROUGH_LAND
Dark green palette colour for rough land.
Palette _cur_palette
Current palette.
Definition palette.cpp:24
static const uint8_t PC_BARE_LAND
Brown palette colour for bare land.
static const uint8_t PC_ORANGE
Orange palette colour.
static const uint8_t PC_RED
Red palette colour.
static const uint8_t PC_VERY_DARK_BLUE
Almost-black blue palette colour.
TextColour GetContrastColour(uint8_t background, uint8_t threshold=128)
Determine a contrasty text colour for a coloured background.
Definition palette.cpp:287
static const uint8_t PC_VERY_DARK_BROWN
Almost-black brown palette colour.
uint8_t GetNearestColourIndex(uint8_t r, uint8_t g, uint8_t b)
Get nearest colour palette index from an RGB colour.
Definition palette.cpp:127
static const uint8_t PC_YELLOW
Yellow palette colour.
static const uint8_t PC_GRASS_LAND
Dark green palette colour for grass land.
void SetColourGradient(Colours colour, ColourShade shade, uint8_t palette_colour)
Set colour gradient palette index.
Definition palette.cpp:325
static const uint8_t PC_RAINFOREST
Pale green palette colour for rainforest.
#define GREY_SCALE(level)
Return the colour for a particular greyscale level.
static const uint8_t PC_VERY_LIGHT_YELLOW
Almost-white yellow palette colour.
Types for strings.
Types related to strings.
Information about the currently used palette.
Definition gfx_type.h:328
Structure to access the alpha, red, green, and blue channels from a 32 bit number.
Definition gfx_type.h:165
uint8_t b
colour channels in BE order
Definition gfx_type.h:171