1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/osx/bitmap.h
3 // Purpose: wxBitmap class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #include "wx/palette.h"
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
;
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
34 class WXDLLIMPEXP_CORE wxMask
: public wxObject
36 DECLARE_DYNAMIC_CLASS(wxMask
)
42 wxMask(const wxMask
& mask
);
44 // Construct a mask from a bitmap and a colour indicating
45 // the transparent area
46 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
48 // Construct a mask from a mono bitmap (black meaning show pixels, white meaning transparent)
49 wxMask(const wxBitmap
& bitmap
);
51 // implementation helper only : construct a mask from a 32 bit memory buffer
52 wxMask(const wxMemoryBuffer
& buf
, int width
, int height
, int bytesPerRow
) ;
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
) ;
60 wxBitmap
GetBitmap() const;
62 // Implementation below
67 void* GetRawAccess() const;
68 int GetBytesPerRow() const { return m_bytesPerRow
; }
69 // renders/updates native representation when necessary
70 void RealizeNative() ;
72 WXHBITMAP
GetHBITMAP() const ;
76 wxMemoryBuffer m_memBuf
;
81 WXHBITMAP m_maskBitmap
;
85 class WXDLLIMPEXP_CORE wxBitmap
: public wxBitmapBase
87 DECLARE_DYNAMIC_CLASS(wxBitmap
)
89 friend class WXDLLIMPEXP_FWD_CORE wxBitmapHandler
;
92 wxBitmap() {} // Platform-specific
94 // Initialize with raw data.
95 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
97 // Initialize with XPM data
98 wxBitmap(const char* const* bits
);
100 // Load a file or resource
101 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_DEFAULT_TYPE
);
103 // Constructor for generalised creation from data
104 wxBitmap(const void* data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
106 // creates an bitmap from the native image format
107 wxBitmap(CGImageRef image
);
108 wxBitmap(WX_NSImage image
);
110 // If depth is omitted, will create a bitmap compatible with the display
111 wxBitmap(int width
, int height
, int depth
= -1) { (void)Create(width
, height
, depth
); }
112 wxBitmap(const wxSize
& sz
, int depth
= -1) { (void)Create(sz
, depth
); }
114 // Convert from wxImage:
115 wxBitmap(const wxImage
& image
, int depth
= -1);
117 // Convert from wxIcon
118 wxBitmap(const wxIcon
& icon
) { CopyFromIcon(icon
); }
120 virtual ~wxBitmap() {}
122 wxImage
ConvertToImage() const;
124 // get the given part of bitmap
125 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
127 virtual bool Create(int width
, int height
, int depth
= wxBITMAP_SCREEN_DEPTH
);
128 virtual bool Create(const wxSize
& sz
, int depth
= wxBITMAP_SCREEN_DEPTH
)
129 { return Create(sz
.GetWidth(), sz
.GetHeight(), depth
); }
131 virtual bool Create(const void* data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
132 bool Create( CGImageRef image
);
133 bool Create( WX_NSImage image
);
135 // virtual bool Create( WXHICON icon) ;
136 virtual bool LoadFile(const wxString
& name
, wxBitmapType type
= wxBITMAP_DEFAULT_TYPE
);
137 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
, const wxPalette
*cmap
= NULL
) const;
139 wxBitmapRefData
*GetBitmapData() const
140 { return (wxBitmapRefData
*)m_refData
; }
142 // copies the contents and mask of the given (colour) icon to the bitmap
143 virtual bool CopyFromIcon(const wxIcon
& icon
);
145 int GetWidth() const;
146 int GetHeight() const;
147 int GetDepth() const;
148 void SetWidth(int w
);
149 void SetHeight(int h
);
150 void SetDepth(int d
);
151 void SetOk(bool isOk
);
154 wxPalette
* GetPalette() const;
155 void SetPalette(const wxPalette
& palette
);
156 #endif // wxUSE_PALETTE
158 wxMask
*GetMask() const;
159 void SetMask(wxMask
*mask
) ;
161 static void InitStandardHandlers();
163 // raw bitmap access support functions, for internal use only
164 void *GetRawData(wxPixelDataBase
& data
, int bpp
);
165 void UngetRawData(wxPixelDataBase
& data
);
167 // these functions are internal and shouldn't be used, they risk to
168 // disappear in the future
169 bool HasAlpha() const;
172 // returns the 'native' implementation, a GWorldPtr for the content and one for the mask
173 WXHBITMAP
GetHBITMAP( WXHBITMAP
* mask
= NULL
) const;
175 // returns a CGImageRef which must released after usage with CGImageRelease
176 CGImageRef
CreateCGImage() const ;
179 // returns an autoreleased version of the image
180 WX_NSImage
GetNSImage() const;
183 // returns an autoreleased version of the image
184 WX_UIImage
GetUIImage() const;
186 // returns a IconRef which must be retained before and released after usage
187 IconRef
GetIconRef() const;
188 // returns a IconRef which must be released after usage
189 IconRef
CreateIconRef() const;
190 // get read only access to the underlying buffer
191 void *GetRawAccess() const ;
192 // brackets to the underlying OS structure for read/write access
193 // makes sure that no cached images will be constructed until terminated
194 void *BeginRawAccess() ;
195 void EndRawAccess() ;
198 virtual wxGDIRefData
*CreateGDIRefData() const;
199 virtual wxGDIRefData
*CloneGDIRefData(const wxGDIRefData
*data
) const;
202 #endif // _WX_BITMAP_H_