Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Kini Games on Thu 18/01/2024 09:07:33

Title: Changing cursor graphic on clickable button hover
Post by: Kini Games on Thu 18/01/2024 09:07:33
Hi!

I'd like to change my cursor graphic when hovering over any clickable button.

I am able to change the cursor graphic when hovering over any GUI control, using this code (in the 'repeatedly_execute' section of my global script):

GUIControl *anyGUIControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
 
if (anyGUIControl)
{
mouse.ChangeModeGraphic(eModePointer, 2); 
}
 
else
{
mouse.ChangeModeGraphic(eModePointer, 1);
}

However, this also changes the cursor graphic when hovering over GUI labels and unclickable buttons, which I don't want.

Thanks in advance!
Title: Re: Changing cursor graphic on clickable button hover
Post by: Khris on Thu 18/01/2024 10:45:18
  if (anyGUIControl && anyGUIControl.AsButton)
Title: Re: Changing cursor graphic on clickable button hover
Post by: Kini Games on Thu 18/01/2024 14:31:26
Thanks, Khris. Unfortunately, that gives me the following error (line 21 is the line in question):

Error (line 21): Operator cannot be applied to this type


Title: Re: Changing cursor graphic on clickable button hover
Post by: Khris on Thu 18/01/2024 16:29:45
Yeah, I was afraid of that. This should definitely work:
  if (anyGUIControl != null && anyGUIControl.AsButton != null)
Title: Re: Changing cursor graphic on clickable button hover
Post by: Kini Games on Thu 18/01/2024 19:14:32
That worked :) Thanks again, Khris!

For anyone who may stumble across this thread later, and who's wondering about how to stop the cursor from changing graphic when hovering over non-clickable buttons, here's the full code I ended up using.

function repeatedly_execute()
{
GUIControl *anyGUIControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
 
  if (anyGUIControl != null && anyGUIControl.AsButton != null && anyGUIControl.AsButton.Clickable)
  {
  mouse.ChangeModeGraphic(eModePointer, 2); 
  }
   
  else
  {
  mouse.ChangeModeGraphic(eModePointer, 1);
  }
}