Change cursor when at bottom of screen & then change back

Started by auhsor, Mon 27/06/2005 10:48:22

Previous topic - Next topic

auhsor

Ok sorry about the simple question, but I can't sem to work it out. I havn't used AGS for a while and now starting a game, it's all pretty unfamiliar. I've read the manual faq's etc, and can't seem to work it out.

I have a gui at the bottom of the screen. Its one of those always on top type of things with buttons etc. So yeah when the mouse is hovered over that gui, I want the cursor to change to a pointer, and when it is moved back over the game area to go to what it was last.

I've tried:
Code: ags

if (mouse.y > 219)
  {  
      mouse.SaveCursorUntilItLeaves();
      mouse.Mode = eModePointer;
  }
  else
  {
      mouse.Mode = mouse.SaveCursorUntilItLeaves();
  }


in function repeatedly_execute(), but that is quite bad. I need to somehow remember the last cursor option. Any help would be appreciated.

Gilbert

I think the problem is:
1. You save the cursor in repeatedly_execute(), so it will be saved every game loop, as long as the cursor's y coordinate is still >219, which is creating problem, because after the cursor was changed to the pointer, the cursor mode is to be continuously saved (so after a loop the actual saved mode is eModePointer, not the original mode).
2. from manual:
Quote
Mouse.SaveCursorUntilItLeaves()

Saves the current mouse cursor, and restores it when the mouse leaves the current hotspot, object or character.
So actually SaveCursorUntilItLeaves() was meant for cursor over hotspot, object or character (but not GUI) and the cursor will automatically be restored whenever it moves off the areas.

Proposed fix are:
1. use a int variable instead to save the mouse mode.
2. use another variable to keep track of the status if the cursor is on the GUI last loop already, so it won't save the mode again.

This is my codes:

1. on top of script declare:
Code: ags

int savedmousemode;
int mouseovergui=0;

2. in repeatedly_execute():
Code: ags

if (mouse.y>219) {
Ã,  if (mouseovergui==0){
Ã,  Ã,  Ã, mouseovergui=1;Ã,  Ã,  Ã, 
Ã,  Ã,  Ã, savedmousemode=mouse.Mode;
Ã,  Ã,  Ã, mouse.Mode = eModePointer;
Ã,  }
} elseÃ,  if (mouseovergui){
Ã,  Ã,  Ã, mouseovergui=0;
Ã,  Ã,  Ã, mouse.Mode = savedmousemode;
}

auhsor

Ah very nice! Thanks for that. Thats alot neater and actually works and makes sense. I didn't know I could store the mouse modes in an int. Must be those fancy enumerated type things maybe.

Gilbert

eNums are actually integers, it's just there so you don't need to emember the exact numbers yourself and can have names.

Sektor 13

i think easier would be to use GetGUIAt (or something like that) like

if (GetGUIAt(*gui number*)==1){
SetCursorGraphics...
}
else

SetCursoGraphics...


..or something luike that

Gilbert

Well it just depends on how to manage the stuff, both methods are okay (GetGUIAt() would be better if it's not easy to check whether you're over it just by coordinates checking).
But if you still want to restore the original cursor (which may not be fixed, your codes are good when the cursor is fixed outside of that GUI), the codes would still be similar in length:

Code: ags

if  (GUI.GetAtScreenXY(mouse.x, mouse.y) == 1) {
  if (mouseovergui==0){
     mouseovergui=1;     
     savedmousemode=mouse.Mode;
     mouse.Mode = eModePointer;
  }
} else  if (mouseovergui){
     mouseovergui=0;
     mouse.Mode = savedmousemode;
}


(Also, SetCursorGraphics() only changes the appearance of the cursor, not th emode, unless that's what you really want).
   

auhsor

Hey thats also great code, and I'll probably use that later for another purpose. Thats useful if your gui is anywhere and different shapes right?

Gilbert

Yeah, it's for more general use. But for your previous case when the GUI is just an area on the bottom both will work.

auhsor


SMF spam blocked by CleanTalk