]>
Commit | Line | Data |
---|---|---|
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 | ||
19 | ||
20 | DocStr(wxColour, | |
21 | "A colour is an object representing a combination of Red, Green, and Blue (RGB) | |
22 | intensity values, and is used to determine drawing colours, window colours, | |
23 | etc. Valid RGB values are in the range 0 to 255. | |
24 | ||
25 | In wxPython there are typemaps that will automatically convert from a colour | |
26 | name, or from a \"#RRGGBB\" colour hex value string to a wx.Colour object when | |
27 | calling C++ methods that expect a wxColour. This means that the following are | |
28 | all equivallent: | |
29 | ||
30 | win.SetBackgroundColour(wxColour(0,0,255)) | |
31 | win.SetBackgroundColour(\"BLUE\") | |
32 | win.SetBackgroundColour(\"#0000FF\") | |
33 | ||
34 | You can retrieve the various current system colour settings with | |
35 | wx.SystemSettings.GetColour."); | |
36 | ||
37 | ||
38 | class wxColour : public wxObject { | |
39 | public: | |
40 | ||
41 | DocCtorStr( | |
42 | wxColour(unsigned char red=0, unsigned char green=0, unsigned char blue=0), | |
43 | "Constructs a colour from red, green and blue values."); | |
44 | ||
45 | DocCtorStrName( | |
46 | wxColour( const wxString& colorName), | |
47 | "Constructs a colour object using a colour name listed in wx.TheColourDatabase.", | |
48 | NamedColour); | |
49 | ||
50 | DocCtorStrName( | |
51 | wxColour( unsigned long colRGB ), | |
52 | "Constructs a colour from a packed RGB value.", | |
53 | ColourRGB); | |
54 | ||
55 | ~wxColour(); | |
56 | ||
57 | ||
58 | DocDeclStr( | |
59 | unsigned char , Red(), | |
60 | "Returns the red intensity."); | |
61 | ||
62 | DocDeclStr( | |
63 | unsigned char , Green(), | |
64 | "Returns the green intensity."); | |
65 | ||
66 | DocDeclStr( | |
67 | unsigned char , Blue(), | |
68 | "Returns the blue intensity."); | |
69 | ||
70 | DocDeclStr( | |
71 | bool , Ok(), | |
72 | "Returns True if the colour object is valid (the colour has been\n" | |
73 | "initialised with RGB values)."); | |
74 | ||
75 | DocDeclStr( | |
76 | void , Set(unsigned char red, unsigned char green, unsigned char blue), | |
77 | "Sets the RGB intensity values."); | |
78 | ||
79 | DocDeclStrName( | |
80 | void , Set(unsigned long colRGB), | |
81 | "Sets the RGB intensity values from a packed RGB value.", | |
82 | SetRGB); | |
83 | ||
84 | DocDeclStrName( | |
85 | void , InitFromName(const wxString& colourName), | |
86 | "Sets the RGB intensity values using a colour name listed in wx.TheColourDatabase.", | |
87 | SetFromName); | |
88 | ||
89 | ||
90 | DocDeclStr( | |
91 | long , GetPixel() const, | |
92 | "Returns a pixel value which is platform-dependent. On Windows, a\n" | |
93 | "COLORREF is returned. On X, an allocated pixel value is returned.\n" | |
94 | "-1 is returned if the pixel is invalid (on X, unallocated)."); | |
95 | ||
96 | ||
97 | DocDeclStr( | |
98 | bool , operator==(const wxColour& colour) const, | |
99 | "Compare colours for equality"); | |
100 | ||
101 | DocDeclStr( | |
102 | bool , operator!=(const wxColour& colour) const, | |
103 | "Compare colours for inequality"); | |
104 | ||
105 | ||
106 | ||
107 | %extend { | |
108 | DocAStr(Get, | |
109 | "Get() -> (r, g, b)", | |
110 | "Returns the RGB intensity values as a tuple."); | |
111 | PyObject* Get() { | |
112 | PyObject* rv = PyTuple_New(3); | |
113 | int red = -1; | |
114 | int green = -1; | |
115 | int blue = -1; | |
116 | if (self->Ok()) { | |
117 | red = self->Red(); | |
118 | green = self->Green(); | |
119 | blue = self->Blue(); | |
120 | } | |
121 | PyTuple_SetItem(rv, 0, PyInt_FromLong(red)); | |
122 | PyTuple_SetItem(rv, 1, PyInt_FromLong(green)); | |
123 | PyTuple_SetItem(rv, 2, PyInt_FromLong(blue)); | |
124 | return rv; | |
125 | } | |
126 | ||
127 | DocStr(GetRGB, | |
128 | "Return the colour as a packed RGB value"); | |
129 | unsigned long GetRGB() { | |
130 | return self->Red() | (self->Green() << 8) | (self->Blue() << 16); | |
131 | } | |
132 | } | |
133 | ||
134 | ||
135 | %pythoncode { | |
136 | asTuple = Get | |
137 | def __str__(self): return str(self.asTuple()) | |
138 | def __repr__(self): return 'wx.Colour' + str(self.asTuple()) | |
139 | def __nonzero__(self): return self.Ok() | |
140 | __safe_for_unpickling__ = True | |
141 | def __reduce__(self): return (Colour, self.Get()) | |
142 | } | |
143 | }; | |
144 | ||
145 | %pythoncode { | |
146 | Color = Colour | |
147 | NamedColor = NamedColour | |
148 | ColorRGB = ColourRGB | |
149 | } | |
150 | ||
151 | //--------------------------------------------------------------------------- | |
152 |