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.

70 lines
2.1KB

  1. #pragma once
  2. #include <nanovg.h>
  3. #include <common.hpp>
  4. #include <string.hpp>
  5. namespace rack {
  6. /** Utilities for `NVGcolor` */
  7. namespace color {
  8. static const NVGcolor BLACK_TRANSPARENT = nvgRGBA(0x00, 0x00, 0x00, 0x00);
  9. static const NVGcolor WHITE_TRANSPARENT = nvgRGBA(0xff, 0xff, 0xff, 0x00);
  10. // All corners of the RGB cube and nothing else
  11. static const NVGcolor BLACK = nvgRGB(0x00, 0x00, 0x00);
  12. static const NVGcolor RED = nvgRGB(0xff, 0x00, 0x00);
  13. static const NVGcolor GREEN = nvgRGB(0x00, 0xff, 0x00);
  14. static const NVGcolor BLUE = nvgRGB(0x00, 0x00, 0xff);
  15. static const NVGcolor CYAN = nvgRGB(0x00, 0xff, 0xff);
  16. static const NVGcolor MAGENTA = nvgRGB(0xff, 0x00, 0xff);
  17. static const NVGcolor YELLOW = nvgRGB(0xff, 0xff, 0x00);
  18. static const NVGcolor WHITE = nvgRGB(0xff, 0xff, 0xff);
  19. /** Returns whether all RGBA color components are equal. */
  20. bool isEqual(NVGcolor a, NVGcolor b);
  21. /** Limits RGBA color components between 0 and 1. */
  22. NVGcolor clamp(NVGcolor a);
  23. /** Subtracts RGB color components elementwise.
  24. Alpha value is copied from `a`.
  25. */
  26. NVGcolor minus(NVGcolor a, NVGcolor b);
  27. /** Adds RGB color components elementwise.
  28. Alpha value is copied from `a`.
  29. */
  30. NVGcolor plus(NVGcolor a, NVGcolor b);
  31. /** Multiplies RGB color components elementwise.
  32. Alpha value is copied from `a`.
  33. */
  34. NVGcolor mult(NVGcolor a, NVGcolor b);
  35. /** Multiplies RGB color components by a scalar.
  36. Alpha value is untouched.
  37. */
  38. NVGcolor mult(NVGcolor a, float x);
  39. /** Interpolates RGBA color components. */
  40. NVGcolor lerp(NVGcolor a, NVGcolor b, float t);
  41. /** Screen blending with alpha compositing.
  42. https://en.wikipedia.org/wiki/Blend_modes#Screen
  43. */
  44. NVGcolor screen(NVGcolor a, NVGcolor b);
  45. /** Multiplies alpha value by a scalar.
  46. RGB color components are untouched.
  47. */
  48. NVGcolor alpha(NVGcolor a, float alpha);
  49. /** Converts from hex string of the form "#RRGGBB" or "#RRGGBBAA".
  50. Must include "#".
  51. Returns WHITE on error.
  52. */
  53. NVGcolor fromHexString(std::string s);
  54. /** Converts color to hex string of the form "#RRGGBB" if opaque or "#RRGGBBAA" if alpha < 255.
  55. Floating point color components are rounded to nearest 8-bit integer.
  56. */
  57. std::string toHexString(NVGcolor c);
  58. } // namespace color
  59. } // namespace rack