cpp-sdl2
C++ header-only SDL2 wrapper
sdl::Color Class Reference

C++ wrapping around the SDL_Color structure. More...

#include <color.hpp>

+ Inheritance diagram for sdl::Color:

Public Member Functions

constexpr Color ()
 Construct an sdl::Color object. Color will be black by default. More...
 
constexpr Color (Uint8 r, Uint8 g, Uint8 b, Uint8 a=255)
 Construct an sdl Color::object with the given 8 bit color values. More...
 
constexpr Color (Color const &)=default
 Default copy ctor. More...
 
constexpr Color (Color &&)=default
 Default move ctor. More...
 
 Color (Uint32 raw, SDL_PixelFormat const &format)
 Converting constructor that will initialize the color with a given 32 bit value, according to the provided PixelFormat. More...
 
 Color (Uint32 raw, Uint32 format)
 Converting constructor that will initialize the color with a given 32 bit value, according to the provided PixelFormat. More...
 
Coloroperator= (Color const &)=default
 Default copy assing operator. More...
 
Coloroperator= (Color &&)=default
 Default move assing operator. More...
 
Uint32 as_uint (SDL_PixelFormat const &format) const
 Return the color of the current object as a 32bit number (4 bytes) More...
 
Uint32 as_uint (Uint32 format) const
 Return the color of the current object as a 32bit number (4 bytes) More...
 
bool operator== (Color const &c) const
 Return true if both colors are identical. More...
 

Static Public Member Functions

static constexpr Color White ()
 
static constexpr Color Black ()
 
static constexpr Color Red ()
 
static constexpr Color Green ()
 
static constexpr Color Blue ()
 
static constexpr Color Transparent ()
 

Friends

std::ostream & operator<< (std::ostream &stream, Color const &c)
 Output stream overload that will print the value of the current color as a 4D vector of 8bit numbers. More...
 

Detailed Description

C++ wrapping around the SDL_Color structure.

Definition at line 10 of file color.hpp.

Constructor & Destructor Documentation

◆ Color() [1/6]

constexpr sdl::Color::Color ( )
inline

Construct an sdl::Color object. Color will be black by default.

Definition at line 14 of file color.hpp.

Referenced by Color().

◆ Color() [2/6]

constexpr sdl::Color::Color ( Uint8  r,
Uint8  g,
Uint8  b,
Uint8  a = 255 
)
inline

Construct an sdl Color::object with the given 8 bit color values.

Alpha channel to fully opaque by default

Parameters
r8 bit quantity of red
g8 bit quantity of green
b8 bit quantity of blue
a8 bit opacity level. Default to 255 (0xff)

Definition at line 21 of file color.hpp.

References sdl::simd::a, and Color().

◆ Color() [3/6]

constexpr sdl::Color::Color ( Color const &  )
default

Default copy ctor.

◆ Color() [4/6]

constexpr sdl::Color::Color ( Color &&  )
default

Default move ctor.

◆ Color() [5/6]

sdl::Color::Color ( Uint32  raw,
SDL_PixelFormat const &  format 
)
inline

Converting constructor that will initialize the color with a given 32 bit value, according to the provided PixelFormat.

Definition at line 33 of file color.hpp.

References sdl::simd::a.

◆ Color() [6/6]

sdl::Color::Color ( Uint32  raw,
Uint32  format 
)
inline

Converting constructor that will initialize the color with a given 32 bit value, according to the provided PixelFormat.

Definition at line 39 of file color.hpp.

References sdl::simd::a, and operator=().

Member Function Documentation

◆ as_uint() [1/2]

Uint32 sdl::Color::as_uint ( SDL_PixelFormat const &  format) const
inline

Return the color of the current object as a 32bit number (4 bytes)

Parameters
formatpixel format to use

Definition at line 55 of file color.hpp.

References sdl::simd::a.

Referenced by as_uint(), sdl::Pixel::set_color(), and sdl::Surface::set_colorkey().

◆ as_uint() [2/2]

Uint32 sdl::Color::as_uint ( Uint32  format) const
inline

Return the color of the current object as a 32bit number (4 bytes)

Parameters
formatpixel format to use

Definition at line 68 of file color.hpp.

References as_uint().

◆ Black()

static constexpr Color sdl::Color::Black ( )
inlinestatic

Definition at line 91 of file color.hpp.

◆ Blue()

static constexpr Color sdl::Color::Blue ( )
inlinestatic

Definition at line 94 of file color.hpp.

◆ Green()

static constexpr Color sdl::Color::Green ( )
inlinestatic

Definition at line 93 of file color.hpp.

◆ operator=() [1/2]

Color& sdl::Color::operator= ( Color const &  )
default

Default copy assing operator.

Referenced by Color().

◆ operator=() [2/2]

Color& sdl::Color::operator= ( Color &&  )
default

Default move assing operator.

◆ operator==()

bool sdl::Color::operator== ( Color const &  c) const
inline

Return true if both colors are identical.

Definition at line 78 of file color.hpp.

References sdl::simd::a.

◆ Red()

static constexpr Color sdl::Color::Red ( )
inlinestatic

Definition at line 92 of file color.hpp.

◆ Transparent()

static constexpr Color sdl::Color::Transparent ( )
inlinestatic

Definition at line 95 of file color.hpp.

◆ White()

static constexpr Color sdl::Color::White ( )
inlinestatic

Definition at line 90 of file color.hpp.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  stream,
Color const &  c 
)
friend

Output stream overload that will print the value of the current color as a 4D vector of 8bit numbers.

Definition at line 84 of file color.hpp.


The documentation for this class was generated from the following file: