]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: _bitmap.i | |
3 | // Purpose: SWIG interface for wxBitmap and wxMask | |
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 | ||
18 | %{ | |
19 | #include <wx/image.h> | |
20 | ||
21 | static char** ConvertListOfStrings(PyObject* listOfStrings) { | |
22 | char** cArray = NULL; | |
23 | int count; | |
24 | ||
25 | if (!PyList_Check(listOfStrings)) { | |
26 | PyErr_SetString(PyExc_TypeError, "Expected a list of strings."); | |
27 | return NULL; | |
28 | } | |
29 | count = PyList_Size(listOfStrings); | |
30 | cArray = new char*[count]; | |
31 | ||
32 | for(int x=0; x<count; x++) { | |
33 | // TODO: Need some validation and error checking here | |
34 | cArray[x] = PyString_AsString(PyList_GET_ITEM(listOfStrings, x)); | |
35 | } | |
36 | return cArray; | |
37 | } | |
38 | ||
39 | %} | |
40 | ||
41 | //--------------------------------------------------------------------------- | |
42 | ||
43 | // TODO: When the API stabalizes and is available on other platforms, add | |
44 | // wrappers for the new wxBitmap, wxRawBitmap, wxDIB stuff... | |
45 | ||
46 | ||
47 | class wxBitmap : public wxGDIObject | |
48 | { | |
49 | public: | |
1e0c8722 RD |
50 | DocCtorStr( |
51 | wxBitmap(const wxString& name, wxBitmapType type=wxBITMAP_TYPE_ANY), | |
52 | "Loads a bitmap from a file."); | |
53 | ||
d14a1e28 RD |
54 | ~wxBitmap(); |
55 | ||
ba938c3d RD |
56 | // DocCtorStrName( |
57 | // wxBitmap(int width, int height, int depth=-1), | |
58 | // "Creates a new bitmap of the given size. A depth of -1 indicates the depth of\n" | |
59 | // "the current screen or visual. Some platforms only support 1 for monochrome and\n" | |
60 | // "-1 for the current colour setting.", | |
61 | // EmptyBitmap); | |
1e0c8722 RD |
62 | |
63 | DocCtorStrName( | |
64 | wxBitmap(const wxIcon& icon), | |
65 | "Create a new bitmap from an Icon object.", | |
66 | BitmapFromIcon); | |
67 | ||
68 | DocCtorStrName( | |
69 | wxBitmap(const wxImage& image, int depth=-1), | |
70 | "Creates bitmap object from the image. This has to be done to actually display\n" | |
71 | "an image as you cannot draw an image directly on a window. The resulting\n" | |
72 | "bitmap will use the provided colour depth (or that of the current system if\n" | |
73 | "depth is -1) which entails that a colour reduction has to take place.", | |
74 | BitmapFromImage); | |
75 | ||
76 | ||
d14a1e28 | 77 | %extend { |
1e0c8722 RD |
78 | DocStr(wxBitmap(PyObject* listOfStrings), |
79 | "Construct a Bitmap from a list of strings formatted as XPM data."); | |
d14a1e28 RD |
80 | %name(BitmapFromXPMData) wxBitmap(PyObject* listOfStrings) { |
81 | char** cArray = NULL; | |
82 | wxBitmap* bmp; | |
83 | ||
84 | cArray = ConvertListOfStrings(listOfStrings); | |
85 | if (! cArray) | |
86 | return NULL; | |
87 | bmp = new wxBitmap(cArray); | |
88 | delete [] cArray; | |
89 | return bmp; | |
90 | } | |
91 | ||
1e0c8722 RD |
92 | DocStr(wxBitmap(PyObject* bits, int width, int height, int depth=1 ), |
93 | "Creates a bitmap from an array of bits. You should only use this function for\n" | |
94 | "monochrome bitmaps (depth 1) in portable programs: in this case the bits\n" | |
95 | "parameter should contain an XBM image. For other bit depths, the behaviour is\n" | |
96 | "platform dependent."); | |
97 | %name(BitmapFromBits) wxBitmap(PyObject* bits, int width, int height, int depth=1 ) { | |
d14a1e28 RD |
98 | char* buf; |
99 | int length; | |
100 | PyString_AsStringAndSize(bits, &buf, &length); | |
101 | return new wxBitmap(buf, width, height, depth); | |
102 | } | |
ba938c3d RD |
103 | |
104 | ||
105 | DocStr(wxBitmap(const wxSize& size, int depth=-1), | |
106 | "Creates a new bitmap of the given size. A depth of -1 indicates | |
107 | the depth of the current screen or visual. Some platforms only | |
108 | support 1 for monochrome and -1 for the current colour setting."); | |
109 | ||
110 | %nokwargs wxBitmap(int width, int height, int depth=-1); | |
111 | %nokwargs wxBitmap(const wxSize& size, int depth=-1); | |
112 | %name(EmptyBitmap)wxBitmap(int width, int height, int depth=-1) { | |
113 | return new wxBitmap(width, height, depth); | |
114 | } | |
115 | %name(EmptyBitmap)wxBitmap(const wxSize& size, int depth=-1) { | |
116 | return new wxBitmap(size.x, size.y, depth); | |
117 | } | |
d14a1e28 RD |
118 | } |
119 | ||
120 | ||
121 | #ifdef __WXMSW__ | |
122 | void SetPalette(wxPalette& palette); | |
123 | #endif | |
124 | ||
125 | // wxGDIImage methods | |
126 | #ifdef __WXMSW__ | |
127 | long GetHandle(); | |
a0c956e8 RD |
128 | %extend { |
129 | void SetHandle(long handle) { self->SetHandle((WXHANDLE)handle); } | |
130 | } | |
d14a1e28 RD |
131 | #endif |
132 | ||
133 | bool Ok(); | |
134 | ||
1e0c8722 | 135 | DocStr(GetWidth, "Gets the width of the bitmap in pixels."); |
d14a1e28 | 136 | int GetWidth(); |
1e0c8722 RD |
137 | |
138 | DocStr(GetHeight, "Gets the height of the bitmap in pixels."); | |
d14a1e28 | 139 | int GetHeight(); |
1e0c8722 RD |
140 | |
141 | DocStr(GetDepth, | |
142 | "Gets the colour depth of the bitmap. A value of 1 indicates a\n" | |
143 | "monochrome bitmap."); | |
d14a1e28 RD |
144 | int GetDepth(); |
145 | ||
ba938c3d RD |
146 | |
147 | %extend { | |
148 | DocStr(GetSize, "Get the size of the bitmap."); | |
149 | wxSize GetSize() { | |
150 | wxSize size(self->GetWidth(), self->GetHeight()); | |
151 | return size; | |
152 | } | |
153 | } | |
154 | ||
155 | ||
1e0c8722 RD |
156 | DocStr(ConvertToImage, |
157 | "Creates a platform-independent image from a platform-dependent bitmap. This\n" | |
158 | "preserves mask information so that bitmaps and images can be converted back\n" | |
159 | "and forth without loss in that respect."); | |
d14a1e28 RD |
160 | virtual wxImage ConvertToImage() const; |
161 | ||
1e0c8722 RD |
162 | DocStr(GetMask, |
163 | "Gets the associated mask (if any) which may have been loaded from a file\n" | |
164 | "or explpicitly set for the bitmap."); | |
d14a1e28 | 165 | virtual wxMask* GetMask() const; |
1e0c8722 RD |
166 | |
167 | DocStr(SetMask, | |
168 | "Sets the mask for this bitmap."); | |
d14a1e28 | 169 | virtual void SetMask(wxMask* mask); |
1e0c8722 | 170 | |
d14a1e28 | 171 | %extend { |
1e0c8722 RD |
172 | DocStr(SetMaskColour, |
173 | "Create a Mask based on a specified colour in the Bitmap."); | |
d14a1e28 RD |
174 | void SetMaskColour(const wxColour& colour) { |
175 | wxMask *mask = new wxMask(*self, colour); | |
176 | self->SetMask(mask); | |
177 | } | |
178 | } | |
d14a1e28 | 179 | |
1e0c8722 RD |
180 | DocStr(GetSubBitmap, |
181 | "Returns a sub bitmap of the current one as long as the rect belongs entirely\n" | |
182 | "to the bitmap. This function preserves bit depth and mask information."); | |
d14a1e28 RD |
183 | virtual wxBitmap GetSubBitmap(const wxRect& rect) const; |
184 | ||
1e0c8722 | 185 | DocStr(SaveFile, "Saves a bitmap in the named file."); |
d14a1e28 RD |
186 | virtual bool SaveFile(const wxString &name, wxBitmapType type, |
187 | wxPalette *palette = (wxPalette *)NULL); | |
1e0c8722 RD |
188 | |
189 | DocStr(LoadFile, "Loads a bitmap from a file"); | |
d14a1e28 RD |
190 | virtual bool LoadFile(const wxString &name, wxBitmapType type); |
191 | ||
192 | ||
193 | #if wxUSE_PALETTE | |
194 | virtual wxPalette *GetPalette() const; | |
195 | virtual void SetPalette(const wxPalette& palette); | |
196 | #endif | |
197 | ||
d14a1e28 | 198 | |
1e0c8722 RD |
199 | virtual bool CopyFromIcon(const wxIcon& icon); |
200 | ||
201 | DocStr(SetHeight, "Set the height property (does not affect the bitmap data).") | |
d14a1e28 | 202 | virtual void SetHeight(int height); |
1e0c8722 RD |
203 | |
204 | DocStr(SetWidth, "Set the width property (does not affect the bitmap data).") | |
d14a1e28 | 205 | virtual void SetWidth(int width); |
1e0c8722 RD |
206 | |
207 | DocStr(SetDepth, "Set the depth property (does not affect the bitmap data).") | |
d14a1e28 RD |
208 | virtual void SetDepth(int depth); |
209 | ||
ba938c3d RD |
210 | %extend { |
211 | DocStr(SetSize, "Set the bitmap size"); | |
212 | void SetSize(const wxSize& size) { | |
213 | self->SetWidth(size.x); | |
214 | self->SetHeight(size.y); | |
215 | } | |
216 | } | |
1e0c8722 | 217 | |
d14a1e28 RD |
218 | #ifdef __WXMSW__ |
219 | bool CopyFromCursor(const wxCursor& cursor); | |
220 | int GetQuality(); | |
221 | void SetQuality(int q); | |
222 | #endif | |
223 | ||
224 | %pythoncode { def __nonzero__(self): return self.Ok() } | |
b403cd65 RD |
225 | |
226 | %extend { | |
227 | bool __eq__(const wxBitmap* other) { return other ? (*self == *other) : False; } | |
228 | bool __ne__(const wxBitmap* other) { return other ? (*self != *other) : True; } | |
229 | } | |
d14a1e28 RD |
230 | }; |
231 | ||
232 | ||
233 | //--------------------------------------------------------------------------- | |
234 | ||
1e0c8722 RD |
235 | DocStr(wxMask, |
236 | "This class encapsulates a monochrome mask bitmap, where the masked area is\n" | |
237 | "black and the unmasked area is white. When associated with a bitmap and drawn\n" | |
238 | "in a device context, the unmasked area of the bitmap will be drawn, and the\n" | |
239 | "masked area will not be drawn."); | |
240 | ||
d14a1e28 RD |
241 | class wxMask : public wxObject { |
242 | public: | |
0482c494 | 243 | #if 0 |
1e0c8722 RD |
244 | DocCtorStr( |
245 | wxMask(const wxBitmap& bitmap), | |
246 | "Constructs a mask from a monochrome bitmap."); | |
0482c494 | 247 | #endif |
1e0c8722 | 248 | |
0482c494 RD |
249 | DocStr(wxMask, |
250 | "Constructs a mask from a bitmap and a colour in that bitmap that indicates\n" | |
251 | "the transparent portions of the mask, by default BLACK is used."); | |
252 | ||
253 | %extend { | |
254 | wxMask(const wxBitmap& bitmap, const wxColour& colour = wxNullColour) { | |
255 | if ( !colour.Ok() ) | |
256 | return new wxMask(bitmap, *wxBLACK); | |
257 | else | |
258 | return new wxMask(bitmap, colour); | |
259 | } | |
260 | } | |
d14a1e28 RD |
261 | |
262 | //~wxMask(); | |
d14a1e28 RD |
263 | }; |
264 | ||
0482c494 RD |
265 | %pythoncode { MaskColour = Mask } |
266 | ||
d14a1e28 RD |
267 | //--------------------------------------------------------------------------- |
268 | //--------------------------------------------------------------------------- |