|
FifeGUI 0.2.0
A C++ GUI library designed for games.
|
#include <color.hpp>
Public Member Functions | |
| Color | blendWith (Color const &other) const |
| Color ()=default | |
| Color (int hexColor) | |
| Color (int r, int g, int b, int a) | |
| Color (std::string const &colorString) | |
| Color (uint8_t r, uint8_t g, uint8_t b, uint8_t a=255) | |
| Color | darken (float percentage) const |
| Color | lighten (float percentage) const |
| bool | operator!= (Color const &color) const |
| Color | operator* (float value) const |
| Color & | operator*= (float value) |
| Color | operator+ (Color const &color) const |
| Color | operator+ (float value) const |
| Color & | operator+= (Color const &color) |
| Color | operator- (Color const &color) const |
| Color | operator- (float value) const |
| Color & | operator-= (Color const &color) |
| bool | operator== (Color const &color) const |
| Color | toGrayScale () const |
| std::string | toHexString () const |
| std::string | toRGBAString () const |
| std::string | toRGBString () const |
Public Attributes | |
| uint8_t | a {255} |
| uint8_t | b {0} |
| uint8_t | g {0} |
| uint8_t | r {0} |
Friends | |
| std::ostream & | operator<< (std::ostream &out, Color const &color) |
Represents a color with red, green, blue and alpha components. The color components are in the range 0-255.
The alpha component is used for transparency. A value of 0 means fully transparent, 255 is fully opaque. The alpha component is 255 by default.
The color can be constructed from a hexadecimal color code or an RGB color code. The hexadecimal color code must be 6 characters long and prefixed with a '#'. The RGB color code must be in the format "rgb(r,g,b)".
The color can be lightened or darkened by a percentage. The percentage should be in the range 0-1. A percentage of 0.1 will return a color that is 10% lighter. A percentage of -0.1 will return a color that is 10% darker.
The color can be converted to grayscale. The color can be blended with another color using alpha blending.
The color can be output as a hexadecimal color code or an RGB color code. The color can be compared with another color. The color can be added, subtracted, multiplied, and divided with another color object. The color can be added, subtracted, multiplied, and divided with a float value. The color can be output to a stream. The color can be converted to a string. The color can be converted to a string in hexadecimal format. The color can be converted to a string in RGB format.
|
default |
Constructor.
Initializes the color to black.
References a, b, blendWith(), Color(), darken(), g, lighten(), operator!=(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator<<, operator==(), r, toGrayScale(), toHexString(), toRGBAString(), and toRGBString().
Referenced by blendWith(), Color(), darken(), lighten(), operator!=(), operator*(), operator*=(), operator+(), operator+(), operator+=(), operator-(), operator-(), operator-=(), operator<<, operator==(), and toGrayScale().
|
explicit |
|
explicit |
Constructor.
Constructs a color from a string. The string can be a hexadecimal color code or an RGB color code. The hexadecimal color code must be 6 characters long and prefixed with a '#'. The RGB color code must be in the format "rgb(r,g,b)". The alpha component is 255 by default.
| colorString | The color to initialise the object with. |
| fcn::Color::Color | ( | int | r, |
| int | g, | ||
| int | b, | ||
| int | a ) |
Constructor.
Constructs a color from the red, green, blue and alpha components. The default alpha value is 255.
| r | Red color component (range 0-255). |
| g | Green color component (range 0-255). |
| b | Blue color component (range 0-255). |
| a | Alpha, used for transparency. A value of 0 means fully transparent, 255 is fully opaque. |
| fcn::Color::Color | ( | uint8_t | r, |
| uint8_t | g, | ||
| uint8_t | b, | ||
| uint8_t | a = 255 ) |
Constructor.
Constructs a color from the red, green, blue and alpha components. The default alpha value is 255.
| r | Red color component (range 0-255). |
| g | Green color component (range 0-255). |
| b | Blue color component (range 0-255). |
| a | Alpha, used for transparency. A value of 0 means fully transparent, 255 is fully opaque. |
Blends the color with another color using alpha blending.
The alpha value changes. The resulting color's alpha will be a combination of both colors' alpha values.
| other | The color to blend with. |
Definition at line 265 of file color.cpp.
References a, b, Color(), g, and r.
Referenced by Color().
| Color fcn::Color::darken | ( | float | percentage | ) | const |
Darkens the color by a percentage.
The alpha value will be kept as it is. The color will be clamped if it goes out of range. The percentage should be in the range 0-1. A percentage of 0 will return the same color. A percentage of 1 will return black. A percentage of -1 will return white. A percentage of 0.1 will return a color that is 10% darker. A percentage of -0.1 will return a color that is 10% lighter.
| percentage | The percentage to darken the color by. |
Definition at line 248 of file color.cpp.
References a, b, Color(), g, and r.
Referenced by Color().
| Color fcn::Color::lighten | ( | float | percentage | ) | const |
Lightens the color by a percentage.
The alpha value will be kept as it is. The color will be clamped if it goes out of range. The percentage should be in the range 0-1. A percentage of 0 will return the same color. A percentage of 1 will return white. A percentage of -1 will return black. A percentage of 0.1 will return a color that is 10% lighter. A percentage of -0.1 will return a color that is 10% darker.
| percentage | The percentage to lighten the color by. |
Definition at line 238 of file color.cpp.
References a, b, Color(), g, and r.
Referenced by Color().
| bool fcn::Color::operator!= | ( | Color const & | color | ) | const |
| Color fcn::Color::operator* | ( | float | value | ) | const |
Multiplies the RGB values of a color with a float value.
The values will be clamped if they go out of range.
| value | The value to multiply the color with. |
Definition at line 200 of file color.cpp.
References a, b, Color(), g, and r.
Referenced by Color().
| Color & fcn::Color::operator*= | ( | float | value | ) |
Multiplies the RGB values of this color with a float value.
The values will be clamped if they go out of range. The alpha value will be kept as it is.
| value | The value to multiply the color with. |
Definition at line 228 of file color.cpp.
References b, Color(), g, and r.
Referenced by Color().
Adds the RGB values of two colors together.
The values will be clamped if they go out of range.
WARNING: This function will reset the alpha value of the returned color to 255.
| color | A color to add to this color. |
Definition at line 161 of file color.cpp.
References a, b, Color(), g, and r.
Referenced by Color().
| Color fcn::Color::operator+ | ( | float | value | ) | const |
Adds the RGB values of another color to this color.
The values will be clamped if they go out of range. The alpha value will be kept as it is.
| color | The color to add to this color. |
Definition at line 210 of file color.cpp.
References b, Color(), g, and r.
Referenced by Color().
Subtracts the RGB values of one color from another.
The values will be clamped if they go out of range.
WARNING: This function will reset the alpha value of the returned color to 255.
| color | A color to subtract from this color. |
Definition at line 171 of file color.cpp.
References a, b, Color(), g, and r.
Referenced by Color().
| Color fcn::Color::operator- | ( | float | value | ) | const |
Subtracts a float value from the RGB values of a color.
The values will be clamped if they go out of range. The alpha value will be kept as it is.
| value | The value to subtract from the color. |
Subtracts the RGB values of another color from this color.
The values will be clamped if they go out of range. The alpha value will be kept as it is.
| color | The color to subtract from this color. |
Definition at line 219 of file color.cpp.
References b, Color(), g, and r.
Referenced by Color().
| bool fcn::Color::operator== | ( | Color const & | color | ) | const |
| Color fcn::Color::toGrayScale | ( | ) | const |
| std::string fcn::Color::toHexString | ( | ) | const |
| std::string fcn::Color::toRGBAString | ( | ) | const |
| std::string fcn::Color::toRGBString | ( | ) | const |
|
friend |
Output operator for output.
| out | The stream to output to. |
| color | The color to output. |
Definition at line 306 of file color.cpp.
References a, b, Color(), g, operator<<, and r.
Referenced by Color(), and operator<<.
| uint8_t fcn::Color::a {255} |
Alpha color component (0-255).
0 = transparent, 255 = opaque.
Definition at line 322 of file color.hpp.
Referenced by blendWith(), Color(), Color(), Color(), darken(), fcn::Button::draw(), fcn::DropDown::draw(), fcn::ImageButton::draw(), fcn::Slider::draw(), fcn::Tab::draw(), fcn::TabbedArea::draw(), fcn::TextField::draw(), fcn::Window::draw(), fcn::Widget::drawBorder(), fcn::CheckBox::drawBox(), fcn::DropDown::drawButton(), fcn::ScrollArea::drawDownButton(), fcn::ScrollArea::drawHBar(), fcn::ScrollArea::drawHMarker(), fcn::Window::drawInnerBorder(), fcn::ScrollArea::drawLeftButton(), fcn::Slider::drawMarker(), fcn::Widget::drawOutline(), fcn::CheckBox::drawRhombus(), fcn::ScrollArea::drawRightButton(), fcn::sdl2::TrueTypeFont::drawString(), fcn::ScrollArea::drawUpButton(), fcn::ScrollArea::drawVBar(), fcn::ScrollArea::drawVMarker(), lighten(), operator*(), operator+(), operator+(), operator-(), operator-(), operator<<, operator==(), fcn::opengl::Image::putPixel(), fcn::sdl2::SDLputPixelAlpha(), fcn::opengl::Graphics::setColor(), fcn::sdl2::Graphics::setColor(), toGrayScale(), and toRGBAString().
| uint8_t fcn::Color::b {0} |
Blue color component (0-255).
Definition at line 319 of file color.hpp.
Referenced by blendWith(), Color(), Color(), Color(), Color(), darken(), fcn::Button::draw(), fcn::ImageButton::draw(), fcn::sdl2::TrueTypeFont::drawString(), lighten(), operator*(), operator*=(), operator+(), operator+(), operator+=(), operator-(), operator-(), operator-=(), operator<<, operator==(), fcn::opengl::Image::putPixel(), fcn::sdl2::SDLputPixel(), fcn::sdl2::SDLputPixelAlpha(), fcn::opengl::Graphics::setColor(), toGrayScale(), toHexString(), toRGBAString(), and toRGBString().
| uint8_t fcn::Color::g {0} |
Green color component (0-255).
Definition at line 316 of file color.hpp.
Referenced by blendWith(), Color(), Color(), Color(), Color(), darken(), fcn::Button::draw(), fcn::ImageButton::draw(), fcn::sdl2::TrueTypeFont::drawString(), lighten(), operator*(), operator*=(), operator+(), operator+(), operator+=(), operator-(), operator-(), operator-=(), operator<<, operator==(), fcn::opengl::Image::putPixel(), fcn::sdl2::SDLputPixel(), fcn::sdl2::SDLputPixelAlpha(), fcn::opengl::Graphics::setColor(), toGrayScale(), toHexString(), toRGBAString(), and toRGBString().
| uint8_t fcn::Color::r {0} |
Red color component (0-255).
Definition at line 313 of file color.hpp.
Referenced by blendWith(), Color(), Color(), Color(), Color(), darken(), fcn::Button::draw(), fcn::ImageButton::draw(), fcn::sdl2::TrueTypeFont::drawString(), lighten(), operator*(), operator*=(), operator+(), operator+(), operator+=(), operator-(), operator-(), operator-=(), operator<<, operator==(), fcn::opengl::Image::putPixel(), fcn::sdl2::SDLputPixel(), fcn::sdl2::SDLputPixelAlpha(), fcn::opengl::Graphics::setColor(), toGrayScale(), toHexString(), toRGBAString(), and toRGBString().