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 class wxBitmap : public wxGDIObject
51 wxBitmap(const wxString& name, wxBitmapType type=wxBITMAP_TYPE_ANY),
52 "Loads a bitmap from a file.");
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.",
64 wxBitmap(const wxIcon& icon),
65 "Create a new bitmap from an Icon object.",
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.",
78 DocStr(wxBitmap(PyObject* listOfStrings),
79 "Construct a Bitmap from a list of strings formatted as XPM data.");
80 %name(BitmapFromXPMData) wxBitmap(PyObject* listOfStrings) {
84 cArray = ConvertListOfStrings(listOfStrings);
87 bmp = new wxBitmap(cArray);
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 ) {
100 PyString_AsStringAndSize(bits, &buf, &length);
101 return new wxBitmap(buf, width, height, depth);
107 void SetPalette(wxPalette& palette);
110 // wxGDIImage methods
114 void SetHandle(long handle) { self->SetHandle((WXHANDLE)handle); }
120 DocStr(GetWidth, "Gets the width of the bitmap in pixels.");
123 DocStr(GetHeight, "Gets the height of the bitmap in pixels.");
127 "Gets the colour depth of the bitmap. A value of 1 indicates a\n"
128 "monochrome bitmap.");
131 DocStr(ConvertToImage,
132 "Creates a platform-independent image from a platform-dependent bitmap. This\n"
133 "preserves mask information so that bitmaps and images can be converted back\n"
134 "and forth without loss in that respect.");
135 virtual wxImage ConvertToImage() const;
138 "Gets the associated mask (if any) which may have been loaded from a file\n"
139 "or explpicitly set for the bitmap.");
140 virtual wxMask* GetMask() const;
143 "Sets the mask for this bitmap.");
144 virtual void SetMask(wxMask* mask);
147 DocStr(SetMaskColour,
148 "Create a Mask based on a specified colour in the Bitmap.");
149 void SetMaskColour(const wxColour& colour) {
150 wxMask *mask = new wxMask(*self, colour);
156 "Returns a sub bitmap of the current one as long as the rect belongs entirely\n"
157 "to the bitmap. This function preserves bit depth and mask information.");
158 virtual wxBitmap GetSubBitmap(const wxRect& rect) const;
160 DocStr(SaveFile, "Saves a bitmap in the named file.");
161 virtual bool SaveFile(const wxString &name, wxBitmapType type,
162 wxPalette *palette = (wxPalette *)NULL);
164 DocStr(LoadFile, "Loads a bitmap from a file");
165 virtual bool LoadFile(const wxString &name, wxBitmapType type);
169 virtual wxPalette *GetPalette() const;
170 virtual void SetPalette(const wxPalette& palette);
174 virtual bool CopyFromIcon(const wxIcon& icon);
176 DocStr(SetHeight, "Set the height property (does not affect the bitmap data).")
177 virtual void SetHeight(int height);
179 DocStr(SetWidth, "Set the width property (does not affect the bitmap data).")
180 virtual void SetWidth(int width);
182 DocStr(SetDepth, "Set the depth property (does not affect the bitmap data).")
183 virtual void SetDepth(int depth);
187 bool CopyFromCursor(const wxCursor& cursor);
189 void SetQuality(int q);
192 %pythoncode { def __nonzero__(self): return self.Ok() }
196 //---------------------------------------------------------------------------
199 "This class encapsulates a monochrome mask bitmap, where the masked area is\n"
200 "black and the unmasked area is white. When associated with a bitmap and drawn\n"
201 "in a device context, the unmasked area of the bitmap will be drawn, and the\n"
202 "masked area will not be drawn.");
204 class wxMask : public wxObject {
208 wxMask(const wxBitmap& bitmap),
209 "Constructs a mask from a monochrome bitmap.");
213 "Constructs a mask from a bitmap and a colour in that bitmap that indicates\n"
214 "the transparent portions of the mask, by default BLACK is used.");
217 wxMask(const wxBitmap& bitmap, const wxColour& colour = wxNullColour) {
219 return new wxMask(bitmap, *wxBLACK);
221 return new wxMask(bitmap, colour);
228 %pythoncode { MaskColour = Mask }
230 //---------------------------------------------------------------------------
231 //---------------------------------------------------------------------------