]>
Commit | Line | Data |
---|---|---|
0dbd6262 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: bitmap.h | |
3 | // Purpose: wxBitmap class | |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: ??/??/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) AUTHOR | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_BITMAP_H_ | |
13 | #define _WX_BITMAP_H_ | |
14 | ||
af49c4b8 | 15 | #if defined(__GNUG__) && !defined(__APPLE__) |
b698c8e9 | 16 | #pragma interface "bitmap.h" |
0dbd6262 SC |
17 | #endif |
18 | ||
0dbd6262 SC |
19 | #include "wx/palette.h" |
20 | ||
21 | // Bitmap | |
22 | class WXDLLEXPORT wxDC; | |
23 | class WXDLLEXPORT wxControl; | |
24 | class WXDLLEXPORT wxBitmap; | |
25 | class WXDLLEXPORT wxBitmapHandler; | |
26 | class WXDLLEXPORT wxIcon; | |
27 | class WXDLLEXPORT wxCursor; | |
fd859211 | 28 | class WXDLLEXPORT wxImage; |
0dbd6262 SC |
29 | |
30 | // A mask is a mono bitmap used for drawing bitmaps | |
31 | // transparently. | |
32 | class WXDLLEXPORT wxMask: public wxObject | |
33 | { | |
be52b341 GD |
34 | DECLARE_DYNAMIC_CLASS(wxMask) |
35 | DECLARE_NO_COPY_CLASS(wxMask) | |
0dbd6262 SC |
36 | |
37 | public: | |
38 | wxMask(); | |
39 | ||
40 | // Construct a mask from a bitmap and a colour indicating | |
41 | // the transparent area | |
42 | wxMask(const wxBitmap& bitmap, const wxColour& colour); | |
43 | ||
44 | // Construct a mask from a bitmap and a palette index indicating | |
45 | // the transparent area | |
46 | wxMask(const wxBitmap& bitmap, int paletteIndex); | |
47 | ||
48 | // Construct a mask from a mono bitmap (copies the bitmap). | |
49 | wxMask(const wxBitmap& bitmap); | |
50 | ||
51 | ~wxMask(); | |
52 | ||
53 | bool Create(const wxBitmap& bitmap, const wxColour& colour); | |
54 | bool Create(const wxBitmap& bitmap, int paletteIndex); | |
55 | bool Create(const wxBitmap& bitmap); | |
56 | ||
0dbd6262 | 57 | // Implementation |
5fde6fcc | 58 | bool PointMasked(int x, int y); |
0dbd6262 SC |
59 | inline WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; } |
60 | inline void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; } | |
61 | protected: | |
62 | WXHBITMAP m_maskBitmap; | |
0dbd6262 SC |
63 | }; |
64 | ||
3dec57ad | 65 | enum { kMacBitmapTypeUnknownType , kMacBitmapTypeGrafWorld, kMacBitmapTypePict , kMacBitmapTypeIcon } ; |
519cb848 | 66 | |
0dbd6262 SC |
67 | class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData |
68 | { | |
be52b341 GD |
69 | DECLARE_NO_COPY_CLASS(wxBitmapRefData) |
70 | ||
0dbd6262 SC |
71 | friend class WXDLLEXPORT wxBitmap; |
72 | friend class WXDLLEXPORT wxIcon; | |
73 | friend class WXDLLEXPORT wxCursor; | |
74 | public: | |
75 | wxBitmapRefData(); | |
76 | ~wxBitmapRefData(); | |
77 | ||
78 | public: | |
79 | int m_width; | |
80 | int m_height; | |
81 | int m_depth; | |
82 | bool m_ok; | |
83 | int m_numColors; | |
84 | wxPalette m_bitmapPalette; | |
85 | int m_quality; | |
86 | ||
be52b341 GD |
87 | int m_bitmapType ; |
88 | WXHMETAFILE m_hPict ; | |
89 | WXHBITMAP m_hBitmap; | |
90 | WXHICON m_hIcon ; | |
0dbd6262 SC |
91 | wxMask * m_bitmapMask; // Optional mask |
92 | }; | |
93 | ||
94 | #define M_BITMAPDATA ((wxBitmapRefData *)m_refData) | |
95 | ||
584bede0 | 96 | class WXDLLEXPORT wxBitmapHandler: public wxBitmapHandlerBase |
0dbd6262 SC |
97 | { |
98 | DECLARE_DYNAMIC_CLASS(wxBitmapHandler) | |
99 | public: | |
be52b341 GD |
100 | wxBitmapHandler() : m_name(), m_extension(), m_type(0) { } |
101 | virtual ~wxBitmapHandler(); | |
0dbd6262 SC |
102 | |
103 | virtual bool Create(wxBitmap *bitmap, void *data, long flags, int width, int height, int depth = 1); | |
104 | virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags, | |
105 | int desiredWidth, int desiredHeight); | |
584bede0 | 106 | virtual bool SaveFile(const wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette = NULL); |
0dbd6262 | 107 | |
be52b341 GD |
108 | void SetName(const wxString& name) { m_name = name; } |
109 | void SetExtension(const wxString& ext) { m_extension = ext; } | |
110 | void SetType(long type) { m_type = type; } | |
111 | wxString GetName() const { return m_name; } | |
112 | wxString GetExtension() const { return m_extension; } | |
113 | long GetType() const { return m_type; } | |
114 | ||
0dbd6262 SC |
115 | protected: |
116 | wxString m_name; | |
117 | wxString m_extension; | |
118 | long m_type; | |
119 | }; | |
120 | ||
121 | #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData()) | |
122 | ||
584bede0 | 123 | class WXDLLEXPORT wxBitmap: public wxBitmapBase |
0dbd6262 SC |
124 | { |
125 | DECLARE_DYNAMIC_CLASS(wxBitmap) | |
126 | ||
127 | friend class WXDLLEXPORT wxBitmapHandler; | |
128 | ||
129 | public: | |
130 | wxBitmap(); // Platform-specific | |
131 | ||
132 | // Copy constructors | |
be52b341 GD |
133 | wxBitmap(const wxBitmap& bitmap) |
134 | : wxBitmapBase() | |
d71c423e | 135 | { Ref(bitmap); } |
0dbd6262 SC |
136 | |
137 | // Initialize with raw data. | |
138 | wxBitmap(const char bits[], int width, int height, int depth = 1); | |
139 | ||
0dbd6262 | 140 | // Initialize with XPM data |
b7d667c5 GD |
141 | bool CreateFromXpm(const char **bits); |
142 | wxBitmap(const char **bits); | |
143 | wxBitmap(char **bits); | |
0dbd6262 SC |
144 | |
145 | // Load a file or resource | |
584bede0 | 146 | wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_PICT_RESOURCE); |
0dbd6262 SC |
147 | |
148 | // Constructor for generalised creation from data | |
584bede0 | 149 | wxBitmap(void *data, wxBitmapType type, int width, int height, int depth = 1); |
0dbd6262 SC |
150 | |
151 | // If depth is omitted, will create a bitmap compatible with the display | |
152 | wxBitmap(int width, int height, int depth = -1); | |
fd859211 VS |
153 | |
154 | // Convert from wxImage: | |
155 | wxBitmap(const wxImage& image, int depth = -1); | |
156 | ||
0dbd6262 | 157 | ~wxBitmap(); |
fd859211 VS |
158 | |
159 | wxImage ConvertToImage() const; | |
0dbd6262 | 160 | |
5fde6fcc GD |
161 | // get the given part of bitmap |
162 | wxBitmap GetSubBitmap( const wxRect& rect ) const; | |
163 | ||
0dbd6262 | 164 | virtual bool Create(int width, int height, int depth = -1); |
584bede0 GD |
165 | virtual bool Create(void *data, wxBitmapType type, int width, int height, int depth = 1); |
166 | virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE); | |
167 | virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const; | |
168 | ||
169 | // copies the contents and mask of the given (colour) icon to the bitmap | |
170 | virtual bool CopyFromIcon(const wxIcon& icon); | |
0dbd6262 | 171 | |
5fde6fcc GD |
172 | bool Ok() const; |
173 | int GetWidth() const; | |
174 | int GetHeight() const; | |
175 | int GetDepth() const; | |
176 | int GetQuality() const; | |
0dbd6262 SC |
177 | void SetWidth(int w); |
178 | void SetHeight(int h); | |
179 | void SetDepth(int d); | |
180 | void SetQuality(int q); | |
181 | void SetOk(bool isOk); | |
182 | ||
5fde6fcc | 183 | wxPalette* GetPalette() const; |
0dbd6262 SC |
184 | void SetPalette(const wxPalette& palette); |
185 | ||
5fde6fcc | 186 | wxMask *GetMask() const; |
0dbd6262 SC |
187 | void SetMask(wxMask *mask) ; |
188 | ||
5fde6fcc GD |
189 | int GetBitmapType() const; |
190 | ||
0dbd6262 | 191 | inline wxBitmap& operator = (const wxBitmap& bitmap) { if (*this == bitmap) return (*this); Ref(bitmap); return *this; } |
15e758d1 GD |
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; } | |
0dbd6262 | 194 | |
0dbd6262 | 195 | static void InitStandardHandlers(); |
0dbd6262 | 196 | protected: |
0dbd6262 | 197 | |
0dbd6262 SC |
198 | // TODO: Implementation |
199 | public: | |
200 | void SetHBITMAP(WXHBITMAP bmp); | |
5fde6fcc | 201 | WXHBITMAP GetHBITMAP() const; |
3dec57ad SC |
202 | void SetHICON(WXHICON ico); |
203 | inline WXHICON GetHICON() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_hIcon : 0); } | |
03e11df5 | 204 | |
5273bf2f | 205 | WXHMETAFILE GetPict() const; |
5fde6fcc | 206 | |
0dbd6262 | 207 | bool FreeResource(bool force = FALSE); |
0dbd6262 SC |
208 | }; |
209 | #endif | |
210 | // _WX_BITMAP_H_ |