Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: HandsFree on Mon 28/05/2012 11:47:04

Title: change cursor on gui button and back
Post by: HandsFree on Mon 28/05/2012 11:47:04
Searching the forum gave me this code:

if (GUIControl.GetAtScreenXY(mouse.x,mouse.y) == buttonname) {
    mouse.Mode = eModePointer;
}

This works but I like to change the cursor on any guibutton, not a specific one.
How do I check the coordinates to find if there's any button or not?

Also this way the cursor doesn't change back when the pointer is no longer over the button. I tried mouse.SaveCursorUntilItLeaves() but that doesn't work. I assume that is because it's in repeatedly_execute(). Any ideas on this?

thanks
Title: Re: change cursor on gui button and back
Post by: geork on Mon 28/05/2012 20:15:49
Hello!

Code (AGS) Select

if(GUIControl.GetAtScreenXY(mouse.x, mouse.y) != null){ //Checks whether the mouse is on ANY button
    Mouse.Mode = eModePointer;
  }
else{
    Mouse.Mode = eModeInteract; //Or whatever
  }


Should work in repeatedly_exececute(). If you want it to go back to the specific mouse mode you were in, try:

Code (AGS) Select

//Declare these at the top of the script
int m;
bool Switch = false;

//Then in repeatedly execute:
if(GUIControl.GetAtScreenXY(mouse.x, mouse.y) != null){
    if(Switch == false){
      m = Mouse.Mode;
      Switch  = true;
    }
    Mouse.Mode = eModePointer;
  }
else{
    if(Switch == true){
      Mouse.Mode = m;
      Switch = false;
    }
  }


Maybe there's a more concise way of doing this, but for now this should work just fine.
Title: Re: change cursor on gui button and back
Post by: Khris on Mon 28/05/2012 22:27:25
To only change over an actual button and not any GUIControl, use:
Code (ags) Select
  GUIControl*gc = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
  if (gc != null && gc.AsButton != null) {


Edit: corrected code
Title: Re: change cursor on gui button and back
Post by: HandsFree on Mon 28/05/2012 22:35:07
I get an null pointer referenced on the line with if (gc.AsButton != null)
(and I did change GUControl*gc to GUIControl*gc :))
Title: Re: change cursor on gui button and back
Post by: Khris on Tue 29/05/2012 00:11:41
Sorry, long day :)
I fixed the code.
Title: Re: change cursor on gui button and back
Post by: HandsFree on Tue 29/05/2012 00:59:42
Cool! Geork's code was good for the gui buttons but the inventory didn't work anymore. Now with Khris' addition everything's ok.
thanks