Changing cursor graphic on clickable button hover

Started by Kini Games, Thu 18/01/2024 09:07:33

Previous topic - Next topic

Kini Games

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):

Code: ags
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!

Khris

Code: ags
  if (anyGUIControl && anyGUIControl.AsButton)

Kini Games

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



Khris

Yeah, I was afraid of that. This should definitely work:
Code: ags
  if (anyGUIControl != null && anyGUIControl.AsButton != null)

Kini Games

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.

Code: ags
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); 
  }
}

SMF spam blocked by CleanTalk