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