Add remaining files
[juce-lv2.git] / juce / source / src / gui / graphics / colour / juce_Colour.h
blobb69e0834739c1403ec9e74190945787e6c455ddb
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCE_COLOUR_JUCEHEADER__
27 #define __JUCE_COLOUR_JUCEHEADER__
29 #include "../colour/juce_PixelFormats.h"
32 //==============================================================================
33 /**
34 Represents a colour, also including a transparency value.
36 The colour is stored internally as unsigned 8-bit red, green, blue and alpha values.
38 class JUCE_API Colour
40 public:
41 //==============================================================================
42 /** Creates a transparent black colour. */
43 Colour() noexcept;
45 /** Creates a copy of another Colour object. */
46 Colour (const Colour& other) noexcept;
48 /** Creates a colour from a 32-bit ARGB value.
50 The format of this number is:
51 ((alpha << 24) | (red << 16) | (green << 8) | blue).
53 All components in the range 0x00 to 0xff.
54 An alpha of 0x00 is completely transparent, alpha of 0xff is opaque.
56 @see getPixelARGB
58 explicit Colour (uint32 argb) noexcept;
60 /** Creates an opaque colour using 8-bit red, green and blue values */
61 Colour (uint8 red,
62 uint8 green,
63 uint8 blue) noexcept;
65 /** Creates an opaque colour using 8-bit red, green and blue values */
66 static Colour fromRGB (uint8 red,
67 uint8 green,
68 uint8 blue) noexcept;
70 /** Creates a colour using 8-bit red, green, blue and alpha values. */
71 Colour (uint8 red,
72 uint8 green,
73 uint8 blue,
74 uint8 alpha) noexcept;
76 /** Creates a colour using 8-bit red, green, blue and alpha values. */
77 static Colour fromRGBA (uint8 red,
78 uint8 green,
79 uint8 blue,
80 uint8 alpha) noexcept;
82 /** Creates a colour from 8-bit red, green, and blue values, and a floating-point alpha.
84 Alpha of 0.0 is transparent, alpha of 1.0f is opaque.
85 Values outside the valid range will be clipped.
87 Colour (uint8 red,
88 uint8 green,
89 uint8 blue,
90 float alpha) noexcept;
92 /** Creates a colour using 8-bit red, green, blue and float alpha values. */
93 static Colour fromRGBAFloat (uint8 red,
94 uint8 green,
95 uint8 blue,
96 float alpha) noexcept;
98 /** Creates a colour using floating point hue, saturation and brightness values, and an 8-bit alpha.
100 The floating point values must be between 0.0 and 1.0.
101 An alpha of 0x00 is completely transparent, alpha of 0xff is opaque.
102 Values outside the valid range will be clipped.
104 Colour (float hue,
105 float saturation,
106 float brightness,
107 uint8 alpha) noexcept;
109 /** Creates a colour using floating point hue, saturation, brightness and alpha values.
111 All values must be between 0.0 and 1.0.
112 Numbers outside the valid range will be clipped.
114 Colour (float hue,
115 float saturation,
116 float brightness,
117 float alpha) noexcept;
119 /** Creates a colour using floating point hue, saturation and brightness values, and an 8-bit alpha.
121 The floating point values must be between 0.0 and 1.0.
122 An alpha of 0x00 is completely transparent, alpha of 0xff is opaque.
123 Values outside the valid range will be clipped.
125 static Colour fromHSV (float hue,
126 float saturation,
127 float brightness,
128 float alpha) noexcept;
130 /** Destructor. */
131 ~Colour() noexcept;
133 /** Copies another Colour object. */
134 Colour& operator= (const Colour& other) noexcept;
136 /** Compares two colours. */
137 bool operator== (const Colour& other) const noexcept;
138 /** Compares two colours. */
139 bool operator!= (const Colour& other) const noexcept;
141 //==============================================================================
142 /** Returns the red component of this colour.
144 @returns a value between 0x00 and 0xff.
146 uint8 getRed() const noexcept { return argb.getRed(); }
148 /** Returns the green component of this colour.
150 @returns a value between 0x00 and 0xff.
152 uint8 getGreen() const noexcept { return argb.getGreen(); }
154 /** Returns the blue component of this colour.
156 @returns a value between 0x00 and 0xff.
158 uint8 getBlue() const noexcept { return argb.getBlue(); }
160 /** Returns the red component of this colour as a floating point value.
162 @returns a value between 0.0 and 1.0
164 float getFloatRed() const noexcept;
166 /** Returns the green component of this colour as a floating point value.
168 @returns a value between 0.0 and 1.0
170 float getFloatGreen() const noexcept;
172 /** Returns the blue component of this colour as a floating point value.
174 @returns a value between 0.0 and 1.0
176 float getFloatBlue() const noexcept;
178 /** Returns a premultiplied ARGB pixel object that represents this colour.
180 const PixelARGB getPixelARGB() const noexcept;
182 /** Returns a 32-bit integer that represents this colour.
184 The format of this number is:
185 ((alpha << 24) | (red << 16) | (green << 16) | blue).
187 uint32 getARGB() const noexcept;
189 //==============================================================================
190 /** Returns the colour's alpha (opacity).
192 Alpha of 0x00 is completely transparent, 0xff is completely opaque.
194 uint8 getAlpha() const noexcept { return argb.getAlpha(); }
196 /** Returns the colour's alpha (opacity) as a floating point value.
198 Alpha of 0.0 is completely transparent, 1.0 is completely opaque.
200 float getFloatAlpha() const noexcept;
202 /** Returns true if this colour is completely opaque.
204 Equivalent to (getAlpha() == 0xff).
206 bool isOpaque() const noexcept;
208 /** Returns true if this colour is completely transparent.
210 Equivalent to (getAlpha() == 0x00).
212 bool isTransparent() const noexcept;
214 /** Returns a colour that's the same colour as this one, but with a new alpha value. */
215 Colour withAlpha (uint8 newAlpha) const noexcept;
217 /** Returns a colour that's the same colour as this one, but with a new alpha value. */
218 Colour withAlpha (float newAlpha) const noexcept;
220 /** Returns a colour that's the same colour as this one, but with a modified alpha value.
222 The new colour's alpha will be this object's alpha multiplied by the value passed-in.
224 Colour withMultipliedAlpha (float alphaMultiplier) const noexcept;
226 //==============================================================================
227 /** Returns a colour that is the result of alpha-compositing a new colour over this one.
229 If the foreground colour is semi-transparent, it is blended onto this colour
230 accordingly.
232 Colour overlaidWith (const Colour& foregroundColour) const noexcept;
234 /** Returns a colour that lies somewhere between this one and another.
236 If amountOfOther is zero, the result is 100% this colour, if amountOfOther
237 is 1.0, the result is 100% of the other colour.
239 Colour interpolatedWith (const Colour& other, float proportionOfOther) const noexcept;
241 //==============================================================================
242 /** Returns the colour's hue component.
243 The value returned is in the range 0.0 to 1.0
245 float getHue() const noexcept;
247 /** Returns the colour's saturation component.
248 The value returned is in the range 0.0 to 1.0
250 float getSaturation() const noexcept;
252 /** Returns the colour's brightness component.
253 The value returned is in the range 0.0 to 1.0
255 float getBrightness() const noexcept;
257 /** Returns the colour's hue, saturation and brightness components all at once.
258 The values returned are in the range 0.0 to 1.0
260 void getHSB (float& hue,
261 float& saturation,
262 float& brightness) const noexcept;
264 //==============================================================================
265 /** Returns a copy of this colour with a different hue. */
266 Colour withHue (float newHue) const noexcept;
268 /** Returns a copy of this colour with a different saturation. */
269 Colour withSaturation (float newSaturation) const noexcept;
271 /** Returns a copy of this colour with a different brightness.
272 @see brighter, darker, withMultipliedBrightness
274 Colour withBrightness (float newBrightness) const noexcept;
276 /** Returns a copy of this colour with it hue rotated.
278 The new colour's hue is ((this->getHue() + amountToRotate) % 1.0)
280 @see brighter, darker, withMultipliedBrightness
282 Colour withRotatedHue (float amountToRotate) const noexcept;
284 /** Returns a copy of this colour with its saturation multiplied by the given value.
286 The new colour's saturation is (this->getSaturation() * multiplier)
287 (the result is clipped to legal limits).
289 Colour withMultipliedSaturation (float multiplier) const noexcept;
291 /** Returns a copy of this colour with its brightness multiplied by the given value.
293 The new colour's saturation is (this->getBrightness() * multiplier)
294 (the result is clipped to legal limits).
296 Colour withMultipliedBrightness (float amount) const noexcept;
298 //==============================================================================
299 /** Returns a brighter version of this colour.
301 @param amountBrighter how much brighter to make it - a value from 0 to 1.0 where 0 is
302 unchanged, and higher values make it brighter
303 @see withMultipliedBrightness
305 Colour brighter (float amountBrighter = 0.4f) const noexcept;
307 /** Returns a darker version of this colour.
309 @param amountDarker how much darker to make it - a value from 0 to 1.0 where 0 is
310 unchanged, and higher values make it darker
311 @see withMultipliedBrightness
313 Colour darker (float amountDarker = 0.4f) const noexcept;
315 //==============================================================================
316 /** Returns a colour that will be clearly visible against this colour.
318 The amount parameter indicates how contrasting the new colour should
319 be, so e.g. Colours::black.contrasting (0.1f) will return a colour
320 that's just a little bit lighter; Colours::black.contrasting (1.0f) will
321 return white; Colours::white.contrasting (1.0f) will return black, etc.
323 Colour contrasting (float amount = 1.0f) const noexcept;
325 /** Returns a colour that contrasts against two colours.
327 Looks for a colour that contrasts with both of the colours passed-in.
329 Handy for things like choosing a highlight colour in text editors, etc.
331 static Colour contrasting (const Colour& colour1,
332 const Colour& colour2) noexcept;
334 //==============================================================================
335 /** Returns an opaque shade of grey.
337 @param brightness the level of grey to return - 0 is black, 1.0 is white
339 static Colour greyLevel (float brightness) noexcept;
341 //==============================================================================
342 /** Returns a stringified version of this colour.
344 The string can be turned back into a colour using the fromString() method.
346 String toString() const;
348 /** Reads the colour from a string that was created with toString().
350 static Colour fromString (const String& encodedColourString);
352 /** Returns the colour as a hex string in the form RRGGBB or AARRGGBB. */
353 String toDisplayString (bool includeAlphaValue) const;
355 private:
356 //==============================================================================
357 PixelARGB argb;
361 #endif // __JUCE_COLOUR_JUCEHEADER__