class Gdk::Cursor

Overview

Used to create and destroy cursors.

Cursors are immutable objects, so once you created them, there is no way to modify them later. You should create a new cursor when you want to change something about it.

Cursors by themselves are not very interesting: they must be bound to a window for users to see them. This is done with Gdk::Surface#cursor= or Gdk::Surface#device_cursor=. Applications will typically use higher-level GTK functions such as gtk_widget_set_cursor() instead.

Cursors are not bound to a given Gdk::Display, so they can be shared. However, the appearance of cursors may vary when used on different platforms.

Named and texture cursors

There are multiple ways to create cursors. The platform's own cursors can be created with Gdk::Cursor#new_from_name. That function lists the commonly available names that are shared with the CSS specification. Other names may be available, depending on the platform in use. On some platforms, what images are used for named cursors may be influenced by the cursor theme.

Another option to create a cursor is to use Gdk::Cursor#new_from_texture and provide an image to use for the cursor.

To ease work with unsupported cursors, a fallback cursor can be provided. If a Gdk::Surface cannot use a cursor because of the reasons mentioned above, it will try the fallback cursor. Fallback cursors can themselves have fallback cursors again, so it is possible to provide a chain of progressively easier to support cursors. If none of the provided cursors can be supported, the default cursor will be the ultimate fallback.

Defined in:

lib/gi-crystal/src/auto/gdk-4.0/cursor.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class GObject::Object

==(other : self) ==, bind_property(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags) : GObject::Binding bind_property, bind_property_full(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags, transform_to : GObject::Closure, transform_from : GObject::Closure) : GObject::Binding bind_property_full, data(key : String) : Pointer(Void) | Nil data, finalize finalize, freeze_notify : Nil freeze_notify, getv(names : Enumerable(String), values : Enumerable(_)) : Nil getv, hash(hasher) hash, notify(property_name : String) : Nil notify, notify_by_pspec(pspec : GObject::ParamSpec) : Nil notify_by_pspec, notify_signal notify_signal, property(property_name : String, value : _) : Nil property, qdata(quark : UInt32) : Pointer(Void) | Nil qdata, ref_count : UInt32 ref_count, run_dispose : Nil run_dispose, set_data(key : String, data : Pointer(Void) | Nil) : Nil set_data, set_property(property_name : String, value : _) : Nil set_property, steal_data(key : String) : Pointer(Void) | Nil steal_data, steal_qdata(quark : UInt32) : Pointer(Void) | Nil steal_qdata, thaw_notify : Nil thaw_notify, to_unsafe : Pointer(Void) to_unsafe, watch_closure(closure : GObject::Closure) : Nil watch_closure

Constructor methods inherited from class GObject::Object

cast(obj : GObject::Object) : self cast, new(pointer : Pointer(Void), transfer : GICrystal::Transfer)
new
new
, newv(object_type : UInt64, parameters : Enumerable(GObject::Parameter)) : self newv

Class methods inherited from class GObject::Object

cast?(obj : GObject::Object) : self | Nil cast?, compat_control(what : UInt64, data : Pointer(Void) | Nil) : UInt64 compat_control, g_type : UInt64 g_type, interface_find_property(g_iface : GObject::TypeInterface, property_name : String) : GObject::ParamSpec interface_find_property, interface_list_properties(g_iface : GObject::TypeInterface) : Enumerable(GObject::ParamSpec) interface_list_properties

Macros inherited from class GObject::Object

previous_vfunc(*args) previous_vfunc, previous_vfunc!(*args) previous_vfunc!, signal(signature) signal

Constructor Detail

def self.new #

Initialize a new Cursor.


def self.new(*, fallback : Gdk::Cursor | Nil = nil, hotspot_x : Int32 | Nil = nil, hotspot_y : Int32 | Nil = nil, name : String | Nil = nil, texture : Gdk::Texture | Nil = nil) #

def self.new_from_texture(texture : Gdk::Texture, hotspot_x : Int32, hotspot_y : Int32, fallback : Gdk::Cursor | Nil) : self #

Creates a new cursor from a Gdk::Texture.


Class Method Detail

def self.g_type : UInt64 #

Returns the type id (GType) registered in GLib type system.


def self.new_from_callback(callback : Gdk::CursorGetTextureCallback, data : Pointer(Void) | Nil, destroy : GLib::DestroyNotify, fallback : Gdk::Cursor | Nil) : self | Nil #

Creates a new callback-based cursor object.

Cursors of this kind produce textures for the cursor image on demand, when the callback is called.


def self.new_from_name(name : String, fallback : Gdk::Cursor | Nil) : self | Nil #

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

A recommended set of cursor names that will work across different platforms can be found in the CSS specification:

| | | | | --- | --- | --- | | | "none" | No cursor | | | "default" | The default cursor | | | "help" | Help is available | | | "pointer" | Indicates a link or interactive element | | |"context-menu" | A context menu is available | | | "progress" | Progress indicator | | | "wait" | Busy cursor | | | "cell" | Cell(s) may be selected | | | "crosshair" | Simple crosshair | | | "text" | Text may be selected | | | "vertical-text" | Vertical text may be selected | | | "alias" | DND: Something will be linked | | | "copy" | DND: Something will be copied | | | "move" | DND: Something will be moved | | | "dnd-ask" | DND: User can choose action to be carried out | | | "no-drop" | DND: Can't drop here | | | "not-allowed" | DND: Action will not be carried out | | | "grab" | DND: Something can be grabbed | | | "grabbing" | DND: Something is being grabbed | | | "n-resize" | Resizing: Move north border | | | "e-resize" | Resizing: Move east border | | | "s-resize" | Resizing: Move south border | | | "w-resize" | Resizing: Move west border | | | "ne-resize" | Resizing: Move north-east corner | | | "nw-resize" | Resizing: Move north-west corner | | | "sw-resize" | Resizing: Move south-west corner | | | "se-resize" | Resizing: Move south-east corner | | | "col-resize" | Resizing: Move an item or border horizontally | | | "row-resize" | Resizing: Move an item or border vertically | | | "ew-resize" | Moving: Something can be moved horizontally | | | "ns-resize" | Moving: Something can be moved vertically | | | "nesw-resize" | Moving: Something can be moved diagonally, north-east to south-west | | | "nwse-resize" | Moving: something can be moved diagonally, north-west to south-east | | | "all-resize" | Moving: Something can be moved in any direction | | | "all-scroll" | Can scroll in any direction | | | "zoom-in" | Zoom in | | | "zoom-out" | Zoom out |


Instance Method Detail

def ==(other : self) #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


def fallback : Gdk::Cursor | Nil #

Returns the fallback for this cursor.

The fallback will be used if this cursor is not available on a given Gdk::Display. For named cursors, this can happen when using nonstandard names or when using an incomplete cursor theme. For textured cursors, this can happen when the texture is too large or when the Gdk::Display it is used on does not support textured cursors.


def fallback=(value : Gdk::Cursor | Nil) : Gdk::Cursor | Nil #

def hash(hasher) #
Description copied from class Reference

See Object#hash(hasher)


def hotspot_x : Int32 #

Returns the horizontal offset of the hotspot.

The hotspot indicates the pixel that will be directly above the cursor.

Note that named cursors may have a nonzero hotspot, but this function will only return the hotspot position for cursors created with Gdk::Cursor#new_from_texture.


def hotspot_x=(value : Int32) : Int32 #

def hotspot_y : Int32 #

Returns the vertical offset of the hotspot.

The hotspot indicates the pixel that will be directly above the cursor.

Note that named cursors may have a nonzero hotspot, but this function will only return the hotspot position for cursors created with Gdk::Cursor#new_from_texture.


def hotspot_y=(value : Int32) : Int32 #

def name : String | Nil #

Returns the name of the cursor.

If the cursor is not a named cursor, nil will be returned.


def name=(value : String) : String #

def name=(value : Nil) : Nil #

Set #name property to nil.


def name? : String | Nil #

Same as #name, but can return nil.


def texture : Gdk::Texture | Nil #

Returns the texture for the cursor.

If the cursor is a named cursor, nil will be returned.


def texture=(value : Gdk::Texture | Nil) : Gdk::Texture | Nil #