You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
562B

  1. #include "util/color.hpp"
  2. namespace rack {
  3. NVGcolor colorFromHexString(std::string s) {
  4. uint8_t r = 0;
  5. uint8_t g = 0;
  6. uint8_t b = 0;
  7. uint8_t a = 255;
  8. sscanf(s.c_str(), "#%2hhx%2hhx%2hhx%2hhx", &r, &g, &b, &a);
  9. return nvgRGBA(r, g, b, a);
  10. }
  11. std::string colorToHexString(NVGcolor c) {
  12. uint8_t r = roundf(c.r * 255);
  13. uint8_t g = roundf(c.g * 255);
  14. uint8_t b = roundf(c.b * 255);
  15. uint8_t a = roundf(c.a * 255);
  16. if (a == 255)
  17. return stringf("#%02x%02x%02x", r, g, b);
  18. else
  19. return stringf("#%02x%02x%02x%02x", r, g, b, a);
  20. }
  21. } // namespace rack