]>
Commit | Line | Data |
---|---|---|
6762286d | 1 | ///////////////////////////////////////////////////////////////////////////// |
80fdcdb9 | 2 | // Name: wx/osx/bitmap.h |
6762286d SC |
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 | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_BITMAP_H_ | |
13 | #define _WX_BITMAP_H_ | |
14 | ||
15 | #include "wx/palette.h" | |
16 | ||
17 | // Bitmap | |
18 | class WXDLLIMPEXP_FWD_CORE wxBitmap; | |
19 | class wxBitmapRefData ; | |
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; | |
27 | ||
28 | // A mask is a bitmap used for drawing bitmaps | |
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 | ||
34 | class WXDLLIMPEXP_CORE wxMask: public wxObject | |
35 | { | |
36 | DECLARE_DYNAMIC_CLASS(wxMask) | |
37 | ||
38 | public: | |
39 | wxMask(); | |
40 | ||
41 | // Copy constructor | |
42 | wxMask(const wxMask& mask); | |
43 | ||
44 | // Construct a mask from a bitmap and a colour indicating | |
45 | // the transparent area | |
46 | wxMask(const wxBitmap& bitmap, const wxColour& colour); | |
47 | ||
48 | // Construct a mask from a mono bitmap (black meaning show pixels, white meaning transparent) | |
49 | wxMask(const wxBitmap& bitmap); | |
50 | ||
51 | // implementation helper only : construct a mask from a 32 bit memory buffer | |
52 | wxMask(const wxMemoryBuffer& buf, int width , int height , int bytesPerRow ) ; | |
53 | ||
54 | virtual ~wxMask(); | |
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 ) ; | |
59 | ||
5ca21fe7 PC |
60 | wxBitmap GetBitmap() const; |
61 | ||
6762286d SC |
62 | // Implementation below |
63 | ||
64 | void Init() ; | |
65 | ||
66 | // a 8 bit depth mask | |
67 | void* GetRawAccess() const; | |
68 | int GetBytesPerRow() const { return m_bytesPerRow ; } | |
69 | // renders/updates native representation when necessary | |
70 | void RealizeNative() ; | |
71 | ||
72 | WXHBITMAP GetHBITMAP() const ; | |
73 | ||
74 | ||
75 | private: | |
76 | wxMemoryBuffer m_memBuf ; | |
77 | int m_bytesPerRow ; | |
78 | int m_width ; | |
79 | int m_height ; | |
80 | ||
81 | WXHBITMAP m_maskBitmap ; | |
82 | ||
83 | }; | |
84 | ||
85 | class WXDLLIMPEXP_CORE wxBitmap: public wxBitmapBase | |
86 | { | |
87 | DECLARE_DYNAMIC_CLASS(wxBitmap) | |
88 | ||
89 | friend class WXDLLIMPEXP_FWD_CORE wxBitmapHandler; | |
90 | ||
91 | public: | |
732d8c74 | 92 | wxBitmap() {} // Platform-specific |
6762286d SC |
93 | |
94 | // Initialize with raw data. | |
95 | wxBitmap(const char bits[], int width, int height, int depth = 1); | |
96 | ||
97 | // Initialize with XPM data | |
98 | wxBitmap(const char* const* bits); | |
99 | ||
100 | // Load a file or resource | |
101 | wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_DEFAULT_TYPE); | |
102 | ||
103 | // Constructor for generalised creation from data | |
104 | wxBitmap(const void* data, wxBitmapType type, int width, int height, int depth = 1); | |
4cf611db SC |
105 | |
106 | // creates an bitmap from the native image format | |
c944835a | 107 | wxBitmap(CGImageRef image, double scale = 1.0); |
72625b36 | 108 | wxBitmap(WX_NSImage image); |
c944835a | 109 | wxBitmap(CGContextRef bitmapcontext); |
6762286d | 110 | |
68d5ce90 SC |
111 | // Create a bitmap compatible with the given DC |
112 | wxBitmap(int width, int height, const wxDC& dc); | |
113 | ||
6762286d | 114 | // If depth is omitted, will create a bitmap compatible with the display |
732d8c74 FM |
115 | wxBitmap(int width, int height, int depth = -1) { (void)Create(width, height, depth); } |
116 | wxBitmap(const wxSize& sz, int depth = -1) { (void)Create(sz, depth); } | |
6762286d SC |
117 | |
118 | // Convert from wxImage: | |
119 | wxBitmap(const wxImage& image, int depth = -1); | |
120 | ||
121 | // Convert from wxIcon | |
122 | wxBitmap(const wxIcon& icon) { CopyFromIcon(icon); } | |
123 | ||
732d8c74 | 124 | virtual ~wxBitmap() {} |
6762286d SC |
125 | |
126 | wxImage ConvertToImage() const; | |
127 | ||
128 | // get the given part of bitmap | |
129 | wxBitmap GetSubBitmap( const wxRect& rect ) const; | |
130 | ||
732d8c74 FM |
131 | virtual bool Create(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH); |
132 | virtual bool Create(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH) | |
133 | { return Create(sz.GetWidth(), sz.GetHeight(), depth); } | |
134 | ||
6762286d | 135 | virtual bool Create(const void* data, wxBitmapType type, int width, int height, int depth = 1); |
c944835a | 136 | bool Create( CGImageRef image, double scale = 1.0 ); |
72625b36 | 137 | bool Create( WX_NSImage image ); |
c944835a | 138 | bool Create( CGContextRef bitmapcontext); |
4cf611db | 139 | |
f8bfebfc SC |
140 | // Create a bitmap compatible with the given DC, inheriting its magnification factor |
141 | bool Create(int width, int height, const wxDC& dc); | |
142 | ||
143 | // Create a bitmap with a scale factor, width and height are multiplied with that factor | |
144 | bool CreateScaled(int logwidth, int logheight, int depth, double logicalScale); | |
145 | ||
6762286d SC |
146 | // virtual bool Create( WXHICON icon) ; |
147 | virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_DEFAULT_TYPE); | |
148 | virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const; | |
149 | ||
150 | wxBitmapRefData *GetBitmapData() const | |
151 | { return (wxBitmapRefData *)m_refData; } | |
152 | ||
153 | // copies the contents and mask of the given (colour) icon to the bitmap | |
154 | virtual bool CopyFromIcon(const wxIcon& icon); | |
155 | ||
156 | int GetWidth() const; | |
157 | int GetHeight() const; | |
158 | int GetDepth() const; | |
159 | void SetWidth(int w); | |
160 | void SetHeight(int h); | |
161 | void SetDepth(int d); | |
162 | void SetOk(bool isOk); | |
163 | ||
164 | #if wxUSE_PALETTE | |
165 | wxPalette* GetPalette() const; | |
166 | void SetPalette(const wxPalette& palette); | |
167 | #endif // wxUSE_PALETTE | |
168 | ||
169 | wxMask *GetMask() const; | |
170 | void SetMask(wxMask *mask) ; | |
171 | ||
172 | static void InitStandardHandlers(); | |
173 | ||
174 | // raw bitmap access support functions, for internal use only | |
175 | void *GetRawData(wxPixelDataBase& data, int bpp); | |
176 | void UngetRawData(wxPixelDataBase& data); | |
177 | ||
178 | // these functions are internal and shouldn't be used, they risk to | |
179 | // disappear in the future | |
180 | bool HasAlpha() const; | |
181 | void UseAlpha(); | |
182 | ||
183 | // returns the 'native' implementation, a GWorldPtr for the content and one for the mask | |
184 | WXHBITMAP GetHBITMAP( WXHBITMAP * mask = NULL ) const; | |
185 | ||
186 | // returns a CGImageRef which must released after usage with CGImageRelease | |
187 | CGImageRef CreateCGImage() const ; | |
188 | ||
4bea628d | 189 | #if wxOSX_USE_COCOA |
6762286d SC |
190 | // returns an autoreleased version of the image |
191 | WX_NSImage GetNSImage() const; | |
4bea628d SC |
192 | #endif |
193 | #if wxOSX_USE_IPHONE | |
194 | // returns an autoreleased version of the image | |
195 | WX_UIImage GetUIImage() const; | |
5c6eb3a8 | 196 | #endif |
6762286d SC |
197 | // returns a IconRef which must be retained before and released after usage |
198 | IconRef GetIconRef() const; | |
199 | // returns a IconRef which must be released after usage | |
200 | IconRef CreateIconRef() const; | |
201 | // get read only access to the underlying buffer | |
202 | void *GetRawAccess() const ; | |
203 | // brackets to the underlying OS structure for read/write access | |
204 | // makes sure that no cached images will be constructed until terminated | |
205 | void *BeginRawAccess() ; | |
206 | void EndRawAccess() ; | |
207 | ||
f8bfebfc | 208 | double GetScaleFactor() const; |
6762286d SC |
209 | protected: |
210 | virtual wxGDIRefData *CreateGDIRefData() const; | |
211 | virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; | |
212 | }; | |
213 | ||
214 | #endif // _WX_BITMAP_H_ |