Elaztek Developer Hub
Blamite Game Engine - Strings  00402.09.29.23.0627.blamite
A library containing general purpose utilities and classes for use in multiple projects.
BlamColor Class Reference

Class representing a color. More...

#include <BlamColor.h>

Public Member Functions

 BlamColor ()
 
 BlamColor (byte _r, byte _g, byte _b)
 Creates a new BlamColor. More...
 
 BlamColor (byte _r, byte _g, byte _b, byte _a)
 Creates a new BlamColor. More...
 
bool operator== (const BlamColor &other)
 
std::string ToString ()
 Converts the color value to a string. More...
 
float GetRedAsFloat ()
 Gets the color's red value as a float, between 0 and 1. More...
 
float GetGreenAsFloat ()
 Gets the color's red value as a float, between 0 and 1. More...
 
float GetBlueAsFloat ()
 Gets the color's red value as a float, between 0 and 1. More...
 
float GetAlphaAsFloat ()
 Gets the color's red value as a float, between 0 and 1. More...
 
int GetColorAsInt ()
 Gets the color's value as an integer. More...
 
std::string ToString (std::string format)
 Converts the color value to a string in the specified format. More...
 
std::string ToStringForCSS ()
 Converts the color to a string that can be used with CSS. More...
 
bool FromString (std::string string)
 Attempts to set color information from a string. More...
 
BlamVector4 ToVector4 ()
 Converts the color into a BlamVector4. More...
 
void FromVector4 (BlamVector4 vector)
 Parses color information from a BlamVector4. More...
 
bool Equals (BlamColor other_color)
 Checks if this color is equal to another color. More...
 
BlamVector3 ToVector3 ()
 Converts the color into a BlamVector3. More...
 
void FromVector3 (BlamVector3 vector)
 Parses color information from a BlamVector3. More...
 

Public Attributes

byte r = 255
 The Red value of the color. More...
 
byte g = 255
 The Green value of the color. More...
 
byte b = 255
 The Blue value of the color. More...
 
byte a = 255
 The Alpha value of the color. More...
 

Detailed Description

Class representing a color.

Used for a variety of purposes in the engine.

Color values range from 0 to 255. To convert to a float-based color, use #Blam::Colors::D2DColorFromBlamColor.

Constructor & Destructor Documentation

◆ BlamColor() [1/3]

BlamColor::BlamColor ( )

◆ BlamColor() [2/3]

BlamColor::BlamColor ( byte  _r,
byte  _g,
byte  _b 
)

Creates a new BlamColor.

Parameters
_r- The Red value of the color.
_g- The Green value of the color.
_b- The Blue value of the color.

◆ BlamColor() [3/3]

BlamColor::BlamColor ( byte  _r,
byte  _g,
byte  _b,
byte  _a 
)

Creates a new BlamColor.

Parameters
_r- The Red value of the color.
_g- The Green value of the color.
_b- The Blue value of the color.
_a- The Alpha value of the color.

Member Function Documentation

◆ Equals()

bool BlamColor::Equals ( BlamColor  other_color)

Checks if this color is equal to another color.

This will check the r, g, b, and a values of the color against other_color. If all colors match, then this will return true. Otherwise, this will return false.

Parameters
other_color- The color to check against.
Returns
true if all RBGA values are equal, otherwise returns false.
+ Here is the caller graph for this function:

◆ FromString()

bool BlamColor::FromString ( std::string  string)

Attempts to set color information from a string.

String should be in either r,g,b or r,g,b,a format - the same format as is returned when using BlamColor::ToString();

Parameters
string- The string to try to convert to a color.
Returns
true if the color was converted successfully, false if the conversion failed.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FromVector3()

void BlamColor::FromVector3 ( BlamVector3  vector)

Parses color information from a BlamVector3.

The XYZ values will be converted into RGB values, from 0 to 255. Any value which falls outside of this range will be clamped to the closest value - anything below 0 will become 0, and anything above 255 will be set to 255.

Parameters
vector- The BlamVector3 to parse.

◆ FromVector4()

void BlamColor::FromVector4 ( BlamVector4  vector)

Parses color information from a BlamVector4.

The XYZW values will be converted into RGBA values, from 0 to 255. Any value which falls outside of this range will be clamped to the closest value - anything below 0 will become 0, and anything above 255 will be set to 255.

Parameters
vector- The BlamVector4 to parse.

◆ GetAlphaAsFloat()

float BlamColor::GetAlphaAsFloat ( )

Gets the color's red value as a float, between 0 and 1.

Returns
The color's red value, converted to a float.
+ Here is the caller graph for this function:

◆ GetBlueAsFloat()

float BlamColor::GetBlueAsFloat ( )

Gets the color's red value as a float, between 0 and 1.

Returns
The color's red value, converted to a float.
+ Here is the caller graph for this function:

◆ GetColorAsInt()

int BlamColor::GetColorAsInt ( )

Gets the color's value as an integer.

This function will convert this color's value as an integer, in 0xAABBGGRR format. Each color is written in its hexadecimal format (ranging from 0x0 to 0xFF).

Returns
The color's value converted to an integer.

◆ GetGreenAsFloat()

float BlamColor::GetGreenAsFloat ( )

Gets the color's red value as a float, between 0 and 1.

Returns
The color's red value, converted to a float.
+ Here is the caller graph for this function:

◆ GetRedAsFloat()

float BlamColor::GetRedAsFloat ( )

Gets the color's red value as a float, between 0 and 1.

Returns
The color's red value, converted to a float.
+ Here is the caller graph for this function:

◆ operator==()

bool BlamColor::operator== ( const BlamColor other)
+ Here is the call graph for this function:

◆ ToString() [1/2]

std::string BlamColor::ToString ( )

Converts the color value to a string.

Returns
The color information in r,g,b,a format.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ToString() [2/2]

std::string BlamColor::ToString ( std::string  format)

Converts the color value to a string in the specified format.

The provided string can contain the following keys which will be replaced with the color values:

  • {r} - Red
  • {g} - Green
  • {b} - Blue
  • {a} - Alpha

Additionally, you can have a float representation of the value (instead of 0-255) by adding >f inside a color placeholder. Example: {r} of 255 would be 1.0 with {r>f}.

Parameters
format- The string containing any color placeholders to be replaced.
Returns
The string with the color placeholders replaced.
+ Here is the call graph for this function:

◆ ToStringForCSS()

std::string BlamColor::ToStringForCSS ( )

Converts the color to a string that can be used with CSS.

Returns
The color represented as a string, in the following format: rgba(r,g,b,a)
+ Here is the call graph for this function:

◆ ToVector3()

BlamVector3 BlamColor::ToVector3 ( )

Converts the color into a BlamVector3.

RGB will be converted into floats, and then set to the XYZ values of the vector. This can be used in cases (such as imgui) where we need to read full color information as a floating-point vector.

Returns
The color information, represented as a BlamVector3.
+ Here is the call graph for this function:

◆ ToVector4()

BlamVector4 BlamColor::ToVector4 ( )

Converts the color into a BlamVector4.

RGBA will be converted into floats, and then set to the XYZW values of the vector. This can be used in cases (such as imgui) where we need to read full color information as a floating-point vector.

Returns
The color information, represented as a BlamVector4.
+ Here is the call graph for this function:

Member Data Documentation

◆ a

byte BlamColor::a = 255

The Alpha value of the color.

◆ b

byte BlamColor::b = 255

The Blue value of the color.

◆ g

byte BlamColor::g = 255

The Green value of the color.

◆ r

byte BlamColor::r = 255

The Red value of the color.


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