]>
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.
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 @returns @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
= wxBITMAP_SCREEN_DEPTH
);
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 @returns @true if the operation succeeded, @false otherwise.
101 @see wxBitmap::LoadFile, wxBitmap::SaveFile, SaveFile()
103 bool LoadFile(wxBitmap
* bitmap
, const wxString
& name
, wxBitmapType type
);
106 Saves a bitmap in the named file.
109 The bitmap object which is to be affected by this operation.
111 A filename. The meaning of name is determined by the type parameter.
113 See ::wxBitmapType for values this can take.
115 An optional palette used for saving the bitmap.
117 @returns @true if the operation succeeded, @false otherwise.
119 @see wxBitmap::LoadFile, wxBitmap::SaveFile, LoadFile()
121 bool SaveFile(wxBitmap
* bitmap
, const wxString
& name
, wxBitmapType 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.
146 void SetType(wxBitmapType type
);
154 This class encapsulates the concept of a platform-dependent bitmap,
155 either monochrome or colour or colour with alpha channel support.
158 Many wxBitmap functions take a @e type parameter, which is a value of the
159 ::wxBitmapType enumeration.
160 The validity of those values depends however on the platform where your program
161 is running and from the wxWidgets configuration.
162 If all possible wxWidgets settings are used, the Windows platform supports BMP file,
163 BMP resource, XPM data, and XPM.
164 Under wxGTK, the available formats are BMP file, XPM data, XPM file, and PNG file.
165 Under wxMotif, the available formats are XBM data, XBM file, XPM data, XPM file.
166 In addition, wxBitmap can load and save all formats that wxImage; see wxImage for
167 more info. Of course, you must have wxImage handlers loaded.
175 @see @ref overview_bitmap, @ref overview_bitmap_supportedformats,
176 wxDC::Blit, wxIcon, wxCursor, wxBitmap, wxMemoryDC
178 class wxBitmap
: public wxGDIObject
184 Constructs a bitmap object with no data; an assignment or another member
185 function such as Create() or LoadFile() must be called subsequently.
190 Copy constructor, uses @ref overview_refcount "reference counting".
191 To make a real copy, you can use:
194 wxBitmap newBitmap = oldBitmap.GetSubBitmap(
195 wxRect(0, 0, oldBitmap.GetWidth(), oldBitmap.GetHeight()));
198 wxBitmap(const wxBitmap
& bitmap
);
202 Creates a bitmap from the given @a data which is interpreted in
203 platform-dependent manner.
206 Specifies the bitmap data in a platform-dependent format.
208 May be one of the ::wxBitmapType values and indicates which type of
209 bitmap does @a data contains. See the note in the class
210 detailed description.
212 Specifies the width of the bitmap.
214 Specifies the height of the bitmap.
216 Specifies the depth of the bitmap.
217 If this is omitted, the display depth of the screen is used.
218 wxBitmap(const void* data, int type, int width, int height, int depth = -1);
221 NOTE: this ctor is not implemented by all port, is somewhat useless
222 without further description of the "data" supported formats and
223 uses 'int type' instead of wxBitmapType, so don't document it.
227 Creates a bitmap from the given array @a bits.
228 You should only use this function for monochrome bitmaps (depth 1) in
229 portable programs: in this case the bits parameter should contain an XBM image.
231 For other bit depths, the behaviour is platform dependent: under Windows,
232 the data is passed without any changes to the underlying CreateBitmap() API.
233 Under other platforms, only monochrome bitmaps may be created using this
234 constructor and wxImage should be used for creating colour bitmaps from
238 Specifies an array of pixel values.
240 Specifies the width of the bitmap.
242 Specifies the height of the bitmap.
244 Specifies the depth of the bitmap.
245 If this is omitted, then a value of 1 (monochrome bitmap) is used.
247 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
250 Creates a new bitmap. A depth of ::wxBITMAP_SCREEN_DEPTH indicates the
251 depth of the current screen or visual.
252 Some platforms only support 1 for monochrome and ::wxBITMAP_SCREEN_DEPTH for
253 the current colour setting.
255 A depth of 32 including an alpha channel is supported under MSW, Mac and GTK+.
257 wxBitmap(int width
, int height
, int depth
= wxBITMAP_SCREEN_DEPTH
);
260 Creates a bitmap from XPM data.
262 wxBitmap(const char* const* bits
);
265 Loads a bitmap from a file or resource.
268 This can refer to a resource name or a filename under MS Windows and X.
269 Its meaning is determined by the @a type parameter.
271 May be one of the ::wxBitmapType values and indicates which type of
272 bitmap should be loaded. See the note in the class detailed description.
276 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_XPM
);
279 Creates this bitmap object from the given image.
280 This has to be done to actually display an image as you cannot draw an
281 image directly on a window.
283 The resulting bitmap will use the provided colour depth (or that of the
284 current system if depth is ::wxBITMAP_SCREEN_DEPTH) which entails that a
285 colour reduction may take place.
287 When in 8-bit mode (PseudoColour mode), the GTK port will use a color cube
288 created on program start-up to look up colors. This ensures a very fast conversion,
289 but the image quality won't be perfect (and could be better for photo images using
290 more sophisticated dithering algorithms).
292 On Windows, if there is a palette present (set with SetPalette), it will be
293 used when creating the wxBitmap (most useful in 8-bit display mode).
294 On other platforms, the palette is currently ignored.
297 Platform-independent wxImage object.
299 Specifies the depth of the bitmap.
300 If this is omitted, the display depth of the screen is used.
302 wxBitmap(const wxImage
& img
, int depth
= wxBITMAP_SCREEN_DEPTH
);
306 See @ref overview_refcount_destruct for more info.
308 If the application omits to delete the bitmap explicitly, the bitmap will be
309 destroyed automatically by wxWidgets when the application exits.
312 Do not delete a bitmap that is selected into a memory device context.
317 Adds a handler to the end of the static list of format handlers.
320 A new bitmap format handler object. There is usually only one instance
321 of a given handler class in an application session.
325 static void AddHandler(wxBitmapHandler
* handler
);
328 Deletes all bitmap handlers.
329 This function is called by wxWidgets on exit.
331 static void CleanUpHandlers();
334 Creates an image from a platform-dependent bitmap. This preserves
335 mask information so that bitmaps and images can be converted back
336 and forth without loss in that respect.
338 wxImage
ConvertToImage();
341 Creates the bitmap from an icon.
343 bool CopyFromIcon(const wxIcon
& icon
);
346 Creates a fresh bitmap.
347 If the final argument is omitted, the display depth of the screen is used.
349 This overload works on all platforms.
351 virtual bool Create(int width
, int height
, int depth
= wxBITMAP_SCREEN_DEPTH
);
354 Creates a bitmap from the given data, which can be of arbitrary type.
357 Data whose type depends on the value of type.
359 A bitmap type identifier; see ::wxBitmapType for the list of values.
360 See the note in the class detailed description for more info.
362 The width of the bitmap in pixels.
364 The height of the bitmap in pixels.
366 The depth of the bitmap in pixels. If this is -1, the screen depth is used.
368 @returns @true if the call succeeded, @false otherwise.
370 This overload depends on the @a type of data.
372 virtual bool Create(const void* data, int type, int width,
373 int height, int depth = -1);
375 NOTE: leave this undoc for the same reason of the relative ctor.
379 Finds the handler with the given @a name.
381 @returns A pointer to the handler if found, @NULL otherwise.
383 static wxBitmapHandler
* FindHandler(const wxString
& name
);
386 Finds the handler associated with the given @a extension and @a type.
389 The file extension, such as "bmp" (without the dot).
391 The bitmap type managed by the handler, see ::wxBitmapType.
393 @returns A pointer to the handler if found, @NULL otherwise.
395 static wxBitmapHandler
* FindHandler(const wxString
& extension
,
396 wxBitmapType bitmapType
);
399 Finds the handler associated with the given bitmap type.
402 The bitmap type managed by the handler, see ::wxBitmapType.
404 @returns A pointer to the handler if found, @NULL otherwise.
409 static wxBitmapHandler
* FindHandler(wxBitmapType bitmapType
);
412 Gets the colour depth of the bitmap.
413 A value of 1 indicates a monochrome bitmap.
415 int GetDepth() const;
418 Returns the static list of bitmap format handlers.
422 static wxList
GetHandlers();
425 Gets the height of the bitmap in pixels.
427 int GetHeight() const;
430 Gets the associated mask (if any) which may have been loaded from a file
431 or set for the bitmap.
433 @see SetMask(), wxMask
435 wxMask
* GetMask() const;
438 Gets the associated palette (if any) which may have been loaded from a file
439 or set for the bitmap.
443 wxPalette
* GetPalette() const;
446 Returns a sub bitmap of the current one as long as the rect belongs entirely to
447 the bitmap. This function preserves bit depth and mask information.
449 wxBitmap
GetSubBitmap(const wxRect
& rect
) const;
452 Gets the width of the bitmap in pixels.
456 int GetWidth() const;
459 Adds the standard bitmap format handlers, which, depending on wxWidgets
460 configuration, can be handlers for Windows bitmap, Windows bitmap resource,
463 This function is called by wxWidgets on startup.
467 static void InitStandardHandlers();
470 Adds a handler at the start of the static list of format handlers.
473 A new bitmap format handler object. There is usually only one instance
474 of a given handler class in an application session.
478 static void InsertHandler(wxBitmapHandler
* handler
);
481 Returns @true if bitmap data is present.
486 Loads a bitmap from a file or resource.
489 Either a filename or a Windows resource name.
490 The meaning of name is determined by the @a type parameter.
492 One of the ::wxBitmapType values; see the note in the class
493 detailed description.
495 @returns @true if the operation succeeded, @false otherwise.
497 @remarks A palette may be associated with the bitmap if one exists
498 (especially for colour Windows bitmaps), and if the
499 code supports it. You can check if one has been created
500 by using the GetPalette() member.
504 bool LoadFile(const wxString
& name
, wxBitmapType type
);
507 Finds the handler with the given name, and removes it.
508 The handler is not deleted.
513 @returns @true if the handler was found and removed, @false otherwise.
517 static bool RemoveHandler(const wxString
& name
);
520 Saves a bitmap in the named file.
523 A filename. The meaning of name is determined by the type parameter.
525 One of the ::wxBitmapType values; see the note in the class
526 detailed description.
528 An optional palette used for saving the bitmap.
530 @returns @true if the operation succeeded, @false otherwise.
532 @remarks Depending on how wxWidgets has been configured, not all formats
537 bool SaveFile(const wxString
& name
, wxBitmapType type
,
538 const wxPalette
* palette
= NULL
);
541 Sets the depth member (does not affect the bitmap data).
543 @todo since these functions do not affect the bitmap data,
549 void SetDepth(int depth
);
552 Sets the height member (does not affect the bitmap data).
555 Bitmap height in pixels.
557 void SetHeight(int height
);
560 Sets the mask for this bitmap.
562 @remarks The bitmap object owns the mask once this has been called.
564 @see GetMask(), wxMask
566 void SetMask(wxMask
* mask
);
569 Sets the associated palette. (Not implemented under GTK+).
576 void SetPalette(const wxPalette
& palette
);
579 Sets the width member (does not affect the bitmap data).
582 Bitmap width in pixels.
584 void SetWidth(int width
);
587 Assignment operator, using @ref overview_refcount "reference counting".
592 wxBitmap
operator =(const wxBitmap
& bitmap
);
596 An empty wxBitmap object.
598 wxBitmap wxNullBitmap
;
607 This class encapsulates a monochrome mask bitmap, where the masked area is
608 black and the unmasked area is white.
610 When associated with a bitmap and drawn in a device context, the unmasked
611 area of the bitmap will be drawn, and the masked area will not be drawn.
616 @see wxBitmap, wxDC::Blit, wxMemoryDC
618 class wxMask
: public wxObject
628 Constructs a mask from a bitmap and a palette index that indicates the
630 Not yet implemented for GTK.
635 Index into a palette, specifying the transparency colour.
637 wxMask(const wxBitmap
& bitmap
, int index
);
640 Constructs a mask from a monochrome bitmap.
643 This is the default constructor for wxMask in wxPython.
646 wxMask(const wxBitmap
& bitmap
);
649 Constructs a mask from a bitmap and a colour that indicates the background.
652 wxPython has an alternate wxMask constructor matching this form called wxMaskColour.
655 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
658 Destroys the wxMask object and the underlying bitmap data.
663 Constructs a mask from a bitmap and a palette index that indicates the
665 Not yet implemented for GTK.
670 Index into a palette, specifying the transparency colour.
672 bool Create(const wxBitmap
& bitmap
, int index
);
675 Constructs a mask from a monochrome bitmap.
677 bool Create(const wxBitmap
& bitmap
);
680 Constructs a mask from a bitmap and a colour that indicates the background.
682 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);