1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/osx/bitmap.h
3 // Purpose: wxBitmap class
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
14 #include "wx/palette.h"
17 class WXDLLIMPEXP_FWD_CORE wxBitmap
;
18 class wxBitmapRefData
;
19 class WXDLLIMPEXP_FWD_CORE wxBitmapHandler
;
20 class WXDLLIMPEXP_FWD_CORE wxControl
;
21 class WXDLLIMPEXP_FWD_CORE wxCursor
;
22 class WXDLLIMPEXP_FWD_CORE wxDC
;
23 class WXDLLIMPEXP_FWD_CORE wxIcon
;
24 class WXDLLIMPEXP_FWD_CORE wxImage
;
25 class WXDLLIMPEXP_FWD_CORE wxPixelDataBase
;
27 // A mask is a bitmap used for drawing bitmaps
28 // Internally it is stored as a 8 bit deep memory chunk, 0 = black means the source will be drawn
29 // 255 = white means the source will not be drawn, no other values will be present
30 // 8 bit is chosen only for performance reasons, note also that this is the inverse value range
31 // from alpha, where 0 = invisible , 255 = fully drawn
33 class WXDLLIMPEXP_CORE wxMask
: public wxObject
35 DECLARE_DYNAMIC_CLASS(wxMask
)
41 wxMask(const wxMask
& mask
);
43 // Construct a mask from a bitmap and a colour indicating
44 // the transparent area
45 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
47 // Construct a mask from a mono bitmap (black meaning show pixels, white meaning transparent)
48 wxMask(const wxBitmap
& bitmap
);
50 // implementation helper only : construct a mask from a 32 bit memory buffer
51 wxMask(const wxMemoryBuffer
& buf
, int width
, int height
, int bytesPerRow
) ;
55 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
56 bool Create(const wxBitmap
& bitmap
);
57 bool Create(const wxMemoryBuffer
& buf
, int width
, int height
, int bytesPerRow
) ;
59 wxBitmap
GetBitmap() const;
61 // Implementation below
66 void* GetRawAccess() const;
67 int GetBytesPerRow() const { return m_bytesPerRow
; }
68 // renders/updates native representation when necessary
69 void RealizeNative() ;
71 WXHBITMAP
GetHBITMAP() const ;
75 wxMemoryBuffer m_memBuf
;
80 WXHBITMAP m_maskBitmap
;
84 class WXDLLIMPEXP_CORE wxBitmap
: public wxBitmapBase
86 DECLARE_DYNAMIC_CLASS(wxBitmap
)
88 friend class WXDLLIMPEXP_FWD_CORE wxBitmapHandler
;
91 wxBitmap() {} // Platform-specific
93 // Initialize with raw data.
94 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
96 // Initialize with XPM data
97 wxBitmap(const char* const* bits
);
99 // Load a file or resource
100 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_DEFAULT_TYPE
);
102 // Constructor for generalised creation from data
103 wxBitmap(const void* data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
105 // creates an bitmap from the native image format
106 wxBitmap(CGImageRef image
, double scale
= 1.0);
107 wxBitmap(WX_NSImage image
);
108 wxBitmap(CGContextRef bitmapcontext
);
110 // Create a bitmap compatible with the given DC
111 wxBitmap(int width
, int height
, const wxDC
& dc
);
113 // If depth is omitted, will create a bitmap compatible with the display
114 wxBitmap(int width
, int height
, int depth
= -1) { (void)Create(width
, height
, depth
); }
115 wxBitmap(const wxSize
& sz
, int depth
= -1) { (void)Create(sz
, depth
); }
117 // Convert from wxImage:
118 wxBitmap(const wxImage
& image
, int depth
= -1, double scale
= 1.0);
120 // Convert from wxIcon
121 wxBitmap(const wxIcon
& icon
) { CopyFromIcon(icon
); }
123 virtual ~wxBitmap() {}
125 wxImage
ConvertToImage() const;
127 // get the given part of bitmap
128 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
130 virtual bool Create(int width
, int height
, int depth
= wxBITMAP_SCREEN_DEPTH
);
131 virtual bool Create(const wxSize
& sz
, int depth
= wxBITMAP_SCREEN_DEPTH
)
132 { return Create(sz
.GetWidth(), sz
.GetHeight(), depth
); }
134 virtual bool Create(const void* data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
135 bool Create( CGImageRef image
, double scale
= 1.0 );
136 bool Create( WX_NSImage image
);
137 bool Create( CGContextRef bitmapcontext
);
139 // Create a bitmap compatible with the given DC, inheriting its magnification factor
140 bool Create(int width
, int height
, const wxDC
& dc
);
142 // Create a bitmap with a scale factor, width and height are multiplied with that factor
143 bool CreateScaled(int logwidth
, int logheight
, int depth
, double logicalScale
);
145 // virtual bool Create( WXHICON icon) ;
146 virtual bool LoadFile(const wxString
& name
, wxBitmapType type
= wxBITMAP_DEFAULT_TYPE
);
147 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
, const wxPalette
*cmap
= NULL
) const;
149 wxBitmapRefData
*GetBitmapData() const
150 { return (wxBitmapRefData
*)m_refData
; }
152 // copies the contents and mask of the given (colour) icon to the bitmap
153 virtual bool CopyFromIcon(const wxIcon
& icon
);
155 int GetWidth() const;
156 int GetHeight() const;
157 int GetDepth() const;
158 void SetWidth(int w
);
159 void SetHeight(int h
);
160 void SetDepth(int d
);
161 void SetOk(bool isOk
);
164 wxPalette
* GetPalette() const;
165 void SetPalette(const wxPalette
& palette
);
166 #endif // wxUSE_PALETTE
168 wxMask
*GetMask() const;
169 void SetMask(wxMask
*mask
) ;
171 static void InitStandardHandlers();
173 // raw bitmap access support functions, for internal use only
174 void *GetRawData(wxPixelDataBase
& data
, int bpp
);
175 void UngetRawData(wxPixelDataBase
& data
);
177 // these functions are internal and shouldn't be used, they risk to
178 // disappear in the future
179 bool HasAlpha() const;
182 // returns the 'native' implementation, a GWorldPtr for the content and one for the mask
183 WXHBITMAP
GetHBITMAP( WXHBITMAP
* mask
= NULL
) const;
185 // returns a CGImageRef which must released after usage with CGImageRelease
186 CGImageRef
CreateCGImage() const ;
189 // returns an autoreleased version of the image
190 WX_NSImage
GetNSImage() const;
193 // returns an autoreleased version of the image
194 WX_UIImage
GetUIImage() const;
196 // returns a IconRef which must be retained before and released after usage
197 IconRef
GetIconRef() const;
198 // returns a IconRef which must be released after usage
199 IconRef
CreateIconRef() const;
200 // get read only access to the underlying buffer
201 void *GetRawAccess() const ;
202 // brackets to the underlying OS structure for read/write access
203 // makes sure that no cached images will be constructed until terminated
204 void *BeginRawAccess() ;
205 void EndRawAccess() ;
207 double GetScaleFactor() const;
209 virtual wxGDIRefData
*CreateGDIRefData() const;
210 virtual wxGDIRefData
*CloneGDIRefData(const wxGDIRefData
*data
) const;
213 #endif // _WX_BITMAP_H_