next up previous index
Next: Displaying Maps Up: Using Xlib Primitives Previous: Drawing Text

Using Pixmaps

The predicate xlib_pixmap/3   converts an existing Tk image into an X11 pixmap which can be used as argument in Xlib functions that require it. For example, the filling style in a graphics context   can also be xFillTiled which means that the drawing will be done using a specified pixmap as a tile, instead with foreground and background colour. For example, it is possible to write a text in rainbow colours; the file rain.pl draws a text using the gif file rainbow.gif. Let us look more in detail at some important parts of the file:

    ...
    tcl 'bind . <q> exit',
    tcl 'bind . <Configure> {after idle {prolog_event redraw %a}}',
We create bindings which exit the program when q is typed and redraw the picture when the window is reconfigured.
    ...
    tcl 'image create photo .b; .b read rainbow1.gif',
We create an image widget and initialize it from the gif file.
    ...
    xlib_pixmap(XID, '.b', Pixmap),
    xlib_change_gc(XID, xGCTile, Pixmap),
    xlib_change_gc(XID, xGCFillStyle, xFillTiled),
    xlib_font(XID, '-*-helvetica-bold-*-*-*-48-*-*-*-*-*-*-*'),
    ...
    xlib_string(XID, "An Example Of Text Tiled With Xlib", 20, 50).
When the image is created, we get the corresponding Xlib pixmap, set it as the xGCTile element of the graphics context   structure and specify that the drawing should be tiled. The graphics context structure contains also elements xGCTileStipXOrigin and xGCTileStipYOrigin to move the tiling (or stippling) pixmap to another position, but we do not need them here.

Another important point is the font specification: such large fonts most probably do not exist in fixed size, so we try to use a scalable font. A scalable font is specified just as a normal font, however all of its dashes must be explicitly present in the font name, they cannot be replaced by asterisks.

After we finish all the initialisation (which is quite complex even for such a small example), we can draw the text:


Note that we use the xlib_string/4   predicate which does not draw the background, but it does take into account all elements of the graphics context, including the tile pixmap.



next up previous index
Next: Displaying Maps Up: Using Xlib Primitives Previous: Drawing Text



Micha Meier
Tue Jul 2 09:49:39 MET DST 1996