Cursors

Name

Cursors -- standard and pixmap cursors.

Synopsis


#include <gdk/gdk.h>


struct      GdkCursor;
enum        GdkCursorType;
GdkCursor*  gdk_cursor_new                  (GdkCursorType cursor_type);
GdkCursor*  gdk_cursor_new_from_pixmap      (GdkPixmap *source,
                                             GdkPixmap *mask,
                                             GdkColor *fg,
                                             GdkColor *bg,
                                             gint x,
                                             gint y);
GdkCursor*  gdk_cursor_ref                  (GdkCursor *cursor);
void        gdk_cursor_unref                (GdkCursor *cursor);
#define     gdk_cursor_destroy

Description

Details

struct GdkCursor

struct GdkCursor
{
  GdkCursorType type;
  guint ref_count;
};


enum GdkCursorType

typedef enum
{
#include <gdk/gdkcursors.h>
  GDK_LAST_CURSOR,
  GDK_CURSOR_IS_PIXMAP = -1
} GdkCursorType;

The standard cursors available.


gdk_cursor_new ()

GdkCursor*  gdk_cursor_new                  (GdkCursorType cursor_type);

Creates a new cursor from the set of builtin cursors. Some useful ones are: GDK_RIGHT_PTR (right-facing arrow), GDK_CROSSHAIR (crosshair), GDK_IBEAM (I-beam), GDK_WATCH (busy), GDK_FLEUR (for moving objects), GDK_HAND (a pointing hand), GDK_LEFT_SIDE (resize left side), GDK_RIGHT_SIDE (resize right side), GDK_TOP_LEFT_CORNER (resize northwest corner), GDK_TOP_RIGHT_CORNER (resize northeast corner), GDK_BOTTOM_LEFT_CORNER (resize southwest corner), GDK_BOTTOM_RIGHT_CORNER (resize southeast corner), GDK_TOP_SIDE (resize top side), GDK_BOTTOM (resize bottom side), GDK_SB_H_DOUBLE_ARROW (move vertical splitter), GDK_SB_V_DOUBLE_ARROW (move horizontal splitter).

To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create a cursor with no pixels in it.

cursor_type : cursor to create
Returns : a new GdkCursor


gdk_cursor_new_from_pixmap ()

GdkCursor*  gdk_cursor_new_from_pixmap      (GdkPixmap *source,
                                             GdkPixmap *mask,
                                             GdkColor *fg,
                                             GdkColor *bg,
                                             gint x,
                                             gint y);

Creates a new cursor from a given pixmap and mask. Both the pixmap and mask must have a depth of 1 (i.e. each pixel has only 2 values - on or off). The standard cursor size is 16 by 16 pixels.

Example 1. Creating a custom cursor.

/* This data is in X bitmap format, and can be created with the 'bitmap'
   utility. */
define cursor1_width 16
define cursor1_height 16
static unsigned char cursor1_bits[] = {
   0x80, 0x01, 0x40, 0x02, 0x20, 0x04, 0x10, 0x08, 0x08, 0x10, 0x04, 0x20,
   0x82, 0x41, 0x41, 0x82, 0x41, 0x82, 0x82, 0x41, 0x04, 0x20, 0x08, 0x10,
   0x10, 0x08, 0x20, 0x04, 0x40, 0x02, 0x80, 0x01};

static unsigned char cursor1mask_bits[] = {
   0x80, 0x01, 0xc0, 0x03, 0x60, 0x06, 0x30, 0x0c, 0x18, 0x18, 0x8c, 0x31,
   0xc6, 0x63, 0x63, 0xc6, 0x63, 0xc6, 0xc6, 0x63, 0x8c, 0x31, 0x18, 0x18,
   0x30, 0x0c, 0x60, 0x06, 0xc0, 0x03, 0x80, 0x01};


  GdkCursor *cursor;
  GdkPixmap *source, *mask;
  GdkColor fg = { 0, 65535, 0, 0 }; /* Red. */
  GdkColor bg = { 0, 0, 0, 65535 }; /* Blue. */


  source = gdk_bitmap_create_from_data (NULL, cursor1_bits,
					cursor1_width, cursor1_height);
  mask = gdk_bitmap_create_from_data (NULL, cursor1mask_bits,
				      cursor1_width, cursor1_height);
  cursor = gdk_cursor_new_from_pixmap (source, mask, &fg, &bg, 8, 8);
  gdk_pixmap_unref (source);
  gdk_pixmap_unref (mask);


  gdk_window_set_cursor (widget->window, cursor);

source :the pixmap specifying the cursor.
mask :the pixmap specifying the mask, which must be the same size as source.
fg :the foreground color, used for the bits in the source which are 1. The color does not have to be allocated first.
bg :the background color, used for the bits in the source which are 0. The color does not have to be allocated first.
x :the horizontal offset of the 'hotspot' of the cursor.
y :the vertical offset of the 'hotspot' of the cursor.
Returns :a new GdkCursor.


gdk_cursor_ref ()

GdkCursor*  gdk_cursor_ref                  (GdkCursor *cursor);

Adds a reference to cursor.

cursor : a GdkCursor
Returns : Same cursor that was passed in


gdk_cursor_unref ()

void        gdk_cursor_unref                (GdkCursor *cursor);

Removes a reference from cursor, deallocating the cursor if no references remain.

cursor : a GdkCursor


gdk_cursor_destroy

#define     gdk_cursor_destroy

Destroys a cursor, freeing any resources allocated for it.