next up previous contents
Next: Examples Up: Rectangleslines, dots, arcs Previous: Printing Characters on the

Creating Cursors

X provides a automatic facility whereby a cursor may be registered for each window and whenever the mouse is in that window it will take on the correct shape. If a special cursor has not been registered for a window the mouse will use the parent-window's cursor.

There are three cursor creating routines. The 1st is much the easiest:- (check in <X11/cursorfont.h> for shape names, or use the xcursors program if available)

Cursor XCreateFontCursor(display,shape);
The utility bitmap is useful for designing bitmaps if you want a cursor which is not in the standard library. Such cursors are defined in terms of two bitmaps and two pixel values. The cursor bitmap determines the shape of the cursor using the display function and the foreground and background pixel values, while the mask bitmap determines the area which the cursor is permitted to modify. Every cursor has a hot-spot which determines the coordinates of the point on the screen where the X server considers it to be. The relative coordinates of this point are also given at this stage.
Cursor XCreateGlyphCursor(display,sfont,mfont,schar,mchar,scolor,bcolor)
   Font sfont;               /* font glyph for cursor*/
   Font mfont;               /* mask font*/       
   unsigned int schar;       /* shape of cursor*/ 
   unsigned int mchar;       /* mask character */ 
   XColor *scolor;            /* RGB foreground */
   XColor *bcolor;            /* RGB background */

Cursor XCreatePixmapCursor(display,source,mask,scolor,bcolor,x,y)
   Pixmap source;
   Pixmap mask;
   XColor *scolor;
   XColor *bcolor;
   unsigned int x,y;

XFreeCursor(display,cursor) /* REMOVE A CURSOR PREVIOUSLY GENERATED */
    Cursor cursor;

XDefineCursor(display,w, cursor)
    Cursor cursor; /*use this cursor when pointer is in window */

XUndefineCursor(display,w) /*mouse will use parent's cursor  */


Tim Love
Mon Mar 11 17:03:18 GMT 1996