A structure that represents a color as RGBA components.
More...
|
constexpr | Color (const SDL_Color &color={}) |
| Wraps Color.
|
|
constexpr | Color (Uint8 r, Uint8 g, Uint8 b, Uint8 a=255) |
| Constructs from its fields.
|
|
constexpr auto | operator<=> (const Color &other) const |
| Default comparison operator.
|
|
constexpr auto | operator<=> (const SDL_Color &color) const |
| Compares with the underlying type.
|
|
constexpr Uint8 | GetR () const |
| Get the red component from the color.
|
|
constexpr Color & | SetR (Uint8 newR) |
| Set the red component from the color.
|
|
constexpr Uint8 | GetG () const |
| Get the green component from the color.
|
|
constexpr Color & | SetG (Uint8 newG) |
| Set the green component from the color.
|
|
constexpr Uint8 | GetB () const |
| Get the blue component from the color.
|
|
constexpr Color & | SetB (Uint8 newB) |
| Set the blue component from the color.
|
|
constexpr Uint8 | GetA () const |
| Get the alpha component from the color.
|
|
constexpr Color & | SetA (Uint8 newA) |
| Set the alpha component from the color.
|
|
Uint32 | Map (const PixelFormatDetails &format, PaletteRef palette) const |
| Map an RGBA quadruple to a pixel value for a given pixel format.
|
|
The bits of this structure can be directly reinterpreted as an integer-packed color which uses the PIXELFORMAT_RGBA32 format (PIXELFORMAT_ABGR8888 on little-endian systems and PIXELFORMAT_RGBA8888 on big-endian systems).
- Since
- This struct is available since SDL 3.2.0.
- Category:
- Wrap extending struct
- See also
- FColor
◆ Color() [1/2]
constexpr SDL::Color::Color |
( |
const SDL_Color & |
color = {} | ) |
|
|
inlineconstexpr |
- Parameters
-
color | the value to be wrapped |
◆ Color() [2/2]
constexpr SDL::Color::Color |
( |
Uint8 |
r, |
|
|
Uint8 |
g, |
|
|
Uint8 |
b, |
|
|
Uint8 |
a = 255 |
|
) |
| |
|
inlineconstexpr |
- Parameters
-
r | the value for channel r. |
g | the value for channel g. |
b | the value for channel b. |
a | the value for channel a. |
◆ Get()
This function uses the entire 8-bit [0..255] range when converting color components from pixel formats with less than 8-bits per RGB component (e.g., a completely white pixel in 16-bit RGB565 format would return [0xff, 0xff, 0xff] not [0xf8, 0xfc, 0xf8]).
If the surface has no alpha component, the alpha will be returned as 0xff (100% opaque).
- Parameters
-
pixel | a pixel value. |
format | a pointer to SDL_PixelFormatDetails describing the pixel format. |
palette | an optional palette for indexed formats, may be NULL. |
- Returns
- a color value.
- Thread safety:
- It is safe to call this function from any thread, as long as the palette is not modified.
- Since
- This function is available since SDL 3.2.0.
- See also
- PixelFormat.GetDetails()
-
GetRGBA()
-
Map()
◆ GetA()
constexpr Uint8 SDL::Color::GetA |
( |
| ) |
const |
|
inlineconstexpr |
- Returns
- The alpha component from the color.
◆ GetB()
constexpr Uint8 SDL::Color::GetB |
( |
| ) |
const |
|
inlineconstexpr |
- Returns
- The blue component from the color.
◆ GetG()
constexpr Uint8 SDL::Color::GetG |
( |
| ) |
const |
|
inlineconstexpr |
- Returns
- The green component from the color.
◆ GetR()
constexpr Uint8 SDL::Color::GetR |
( |
| ) |
const |
|
inlineconstexpr |
- Returns
- The red component from the color.
◆ Map()
This function maps the RGBA color value to the specified pixel format and returns the pixel value best approximating the given RGBA color value for the given pixel format.
If the specified pixel format has no alpha component the alpha value will be ignored (as it will be in formats with a palette).
If the format has a palette (8-bit) the index of the closest matching color in the palette will be returned.
If the pixel format bpp (color depth) is less than 32-bpp then the unused upper bits of the return value can safely be ignored (e.g., with a 16-bpp format the return value can be assigned to a Uint16, and similarly a Uint8 for an 8-bpp format).
- Parameters
-
format | a pointer to PixelFormatDetails describing the pixel format. |
palette | an optional palette for indexed formats, may be NULL. |
- Returns
- a pixel value.
- Thread safety:
- It is safe to call this function from any thread, as long as the palette is not modified.
◆ SetA()
constexpr Color & SDL::Color::SetA |
( |
Uint8 |
newA | ) |
|
|
inlineconstexpr |
- Parameters
-
newA | New alpha component value. |
- Returns
- Reference to self.
◆ SetB()
constexpr Color & SDL::Color::SetB |
( |
Uint8 |
newB | ) |
|
|
inlineconstexpr |
- Parameters
-
newB | New blue component value. |
- Returns
- Reference to self.
◆ SetG()
constexpr Color & SDL::Color::SetG |
( |
Uint8 |
newG | ) |
|
|
inlineconstexpr |
- Parameters
-
newG | New green component value. |
- Returns
- Reference to self.
◆ SetR()
constexpr Color & SDL::Color::SetR |
( |
Uint8 |
newR | ) |
|
|
inlineconstexpr |
- Parameters
-
newR | New red component value. |
- Returns
- Reference to self.
The documentation for this struct was generated from the following file: