blt::bitmap(3tcl) | BLT Built-In Commands | blt::bitmap(3tcl) |
bitmap - Define a new bitmap from a Tcl script
bitmap define bitmapName data ?option value?...
bitmap compose bitmapName text ?option value?...
bitmap exists bitmapName
bitmap source bitmapName
bitmap data bitmapName
bitmap height bitmapName
bitmap width bitmapName
The bitmap command lets you create new bitmaps directly from your Tcl script. The bitmap can be specified as a list of data or a text string which is converted into a bitmap. You can arbitrarily scale or rotate the bitmap too.
Bitmaps are commonly used within Tk. In label and button widgets, you display bitmaps them instead of text strings and in the canvas and text widgets, they're used for stippling. But Tk let's you can create new bitmaps only by reading the bitmap data from a file. This makes bitmaps cumbersome to manage, especially in packaging the program as a wish script, since each bitmap must be its own file. It would be nicer if you could create new bitmaps directly from your Tcl script.
The bitmap command lets you do just that. You can specify the bitmap as in various formats (such as the X11 bitmap format). You can also compose a bitmap from a text string. The bitmap command also lets you and arbitrarily rotate or scale the bitmap. For example, you could use this to create button widgets with the text label rotated 90 degrees.
<<<<<<< bitmap.mann You can define a new bitmap with the define operation. For example, let's say you are using the X11 bitmap "gray1". Normally to use it, you would specify the location of the file.
label .l -bitmap @/usr/X11R6/include/X11/bitmaps/gray1
But you can simply cut and paste the contents of "gray1" into the bitmap command.
bitmap define gray1 {
#define gray1_width 2
#define gray1_height 2
static char gray1_bits[] = {
0x01, 0x02}; } label .l -bitmap gray1
Tk will recognize "gray1" as a bitmap which can now be used with any widget that accepts bitmaps.
.barchart element configure elem1 -stipple gray1
The bitmap data can be specified in a multitude of forms. The following commands are all equivalent.
bitmap define gray1 {
#define gray1_width 2
#define gray1_height 2
static char gray1_bits[] = {
0x01, 0x02}; } bitmap define gray1 { { 2 2 } { 0x01, 0x02 } } bitmap define gray1 { { 2 2 } { 0x01 0x02 } } bitmap define gray1 { { 2 2 } { 1 2 } }
Either the data is in the standard X11 bitmap form, or it's a list of two lists. The first list contains the height and width of the bitmap. The second list is the bitmap source data. Each element of that list is an hexadecimal number specifying which pixels are foreground (1) and which are background (0) of the bitmap. Note that the format of the source data is exactly that of the XBM format.
You can scale or rotate the bitmap as you create it, by using the -scale or-rotate options.
bitmap define gray1 {
#define gray1_width 2
#define gray1_height 2
static char gray1_bits[] = {
0x01, 0x02}; } -scale 2.0 -rotate 90.0
In addition, you can compose bitmaps from text strings. This makes it easy to create rotated buttons or labels. The text string can have multi-line.
bitmap compose rot_text "This is rotated\ntext" \ -rotate 90.0 -font fixed
There are also a number of ways to query bitmaps. This isn't limited to bitmaps that you create, but any bitmap.
bitmap exists rot_text bitmap width rot_text bitmap height rot_text bitmap data rot_text bitmap source rot_text
The exists operation indicates if a bitmap by that name is defined. You can query the dimensions of the bitmap using the width and height operations. The data operation returns the list of the data used to create the bitmap. For example, you could query the data of a bitmap and send it across the network to another Tk application.
set data [bitmap data @/usr/X11R6/include/X11/bitmaps/ghost.xbm] send {wish #2} bitmap define ghost $data
The following operations are available for bitmap:
Tk currently offers no way of destroying bitmaps. Once a bitmap is created, it exists until the application terminates.
bitmap
2.5 | BLT |