]>
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 A colour is an object representing a combination of Red, Green, and Blue
13 (RGB) intensity values, and is used to determine drawing colours. See the
14 entry for wxColourDatabase for how a pointer to a predefined, named colour
15 may be returned instead of creating a new colour.
17 Valid RGB values are in the range 0 to 255.
19 You can retrieve the current system colour settings with wxSystemSettings.
25 - ::wxNullColour - An empty, invalid colour.
34 @see wxColourDatabase, wxPen, wxBrush, wxColourDialog, wxSystemSettings
36 class wxColour
: public wxObject
53 The alpha value. Alpha values range from 0 (wxALPHA_TRANSPARENT) to
56 wxColour(unsigned char red
, unsigned char green
, unsigned char blue
,
57 unsigned char alpha
= wxALPHA_OPAQUE
);
63 wxColour(const wxString
& colourName
);
68 wxColour(const wxColour
& colour
);
71 Returns the alpha value, on platforms where alpha is not yet supported, this
72 always returns wxALPHA_OPAQUE.
74 unsigned char Alpha() const;
77 Returns the blue intensity.
79 unsigned char Blue() const;
82 Converts this colour to a wxString using the given flags.
84 The supported flags are wxC2S_NAME, to obtain the colour name (e.g.
85 wxColour(255,0,0) == "red"), wxC2S_CSS_SYNTAX, to obtain the colour in
86 the "rgb(r,g,b)" or "rgba(r,g,b,a)" syntax (e.g.
87 wxColour(255,0,0,85) == "rgba(255,0,0,0.333)"), and wxC2S_HTML_SYNTAX,
88 to obtain the colour as "#" followed by 6 hexadecimal digits (e.g.
89 wxColour(255,0,0) == "#FF0000").
91 This function never fails and always returns a non-empty string but
92 asserts if the colour has alpha channel (i.e. is non opaque) but
93 wxC2S_CSS_SYNTAX (which is the only one supporting alpha) is not
98 wxString
GetAsString(long flags
);
101 Returns a pixel value which is platform-dependent. On Windows, a COLORREF is
103 On X, an allocated pixel value is returned.
104 -1 is returned if the pixel is invalid (on X, unallocated).
106 long GetPixel() const;
109 Returns the green intensity.
111 unsigned char Green() const;
114 Returns @true if the colour object is valid (the colour has been initialised
120 Returns the red intensity.
122 unsigned char Red() const;
126 Sets the RGB intensity values using the given values (first overload),
127 extracting them from the packed long (second overload), using the given
128 string (third overloard).
130 When using third form, Set() accepts: colour names (those listed in
131 wxTheColourDatabase()), the CSS-like @c "rgb(r,g,b)" or
132 @c "rgba(r,g,b,a)" syntax (case insensitive) and the HTML-like syntax
133 (i.e. @c "#" followed by 6 hexadecimal digits for red, green, blue
136 Returns @true if the conversion was successful, @false otherwise.
140 void Set(unsigned char red
, unsigned char green
,
142 unsigned char alpha
= wxALPHA_OPAQUE
);
143 void Set(unsigned long RGB
);
144 bool Set(const wxString
& str
);
148 Tests the inequality of two colours by comparing individual red, green, blue
149 colours and alpha values.
151 bool operator !=(const wxColour
& colour
);
155 Assignment operator, using a colour name to be found in the colour database.
157 @see wxColourDatabase
159 wxColour
operator =(const wxColour
& colour
);
160 wxColour
operator =(const wxString
& colourName
);
164 Tests the equality of two colours by comparing individual red, green, blue
165 colours and alpha values.
167 bool operator ==(const wxColour
& colour
);
171 /** @name Predefined colors. */
173 wxColour wxNullColour
;
178 wxColour
* wxLIGHT_GREY
;
185 // ============================================================================
186 // Global functions/macros
187 // ============================================================================
189 /** @ingroup group_funcmacro_misc */
193 Converts string to a wxColour best represented by the given string. Returns
196 @see wxToString(const wxColour&)
200 bool wxFromString(const wxString
& string
, wxColour
* colour
);
203 Converts the given wxColour into a string.
205 @see wxFromString(const wxString&, wxColour*)
209 wxString
wxToString(const wxColour
& colour
);