change cursor on gui button and back

Started by HandsFree, Mon 28/05/2012 11:47:04

Previous topic - Next topic

HandsFree

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

geork

Hello!

Code: AGS

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

//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.

Khris

#2
To only change over an actual button and not any GUIControl, use:
Code: ags
  GUIControl*gc = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
  if (gc != null && gc.AsButton != null) {


Edit: corrected code

HandsFree

I get an null pointer referenced on the line with if (gc.AsButton != null)
(and I did change GUControl*gc to GUIControl*gc :))

Khris


HandsFree

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

SMF spam blocked by CleanTalk