]>
git.saurik.com Git - wxWidgets.git/blob - interface/bitmap.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxBitmap* classes
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxBitmapHandler
13 This is the base class for implementing bitmap file loading/saving, and
14 bitmap creation from data.
15 It is used within wxBitmap and is not normally seen by the application.
17 If you wish to extend the capabilities of wxBitmap, derive a class from
18 wxBitmapHandler and add the handler using wxBitmap::AddHandler in your
19 application initialisation.
24 @see @ref overview_bitmap, wxBitmap, wxIcon, wxCursor
26 class wxBitmapHandler
: public wxObject
32 In your own default constructor, initialise the members m_name,
33 m_extension and m_type.
38 Destroys the wxBitmapHandler object.
43 Creates a bitmap from the given data, which can be of arbitrary type.
44 The wxBitmap object @a bitmap is manipulated by this function.
49 The width of the bitmap in pixels.
51 The height of the bitmap in pixels.
53 The depth of the bitmap in pixels. If this is -1, the screen depth is used.
55 Data whose type depends on the value of type.
57 A bitmap type identifier - see ::wxBitmapType for a list
60 @todo why type is an int and not a wxBitmapType?
62 @returns @true if the call succeeded, @false otherwise (the default).
64 virtual bool Create(wxBitmap
* bitmap
, const void* data
, int type
,
65 int width
, int height
, int depth
= -1);
68 Gets the file extension associated with this handler.
70 const wxString
GetExtension() const;
73 Gets the name of this handler.
75 const wxString
GetName() const;
78 Gets the bitmap type associated with this handler.
79 @todo why type is an int and not a wxBitmapType?
84 Loads a bitmap from a file or resource, putting the resulting data into
88 The bitmap object which is to be affected by this operation.
90 Either a filename or a Windows resource name.
91 The meaning of name is determined by the type parameter.
93 See wxBitmap::wxBitmap for values this can take.
95 @returns @true if the operation succeeded, @false otherwise.
97 @todo why type is an int and not a wxBitmapType?
99 @see wxBitmap::LoadFile, wxBitmap::SaveFile, SaveFile()
101 bool LoadFile(wxBitmap
* bitmap
, const wxString
& name
, long type
);
104 Saves a bitmap in the named file.
107 The bitmap object which is to be affected by this operation.
109 A filename. The meaning of name is determined by the type parameter.
111 See wxBitmap::wxBitmap for values this can take.
113 An optional palette used for saving the bitmap.
115 @returns @true if the operation succeeded, @false otherwise.
117 @todo why type is an int and not a wxBitmapType?
119 @see wxBitmap::LoadFile, wxBitmap::SaveFile, LoadFile()
121 bool SaveFile(wxBitmap
* bitmap
, const wxString
& name
, int type
,
122 wxPalette
* palette
= NULL
);
125 Sets the handler extension.
130 void SetExtension(const wxString
& extension
);
133 Sets the handler name.
138 void SetName(const wxString
& name
);
141 Sets the handler type.
143 @todo why type is an int and not a wxBitmapType?
148 void SetType(long type
);
156 This class encapsulates the concept of a platform-dependent bitmap,
157 either monochrome or colour or colour with alpha channel support.
160 Many wxBitmap functions take a @e type parameter, which is a value of
161 the ::wxBitmapType enumeration.
162 The validity of those values depends however on the platform where your program
163 is running and from the wxWidgets configuration.
164 If all possible wxWidgets settings are used, the Windows platform supports BMP file,
165 BMP resource, XPM data, and XPM.
166 Under wxGTK, the available formats are BMP file, XPM data, XPM file, and PNG file.
167 Under wxMotif, the available formats are XBM data, XBM file, XPM data, XPM file.
168 In addition, wxBitmap can load and save all formats that wxImage; see wxImage for
169 more info. Of course, you must have wxImage handlers loaded.
177 @see @ref overview_bitmap, @ref overview_bitmap_supportedformats,
178 wxDC::Blit, wxIcon, wxCursor, wxBitmap, wxMemoryDC
180 class wxBitmap
: public wxGDIObject
186 Constructs a bitmap object with no data; an assignment or another member
187 function such as Create() or LoadFile() must be called subsequently.
192 Copy constructor, uses @ref overview_refcount "reference counting".
193 To make a real copy, you can use:
196 wxBitmap newBitmap = oldBitmap.GetSubBitmap(
197 wxRect(0, 0, oldBitmap.GetWidth(), oldBitmap.GetHeight()));
200 wxBitmap(const wxBitmap
& bitmap
);
203 Creates a bitmap from the given @a data which is interpreted in
204 platform-dependent manner.
207 Specifies the bitmap data in a platform-dependent format.
209 May be one of the ::wxBitmapType values and indicates which type of
210 bitmap does @a data contains. See the note in the class
211 detailed description.
213 Specifies the width of the bitmap.
215 Specifies the height of the bitmap.
217 Specifies the depth of the bitmap.
218 If this is omitted, the display depth of the screen is used.
220 @todo why type is an int and not a wxBitmapType?
223 wxBitmap(const void* data
, int type
, int width
, int height
, int depth
= -1);
226 Creates a bitmap from the given array @a bits.
227 You should only use this function for monochrome bitmaps (depth 1) in
228 portable programs: in this case the bits parameter should contain an XBM image.
230 For other bit depths, the behaviour is platform dependent: under Windows,
231 the data is passed without any changes to the underlying CreateBitmap() API.
232 Under other platforms, only monochrome bitmaps may be created using this constructor
233 and wxImage should be used for creating colour bitmaps from static data.
236 Specifies an array of pixel values.
238 Specifies the width of the bitmap.
240 Specifies the height of the bitmap.
242 Specifies the depth of the bitmap.
243 If this is omitted, the display depth of the screen is used.
245 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
248 Creates a new bitmap. A depth of -1 indicates the depth of the current
249 screen or visual. Some platforms only support 1 for monochrome and -1 for
250 the current colour setting.
252 A depth of 32 including an alpha channel is supported under MSW, Mac and GTK+.
254 wxBitmap(int width
, int height
, int depth
= -1);
257 Creates a bitmap from XPM data.
259 wxBitmap(const char* const* bits
);
262 Loads a bitmap from a file or resource.
265 This can refer to a resource name or a filename under MS Windows and X.
266 Its meaning is determined by the @a type parameter.
268 May be one of the ::wxBitmapType values and indicates which type of
269 bitmap should be loaded. See the note in the class detailed description.
273 wxBitmap(const wxString
& name
, long type
);
276 Creates bitmap object from the image. This has to be done to actually
277 display an image as you cannot draw an image directly on a window.
279 The resulting bitmap will use the provided colour depth (or that of the
280 current system if depth is -1) which entails that a colour reduction has
283 When in 8-bit mode (PseudoColour mode), the GTK port will use a color cube
284 created on program start-up to look up colors. This ensures a very fast conversion,
285 but the image quality won't be perfect (and could be better for photo images using
286 more sophisticated dithering algorithms).
288 On Windows, if there is a palette present (set with SetPalette), it will be
289 used when creating the wxBitmap (most useful in 8-bit display mode).
290 On other platforms, the palette is currently ignored.
293 Platform-independent wxImage object.
295 Specifies the depth of the bitmap.
296 If this is omitted, the display depth of the screen is used.
298 wxBitmap(const wxImage
& img
, int depth
= -1);
303 See @ref overview_refcount_destruct for more info.
305 If the application omits to delete the bitmap explicitly, the bitmap will be
306 destroyed automatically by wxWidgets when the application exits.
309 Do not delete a bitmap that is selected into a memory device context.
314 Adds a handler to the end of the static list of format handlers.
317 A new bitmap format handler object. There is usually only one instance
318 of a given handler class in an application session.
322 static void AddHandler(wxBitmapHandler
* handler
);
325 Deletes all bitmap handlers.
326 This function is called by wxWidgets on exit.
328 static void CleanUpHandlers();
331 Creates an image from a platform-dependent bitmap. This preserves
332 mask information so that bitmaps and images can be converted back
333 and forth without loss in that respect.
335 wxImage
ConvertToImage();
338 Creates the bitmap from an icon.
340 bool CopyFromIcon(const wxIcon
& icon
);
344 Creates a fresh bitmap.
345 If the final argument is omitted, the display depth of the screen is used.
347 This overload works on all platforms.
349 virtual bool Create(int width
, int height
, int depth
= -1);
352 Creates a bitmap from the given data, which can be of arbitrary type.
355 Data whose type depends on the value of type.
357 A bitmap type identifier; see ::wxBitmapType for the list of values.
358 See the note in the class detailed description for more info.
360 The width of the bitmap in pixels.
362 The height of the bitmap in pixels.
364 The depth of the bitmap in pixels. If this is -1, the screen depth is used.
366 @returns @true if the call succeeded, @false otherwise.
368 This overload depends on the @a type of data.
371 virtual bool Create(const void* data
, int type
, int width
,
372 int height
, int depth
= -1);
375 Finds the handler with the given @a name.
377 @returns A pointer to the handler if found, @NULL otherwise.
379 static wxBitmapHandler
* FindHandler(const wxString
& name
);
382 Finds the handler associated with the given @a extension and @a type.
385 The file extension, such as "bmp" (without the dot).
387 The bitmap type managed by the handler, see ::wxBitmapType.
389 @returns A pointer to the handler if found, @NULL otherwise.
391 static wxBitmapHandler
* FindHandler(const wxString
& extension
,
392 wxBitmapType bitmapType
);
395 Finds the handler associated with the given bitmap type.
398 The bitmap type managed by the handler, see ::wxBitmapType.
400 @returns A pointer to the handler if found, @NULL otherwise.
405 static wxBitmapHandler
* FindHandler(wxBitmapType bitmapType
);
408 Gets the colour depth of the bitmap. A value of 1 indicates a
411 int GetDepth() const;
414 Returns the static list of bitmap format handlers.
418 static wxList
GetHandlers();
421 Gets the height of the bitmap in pixels.
423 int GetHeight() const;
426 Gets the associated mask (if any) which may have been loaded from a file
427 or set for the bitmap.
429 @see SetMask(), wxMask
431 wxMask
* GetMask() const;
434 Gets the associated palette (if any) which may have been loaded from a file
435 or set for the bitmap.
439 wxPalette
* GetPalette() const;
442 Returns a sub bitmap of the current one as long as the rect belongs entirely to
443 the bitmap. This function preserves bit depth and mask information.
445 wxBitmap
GetSubBitmap(const wxRect
& rect
) const;
448 Gets the width of the bitmap in pixels.
452 int GetWidth() const;
455 Adds the standard bitmap format handlers, which, depending on wxWidgets
456 configuration, can be handlers for Windows bitmap, Windows bitmap resource,
459 This function is called by wxWidgets on startup.
463 static void InitStandardHandlers();
466 Adds a handler at the start of the static list of format handlers.
469 A new bitmap format handler object. There is usually only one instance
470 of a given handler class in an application session.
474 static void InsertHandler(wxBitmapHandler
* handler
);
477 Returns @true if bitmap data is present.
482 Loads a bitmap from a file or resource.
485 Either a filename or a Windows resource name.
486 The meaning of name is determined by the @a type parameter.
488 One of the ::wxBitmapType values; see the note in the class
489 detailed description.
491 @returns @true if the operation succeeded, @false otherwise.
493 @remarks A palette may be associated with the bitmap if one exists
494 (especially for colour Windows bitmaps), and if the
495 code supports it. You can check if one has been created
496 by using the GetPalette() member.
500 bool LoadFile(const wxString
& name
, wxBitmapType type
);
503 Finds the handler with the given name, and removes it.
504 The handler is not deleted.
509 @returns @true if the handler was found and removed, @false otherwise.
513 static bool RemoveHandler(const wxString
& name
);
516 Saves a bitmap in the named file.
519 A filename. The meaning of name is determined by the type parameter.
521 One of the ::wxBitmapType values; see the note in the class
522 detailed description.
524 An optional palette used for saving the bitmap.
526 @returns @true if the operation succeeded, @false otherwise.
528 @remarks Depending on how wxWidgets has been configured, not all formats
533 bool SaveFile(const wxString
& name
, wxBitmapType type
,
534 wxPalette
* palette
= NULL
);
537 Sets the depth member (does not affect the bitmap data).
539 @todo since these functions do not affect the bitmap data,
545 void SetDepth(int depth
);
548 Sets the height member (does not affect the bitmap data).
551 Bitmap height in pixels.
553 void SetHeight(int height
);
556 Sets the mask for this bitmap.
558 @remarks The bitmap object owns the mask once this has been called.
560 @see GetMask(), wxMask
562 void SetMask(wxMask
* mask
);
565 Sets the associated palette. (Not implemented under GTK+).
572 void SetPalette(const wxPalette
& palette
);
575 Sets the width member (does not affect the bitmap data).
578 Bitmap width in pixels.
580 void SetWidth(int width
);
583 Assignment operator, using @ref overview_refcount "reference counting".
588 wxBitmap
operator =(const wxBitmap
& bitmap
);
592 An empty wxBitmap object.
594 wxBitmap wxNullBitmap
;
603 This class encapsulates a monochrome mask bitmap, where the masked area is
604 black and the unmasked area is white.
606 When associated with a bitmap and drawn in a device context, the unmasked
607 area of the bitmap will be drawn, and the masked area will not be drawn.
612 @see wxBitmap, wxDC::Blit, wxMemoryDC
614 class wxMask
: public wxObject
624 Constructs a mask from a bitmap and a palette index that indicates the
626 Not yet implemented for GTK.
631 Index into a palette, specifying the transparency colour.
633 wxMask(const wxBitmap
& bitmap
, int index
);
636 Constructs a mask from a monochrome bitmap.
639 This is the default constructor for wxMask in wxPython.
642 wxMask(const wxBitmap
& bitmap
);
645 Constructs a mask from a bitmap and a colour that indicates the background.
648 wxPython has an alternate wxMask constructor matching this form called wxMaskColour.
651 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
654 Destroys the wxMask object and the underlying bitmap data.
659 Constructs a mask from a bitmap and a palette index that indicates the
661 Not yet implemented for GTK.
666 Index into a palette, specifying the transparency colour.
668 bool Create(const wxBitmap
& bitmap
, int index
);
671 Constructs a mask from a monochrome bitmap.
673 bool Create(const wxBitmap
& bitmap
);
676 Constructs a mask from a bitmap and a colour that indicates the background.
678 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);