]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: colour.h | |
e54c96f1 | 3 | // Purpose: interface of wxColour |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
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 BP |
39 | - ::wxNullColour - An empty, invalid colour. |
40 | - ::wxBLACK | |
41 | - ::wxBLUE | |
42 | - ::wxCYAN | |
43 | - ::wxGREEN | |
86028025 | 44 | - ::wxYELLOW |
968f15e2 BP |
45 | - ::wxLIGHT_GREY |
46 | - ::wxRED | |
47 | - ::wxWHITE | |
7c913512 | 48 | |
e54c96f1 | 49 | @see wxColourDatabase, wxPen, wxBrush, wxColourDialog, wxSystemSettings |
23324ae1 FM |
50 | */ |
51 | class wxColour : public wxObject | |
52 | { | |
53 | public: | |
7fa7088e | 54 | |
23324ae1 | 55 | /** |
7fa7088e BP |
56 | Default constructor. |
57 | */ | |
58 | wxColour(); | |
3c4f71cc | 59 | |
7fa7088e | 60 | /** |
7c913512 | 61 | @param red |
4cc4bfaf | 62 | The red value. |
7c913512 | 63 | @param green |
4cc4bfaf | 64 | The green value. |
7c913512 | 65 | @param blue |
4cc4bfaf | 66 | The blue value. |
7c913512 | 67 | @param alpha |
7fa7088e BP |
68 | The alpha value. Alpha values range from 0 (wxALPHA_TRANSPARENT) to |
69 | 255 (wxALPHA_OPAQUE). | |
70 | */ | |
71 | wxColour(unsigned char red, unsigned char green, unsigned char blue, | |
72 | unsigned char alpha = wxALPHA_OPAQUE); | |
73 | ||
74 | /** | |
7c913512 | 75 | @param colourName |
4cc4bfaf | 76 | The colour name. |
7fa7088e BP |
77 | */ |
78 | wxColour(const wxString& colourName); | |
3c4f71cc | 79 | |
7fa7088e BP |
80 | /** |
81 | Copy constructor. | |
23324ae1 | 82 | */ |
7c913512 | 83 | wxColour(const wxColour& colour); |
23324ae1 FM |
84 | |
85 | /** | |
86 | Returns the alpha value, on platforms where alpha is not yet supported, this | |
87 | always returns wxALPHA_OPAQUE. | |
88 | */ | |
b7e94bd7 | 89 | virtual unsigned char Alpha() const; |
23324ae1 FM |
90 | |
91 | /** | |
92 | Returns the blue intensity. | |
93 | */ | |
b7e94bd7 | 94 | virtual unsigned char Blue() const; |
23324ae1 | 95 | |
23324ae1 | 96 | /** |
7fa7088e BP |
97 | Converts this colour to a wxString using the given flags. |
98 | ||
4707b84c FM |
99 | The supported flags are @c wxC2S_NAME, to obtain the colour name |
100 | (e.g. wxColour(255,0,0) == "red"), @c wxC2S_CSS_SYNTAX, to obtain | |
101 | the colour in the "rgb(r,g,b)" or "rgba(r,g,b,a)" syntax | |
102 | (e.g. wxColour(255,0,0,85) == "rgba(255,0,0,0.333)"), and | |
103 | @c wxC2S_HTML_SYNTAX, to obtain the colour as "#" followed by 6 | |
104 | hexadecimal digits (e.g. wxColour(255,0,0) == "#FF0000"). | |
7fa7088e BP |
105 | |
106 | This function never fails and always returns a non-empty string but | |
107 | asserts if the colour has alpha channel (i.e. is non opaque) but | |
4707b84c | 108 | @c wxC2S_CSS_SYNTAX (which is the only one supporting alpha) is not |
23324ae1 | 109 | specified in flags. |
3c4f71cc | 110 | |
1e24c2af | 111 | @since 2.7.0 |
23324ae1 | 112 | */ |
4707b84c | 113 | virtual wxString GetAsString(long flags = wxC2S_NAME | wxC2S_CSS_SYNTAX) const; |
23324ae1 FM |
114 | |
115 | /** | |
4707b84c FM |
116 | Returns a pixel value which is platform-dependent. |
117 | On Windows, a COLORREF is returned. | |
23324ae1 | 118 | On X, an allocated pixel value is returned. |
4707b84c | 119 | If the pixel is invalid (on X, unallocated), @c -1 is returned. |
23324ae1 | 120 | */ |
4707b84c | 121 | int GetPixel() const; |
23324ae1 FM |
122 | |
123 | /** | |
124 | Returns the green intensity. | |
125 | */ | |
b7e94bd7 | 126 | virtual unsigned char Green() const; |
23324ae1 FM |
127 | |
128 | /** | |
129 | Returns @true if the colour object is valid (the colour has been initialised | |
130 | with RGB values). | |
131 | */ | |
0004982c | 132 | virtual bool IsOk() const; |
23324ae1 FM |
133 | |
134 | /** | |
135 | Returns the red intensity. | |
136 | */ | |
b7e94bd7 | 137 | virtual unsigned char Red() const; |
23324ae1 FM |
138 | |
139 | //@{ | |
140 | /** | |
141 | Sets the RGB intensity values using the given values (first overload), | |
7fa7088e BP |
142 | extracting them from the packed long (second overload), using the given |
143 | string (third overloard). | |
144 | ||
7c913512 | 145 | When using third form, Set() accepts: colour names (those listed in |
7fa7088e BP |
146 | wxTheColourDatabase()), the CSS-like @c "rgb(r,g,b)" or |
147 | @c "rgba(r,g,b,a)" syntax (case insensitive) and the HTML-like syntax | |
148 | (i.e. @c "#" followed by 6 hexadecimal digits for red, green, blue | |
149 | components). | |
150 | ||
23324ae1 | 151 | Returns @true if the conversion was successful, @false otherwise. |
3c4f71cc | 152 | |
1e24c2af | 153 | @since 2.7.0 |
23324ae1 FM |
154 | */ |
155 | void Set(unsigned char red, unsigned char green, | |
156 | unsigned char blue, | |
4cc4bfaf | 157 | unsigned char alpha = wxALPHA_OPAQUE); |
7c913512 | 158 | void Set(unsigned long RGB); |
4cc4bfaf | 159 | bool Set(const wxString& str); |
23324ae1 FM |
160 | //@} |
161 | ||
162 | /** | |
163 | Tests the inequality of two colours by comparing individual red, green, blue | |
164 | colours and alpha values. | |
165 | */ | |
4707b84c | 166 | bool operator !=(const wxColour& colour) const; |
23324ae1 | 167 | |
23324ae1 FM |
168 | /** |
169 | Assignment operator, using a colour name to be found in the colour database. | |
3c4f71cc | 170 | |
4cc4bfaf | 171 | @see wxColourDatabase |
23324ae1 | 172 | */ |
382f12e4 | 173 | wxColour& operator=(const wxColour& colour); |
23324ae1 FM |
174 | |
175 | /** | |
176 | Tests the equality of two colours by comparing individual red, green, blue | |
177 | colours and alpha values. | |
178 | */ | |
4707b84c | 179 | bool operator ==(const wxColour& colour) const; |
23324ae1 | 180 | }; |
e54c96f1 FM |
181 | |
182 | ||
968f15e2 BP |
183 | /** @name Predefined colors. */ |
184 | //@{ | |
e54c96f1 | 185 | wxColour wxNullColour; |
968f15e2 BP |
186 | wxColour* wxBLACK; |
187 | wxColour* wxBLUE; | |
188 | wxColour* wxCYAN; | |
189 | wxColour* wxGREEN; | |
86028025 | 190 | wxColour* wxYELLOW; |
968f15e2 BP |
191 | wxColour* wxLIGHT_GREY; |
192 | wxColour* wxRED; | |
193 | wxColour* wxWHITE; | |
194 | //@} | |
e54c96f1 FM |
195 | |
196 | ||
7fa7088e BP |
197 | |
198 | // ============================================================================ | |
199 | // Global functions/macros | |
200 | // ============================================================================ | |
201 | ||
b21126db | 202 | /** @addtogroup group_funcmacro_misc */ |
7fa7088e BP |
203 | //@{ |
204 | ||
205 | /** | |
206 | Converts string to a wxColour best represented by the given string. Returns | |
207 | @true on success. | |
208 | ||
209 | @see wxToString(const wxColour&) | |
210 | ||
211 | @header{wx/colour.h} | |
212 | */ | |
213 | bool wxFromString(const wxString& string, wxColour* colour); | |
214 | ||
215 | /** | |
216 | Converts the given wxColour into a string. | |
217 | ||
218 | @see wxFromString(const wxString&, wxColour*) | |
219 | ||
220 | @header{wx/colour.h} | |
221 | */ | |
222 | wxString wxToString(const wxColour& colour); | |
223 | ||
224 | //@} | |
225 |