]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/colour.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxColour
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
12 Flags for wxColour -> wxString conversion (see wxColour::GetAsString).
16 #define wxC2S_NAME 1 //!< Return colour name, when possible.
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.
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.
31 Valid RGB values are in the range 0 to 255.
33 You can retrieve the current system colour settings with wxSystemSettings.
39 - ::wxNullColour - An empty, invalid colour.
40 - ::wxTransparentColour - Valid but fully transparent colour (new in 2.9.1).
50 @see wxColourDatabase, wxPen, wxBrush, wxColourDialog, wxSystemSettings
52 class wxColour
: public wxObject
69 The alpha value. Alpha values range from 0 (wxALPHA_TRANSPARENT) to
72 wxColour(unsigned char red
, unsigned char green
, unsigned char blue
,
73 unsigned char alpha
= wxALPHA_OPAQUE
);
79 wxColour(const wxString
& colourName
);
84 wxColour(const wxColour
& colour
);
87 Returns the alpha value, on platforms where alpha is not yet supported, this
88 always returns wxALPHA_OPAQUE.
90 virtual unsigned char Alpha() const;
93 Returns the blue intensity.
95 virtual unsigned char Blue() const;
98 Converts this colour to a wxString using the given flags.
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").
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
109 @c wxC2S_CSS_SYNTAX (which is the only one supporting alpha) is not
114 virtual wxString
GetAsString(long flags
= wxC2S_NAME
| wxC2S_CSS_SYNTAX
) const;
118 Sets the RGB or RGBA colour values from a single 32 bit value.
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.
124 Notice the right-to-left order of components!
126 @see GetRGB(), GetRGBA()
130 void SetRGB(wxUint32 colRGB
);
131 void SetRGBA(wxUint32 colRGBA
);
136 Gets the RGB or RGBA colour values as a single 32 bit value.
138 The returned value is of the same form as expected by SetRGB() and
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.
148 wxUint32
GetRGB() const;
149 wxUint32
GetRGBA() const;
153 Returns a pixel value which is platform-dependent.
154 On Windows, a COLORREF is returned.
155 On X, an allocated pixel value is returned.
156 If the pixel is invalid (on X, unallocated), @c -1 is returned.
158 int GetPixel() const;
161 Returns the green intensity.
163 virtual unsigned char Green() const;
166 Returns @true if the colour object is valid (the colour has been initialised
169 virtual bool IsOk() const;
172 Returns the red intensity.
174 virtual unsigned char Red() const;
178 Sets the RGB intensity values using the given values (first overload),
179 extracting them from the packed long (second overload), using the given
180 string (third overloard).
182 When using third form, Set() accepts: colour names (those listed in
183 wxTheColourDatabase()), the CSS-like @c "rgb(r,g,b)" or
184 @c "rgba(r,g,b,a)" syntax (case insensitive) and the HTML-like syntax
185 (i.e. @c "#" followed by 6 hexadecimal digits for red, green, blue
188 Returns @true if the conversion was successful, @false otherwise.
192 void Set(unsigned char red
, unsigned char green
,
194 unsigned char alpha
= wxALPHA_OPAQUE
);
195 void Set(unsigned long RGB
);
196 bool Set(const wxString
& str
);
200 Tests the inequality of two colours by comparing individual red, green, blue
201 colours and alpha values.
203 bool operator !=(const wxColour
& colour
) const;
206 Assignment operator, using a colour name to be found in the colour database.
208 @see wxColourDatabase
210 wxColour
& operator=(const wxColour
& colour
);
213 Tests the equality of two colours by comparing individual red, green, blue
214 colours and alpha values.
216 bool operator ==(const wxColour
& colour
) const;
219 Assign 0 or 255 to rgb out parameters.
222 static void MakeMono(unsigned char* r
, unsigned char* g
, unsigned char* b
, bool on
);
225 Create a disabled (dimmed) colour from (in/out) rgb parameters.
228 static void MakeDisabled(unsigned char* r
, unsigned char* g
, unsigned char* b
, unsigned char brightness
= 255);
231 Create a grey colour from (in/out) rgb parameters using integer arithmetic.
234 static void MakeGrey(unsigned char* r
, unsigned char* g
, unsigned char* b
);
237 Create a grey colour from (in/out) rgb parameters using floating point arithmetic.
238 Defaults to using the standard ITU-T BT.601 when converting to YUV, where every pixel equals
239 (R * @a weight_r) + (G * @a weight_g) + (B * @a weight_b).
242 static void MakeGrey(unsigned char* r
, unsigned char* g
, unsigned char* b
,
243 double weight_r
, double weight_g
, double weight_b
);
246 Blend colour, taking alpha into account.
249 static unsigned char AlphaBlend(unsigned char fg
, unsigned char bg
, double alpha
);
252 ChangeLightness() is a utility function that simply darkens
253 or lightens a color, based on the specified percentage
254 ialpha of 0 would be completely black, 200 completely white
255 an ialpha of 100 returns the same colour
258 static void ChangeLightness(unsigned char* r
, unsigned char* g
, unsigned char* b
, int ialpha
);
261 wxColour wrapper for ChangeLightness(r,g,b,ialpha).
264 wxColour
ChangeLightness(int ialpha
) const;
268 /** @name Predefined colors. */
270 wxColour wxNullColour
;
276 wxColour
* wxLIGHT_GREY
;
283 // ============================================================================
284 // Global functions/macros
285 // ============================================================================
287 /** @addtogroup group_funcmacro_misc */
291 Converts string to a wxColour best represented by the given string. Returns
294 @see wxToString(const wxColour&)
298 bool wxFromString(const wxString
& string
, wxColour
* colour
);
301 Converts the given wxColour into a string.
303 @see wxFromString(const wxString&, wxColour*)
307 wxString
wxToString(const wxColour
& colour
);