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 WXDLLEXPORT wxBitmapHandler
;
24 class WXDLLEXPORT wxControl
;
25 class WXDLLEXPORT wxCursor
;
26 class WXDLLEXPORT wxDC
;
27 class WXDLLEXPORT wxIcon
;
28 class WXDLLEXPORT wxImage
;
29 class WXDLLEXPORT wxPixelDataBase
;
31 // A mask is a bitmap used for drawing bitmaps
32 // it can be a monochrome bitmap or a multi-bit bitmap which transfers to alpha channels
34 class WXDLLEXPORT wxMask
: public wxObject
36 DECLARE_DYNAMIC_CLASS(wxMask
)
37 DECLARE_NO_COPY_CLASS(wxMask
)
42 // Construct a mask from a bitmap and a colour indicating
43 // the transparent area
44 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
46 // Construct a mask from a bitmap and a palette index indicating
47 // the transparent area
48 wxMask(const wxBitmap
& bitmap
, int paletteIndex
);
50 // Construct a mask from a mono bitmap (copies the bitmap).
51 wxMask(const wxBitmap
& bitmap
);
55 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
56 bool Create(const wxBitmap
& bitmap
, int paletteIndex
);
57 bool Create(const wxBitmap
& bitmap
);
60 bool PointMasked(int x
, int y
);
61 inline WXHBITMAP
GetMaskBitmap() const { return m_maskBitmap
; }
62 inline void SetMaskBitmap(WXHBITMAP bmp
) { m_maskBitmap
= bmp
; }
63 int GetDepth() const { return m_depth
; }
64 void SetDepth( int depth
) { m_depth
= depth
; }
66 WXHBITMAP m_maskBitmap
;
70 enum { kMacBitmapTypeUnknownType
, kMacBitmapTypeGrafWorld
, kMacBitmapTypePict
, kMacBitmapTypeIcon
} ;
72 class WXDLLEXPORT wxBitmapRefData
: public wxGDIRefData
74 DECLARE_NO_COPY_CLASS(wxBitmapRefData
)
76 friend class WXDLLEXPORT wxBitmap
;
77 friend class WXDLLEXPORT wxIcon
;
78 friend class WXDLLEXPORT wxCursor
;
90 wxPalette m_bitmapPalette
;
91 #endif // wxUSE_PALETTE
98 wxMask
* m_bitmapMask
; // Optional mask
102 #define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
104 class WXDLLEXPORT wxBitmapHandler
: public wxBitmapHandlerBase
107 wxBitmapHandler() { }
108 virtual ~wxBitmapHandler();
110 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
111 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
112 int desiredWidth
, int desiredHeight
);
113 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
116 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
119 #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
121 class WXDLLEXPORT wxBitmap
: public wxBitmapBase
123 DECLARE_DYNAMIC_CLASS(wxBitmap
)
125 friend class WXDLLEXPORT wxBitmapHandler
;
128 wxBitmap(); // Platform-specific
131 wxBitmap(const wxBitmap
& bitmap
)
135 // Initialize with raw data.
136 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
138 // Initialize with XPM data
139 bool CreateFromXpm(const char **bits
);
140 wxBitmap(const char **bits
);
141 wxBitmap(char **bits
);
143 // Load a file or resource
144 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_PICT_RESOURCE
);
146 // Constructor for generalised creation from data
147 wxBitmap(void *data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
149 // If depth is omitted, will create a bitmap compatible with the display
150 wxBitmap(int width
, int height
, int depth
= -1);
152 // Convert from wxImage:
153 wxBitmap(const wxImage
& image
, int depth
= -1);
157 wxImage
ConvertToImage() const;
159 // get the given part of bitmap
160 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
162 virtual bool Create(int width
, int height
, int depth
= -1);
163 virtual bool Create(void *data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
164 virtual bool LoadFile(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
165 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
, const wxPalette
*cmap
= NULL
) const;
167 // copies the contents and mask of the given (colour) icon to the bitmap
168 virtual bool CopyFromIcon(const wxIcon
& icon
);
171 int GetWidth() const;
172 int GetHeight() const;
173 int GetDepth() const;
174 int GetQuality() const;
175 void SetWidth(int w
);
176 void SetHeight(int h
);
177 void SetDepth(int d
);
178 void SetQuality(int q
);
179 void SetOk(bool isOk
);
182 wxPalette
* GetPalette() const;
183 void SetPalette(const wxPalette
& palette
);
184 #endif // wxUSE_PALETTE
186 wxMask
*GetMask() const;
187 void SetMask(wxMask
*mask
) ;
189 int GetBitmapType() const;
191 inline wxBitmap
& operator = (const wxBitmap
& bitmap
) { if (*this == bitmap
) return (*this); Ref(bitmap
); return *this; }
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
);