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.

115 lines
3.2KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2016 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. #ifndef HAVE_DCAIRO
  20. struct NVGcolor;
  21. #endif
  22. START_NAMESPACE_DGL
  23. // -----------------------------------------------------------------------
  24. /**
  25. A color made from red, green, blue and alpha floating-point values in [0..1] range.
  26. */
  27. struct Color {
  28. /**
  29. Direct access to the color values.
  30. */
  31. union {
  32. float rgba[4];
  33. struct { float red, green, blue, alpha; };
  34. };
  35. /**
  36. Create solid black color.
  37. */
  38. Color() noexcept;
  39. /**
  40. Create a color from red, green, blue and alpha numeric values.
  41. Values must be in [0..255] range.
  42. */
  43. Color(int red, int green, int blue, int alpha = 255) noexcept;
  44. /**
  45. Create a color from red, green, blue and alpha floating-point values.
  46. Values must in [0..1] range.
  47. */
  48. Color(float red, float green, float blue, float alpha = 1.0f) noexcept;
  49. /**
  50. Create a color by copying another color.
  51. */
  52. Color(const Color& color) noexcept;
  53. Color& operator=(const Color& color) noexcept;
  54. /**
  55. Create a color by linearly interpolating two other colors.
  56. */
  57. Color(const Color& color1, const Color& color2, float u) noexcept;
  58. /**
  59. Create a color specified by hue, saturation and lightness.
  60. Values must in [0..1] range.
  61. */
  62. static Color fromHSL(float hue, float saturation, float lightness, float alpha = 1.0f);
  63. /**
  64. Create a color from a HTML string like "#333" or "#112233".
  65. */
  66. static Color fromHTML(const char* rgb, float alpha = 1.0f);
  67. /**
  68. Linearly interpolate this color against another.
  69. */
  70. void interpolate(const Color& other, float u) noexcept;
  71. /**
  72. Check if this color matches another.
  73. @note Comparison is forced within 8-bit color values.
  74. */
  75. bool isEqual(const Color& color, bool withAlpha = true) noexcept;
  76. bool isNotEqual(const Color& color, bool withAlpha = true) noexcept;
  77. bool operator==(const Color& color) noexcept;
  78. bool operator!=(const Color& color) noexcept;
  79. /**
  80. Fix color bounds if needed.
  81. */
  82. void fixBounds() noexcept;
  83. #ifndef HAVE_DCAIRO
  84. /**
  85. @internal
  86. Needed for NanoVG compatibility.
  87. */
  88. Color(const NVGcolor&) noexcept;
  89. operator NVGcolor() const noexcept;
  90. #endif
  91. };
  92. // -----------------------------------------------------------------------
  93. END_NAMESPACE_DGL
  94. #endif // DGL_COLOR_HPP_INCLUDED