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.

color.hpp 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #include <nanovg.h>
  3. #include <common.hpp>
  4. #include <string.hpp>
  5. namespace rack {
  6. /** Utilities for `NVGcolor`
  7. */
  8. namespace color {
  9. static const NVGcolor BLACK_TRANSPARENT = nvgRGBA(0x00, 0x00, 0x00, 0x00);
  10. static const NVGcolor WHITE_TRANSPARENT = nvgRGBA(0xff, 0xff, 0xff, 0x00);
  11. // All corners of the RGB cube and nothing else
  12. static const NVGcolor BLACK = nvgRGB(0x00, 0x00, 0x00);
  13. static const NVGcolor RED = nvgRGB(0xff, 0x00, 0x00);
  14. static const NVGcolor GREEN = nvgRGB(0x00, 0xff, 0x00);
  15. static const NVGcolor BLUE = nvgRGB(0x00, 0x00, 0xff);
  16. static const NVGcolor CYAN = nvgRGB(0x00, 0xff, 0xff);
  17. static const NVGcolor MAGENTA = nvgRGB(0xff, 0x00, 0xff);
  18. static const NVGcolor YELLOW = nvgRGB(0xff, 0xff, 0x00);
  19. static const NVGcolor WHITE = nvgRGB(0xff, 0xff, 0xff);
  20. bool isEqual(NVGcolor a, NVGcolor b);
  21. /** Limits color components between 0 and 1. */
  22. NVGcolor clamp(NVGcolor a);
  23. /** Subtracts color components elementwise. */
  24. NVGcolor minus(NVGcolor a, NVGcolor b);
  25. /** Adds color components elementwise. */
  26. NVGcolor plus(NVGcolor a, NVGcolor b);
  27. /** Multiplies color components elementwise. */
  28. NVGcolor mult(NVGcolor a, NVGcolor b);
  29. NVGcolor mult(NVGcolor a, float x);
  30. /** Screen blending with alpha compositing */
  31. NVGcolor screen(NVGcolor a, NVGcolor b);
  32. /** Multiplies alpha value. */
  33. NVGcolor alpha(NVGcolor a, float alpha);
  34. /** Converts from color hex string of the form "#RRGGBB" or "#RRGGBBAA".
  35. Returns WHITE on error.
  36. */
  37. NVGcolor fromHexString(std::string s);
  38. std::string toHexString(NVGcolor c);
  39. } // namespace color
  40. } // namespace rack