TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
TurtleBrains::Graphics::Color Class Reference

#include <tb_color.hpp>

Public Member Functions

constexpr Color (void) noexcept
 
constexpr Color (const tbCore::uint32 &colorARGB) noexcept
 
constexpr Color (const float clampedAlpha, const float clampedRed, const float clampedGreen, const float clampedBlue) noexcept
 
bool SetColor (const tbCore::DynamicStructure &colorData, bool triggerErrorOnFailure=true)
 
void SetColor (const tbCore::uint32 &colorARGB)
 
void SetColor (const float clampedAlpha, const float clampedRed, const float clampedGreen, const float clampedBlue)
 
void SetColor (const float clampedTween, const Color &startColor, const Color &finalColor)
 
tbCore::uint32 GetColorARGB (void) const
 
tbCore::uint32 GetColorABGR (void) const
 
tbCore::uint8 GetAlphaByte (void) const
 
tbCore::uint8 GetRedByte (void) const
 
tbCore::uint8 GetGreenByte (void) const
 
tbCore::uint8 GetBlueByte (void) const
 
float GetAlpha (void) const
 
void SetAlpha (const float alpha)
 
void SetAlpha (const int alpha)
 
float GetRed (void) const
 
void SetRed (const float red)
 
void SetRed (const int red)
 
float GetGreen (void) const
 
void SetGreen (const float green)
 
void SetGreen (const int green)
 
float GetBlue (void) const
 
void SetBlue (const float blue)
 
void SetBlue (const int blue)
 

Detailed Description

Stores a 24 bit color with 8 bit alpha and provides an interface to set the color through a variety of inputs either floating point channels or unsigned byte channels.

Constructor & Destructor Documentation

◆ Color() [1/3]

constexpr TurtleBrains::Graphics::Color::Color ( void  )
inlineconstexprnoexcept

Constructs a default Color object with all channels fully on including alpha, resulting in white.

◆ Color() [2/3]

constexpr TurtleBrains::Graphics::Color::Color ( const tbCore::uint32 colorARGB)
inlineexplicitconstexprnoexcept

Constructs a Color object from the 32bit color value with each channel as a byte in the order Alpha, Red, Green, Blue.

◆ Color() [3/3]

constexpr TurtleBrains::Graphics::Color::Color ( const float  clampedAlpha,
const float  clampedRed,
const float  clampedGreen,
const float  clampedBlue 
)
inlineexplicitconstexprnoexcept

Constructs a Color object based on floats for each of the channels. Each channel should be clamped in the range of 0.0f to 1.0f, although that will happen automatically when setting a color in this function.

Parameters
clampedAlphaThe amount of alpha to use for the color from transparent 0.0f to opaque 1.0f.
clampedRedThe amount of red to use for the color from none 0.0f to full 1.0f.
clampedGreenThe amount of green to use for the color from none 0.0f to full 1.0f.
clampedBlueThe amount of blue to use for the color from none 0.0f to full 1.0f.
Note
This does not normalize the color if any of the channels were out of bounds, it simply clamps them.

Member Function Documentation

◆ GetAlpha()

float TurtleBrains::Graphics::Color::GetAlpha ( void  ) const

Returns the clamped value of the alpha channel from transparent at 0.0f to 1.0f fully opaque.

◆ GetAlphaByte()

tbCore::uint8 TurtleBrains::Graphics::Color::GetAlphaByte ( void  ) const

Returns the byte value of the alpha channel from transparent at 0 to 255 fully opaque.

◆ GetBlue()

float TurtleBrains::Graphics::Color::GetBlue ( void  ) const

Returns the clamped value of the blue channel from 0.0f to 1.0f representing full blue.

◆ GetBlueByte()

tbCore::uint8 TurtleBrains::Graphics::Color::GetBlueByte ( void  ) const

Returns the byte value of the blue channel from 0 to 255 for full blue.

◆ GetColorABGR()

tbCore::uint32 TurtleBrains::Graphics::Color::GetColorABGR ( void  ) const

Computes and returns the 32bit color with each channel as a byte in the order Alpha, Blue, Green, Red.

◆ GetColorARGB()

tbCore::uint32 TurtleBrains::Graphics::Color::GetColorARGB ( void  ) const

Returns the 32bit color value with each channel as a byte in the order Alpha, Red, Green, Blue.

◆ GetGreen()

float TurtleBrains::Graphics::Color::GetGreen ( void  ) const

Returns the clamped value of the green channel from 0.0f to 1.0f representing full green.

◆ GetGreenByte()

tbCore::uint8 TurtleBrains::Graphics::Color::GetGreenByte ( void  ) const

Returns the byte value of the green channel from 0 to 255 for full green.

◆ GetRed()

float TurtleBrains::Graphics::Color::GetRed ( void  ) const

Returns the clamped value of the red channel from 0.0f to 1.0f representing full red.

◆ GetRedByte()

tbCore::uint8 TurtleBrains::Graphics::Color::GetRedByte ( void  ) const

Returns the byte value of the red channel from 0 to 255 for full red.

◆ SetColor() [1/4]

void TurtleBrains::Graphics::Color::SetColor ( const float  clampedAlpha,
const float  clampedRed,
const float  clampedGreen,
const float  clampedBlue 
)

Set the color value based on floats for each of the channels. Each channel should be clamped in the range of 0.0f to 1.0f, although that will happen automatically when setting a color in this function.

Parameters
clampedAlphaThe amount of alpha to use for the color from transparent 0.0f to opaque 1.0f.
clampedRedThe amount of red to use for the color from none 0.0f to full 1.0f.
clampedGreenThe amount of green to use for the color from none 0.0f to full 1.0f.
clampedBlueThe amount of blue to use for the color from none 0.0f to full 1.0f.
Note
This does not normalize the color if any of the channels were out of bounds, it simply clamps them.

◆ SetColor() [2/4]

void TurtleBrains::Graphics::Color::SetColor ( const float  clampedTween,
const Color startColor,
const Color finalColor 
)

Sets a color to be a color in between a startColor and finalColor by linearly interpolating between the two values.

Parameters
clampedTweenThe amount of interpolation to be applied from 0.0f to be startColor and 1.0f to be the finalColor. Any value in between will use linear interpolation, so 0.5f is the color halfway between the startColor and finalColor.
startColorA color the start from for the in-between linear interpolation.
finalColorA color at the end of the in-between linear interpolation.

◆ SetColor() [3/4]

bool TurtleBrains::Graphics::Color::SetColor ( const tbCore::DynamicStructure colorData,
bool  triggerErrorOnFailure = true 
)

Returns a Color object based on a dynamic structure of information. The information can be: A string represnting a color name in the palette, a string of hexadecimal ARGB values starting with 0xFFFFFFFF. More support to come in the future.

Parameters
colorDataThe dynamic structure object holding the data for the color.
triggerErrorOnFailureWhen set to false no error conditions will be triggered, only false returned, color will remain unchanged.

◆ SetColor() [4/4]

void TurtleBrains::Graphics::Color::SetColor ( const tbCore::uint32 colorARGB)

Sets the color value based on the 32bit value with each channel as a byte in the order Alpha, Red, Green, Blue.