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