]>
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 /////////////////////////////////////////////////////////////////////////////
11 In wxBitmap and wxBitmapHandler context this value means: "use the screen depth".
13 #define wxBITMAP_SCREEN_DEPTH (-1)
16 @class wxBitmapHandler
19 This is the base class for implementing bitmap file loading/saving, and
20 bitmap creation from data.
21 It is used within wxBitmap and is not normally seen by the application.
23 If you wish to extend the capabilities of wxBitmap, derive a class from
24 wxBitmapHandler and add the handler using wxBitmap::AddHandler() in your
25 application initialisation.
30 @see @ref overview_bitmap, wxBitmap, wxIcon, wxCursor
32 class wxBitmapHandler
: public wxObject
38 In your own default constructor, initialise the members m_name,
39 m_extension and m_type.
44 Destroys the wxBitmapHandler object.
46 virtual ~wxBitmapHandler();
49 Creates a bitmap from the given data, which can be of arbitrary type.
50 The wxBitmap object @a bitmap is manipulated by this function.
55 The width of the bitmap in pixels.
57 The height of the bitmap in pixels.
59 The depth of the bitmap in pixels.
60 If this is ::wxBITMAP_SCREEN_DEPTH, the screen depth is used.
62 Data whose type depends on the value of type.
64 A bitmap type identifier - see ::wxBitmapType for a list
67 @return @true if the call succeeded, @false otherwise (the default).
69 virtual bool Create(wxBitmap
* bitmap
, const void* data
, wxBitmapType type
,
70 int width
, int height
, int depth
= 1);
73 Gets the file extension associated with this handler.
75 const wxString
& GetExtension() const;
78 Gets the name of this handler.
80 const wxString
& GetName() const;
83 Gets the bitmap type associated with this handler.
85 wxBitmapType
GetType() const;
88 Loads a bitmap from a file or resource, putting the resulting data into
92 The bitmap object which is to be affected by this operation.
94 Either a filename or a Windows resource name.
95 The meaning of name is determined by the type parameter.
97 See ::wxBitmapType for values this can take.
99 The desired width for the loaded bitmap.
101 The desired height for the loaded bitmap.
103 @return @true if the operation succeeded, @false otherwise.
105 @see wxBitmap::LoadFile, wxBitmap::SaveFile, SaveFile()
107 virtual bool LoadFile(wxBitmap
* bitmap
, const wxString
& name
, wxBitmapType type
,
108 int desiredWidth
, int desiredHeight
);
111 Saves a bitmap in the named file.
114 The bitmap object which is to be affected by this operation.
116 A filename. The meaning of name is determined by the type parameter.
118 See ::wxBitmapType for values this can take.
120 An optional palette used for saving the bitmap.
122 @return @true if the operation succeeded, @false otherwise.
124 @see wxBitmap::LoadFile, wxBitmap::SaveFile, LoadFile()
126 virtual bool SaveFile(const wxBitmap
* bitmap
, const wxString
& name
, wxBitmapType type
,
127 const wxPalette
* palette
= NULL
) const;
130 Sets the handler extension.
135 void SetExtension(const wxString
& extension
);
138 Sets the handler name.
143 void SetName(const wxString
& name
);
146 Sets the handler type.
151 void SetType(wxBitmapType type
);
159 This class encapsulates the concept of a platform-dependent bitmap,
160 either monochrome or colour or colour with alpha channel support.
162 If you need direct access the bitmap data instead going through
163 drawing to it using wxMemoryDC you need to use the wxPixelData
164 class (either wxNativePixelData for RGB bitmaps or wxAlphaPixelData
165 for bitmaps with an additionaly alpha channel).
168 Many wxBitmap functions take a @e type parameter, which is a value of the
169 ::wxBitmapType enumeration.
170 The validity of those values depends however on the platform where your program
171 is running and from the wxWidgets configuration.
172 If all possible wxWidgets settings are used, the Windows platform supports BMP file,
173 BMP resource, XPM data, and XPM.
174 Under wxGTK, the available formats are BMP file, XPM data, XPM file, and PNG file.
175 Under wxMotif, the available formats are XBM data, XBM file, XPM data, XPM file.
176 In addition, wxBitmap can load and save all formats that wxImage; see wxImage for
177 more info. Of course, you must have wxImage handlers loaded.
185 @see @ref overview_bitmap, @ref overview_bitmap_supportedformats,
186 wxDC::Blit, wxIcon, wxCursor, wxMemoryDC, wxImage, wxPixelData
188 class wxBitmap
: public wxGDIObject
194 Constructs a bitmap object with no data; an assignment or another member
195 function such as Create() or LoadFile() must be called subsequently.
200 Copy constructor, uses @ref overview_refcount "reference counting".
201 To make a real copy, you can use:
204 wxBitmap newBitmap = oldBitmap.GetSubBitmap(
205 wxRect(0, 0, oldBitmap.GetWidth(), oldBitmap.GetHeight()));
208 wxBitmap(const wxBitmap
& bitmap
);
212 Creates a bitmap from the given @a data which is interpreted in
213 platform-dependent manner.
216 Specifies the bitmap data in a platform-dependent format.
218 May be one of the ::wxBitmapType values and indicates which type of
219 bitmap does @a data contains. See the note in the class
220 detailed description.
222 Specifies the width of the bitmap.
224 Specifies the height of the bitmap.
226 Specifies the depth of the bitmap.
227 If this is omitted, the display depth of the screen is used.
228 wxBitmap(const void* data, int type, int width, int height, int depth = -1);
231 NOTE: this ctor is not implemented by all ports, is somewhat useless
232 without further description of the "data" supported formats and
233 uses 'int type' instead of wxBitmapType, so don't document it.
237 Creates a bitmap from the given array @a bits.
238 You should only use this function for monochrome bitmaps (depth 1) in
239 portable programs: in this case the bits parameter should contain an XBM image.
241 For other bit depths, the behaviour is platform dependent: under Windows,
242 the data is passed without any changes to the underlying CreateBitmap() API.
243 Under other platforms, only monochrome bitmaps may be created using this
244 constructor and wxImage should be used for creating colour bitmaps from
248 Specifies an array of pixel values.
250 Specifies the width of the bitmap.
252 Specifies the height of the bitmap.
254 Specifies the depth of the bitmap.
255 If this is omitted, then a value of 1 (monochrome bitmap) is used.
257 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
260 Creates a new bitmap. A depth of ::wxBITMAP_SCREEN_DEPTH indicates the
261 depth of the current screen or visual.
263 Some platforms only support 1 for monochrome and ::wxBITMAP_SCREEN_DEPTH for
264 the current colour setting.
266 A depth of 32 including an alpha channel is supported under MSW, Mac and GTK+.
268 wxBitmap(int width
, int height
, int depth
= wxBITMAP_SCREEN_DEPTH
);
271 Creates a bitmap from XPM data.
273 wxBitmap(const char* const* bits
);
276 Loads a bitmap from a file or resource.
279 This can refer to a resource name or a filename under MS Windows and X.
280 Its meaning is determined by the @a type parameter.
282 May be one of the ::wxBitmapType values and indicates which type of
283 bitmap should be loaded. See the note in the class detailed description.
287 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_XPM
);
290 Creates this bitmap object from the given image.
291 This has to be done to actually display an image as you cannot draw an
292 image directly on a window.
294 The resulting bitmap will use the provided colour depth (or that of the
295 current system if depth is ::wxBITMAP_SCREEN_DEPTH) which entails that a
296 colour reduction may take place.
298 When in 8-bit mode (PseudoColour mode), the GTK port will use a color cube
299 created on program start-up to look up colors. This ensures a very fast conversion,
300 but the image quality won't be perfect (and could be better for photo images using
301 more sophisticated dithering algorithms).
303 On Windows, if there is a palette present (set with SetPalette), it will be
304 used when creating the wxBitmap (most useful in 8-bit display mode).
305 On other platforms, the palette is currently ignored.
308 Platform-independent wxImage object.
310 Specifies the depth of the bitmap.
311 If this is omitted, the display depth of the screen is used.
313 wxBitmap(const wxImage
& img
, int depth
= wxBITMAP_SCREEN_DEPTH
);
317 See @ref overview_refcount_destruct for more info.
319 If the application omits to delete the bitmap explicitly, the bitmap will be
320 destroyed automatically by wxWidgets when the application exits.
323 Do not delete a bitmap that is selected into a memory device context.
328 Adds a handler to the end of the static list of format handlers.
331 A new bitmap format handler object. There is usually only one instance
332 of a given handler class in an application session.
336 static void AddHandler(wxBitmapHandler
* handler
);
339 Deletes all bitmap handlers.
340 This function is called by wxWidgets on exit.
342 static void CleanUpHandlers();
345 Creates an image from a platform-dependent bitmap. This preserves
346 mask information so that bitmaps and images can be converted back
347 and forth without loss in that respect.
349 virtual wxImage
ConvertToImage() const;
352 Creates the bitmap from an icon.
354 virtual bool CopyFromIcon(const wxIcon
& icon
);
357 Creates a fresh bitmap.
358 If the final argument is omitted, the display depth of the screen is used.
360 This overload works on all platforms.
362 virtual bool Create(int width
, int height
, int depth
= wxBITMAP_SCREEN_DEPTH
);
365 Creates a bitmap from the given data, which can be of arbitrary type.
368 Data whose type depends on the value of type.
370 A bitmap type identifier; see ::wxBitmapType for the list of values.
371 See the note in the class detailed description for more info.
373 The width of the bitmap in pixels.
375 The height of the bitmap in pixels.
377 The depth of the bitmap in pixels. If this is -1, the screen depth is used.
379 @return @true if the call succeeded, @false otherwise.
381 This overload depends on the @a type of data.
383 virtual bool Create(const void* data, int type, int width,
384 int height, int depth = -1);
386 NOTE: leave this undoc for the same reason of the relative ctor.
390 Finds the handler with the given @a name.
392 @return A pointer to the handler if found, @NULL otherwise.
394 static wxBitmapHandler
* FindHandler(const wxString
& name
);
397 Finds the handler associated with the given @a extension and @a type.
400 The file extension, such as "bmp" (without the dot).
402 The bitmap type managed by the handler, see ::wxBitmapType.
404 @return A pointer to the handler if found, @NULL otherwise.
406 static wxBitmapHandler
* FindHandler(const wxString
& extension
,
407 wxBitmapType bitmapType
);
410 Finds the handler associated with the given bitmap type.
413 The bitmap type managed by the handler, see ::wxBitmapType.
415 @return A pointer to the handler if found, @NULL otherwise.
420 static wxBitmapHandler
* FindHandler(wxBitmapType bitmapType
);
423 Gets the colour depth of the bitmap.
424 A value of 1 indicates a monochrome bitmap.
426 virtual int GetDepth() const;
429 Returns the static list of bitmap format handlers.
433 static wxList
GetHandlers();
436 Gets the height of the bitmap in pixels.
438 virtual int GetHeight() const;
441 Gets the associated mask (if any) which may have been loaded from a file
442 or set for the bitmap.
444 @see SetMask(), wxMask
446 virtual wxMask
* GetMask() const;
449 Gets the associated palette (if any) which may have been loaded from a file
450 or set for the bitmap.
454 virtual wxPalette
* GetPalette() const;
457 Returns a sub bitmap of the current one as long as the rect belongs entirely to
458 the bitmap. This function preserves bit depth and mask information.
460 virtual wxBitmap
GetSubBitmap(const wxRect
& rect
) const;
463 Gets the width of the bitmap in pixels.
467 virtual int GetWidth() const;
470 Adds the standard bitmap format handlers, which, depending on wxWidgets
471 configuration, can be handlers for Windows bitmap, Windows bitmap resource,
474 This function is called by wxWidgets on startup.
478 static void InitStandardHandlers();
481 Adds a handler at the start of the static list of format handlers.
484 A new bitmap format handler object. There is usually only one instance
485 of a given handler class in an application session.
489 static void InsertHandler(wxBitmapHandler
* handler
);
492 Returns @true if bitmap data is present.
497 Loads a bitmap from a file or resource.
500 Either a filename or a Windows resource name.
501 The meaning of name is determined by the @a type parameter.
503 One of the ::wxBitmapType values; see the note in the class
504 detailed description.
506 @return @true if the operation succeeded, @false otherwise.
508 @remarks A palette may be associated with the bitmap if one exists
509 (especially for colour Windows bitmaps), and if the
510 code supports it. You can check if one has been created
511 by using the GetPalette() member.
515 virtual bool LoadFile(const wxString
& name
, wxBitmapType type
);
518 Finds the handler with the given name, and removes it.
519 The handler is not deleted.
524 @return @true if the handler was found and removed, @false otherwise.
528 static bool RemoveHandler(const wxString
& name
);
531 Saves a bitmap in the named file.
534 A filename. The meaning of name is determined by the type parameter.
536 One of the ::wxBitmapType values; see the note in the class
537 detailed description.
539 An optional palette used for saving the bitmap.
541 @return @true if the operation succeeded, @false otherwise.
543 @remarks Depending on how wxWidgets has been configured, not all formats
548 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
,
549 const wxPalette
* palette
= NULL
) const;
552 Sets the depth member (does not affect the bitmap data).
554 @todo since these functions do not affect the bitmap data,
560 virtual void SetDepth(int depth
);
563 Sets the height member (does not affect the bitmap data).
566 Bitmap height in pixels.
568 virtual void SetHeight(int height
);
571 Sets the mask for this bitmap.
573 @remarks The bitmap object owns the mask once this has been called.
575 @see GetMask(), wxMask
577 virtual void SetMask(wxMask
* mask
);
580 Sets the associated palette. (Not implemented under GTK+).
587 virtual void SetPalette(const wxPalette
& palette
);
590 Sets the width member (does not affect the bitmap data).
593 Bitmap width in pixels.
595 virtual void SetWidth(int width
);
599 An empty wxBitmap object.
601 wxBitmap wxNullBitmap
;
610 This class encapsulates a monochrome mask bitmap, where the masked area is
611 black and the unmasked area is white.
613 When associated with a bitmap and drawn in a device context, the unmasked
614 area of the bitmap will be drawn, and the masked area will not be drawn.
619 @see wxBitmap, wxDC::Blit, wxMemoryDC
621 class wxMask
: public wxObject
631 Constructs a mask from a bitmap and a palette index that indicates the
633 Not yet implemented for GTK.
638 Index into a palette, specifying the transparency colour.
640 wxMask(const wxBitmap
& bitmap
, int index
);
643 Constructs a mask from a monochrome bitmap.
646 This is the default constructor for wxMask in wxPython.
649 wxMask(const wxBitmap
& bitmap
);
652 Constructs a mask from a bitmap and a colour that indicates the background.
655 wxPython has an alternate wxMask constructor matching this form called wxMaskColour.
658 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
661 Destroys the wxMask object and the underlying bitmap data.
666 Constructs a mask from a bitmap and a palette index that indicates the
668 Not yet implemented for GTK.
673 Index into a palette, specifying the transparency colour.
675 bool Create(const wxBitmap
& bitmap
, int index
);
678 Constructs a mask from a monochrome bitmap.
680 bool Create(const wxBitmap
& bitmap
);
683 Constructs a mask from a bitmap and a colour that indicates the background.
685 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);