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