2019-11-13 13:37:49 +01:00
|
|
|
#include "Color.hpp"
|
2019-10-29 15:24:57 +01:00
|
|
|
|
2019-11-13 13:37:49 +01:00
|
|
|
namespace vkvm {
|
2019-10-29 15:24:57 +01:00
|
|
|
|
2019-11-29 11:39:40 +01:00
|
|
|
constexpr int maxValue = 255;
|
|
|
|
|
2019-11-26 13:22:53 +01:00
|
|
|
Color::Color() noexcept
|
|
|
|
: red(0), green(0), blue(0) {}
|
|
|
|
|
2019-11-29 11:39:40 +01:00
|
|
|
Color::Color(int red, int green, int blue) noexcept {
|
|
|
|
setRed(red);
|
|
|
|
setGreen(green);
|
|
|
|
setBlue(blue);
|
|
|
|
}
|
2019-11-26 13:22:53 +01:00
|
|
|
|
2019-11-21 12:37:52 +01:00
|
|
|
Color::Color(unsigned int hex) noexcept {
|
2019-12-01 19:56:35 +01:00
|
|
|
red = static_cast<unsigned char>(hex >> 16 & 0xFF);
|
|
|
|
green = static_cast<unsigned char>(hex >> 8U & 0xFF);
|
|
|
|
blue = static_cast<unsigned char>((hex & 0xFF));
|
2019-11-13 13:37:49 +01:00
|
|
|
}
|
2019-10-29 15:24:57 +01:00
|
|
|
|
2019-11-13 13:37:49 +01:00
|
|
|
auto Color::getRed() -> unsigned char {
|
|
|
|
return red;
|
|
|
|
}
|
2019-11-07 16:34:15 +01:00
|
|
|
|
2019-11-13 13:37:49 +01:00
|
|
|
auto Color::getGreen() -> unsigned char {
|
|
|
|
return green;
|
|
|
|
}
|
2019-11-07 16:34:15 +01:00
|
|
|
|
2019-11-13 13:37:49 +01:00
|
|
|
auto Color::getBlue() -> unsigned char {
|
|
|
|
return blue;
|
|
|
|
}
|
2019-11-07 16:34:15 +01:00
|
|
|
|
2019-11-29 11:39:40 +01:00
|
|
|
auto Color::setRed(int value) -> void {
|
|
|
|
if(value > maxValue) {
|
|
|
|
value = maxValue;
|
|
|
|
}
|
|
|
|
|
2019-11-13 13:37:49 +01:00
|
|
|
red = value;
|
|
|
|
}
|
2019-11-07 16:34:15 +01:00
|
|
|
|
2019-11-29 11:39:40 +01:00
|
|
|
auto Color::setGreen(int value) -> void {
|
|
|
|
if(value > maxValue) {
|
|
|
|
value = maxValue;
|
|
|
|
}
|
|
|
|
|
2019-11-13 13:37:49 +01:00
|
|
|
green = value;
|
|
|
|
}
|
2019-11-07 16:34:15 +01:00
|
|
|
|
2019-11-29 11:39:40 +01:00
|
|
|
auto Color::setBlue(int value) -> void {
|
|
|
|
if(value > maxValue) {
|
|
|
|
value = maxValue;
|
|
|
|
}
|
|
|
|
|
2019-11-13 13:37:49 +01:00
|
|
|
blue = value;
|
|
|
|
}
|
2019-11-21 11:35:54 +01:00
|
|
|
|
|
|
|
bool Color::operator==(const Color &other) const {
|
|
|
|
return this->blue == other.blue && this->green == other.green && this->red == other.red;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Color::operator!=(const Color &other) const {
|
|
|
|
return this->blue != other.blue || this->green != other.green || this->red != other.red;
|
|
|
|
}
|
2019-11-13 13:37:49 +01:00
|
|
|
}
|