Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: WHAM on Fri 29/07/2011 18:22:00

Title: [SOLVED] Gui transparent area click detection
Post by: WHAM on Fri 29/07/2011 18:22:00
I have a small problem with click detection with my GUI and GUI buttons.
Is there a way to have AGS detect clicks on a GUI or a GUI button, so that transparent areas do not detect clicks? For example, I have a GUI that is 320x30 in size (the picture I've attached) and a large portion of it is transparent. However, if the player clicks the transparent area with the walk-to cursor, the character does not respond as the click is intercepted by the GUI.

I found this 2006 thread with my searches and I could do the workaround mentioned there, but I was hoping someone would have an idea on a more elegant solution.

http://www.adventuregamestudio.co.uk/yabb/index.php?topic=28882.0

(http://whamgames.com/images/prototypes/troubleshapegui.png)

Why is it, that AGS detects clicks on transparent images correctly in characters and objects, but not GUI's and GUI buttons?
Title: Re: Gui transparent area click detection
Post by: selmiak on Sun 31/07/2011 15:34:19
why not make the gui only half as high and have the image for the half circle in the gui in the backgroundimage of the scene. Then you obviously will not be able to let the gui disappear for cutscenes.
Title: Re: Gui transparent area click detection
Post by: Mazoliin on Sun 31/07/2011 15:56:07
You could use DrawingSurface.GetPixel, and based on the result you set the gui to non-clickable, process the click again, and reset the gui to clickable.
Title: Re: Gui transparent area click detection
Post by: Khris on Sun 31/07/2011 15:59:51
You could calculate whether the cursor is over the transparent part.

bool CursorOverGUI(GUI*g) {

  int x = mouse.x, y = mouse.y;

  // ellipse
  int ex = x - 257;
  int ey = ((y - (g.Y + 35))*46)/35;
 
  if (y - g.Y < 12 && ex*ex + ey*ey > 46*46) return false;
  return true;
}


Now double click the GUI to get its OnClick and put this inside:

  if (CursorOverGUI(theGUI)) return;
  on_mouse_click(button);
Title: Re: Gui transparent area click detection
Post by: WHAM on Sun 31/07/2011 18:02:32
Sorry guys, I was a bit hasty and when I didn't get answers during the same evening, I went ahead and did a small redesign of the GUI to avoid the issue. It's just as functional, just without the round bits.

Still, thanks for the asnwers! Mazoliin's suggestion seemed like it might be the easiest to use in my case, so in the future I might look into using that.

I'll change the title to "solved" now.