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