]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/colour.h
Add test for absence of events from wxSpinCtrlDouble ctor.
[wxWidgets.git] / interface / wx / colour.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: colour.h
e54c96f1 3// Purpose: interface of wxColour
23324ae1 4// Author: wxWidgets team
526954c5 5// Licence: wxWindows licence
23324ae1
FM
6/////////////////////////////////////////////////////////////////////////////
7
4707b84c
FM
8
9
10/**
11 Flags for wxColour -> wxString conversion (see wxColour::GetAsString).
12
13 @{
14*/
63a6a750
RD
15enum {
16 wxC2S_NAME = 1, // return colour name, when possible
17 wxC2S_CSS_SYNTAX = 2, // return colour in rgb(r,g,b) syntax
18 wxC2S_HTML_SYNTAX = 4 // return colour in #rrggbb syntax
19};
4707b84c
FM
20
21//@}
22
63a6a750
RD
23const unsigned char wxALPHA_TRANSPARENT = 0;
24const unsigned char wxALPHA_OPAQUE = 0xff;
4707b84c 25
23324ae1
FM
26/**
27 @class wxColour
7c913512 28
7fa7088e
BP
29 A colour is an object representing a combination of Red, Green, and Blue
30 (RGB) intensity values, and is used to determine drawing colours. See the
31 entry for wxColourDatabase for how a pointer to a predefined, named colour
32 may be returned instead of creating a new colour.
7c913512 33
23324ae1 34 Valid RGB values are in the range 0 to 255.
7c913512 35
23324ae1 36 You can retrieve the current system colour settings with wxSystemSettings.
7c913512 37
23324ae1
FM
38 @library{wxcore}
39 @category{gdi}
7c913512 40
23324ae1 41 @stdobjects
968f15e2 42 - ::wxNullColour - An empty, invalid colour.
cd300ef7 43 - ::wxTransparentColour - Valid but fully transparent colour (new in 2.9.1).
968f15e2
BP
44 - ::wxBLACK
45 - ::wxBLUE
46 - ::wxCYAN
47 - ::wxGREEN
86028025 48 - ::wxYELLOW
968f15e2
BP
49 - ::wxLIGHT_GREY
50 - ::wxRED
51 - ::wxWHITE
7c913512 52
e54c96f1 53 @see wxColourDatabase, wxPen, wxBrush, wxColourDialog, wxSystemSettings
23324ae1
FM
54*/
55class wxColour : public wxObject
56{
57public:
7fa7088e 58
23324ae1 59 /**
7fa7088e
BP
60 Default constructor.
61 */
62 wxColour();
3c4f71cc 63
7fa7088e 64 /**
7c913512 65 @param red
4cc4bfaf 66 The red value.
7c913512 67 @param green
4cc4bfaf 68 The green value.
7c913512 69 @param blue
4cc4bfaf 70 The blue value.
7c913512 71 @param alpha
7fa7088e
BP
72 The alpha value. Alpha values range from 0 (wxALPHA_TRANSPARENT) to
73 255 (wxALPHA_OPAQUE).
74 */
75 wxColour(unsigned char red, unsigned char green, unsigned char blue,
76 unsigned char alpha = wxALPHA_OPAQUE);
77
78 /**
7c913512 79 @param colourName
4cc4bfaf 80 The colour name.
7fa7088e
BP
81 */
82 wxColour(const wxString& colourName);
3c4f71cc 83
63a6a750
RD
84 /**
85 @param colRGB
86 A packed RGB value.
87 */
88 wxColour(unsigned long colRGB);
89
7fa7088e
BP
90 /**
91 Copy constructor.
23324ae1 92 */
7c913512 93 wxColour(const wxColour& colour);
23324ae1
FM
94
95 /**
96 Returns the alpha value, on platforms where alpha is not yet supported, this
97 always returns wxALPHA_OPAQUE.
98 */
b7e94bd7 99 virtual unsigned char Alpha() const;
23324ae1
FM
100
101 /**
102 Returns the blue intensity.
103 */
b7e94bd7 104 virtual unsigned char Blue() const;
23324ae1 105
23324ae1 106 /**
7fa7088e
BP
107 Converts this colour to a wxString using the given flags.
108
4707b84c
FM
109 The supported flags are @c wxC2S_NAME, to obtain the colour name
110 (e.g. wxColour(255,0,0) == "red"), @c wxC2S_CSS_SYNTAX, to obtain
111 the colour in the "rgb(r,g,b)" or "rgba(r,g,b,a)" syntax
112 (e.g. wxColour(255,0,0,85) == "rgba(255,0,0,0.333)"), and
113 @c wxC2S_HTML_SYNTAX, to obtain the colour as "#" followed by 6
114 hexadecimal digits (e.g. wxColour(255,0,0) == "#FF0000").
7fa7088e
BP
115
116 This function never fails and always returns a non-empty string but
117 asserts if the colour has alpha channel (i.e. is non opaque) but
4707b84c 118 @c wxC2S_CSS_SYNTAX (which is the only one supporting alpha) is not
23324ae1 119 specified in flags.
3c4f71cc 120
1e24c2af 121 @since 2.7.0
23324ae1 122 */
4707b84c 123 virtual wxString GetAsString(long flags = wxC2S_NAME | wxC2S_CSS_SYNTAX) const;
23324ae1 124
b0edecea
VZ
125 //@{
126 /**
127 Sets the RGB or RGBA colour values from a single 32 bit value.
128
129 The arguments @a colRGB and @a colRGBA should be of the form 0x00BBGGRR
130 and 0xAABBGGRR respectively where @c 0xRR, @c 0xGG, @c 0xBB and @c 0xAA
131 are the values of the red, blue, green and alpha components.
132
133 Notice the right-to-left order of components!
134
135 @see GetRGB(), GetRGBA()
136
137 @since 2.9.1
138 */
139 void SetRGB(wxUint32 colRGB);
140 void SetRGBA(wxUint32 colRGBA);
141 //@}
142
143 //@{
144 /**
145 Gets the RGB or RGBA colour values as a single 32 bit value.
146
147 The returned value is of the same form as expected by SetRGB() and
148 SetRGBA().
149
150 Notice that GetRGB() returns the value with 0 as its highest byte
151 independently of the value actually returned by Alpha(). So for a fully
152 opaque colour, the return value of GetRGBA() is @c 0xFFBBGGRR while
153 that of GetRGB() is @c 0x00BBGGRR.
154
155 @since 2.9.1
156 */
157 wxUint32 GetRGB() const;
158 wxUint32 GetRGBA() const;
159 //@}
160
23324ae1 161 /**
4707b84c
FM
162 Returns a pixel value which is platform-dependent.
163 On Windows, a COLORREF is returned.
23324ae1 164 On X, an allocated pixel value is returned.
4707b84c 165 If the pixel is invalid (on X, unallocated), @c -1 is returned.
23324ae1 166 */
63a6a750 167 wxIntPtr GetPixel() const;
23324ae1
FM
168
169 /**
170 Returns the green intensity.
171 */
b7e94bd7 172 virtual unsigned char Green() const;
23324ae1
FM
173
174 /**
175 Returns @true if the colour object is valid (the colour has been initialised
176 with RGB values).
177 */
0004982c 178 virtual bool IsOk() const;
23324ae1
FM
179
180 /**
181 Returns the red intensity.
182 */
b7e94bd7 183 virtual unsigned char Red() const;
23324ae1
FM
184
185 //@{
186 /**
187 Sets the RGB intensity values using the given values (first overload),
7fa7088e 188 extracting them from the packed long (second overload), using the given
d13b34d3 189 string (third overload).
7fa7088e 190
7c913512 191 When using third form, Set() accepts: colour names (those listed in
b2025b31
FM
192 wxColourDatabase), the CSS-like @c "rgb(r,g,b)" or @c "rgba(r,g,b,a)" syntax
193 (case insensitive) and the HTML-like syntax: @c "#" followed by 6 hexadecimal
194 digits for red, green, blue components.
7fa7088e 195
23324ae1 196 Returns @true if the conversion was successful, @false otherwise.
3c4f71cc 197
1e24c2af 198 @since 2.7.0
23324ae1
FM
199 */
200 void Set(unsigned char red, unsigned char green,
201 unsigned char blue,
4cc4bfaf 202 unsigned char alpha = wxALPHA_OPAQUE);
7c913512 203 void Set(unsigned long RGB);
4cc4bfaf 204 bool Set(const wxString& str);
23324ae1
FM
205 //@}
206
207 /**
208 Tests the inequality of two colours by comparing individual red, green, blue
209 colours and alpha values.
210 */
4707b84c 211 bool operator !=(const wxColour& colour) const;
23324ae1 212
23324ae1
FM
213 /**
214 Assignment operator, using a colour name to be found in the colour database.
3c4f71cc 215
4cc4bfaf 216 @see wxColourDatabase
23324ae1 217 */
382f12e4 218 wxColour& operator=(const wxColour& colour);
23324ae1
FM
219
220 /**
221 Tests the equality of two colours by comparing individual red, green, blue
222 colours and alpha values.
223 */
4707b84c 224 bool operator ==(const wxColour& colour) const;
198c264d
JS
225
226 /**
227 Assign 0 or 255 to rgb out parameters.
228 @since 2.9.0
229 */
230 static void MakeMono(unsigned char* r, unsigned char* g, unsigned char* b, bool on);
231
232 /**
233 Create a disabled (dimmed) colour from (in/out) rgb parameters.
234 @since 2.9.0
235 */
236 static void MakeDisabled(unsigned char* r, unsigned char* g, unsigned char* b, unsigned char brightness = 255);
893d540e
VZ
237
238 /**
239 Make a disabled version of this colour.
240
241 This method modifies the object in place and returns the object itself.
242
243 @since 2.9.5
244 */
245 wxColour& MakeDisabled(unsigned char brightness = 255);
246
198c264d
JS
247 /**
248 Create a grey colour from (in/out) rgb parameters using integer arithmetic.
249 @since 2.9.0
250 */
251 static void MakeGrey(unsigned char* r, unsigned char* g, unsigned char* b);
252
253 /**
254 Create a grey colour from (in/out) rgb parameters using floating point arithmetic.
255 Defaults to using the standard ITU-T BT.601 when converting to YUV, where every pixel equals
256 (R * @a weight_r) + (G * @a weight_g) + (B * @a weight_b).
257 @since 2.9.0
258 */
259 static void MakeGrey(unsigned char* r, unsigned char* g, unsigned char* b,
260 double weight_r, double weight_g, double weight_b);
261
262 /**
263 Blend colour, taking alpha into account.
264 @since 2.9.0
265 */
266 static unsigned char AlphaBlend(unsigned char fg, unsigned char bg, double alpha);
267
268 /**
269 ChangeLightness() is a utility function that simply darkens
270 or lightens a color, based on the specified percentage
271 ialpha of 0 would be completely black, 200 completely white
272 an ialpha of 100 returns the same colour
273 @since 2.9.0
274 */
275 static void ChangeLightness(unsigned char* r, unsigned char* g, unsigned char* b, int ialpha);
276
277 /**
278 wxColour wrapper for ChangeLightness(r,g,b,ialpha).
279 @since 2.9.0
280 */
281 wxColour ChangeLightness(int ialpha) const;
23324ae1 282};
e54c96f1
FM
283
284
968f15e2
BP
285/** @name Predefined colors. */
286//@{
e54c96f1 287wxColour wxNullColour;
ca2c1e0d 288wxColour wxTransparentColour;
968f15e2
BP
289wxColour* wxBLACK;
290wxColour* wxBLUE;
291wxColour* wxCYAN;
292wxColour* wxGREEN;
86028025 293wxColour* wxYELLOW;
968f15e2
BP
294wxColour* wxLIGHT_GREY;
295wxColour* wxRED;
296wxColour* wxWHITE;
297//@}
e54c96f1
FM
298
299
7fa7088e
BP
300
301// ============================================================================
302// Global functions/macros
303// ============================================================================
304
b21126db 305/** @addtogroup group_funcmacro_misc */
7fa7088e
BP
306//@{
307
308/**
309 Converts string to a wxColour best represented by the given string. Returns
310 @true on success.
311
312 @see wxToString(const wxColour&)
313
314 @header{wx/colour.h}
315*/
316bool wxFromString(const wxString& string, wxColour* colour);
317
318/**
319 Converts the given wxColour into a string.
320
321 @see wxFromString(const wxString&, wxColour*)
322
323 @header{wx/colour.h}
324*/
325wxString wxToString(const wxColour& colour);
326
327//@}
328