![]() |
Blamite Game Engine - Strings
00386.06.16.23.0646.blamite
A library containing general purpose utilities and classes for use in multiple projects.
|
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... | |
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... | |
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.
BlamColor::BlamColor | ( | ) |
Creates a new BlamColor.
_r | - The Red value of the color. |
_g | - The Green value of the color. |
_b | - The Blue value of the color. |
Creates a new BlamColor.
_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. |
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
.
other_color | - The color to check against. |
true
if all RBGA values are equal, otherwise returns false
. 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();
string | - The string to try to convert to a color. |
true
if the color was converted successfully, false
if the conversion failed. 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.
vector | - The BlamVector3 to parse. |
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.
vector | - The BlamVector4 to parse. |
float BlamColor::GetAlphaAsFloat | ( | ) |
Gets the color's red value as a float, between 0 and 1.
float BlamColor::GetBlueAsFloat | ( | ) |
Gets the color's red value as a float, between 0 and 1.
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).
float BlamColor::GetGreenAsFloat | ( | ) |
Gets the color's red value as a float, between 0 and 1.
float BlamColor::GetRedAsFloat | ( | ) |
Gets the color's red value as a float, between 0 and 1.
std::string BlamColor::ToString | ( | ) |
Converts the color value to a string.
r,g,b,a
format. 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}
- AlphaAdditionally, 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}
.
format | - The string containing any color placeholders to be replaced. |
std::string BlamColor::ToStringForCSS | ( | ) |
Converts the color to a string that can be used with CSS.
rgba(r,g,b,a)
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.
BlamVector3
. 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.
BlamVector4
. byte BlamColor::a = 255 |
The Alpha value of the color.
byte BlamColor::b = 255 |
The Blue value of the color.
byte BlamColor::g = 255 |
The Green value of the color.
byte BlamColor::r = 255 |
The Red value of the color.