]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/colour.h
document Connect(host, port) overload
[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
9/**
10 @class wxColour
7c913512 11
7fa7088e
BP
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.
7c913512 16
23324ae1 17 Valid RGB values are in the range 0 to 255.
7c913512 18
23324ae1 19 You can retrieve the current system colour settings with wxSystemSettings.
7c913512 20
23324ae1
FM
21 @library{wxcore}
22 @category{gdi}
7c913512 23
23324ae1 24 @stdobjects
968f15e2
BP
25 - ::wxNullColour - An empty, invalid colour.
26 - ::wxBLACK
27 - ::wxBLUE
28 - ::wxCYAN
29 - ::wxGREEN
30 - ::wxLIGHT_GREY
31 - ::wxRED
32 - ::wxWHITE
7c913512 33
e54c96f1 34 @see wxColourDatabase, wxPen, wxBrush, wxColourDialog, wxSystemSettings
23324ae1
FM
35*/
36class wxColour : public wxObject
37{
38public:
7fa7088e 39
23324ae1 40 /**
7fa7088e
BP
41 Default constructor.
42 */
43 wxColour();
3c4f71cc 44
7fa7088e 45 /**
7c913512 46 @param red
4cc4bfaf 47 The red value.
7c913512 48 @param green
4cc4bfaf 49 The green value.
7c913512 50 @param blue
4cc4bfaf 51 The blue value.
7c913512 52 @param alpha
7fa7088e
BP
53 The alpha value. Alpha values range from 0 (wxALPHA_TRANSPARENT) to
54 255 (wxALPHA_OPAQUE).
55 */
56 wxColour(unsigned char red, unsigned char green, unsigned char blue,
57 unsigned char alpha = wxALPHA_OPAQUE);
58
59 /**
7c913512 60 @param colourName
4cc4bfaf 61 The colour name.
7fa7088e
BP
62 */
63 wxColour(const wxString& colourName);
3c4f71cc 64
7fa7088e
BP
65 /**
66 Copy constructor.
23324ae1 67 */
7c913512 68 wxColour(const wxColour& colour);
23324ae1
FM
69
70 /**
71 Returns the alpha value, on platforms where alpha is not yet supported, this
72 always returns wxALPHA_OPAQUE.
73 */
b7e94bd7 74 virtual unsigned char Alpha() const;
23324ae1
FM
75
76 /**
77 Returns the blue intensity.
78 */
b7e94bd7 79 virtual unsigned char Blue() const;
23324ae1 80
23324ae1 81 /**
7fa7088e
BP
82 Converts this colour to a wxString using the given flags.
83
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").
90
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
23324ae1 94 specified in flags.
3c4f71cc 95
1e24c2af 96 @since 2.7.0
23324ae1
FM
97 */
98 wxString GetAsString(long flags);
23324ae1
FM
99
100 /**
101 Returns a pixel value which is platform-dependent. On Windows, a COLORREF is
102 returned.
103 On X, an allocated pixel value is returned.
23324ae1
FM
104 -1 is returned if the pixel is invalid (on X, unallocated).
105 */
328f5751 106 long GetPixel() const;
23324ae1
FM
107
108 /**
109 Returns the green intensity.
110 */
b7e94bd7 111 virtual unsigned char Green() const;
23324ae1
FM
112
113 /**
114 Returns @true if the colour object is valid (the colour has been initialised
115 with RGB values).
116 */
328f5751 117 bool IsOk() const;
23324ae1
FM
118
119 /**
120 Returns the red intensity.
121 */
b7e94bd7 122 virtual unsigned char Red() const;
23324ae1
FM
123
124 //@{
125 /**
126 Sets the RGB intensity values using the given values (first overload),
7fa7088e
BP
127 extracting them from the packed long (second overload), using the given
128 string (third overloard).
129
7c913512 130 When using third form, Set() accepts: colour names (those listed in
7fa7088e
BP
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
134 components).
135
23324ae1 136 Returns @true if the conversion was successful, @false otherwise.
3c4f71cc 137
1e24c2af 138 @since 2.7.0
23324ae1
FM
139 */
140 void Set(unsigned char red, unsigned char green,
141 unsigned char blue,
4cc4bfaf 142 unsigned char alpha = wxALPHA_OPAQUE);
7c913512 143 void Set(unsigned long RGB);
4cc4bfaf 144 bool Set(const wxString& str);
23324ae1
FM
145 //@}
146
147 /**
148 Tests the inequality of two colours by comparing individual red, green, blue
149 colours and alpha values.
150 */
151 bool operator !=(const wxColour& colour);
152
153 //@{
154 /**
155 Assignment operator, using a colour name to be found in the colour database.
3c4f71cc 156
4cc4bfaf 157 @see wxColourDatabase
23324ae1
FM
158 */
159 wxColour operator =(const wxColour& colour);
7c913512 160 wxColour operator =(const wxString& colourName);
23324ae1
FM
161 //@}
162
163 /**
164 Tests the equality of two colours by comparing individual red, green, blue
165 colours and alpha values.
166 */
167 bool operator ==(const wxColour& colour);
168};
e54c96f1
FM
169
170
968f15e2
BP
171/** @name Predefined colors. */
172//@{
e54c96f1 173wxColour wxNullColour;
968f15e2
BP
174wxColour* wxBLACK;
175wxColour* wxBLUE;
176wxColour* wxCYAN;
177wxColour* wxGREEN;
178wxColour* wxLIGHT_GREY;
179wxColour* wxRED;
180wxColour* wxWHITE;
181//@}
e54c96f1
FM
182
183
7fa7088e
BP
184
185// ============================================================================
186// Global functions/macros
187// ============================================================================
188
189/** @ingroup group_funcmacro_misc */
190//@{
191
192/**
193 Converts string to a wxColour best represented by the given string. Returns
194 @true on success.
195
196 @see wxToString(const wxColour&)
197
198 @header{wx/colour.h}
199*/
200bool wxFromString(const wxString& string, wxColour* colour);
201
202/**
203 Converts the given wxColour into a string.
204
205 @see wxFromString(const wxString&, wxColour*)
206
207 @header{wx/colour.h}
208*/
209wxString wxToString(const wxColour& colour);
210
211//@}
212