2 * DISTRHO Plugin Framework (DPF)
3 * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
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.
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.
17 #ifndef DGL_COLOR_HPP_INCLUDED
18 #define DGL_COLOR_HPP_INCLUDED
26 // --------------------------------------------------------------------------------------------------------------------
29 A color made from red, green, blue and alpha floating-point values in [0..1] range.
33 Direct access to the color values.
37 struct { float red
, green
, blue
, alpha
; };
41 Create solid black color.
46 Create a color from red, green, blue and alpha numeric values.
47 All values except alpha must be in [0..255] range, with alpha in [0..1] range.
49 Color(int red
, int green
, int blue
, float alpha
= 1.0f
) noexcept
;
52 Create a color from red, green, blue and alpha floating-point values.
53 All values must in [0..1] range.
55 Color(float red
, float green
, float blue
, float alpha
= 1.0f
) noexcept
;
58 Create a color by copying another color.
60 Color(const Color
& color
) noexcept
;
61 Color
& operator=(const Color
& color
) noexcept
;
64 Create a color by linearly interpolating two other colors.
66 Color(const Color
& color1
, const Color
& color2
, float u
) noexcept
;
69 Create a new color based on this one but with a different alpha value.
71 Color
withAlpha(float alpha
) noexcept
;
74 Create a color specified by hue, saturation and lightness.
75 Values must in [0..1] range.
77 static Color
fromHSL(float hue
, float saturation
, float lightness
, float alpha
= 1.0f
);
80 Create a color from a HTML string like "#333" or "#112233".
82 static Color
fromHTML(const char* rgb
, float alpha
= 1.0f
) noexcept
;
85 Linearly interpolate this color against another.
87 void interpolate(const Color
& other
, float u
) noexcept
;
90 Check if this color matches another.
91 @note Comparison is done within 8-bit color space.
93 bool isEqual(const Color
& color
, bool withAlpha
= true) noexcept
;
94 bool isNotEqual(const Color
& color
, bool withAlpha
= true) noexcept
;
95 bool operator==(const Color
& color
) noexcept
;
96 bool operator!=(const Color
& color
) noexcept
;
99 Fix color bounds if needed.
101 void fixBounds() noexcept
;
104 Set this color for use in the next drawing operation for the provided context.
106 void setFor(const GraphicsContext
& context
, bool includeAlpha
= false);
110 Needed for NanoVG compatibility.
112 Color(const NVGcolor
&) noexcept
;
113 operator NVGcolor() const noexcept
;
116 // --------------------------------------------------------------------------------------------------------------------
120 #endif // DGL_COLOR_HPP_INCLUDED