35 lines
634 B
C++
35 lines
634 B
C++
#include <string>
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include "colour.h"
|
|
|
|
Colour::Colour()
|
|
{
|
|
}
|
|
|
|
Colour::Colour(std::string Code)
|
|
{
|
|
if (Code.length() == 7) {
|
|
char p[3];
|
|
p[0] = Code[1];
|
|
p[1] = Code[2];
|
|
p[2] = '\0';
|
|
r = (float)strtol(p, NULL, 16) / 0xFF;
|
|
p[0] = Code[3];
|
|
p[1] = Code[4];
|
|
g = (float)strtol(p, NULL, 16) / 0xFF;
|
|
p[0] = Code[5];
|
|
p[1] = Code[6];
|
|
b = (float)strtol(p, NULL, 16) / 0xFF;
|
|
|
|
colour.set_rgb_p(r, g, b);
|
|
}
|
|
}
|
|
|
|
std::string Colour::ToCode() const
|
|
{
|
|
char code[8];
|
|
snprintf(code, sizeof code, "#%02X%02X%02X", (int)(r * 0xFF), (int)(g * 0xFF), (int)(b * 0xFF));
|
|
return std::string(code);
|
|
}
|