Class Cursor
- All Implemented Interfaces:
Proxy
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 Surface.setCursor(org.gnome.gdk.Cursor)
or Surface.setDeviceCursor(org.gnome.gdk.Device, org.gnome.gdk.Cursor)
. Applications will typically
use higher-level GTK functions such as gtk_widget_set_cursor()
instead.
Cursors are not bound to a given 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 fromName(java.lang.String, org.gnome.gdk.Cursor)
. 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 fromTexture(org.gnome.gdk.Texture, int, int, org.gnome.gdk.Cursor)
and provide an image to use for the cursor.
To ease work with unsupported cursors, a fallback cursor can be provided.
If a 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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Cursor.Builder<B extends Cursor.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionCursor
(MemorySegment address) Create a Cursor proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected Cursor
asParent()
Returns this instance as if it were its parent type.static Cursor.Builder
<? extends Cursor.Builder> builder()
ACursor.Builder
object constructs aCursor
with the specified properties.static Cursor
fromCallback
(CursorGetTextureCallback callback, @Nullable Cursor fallback) Creates a new callback-based cursor object.static Cursor
Creates a new cursor by looking upname
in the current cursor theme.static Cursor
fromTexture
(Texture texture, int hotspotX, int hotspotY, @Nullable Cursor fallback) Creates a new cursor from aGdkTexture
.Returns the fallback for this this Cursor.int
Returns the horizontal offset of the hotspot.int
Returns the vertical offset of the hotspot.getName()
Returns the name of the cursor.Returns the texture for the cursor.static Type
getType()
Get the GType of the Cursor classMethods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Cursor
Create a Cursor proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
fromCallback
public static Cursor fromCallback(CursorGetTextureCallback callback, @Nullable @Nullable Cursor fallback) Creates a new callback-based cursor object.Cursors of this kind produce textures for the cursor image on demand, when the
callback
is called.- Parameters:
callback
- theGdkCursorGetTextureCallback
fallback
- theGdkCursor
to fall back to when this one cannot be supported- Returns:
- a new
GdkCursor
-
fromName
Creates a new cursor by looking upname
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" | "default" | "help" | "pointer" | | "context-menu" | "progress" | "wait" | "cell" | | "crosshair" | "text" | "vertical-text" | "alias" | | "copy" | "no-drop" | "move" | "not-allowed" | | "grab" | "grabbing" | "all-scroll" | "col-resize" | | "row-resize" | "n-resize" | "e-resize" | "s-resize" | | "w-resize" | "ne-resize" | "nw-resize" | "sw-resize" | | "se-resize" | "ew-resize" | "ns-resize" | "nesw-resize" | | "nwse-resize" | "zoom-in" | "zoom-out" | |
- Parameters:
name
- the name of the cursorfallback
-null
or theGdkCursor
to fall back to when this one cannot be supported- Returns:
- a new
GdkCursor
, ornull
if there is no cursor with the given name
-
fromTexture
public static Cursor fromTexture(Texture texture, int hotspotX, int hotspotY, @Nullable @Nullable Cursor fallback) Creates a new cursor from aGdkTexture
.- Parameters:
texture
- the texture providing the pixel datahotspotX
- the horizontal offset of the “hotspot” of the cursorhotspotY
- the vertical offset of the “hotspot” of the cursorfallback
- theGdkCursor
to fall back to when this one cannot be supported- Returns:
- a new
GdkCursor
-
getFallback
Returns the fallback for this this Cursor.The fallback will be used if this cursor is not available on a given
GdkDisplay
. 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 theGdkDisplay
it is used on does not support textured cursors.- Returns:
- the fallback of the cursor or
null
to use the default cursor as fallback
-
getHotspotX
public int getHotspotX()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
fromTexture(org.gnome.gdk.Texture, int, int, org.gnome.gdk.Cursor)
.- Returns:
- the horizontal offset of the hotspot or 0 for named cursors
-
getHotspotY
public int getHotspotY()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
fromTexture(org.gnome.gdk.Texture, int, int, org.gnome.gdk.Cursor)
.- Returns:
- the vertical offset of the hotspot or 0 for named cursors
-
getName
Returns the name of the cursor.If the cursor is not a named cursor,
null
will be returned.- Returns:
- the name of the cursor or
null
if it is not a named cursor
-
getTexture
Returns the texture for the cursor.If the cursor is a named cursor,
null
will be returned.- Returns:
- the texture for cursor or
null
if it is a named cursor
-
builder
ACursor.Builder
object constructs aCursor
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withCursor.Builder.build()
.
-