5 #ifndef TILESON_COLOR_HPP
6 #define TILESON_COLOR_HPP
25 inline explicit Color(
const std::string &color)
27 parseHexString(color);
29 inline Color(T red, T green, T blue, T alpha);
49 void parseHexString(
const std::string &color)
51 if constexpr (std::is_same<T, float>::value)
53 if (color.size() == 9)
55 a = (float) std::stoi(color.substr(1, 2),
nullptr, 16) / 255;
56 r = (float) std::stoi(color.substr(3, 2),
nullptr, 16) / 255;
57 g = (float) std::stoi(color.substr(5, 2),
nullptr, 16) / 255;
58 b = (float) std::stoi(color.substr(7, 2),
nullptr, 16) / 255;
60 else if (color.size() == 7)
62 r = (float) std::stoi(color.substr(1, 2),
nullptr, 16) / 255;
63 g = (float) std::stoi(color.substr(3, 2),
nullptr, 16) / 255;
64 b = (float) std::stoi(color.substr(5, 2),
nullptr, 16) / 255;
70 if (color.size() == 9)
72 a = std::stoi(color.substr(1, 2),
nullptr, 16);
73 r = std::stoi(color.substr(3, 2),
nullptr, 16);
74 g = std::stoi(color.substr(5, 2),
nullptr, 16);
75 b = std::stoi(color.substr(7, 2),
nullptr, 16);
77 else if (color.size() == 7)
79 r = std::stoi(color.substr(1, 2),
nullptr, 16);
80 g = std::stoi(color.substr(3, 2),
nullptr, 16);
81 b = std::stoi(color.substr(5, 2),
nullptr, 16);
101 if constexpr (std::is_same<T, float>::value)
104 return tson::Colorf((
float) r / 255, (
float) g / 255, (
float) b / 255, (
float) a / 255);
116 if constexpr (std::is_same<T, float>::value)
117 return tson::Colori((
float) r * 255, (
float) g * 255, (
float) b * 255, (
float) a * 255);
142 return *
this == other;
157 return !(rhs == *
this);
Color< uint8_t > asInt()
Definition: Color.hpp:114
Color(const std::string &color)
Definition: Color.hpp:25
Color()
Definition: Color.hpp:30
Color< float > asFloat()
Definition: Color.hpp:99
Color(T red, T green, T blue, T alpha)
Definition: Color.hpp:131
T a
Definition: Color.hpp:46
bool operator!=(const Color &rhs) const
Definition: Color.hpp:155
bool operator==(const Color &rhs) const
Definition: Color.hpp:146
T b
Definition: Color.hpp:44
T g
Definition: Color.hpp:42
T r
Definition: Color.hpp:40
bool operator==(const std::string &rhs) const
Definition: Color.hpp:140
Definition: Base64.hpp:12
Color< float > Colorf
Definition: Color.hpp:90
Color< uint8_t > Colori
Definition: Color.hpp:89