Class: Gdk::Cursor

Inherits:
Object
  • Object
show all
Extended by:
GLib::Deprecatable
Defined in:
lib/gdk4/cursor.rb,
lib/gdk4/deprecated.rb

Overview

GdkCursor is 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 [methodGdk.Surface.set_cursor] or [methodGdk.Surface.set_device_cursor]. Applications will typically use higher-level GTK functions such as gtk_widget_set_cursor() instead.

Cursors are not bound to a given [classGdk.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 [ctorGdk.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 [ctorGdk.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 [classGdk.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.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(texture, hotspot_x, hotspot_y, fallback) ⇒ Gdk::Cursor

Creates a new cursor from a GdkTexture.

Parameters:

  • texture (Gdk::Texture)

    the texture providing the pixel data

  • hotspot_x (Integer)

    the horizontal offset of the “hotspot” of the cursor

  • hotspot_y (Integer)

    the vertical offset of the “hotspot” of the cursor

  • fallback (Gdk::Cursor)

    the GdkCursor to fall back to when this one cannot be supported

Class Method Details

.new(*args) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/gdk4/cursor.rb', line 21

def new(*args)
  first_arg = args.first
  case first_arg
  when String, Symbol
    @caches[first_arg] ||= super
  else
    super
  end
end

Instance Method Details

#fallbackGdk::Cursor

Cursor to fall back to if this cursor cannot be displayed.

Returns:

#fallback=(fallback) ⇒ Gdk::Cursor

Cursor to fall back to if this cursor cannot be displayed.

Parameters:

Returns:

#hotspot_xInteger

X position of the cursor hotspot in the cursor image.

Returns:

  • (Integer)

    hotspot-x

#hotspot_x=(hotspot_x) ⇒ Integer

X position of the cursor hotspot in the cursor image.

Parameters:

  • hotspot_x (Integer)

Returns:

  • (Integer)

    hotspot-x

  • (Integer)

    hotspot-x

#hotspot_yInteger

Y position of the cursor hotspot in the cursor image.

Returns:

  • (Integer)

    hotspot-y

#hotspot_y=(hotspot_y) ⇒ Integer

Y position of the cursor hotspot in the cursor image.

Parameters:

  • hotspot_y (Integer)

Returns:

  • (Integer)

    hotspot-y

  • (Integer)

    hotspot-y

#nameString

Name of this this cursor.

The name will be nil if the cursor was created from a texture.

Returns:

  • (String)

    name

#name=(name) ⇒ String

Name of this this cursor.

The name will be nil if the cursor was created from a texture.

Parameters:

  • name (String)

Returns:

  • (String)

    name

  • (String)

    name

#textureGdk::Texture

The texture displayed by this cursor.

The texture will be nil if the cursor was created from a name.

Returns:

#texture=(texture) ⇒ Gdk::Texture

The texture displayed by this cursor.

The texture will be nil if the cursor was created from a name.

Parameters:

Returns: