Next: Clipboard, Previous: Windowing Support, Up: Part V Some Useful Functions [Contents][Index]

### 33.3 Cursors

XForms provides a convenience function to change the cursor shapes:

    void fl_set_cursor(Window win, int name);

where `win` must be a valid window identifier and `name` is one of the symbolic cursor names (shapes) defined by standard X or the integer values returned by `fl_create_bitmap_cursor()` or one of the Forms Library’s pre-defined symbolic names.

The X standard symbolic cursor names (all starts with `XC_`) are defined in `<X11/cursorfont.h>` (you don’t need to explicitly include this as `<forms.h>` already does this for you). For example, to set a watch-shaped cursor for form `form` (after the form is shown), the following call may be made

    fl_set_cursor(form->window, XC_watch);

The Forms Library defines a special symbolic constants, `FL_INVISIBLE_CURSOR` that can be used to hide the cursor for window `win`:

    fl_set_cursor(win, FL_INVISIBLE_CURSOR);

Depending on the structure of the application program, a call of `XFlush(fl_get_display());` may be required following `fl_set_cursor()`.

To reset the cursor to the XForms’s default (an arrow pointing northwest), use the following routine

    void fl_reset_cursor(Window win);

To change the color of a cursor use the following routine

    void fl_set_cursor_color(int name, FL_COLOR fg, FL_COLOR bg);

where `fg` and `bg` are the foreground and background color of the cursor, respectively. If the cursor is being displayed, the color change is visible immediately.

It is possible to use cursors other than those defined by the standard cursor font by creating a bitmap cursor with

    int fl_create_bitmap_cursor(const char *source, const char *mask,
                                int w, int h, int hotx, int hoty);

where `source` and `mask` are two (x)bitmaps. The mask defines the shape of the cursor. The pixels set to 1 in the mask define which source pixels are displayed. If `mask` is `NULL` all bits in `source` are displayed. `hotx` and `hoty` are the hotspot of the cursor (relative to the source’s origin). The function returns the cursor ID which can be used in calls of `fl_set_cursor()` and `fl_set_cursor_color()` etc.

Finally, there is a routine to create animated cursors where several cursors are displayed one after another:

    int fl_create_animated_cursor(int *cur_names, int interval);

The function returns the cursor name (ID) that can be shown later via `fl_set_cursor()`. In the function call `cur_names` is an array of cursor names (either X standard cursors or cursor names returned by `fl_create_bitmap_cursor()`), terminated by -1. Parameter `interval` indicates the time each cursor is displayed before it is replaced by the next in the array. An interval about 150 msec is a good value for typical uses. Note that there is currently a limit of 24 cursors per animation sequence.

Internally animated cursor works by utilizing the timeout callback. This means that if the application blocks (thus the main loop has no chance of servicing the timeouts), the animation will stop.

See demo program `cursor.c` for an example use of the cursor routines.

Next: Clipboard, Previous: Windowing Support, Up: Part V Some Useful Functions [Contents][Index]