Mouse and Touch Screen (Cursor)
Introduction
Gum supports reading from the mouse and touch screen for events. Both the mouse and touch screen report their actions through the Cursor class. Controls which respond to click events (such as Button and CheckBox) automatically read from the Cursor.
Code Example: Accessing the Cursor
GumService contains an instance of the Cursor class. The following code shows how to access the Cursor class and create rectangles when the Cursor detects a click.
protected override void Update(GameTime gameTime)
{
GumUI.Update(gameTime);
Cursor cursor = GumUI.Cursor;
if(cursor.PrimaryClick)
{
ColoredRectangleRuntime rectangle = new ();
rectangle.AddToRoot();
rectangle.X = cursor.XRespectingGumZoomAndBounds();
rectangle.Y = cursor.YRespectingGumZoomAndBounds();
rectangle.Color = Color.Red;
}
base.Update(gameTime);
}
Cursor clicksChecking Control Over
The Cursor class reports information about what it is over which can be checked in events or in an Update call.
WindowOver
The WindowOver property returns the visual that the Cursor is over. The following code shows how to detect the Button that the Cursor is hovering over.

Disabling the Cursor Globally
The Cursor instance reported by GumService can be replaced with a custom implementation of the ICursor interface. A custom ICursor class can be created to modify its behavior. For example, the following implementation disables all behavior:
Future versions of Gum are likely to change the ICursor class by adding or renaming properties. Be aware that any custom ICursor implementation may need to be adjusted in response to these changes.
This DisabledCursor class can be assigned to disable all Cursor actions as shown in the following code:

DisabledCursor used to prevent UI interactionLast updated
Was this helpful?

