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