]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: _colour.i | |
3 | // Purpose: SWIG interface for wxColour | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 7-July-1997 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2003 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | // Not a %module | |
14 | ||
15 | ||
16 | //--------------------------------------------------------------------------- | |
17 | %newgroup; | |
18 | ||
d14a1e28 | 19 | |
6ad421ae | 20 | DocStr(wxColour, |
d07d2bc9 RD |
21 | "A colour is an object representing a combination of Red, Green, and |
22 | Blue (RGB) intensity values, and is used to determine drawing colours, | |
23 | window colours, etc. Valid RGB values are in the range 0 to 255. | |
6ad421ae | 24 | |
d07d2bc9 RD |
25 | In wxPython there are typemaps that will automatically convert from a |
26 | colour name, or from a '#RRGGBB' colour hex value string to a | |
27 | wx.Colour object when calling C++ methods that expect a wxColour. | |
28 | This means that the following are all equivallent:: | |
6ad421ae RD |
29 | |
30 | win.SetBackgroundColour(wxColour(0,0,255)) | |
2b619822 RD |
31 | win.SetBackgroundColour('BLUE') |
32 | win.SetBackgroundColour('#0000FF') | |
6ad421ae | 33 | |
d07d2bc9 RD |
34 | Additional colour names and their coresponding values can be added |
35 | using `wx.ColourDatabase`. Various system colours (as set in the | |
36 | user's system preferences) can be retrieved with | |
37 | `wx.SystemSettings.GetColour`. | |
38 | ", ""); | |
6ad421ae RD |
39 | |
40 | ||
d14a1e28 RD |
41 | class wxColour : public wxObject { |
42 | public: | |
6ad421ae RD |
43 | |
44 | DocCtorStr( | |
d07d2bc9 RD |
45 | wxColour(byte red=0, byte green=0, byte blue=0), |
46 | "Constructs a colour from red, green and blue values. | |
47 | ||
48 | :see: Alternate constructors `wx.NamedColour` and `wx.ColourRGB`. | |
49 | ", ""); | |
6ad421ae RD |
50 | |
51 | DocCtorStrName( | |
52 | wxColour( const wxString& colorName), | |
d07d2bc9 RD |
53 | "Constructs a colour object using a colour name listed in |
54 | ``wx.TheColourDatabase``.", "", | |
6ad421ae RD |
55 | NamedColour); |
56 | ||
57 | DocCtorStrName( | |
58 | wxColour( unsigned long colRGB ), | |
d07d2bc9 | 59 | "Constructs a colour from a packed RGB value.", "", |
6ad421ae RD |
60 | ColourRGB); |
61 | ||
d14a1e28 RD |
62 | ~wxColour(); |
63 | ||
6ad421ae RD |
64 | |
65 | DocDeclStr( | |
d07d2bc9 RD |
66 | byte , Red(), |
67 | "Returns the red intensity.", ""); | |
6ad421ae RD |
68 | |
69 | DocDeclStr( | |
d07d2bc9 RD |
70 | byte , Green(), |
71 | "Returns the green intensity.", ""); | |
6ad421ae RD |
72 | |
73 | DocDeclStr( | |
d07d2bc9 RD |
74 | byte , Blue(), |
75 | "Returns the blue intensity.", ""); | |
6ad421ae RD |
76 | |
77 | DocDeclStr( | |
78 | bool , Ok(), | |
d07d2bc9 RD |
79 | "Returns True if the colour object is valid (the colour has been |
80 | initialised with RGB values).", ""); | |
6ad421ae RD |
81 | |
82 | DocDeclStr( | |
d07d2bc9 RD |
83 | void , Set(byte red, byte green, byte blue), |
84 | "Sets the RGB intensity values.", ""); | |
d14a1e28 | 85 | |
6ad421ae RD |
86 | DocDeclStrName( |
87 | void , Set(unsigned long colRGB), | |
d07d2bc9 | 88 | "Sets the RGB intensity values from a packed RGB value.", "", |
6ad421ae | 89 | SetRGB); |
d14a1e28 | 90 | |
6ad421ae RD |
91 | DocDeclStrName( |
92 | void , InitFromName(const wxString& colourName), | |
d07d2bc9 RD |
93 | "Sets the RGB intensity values using a colour name listed in |
94 | ``wx.TheColourDatabase``.", "", | |
6ad421ae RD |
95 | SetFromName); |
96 | ||
97 | ||
98 | DocDeclStr( | |
99 | long , GetPixel() const, | |
d07d2bc9 RD |
100 | "Returns a pixel value which is platform-dependent. On Windows, a |
101 | COLORREF is returned. On X, an allocated pixel value is returned. -1 | |
102 | is returned if the pixel is invalid (on X, unallocated).", ""); | |
6ad421ae RD |
103 | |
104 | ||
105 | DocDeclStr( | |
106 | bool , operator==(const wxColour& colour) const, | |
d07d2bc9 | 107 | "Compare colours for equality", ""); |
6ad421ae RD |
108 | |
109 | DocDeclStr( | |
110 | bool , operator!=(const wxColour& colour) const, | |
d07d2bc9 | 111 | "Compare colours for inequality", ""); |
6ad421ae | 112 | |
d14a1e28 | 113 | |
3f0ff538 | 114 | |
d14a1e28 | 115 | %extend { |
6ad421ae RD |
116 | DocAStr(Get, |
117 | "Get() -> (r, g, b)", | |
d07d2bc9 | 118 | "Returns the RGB intensity values as a tuple.", ""); |
d14a1e28 RD |
119 | PyObject* Get() { |
120 | PyObject* rv = PyTuple_New(3); | |
121 | int red = -1; | |
122 | int green = -1; | |
123 | int blue = -1; | |
124 | if (self->Ok()) { | |
125 | red = self->Red(); | |
126 | green = self->Green(); | |
127 | blue = self->Blue(); | |
128 | } | |
129 | PyTuple_SetItem(rv, 0, PyInt_FromLong(red)); | |
130 | PyTuple_SetItem(rv, 1, PyInt_FromLong(green)); | |
131 | PyTuple_SetItem(rv, 2, PyInt_FromLong(blue)); | |
132 | return rv; | |
133 | } | |
6ad421ae RD |
134 | |
135 | DocStr(GetRGB, | |
d07d2bc9 | 136 | "Return the colour as a packed RGB value", ""); |
6ad421ae RD |
137 | unsigned long GetRGB() { |
138 | return self->Red() | (self->Green() << 8) | (self->Blue() << 16); | |
139 | } | |
d14a1e28 RD |
140 | } |
141 | ||
142 | ||
143 | %pythoncode { | |
d07d2bc9 RD |
144 | asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead") |
145 | def __str__(self): return str(self.Get()) | |
146 | def __repr__(self): return 'wx.Colour' + str(self.Get()) | |
d14a1e28 | 147 | def __nonzero__(self): return self.Ok() |
02376d73 RD |
148 | __safe_for_unpickling__ = True |
149 | def __reduce__(self): return (Colour, self.Get()) | |
d14a1e28 RD |
150 | } |
151 | }; | |
152 | ||
2b9048c5 RD |
153 | %pythoncode { |
154 | Color = Colour | |
155 | NamedColor = NamedColour | |
156 | ColorRGB = ColourRGB | |
157 | } | |
cf763f5b | 158 | |
d14a1e28 RD |
159 | //--------------------------------------------------------------------------- |
160 |