]>
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 | ||
1e0c8722 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); | |
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 | } | |
103 | } | |
104 | ||
105 | ||
106 | #ifdef __WXMSW__ | |
107 | void SetPalette(wxPalette& palette); | |
108 | #endif | |
109 | ||
110 | // wxGDIImage methods | |
111 | #ifdef __WXMSW__ | |
112 | long GetHandle(); | |
113 | void SetHandle(long handle); | |
114 | #endif | |
115 | ||
116 | bool Ok(); | |
117 | ||
1e0c8722 | 118 | DocStr(GetWidth, "Gets the width of the bitmap in pixels."); |
d14a1e28 | 119 | int GetWidth(); |
1e0c8722 RD |
120 | |
121 | DocStr(GetHeight, "Gets the height of the bitmap in pixels."); | |
d14a1e28 | 122 | int GetHeight(); |
1e0c8722 RD |
123 | |
124 | DocStr(GetDepth, | |
125 | "Gets the colour depth of the bitmap. A value of 1 indicates a\n" | |
126 | "monochrome bitmap."); | |
d14a1e28 RD |
127 | int GetDepth(); |
128 | ||
1e0c8722 RD |
129 | DocStr(ConvertToImage, |
130 | "Creates a platform-independent image from a platform-dependent bitmap. This\n" | |
131 | "preserves mask information so that bitmaps and images can be converted back\n" | |
132 | "and forth without loss in that respect."); | |
d14a1e28 RD |
133 | virtual wxImage ConvertToImage() const; |
134 | ||
1e0c8722 RD |
135 | DocStr(GetMask, |
136 | "Gets the associated mask (if any) which may have been loaded from a file\n" | |
137 | "or explpicitly set for the bitmap."); | |
d14a1e28 | 138 | virtual wxMask* GetMask() const; |
1e0c8722 RD |
139 | |
140 | DocStr(SetMask, | |
141 | "Sets the mask for this bitmap."); | |
d14a1e28 | 142 | virtual void SetMask(wxMask* mask); |
1e0c8722 | 143 | |
d14a1e28 | 144 | %extend { |
1e0c8722 RD |
145 | DocStr(SetMaskColour, |
146 | "Create a Mask based on a specified colour in the Bitmap."); | |
d14a1e28 RD |
147 | void SetMaskColour(const wxColour& colour) { |
148 | wxMask *mask = new wxMask(*self, colour); | |
149 | self->SetMask(mask); | |
150 | } | |
151 | } | |
d14a1e28 | 152 | |
1e0c8722 RD |
153 | DocStr(GetSubBitmap, |
154 | "Returns a sub bitmap of the current one as long as the rect belongs entirely\n" | |
155 | "to the bitmap. This function preserves bit depth and mask information."); | |
d14a1e28 RD |
156 | virtual wxBitmap GetSubBitmap(const wxRect& rect) const; |
157 | ||
1e0c8722 | 158 | DocStr(SaveFile, "Saves a bitmap in the named file."); |
d14a1e28 RD |
159 | virtual bool SaveFile(const wxString &name, wxBitmapType type, |
160 | wxPalette *palette = (wxPalette *)NULL); | |
1e0c8722 RD |
161 | |
162 | DocStr(LoadFile, "Loads a bitmap from a file"); | |
d14a1e28 RD |
163 | virtual bool LoadFile(const wxString &name, wxBitmapType type); |
164 | ||
165 | ||
166 | #if wxUSE_PALETTE | |
167 | virtual wxPalette *GetPalette() const; | |
168 | virtual void SetPalette(const wxPalette& palette); | |
169 | #endif | |
170 | ||
d14a1e28 | 171 | |
1e0c8722 RD |
172 | virtual bool CopyFromIcon(const wxIcon& icon); |
173 | ||
174 | DocStr(SetHeight, "Set the height property (does not affect the bitmap data).") | |
d14a1e28 | 175 | virtual void SetHeight(int height); |
1e0c8722 RD |
176 | |
177 | DocStr(SetWidth, "Set the width property (does not affect the bitmap data).") | |
d14a1e28 | 178 | virtual void SetWidth(int width); |
1e0c8722 RD |
179 | |
180 | DocStr(SetDepth, "Set the depth property (does not affect the bitmap data).") | |
d14a1e28 RD |
181 | virtual void SetDepth(int depth); |
182 | ||
1e0c8722 | 183 | |
d14a1e28 RD |
184 | #ifdef __WXMSW__ |
185 | bool CopyFromCursor(const wxCursor& cursor); | |
186 | int GetQuality(); | |
187 | void SetQuality(int q); | |
188 | #endif | |
189 | ||
190 | %pythoncode { def __nonzero__(self): return self.Ok() } | |
191 | }; | |
192 | ||
193 | ||
194 | //--------------------------------------------------------------------------- | |
195 | ||
1e0c8722 RD |
196 | DocStr(wxMask, |
197 | "This class encapsulates a monochrome mask bitmap, where the masked area is\n" | |
198 | "black and the unmasked area is white. When associated with a bitmap and drawn\n" | |
199 | "in a device context, the unmasked area of the bitmap will be drawn, and the\n" | |
200 | "masked area will not be drawn."); | |
201 | ||
d14a1e28 RD |
202 | class wxMask : public wxObject { |
203 | public: | |
1e0c8722 RD |
204 | DocCtorStr( |
205 | wxMask(const wxBitmap& bitmap), | |
206 | "Constructs a mask from a monochrome bitmap."); | |
207 | ||
208 | DocCtorStrName( | |
209 | wxMask(const wxBitmap& bitmap, const wxColour& colour), | |
210 | "Constructs a mask from a bitmap and a colour in that bitmap that indicates the\n" | |
211 | "background.", | |
212 | MaskColour); | |
d14a1e28 RD |
213 | |
214 | //~wxMask(); | |
215 | ||
216 | }; | |
217 | ||
218 | //--------------------------------------------------------------------------- | |
219 | //--------------------------------------------------------------------------- |