1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmap class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "bitmap.h"
19 #include "wx/palette.h"
22 class WXDLLEXPORT wxBitmap
;
23 class wxBitmapRefData
;
24 class WXDLLEXPORT wxBitmapHandler
;
25 class WXDLLEXPORT wxControl
;
26 class WXDLLEXPORT wxCursor
;
27 class WXDLLEXPORT wxDC
;
28 class WXDLLEXPORT wxIcon
;
29 class WXDLLEXPORT wxImage
;
30 class WXDLLEXPORT wxPixelDataBase
;
32 // A mask is a bitmap used for drawing bitmaps
33 // Internally it is stored as a 8 bit deep memory chunk, 0 = black means the source will be drawn
34 // 255 = white means the source will not be drawn, no other values will be present
35 // 8 bit is chosen only for performance reasons, note also that this is the inverse value range
36 // from alpha, where 0 = invisible , 255 = fully drawn
38 class WXDLLEXPORT wxMask
: public wxObject
40 DECLARE_DYNAMIC_CLASS(wxMask
)
41 DECLARE_NO_COPY_CLASS(wxMask
)
46 // Construct a mask from a bitmap and a colour indicating
47 // the transparent area
48 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
50 // Construct a mask from a mono bitmap (black meaning show pixels, white meaning transparent)
51 wxMask(const wxBitmap
& bitmap
);
53 // implementation helper only : construct a mask from a 8 bit memory buffer
54 wxMask(const wxMemoryBuffer
& buf
, int width
, int height
, int bytesPerRow
) ;
58 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
59 bool Create(const wxBitmap
& bitmap
);
60 bool Create(const wxMemoryBuffer
& buf
, int width
, int height
, int bytesPerRow
) ;
62 // Implementation below
67 void* GetRawAccess() const;
68 int GetBytesPerRow() const { return m_bytesPerRow
; }
69 // renders/updates native representation when necessary
70 void RealizeNative() ;
72 WXHBITMAP
GetHBITMAP() const ;
76 wxMemoryBuffer m_memBuf
;
81 WXHBITMAP m_maskBitmap
;
85 class WXDLLEXPORT wxBitmapHandler
: public wxBitmapHandlerBase
89 virtual ~wxBitmapHandler();
91 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
92 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
93 int desiredWidth
, int desiredHeight
);
94 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
97 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
100 #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
102 class WXDLLEXPORT wxBitmap
: public wxBitmapBase
104 DECLARE_DYNAMIC_CLASS(wxBitmap
)
106 friend class WXDLLEXPORT wxBitmapHandler
;
109 wxBitmap(); // Platform-specific
112 wxBitmap(const wxBitmap
& bitmap
)
115 // Initialize with raw data.
116 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
118 // Initialize with XPM data
119 bool CreateFromXpm(const char **bits
);
120 wxBitmap(const char **bits
);
121 wxBitmap(char **bits
);
123 // Load a file or resource
124 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_PICT_RESOURCE
);
126 // Constructor for generalised creation from data
127 wxBitmap(void *data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
129 // If depth is omitted, will create a bitmap compatible with the display
130 wxBitmap(int width
, int height
, int depth
= -1);
132 // Convert from wxImage:
133 wxBitmap(const wxImage
& image
, int depth
= -1);
135 // Convert from wxIcon
136 wxBitmap(const wxIcon
& icon
) { CopyFromIcon(icon
); }
140 wxImage
ConvertToImage() const;
142 // get the given part of bitmap
143 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
145 virtual bool Create(int width
, int height
, int depth
= -1);
146 virtual bool Create(void *data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
147 // virtual bool Create( WXHICON icon) ;
148 virtual bool LoadFile(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
149 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
, const wxPalette
*cmap
= NULL
) const;
151 wxBitmapRefData
*GetBitmapData() const
152 { return (wxBitmapRefData
*)m_refData
; }
154 // copies the contents and mask of the given (colour) icon to the bitmap
155 virtual bool CopyFromIcon(const wxIcon
& icon
);
158 int GetWidth() const;
159 int GetHeight() const;
160 int GetDepth() const;
161 void SetWidth(int w
);
162 void SetHeight(int h
);
163 void SetDepth(int d
);
164 void SetOk(bool isOk
);
166 #if WXWIN_COMPATIBILITY_2_4
167 // these functions do nothing and are only there for backwards
169 wxDEPRECATED( int GetQuality() const );
170 wxDEPRECATED( void SetQuality(int quality
) );
171 #endif // WXWIN_COMPATIBILITY_2_4
174 wxPalette
* GetPalette() const;
175 void SetPalette(const wxPalette
& palette
);
176 #endif // wxUSE_PALETTE
178 wxMask
*GetMask() const;
179 void SetMask(wxMask
*mask
) ;
181 inline wxBitmap
& operator = (const wxBitmap
& bitmap
) { if (*this == bitmap
) return (*this); Ref(bitmap
); return *this; }
182 inline bool operator == (const wxBitmap
& bitmap
) const { return m_refData
== bitmap
.m_refData
; }
183 inline bool operator != (const wxBitmap
& bitmap
) const { return m_refData
!= bitmap
.m_refData
; }
185 static void InitStandardHandlers();
187 // raw bitmap access support functions, for internal use only
188 void *GetRawData(wxPixelDataBase
& data
, int bpp
);
189 void UngetRawData(wxPixelDataBase
& data
);
191 // these functions are internal and shouldn't be used, they risk to
192 // disappear in the future
193 bool HasAlpha() const;
196 // returns the 'native' implementation, a GWorldPtr for the content and one for the mask
197 WXHBITMAP
GetHBITMAP( WXHBITMAP
* mask
= NULL
) const;
200 // returns a CGImageRef which must released after usage with CGImageRelease
201 WXCGIMAGEREF
CGImageCreate() const ;
203 // get read only access to the underlying buffer
204 void *GetRawAccess() const ;
205 // brackets to the underlying OS structure for read/write access
206 // makes sure that no cached images will be constructed until terminated
207 void *BeginRawAccess() ;
208 void EndRawAccess() ;