Elaztek Developer Hub
Blamite Game Engine - Strings  00326.06.27.21.0407.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...
 
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...
 

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

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ ToString() [1/2]

std::string BlamColor::ToString ( )

Converts the color value to a string.

Returns
The color information in r,g,b,a format.

◆ 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.

◆ 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)

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: