| 349 | } |
| 350 | |
| 351 | void Color::fromHex(std::string hexCode) |
| 352 | { |
| 353 | std::array<unsigned short, 3> rgb {}; |
| 354 | std::stringstream ss; |
| 355 | std::string str; |
| 356 | |
| 357 | if (hexCode[0] == '#') |
| 358 | { |
| 359 | hexCode.erase(0, 1); |
| 360 | } |
| 361 | |
| 362 | const int size = hexCode.size(); |
| 363 | |
| 364 | for (unsigned int i = 0; i < 3; i++) |
| 365 | { |
| 366 | if (size == 3) |
| 367 | { |
| 368 | str = std::string(2, hexCode[i]); |
| 369 | } |
| 370 | else if (size == 6) |
| 371 | { |
| 372 | str = hexCode.substr(i * 2, 2); |
| 373 | } |
| 374 | else |
| 375 | { |
| 376 | break; |
| 377 | } |
| 378 | ss << std::hex << str; |
| 379 | ss >> rgb[i]; |
| 380 | ss.clear(); |
| 381 | } |
| 382 | |
| 383 | this->r = rgb[0]; |
| 384 | this->g = rgb[1]; |
| 385 | this->b = rgb[2]; |
| 386 | } |
| 387 | |
| 388 | bool Color::operator==(const Color& color) const |
| 389 | { |