Next: , Previous: Fonts, Up: Top


16 Cursors

Standard and pixmap cursors

16.1 Overview

These functions are used to create and destroy cursors. There is a number of standard cursors, but it is also possible to construct new cursors from pixmaps and pixbufs. There may be limitations as to what kinds of cursors can be constructed on a given display, see gdk-display-supports-cursor-alpha, gdk-display-supports-cursor-color, gdk-display-get-default-cursor-size and gdk-display-get-maximal-cursor-size.

Cursors by themselves are not very interesting, they must be be bound to a window for users to see them. This is done with gdk-window-set-cursor or by setting the cursor member of the <gdk-window-attr> struct passed to gdk-window-new.

16.2 Usage

— Class: <gdk-cursor>

Derives from <gboxed>.

This class defines no direct slots.

— Function: gdk-cursor-new (cursor_type <gdk-cursor-type>) ⇒  (ret <gdk-cursor>)

Creates a new cursor from the set of builtin cursors for the default display. See gdk-cursor-new-for-display.

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
ret
a new <gdk-cursor>
— Function: gdk-cursor-new-from-pixmap (source <gdk-pixmap>) (mask <gdk-pixmap>) (fg <gdk-color>) (bg <gdk-color>) (int) (int) ⇒  (ret <gdk-cursor>)

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. You can create a bitmap from inline data as in the below example.

          
          /* This data is in X bitmap format, and can be created with the 'bitmap'
             utility. */
          &#x0023;define cursor1_width 16
          &#x0023;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.
ret
a new <gdk-cursor>.
— Function: gdk-cursor-new-from-pixbuf (display <gdk-display>) (pixbuf <gdk-pixbuf>) (int) (int) ⇒  (ret <gdk-cursor>)

Creates a new cursor from a pixbuf.

Not all GDK backends support RGBA cursors. If they are not supported, a monochrome approximation will be displayed. The functions gdk-display-supports-cursor-alpha and gdk-display-supports-cursor-color can be used to determine whether RGBA cursors are supported; gdk-display-get-default-cursor-size and gdk-display-get-maximal-cursor-size give information about cursor sizes.

On the X backend, support for RGBA cursors requires a sufficently new version of the X Render extension.

display
the <gdk-display> for which the cursor will be created
pixbuf
the <gdk-pixbuf> containing the cursor image
x
the horizontal offset of the 'hotspot' of the cursor.
y
the vertical offset of the 'hotspot' of the cursor.
ret
a new <gdk-cursor>.

Since 2.4

— Function: gdk-cursor-new-from-name (display <gdk-display>) (name mchars) ⇒  (ret <gdk-cursor>)

Creates a new cursor by looking up name in the current cursor theme.

display
the <gdk-display> for which the cursor will be created
name
the name of the cursor
ret
a new <gdk-cursor>, or ‘#f’ if there is no cursor with the given name

Since 2.8

— Function: gdk-cursor-new-for-display (display <gdk-display>) (cursor_type <gdk-cursor-type>) ⇒  (ret <gdk-cursor>)

Creates a new cursor from the set of builtin cursors. Some useful ones are:

<gdk-right-ptr> (right-facing arrow)

<gdk-crosshair> (crosshair)

(I-beam)

(busy)

(for moving objects)

(a right-pointing hand)

(a left-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-side> (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.

display
the <gdk-display> for which the cursor will be created
cursor-type
cursor to create
ret
a new <gdk-cursor>

Since 2.2

— Function: gdk-cursor-get-display (self <gdk-cursor>) ⇒  (ret <gdk-display>)

Returns the display on which the <gdk-cursor> is defined.

cursor
a <gdk-cursor>.
ret
the <gdk-display> associated to cursor

Since 2.2

— Function: gdk-cursor-get-image (self <gdk-cursor>) ⇒  (ret <gdk-pixbuf>)

Returns a <gdk-pixbuf> with the image used to display the cursor.

Note that depending on the capabilities of the windowing system and on the cursor, GDK may not be able to obtain the image data. In this case, ‘#f’ is returned.

cursor
a <gdk-cursor>
ret
a <gdk-pixbuf> representing cursor, or ‘#f

Since 2.8