1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmap class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #include "wx/palette.h"
18 class WXDLLEXPORT wxBitmap
;
19 class wxBitmapRefData
;
20 class WXDLLEXPORT wxBitmapHandler
;
21 class WXDLLEXPORT wxControl
;
22 class WXDLLEXPORT wxCursor
;
23 class WXDLLEXPORT wxDC
;
24 class WXDLLEXPORT wxIcon
;
25 class WXDLLEXPORT wxImage
;
26 class WXDLLEXPORT wxPixelDataBase
;
28 // A mask is a bitmap used for drawing bitmaps
29 // Internally it is stored as a 8 bit deep memory chunk, 0 = black means the source will be drawn
30 // 255 = white means the source will not be drawn, no other values will be present
31 // 8 bit is chosen only for performance reasons, note also that this is the inverse value range
32 // from alpha, where 0 = invisible , 255 = fully drawn
34 class WXDLLEXPORT wxMask
: public wxObject
36 DECLARE_DYNAMIC_CLASS(wxMask
)
42 wxMask(const wxMask
& mask
);
44 // Construct a mask from a bitmap and a colour indicating
45 // the transparent area
46 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
48 // Construct a mask from a mono bitmap (black meaning show pixels, white meaning transparent)
49 wxMask(const wxBitmap
& bitmap
);
51 // implementation helper only : construct a mask from a 32 bit memory buffer
52 wxMask(const wxMemoryBuffer
& buf
, int width
, int height
, int bytesPerRow
) ;
56 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
57 bool Create(const wxBitmap
& bitmap
);
58 bool Create(const wxMemoryBuffer
& buf
, int width
, int height
, int bytesPerRow
) ;
60 // Implementation below
65 void* GetRawAccess() const;
66 int GetBytesPerRow() const { return m_bytesPerRow
; }
67 // renders/updates native representation when necessary
68 void RealizeNative() ;
70 WXHBITMAP
GetHBITMAP() const ;
74 wxMemoryBuffer m_memBuf
;
79 WXHBITMAP m_maskBitmap
;
83 class WXDLLIMPEXP_CORE wxBitmapHandler
: public wxBitmapHandlerBase
85 DECLARE_ABSTRACT_CLASS(wxBitmapHandler
)
88 class WXDLLEXPORT wxBitmap
: public wxBitmapBase
90 DECLARE_DYNAMIC_CLASS(wxBitmap
)
92 friend class WXDLLEXPORT wxBitmapHandler
;
95 wxBitmap(); // Platform-specific
97 // Initialize with raw data.
98 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
100 // Initialize with XPM data
101 wxBitmap(const char* const* bits
);
103 // Load a file or resource
104 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_PICT_RESOURCE
);
106 // Constructor for generalised creation from data
107 wxBitmap(const void* data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
109 // If depth is omitted, will create a bitmap compatible with the display
110 wxBitmap(int width
, int height
, int depth
= -1);
112 // Convert from wxImage:
113 wxBitmap(const wxImage
& image
, int depth
= -1);
115 // Convert from wxIcon
116 wxBitmap(const wxIcon
& icon
) { CopyFromIcon(icon
); }
120 wxImage
ConvertToImage() const;
122 // get the given part of bitmap
123 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
125 virtual bool Create(int width
, int height
, int depth
= -1);
126 virtual bool Create(const void* data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
127 // virtual bool Create( WXHICON icon) ;
128 virtual bool LoadFile(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
129 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
, const wxPalette
*cmap
= NULL
) const;
131 wxBitmapRefData
*GetBitmapData() const
132 { return (wxBitmapRefData
*)m_refData
; }
134 // copies the contents and mask of the given (colour) icon to the bitmap
135 virtual bool CopyFromIcon(const wxIcon
& icon
);
137 bool Ok() const { return IsOk(); }
139 int GetWidth() const;
140 int GetHeight() const;
141 int GetDepth() const;
142 void SetWidth(int w
);
143 void SetHeight(int h
);
144 void SetDepth(int d
);
145 void SetOk(bool isOk
);
147 #if WXWIN_COMPATIBILITY_2_4
148 // these functions do nothing and are only there for backwards
150 wxDEPRECATED( int GetQuality() const );
151 wxDEPRECATED( void SetQuality(int quality
) );
152 #endif // WXWIN_COMPATIBILITY_2_4
155 wxPalette
* GetPalette() const;
156 void SetPalette(const wxPalette
& palette
);
157 #endif // wxUSE_PALETTE
159 wxMask
*GetMask() const;
160 void SetMask(wxMask
*mask
) ;
162 static void InitStandardHandlers();
164 // raw bitmap access support functions, for internal use only
165 void *GetRawData(wxPixelDataBase
& data
, int bpp
);
166 void UngetRawData(wxPixelDataBase
& data
);
168 // these functions are internal and shouldn't be used, they risk to
169 // disappear in the future
170 bool HasAlpha() const;
173 // returns the 'native' implementation, a GWorldPtr for the content and one for the mask
174 WXHBITMAP
GetHBITMAP( WXHBITMAP
* mask
= NULL
) const;
177 // returns a CGImageRef which must released after usage with CGImageRelease
178 WXCGIMAGEREF
CGImageCreate() const ;
180 // get read only access to the underlying buffer
181 void *GetRawAccess() const ;
182 // brackets to the underlying OS structure for read/write access
183 // makes sure that no cached images will be constructed until terminated
184 void *BeginRawAccess() ;
185 void EndRawAccess() ;
189 virtual wxObjectRefData
*CreateRefData() const;
190 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;