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 WXDLLEXPORT wxBitmapHandler
;
20 class WXDLLEXPORT wxControl
;
21 class WXDLLEXPORT wxCursor
;
22 class WXDLLEXPORT wxDC
;
23 class WXDLLEXPORT wxIcon
;
24 class WXDLLEXPORT wxImage
;
25 class WXDLLEXPORT wxPixelDataBase
;
27 // A mask is a bitmap used for drawing bitmaps
28 // it can be a monochrome bitmap or a multi-bit bitmap which transfers to alpha channels
30 class WXDLLEXPORT wxMask
: public wxObject
32 DECLARE_DYNAMIC_CLASS(wxMask
)
33 DECLARE_NO_COPY_CLASS(wxMask
)
38 // Construct a mask from a bitmap and a colour indicating
39 // the transparent area
40 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
42 // Construct a mask from a bitmap and a palette index indicating
43 // the transparent area
44 wxMask(const wxBitmap
& bitmap
, int paletteIndex
);
46 // Construct a mask from a mono bitmap (copies the bitmap).
47 wxMask(const wxBitmap
& bitmap
);
51 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
52 bool Create(const wxBitmap
& bitmap
, int paletteIndex
);
53 bool Create(const wxBitmap
& bitmap
);
56 bool PointMasked(int x
, int y
);
57 inline WXHBITMAP
GetMaskBitmap() const { return m_maskBitmap
; }
58 inline void SetMaskBitmap(WXHBITMAP bmp
) { m_maskBitmap
= bmp
; }
59 int GetDepth() const { return m_depth
; }
60 void SetDepth( int depth
) { m_depth
= depth
; }
62 WXHBITMAP m_maskBitmap
;
66 enum { kMacBitmapTypeUnknownType
, kMacBitmapTypeGrafWorld
, kMacBitmapTypePict
, kMacBitmapTypeIcon
} ;
68 class WXDLLEXPORT wxBitmapRefData
: public wxGDIRefData
70 DECLARE_NO_COPY_CLASS(wxBitmapRefData
)
72 friend class WXDLLEXPORT wxBitmap
;
73 friend class WXDLLEXPORT wxIcon
;
74 friend class WXDLLEXPORT wxCursor
;
86 wxPalette m_bitmapPalette
;
87 #endif // wxUSE_PALETTE
94 wxMask
* m_bitmapMask
; // Optional mask
98 #define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
100 class WXDLLEXPORT wxBitmapHandler
: public wxBitmapHandlerBase
102 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
104 wxBitmapHandler() : m_name(), m_extension(), m_type(0) { }
105 virtual ~wxBitmapHandler();
107 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
108 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
109 int desiredWidth
, int desiredHeight
);
110 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
112 void SetName(const wxString
& name
) { m_name
= name
; }
113 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
114 void SetType(long type
) { m_type
= type
; }
115 wxString
GetName() const { return m_name
; }
116 wxString
GetExtension() const { return m_extension
; }
117 long GetType() const { return m_type
; }
121 wxString m_extension
;
125 #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
127 class WXDLLEXPORT wxBitmap
: public wxBitmapBase
129 DECLARE_DYNAMIC_CLASS(wxBitmap
)
131 friend class WXDLLEXPORT wxBitmapHandler
;
134 wxBitmap(); // Platform-specific
136 // Initialize with raw data.
137 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
139 // Initialize with XPM data
140 bool CreateFromXpm(const char **bits
);
141 wxBitmap(const char **bits
);
142 wxBitmap(char **bits
);
144 // Load a file or resource
145 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_PICT_RESOURCE
);
147 // Constructor for generalised creation from data
148 wxBitmap(void *data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
150 // If depth is omitted, will create a bitmap compatible with the display
151 wxBitmap(int width
, int height
, int depth
= -1);
153 // Convert from wxImage:
154 wxBitmap(const wxImage
& image
, int depth
= -1);
158 wxImage
ConvertToImage() const;
160 // get the given part of bitmap
161 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
163 virtual bool Create(int width
, int height
, int depth
= -1);
164 virtual bool Create(void *data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
165 virtual bool LoadFile(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
166 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
, const wxPalette
*cmap
= NULL
) const;
168 // copies the contents and mask of the given (colour) icon to the bitmap
169 virtual bool CopyFromIcon(const wxIcon
& icon
);
172 int GetWidth() const;
173 int GetHeight() const;
174 int GetDepth() const;
175 int GetQuality() const;
176 void SetWidth(int w
);
177 void SetHeight(int h
);
178 void SetDepth(int d
);
179 void SetQuality(int q
);
180 void SetOk(bool isOk
);
183 wxPalette
* GetPalette() const;
184 void SetPalette(const wxPalette
& palette
);
185 #endif // wxUSE_PALETTE
187 wxMask
*GetMask() const;
188 void SetMask(wxMask
*mask
) ;
190 int GetBitmapType() const;
192 inline bool operator == (const wxBitmap
& bitmap
) const { return m_refData
== bitmap
.m_refData
; }
193 inline bool operator != (const wxBitmap
& bitmap
) const { return m_refData
!= bitmap
.m_refData
; }
195 static void InitStandardHandlers();
197 // raw bitmap access support functions, for internal use only
198 void *GetRawData(wxPixelDataBase
& data
, int bpp
);
199 void UngetRawData(wxPixelDataBase
& data
);
204 WXHBITMAP
GetHBITMAP() const;
205 inline WXHICON
GetHICON() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_hIcon
: 0); }
206 WXHMETAFILE
GetPict(bool *created
= NULL
) const;
208 void SetHBITMAP(WXHBITMAP bmp
);
209 void SetHICON(WXHICON ico
);
210 void SetPict( WXHMETAFILE pict
) ;
212 bool FreeResource(bool force
= FALSE
);