]>
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 initialisation.
29 @see @ref overview_bitmap, wxBitmap, wxIcon, wxCursor
31 class wxBitmapHandler
: public wxObject
37 In your own default constructor, initialise the members m_name,
38 m_extension and m_type.
43 Destroys the wxBitmapHandler object.
45 virtual ~wxBitmapHandler();
48 Creates a bitmap from the given data, which can be of arbitrary type.
49 The wxBitmap object @a bitmap is manipulated by this function.
54 The width of the bitmap in pixels.
56 The height of the bitmap in pixels.
58 The depth of the bitmap in pixels.
59 If this is ::wxBITMAP_SCREEN_DEPTH, the screen depth is used.
61 Data whose type depends on the value of type.
63 A bitmap type identifier - see ::wxBitmapType for a list
66 @return @true if the call succeeded, @false otherwise (the default).
68 virtual bool Create(wxBitmap
* bitmap
, const void* data
, wxBitmapType type
,
69 int width
, int height
, int depth
= 1);
72 Gets the file extension associated with this handler.
74 const wxString
& GetExtension() const;
77 Gets the name of this handler.
79 const wxString
& GetName() const;
82 Gets the bitmap type associated with this handler.
84 wxBitmapType
GetType() const;
87 Loads a bitmap from a file or resource, putting the resulting data into
91 The bitmap object which is to be affected by this operation.
93 Either a filename or a Windows resource name.
94 The meaning of name is determined by the type parameter.
96 See ::wxBitmapType for values this can take.
98 The desired width for the loaded bitmap.
100 The desired height for the loaded bitmap.
102 @return @true if the operation succeeded, @false otherwise.
104 @see wxBitmap::LoadFile, wxBitmap::SaveFile, SaveFile()
106 virtual bool LoadFile(wxBitmap
* bitmap
, const wxString
& name
, wxBitmapType type
,
107 int desiredWidth
, int desiredHeight
);
110 Saves a bitmap in the named file.
113 The bitmap object which is to be affected by this operation.
115 A filename. The meaning of name is determined by the type parameter.
117 See ::wxBitmapType for values this can take.
119 An optional palette used for saving the bitmap.
121 @return @true if the operation succeeded, @false otherwise.
123 @see wxBitmap::LoadFile, wxBitmap::SaveFile, LoadFile()
125 virtual bool SaveFile(const wxBitmap
* bitmap
, const wxString
& name
, wxBitmapType type
,
126 const wxPalette
* palette
= NULL
) const;
129 Sets the handler extension.
134 void SetExtension(const wxString
& extension
);
137 Sets the handler name.
142 void SetName(const wxString
& name
);
145 Sets the handler type.
150 void SetType(wxBitmapType type
);
157 This class encapsulates the concept of a platform-dependent bitmap,
158 either monochrome or colour or colour with alpha channel support.
160 If you need direct access the bitmap data instead going through
161 drawing to it using wxMemoryDC you need to use the wxPixelData
162 class (either wxNativePixelData for RGB bitmaps or wxAlphaPixelData
163 for bitmaps with an additionaly alpha channel).
166 Many wxBitmap functions take a @e type parameter, which is a value of the
167 ::wxBitmapType enumeration.
168 The validity of those values depends however on the platform where your program
169 is running and from the wxWidgets configuration.
170 If all possible wxWidgets settings are used, the Windows platform supports BMP file,
171 BMP resource, XPM data, and XPM.
172 Under wxGTK, the available formats are BMP file, XPM data, XPM file, and PNG file.
173 Under wxMotif, the available formats are XBM data, XBM file, XPM data, XPM file.
174 In addition, wxBitmap can load and save all formats that wxImage; see wxImage for
175 more info. Of course, you must have wxImage handlers loaded.
183 @see @ref overview_bitmap, @ref overview_bitmap_supportedformats,
184 wxDC::Blit, wxIcon, wxCursor, wxMemoryDC, wxImage, wxPixelData
186 class wxBitmap
: public wxGDIObject
192 Constructs a bitmap object with no data; an assignment or another member
193 function such as Create() or LoadFile() must be called subsequently.
198 Copy constructor, uses @ref overview_refcount "reference counting".
199 To make a real copy, you can use:
202 wxBitmap newBitmap = oldBitmap.GetSubBitmap(
203 wxRect(0, 0, oldBitmap.GetWidth(), oldBitmap.GetHeight()));
206 wxBitmap(const wxBitmap
& bitmap
);
210 Creates a bitmap from the given @a data which is interpreted in
211 platform-dependent manner.
214 Specifies the bitmap data in a platform-dependent format.
216 May be one of the ::wxBitmapType values and indicates which type of
217 bitmap does @a data contains. See the note in the class
218 detailed description.
220 Specifies the width of the bitmap.
222 Specifies the height of the bitmap.
224 Specifies the depth of the bitmap.
225 If this is omitted, the display depth of the screen is used.
226 wxBitmap(const void* data, int type, int width, int height, int depth = -1);
229 NOTE: this ctor is not implemented by all ports, is somewhat useless
230 without further description of the "data" supported formats and
231 uses 'int type' instead of wxBitmapType, so don't document it.
235 Creates a bitmap from the given array @a bits.
236 You should only use this function for monochrome bitmaps (depth 1) in
237 portable programs: in this case the bits parameter should contain an XBM image.
239 For other bit depths, the behaviour is platform dependent: under Windows,
240 the data is passed without any changes to the underlying CreateBitmap() API.
241 Under other platforms, only monochrome bitmaps may be created using this
242 constructor and wxImage should be used for creating colour bitmaps from
246 Specifies an array of pixel values.
248 Specifies the width of the bitmap.
250 Specifies the height of the bitmap.
252 Specifies the depth of the bitmap.
253 If this is omitted, then a value of 1 (monochrome bitmap) is used.
255 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
258 Creates a new bitmap. A depth of ::wxBITMAP_SCREEN_DEPTH indicates the
259 depth of the current screen or visual.
261 Some platforms only support 1 for monochrome and ::wxBITMAP_SCREEN_DEPTH for
262 the current colour setting.
264 A depth of 32 including an alpha channel is supported under MSW, Mac and GTK+.
266 wxBitmap(int width
, int height
, int depth
= wxBITMAP_SCREEN_DEPTH
);
269 Creates a bitmap from XPM data.
271 wxBitmap(const char* const* bits
);
274 Loads a bitmap from a file or resource.
277 This can refer to a resource name or a filename under MS Windows and X.
278 Its meaning is determined by the @a type parameter.
280 May be one of the ::wxBitmapType values and indicates which type of
281 bitmap should be loaded. See the note in the class detailed description.
282 Note that the wxBITMAP_DEFAULT_TYPE constant has different value under
283 different wxWidgets ports. See the bitmap.h header for the value it takes
288 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_DEFAULT_TYPE
);
291 Creates this bitmap object from the given image.
292 This has to be done to actually display an image as you cannot draw an
293 image directly on a window.
295 The resulting bitmap will use the provided colour depth (or that of the
296 current system if depth is ::wxBITMAP_SCREEN_DEPTH) which entails that a
297 colour reduction may take place.
299 When in 8-bit mode (PseudoColour mode), the GTK port will use a color cube
300 created on program start-up to look up colors. This ensures a very fast conversion,
301 but the image quality won't be perfect (and could be better for photo images using
302 more sophisticated dithering algorithms).
304 On Windows, if there is a palette present (set with SetPalette), it will be
305 used when creating the wxBitmap (most useful in 8-bit display mode).
306 On other platforms, the palette is currently ignored.
309 Platform-independent wxImage object.
311 Specifies the depth of the bitmap.
312 If this is omitted, the display depth of the screen is used.
314 wxBitmap(const wxImage
& img
, int depth
= wxBITMAP_SCREEN_DEPTH
);
318 See @ref overview_refcount_destruct for more info.
320 If the application omits to delete the bitmap explicitly, the bitmap will be
321 destroyed automatically by wxWidgets when the application exits.
324 Do not delete a bitmap that is selected into a memory device context.
329 Adds a handler to the end of the static list of format handlers.
332 A new bitmap format handler object. There is usually only one instance
333 of a given handler class in an application session.
337 static void AddHandler(wxBitmapHandler
* handler
);
340 Deletes all bitmap handlers.
341 This function is called by wxWidgets on exit.
343 static void CleanUpHandlers();
346 Creates an image from a platform-dependent bitmap. This preserves
347 mask information so that bitmaps and images can be converted back
348 and forth without loss in that respect.
350 virtual wxImage
ConvertToImage() const;
353 Creates the bitmap from an icon.
355 virtual bool CopyFromIcon(const wxIcon
& icon
);
358 Creates a fresh bitmap.
359 If the final argument is omitted, the display depth of the screen is used.
361 This overload works on all platforms.
363 virtual bool Create(int width
, int height
, int depth
= wxBITMAP_SCREEN_DEPTH
);
366 Creates a bitmap from the given data, which can be of arbitrary type.
369 Data whose type depends on the value of type.
371 A bitmap type identifier; see ::wxBitmapType for the list of values.
372 See the note in the class detailed description for more info.
374 The width of the bitmap in pixels.
376 The height of the bitmap in pixels.
378 The depth of the bitmap in pixels. If this is -1, the screen depth is used.
380 @return @true if the call succeeded, @false otherwise.
382 This overload depends on the @a type of data.
384 virtual bool Create(const void* data, int type, int width,
385 int height, int depth = -1);
387 NOTE: leave this undoc for the same reason of the relative ctor.
391 Finds the handler with the given @a name.
393 @return A pointer to the handler if found, @NULL otherwise.
395 static wxBitmapHandler
* FindHandler(const wxString
& name
);
398 Finds the handler associated with the given @a extension and @a type.
401 The file extension, such as "bmp" (without the dot).
403 The bitmap type managed by the handler, see ::wxBitmapType.
405 @return A pointer to the handler if found, @NULL otherwise.
407 static wxBitmapHandler
* FindHandler(const wxString
& extension
,
408 wxBitmapType bitmapType
);
411 Finds the handler associated with the given bitmap type.
414 The bitmap type managed by the handler, see ::wxBitmapType.
416 @return A pointer to the handler if found, @NULL otherwise.
421 static wxBitmapHandler
* FindHandler(wxBitmapType bitmapType
);
424 Gets the colour depth of the bitmap.
425 A value of 1 indicates a monochrome bitmap.
427 virtual int GetDepth() const;
430 Returns the static list of bitmap format handlers.
434 static wxList
GetHandlers();
437 Gets the height of the bitmap in pixels.
439 virtual int GetHeight() const;
442 Gets the associated mask (if any) which may have been loaded from a file
443 or set for the bitmap.
445 @see SetMask(), wxMask
447 virtual wxMask
* GetMask() const;
450 Gets the associated palette (if any) which may have been loaded from a file
451 or set for the bitmap.
455 virtual wxPalette
* GetPalette() const;
458 Returns a sub bitmap of the current one as long as the rect belongs entirely to
459 the bitmap. This function preserves bit depth and mask information.
461 virtual wxBitmap
GetSubBitmap(const wxRect
& rect
) const;
464 Gets the width of the bitmap in pixels.
468 virtual int GetWidth() const;
471 Adds the standard bitmap format handlers, which, depending on wxWidgets
472 configuration, can be handlers for Windows bitmap, Windows bitmap resource,
475 This function is called by wxWidgets on startup.
479 static void InitStandardHandlers();
482 Adds a handler at the start of the static list of format handlers.
485 A new bitmap format handler object. There is usually only one instance
486 of a given handler class in an application session.
490 static void InsertHandler(wxBitmapHandler
* handler
);
493 Returns @true if bitmap data is present.
498 Loads a bitmap from a file or resource.
501 Either a filename or a Windows resource name.
502 The meaning of name is determined by the @a type parameter.
504 One of the ::wxBitmapType values; see the note in the class
505 detailed description.
506 Note that the wxBITMAP_DEFAULT_TYPE constant has different value under
507 different wxWidgets ports. See the bitmap.h header for the value it takes
510 @return @true if the operation succeeded, @false otherwise.
512 @remarks A palette may be associated with the bitmap if one exists
513 (especially for colour Windows bitmaps), and if the
514 code supports it. You can check if one has been created
515 by using the GetPalette() member.
519 virtual bool LoadFile(const wxString
& name
, wxBitmapType type
= wxBITMAP_DEFAULT_TYPE
);
522 Finds the handler with the given name, and removes it.
523 The handler is not deleted.
528 @return @true if the handler was found and removed, @false otherwise.
532 static bool RemoveHandler(const wxString
& name
);
535 Saves a bitmap in the named file.
538 A filename. The meaning of name is determined by the type parameter.
540 One of the ::wxBitmapType values; see the note in the class
541 detailed description.
543 An optional palette used for saving the bitmap.
545 @return @true if the operation succeeded, @false otherwise.
547 @remarks Depending on how wxWidgets has been configured, not all formats
552 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
,
553 const wxPalette
* palette
= NULL
) const;
556 Sets the depth member (does not affect the bitmap data).
558 @todo since these functions do not affect the bitmap data,
564 virtual void SetDepth(int depth
);
567 Sets the height member (does not affect the bitmap data).
570 Bitmap height in pixels.
572 virtual void SetHeight(int height
);
575 Sets the mask for this bitmap.
577 @remarks The bitmap object owns the mask once this has been called.
579 @see GetMask(), wxMask
581 virtual void SetMask(wxMask
* mask
);
584 Sets the associated palette. (Not implemented under GTK+).
591 virtual void SetPalette(const wxPalette
& palette
);
594 Sets the width member (does not affect the bitmap data).
597 Bitmap width in pixels.
599 virtual void SetWidth(int width
);
603 An empty wxBitmap object.
605 wxBitmap wxNullBitmap
;
613 This class encapsulates a monochrome mask bitmap, where the masked area is
614 black and the unmasked area is white.
616 When associated with a bitmap and drawn in a device context, the unmasked
617 area of the bitmap will be drawn, and the masked area will not be drawn.
622 @see wxBitmap, wxDC::Blit, wxMemoryDC
624 class wxMask
: public wxObject
634 Constructs a mask from a bitmap and a palette index that indicates the
636 Not yet implemented for GTK.
641 Index into a palette, specifying the transparency colour.
643 wxMask(const wxBitmap
& bitmap
, int index
);
646 Constructs a mask from a monochrome bitmap.
649 This is the default constructor for wxMask in wxPython.
652 wxMask(const wxBitmap
& bitmap
);
655 Constructs a mask from a bitmap and a colour that indicates the background.
658 wxPython has an alternate wxMask constructor matching this form called wxMaskColour.
661 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
664 Destroys the wxMask object and the underlying bitmap data.
669 Constructs a mask from a bitmap and a palette index that indicates the
671 Not yet implemented for GTK.
676 Index into a palette, specifying the transparency colour.
678 bool Create(const wxBitmap
& bitmap
, int index
);
681 Constructs a mask from a monochrome bitmap.
683 bool Create(const wxBitmap
& bitmap
);
686 Constructs a mask from a bitmap and a colour that indicates the background.
688 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);