]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/bitmap.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxBitmap* classes
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
11 In wxBitmap and wxBitmapHandler context this value means: "use the screen depth".
13 #define wxBITMAP_SCREEN_DEPTH (-1)
16 @class wxBitmapHandler
18 This is the base class for implementing bitmap file loading/saving, and
19 bitmap creation from data.
20 It is used within wxBitmap and is not normally seen by the application.
22 If you wish to extend the capabilities of wxBitmap, derive a class from
23 wxBitmapHandler and add the handler using wxBitmap::AddHandler() in your
24 application initialization.
26 Note that all wxBitmapHandlers provided by wxWidgets are part of the
27 @ref page_libs_wxcore library.
28 For details about the default handlers, please see the note in the
29 wxBitmap class documentation.
34 @see @ref overview_bitmap, wxBitmap, wxIcon, wxCursor
36 class wxBitmapHandler
: public wxObject
42 In your own default constructor, initialise the members m_name,
43 m_extension and m_type.
48 Destroys the wxBitmapHandler object.
50 virtual ~wxBitmapHandler();
53 Creates a bitmap from the given data, which can be of arbitrary type.
54 The wxBitmap object @a bitmap is manipulated by this function.
59 The width of the bitmap in pixels.
61 The height of the bitmap in pixels.
63 The depth of the bitmap in pixels.
64 If this is ::wxBITMAP_SCREEN_DEPTH, the screen depth is used.
66 Data whose type depends on the value of type.
68 A bitmap type identifier - see ::wxBitmapType for a list
71 @return @true if the call succeeded, @false otherwise (the default).
73 virtual bool Create(wxBitmap
* bitmap
, const void* data
, wxBitmapType type
,
74 int width
, int height
, int depth
= 1);
77 Gets the file extension associated with this handler.
79 const wxString
& GetExtension() const;
82 Gets the name of this handler.
84 const wxString
& GetName() const;
87 Gets the bitmap type associated with this handler.
89 wxBitmapType
GetType() const;
92 Loads a bitmap from a file or resource, putting the resulting data into
96 The bitmap object which is to be affected by this operation.
98 Either a filename or a Windows resource name.
99 The meaning of name is determined by the type parameter.
101 See ::wxBitmapType for values this can take.
103 The desired width for the loaded bitmap.
105 The desired height for the loaded bitmap.
107 @return @true if the operation succeeded, @false otherwise.
109 @see wxBitmap::LoadFile, wxBitmap::SaveFile, SaveFile()
111 virtual bool LoadFile(wxBitmap
* bitmap
, const wxString
& name
, wxBitmapType type
,
112 int desiredWidth
, int desiredHeight
);
115 Saves a bitmap in the named file.
118 The bitmap object which is to be affected by this operation.
120 A filename. The meaning of name is determined by the type parameter.
122 See ::wxBitmapType for values this can take.
124 An optional palette used for saving the bitmap.
126 @return @true if the operation succeeded, @false otherwise.
128 @see wxBitmap::LoadFile, wxBitmap::SaveFile, LoadFile()
130 virtual bool SaveFile(const wxBitmap
* bitmap
, const wxString
& name
, wxBitmapType type
,
131 const wxPalette
* palette
= NULL
) const;
134 Sets the handler extension.
139 void SetExtension(const wxString
& extension
);
142 Sets the handler name.
147 void SetName(const wxString
& name
);
150 Sets the handler type.
155 void SetType(wxBitmapType type
);
162 This class encapsulates the concept of a platform-dependent bitmap,
163 either monochrome or colour or colour with alpha channel support.
165 If you need direct access the bitmap data instead going through
166 drawing to it using wxMemoryDC you need to use the wxPixelData
167 class (either wxNativePixelData for RGB bitmaps or wxAlphaPixelData
168 for bitmaps with an additionaly alpha channel).
170 Note that many wxBitmap functions take a @e type parameter, which is a
171 value of the ::wxBitmapType enumeration.
172 The validity of those values depends however on the platform where your program
173 is running and from the wxWidgets configuration.
174 If all possible wxWidgets settings are used:
175 - wxMSW supports BMP and ICO files, BMP and ICO resources;
176 - wxGTK supports XPM files;
177 - wxMac supports PICT resources;
178 - wxX11 supports XPM files, XPM data, XBM data;
180 In addition, wxBitmap can load and save all formats that wxImage can; see wxImage
181 for more info. Of course, you must have loaded the wxImage handlers
182 (see ::wxInitAllImageHandlers() and wxImage::AddHandler).
183 Note that all available wxBitmapHandlers for a given wxWidgets port are
184 automatically loaded at startup so you won't need to use wxBitmap::AddHandler.
192 @see @ref overview_bitmap, @ref overview_bitmap_supportedformats,
193 wxDC::Blit, wxIcon, wxCursor, wxMemoryDC, wxImage, wxPixelData
195 class wxBitmap
: public wxGDIObject
201 Constructs a bitmap object with no data; an assignment or another member
202 function such as Create() or LoadFile() must be called subsequently.
207 Copy constructor, uses @ref overview_refcount "reference counting".
208 To make a real copy, you can use:
211 wxBitmap newBitmap = oldBitmap.GetSubBitmap(
212 wxRect(0, 0, oldBitmap.GetWidth(), oldBitmap.GetHeight()));
215 wxBitmap(const wxBitmap
& bitmap
);
219 Creates a bitmap from the given @a data which is interpreted in
220 platform-dependent manner.
223 Specifies the bitmap data in a platform-dependent format.
225 May be one of the ::wxBitmapType values and indicates which type of
226 bitmap does @a data contains. See the note in the class
227 detailed description.
229 Specifies the width of the bitmap.
231 Specifies the height of the bitmap.
233 Specifies the depth of the bitmap.
234 If this is omitted, the display depth of the screen is used.
235 wxBitmap(const void* data, int type, int width, int height, int depth = -1);
238 NOTE: this ctor is not implemented by all ports, is somewhat useless
239 without further description of the "data" supported formats and
240 uses 'int type' instead of wxBitmapType, so don't document it.
244 Creates a bitmap from the given array @a bits.
245 You should only use this function for monochrome bitmaps (depth 1) in
246 portable programs: in this case the bits parameter should contain an XBM image.
248 For other bit depths, the behaviour is platform dependent: under Windows,
249 the data is passed without any changes to the underlying CreateBitmap() API.
250 Under other platforms, only monochrome bitmaps may be created using this
251 constructor and wxImage should be used for creating colour bitmaps from
255 Specifies an array of pixel values.
257 Specifies the width of the bitmap.
259 Specifies the height of the bitmap.
261 Specifies the depth of the bitmap.
262 If this is omitted, then a value of 1 (monochrome bitmap) is used.
264 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
267 Creates a new bitmap. A depth of ::wxBITMAP_SCREEN_DEPTH indicates the
268 depth of the current screen or visual.
270 Some platforms only support 1 for monochrome and ::wxBITMAP_SCREEN_DEPTH for
271 the current colour setting.
273 A depth of 32 including an alpha channel is supported under MSW, Mac and GTK+.
275 wxBitmap(int width
, int height
, int depth
= wxBITMAP_SCREEN_DEPTH
);
278 Creates a bitmap from XPM data.
280 wxBitmap(const char* const* bits
);
283 Loads a bitmap from a file or resource.
286 This can refer to a resource name or a filename under MS Windows and X.
287 Its meaning is determined by the @a type parameter.
289 May be one of the ::wxBitmapType values and indicates which type of
290 bitmap should be loaded. See the note in the class detailed description.
291 Note that the wxBITMAP_DEFAULT_TYPE constant has different value under
292 different wxWidgets ports. See the bitmap.h header for the value it takes
297 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_DEFAULT_TYPE
);
300 Creates this bitmap object from the given image.
301 This has to be done to actually display an image as you cannot draw an
302 image directly on a window.
304 The resulting bitmap will use the provided colour depth (or that of the
305 current system if depth is ::wxBITMAP_SCREEN_DEPTH) which entails that a
306 colour reduction may take place.
308 When in 8-bit mode (PseudoColour mode), the GTK port will use a color cube
309 created on program start-up to look up colors. This ensures a very fast conversion,
310 but the image quality won't be perfect (and could be better for photo images using
311 more sophisticated dithering algorithms).
313 On Windows, if there is a palette present (set with SetPalette), it will be
314 used when creating the wxBitmap (most useful in 8-bit display mode).
315 On other platforms, the palette is currently ignored.
318 Platform-independent wxImage object.
320 Specifies the depth of the bitmap.
321 If this is omitted, the display depth of the screen is used.
323 wxBitmap(const wxImage
& img
, int depth
= wxBITMAP_SCREEN_DEPTH
);
327 See @ref overview_refcount_destruct for more info.
329 If the application omits to delete the bitmap explicitly, the bitmap will be
330 destroyed automatically by wxWidgets when the application exits.
333 Do not delete a bitmap that is selected into a memory device context.
338 Adds a handler to the end of the static list of format handlers.
341 A new bitmap format handler object. There is usually only one instance
342 of a given handler class in an application session.
344 Note that unlike wxImage::AddHandler, there's no documented list of
345 the wxBitmapHandlers available in wxWidgets.
346 This is because they are platform-specific and most important, they are
347 all automatically loaded at startup.
349 If you want to be sure that wxBitmap can load a certain type of image,
350 you'd better use wxImage::AddHandler.
354 static void AddHandler(wxBitmapHandler
* handler
);
357 Deletes all bitmap handlers.
358 This function is called by wxWidgets on exit.
360 static void CleanUpHandlers();
363 Creates an image from a platform-dependent bitmap. This preserves
364 mask information so that bitmaps and images can be converted back
365 and forth without loss in that respect.
367 virtual wxImage
ConvertToImage() const;
370 Creates the bitmap from an icon.
372 virtual bool CopyFromIcon(const wxIcon
& icon
);
375 Creates a fresh bitmap.
376 If the final argument is omitted, the display depth of the screen is used.
378 This overload works on all platforms.
380 virtual bool Create(int width
, int height
, int depth
= wxBITMAP_SCREEN_DEPTH
);
383 Creates a bitmap from the given data, which can be of arbitrary type.
386 Data whose type depends on the value of type.
388 A bitmap type identifier; see ::wxBitmapType for the list of values.
389 See the note in the class detailed description for more info.
391 The width of the bitmap in pixels.
393 The height of the bitmap in pixels.
395 The depth of the bitmap in pixels. If this is -1, the screen depth is used.
397 @return @true if the call succeeded, @false otherwise.
399 This overload depends on the @a type of data.
401 virtual bool Create(const void* data, int type, int width,
402 int height, int depth = -1);
404 NOTE: leave this undoc for the same reason of the relative ctor.
408 Finds the handler with the given @a name.
410 @return A pointer to the handler if found, @NULL otherwise.
412 static wxBitmapHandler
* FindHandler(const wxString
& name
);
415 Finds the handler associated with the given @a extension and @a type.
418 The file extension, such as "bmp" (without the dot).
420 The bitmap type managed by the handler, see ::wxBitmapType.
422 @return A pointer to the handler if found, @NULL otherwise.
424 static wxBitmapHandler
* FindHandler(const wxString
& extension
,
425 wxBitmapType bitmapType
);
428 Finds the handler associated with the given bitmap type.
431 The bitmap type managed by the handler, see ::wxBitmapType.
433 @return A pointer to the handler if found, @NULL otherwise.
438 static wxBitmapHandler
* FindHandler(wxBitmapType bitmapType
);
441 Gets the colour depth of the bitmap.
442 A value of 1 indicates a monochrome bitmap.
444 virtual int GetDepth() const;
447 Returns the static list of bitmap format handlers.
451 static wxList
& GetHandlers();
454 Gets the height of the bitmap in pixels.
456 @see GetWidth(), GetSize()
458 virtual int GetHeight() const;
461 Gets the associated mask (if any) which may have been loaded from a file
462 or set for the bitmap.
464 @see SetMask(), wxMask
466 virtual wxMask
* GetMask() const;
469 Gets the associated palette (if any) which may have been loaded from a file
470 or set for the bitmap.
474 virtual wxPalette
* GetPalette() const;
477 Returns a sub bitmap of the current one as long as the rect belongs entirely to
478 the bitmap. This function preserves bit depth and mask information.
480 virtual wxBitmap
GetSubBitmap(const wxRect
& rect
) const;
483 Returns the size of the bitmap in pixels.
487 @see GetHeight(), GetWidth()
489 wxSize
GetSize() const;
492 Gets the width of the bitmap in pixels.
494 @see GetHeight(), GetSize()
496 virtual int GetWidth() const;
499 Adds the standard bitmap format handlers, which, depending on wxWidgets
500 configuration, can be handlers for Windows bitmap, Windows bitmap resource,
503 This function is called by wxWidgets on startup.
507 static void InitStandardHandlers();
510 Adds a handler at the start of the static list of format handlers.
513 A new bitmap format handler object. There is usually only one instance
514 of a given handler class in an application session.
518 static void InsertHandler(wxBitmapHandler
* handler
);
521 Returns @true if bitmap data is present.
523 virtual bool IsOk() const;
526 Loads a bitmap from a file or resource.
529 Either a filename or a Windows resource name.
530 The meaning of name is determined by the @a type parameter.
532 One of the ::wxBitmapType values; see the note in the class
533 detailed description.
534 Note that the wxBITMAP_DEFAULT_TYPE constant has different value under
535 different wxWidgets ports. See the bitmap.h header for the value it takes
538 @return @true if the operation succeeded, @false otherwise.
540 @remarks A palette may be associated with the bitmap if one exists
541 (especially for colour Windows bitmaps), and if the
542 code supports it. You can check if one has been created
543 by using the GetPalette() member.
547 virtual bool LoadFile(const wxString
& name
, wxBitmapType type
= wxBITMAP_DEFAULT_TYPE
);
550 Finds the handler with the given name, and removes it.
551 The handler is not deleted.
556 @return @true if the handler was found and removed, @false otherwise.
560 static bool RemoveHandler(const wxString
& name
);
563 Saves a bitmap in the named file.
566 A filename. The meaning of name is determined by the type parameter.
568 One of the ::wxBitmapType values; see the note in the class
569 detailed description.
571 An optional palette used for saving the bitmap.
573 @return @true if the operation succeeded, @false otherwise.
575 @remarks Depending on how wxWidgets has been configured, not all formats
580 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
,
581 const wxPalette
* palette
= NULL
) const;
584 Sets the depth member (does not affect the bitmap data).
586 @todo since these functions do not affect the bitmap data,
592 virtual void SetDepth(int depth
);
595 Sets the height member (does not affect the bitmap data).
598 Bitmap height in pixels.
600 virtual void SetHeight(int height
);
603 Sets the mask for this bitmap.
605 @remarks The bitmap object owns the mask once this has been called.
607 @see GetMask(), wxMask
609 virtual void SetMask(wxMask
* mask
);
612 Sets the associated palette. (Not implemented under GTK+).
619 virtual void SetPalette(const wxPalette
& palette
);
622 Sets the width member (does not affect the bitmap data).
625 Bitmap width in pixels.
627 virtual void SetWidth(int width
);
631 An empty wxBitmap object.
633 wxBitmap wxNullBitmap
;
641 This class encapsulates a monochrome mask bitmap, where the masked area is
642 black and the unmasked area is white.
644 When associated with a bitmap and drawn in a device context, the unmasked
645 area of the bitmap will be drawn, and the masked area will not be drawn.
650 @see wxBitmap, wxDC::Blit, wxMemoryDC
652 class wxMask
: public wxObject
662 Constructs a mask from a bitmap and a palette index that indicates the
664 Not yet implemented for GTK.
669 Index into a palette, specifying the transparency colour.
671 wxMask(const wxBitmap
& bitmap
, int index
);
674 Constructs a mask from a monochrome bitmap.
677 This is the default constructor for wxMask in wxPython.
680 wxMask(const wxBitmap
& bitmap
);
683 Constructs a mask from a bitmap and a colour that indicates the background.
686 wxPython has an alternate wxMask constructor matching this form called wxMaskColour.
689 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
692 Destroys the wxMask object and the underlying bitmap data.
697 Constructs a mask from a bitmap and a palette index that indicates the
699 Not yet implemented for GTK.
704 Index into a palette, specifying the transparency colour.
706 bool Create(const wxBitmap
& bitmap
, int index
);
709 Constructs a mask from a monochrome bitmap.
711 bool Create(const wxBitmap
& bitmap
);
714 Constructs a mask from a bitmap and a colour that indicates the background.
716 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);