Cursors

OBJECTS

  typedef struct Cursor  Cursor;

  struct Cursor {
	App *  app;                     /* associated App */
	void * extra;                   /* platform-specific data */
  };

FUNCTIONS

  Cursor *new_cursor(App *app, Image *img, Point hotspot);
  Cursor *get_standard_cursor(App *app, int shape);
  void    del_cursor(Cursor *c);
  void    find_best_cursor_size(App *app, int *width, int *height,
                                    int *depth);
  void    set_window_cursor(Window *win, Cursor *c);
  Point   get_cursor_position(App *app);
  void    set_cursor_position(App *app, Point p);

CONSTANTS

  enum StandardCursors {
	BLANK_CURSOR,
	ARROW_CURSOR,
	WAIT_CURSOR,
	CARET_CURSOR,
	CROSS_CURSOR,
	HAND_CURSOR,
	GRAB_CURSOR,
	POINTING_CURSOR,
	PENCIL_CURSOR,
	LASSO_CURSOR,
	DROPPER_CURSOR,
	MAGNIFY_CURSOR,
	MAGPLUS_CURSOR,
	MAGMINUS_CURSOR,
	TEXT_CURSOR      = CARET_CURSOR
  };

NOTES

A Cursor represents a mouse pointer on the screen.

New cursors can be created using the new_cursor function. The hotspot point is where the 'tip' of the mouse pointer should be, and the image defines the shape of the cursor. The image can have transparent regions, and is allowed to use BLACK, WHITE and CLEAR colours, and can be at least 16 by 16 pixels in size. Other colours and larger cursors sizes may be possible, depending on the window manager.

A number of standard cursors can be obtained using the get_standard_cursor function and supplying one of the constants:

The memory used by a cursor can be reclaimed by calling del_cursor. Normally this is not necessary, since all used cursors are released when the App is deleted.

The find_best_cursor_size function asks the window manager what other colours and sizes can be used by a cursor. Pointers to integers are passed, and filled with appropriate values. The width and height will be the maximum size of a cursor. Often these will be 32 or 64, although a cursor might only look good at a width and height of 16, so beware of using all the available space. The depth may be 1, indicating BLACK and WHITE and CLEAR are the only colours to be used, or it may be 32, indicating the cursor may use any colours. The window manager may or may not allow alpha-blending effects to produce shadows around the cursor.

To change a window's cursor, use set_window_cursor. This sets the cursor for the entire window. It is valid to call this repeatedly within mouse event handlers.

The get_cursor_position returns the current location of the mouse cursor's hotspot in screen co-ordinates. To move the cursor to another location on the screen, use set_cursor_position and pass the new position in screen co-ordinates.