| Page: | 1 | 2 | 3 |
|---|
Once you have connected to an X server, you can use the Xlib functions to:
5.1. Creating and Freeing Pixmaps
Pixmaps can only be used on the screen on which they were created. Pixmaps are off-screen resources that are used for various operations, for example, defining cursors as tiling patterns or as the source for certain raster operations. Most graphics requests can operate either on a window or on a pixmap. A bitmap is a single bit-plane pixmap.
To create a pixmap of a given size, use XCreatePixmap.
Pixmap XCreatePixmap(display, d, width, height, depth) Display *display; Drawable d; unsigned int width, height; unsigned int depth;
The XCreatePixmap function creates a pixmap of the width, height, and depth you specified and returns a pixmap ID that identifies it. It is valid to pass an InputOnly window to the drawable argument. The width and height arguments must be nonzero, or a BadValue error results. The depth argument must be one of the depths supported by the screen of the specified drawable, or a BadValue error results.
The server uses the specified drawable to determine on which screen to create the pixmap. The pixmap can be used only on this screen and only with other drawables of the same depth (see XCopyPlane for an exception to this rule). The initial contents of the pixmap are undefined.
XCreatePixmap can generate BadAlloc, BadDrawable, and BadValue errors.
To free all storage associated with a specified pixmap, use XFreePixmap.
XFreePixmap(display, pixmap) Display *display; Pixmap pixmap;
The XFreePixmap function first deletes the association between the pixmap ID and the pixmap. Then, the X server frees the pixmap storage when there are no references to it. The pixmap should never be referenced again.
XFreePixmap can generate a BadPixmap error.
| Home |
|---|
5.2. Creating, Recoloring, and Freeing Cursors
Each window can have a different cursor defined for it. Whenever the pointer is in a visible window, it is set to the cursor defined for that window. If no cursor was defined for that window, the cursor is the one defined for the parent window.
From X's perspective, a cursor consists of a cursor source, mask, colors, and a hotspot. The mask pixmap determines the shape of the cursor and must be a depth of one. The source pixmap must have a depth of one, and the colors determine the colors of the source. The hotspot defines the point on the cursor that is reported when a pointer event occurs. There may be limitations imposed by the hardware on cursors as to size and whether a mask is implemented. XQueryBestCursor can be used to find out what sizes are possible. There is a standard font for creating cursors, but Xlib provides functions that you can use to create cursors from an arbitrary font or from bitmaps.
To create a cursor from the standard cursor font, use XCreateFontCursor.
#include <X11/cursorfont.h> Cursor XCreateFontCursor(display, shape) Display *display; unsigned int shape;
X provides a set of standard cursor shapes in a special font named cursor. Applications are encouraged to use this interface for their cursors because the font can be customized for the individual display type. The shape argument specifies which glyph of the standard fonts to use.
The hotspot comes from the information stored in the cursor font. The initial colors of a cursor are a black foreground and a white background (see XRecolorCursor). For further information about cursor shapes, see Appendix B.
XCreateFontCursor can generate BadAlloc and BadValue errors.
To create a cursor from font glyphs, use XCreateGlyphCursor.
Cursor XCreateGlyphCursor(display, source_font, mask_font, source_char, mask_char, foreground_color, background_color) Display *display; Font source_font, mask_font; unsigned int source_char, mask_char; XColor *foreground_color; XColor *background_color;
The XCreateGlyphCursor function is similar to XCreatePixmapCursor except that the source and mask bitmaps are obtained from the specified font glyphs. The source_char must be a defined glyph in source_font, or a BadValue error results. If mask_font is given, mask_char must be a defined glyph in mask_font, or a BadValue error results. The mask_font and character are optional. The origins of the source_char and mask_char (if defined) glyphs are positioned coincidentally and define the hotspot. The source_char and mask_char need not have the same bounding box metrics, and there is no restriction on the placement of the hotspot relative to the bounding boxes. If no mask_char is given, all pixels of the source are displayed. You can free the fonts immediately by calling XFreeFont if no further explicit references to them are to be made.
| Home |
|---|
For 2-byte matrix fonts, the 16-bit value should be formed with the byte1 member in the most-significant byte and the byte2 member in the least-significant byte.
XCreateGlyphCursor can generate BadAlloc, BadFont, and BadValue errors.
To create a cursor from two bitmaps, use XCreatePixmapCursor.
Cursor XCreatePixmapCursor(display, source, mask, foreground_color, background_color, x, y) Display *display; Pixmap source; Pixmap mask; XColor *foreground_color; XColor *background_color; unsigned int x, y;
The XCreatePixmapCursor function creates a cursor and returns the cursor ID associated with it. The foreground and background RGB values must be specified using foreground_color ,and background_color, even if the X server only has a StaticGray or GrayScale screen. The foreground color is used for the pixels set to 1 in the source, and the background color is used for the pixels set to 0. Both source and mask, if specified, must have depth one (or a BadMatch error results) but can have any root. The mask argument defines the shape of the cursor. The pixels set to 1 in the mask define which source pixels are displayed, and the pixels set to 0 define which pixels are ignored. If no mask is given, all pixels of the source are displayed. The mask, if present, must be the same size as the pixmap defined by the source argument, or a BadMatch error results. The hotspot must be a point within the source, or a BadMatch error results.
The components of the cursor can be transformed arbitrarily to meet display limitations. The pixmaps can be freed immediately if no further explicit references to them are to be made. Subsequent drawing in the source or mask pixmap has an undefined effect on the cursor. The X server might or might not make a copy of the pixmap. XCreatePixmapCursor can generate BadAlloc and BadPixmap errors.
To determine useful cursor sizes, use XQueryBestCursor.
Status XQueryBestCursor(display, d, width, height, width_return, height_return) Display *display; Drawable d; unsigned int width, height; unsigned int *width_return, *height_return;
Some displays allow larger cursors than other displays. The XQueryBestCursor function provides a way to find out what size cursors are actually possible on the display. It returns the largest size that can be displayed. Applications should be prepared to use smaller cursors on displays that cannot support large ones.
XQueryBestCursor can generate a BadDrawable error.
To change the color of a given cursor, use XRecolorCursor.
XRecolorCursor(display, cursor, foreground_color, background_color) Display *display; Cursor cursor; XColor *foreground_color, *background_color;
The XRecolorCursor function changes the color of the specified cursor, and if the cursor is being displayed on a screen, the change is visible immediately. The pixel members of the XColor structures are ignored; only the RGB values are used.
XRecolorCursor can generate a BadCursor error.
To free (destroy) a given cursor, use XFreeCursor.
XFreeCursor(display, cursor) Display *display; Cursor cursor;
The XFreeCursor function deletes the association between the cursor resource ID and the specified cursor. The cursor storage is freed when no other resource references it. The specified cursor ID should not be referred to again.
XFreeCursor can generate a BadCursor error.
| Home |
|---|
| Contents | Previous Chapter | Next Chapter |