]>
Commit | Line | Data |
---|---|---|
8cf73271 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 |
8cf73271 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_BITMAP_H_ | |
13 | #define _WX_BITMAP_H_ | |
14 | ||
8cf73271 SC |
15 | #include "wx/palette.h" |
16 | ||
17 | // Bitmap | |
b5dbe15d | 18 | class WXDLLIMPEXP_FWD_CORE wxBitmap; |
20b69855 | 19 | class wxBitmapRefData ; |
b5dbe15d VS |
20 | class WXDLLIMPEXP_FWD_CORE wxBitmapHandler; |
21 | class WXDLLIMPEXP_FWD_CORE wxControl; | |
22 | class WXDLLIMPEXP_FWD_CORE wxCursor; | |
23 | class WXDLLIMPEXP_FWD_CORE wxDC; | |
24 | class WXDLLIMPEXP_FWD_CORE wxIcon; | |
25 | class WXDLLIMPEXP_FWD_CORE wxImage; | |
26 | class WXDLLIMPEXP_FWD_CORE wxPixelDataBase; | |
8cf73271 SC |
27 | |
28 | // A mask is a bitmap used for drawing bitmaps | |
20b69855 SC |
29 | // Internally it is stored as a 8 bit deep memory chunk, 0 = black means the source will be drawn |
30 | // 255 = white means the source will not be drawn, no other values will be present | |
31 | // 8 bit is chosen only for performance reasons, note also that this is the inverse value range | |
32 | // from alpha, where 0 = invisible , 255 = fully drawn | |
33 | ||
8cf73271 SC |
34 | class WXDLLEXPORT wxMask: public wxObject |
35 | { | |
36 | DECLARE_DYNAMIC_CLASS(wxMask) | |
8cf73271 SC |
37 | |
38 | public: | |
20b69855 | 39 | wxMask(); |
8cf73271 | 40 | |
2bf8f4c0 RD |
41 | // Copy constructor |
42 | wxMask(const wxMask& mask); | |
43 | ||
20b69855 SC |
44 | // Construct a mask from a bitmap and a colour indicating |
45 | // the transparent area | |
46 | wxMask(const wxBitmap& bitmap, const wxColour& colour); | |
8cf73271 | 47 | |
20b69855 SC |
48 | // Construct a mask from a mono bitmap (black meaning show pixels, white meaning transparent) |
49 | wxMask(const wxBitmap& bitmap); | |
8f884a0d | 50 | |
835a3473 | 51 | // implementation helper only : construct a mask from a 32 bit memory buffer |
20b69855 | 52 | wxMask(const wxMemoryBuffer& buf, int width , int height , int bytesPerRow ) ; |
8cf73271 | 53 | |
d3c7fc99 | 54 | virtual ~wxMask(); |
20b69855 SC |
55 | |
56 | bool Create(const wxBitmap& bitmap, const wxColour& colour); | |
57 | bool Create(const wxBitmap& bitmap); | |
58 | bool Create(const wxMemoryBuffer& buf, int width , int height , int bytesPerRow ) ; | |
8cf73271 | 59 | |
20b69855 SC |
60 | // Implementation below |
61 | ||
62 | void Init() ; | |
63 | ||
8f884a0d | 64 | // a 8 bit depth mask |
20b69855 SC |
65 | void* GetRawAccess() const; |
66 | int GetBytesPerRow() const { return m_bytesPerRow ; } | |
8f884a0d | 67 | // renders/updates native representation when necessary |
20b69855 | 68 | void RealizeNative() ; |
71cc158e | 69 | |
20b69855 | 70 | WXHBITMAP GetHBITMAP() const ; |
71cc158e | 71 | |
20b69855 SC |
72 | |
73 | private: | |
74 | wxMemoryBuffer m_memBuf ; | |
75 | int m_bytesPerRow ; | |
76 | int m_width ; | |
77 | int m_height ; | |
71cc158e | 78 | |
20b69855 | 79 | WXHBITMAP m_maskBitmap ; |
71cc158e | 80 | |
20b69855 | 81 | }; |
8cf73271 | 82 | |
8cf73271 SC |
83 | class WXDLLEXPORT wxBitmap: public wxBitmapBase |
84 | { | |
20b69855 | 85 | DECLARE_DYNAMIC_CLASS(wxBitmap) |
8cf73271 | 86 | |
b5dbe15d | 87 | friend class WXDLLIMPEXP_FWD_CORE wxBitmapHandler; |
8cf73271 SC |
88 | |
89 | public: | |
20b69855 SC |
90 | wxBitmap(); // Platform-specific |
91 | ||
20b69855 SC |
92 | // Initialize with raw data. |
93 | wxBitmap(const char bits[], int width, int height, int depth = 1); | |
94 | ||
95 | // Initialize with XPM data | |
452418c4 | 96 | wxBitmap(const char* const* bits); |
20b69855 SC |
97 | |
98 | // Load a file or resource | |
99 | wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_PICT_RESOURCE); | |
100 | ||
101 | // Constructor for generalised creation from data | |
452418c4 | 102 | wxBitmap(const void* data, wxBitmapType type, int width, int height, int depth = 1); |
20b69855 SC |
103 | |
104 | // If depth is omitted, will create a bitmap compatible with the display | |
105 | wxBitmap(int width, int height, int depth = -1); | |
106 | ||
107 | // Convert from wxImage: | |
108 | wxBitmap(const wxImage& image, int depth = -1); | |
109 | ||
110 | // Convert from wxIcon | |
111 | wxBitmap(const wxIcon& icon) { CopyFromIcon(icon); } | |
112 | ||
d3c7fc99 | 113 | virtual ~wxBitmap(); |
20b69855 SC |
114 | |
115 | wxImage ConvertToImage() const; | |
116 | ||
117 | // get the given part of bitmap | |
118 | wxBitmap GetSubBitmap( const wxRect& rect ) const; | |
119 | ||
120 | virtual bool Create(int width, int height, int depth = -1); | |
452418c4 | 121 | virtual bool Create(const void* data, wxBitmapType type, int width, int height, int depth = 1); |
20b69855 SC |
122 | // virtual bool Create( WXHICON icon) ; |
123 | virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE); | |
124 | virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const; | |
125 | ||
126 | wxBitmapRefData *GetBitmapData() const | |
127 | { return (wxBitmapRefData *)m_refData; } | |
128 | ||
129 | // copies the contents and mask of the given (colour) icon to the bitmap | |
130 | virtual bool CopyFromIcon(const wxIcon& icon); | |
131 | ||
20b69855 SC |
132 | int GetWidth() const; |
133 | int GetHeight() const; | |
134 | int GetDepth() const; | |
135 | void SetWidth(int w); | |
136 | void SetHeight(int h); | |
137 | void SetDepth(int d); | |
138 | void SetOk(bool isOk); | |
139 | ||
8cf73271 | 140 | #if wxUSE_PALETTE |
20b69855 SC |
141 | wxPalette* GetPalette() const; |
142 | void SetPalette(const wxPalette& palette); | |
8cf73271 SC |
143 | #endif // wxUSE_PALETTE |
144 | ||
20b69855 SC |
145 | wxMask *GetMask() const; |
146 | void SetMask(wxMask *mask) ; | |
8cf73271 | 147 | |
20b69855 | 148 | static void InitStandardHandlers(); |
8cf73271 SC |
149 | |
150 | // raw bitmap access support functions, for internal use only | |
151 | void *GetRawData(wxPixelDataBase& data, int bpp); | |
152 | void UngetRawData(wxPixelDataBase& data); | |
153 | ||
20b69855 SC |
154 | // these functions are internal and shouldn't be used, they risk to |
155 | // disappear in the future | |
156 | bool HasAlpha() const; | |
8cf73271 SC |
157 | void UseAlpha(); |
158 | ||
8f884a0d | 159 | // returns the 'native' implementation, a GWorldPtr for the content and one for the mask |
20b69855 | 160 | WXHBITMAP GetHBITMAP( WXHBITMAP * mask = NULL ) const; |
8cf73271 | 161 | |
20b69855 | 162 | // returns a CGImageRef which must released after usage with CGImageRelease |
e06b0afb | 163 | CGImageRef CreateCGImage() const ; |
a9479081 | 164 | |
e06b0afb SC |
165 | // returns a IconRef which must be retained before and released after usage |
166 | IconRef GetIconRef() const; | |
167 | // returns a IconRef which must be released after usage | |
168 | IconRef CreateIconRef() const; | |
20b69855 SC |
169 | // get read only access to the underlying buffer |
170 | void *GetRawAccess() const ; | |
171 | // brackets to the underlying OS structure for read/write access | |
172 | // makes sure that no cached images will be constructed until terminated | |
173 | void *BeginRawAccess() ; | |
174 | void EndRawAccess() ; | |
2bf8f4c0 RD |
175 | |
176 | protected: | |
8f884a0d VZ |
177 | virtual wxGDIRefData *CreateGDIRefData() const; |
178 | virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; | |
8cf73271 | 179 | }; |
8f884a0d VZ |
180 | |
181 | #endif // _WX_BITMAP_H_ |