]>
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.
48 @see wxColourDatabase, wxPen, wxBrush, wxColourDialog, wxSystemSettings
50 class wxColour
: public wxObject
67 The alpha value. Alpha values range from 0 (wxALPHA_TRANSPARENT) to
70 wxColour(unsigned char red
, unsigned char green
, unsigned char blue
,
71 unsigned char alpha
= wxALPHA_OPAQUE
);
77 wxColour(const wxString
& colourName
);
82 wxColour(const wxColour
& colour
);
85 Returns the alpha value, on platforms where alpha is not yet supported, this
86 always returns wxALPHA_OPAQUE.
88 virtual unsigned char Alpha() const;
91 Returns the blue intensity.
93 virtual unsigned char Blue() const;
96 Converts this colour to a wxString using the given flags.
98 The supported flags are @c wxC2S_NAME, to obtain the colour name
99 (e.g. wxColour(255,0,0) == "red"), @c wxC2S_CSS_SYNTAX, to obtain
100 the colour in the "rgb(r,g,b)" or "rgba(r,g,b,a)" syntax
101 (e.g. wxColour(255,0,0,85) == "rgba(255,0,0,0.333)"), and
102 @c wxC2S_HTML_SYNTAX, to obtain the colour as "#" followed by 6
103 hexadecimal digits (e.g. wxColour(255,0,0) == "#FF0000").
105 This function never fails and always returns a non-empty string but
106 asserts if the colour has alpha channel (i.e. is non opaque) but
107 @c wxC2S_CSS_SYNTAX (which is the only one supporting alpha) is not
112 virtual wxString
GetAsString(long flags
= wxC2S_NAME
| wxC2S_CSS_SYNTAX
) const;
115 Returns a pixel value which is platform-dependent.
116 On Windows, a COLORREF is returned.
117 On X, an allocated pixel value is returned.
118 If the pixel is invalid (on X, unallocated), @c -1 is returned.
120 int GetPixel() const;
123 Returns the green intensity.
125 virtual unsigned char Green() const;
128 Returns @true if the colour object is valid (the colour has been initialised
131 virtual bool IsOk() const;
134 Returns the red intensity.
136 virtual unsigned char Red() const;
140 Sets the RGB intensity values using the given values (first overload),
141 extracting them from the packed long (second overload), using the given
142 string (third overloard).
144 When using third form, Set() accepts: colour names (those listed in
145 wxTheColourDatabase()), the CSS-like @c "rgb(r,g,b)" or
146 @c "rgba(r,g,b,a)" syntax (case insensitive) and the HTML-like syntax
147 (i.e. @c "#" followed by 6 hexadecimal digits for red, green, blue
150 Returns @true if the conversion was successful, @false otherwise.
154 void Set(unsigned char red
, unsigned char green
,
156 unsigned char alpha
= wxALPHA_OPAQUE
);
157 void Set(unsigned long RGB
);
158 bool Set(const wxString
& str
);
162 Tests the inequality of two colours by comparing individual red, green, blue
163 colours and alpha values.
165 bool operator !=(const wxColour
& colour
) const;
169 Assignment operator, using a colour name to be found in the colour database.
171 @see wxColourDatabase
173 wxColour
operator =(const wxColour
& colour
);
174 wxColour
operator =(const wxString
& colourName
);
178 Tests the equality of two colours by comparing individual red, green, blue
179 colours and alpha values.
181 bool operator ==(const wxColour
& colour
) const;
185 /** @name Predefined colors. */
187 wxColour wxNullColour
;
192 wxColour
* wxLIGHT_GREY
;
199 // ============================================================================
200 // Global functions/macros
201 // ============================================================================
203 /** @addtogroup group_funcmacro_misc */
207 Converts string to a wxColour best represented by the given string. Returns
210 @see wxToString(const wxColour&)
214 bool wxFromString(const wxString
& string
, wxColour
* colour
);
217 Converts the given wxColour into a string.
219 @see wxFromString(const wxString&, wxColour*)
223 wxString
wxToString(const wxColour
& colour
);