]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: bitmap.h | |
3 | // Purpose: topic overview | |
4 | // Author: wxWidgets team | |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /*! | |
10 | ||
11 | @page overview_bitmap Bitmaps and icons overview | |
12 | ||
13 | Classes: #wxBitmap, #wxBitmapHandler, #wxIcon, #wxCursor. | |
14 | ||
15 | The wxBitmap class encapsulates the concept of a platform-dependent bitmap, | |
16 | either monochrome or colour. Platform-specific methods for creating a | |
17 | wxBitmap object from an existing file are catered for, and | |
18 | this is an occasion where conditional compilation will sometimes be | |
19 | required. | |
20 | ||
21 | A bitmap created dynamically or loaded from a file can be selected | |
22 | into a memory device context (instance of #wxMemoryDC). This | |
23 | enables the bitmap to be copied to a window or memory device context | |
24 | using wxDC::Blit, or to be used as a drawing surface. | |
25 | ||
26 | See #wxMemoryDC for an example of drawing onto a bitmap. | |
27 | ||
28 | All wxWidgets platforms support XPMs for small bitmaps and icons. | |
29 | You may include the XPM inline as below, since it's C code, or you | |
30 | can load it at run-time. | |
31 | ||
32 | @code | |
33 | #include "mondrian.xpm" | |
34 | @endcode | |
35 | ||
36 | Sometimes you wish to use a .ico resource on Windows, and XPMs on | |
37 | other platforms (for example to take advantage of Windows' support for | |
38 | multiple icon resolutions). | |
39 | ||
40 | A macro, #wxICON, is available which creates an icon using an XPM | |
41 | on the appropriate platform, or an icon resource on Windows. | |
42 | ||
43 | @code | |
44 | wxIcon icon(wxICON(mondrian)); | |
45 | ||
46 | // Equivalent to: | |
47 | ||
48 | #if defined(__WXGTK__) || defined(__WXMOTIF__) | |
49 | wxIcon icon(mondrian_xpm); | |
50 | #endif | |
51 | ||
52 | #if defined(__WXMSW__) | |
53 | wxIcon icon("mondrian"); | |
54 | #endif | |
55 | @endcode | |
56 | ||
57 | There is also a corresponding #wxBITMAP macro which allows | |
58 | to create the bitmaps in much the same way as #wxICON creates | |
59 | icons. It assumes that bitmaps live in resources under Windows or OS2 and XPM | |
60 | files under all other platforms (for XPMs, the corresponding file must be | |
61 | included before this macro is used, of course, and the name of the bitmap | |
62 | should be the same as the resource name under Windows with @c _xpm | |
63 | suffix). For example: | |
64 | ||
65 | @code | |
66 | // an easy and portable way to create a bitmap | |
67 | wxBitmap bmp(wxBITMAP(bmpname)); | |
68 | ||
69 | // which is roughly equivalent to the following | |
70 | #if defined(__WXMSW__) || defined(__WXPM__) | |
71 | wxBitmap bmp("bmpname", wxBITMAP_TYPE_RESOURCE); | |
72 | #else // Unix | |
73 | wxBitmap bmp(bmpname_xpm, wxBITMAP_TYPE_XPM); | |
74 | #endif | |
75 | @endcode | |
76 | ||
77 | You should always use wxICON and wxBITMAP macros because they work for any | |
78 | platform (unlike the code above which doesn't deal with wxMac, wxX11, ...) and | |
79 | are more short and clear than versions with @c #ifdefs. Even better, | |
80 | use the same XPMs on all platforms. | |
81 | ||
82 | @li @ref overview_bitmap_supportedformats | |
83 | @li @ref overview_bitmap_handlers | |
84 | ||
85 | ||
86 | <hr> | |
87 | ||
88 | ||
89 | @section overview_bitmap_supportedformats Supported bitmap file formats | |
90 | ||
91 | The following lists the formats handled on different platforms. Note | |
92 | that missing or partially-implemented formats are automatically supplemented | |
93 | by the #wxImage to load the data, and then converting | |
94 | it to wxBitmap form. Note that using wxImage is the preferred way to | |
95 | load images in wxWidgets, with the exception of resources (XPM-files or | |
96 | native Windows resources). | |
97 | ||
98 | Writing an image format handler for wxImage is also far easier than writing | |
99 | one for wxBitmap, because wxImage has exactly one format on all platforms | |
100 | whereas wxBitmap can store pixel data very differently, depending on colour | |
101 | depths and platform. | |
102 | ||
103 | @b wxBitmap | |
104 | Under Windows, wxBitmap may load the following formats: | |
105 | ||
106 | @li Windows bitmap resource (wxBITMAP_TYPE_BMP_RESOURCE) | |
107 | @li Windows bitmap file (wxBITMAP_TYPE_BMP) | |
108 | @li XPM data and file (wxBITMAP_TYPE_XPM) | |
109 | @li All formats that are supported by the #wxImage class. | |
110 | ||
111 | Under wxGTK, wxBitmap may load the following formats: | |
112 | ||
113 | @li XPM data and file (wxBITMAP_TYPE_XPM) | |
114 | @li All formats that are supported by the #wxImage class. | |
115 | ||
116 | Under wxMotif and wxX11, wxBitmap may load the following formats: | |
117 | ||
118 | @li XBM data and file (wxBITMAP_TYPE_XBM) | |
119 | @li XPM data and file (wxBITMAP_TYPE_XPM) | |
120 | @li All formats that are supported by the #wxImage class. | |
121 | ||
122 | ||
123 | @b wxIcon | |
124 | Under Windows, wxIcon may load the following formats: | |
125 | ||
126 | @li Windows icon resource (wxBITMAP_TYPE_ICO_RESOURCE) | |
127 | @li Windows icon file (wxBITMAP_TYPE_ICO) | |
128 | @li XPM data and file (wxBITMAP_TYPE_XPM) | |
129 | ||
130 | Under wxGTK, wxIcon may load the following formats: | |
131 | ||
132 | @li XPM data and file (wxBITMAP_TYPE_XPM) | |
133 | @li All formats that are supported by the #wxImage class. | |
134 | ||
135 | Under wxMotif and wxX11, wxIcon may load the following formats: | |
136 | ||
137 | @li XBM data and file (wxBITMAP_TYPE_XBM) | |
138 | @li XPM data and file (wxBITMAP_TYPE_XPM) | |
139 | @li All formats that are supported by the #wxImage class. | |
140 | ||
141 | ||
142 | @b wxCursor | |
143 | Under Windows, wxCursor may load the following formats: | |
144 | ||
145 | @li Windows cursor resource (wxBITMAP_TYPE_CUR_RESOURCE) | |
146 | @li Windows cursor file (wxBITMAP_TYPE_CUR) | |
147 | @li Windows icon file (wxBITMAP_TYPE_ICO) | |
148 | @li Windows bitmap file (wxBITMAP_TYPE_BMP) | |
149 | ||
150 | Under wxGTK, wxCursor may load the following formats (in additional | |
151 | to stock cursors): | |
152 | ||
153 | @li None (stock cursors only). | |
154 | ||
155 | Under wxMotif and wxX11, wxCursor may load the following formats: | |
156 | ||
157 | @li XBM data and file (wxBITMAP_TYPE_XBM) | |
158 | ||
159 | ||
160 | ||
161 | @section overview_bitmap_handlers Bitmap format handlers | |
162 | ||
163 | To provide extensibility, the functionality for loading and saving bitmap formats | |
164 | is not implemented in the wxBitmap class, but in a number of handler classes, | |
165 | derived from wxBitmapHandler. There is a static list of handlers which wxBitmap | |
166 | examines when a file load/save operation is requested. | |
167 | ||
168 | Some handlers are provided as standard, but if you | |
169 | have special requirements, you may wish to initialise the wxBitmap class with | |
170 | some extra handlers which you write yourself or receive from a third party. | |
171 | ||
172 | To add a handler object to wxBitmap, your application needs to include the header | |
173 | which implements it, and then call the static function wxBitmap::AddHandler. | |
174 | ||
175 | @b Note: bitmap handlers are not implemented on all platforms, and new ones rarely need | |
176 | to be implemented since wxImage can be used for loading most formats, as noted earlier. | |
177 | ||
178 | */ | |
179 |