]> git.saurik.com Git - wxWidgets.git/blame - include/wx/cocoa/bitmap.h
Add wxBitmap constructors and Create methods to allow creating a wxBitmap from an...
[wxWidgets.git] / include / wx / cocoa / bitmap.h
CommitLineData
a24aff65 1/////////////////////////////////////////////////////////////////////////////
1b88201f 2// Name: wx/cocoa/bitmap.h
a24aff65 3// Purpose: wxBitmap class
d135b1a5 4// Author: David Elliott
a24aff65 5// Modified by:
d135b1a5 6// Created: 2003/07/19
a24aff65 7// RCS-ID: $Id$
d135b1a5 8// Copyright: (c) 2003 David Elliott
1b88201f 9// Licence: wxWindows licence
a24aff65
DE
10/////////////////////////////////////////////////////////////////////////////
11
d135b1a5
DE
12#ifndef __WX_COCOA_BITMAP_H__
13#define __WX_COCOA_BITMAP_H__
a24aff65
DE
14
15#include "wx/palette.h"
16
17// Bitmap
b5dbe15d
VS
18class WXDLLIMPEXP_FWD_CORE wxBitmap;
19class WXDLLIMPEXP_FWD_CORE wxIcon;
20class WXDLLIMPEXP_FWD_CORE wxCursor;
21class WXDLLIMPEXP_FWD_CORE wxImage;
22class WXDLLIMPEXP_FWD_CORE wxPixelDataBase;
a24aff65 23
d135b1a5
DE
24// ========================================================================
25// wxMask
26// ========================================================================
d135b1a5 27
016b0643 28// A mask is a 1-bit alpha bitmap used for drawing bitmaps transparently.
a24aff65
DE
29class WXDLLEXPORT wxMask: public wxObject
30{
31 DECLARE_DYNAMIC_CLASS(wxMask)
a24aff65 32public:
016b0643 33 wxMask();
a24aff65 34
016b0643
DE
35 // Construct a mask from a bitmap and a colour indicating
36 // the transparent area
37 wxMask(const wxBitmap& bitmap, const wxColour& colour);
a24aff65 38
016b0643
DE
39 // Construct a mask from a bitmap and a palette index indicating
40 // the transparent area
41 wxMask(const wxBitmap& bitmap, int paletteIndex);
a24aff65 42
016b0643
DE
43 // Construct a mask from a mono bitmap (copies the bitmap).
44 wxMask(const wxBitmap& bitmap);
a24aff65 45
319fe103
DE
46 // Copy constructor
47 wxMask(const wxMask& src);
48
d3c7fc99 49 virtual ~wxMask();
a24aff65 50
016b0643
DE
51 bool Create(const wxBitmap& bitmap, const wxColour& colour);
52 bool Create(const wxBitmap& bitmap, int paletteIndex);
53 bool Create(const wxBitmap& bitmap);
a24aff65 54
016b0643
DE
55 // wxCocoa
56 inline WX_NSBitmapImageRep GetNSBitmapImageRep()
57 { return m_cocoaNSBitmapImageRep; }
a24aff65 58protected:
016b0643 59 WX_NSBitmapImageRep m_cocoaNSBitmapImageRep;
a24aff65
DE
60};
61
d135b1a5
DE
62// ========================================================================
63// wxBitmap
64// ========================================================================
65class WXDLLEXPORT wxBitmap: public wxGDIObject
a24aff65 66{
d135b1a5
DE
67 DECLARE_DYNAMIC_CLASS(wxBitmap)
68// ------------------------------------------------------------------------
69// initialization
70// ------------------------------------------------------------------------
a24aff65 71public:
d135b1a5
DE
72 // Platform-specific default constructor
73 wxBitmap();
d135b1a5
DE
74 // Initialize with raw data.
75 wxBitmap(const char bits[], int width, int height, int depth = 1);
76 // Initialize with XPM data
452418c4 77 wxBitmap(const char* const* bits);
d135b1a5
DE
78 // Load a file or resource
79 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
d381b7df
DE
80 // Construct from Cocoa's NSImage
81 wxBitmap(NSImage* cocoaNSImage);
82 // Construct from Cocoa's NSBitmapImageRep
83 wxBitmap(NSBitmapImageRep* cocoaNSBitmapImageRep);
d135b1a5 84 // Constructor for generalised creation from data
452418c4 85 wxBitmap(const void* data, wxBitmapType type, int width, int height, int depth = 1);
d135b1a5
DE
86 // If depth is omitted, will create a bitmap compatible with the display
87 wxBitmap(int width, int height, int depth = -1);
88 // Convert from wxImage:
89 wxBitmap(const wxImage& image, int depth = -1)
90 { CreateFromImage(image, depth); }
b5df4fc7
DE
91 // Convert from wxIcon
92 wxBitmap(const wxIcon& icon) { CopyFromIcon(icon); }
93
d135b1a5 94 // destructor
d3c7fc99 95 virtual ~wxBitmap();
1b88201f 96
d135b1a5
DE
97// ------------------------------------------------------------------------
98// Implementation
99// ------------------------------------------------------------------------
a24aff65 100public:
d135b1a5
DE
101 // Initialize from wxImage
102 bool CreateFromImage(const wxImage& image, int depth=-1);
103
104 virtual bool Create(int width, int height, int depth = -1);
d381b7df
DE
105 virtual bool Create(NSImage* cocoaNSImage);
106 virtual bool Create(NSBitmapImageRep* cocoaNSBitmapImageRep);
452418c4 107 virtual bool Create(const void* data, wxBitmapType type, int width, int height, int depth = 1);
d135b1a5
DE
108 virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
109 virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const;
110
111 // copies the contents and mask of the given (colour) icon to the bitmap
112 virtual bool CopyFromIcon(const wxIcon& icon);
113
114 wxImage ConvertToImage() const;
115
116 // get the given part of bitmap
117 wxBitmap GetSubBitmap( const wxRect& rect ) const;
118
b7cacb43
VZ
119 bool Ok() const { return IsOk(); }
120 bool IsOk() const;
d135b1a5
DE
121 int GetWidth() const;
122 int GetHeight() const;
123 int GetDepth() const;
124 int GetQuality() const;
125 void SetWidth(int w);
126 void SetHeight(int h);
127 void SetDepth(int d);
128 void SetQuality(int q);
129 void SetOk(bool isOk);
130
b60c6e97
DE
131 // raw bitmap access support functions
132 void *GetRawData(wxPixelDataBase& data, int bpp);
133 void UngetRawData(wxPixelDataBase& data);
134
d135b1a5
DE
135 wxPalette* GetPalette() const;
136 void SetPalette(const wxPalette& palette);
137
138 wxMask *GetMask() const;
139 void SetMask(wxMask *mask) ;
140
141 int GetBitmapType() const;
1b88201f 142
d135b1a5
DE
143 // wxObjectRefData
144 wxObjectRefData *CreateRefData() const;
145 wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
146
147 // wxCocoa
148 WX_NSBitmapImageRep GetNSBitmapImageRep();
ab13160e 149 void SetNSBitmapImageRep(WX_NSBitmapImageRep bitmapImageRep);
9c54e4ae 150 WX_NSImage GetNSImage(bool useMask) const;
d135b1a5
DE
151
152 static void InitStandardHandlers() { }
153 static void CleanUpHandlers() { }
a24aff65 154};
d135b1a5 155
452418c4
PC
156class WXDLLIMPEXP_CORE wxBitmapHandler: public wxBitmapHandlerBase
157{
158 DECLARE_ABSTRACT_CLASS(wxBitmapHandler)
159};
160
1b88201f
WS
161#endif
162 // __WX_COCOA_BITMAP_H__