Make GUI button Non-clickable on Transparent Area?

Started by Janik, Sun 29/10/2006 03:50:08

Previous topic - Next topic

Janik

Hi,

I am making a verb coin GUI and have 3 buttons of non-rectangular shapes. I use transparency (the magic pink color) which works fine for the display, but the mouse acts as though it is over the button even when the pixel is transparent. Is it possible to make these areas non-clickable?

Thanks!
Play pen and paper D&D? Then try DM Genie - software for Dungeons and Dragons!

Colxfile

Always carry a UV marker pen with you. When you go to a shop or a friend's house, if you see something you like, put your name and postcode on it. If it gets stolen and subsequently recovered, the police will get in touch with you so that they can 'return' it.

GarageGothic

#2
This shouldn't be too hard to script by using an invisible character, assigning the graphic of the GUI button to him and then using pixel perfect detection to see whether the mouse is over him or not. Something like:

Code: ags

function IsMouseOverButton(Button *mybutton) {
   ViewFrame *tempframe = Game.GetViewFrame(cTemp.View, cTemp.Loop, cTemp.Frame);
   tempframe.Graphic = mybutton.Graphic;
   cTemp.Transparency = 100;
   cTemp.ChangeRoom(player.Room, mybutton.OwningGUI.X + mybutton.X + Game.SpriteWidth[mybutton.Graphic]/2,  mybutton.OwningGUI.Y + mybutton.Y + Game.SpriteHeight[mybutton.Graphic]);
   cTemp.Baseline = 200; //set the baseline of character to front, to avoid other stuff getting in-between
   mybutton.OwningGUI.Clickable = false;
   bool mouseisoverbutton;
   if (Character.GetAtScreenXY(mouse.x, mouse.y) == cTemp) mouseisoverbutton = true;
   mybutton.OwningGUI.Clickable = true;
   cTemp.ChangeRoom(-1);
   return mouseisoverbutton; //returns true if mouse is over non-transparent area, otherwise false
   }


This requires that you add a character with the script-o-name TEMP, and make sure that its frame isn't used by any other character (easiest to do by creating a unique View for the character). That character should be "Clickable" and have "Ignore room area scaling" checked. Of course the game must also have "Pixel perfect click detection" turned on.

When the player clicks on a button, you run IsMouseOverButton(button) in the beginning of the button interaction, and if it returns true, you let the button script do whatever it's supposed to.

EDIT: I've tested the code and it seems to work. I don't guarantee that it's bug free though. If you need to check several non-rectangular buttons that overlap (as the shapes in a yin-yang symbol for example), you should run the check for the other button, when the topmost one is clicked and IsMouseOverButton(button) returns false.

Janik

Play pen and paper D&D? Then try DM Genie - software for Dungeons and Dragons!

SMF spam blocked by CleanTalk