DISTRHO Plugin Framework
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.

100 lines
2.9KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef DGL_COLOR_HPP_INCLUDED
  17. #define DGL_COLOR_HPP_INCLUDED
  18. #include "Base.hpp"
  19. struct NVGcolor;
  20. START_NAMESPACE_DGL
  21. // -----------------------------------------------------------------------
  22. // TODO: create color from "#333" and "#112233" like strings
  23. /**
  24. A color made from red, green, blue and alpha floating-point values in [0..1] range.
  25. */
  26. struct Color {
  27. /**
  28. Direct access to the color values.
  29. */
  30. union {
  31. float rgba[4];
  32. struct { float red, green, blue, alpha; };
  33. };
  34. /**
  35. Create black color.
  36. */
  37. Color() noexcept;
  38. /**
  39. Create a color from red, green, blue and alpha numeric values.
  40. Values must be in [0..255] range.
  41. */
  42. Color(const int red, const int green, const int blue, const int alpha = 255) noexcept;
  43. /**
  44. Create a color from red, green, blue and alpha floating-point values.
  45. Values must in [0..1] range.
  46. */
  47. Color(const float red, const float green, const float blue, const float alpha = 1.0f) noexcept;
  48. /**
  49. Create a color by copying another color.
  50. */
  51. Color(const Color& color) noexcept;
  52. Color& operator=(const Color& color) noexcept;
  53. /**
  54. Create a color by linearly interpolating two other colors.
  55. */
  56. Color(const Color& color1, const Color& color2, const float u) noexcept;
  57. /**
  58. Create a color specified by hue, saturation, lightness and alpha.
  59. HSL values are all in [0..1] range, alpha in [0..255] range.
  60. */
  61. static Color HSL(const float hue, const float saturation, const float lightness, const int alpha = 255);
  62. /**
  63. Linearly interpolate this color against another.
  64. */
  65. void interpolate(const Color& other, const float u) noexcept;
  66. /**
  67. Check if this color matches another.
  68. */
  69. bool operator==(const Color& color) noexcept;
  70. bool operator!=(const Color& color) noexcept;
  71. /**
  72. @internal
  73. Needed for NanoVG compatibility.
  74. */
  75. Color(const NVGcolor&) noexcept;
  76. operator NVGcolor() const noexcept;
  77. };
  78. // -----------------------------------------------------------------------
  79. END_NAMESPACE_DGL
  80. #endif // DGL_COLOR_HPP_INCLUDED