OpenTTD Source 20241224-master-gee860a5c8e
|
Functions related to palettes. More...
#include "core/enum_type.hpp"
#include "gfx_type.h"
#include "strings_type.h"
#include "string_type.h"
Go to the source code of this file.
Macros | |
#define | GREY_SCALE(level) (level) |
Return the colour for a particular greyscale level. | |
Functions | |
bool | CopyPalette (Palette &local_palette, bool force_copy=false) |
Copy the current palette if the palette was updated. | |
void | GfxInitPalettes () |
uint8_t | GetNearestColourIndex (uint8_t r, uint8_t g, uint8_t b) |
Get nearest colour palette index from an RGB colour. | |
uint8_t | GetNearestColourIndex (const Colour colour) |
bool | IsValidColours (Colours colours) |
Checks if a Colours value is valid. | |
TextColour | GetContrastColour (uint8_t background, uint8_t threshold=128) |
Determine a contrasty text colour for a coloured background. | |
uint8_t | GetColourGradient (Colours colour, ColourShade shade) |
Get colour gradient palette index. | |
void | SetColourGradient (Colours colour, ColourShade shade, uint8_t palette_colour) |
Set colour gradient palette index. | |
Variables | |
Palette | _cur_palette |
Current palette. | |
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 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 const uint8_t | PC_VERY_DARK_BROWN = 0x56 |
Almost-black brown palette colour. | |
static const uint8_t | 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 const uint8_t | 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 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. | |
Functions related to palettes.
Definition in file palette_func.h.
#define GREY_SCALE | ( | level | ) | (level) |
Return the colour for a particular greyscale level.
level | Intensity, 0 = black, 15 = white |
Definition at line 65 of file palette_func.h.
enum ColourShade : uint8_t |
Definition at line 43 of file palette_func.h.
bool CopyPalette | ( | Palette & | local_palette, |
bool | force_copy | ||
) |
Copy the current palette if the palette was updated.
Used by video-driver to get a current up-to-date version of the palette, to avoid two threads accessing the same piece of memory (with a good chance one is already updating the palette while the other is drawing based on it).
local_palette | The location to copy the palette to. |
force_copy | Whether to ignore if there is an update for the palette. |
Definition at line 152 of file palette.cpp.
References _cur_palette, _palette_mutex, Palette::count_dirty, Palette::first_dirty, and lock.
Referenced by VideoDriver_SDL_OpenGL::AllocateBackingStore(), VideoDriver_SDL_Base::CheckPaletteAnim(), VideoDriver_SDL::CheckPaletteAnim(), VideoDriver_Win32Base::CheckPaletteAnim(), and VideoDriver_SDL_Base::ClientSizeChanged().
uint8_t GetColourGradient | ( | Colours | colour, |
ColourShade | shade | ||
) |
Get colour gradient palette index.
colour | Colour. |
shade | Shade level from 1 to 7. |
Definition at line 314 of file palette.cpp.
Referenced by BuildOwnerLegend(), NWidgetMatrix::Draw(), NWidgetBackground::Draw(), NWidgetScrollbar::Draw(), NWidgetLeaf::Draw(), BaseSettingEntry::Draw(), DrawArrowButtons(), NetworkClientListWindow::DrawButtons(), DrawCaption(), LinkGraphOverlay::DrawContent(), DrawDropDownButton(), DrawEngineList(), DrawFrame(), DrawFrameRect(), VehicleGroupWindow::DrawGroupInfo(), DrawHorizontalScrollbar(), DrawMatrix(), DrawResizeBox(), DrawSliderWidget(), LinkGraphOverlay::DrawStationDots(), DrawTrainDetails(), DrawVehicleRefitWindow(), DrawVerticalScrollbar(), DepotWindow::DrawWidget(), PerformanceRatingDetailWindow::DrawWidget(), VehicleGroupWindow::DrawWidget(), OrdersWindow::DrawWidget(), PickerWindow::DrawWidget(), GetDrawStringCompanyColour(), HighlightDragPosition(), IsValidConsoleColour(), and BaseGraphWindow::UpdateStatistics().
TextColour GetContrastColour | ( | uint8_t | background, |
uint8_t | threshold | ||
) |
Determine a contrasty text colour for a coloured background.
background | Background colour. |
threshold | Background colour brightness threshold below which the background is considered dark and TC_WHITE is returned, range: 0 - 255, default 128. |
Definition at line 287 of file palette.cpp.
References _cur_palette, Colour::b, and Palette::palette.
Referenced by LinkGraphLegendWindow::DrawWidget(), and StationsWndShowStationRating().
|
inline |
Definition at line 25 of file palette_func.h.
uint8_t GetNearestColourIndex | ( | uint8_t | r, |
uint8_t | g, | ||
uint8_t | b | ||
) |
Get nearest colour palette index from an RGB colour.
A search is performed if this colour is not already in the lookup table.
r | Red component. |
g | Green component. |
b | Blue component. |
Definition at line 127 of file palette.cpp.
References FindNearestColourIndex(), and PALETTE_BITS.
Referenced by Blitter_32bppSimple::Draw(), Blitter_32bppOptimized::Draw(), and Blitter_40bppAnim::Draw().
void GfxInitPalettes | ( | ) |
Definition at line 136 of file palette.cpp.
|
inline |
Checks if a Colours value is valid.
colours | The value to check |
Definition at line 36 of file palette_func.h.
Referenced by StoryPageButtonData::GetColour().
void SetColourGradient | ( | Colours | colour, |
ColourShade | shade, | ||
uint8_t | palette_index | ||
) |
Set colour gradient palette index.
Definition at line 325 of file palette.cpp.
Referenced by HandleBootstrap(), and SetupColoursAndInitialWindow().
|
extern |
Current palette.
Definition at line 24 of file palette.cpp.
Referenced by CopyPalette(), and GetContrastColour().
|
static |
Brown palette colour for bare land.
Definition at line 92 of file palette_func.h.
Referenced by GetSmallMapVegetationPixels().
|
static |
Black palette colour.
Definition at line 67 of file palette_func.h.
Referenced by NWidgetLeaf::Draw(), CargoesField::Draw(), SmallMapWindow::DrawSmallMap(), BuildAirportWindow::DrawWidget(), CompanyFinancesWindow::DrawWidget(), DropdownWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), FrametimeGraphWindow::DrawWidget(), PaymentRatesGraphWindow::DrawWidget(), IndustryProductionGraphWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), TooltipsWindow::DrawWidget(), MusicTrackSelectionWindow::DrawWidget(), MusicWindow::DrawWidget(), NewGRFWindow::DrawWidget(), SavePresetWindow::DrawWidget(), SmallMapWindow::DrawWidget(), ScriptDebugWindow::DrawWidgetLog(), DrawYearCategory(), DrawYearColumn(), GetSmallMapOwnerPixels(), and IConsoleWindow::OnPaint().
|
static |
Dark blue palette colour.
Definition at line 87 of file palette_func.h.
Referenced by NetworkContentListWindow::DrawDetails(), SaveLoadWindow::DrawWidget(), NewGRFWindow::DrawWidget(), and SavePresetWindow::DrawWidget().
|
static |
Dark grey palette colour.
Definition at line 68 of file palette_func.h.
Referenced by FrametimeGraphWindow::DrawWidget(), NewGRFWindow::DrawWidget(), and GetSmallMapOwnerPixels().
|
static |
Dark red palette colour.
Definition at line 73 of file palette_func.h.
Referenced by NWidgetToolbarContainer::Draw(), FrametimeGraphWindow::DrawWidget(), GetSmallMapOwnerPixels(), GetSmallMapVegetationPixels(), and IConsoleWindow::OnPaint().
|
static |
Light brown palette colour for fields.
Definition at line 94 of file palette_func.h.
|
static |
Dark green palette colour for grass land.
Definition at line 91 of file palette_func.h.
Referenced by GetSmallMapVegetationPixels().
|
static |
Green palette colour.
Definition at line 84 of file palette_func.h.
Referenced by GetSmallMapVegetationPixels(), and StationsWndShowStationRating().
|
static |
Grey palette colour.
Definition at line 69 of file palette_func.h.
Referenced by NetworkContentListWindow::DrawMatrix(), NetworkGameWindow::DrawServerLine(), NewGRFWindow::DrawWidget(), and NewsWindow::DrawWidget().
|
static |
Light blue palette colour.
Definition at line 88 of file palette_func.h.
Referenced by SpriteAlignerWindow::DrawWidget(), GetSmallMapRoutesPixels(), and GetSmallMapVegetationPixels().
|
static |
Light yellow palette colour.
Definition at line 81 of file palette_func.h.
Referenced by TooltipsWindow::DrawWidget().
|
static |
Orange palette colour.
Definition at line 78 of file palette_func.h.
Referenced by GetSmallMapRoutesPixels(), and GetSmallMapVegetationPixels().
|
static |
Pale green palette colour for rainforest.
Definition at line 93 of file palette_func.h.
Referenced by GetSmallMapVegetationPixels().
|
static |
Red palette colour.
Definition at line 74 of file palette_func.h.
Referenced by GetSmallMapRoutesPixels(), and StationsWndShowStationRating().
|
static |
Dark green palette colour for rough land.
Definition at line 90 of file palette_func.h.
|
static |
Green palette colour for trees.
Definition at line 95 of file palette_func.h.
Referenced by GetSmallMapVegetationPixels().
|
static |
Almost-black blue palette colour.
Definition at line 86 of file palette_func.h.
Referenced by SaveLoadWindow::DrawWidget().
|
static |
Almost-black brown palette colour.
Definition at line 76 of file palette_func.h.
Referenced by GetSmallMapRoutesPixels().
|
static |
Almost-black red palette colour.
Definition at line 72 of file palette_func.h.
Referenced by NWidgetToolbarContainer::Draw().
|
static |
Almost-white yellow palette colour.
Definition at line 82 of file palette_func.h.
Referenced by SmallMapWindow::DrawHorizMapIndicator(), and SmallMapWindow::DrawVertMapIndicator().
|
static |
Dark blue palette colour for water.
Definition at line 96 of file palette_func.h.
Referenced by GetSmallMapOwnerPixels().
|
static |
White palette colour.
Definition at line 70 of file palette_func.h.
Referenced by NWidgetSpacer::Draw(), DrawBox(), SmallMapWindow::DrawVehicles(), CompanyInfrastructureWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), SmallMapWindow::DrawWidget(), and SmallMapWindow::GetTileColours().
|
static |
Yellow palette colour.
Definition at line 80 of file palette_func.h.
Referenced by GetSmallMapRoutesPixels().