]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_bitmap.i
Fixed typo
[wxWidgets.git] / wxPython / src / _bitmap.i
CommitLineData
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
dce2bd22
RD
46DocStr(wxBitmap,
47"The wx.Bitmap class encapsulates the concept of a platform-dependent
48bitmap. It can be either monochrome or colour, and either loaded from
49a file or created dynamically. A bitmap can be selected into a memory
50device context (instance of `wx.MemoryDC`). This enables the bitmap to
51be copied to a window or memory device context using `wx.DC.Blit`, or
d07d2bc9 52to be used as a drawing surface.", "
dce2bd22
RD
53
54The BMP and XMP image file formats are supported on all platforms by
55wx.Bitmap. Other formats are automatically loaded by `wx.Image` and
56converted to a wx.Bitmap, so any image file format supported by
57`wx.Image` can be used.
58
59:todo: Add wrappers and support for raw bitmap data access. Can this
60 be be put into Python without losing the speed benefits of the
61 teplates and iterators in rawbmp.h?
62
63:todo: Find a way to do very efficient PIL Image <--> wx.Bitmap
64 converstions.
65");
66
d14a1e28
RD
67
68class wxBitmap : public wxGDIObject
69{
70public:
1e0c8722
RD
71 DocCtorStr(
72 wxBitmap(const wxString& name, wxBitmapType type=wxBITMAP_TYPE_ANY),
d07d2bc9
RD
73 "Loads a bitmap from a file.",
74 "
75 :param name: Name of the file to load the bitmap from.
76 :param type: The type of image to expect. Can be one of the following
77 constants (assuming that the neccessary `wx.Image` handlers are
78 loaded):
dce2bd22
RD
79
80 * wx.BITMAP_TYPE_ANY
81 * wx.BITMAP_TYPE_BMP
82 * wx.BITMAP_TYPE_ICO
83 * wx.BITMAP_TYPE_CUR
84 * wx.BITMAP_TYPE_XBM
85 * wx.BITMAP_TYPE_XPM
86 * wx.BITMAP_TYPE_TIF
87 * wx.BITMAP_TYPE_GIF
88 * wx.BITMAP_TYPE_PNG
89 * wx.BITMAP_TYPE_JPEG
90 * wx.BITMAP_TYPE_PNM
91 * wx.BITMAP_TYPE_PCX
92 * wx.BITMAP_TYPE_PICT
93 * wx.BITMAP_TYPE_ICON
94 * wx.BITMAP_TYPE_ANI
95 * wx.BITMAP_TYPE_IFF
96
97:see: Alternate constructors `wx.EmptyBitmap`, `wx.BitmapFromIcon`,
98 `wx.BitmapFromImage`, `wx.BitmapFromXPMData`,
99 `wx.BitmapFromBits`
100");
1e0c8722 101
d14a1e28
RD
102 ~wxBitmap();
103
dce2bd22
RD
104 DocCtorStrName(
105 wxBitmap(int width, int height, int depth=-1),
106 "Creates a new bitmap of the given size. A depth of -1 indicates the
107depth of the current screen or visual. Some platforms only support 1
d07d2bc9 108for monochrome and -1 for the current colour setting.", "",
dce2bd22 109 EmptyBitmap);
1e0c8722
RD
110
111 DocCtorStrName(
112 wxBitmap(const wxIcon& icon),
d07d2bc9 113 "Create a new bitmap from a `wx.Icon` object.", "",
1e0c8722
RD
114 BitmapFromIcon);
115
116 DocCtorStrName(
117 wxBitmap(const wxImage& image, int depth=-1),
dce2bd22
RD
118 "Creates bitmap object from a `wx.Image`. This has to be done to
119actually display a `wx.Image` as you cannot draw an image directly on
120a window. The resulting bitmap will use the provided colour depth (or
121that of the current screen colour depth if depth is -1) which entails
d07d2bc9 122that a colour reduction may have to take place.", "",
1e0c8722
RD
123 BitmapFromImage);
124
125
d14a1e28 126 %extend {
1e0c8722 127 DocStr(wxBitmap(PyObject* listOfStrings),
d07d2bc9 128 "Construct a Bitmap from a list of strings formatted as XPM data.", "");
d14a1e28
RD
129 %name(BitmapFromXPMData) wxBitmap(PyObject* listOfStrings) {
130 char** cArray = NULL;
131 wxBitmap* bmp;
132
133 cArray = ConvertListOfStrings(listOfStrings);
134 if (! cArray)
135 return NULL;
136 bmp = new wxBitmap(cArray);
137 delete [] cArray;
138 return bmp;
139 }
140
1e0c8722 141 DocStr(wxBitmap(PyObject* bits, int width, int height, int depth=1 ),
dce2bd22
RD
142 "Creates a bitmap from an array of bits. You should only use this
143function for monochrome bitmaps (depth 1) in portable programs: in
144this case the bits parameter should contain an XBM image. For other
d07d2bc9 145bit depths, the behaviour is platform dependent.", "");
1e0c8722 146 %name(BitmapFromBits) wxBitmap(PyObject* bits, int width, int height, int depth=1 ) {
d14a1e28
RD
147 char* buf;
148 int length;
149 PyString_AsStringAndSize(bits, &buf, &length);
150 return new wxBitmap(buf, width, height, depth);
151 }
152 }
153
154
155#ifdef __WXMSW__
156 void SetPalette(wxPalette& palette);
157#endif
158
159 // wxGDIImage methods
160#ifdef __WXMSW__
161 long GetHandle();
a0c956e8
RD
162 %extend {
163 void SetHandle(long handle) { self->SetHandle((WXHANDLE)handle); }
164 }
d14a1e28
RD
165#endif
166
167 bool Ok();
168
dce2bd22
RD
169 DocDeclStr(
170 int , GetWidth(),
d07d2bc9 171 "Gets the width of the bitmap in pixels.", "");
dce2bd22 172
1e0c8722 173
dce2bd22
RD
174 DocDeclStr(
175 int , GetHeight(),
d07d2bc9 176 "Gets the height of the bitmap in pixels.", "");
dce2bd22 177
1e0c8722 178
dce2bd22
RD
179 DocDeclStr(
180 int , GetDepth(),
181 "Gets the colour depth of the bitmap. A value of 1 indicates a
d07d2bc9 182monochrome bitmap.", "");
dce2bd22 183
d14a1e28 184
ba938c3d
RD
185
186 %extend {
d07d2bc9 187 DocStr(GetSize, "Get the size of the bitmap.", "");
ba938c3d
RD
188 wxSize GetSize() {
189 wxSize size(self->GetWidth(), self->GetHeight());
190 return size;
191 }
192 }
193
194
dce2bd22
RD
195 DocDeclStr(
196 virtual wxImage , ConvertToImage() const,
197 "Creates a platform-independent image from a platform-dependent
198bitmap. This preserves mask information so that bitmaps and images can
d07d2bc9 199be converted back and forth without loss in that respect.", "");
dce2bd22
RD
200
201
202 DocDeclStr(
203 virtual wxMask* , GetMask() const,
204 "Gets the associated mask (if any) which may have been loaded from a
205file or explpicitly set for the bitmap.
206
207:see: `SetMask`, `wx.Mask`
d07d2bc9 208", "");
dce2bd22
RD
209
210
211 DocDeclStr(
212 virtual void , SetMask(wxMask* mask),
213 "Sets the mask for this bitmap.
214
215:see: `GetMask`, `wx.Mask`
d07d2bc9 216", "");
dce2bd22 217
1e0c8722 218
d14a1e28 219 %extend {
1e0c8722 220 DocStr(SetMaskColour,
d07d2bc9 221 "Create a Mask based on a specified colour in the Bitmap.", "");
d14a1e28
RD
222 void SetMaskColour(const wxColour& colour) {
223 wxMask *mask = new wxMask(*self, colour);
224 self->SetMask(mask);
225 }
226 }
d14a1e28 227
d14a1e28 228
dce2bd22
RD
229 DocDeclStr(
230 virtual wxBitmap , GetSubBitmap(const wxRect& rect) const,
231 "Returns a sub-bitmap of the current one as long as the rect belongs
232entirely to the bitmap. This function preserves bit depth and mask
d07d2bc9 233information.", "");
dce2bd22
RD
234
235
236 DocDeclStr(
237 virtual bool , SaveFile(const wxString &name, wxBitmapType type,
238 wxPalette *palette = NULL),
239 "Saves a bitmap in the named file. See `__init__` for a description of
d07d2bc9 240the ``type`` parameter.", "");
dce2bd22 241
1e0c8722 242
dce2bd22
RD
243 DocDeclStr(
244 virtual bool , LoadFile(const wxString &name, wxBitmapType type),
245 "Loads a bitmap from a file. See `__init__` for a description of the
d07d2bc9 246``type`` parameter.", "");
dce2bd22 247
d14a1e28
RD
248
249
250#if wxUSE_PALETTE
251 virtual wxPalette *GetPalette() const;
252 virtual void SetPalette(const wxPalette& palette);
253#endif
254
d14a1e28 255
1e0c8722
RD
256 virtual bool CopyFromIcon(const wxIcon& icon);
257
dce2bd22
RD
258 DocDeclStr(
259 virtual void , SetHeight(int height),
d07d2bc9 260 "Set the height property (does not affect the existing bitmap data).", "");
dce2bd22
RD
261
262
263 DocDeclStr(
264 virtual void , SetWidth(int width),
d07d2bc9 265 "Set the width property (does not affect the existing bitmap data).", "");
1e0c8722 266
1e0c8722 267
dce2bd22
RD
268 DocDeclStr(
269 virtual void , SetDepth(int depth),
d07d2bc9 270 "Set the depth property (does not affect the existing bitmap data).", "");
dce2bd22 271
d14a1e28 272
ba938c3d 273 %extend {
d07d2bc9 274 DocStr(SetSize, "Set the bitmap size (does not affect the existing bitmap data).", "");
ba938c3d
RD
275 void SetSize(const wxSize& size) {
276 self->SetWidth(size.x);
277 self->SetHeight(size.y);
278 }
279 }
1e0c8722 280
d14a1e28
RD
281#ifdef __WXMSW__
282 bool CopyFromCursor(const wxCursor& cursor);
283 int GetQuality();
284 void SetQuality(int q);
285#endif
286
287 %pythoncode { def __nonzero__(self): return self.Ok() }
b403cd65
RD
288
289 %extend {
290 bool __eq__(const wxBitmap* other) { return other ? (*self == *other) : False; }
291 bool __ne__(const wxBitmap* other) { return other ? (*self != *other) : True; }
292 }
d14a1e28
RD
293};
294
295
296//---------------------------------------------------------------------------
297
1e0c8722 298DocStr(wxMask,
dce2bd22
RD
299"This class encapsulates a monochrome mask bitmap, where the masked
300area is black and the unmasked area is white. When associated with a
301bitmap and drawn in a device context, the unmasked area of the bitmap
302will be drawn, and the masked area will not be drawn.
303
304A mask may be associated with a `wx.Bitmap`. It is used in
305`wx.DC.DrawBitmap` or `wx.DC.Blit` when the source device context is a
306`wx.MemoryDC` with a `wx.Bitmap` selected into it that contains a
d07d2bc9 307mask.", "");
1e0c8722 308
d14a1e28
RD
309class wxMask : public wxObject {
310public:
1e0c8722 311
0482c494 312 DocStr(wxMask,
dce2bd22
RD
313 "Constructs a mask from a `wx.Bitmap` and a `wx.Colour` in that bitmap
314that indicates the transparent portions of the mask. In other words,
315the pixels in ``bitmap`` that match ``colour`` will be the transparent
316portions of the mask. If no ``colour`` or an invalid ``colour`` is
317passed then BLACK is used.
318
d07d2bc9 319:see: `wx.Bitmap`, `wx.Colour`", "");
0482c494
RD
320
321 %extend {
322 wxMask(const wxBitmap& bitmap, const wxColour& colour = wxNullColour) {
323 if ( !colour.Ok() )
324 return new wxMask(bitmap, *wxBLACK);
325 else
326 return new wxMask(bitmap, colour);
327 }
328 }
d14a1e28
RD
329
330 //~wxMask();
d14a1e28
RD
331};
332
dce2bd22 333%pythoncode { MaskColour = wx._deprecated(Mask, "wx.MaskColour is deprecated, use `wx.Mask` instead.") }
0482c494 334
d14a1e28
RD
335//---------------------------------------------------------------------------
336//---------------------------------------------------------------------------