OpenTTD Source  14.0-beta3
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 "gfx_type.h"
14 #include "strings_type.h"
15 #include "string_type.h"
16 
17 extern Palette _cur_palette;
18 
19 bool CopyPalette(Palette &local_palette, bool force_copy = false);
20 void GfxInitPalettes();
21 
22 uint8_t GetNearestColourIndex(uint8_t r, uint8_t g, uint8_t b);
23 
24 inline uint8_t GetNearestColourIndex(const Colour colour)
25 {
26  return GetNearestColourIndex(colour.r, colour.g, colour.b);
27 }
28 
35 inline bool IsValidColours(Colours colours)
36 {
37  return colours < COLOUR_END;
38 }
39 
40 TextColour GetContrastColour(uint8_t background, uint8_t threshold = 128);
41 
46 extern byte _colour_gradient[COLOUR_END][8];
47 
53 #define GREY_SCALE(level) (level)
54 
55 static const uint8_t PC_BLACK = GREY_SCALE(1);
56 static const uint8_t PC_DARK_GREY = GREY_SCALE(6);
57 static const uint8_t PC_GREY = GREY_SCALE(10);
58 static const uint8_t PC_WHITE = GREY_SCALE(15);
59 
60 static const uint8_t PC_VERY_DARK_RED = 0xB2;
61 static const uint8_t PC_DARK_RED = 0xB4;
62 static const uint8_t PC_RED = 0xB8;
63 
64 static const uint8_t PC_VERY_DARK_BROWN = 0x56;
65 
66 static const uint8_t PC_ORANGE = 0xC2;
67 
68 static const uint8_t PC_YELLOW = 0xBF;
69 static const uint8_t PC_LIGHT_YELLOW = 0x44;
70 static const uint8_t PC_VERY_LIGHT_YELLOW = 0x45;
71 
72 static const uint8_t PC_GREEN = 0xD0;
73 
74 static const uint8_t PC_VERY_DARK_BLUE = 0x9A;
75 static const uint8_t PC_DARK_BLUE = 0x9D;
76 static const uint8_t PC_LIGHT_BLUE = 0x98;
77 
78 static const uint8_t PC_ROUGH_LAND = 0x52;
79 static const uint8_t PC_GRASS_LAND = 0x54;
80 static const uint8_t PC_BARE_LAND = 0x37;
81 static const uint8_t PC_RAINFOREST = 0x5C;
82 static const uint8_t PC_FIELDS = 0x25;
83 static const uint8_t PC_TREES = 0x57;
84 static const uint8_t PC_WATER = 0xC9;
85 
86 #endif /* PALETTE_FUNC_H */
PC_DARK_BLUE
static const uint8_t PC_DARK_BLUE
Dark blue palette colour.
Definition: palette_func.h:75
PC_VERY_DARK_BROWN
static const uint8_t PC_VERY_DARK_BROWN
Almost-black brown palette colour.
Definition: palette_func.h:64
GetNearestColourIndex
uint8_t GetNearestColourIndex(uint8_t r, uint8_t g, uint8_t b)
Get nearest colour palette index from an RGB colour.
Definition: palette.cpp:129
PC_RAINFOREST
static const uint8_t PC_RAINFOREST
Pale green palette colour for rainforest.
Definition: palette_func.h:81
PC_WHITE
static const uint8_t PC_WHITE
White palette colour.
Definition: palette_func.h:58
PC_VERY_DARK_BLUE
static const uint8_t PC_VERY_DARK_BLUE
Almost-black blue palette colour.
Definition: palette_func.h:74
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
IsValidColours
bool IsValidColours(Colours colours)
Checks if a Colours value is valid.
Definition: palette_func.h:35
strings_type.h
PC_FIELDS
static const uint8_t PC_FIELDS
Light brown palette colour for fields.
Definition: palette_func.h:82
PC_GREEN
static const uint8_t PC_GREEN
Green palette colour.
Definition: palette_func.h:72
PC_VERY_DARK_RED
static const uint8_t PC_VERY_DARK_RED
Almost-black red palette colour.
Definition: palette_func.h:60
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: palette.cpp:26
_cur_palette
Palette _cur_palette
Current palette.
Definition: palette.cpp:24
PC_GRASS_LAND
static const uint8_t PC_GRASS_LAND
Dark green palette colour for grass land.
Definition: palette_func.h:79
PC_VERY_LIGHT_YELLOW
static const uint8_t PC_VERY_LIGHT_YELLOW
Almost-white yellow palette colour.
Definition: palette_func.h:70
string_type.h
Colour
Structure to access the alpha, red, green, and blue channels from a 32 bit number.
Definition: gfx_type.h:159
PC_LIGHT_YELLOW
static const uint8_t PC_LIGHT_YELLOW
Light yellow palette colour.
Definition: palette_func.h:69
PC_YELLOW
static const uint8_t PC_YELLOW
Yellow palette colour.
Definition: palette_func.h:68
PC_DARK_RED
static const uint8_t PC_DARK_RED
Dark red palette colour.
Definition: palette_func.h:61
PC_TREES
static const uint8_t PC_TREES
Green palette colour for trees.
Definition: palette_func.h:83
PC_ORANGE
static const uint8_t PC_ORANGE
Orange palette colour.
Definition: palette_func.h:66
PC_GREY
static const uint8_t PC_GREY
Grey palette colour.
Definition: palette_func.h:57
PC_WATER
static const uint8_t PC_WATER
Dark blue palette colour for water.
Definition: palette_func.h:84
PC_BLACK
static const uint8_t PC_BLACK
Black palette colour.
Definition: palette_func.h:55
CopyPalette
bool CopyPalette(Palette &local_palette, bool force_copy=false)
Copy the current palette if the palette was updated.
Definition: palette.cpp:154
PC_ROUGH_LAND
static const uint8_t PC_ROUGH_LAND
Dark green palette colour for rough land.
Definition: palette_func.h:78
PC_RED
static const uint8_t PC_RED
Red palette colour.
Definition: palette_func.h:62
PC_DARK_GREY
static const uint8_t PC_DARK_GREY
Dark grey palette colour.
Definition: palette_func.h:56
gfx_type.h
Palette
Information about the currently used palette.
Definition: gfx_type.h:323
GREY_SCALE
#define GREY_SCALE(level)
Return the colour for a particular greyscale level.
Definition: palette_func.h:53
PC_LIGHT_BLUE
static const uint8_t PC_LIGHT_BLUE
Light blue palette colour.
Definition: palette_func.h:76
GetContrastColour
TextColour GetContrastColour(uint8_t background, uint8_t threshold=128)
Determine a contrasty text colour for a coloured background.
Definition: palette.cpp:289
PC_BARE_LAND
static const uint8_t PC_BARE_LAND
Brown palette colour for bare land.
Definition: palette_func.h:80