1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface for wxBitmap and wxMask
7 // Created: 7-July-1997
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
21 static char** ConvertListOfStrings(PyObject* listOfStrings) {
25 if (!PyList_Check(listOfStrings)) {
26 PyErr_SetString(PyExc_TypeError, "Expected a list of strings.");
29 count = PyList_Size(listOfStrings);
30 cArray = new char*[count];
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));
41 //---------------------------------------------------------------------------
43 // TODO: When the API stabalizes and is available on other platforms, add
44 // wrappers for the new wxBitmap, wxRawBitmap, wxDIB stuff...
47 "The wx.Bitmap class encapsulates the concept of a platform-dependent
48 bitmap. It can be either monochrome or colour, and either loaded from
49 a file or created dynamically. A bitmap can be selected into a memory
50 device context (instance of `wx.MemoryDC`). This enables the bitmap to
51 be copied to a window or memory device context using `wx.DC.Blit`, or
52 to be used as a drawing surface.", "
54 The BMP and XMP image file formats are supported on all platforms by
55 wx.Bitmap. Other formats are automatically loaded by `wx.Image` and
56 converted to a wx.Bitmap, so any image file format supported by
57 `wx.Image` can be used.
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?
63 :todo: Find a way to do very efficient PIL Image <--> wx.Bitmap
68 MustHaveApp(wxBitmap);
70 class wxBitmap : public wxGDIObject
74 wxBitmap(const wxString& name, wxBitmapType type=wxBITMAP_TYPE_ANY),
75 "Loads a bitmap from a file.",
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
99 :see: Alternate constructors `wx.EmptyBitmap`, `wx.BitmapFromIcon`,
100 `wx.BitmapFromImage`, `wx.BitmapFromXPMData`,
107 wxBitmap(int width, int height, int depth=-1),
108 "Creates a new bitmap of the given size. A depth of -1 indicates the
109 depth of the current screen or visual. Some platforms only support 1
110 for monochrome and -1 for the current display depth.", "",
114 wxBitmap(const wxIcon& icon),
115 "Create a new bitmap from a `wx.Icon` object.", "",
119 wxBitmap(const wxImage& image, int depth=-1),
120 "Creates bitmap object from a `wx.Image`. This has to be done to
121 actually display a `wx.Image` as you cannot draw an image directly on
122 a window. The resulting bitmap will use the provided colour depth (or
123 that of the current screen colour depth if depth is -1) which entails
124 that a colour reduction may have to take place.", "",
129 DocStr(wxBitmap(PyObject* listOfStrings),
130 "Construct a Bitmap from a list of strings formatted as XPM data.", "");
132 %RenameCtor(BitmapFromXPMData, wxBitmap(PyObject* listOfStrings))
134 char** cArray = NULL;
137 cArray = ConvertListOfStrings(listOfStrings);
140 bmp = new wxBitmap(cArray);
145 DocStr(wxBitmap(PyObject* bits, int width, int height, int depth=1 ),
146 "Creates a bitmap from an array of bits. You should only use this
147 function for monochrome bitmaps (depth 1) in portable programs: in
148 this case the bits parameter should contain an XBM image. For other
149 bit depths, the behaviour is platform dependent.", "");
151 %RenameCtor(BitmapFromBits, wxBitmap(PyObject* bits, int width, int height, int depth=1 ))
155 PyString_AsStringAndSize(bits, &buf, &length);
156 return new wxBitmap(buf, width, height, depth);
161 // wxGDIImage methods
165 void SetHandle(long handle) { self->SetHandle((WXHANDLE)handle); }
173 "Gets the width of the bitmap in pixels.", "");
178 "Gets the height of the bitmap in pixels.", "");
183 "Gets the colour depth of the bitmap. A value of 1 indicates a
184 monochrome bitmap.", "");
189 DocStr(GetSize, "Get the size of the bitmap.", "");
191 wxSize size(self->GetWidth(), self->GetHeight());
198 virtual wxImage , ConvertToImage() const,
199 "Creates a platform-independent image from a platform-dependent
200 bitmap. This preserves mask information so that bitmaps and images can
201 be converted back and forth without loss in that respect.", "");
205 virtual wxMask* , GetMask() const,
206 "Gets the associated mask (if any) which may have been loaded from a
207 file or explpicitly set for the bitmap.
209 :see: `SetMask`, `wx.Mask`
212 // MSW only? wxBitmap GetMaskBitmap() const;
215 virtual void , SetMask(wxMask* mask),
216 "Sets the mask for this bitmap.
218 :see: `GetMask`, `wx.Mask`
223 DocStr(SetMaskColour,
224 "Create a Mask based on a specified colour in the Bitmap.", "");
225 void SetMaskColour(const wxColour& colour) {
226 wxMask *mask = new wxMask(*self, colour);
233 virtual wxBitmap , GetSubBitmap(const wxRect& rect) const,
234 "Returns a sub-bitmap of the current one as long as the rect belongs
235 entirely to the bitmap. This function preserves bit depth and mask
240 virtual bool , SaveFile(const wxString &name, wxBitmapType type,
241 wxPalette *palette = NULL),
242 "Saves a bitmap in the named file. See `__init__` for a description of
243 the ``type`` parameter.", "");
247 virtual bool , LoadFile(const wxString &name, wxBitmapType type),
248 "Loads a bitmap from a file. See `__init__` for a description of the
249 ``type`` parameter.", "");
253 virtual wxPalette *GetPalette() const;
255 virtual void SetPalette(const wxPalette& palette);
259 virtual bool CopyFromIcon(const wxIcon& icon);
262 virtual void , SetHeight(int height),
263 "Set the height property (does not affect the existing bitmap data).", "");
267 virtual void , SetWidth(int width),
268 "Set the width property (does not affect the existing bitmap data).", "");
272 virtual void , SetDepth(int depth),
273 "Set the depth property (does not affect the existing bitmap data).", "");
277 DocStr(SetSize, "Set the bitmap size (does not affect the existing bitmap data).", "");
278 void SetSize(const wxSize& size) {
279 self->SetWidth(size.x);
280 self->SetHeight(size.y);
285 bool CopyFromCursor(const wxCursor& cursor);
287 // WXWIN_COMPATIBILITY_2_4
290 void SetQuality(int q);
291 %pythoncode { GetQuality = wx._deprecated(GetQuality) }
292 %pythoncode { SetQuality = wx._deprecated(SetQuality) }
296 %pythoncode { def __nonzero__(self): return self.Ok() }
299 bool __eq__(const wxBitmap* other) { return other ? (*self == *other) : false; }
300 bool __ne__(const wxBitmap* other) { return other ? (*self != *other) : true; }
305 //---------------------------------------------------------------------------
308 "This class encapsulates a monochrome mask bitmap, where the masked
309 area is black and the unmasked area is white. When associated with a
310 bitmap and drawn in a device context, the unmasked area of the bitmap
311 will be drawn, and the masked area will not be drawn.
313 A mask may be associated with a `wx.Bitmap`. It is used in
314 `wx.DC.DrawBitmap` or `wx.DC.Blit` when the source device context is a
315 `wx.MemoryDC` with a `wx.Bitmap` selected into it that contains a
320 class wxMask : public wxObject {
324 "Constructs a mask from a `wx.Bitmap` and a `wx.Colour` in that bitmap
325 that indicates the transparent portions of the mask. In other words,
326 the pixels in ``bitmap`` that match ``colour`` will be the transparent
327 portions of the mask. If no ``colour`` or an invalid ``colour`` is
328 passed then BLACK is used.
330 :see: `wx.Bitmap`, `wx.Colour`", "");
333 wxMask(const wxBitmap& bitmap, const wxColour& colour = wxNullColour) {
335 return new wxMask(bitmap, *wxBLACK);
337 return new wxMask(bitmap, colour);
344 %pythoncode { MaskColour = wx._deprecated(Mask, "wx.MaskColour is deprecated, use `wx.Mask` instead.") }
346 //---------------------------------------------------------------------------
347 //---------------------------------------------------------------------------