About Store Forum Documentation Contact



Post Reply 
Gui Button Clicked & Mouse Hit
Author Message
Scarlet Thread Offline
Member

Post: #1
Gui Button Clicked & Mouse Hit
Hi,

It seems that Gui Button clicks are only registered in the frame after the click is actually made. I'm not sure if this is intended or if it is a bug but it is rather frustrating.

Consider the following situation: In my game, LMB click by default selects or de-selects a unit. Now if the player clicks on the GUI I want to register a GUI click. If a gui click is registered in that frame then I don't want the LMB button to select or de-select.... This of course doesn't work because Button clicks are only registered a frame after mouse clicks therefore, every time I click the GUI the character is de-selected and then only in the next frame does the GUI take the click. Same problem with RMB which clicks to move. I don't want to be moving the player every time I right click on the HUD.

Even if you use Ms.eat() when a button is clicked it is only happening in the frame after the Mouse button was clicked. Also tried setting Button::mode to immediate instead of default which didn't change anything.

Is this 'as intended' or is it a bug? It doesn't seem right. The only way I could check if a button was clicked in the current frame was to check Button::Lit() and Ms.bp(1) in a single if statement... this is a messy work around but it works for now
(This post was last modified: 04-24-2013 12:11 AM by Scarlet Thread.)
04-24-2013 12:05 AM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #2
RE: Gui Button Clicked & Mouse Hit
You can use something like this to check. Just do this once at the start of your frame somewhere.

Quote:Bool overGui = Gui.msLit() && Gui.msLit()->type() != GO_DESKTOP;

Then anytime you need to perform mouse click operations in the game world, just check overGui first. If it is true, then discard the click.
04-24-2013 12:52 AM
Find all posts by this user Quote this message in a reply
Scarlet Thread Offline
Member

Post: #3
RE: Gui Button Clicked & Mouse Hit
(04-24-2013 12:52 AM)fatcoder Wrote:  You can use something like this to check. Just do this once at the start of your frame somewhere.

Quote:Bool overGui = Gui.msLit() && Gui.msLit()->type() != GO_DESKTOP;

Then anytime you need to perform mouse click operations in the game world, just check overGui first. If it is true, then discard the click.

Cheers
04-24-2013 07:26 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Gui Button Clicked & Mouse Hit
Yes when you check for mouse clicks you should also check for the gui object focus of the mouse
if(Ms.bp(0) && Gui.ms()==&gui_obj)

Please also read comments about Gui.ms and Gui.msLit (I recommend Gui.ms for that kind of operation)
04-25-2013 12:42 PM
Find all posts by this user Quote this message in a reply
Post Reply