]>
Commit | Line | Data |
---|---|---|
52479aef SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: bitmap.h | |
3 | // Purpose: wxBitmap class | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
65571936 | 9 | // Licence: wxWindows licence |
52479aef SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_BITMAP_H_ | |
13 | #define _WX_BITMAP_H_ | |
14 | ||
52479aef SC |
15 | #include "wx/palette.h" |
16 | ||
17 | // Bitmap | |
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; | |
26 | ||
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 | |
29 | // transparently. | |
30 | class WXDLLEXPORT wxMask: public wxObject | |
31 | { | |
32 | DECLARE_DYNAMIC_CLASS(wxMask) | |
33 | DECLARE_NO_COPY_CLASS(wxMask) | |
34 | ||
35 | public: | |
36 | wxMask(); | |
37 | ||
38 | // Construct a mask from a bitmap and a colour indicating | |
39 | // the transparent area | |
40 | wxMask(const wxBitmap& bitmap, const wxColour& colour); | |
41 | ||
42 | // Construct a mask from a bitmap and a palette index indicating | |
43 | // the transparent area | |
44 | wxMask(const wxBitmap& bitmap, int paletteIndex); | |
45 | ||
46 | // Construct a mask from a mono bitmap (copies the bitmap). | |
47 | wxMask(const wxBitmap& bitmap); | |
48 | ||
49 | ~wxMask(); | |
50 | ||
51 | bool Create(const wxBitmap& bitmap, const wxColour& colour); | |
52 | bool Create(const wxBitmap& bitmap, int paletteIndex); | |
53 | bool Create(const wxBitmap& bitmap); | |
54 | ||
55 | // Implementation | |
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 ; } | |
61 | protected: | |
62 | WXHBITMAP m_maskBitmap; | |
63 | int m_depth ; | |
64 | }; | |
65 | ||
66 | enum { kMacBitmapTypeUnknownType , kMacBitmapTypeGrafWorld, kMacBitmapTypePict , kMacBitmapTypeIcon } ; | |
67 | ||
68 | class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData | |
69 | { | |
70 | DECLARE_NO_COPY_CLASS(wxBitmapRefData) | |
71 | ||
72 | friend class WXDLLEXPORT wxBitmap; | |
73 | friend class WXDLLEXPORT wxIcon; | |
74 | friend class WXDLLEXPORT wxCursor; | |
75 | public: | |
76 | wxBitmapRefData(); | |
77 | ~wxBitmapRefData(); | |
78 | ||
79 | public: | |
80 | int m_width; | |
81 | int m_height; | |
82 | int m_depth; | |
83 | bool m_ok; | |
84 | int m_numColors; | |
85 | #if wxUSE_PALETTE | |
86 | wxPalette m_bitmapPalette; | |
87 | #endif // wxUSE_PALETTE | |
88 | int m_quality; | |
89 | ||
90 | int m_bitmapType ; | |
91 | WXHMETAFILE m_hPict ; | |
92 | WXHBITMAP m_hBitmap; | |
93 | WXHICON m_hIcon ; | |
94 | wxMask * m_bitmapMask; // Optional mask | |
95 | bool m_hasAlpha; | |
96 | }; | |
97 | ||
98 | #define M_BITMAPDATA ((wxBitmapRefData *)m_refData) | |
99 | ||
100 | class WXDLLEXPORT wxBitmapHandler: public wxBitmapHandlerBase | |
101 | { | |
102 | DECLARE_DYNAMIC_CLASS(wxBitmapHandler) | |
103 | public: | |
104 | wxBitmapHandler() : m_name(), m_extension(), m_type(0) { } | |
105 | virtual ~wxBitmapHandler(); | |
106 | ||
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); | |
111 | ||
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; } | |
118 | ||
119 | protected: | |
120 | wxString m_name; | |
121 | wxString m_extension; | |
122 | long m_type; | |
123 | }; | |
124 | ||
125 | #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData()) | |
126 | ||
127 | class WXDLLEXPORT wxBitmap: public wxBitmapBase | |
128 | { | |
129 | DECLARE_DYNAMIC_CLASS(wxBitmap) | |
130 | ||
131 | friend class WXDLLEXPORT wxBitmapHandler; | |
132 | ||
133 | public: | |
134 | wxBitmap(); // Platform-specific | |
135 | ||
136 | // Copy constructors | |
137 | wxBitmap(const wxBitmap& bitmap) | |
138 | : wxBitmapBase() | |
139 | { Ref(bitmap); } | |
140 | ||
141 | // Initialize with raw data. | |
142 | wxBitmap(const char bits[], int width, int height, int depth = 1); | |
143 | ||
144 | // Initialize with XPM data | |
145 | bool CreateFromXpm(const char **bits); | |
146 | wxBitmap(const char **bits); | |
147 | wxBitmap(char **bits); | |
148 | ||
149 | // Load a file or resource | |
150 | wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_PICT_RESOURCE); | |
151 | ||
152 | // Constructor for generalised creation from data | |
153 | wxBitmap(void *data, wxBitmapType type, int width, int height, int depth = 1); | |
154 | ||
155 | // If depth is omitted, will create a bitmap compatible with the display | |
156 | wxBitmap(int width, int height, int depth = -1); | |
157 | ||
158 | // Convert from wxImage: | |
159 | wxBitmap(const wxImage& image, int depth = -1); | |
160 | ||
161 | ~wxBitmap(); | |
162 | ||
163 | wxImage ConvertToImage() const; | |
164 | ||
165 | // get the given part of bitmap | |
166 | wxBitmap GetSubBitmap( const wxRect& rect ) const; | |
167 | ||
168 | virtual bool Create(int width, int height, int depth = -1); | |
169 | virtual bool Create(void *data, wxBitmapType type, int width, int height, int depth = 1); | |
170 | virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE); | |
171 | virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const; | |
172 | ||
173 | // copies the contents and mask of the given (colour) icon to the bitmap | |
174 | virtual bool CopyFromIcon(const wxIcon& icon); | |
175 | ||
176 | bool Ok() const; | |
177 | int GetWidth() const; | |
178 | int GetHeight() const; | |
179 | int GetDepth() const; | |
180 | int GetQuality() const; | |
181 | void SetWidth(int w); | |
182 | void SetHeight(int h); | |
183 | void SetDepth(int d); | |
184 | void SetQuality(int q); | |
185 | void SetOk(bool isOk); | |
186 | ||
187 | #if wxUSE_PALETTE | |
188 | wxPalette* GetPalette() const; | |
189 | void SetPalette(const wxPalette& palette); | |
190 | #endif // wxUSE_PALETTE | |
191 | ||
192 | wxMask *GetMask() const; | |
193 | void SetMask(wxMask *mask) ; | |
194 | ||
195 | int GetBitmapType() const; | |
196 | ||
197 | inline wxBitmap& operator = (const wxBitmap& bitmap) { if (*this == bitmap) return (*this); Ref(bitmap); return *this; } | |
198 | inline bool operator == (const wxBitmap& bitmap) const { return m_refData == bitmap.m_refData; } | |
199 | inline bool operator != (const wxBitmap& bitmap) const { return m_refData != bitmap.m_refData; } | |
200 | ||
201 | static void InitStandardHandlers(); | |
202 | ||
203 | // raw bitmap access support functions, for internal use only | |
204 | void *GetRawData(wxPixelDataBase& data, int bpp); | |
205 | void UngetRawData(wxPixelDataBase& data); | |
206 | ||
207 | void UseAlpha(); | |
208 | ||
209 | public: | |
210 | WXHBITMAP GetHBITMAP() const; | |
211 | inline WXHICON GetHICON() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_hIcon : 0); } | |
212 | WXHMETAFILE GetPict(bool *created = NULL ) const; | |
213 | ||
214 | void SetHBITMAP(WXHBITMAP bmp); | |
215 | void SetHICON(WXHICON ico); | |
216 | void SetPict( WXHMETAFILE pict ) ; | |
217 | ||
218 | bool FreeResource(bool force = FALSE); | |
219 | }; | |
220 | #endif | |
221 | // _WX_BITMAP_H_ |