| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
<HTML> |
| 5 |
<HEAD> |
| 6 |
<TITLE>bitmap(n) manual page</TITLE> |
| 7 |
</HEAD> |
| 8 |
<BODY BGCOLOR="#efefef" TEXT="black" LINK="blue" VLINK="#551A8B" ALINK="red"> |
| 9 |
<A HREF="#toc">Table of Contents</A><P> |
| 10 |
|
| 11 |
<H2><A NAME="sect0" HREF="#toc0">Name</A></H2> |
| 12 |
bitmap - Define a new bitmap from a Tcl script |
| 13 |
|
| 14 |
<H2><A NAME="sect1" HREF="#toc1">Synopsis</A></H2> |
| 15 |
<B>bitmap define <I>bitmapName data</I></B> ?<I>option value</I>?... <P> |
| 16 |
<B>bitmap compose <I>bitmapName |
| 17 |
text</I></B> ?<I>option value</I>?... <P> |
| 18 |
<B>bitmap exists <I>bitmapName</I></B> <P> |
| 19 |
<B>bitmap source <I>bitmapName</I></B> <P> |
| 20 |
<B>bitmap |
| 21 |
data <I>bitmapName</I></B> <P> |
| 22 |
<B>bitmap height <I>bitmapName</I></B> <P> |
| 23 |
<B>bitmap width <I>bitmapName</I></B> |
| 24 |
<H2><A NAME="sect2" HREF="#toc2">Description</A></H2> |
| 25 |
The |
| 26 |
<B>bitmap</B> command lets you create new bitmaps directly from your Tcl script. |
| 27 |
The bitmap can be specified as a list of data or a text string which is |
| 28 |
converted into a bitmap. You can arbitrarily scale or rotate the bitmap |
| 29 |
too. |
| 30 |
<H2><A NAME="sect3" HREF="#toc3">Introduction</A></H2> |
| 31 |
Bitmaps are commonly used within Tk. In label and button |
| 32 |
widgets, you display bitmaps them instead of text strings and in the canvas |
| 33 |
and text widgets, they're used for stippling. But Tk let's you can create |
| 34 |
new bitmaps only by reading the bitmap data from a file. This makes bitmaps |
| 35 |
cumbersome to manage, especially in packaging the program as a <B>wish</B> script, |
| 36 |
since each bitmap must be its own file. It would be nicer if you could |
| 37 |
create new bitmaps directly from your Tcl script. <P> |
| 38 |
The <B>bitmap</B> command lets |
| 39 |
you do just that. You can specify the bitmap as in various formats (such |
| 40 |
as the X11 bitmap format). You can also compose a bitmap from a text string. |
| 41 |
The <B>bitmap</B> command also lets you and arbitrarily rotate or scale the bitmap. |
| 42 |
For example, you could use this to create button widgets with the text |
| 43 |
label rotated 90 degrees. |
| 44 |
<H2><A NAME="sect4" HREF="#toc4">Example</A></H2> |
| 45 |
<<<<<<< bitmap.mann You can define a new bitmap |
| 46 |
with the <B>define</B> operation. For example, let's say you are using the X11 |
| 47 |
bitmap "gray1". Normally to use it, you would specify the location of the |
| 48 |
file. <BR> |
| 49 |
<CODE>label .l -bitmap @/usr/X11R6/include/X11/bitmaps/gray1<BR> |
| 50 |
</CODE><P>But you can simply cut and paste the contents of "gray1" into the <B>bitmap</B> |
| 51 |
command. <BR> |
| 52 |
<CODE>bitmap define gray1 {<BR> |
| 53 |
#define gray1_width 2<BR> |
| 54 |
#define gray1_height 2<BR> |
| 55 |
static char gray1_bits[] = {<BR> |
| 56 |
0x01, 0x02};<BR> |
| 57 |
}<BR> |
| 58 |
label .l -bitmap gray1<BR> |
| 59 |
</CODE><P>Tk will recognize "gray1" as a bitmap which can now be used with any widget |
| 60 |
that accepts bitmaps. <BR> |
| •61 |
<CODE>.barchart element configure elem1 -stipple gray1<BR> |
| 62 |
</CODE><P>The bitmap data can be specified in a multitude of forms. The following commands |
| 63 |
are all equivalent. <BR> |
| 64 |
<CODE>bitmap define gray1 {<BR> |
| 65 |
#define gray1_width 2<BR> |
| 66 |
#define gray1_height 2<BR> |
| 67 |
static char gray1_bits[] = {<BR> |
| 68 |
0x01, 0x02};<BR> |
| 69 |
}<BR> |
| 70 |
bitmap define gray1 { { 2 2 } { 0x01, 0x02 } }<BR> |
| 71 |
bitmap define gray1 { { 2 2 } { 0x01 0x02 } }<BR> |
| 72 |
bitmap define gray1 { { 2 2 } { 1 2 } }<BR> |
| 73 |
</CODE><P>Either the data is in the standard X11 bitmap form, or it's a list of two |
| 74 |
lists. The first list contains the height and width of the bitmap. The second |
| 75 |
list is the bitmap source data. Each element of that list is an hexadecimal |
| 76 |
number specifying which pixels are <A HREF="foreground.1.html">foreground (1)</A> |
| 77 |
and which are background |
| 78 |
(0) of the bitmap. Note that the format of the source data is exactly that |
| 79 |
of the XBM format. <P> |
| 80 |
You can scale or rotate the bitmap as you create it, |
| 81 |
by using the <B>-scale</B> or<B>-rotate</B> options. <BR> |
| 82 |
<CODE>bitmap define gray1 {<BR> |
| 83 |
#define gray1_width 2<BR> |
| 84 |
#define gray1_height 2<BR> |
| 85 |
static char gray1_bits[] = {<BR> |
| 86 |
0x01, 0x02};<BR> |
| 87 |
} -scale 2.0 -rotate 90.0<BR> |
| 88 |
</CODE><P>In addition, you can compose bitmaps from text strings. This makes it easy |
| 89 |
to create rotated buttons or labels. The text string can have multi-line. |
| 90 |
<BR> |
| 91 |
<CODE>bitmap compose rot_text "This is rotated\ntext" \<BR> |
| 92 |
<tt> </tt> <tt> </tt> -rotate 90.0 -font fixed<BR> |
| 93 |
</CODE><P>There are also a number of ways to query bitmaps. This isn't limited to |
| 94 |
bitmaps that you create, but any bitmap. <BR> |
| 95 |
<CODE>bitmap exists rot_text<BR> |
| 96 |
bitmap width rot_text<BR> |
| 97 |
bitmap height rot_text<BR> |
| 98 |
bitmap data rot_text<BR> |
| 99 |
bitmap source rot_text<BR> |
| 100 |
</CODE><P>The <B>exists</B> operation indicates if a bitmap by that name is defined. You |
| 101 |
can query the dimensions of the bitmap using the <B>width</B> and <B>height</B> operations. |
| 102 |
The <B>data</B> operation returns the list of the data used to create the bitmap. |
| 103 |
For example, you could query the data of a bitmap and <B>send</B> it across |
| 104 |
the network to another Tk application. <BR> |
| 105 |
<CODE>set data [bitmap data @/usr/X11R6/include/X11/bitmaps/ghost.xbm]<BR> |
| 106 |
send {wish #2} bitmap define ghost $data<BR> |
| 107 |
|
| 108 |
<H2><A NAME="sect5" HREF="#toc5"></CODE><P>Operations</A></H2> |
| 109 |
The following operations are available for <B>bitmap</B>: |
| 110 |
<DL> |
| 111 |
|
| 112 |
<DT><B>bitmap compose |
| 113 |
<I>bitmapName text </I></B>?<I>option value</I>?... </DT> |
| 114 |
<DD>Creates a bitmap <I>bitmapName</I> from the text |
| 115 |
string <I>text</I>. A bitmap <I>bitmapName</I> can not already exist. The following options |
| 116 |
are available. <blockquote></DD> |
| 117 |
|
| 118 |
<DT><B>-font <I>fontName</I></B> </DT> |
| 119 |
<DD>Specifies a font to use when drawing text |
| 120 |
into the bitmap. If this option isn't specified then <I>fontName</I> defaults to |
| 121 |
<I>*-Helvetica-Bold-R-Normal-*-140-*</I>. </DD> |
| 122 |
|
| 123 |
<DT><B>-rotate <I>theta</I></B> </DT> |
| 124 |
<DD>Specifies the angle of rotation |
| 125 |
of the text in the bitmap. <I>Theta</I> is a real number representing the angle |
| 126 |
in degrees. It defaults to <I>0.0</I> degrees. </DD> |
| 127 |
|
| 128 |
<DT><B>-scale <I>value</I></B> </DT> |
| 129 |
<DD>Specifies the scale of |
| 130 |
the bitmap. <I>Value</I> is a real number representing the scale. A scale of 1.0 |
| 131 |
indicates no scaling is necessary, while 2.0 would double the size of the |
| •132 |
bitmap. There is no way to specify different scales for the width and |
| 133 |
height of the bitmap. The default scale is <I>1.0</I>. </DD> |
| 134 |
</DL> |
| 135 |
</blockquote> |
| 136 |
|
| 137 |
<DL> |
| 138 |
|
| 139 |
<DT><B>bitmap data <I>bitmapName</I></B> </DT> |
| 140 |
<DD>Returns |
| 141 |
a list of both the dimensions of the bitmap <I>bitmapName</I> and its source data. |
| 142 |
</DD> |
| 143 |
|
| 144 |
<DT><B>bitmap define <I>bitmapName data</I></B> ?<I>option value</I>?... </DT> |
| 145 |
<DD>Associates <I>bitmapName</I> with |
| 146 |
in-memory bitmap data so that <I>bitmapName</I> can be used in later calls to <B>Tk_GetBitmap</B>. |
| 147 |
The <I>bitmapName</I> argument is the name of the bitmap; it must not previously |
| 148 |
have been defined in either a call to Tk_DefineBitmap or <B>bitmap</B>. The argument |
| 149 |
<I>data</I> describes the bitmap to be created. It is either the X11 bitmap format |
| 150 |
(a C structure) or a list of two lists: the dimensions and source data. |
| 151 |
The dimensions are a list of two numbers which are the width and height |
| 152 |
of the bitmap. The source data is a list of hexadecimal values in a format |
| 153 |
similar to the X11 or X10 bitmap format. The values may be optionally separated |
| 154 |
by commas and do not need to be prefixed with "0x". The following options |
| 155 |
are available. <blockquote></DD> |
| 156 |
|
| 157 |
<DT><B>-rotate <I>theta</I></B> </DT> |
| 158 |
<DD>Specifies how many degrees to rotate the bitmap. |
| 159 |
<I>Theta</I> is a real number representing the angle. The default is <I>0.0</I> degrees. |
| 160 |
</DD> |
| 161 |
|
| 162 |
<DT><B>-scale <I>value</I></B> </DT> |
| 163 |
<DD>Specifies how to scale the bitmap. <I>Value</I> is a real number representing |
| 164 |
the scale. A scale of 1.0 indicates no scaling is necessary, while 2.0 would |
| •165 |
double the size of the bitmap. There is no way to specify different scales |
| 166 |
for the width and height of the bitmap. The default scale is <I>1.0</I>. </DD> |
| 167 |
</DL> |
| 168 |
</blockquote> |
| 169 |
|
| 170 |
<DL> |
| 171 |
|
| 172 |
<DT><B>bitmap exists |
| 173 |
<I>bitmapName</I></B> </DT> |
| 174 |
<DD>Returns <I>1</I> if a bitmap <I>bitmapName</I> exists, otherwise <I>0</I>. </DD> |
| 175 |
|
| 176 |
<DT><B>bitmap |
| 177 |
height <I>bitmapName</I></B> </DT> |
| 178 |
<DD>Returns the height in pixels of the bitmap <I>bitmapName</I>. |
| 179 |
</DD> |
| 180 |
|
| 181 |
<DT><B>bitmap source <I>bitmapName</I></B> </DT> |
| 182 |
<DD>Returns the source data of the bitmap <I>bitmapName</I>. |
| 183 |
The source data is a list of the hexadecimal values. </DD> |
| 184 |
|
| 185 |
<DT><B>bitmap width <I>bitmapName</I></B> |
| 186 |
</DT> |
| 187 |
<DD>Returns the width in pixels of the bitmap <I>bitmapName</I>. </DD> |
| 188 |
</DL> |
| 189 |
|
| 190 |
<H2><A NAME="sect6" HREF="#toc6">Limitations</A></H2> |
| 191 |
Tk currently |
| 192 |
offers no way of destroying bitmaps. Once a bitmap is created, it exists |
| 193 |
until the application terminates. |
| 194 |
<H2><A NAME="sect7" HREF="#toc7">Keywords</A></H2> |
| 195 |
bitmap <P> |
| 196 |
|
| 197 |
<HR><P> |
| 198 |
<A NAME="toc"><B>Table of Contents</B></A><P> |
| 199 |
<UL> |
| 200 |
<LI><A NAME="toc0" HREF="#sect0">Name</A></LI> |
| 201 |
<LI><A NAME="toc1" HREF="#sect1">Synopsis</A></LI> |
| 202 |
<LI><A NAME="toc2" HREF="#sect2">Description</A></LI> |
| 203 |
<LI><A NAME="toc3" HREF="#sect3">Introduction</A></LI> |
| 204 |
<LI><A NAME="toc4" HREF="#sect4">Example</A></LI> |
| 205 |
<LI><A NAME="toc5" HREF="#sect5">Operations</A></LI> |
| 206 |
<LI><A NAME="toc6" HREF="#sect6">Limitations</A></LI> |
| 207 |
<LI><A NAME="toc7" HREF="#sect7">Keywords</A></LI> |
| 208 |
</UL> |
| 209 |
</BODY></HTML> |