1
/////////////////////////////////////////////////////////////////////////////
3
// Purpose: SWIG interface for wxColour
7
// Created: 7-July-1997
8
// RCS-ID: $Id: _colour.i 69040 2011-09-10 01:00:23Z RD $
9
// Copyright: (c) 2003 by Total Control Software
10
// Licence: wxWindows license
11
/////////////////////////////////////////////////////////////////////////////
18
#include <wx/osx/private.h>
22
//---------------------------------------------------------------------------
27
wxC2S_NAME, // return colour name, when possible
28
wxC2S_CSS_SYNTAX, // return colour in rgb(r,g,b) syntax
29
wxC2S_HTML_SYNTAX, // return colour in #rrggbb syntax
39
"A colour is an object representing a combination of Red, Green, and
40
Blue (RGB) intensity values, and is used to determine drawing colours,
41
window colours, etc. Valid RGB values are in the range 0 to 255.
43
In wxPython there are typemaps that will automatically convert from a
44
colour name, from a '#RRGGBB' colour hex value string, or from a 3 or 4
45
integer tuple to a wx.Colour object when calling C++ methods that
46
expect a wxColour. This means that the following are all
49
win.SetBackgroundColour(wxColour(0,0,255))
50
win.SetBackgroundColour('BLUE')
51
win.SetBackgroundColour('#0000FF')
52
win.SetBackgroundColour((0,0,255))
54
In addition to the RGB values, the alpha transparency can optionally
55
be set. This is supported by the typemaps as well as the wx.Colour
56
constructors and setters. (The alpha value is ignored in many places
57
that take a wx.Colour object, but it is honored in things like wx.GCDC
58
or wx.GraphicsContext.) Adding an alpha value of 0xC0 (192) to the
59
above samples looks like this:
61
win.SetBackgroundColour(wxColour(0,0,255,192))
62
win.SetBackgroundColour('BLUE:C0')
63
win.SetBackgroundColour('#0000FFC0')
64
win.SetBackgroundColour((0,0,255,192))
66
Additional colour names and their coresponding values can be added
67
using `wx.ColourDatabase`. Also see `wx.lib.colourdb` for a large set
68
of colour names and values. Various system colours (as set in the
69
user's system preferences or control panel) can be retrieved with
70
`wx.SystemSettings.GetColour`.
74
MustHaveApp( wxColour(const wxString& colorName) );
76
class wxColour : public wxObject {
80
wxColour(byte red=0, byte green=0, byte blue=0, byte alpha=wxALPHA_OPAQUE),
81
"Constructs a colour from red, green, blue and alpha values.
83
:see: Alternate constructors `wx.NamedColour`, `wx.ColourRGB` and `MacThemeColour`.
88
"NamedColour(String colourName) -> Colour",
89
"Constructs a colour object using a colour name listed in
90
``wx.TheColourDatabase``, or any string format supported by the
91
wxColour typemaps.", "",
92
// NOTE: We say String in the docstring but use wxColour for
93
// real so the typemap will be applied.
94
wxColour( const wxColour& colourName ));
99
"Constructs a colour from a packed RGB value.", "",
100
wxColour( unsigned long colRGB ));
105
"Creates a color (or pattern) from a Mac theme brush ID. Raises a
106
NotImplemented exception on other platforms.", "",
107
wxColour( int themeBrushID ))
110
return new wxColour(wxMacCreateCGColorFromHITheme(themeBrushID));
112
wxPyRaiseNotImplemented(); return NULL;
122
"Returns the red intensity.", "");
126
"Returns the green intensity.", "");
130
"Returns the blue intensity.", "");
134
"Returns the Alpha value.", "");
138
"Returns True if the colour object is valid (the colour has been
139
initialised with RGB values).", "");
140
%pythoncode { Ok = IsOk }
143
void , Set(byte red, byte green, byte blue, byte alpha=wxALPHA_OPAQUE),
144
"Sets the RGB intensity values.", "");
147
def SetFromString(self, colourName):
149
Sets the RGB intensity values using a colour name listed in
150
``wx.TheColourDatabase``, or any string format supported by
151
the wxColour typemaps.
153
c = wx.NamedColour(colourName)
154
self.Set(c.red, c.green, c.blue, c.alpha)
155
SetFromName = SetFromString
158
// TODO: This needs to be updated to include alpha in the html
159
// syntax to match our typemaps
161
wxString , GetAsString(long flags = wxC2S_NAME | wxC2S_CSS_SYNTAX) const,
162
"Return the colour as a string. Acceptable flags are:
164
=================== ==================================
165
wx.C2S_NAME return colour name, when possible
166
wx.C2S_CSS_SYNTAX return colour in rgb(r,g,b) syntax
167
wx.C2S_HTML_SYNTAX return colour in #rrggbb syntax
168
=================== ==================================", "");
172
void , SetRGB(wxUint32 colRGB),
173
"Sets the RGB colour values from a single 32 bit value.
175
The argument colRGB should be of the form 0x00BBGGRR and where 0xRR,
176
0xGG and 0xBB are the values of the red, green and blue components.", "");
179
void , SetRGBA(wxUint32 colRGBA),
180
"Sets the RGBA colour values from a single 32 bit value.
182
The argument colRGBA should be of the form 0xAABBGGRR where 0xRR,
183
0xGG, 0xBB and 0xAA are the values of the red, green, blue and alpha
187
wxUint32 , GetRGB() const,
191
wxUint32 , GetRGBA() const,
196
// TODO: deal with these...
198
// static void MakeMono (byte* r, byte* g, byte* b, bool on);
199
// static void MakeDisabled(byte* r, byte* g, byte* b, byte brightness = 255);
200
// static void MakeGrey (byte* r, byte* g, byte* b); // integer version
201
// static void MakeGrey (byte* r, byte* g, byte* b,
202
// double weight_r, double weight_g, double weight_b); // floating point version
203
// static byte AlphaBlend (byte fg, byte bg, double alpha);
204
// static void ChangeLightness(byte* r, byte* g, byte* b, int ialpha);
205
// wxColour ChangeLightness(int ialpha) const;
209
long , GetPixel() const,
210
"Returns a pixel value which is platform-dependent. On Windows, a
211
COLORREF is returned. On X, an allocated pixel value is returned. -1
212
is returned if the pixel is invalid (on X, unallocated).", "");
217
DocStr(__eq__, "Compare colours for equality.", "");
218
bool __eq__(PyObject* other) {
219
wxColour temp, *obj = &temp;
220
if ( other == Py_None ) return false;
221
if ( ! wxColour_helper(other, &obj) ) {
225
return self->operator==(*obj);
230
DocStr(__ne__, "Compare colours for inequality.", "");
231
bool __ne__(PyObject* other) {
232
wxColour temp, *obj = &temp;
233
if ( other == Py_None ) return true;
234
if ( ! wxColour_helper(other, &obj)) {
238
return self->operator!=(*obj);
246
"Get(self, bool includeAlpha=False) -> (r,g,b) or (r,g,b,a)",
247
"Returns the RGB intensity values as a tuple, optionally the alpha value as well.", "");
248
PyObject* Get(bool includeAlpha=false) {
249
PyObject* rv = PyTuple_New(includeAlpha ? 4 : 3);
253
int alpha = wxALPHA_OPAQUE;
256
green = self->Green();
258
alpha = self->Alpha();
260
PyTuple_SetItem(rv, 0, PyInt_FromLong(red));
261
PyTuple_SetItem(rv, 1, PyInt_FromLong(green));
262
PyTuple_SetItem(rv, 2, PyInt_FromLong(blue));
264
PyTuple_SetItem(rv, 3, PyInt_FromLong(alpha));
270
"Return the colour as a packed RGB value", "");
271
unsigned long GetRGB() {
272
return self->Red() | (self->Green() << 8) | (self->Blue() << 16);
278
asTuple = wx.deprecated(Get, "asTuple is deprecated, use `Get` instead")
279
def __str__(self): return str(self.Get(True))
281
%# help() can access the stock colors before they are created,
282
%# so make sure there is a this attribute before calling any wrapper method.
284
if hasattr(self, 'this'):
285
return 'wx.Colour' + str(self.Get(True))
289
def __len__(self): return len(self.Get())
290
def __getitem__(self, index): return self.Get()[index]
291
def __nonzero__(self): return self.IsOk()
292
__safe_for_unpickling__ = True
293
def __reduce__(self): return (Colour, self.Get(True))
296
%property(Pixel, GetPixel, doc="See `GetPixel`");
297
%property(RGB, GetRGB, SetRGB, doc="See `GetRGB` and `SetRGB`");
299
%property(green, Green);
300
%property(blue, Blue);
301
%property(alpha, Alpha);
304
//---------------------------------------------------------------------------