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