'Capturing' clicks for GUI items

Hey guys,

I want to be able to capture certain mouse activities in a different way when they are performed on a GUI item (compared to the rest of the screen).

For example, if I click on the screen --> something happens. But if I click on a button or scroll bar, I don’t want it to happen.

I’ve thought about doing it this way - I can get the location of the mouse watcher.getMouse().getX() and watcher.getMouse().getY()

Now I need to find a way to check whether this (x, y) coordinate is a point that is covered by say, a DirectFrame.

The only issue is, when I place a DirectFrame onto the screen, the values I use to describe its size and location are strange. They don’t seem to be in a coordinate system relative to the screen that usually goes from about -1 to 1. Also, when I resize the screen, the GUI items tend to resize in funny ways :S

Are there any GUI methods that would give me the current area covered by the GUI element so I can see whether a mouse click is in that area?

Or even something like, the coordinates of the center of a frame, and its height/width in absolute (and not relative values), so i can calculate whether the mouse click was within its area.

I really want to be able to click on something like a GUI scroll bar, and not also be clicking on the stuff ‘underneath’.

why not use a directButton? it’s designed to be clickable.

hmm… I think maybe I wasn’t so clear.

The problem isn’t about clicking on GUI items. The problem is, when I click on a GUI item, I don’t want the click to do anything else.

Imagine I have this:
base.accept(‘mouse1’, methodThatDoesStuff)

However, when I click on a GUI item like a button or a slider, I don’t want to trigger methodThatDoesStuff.

I’ve tried defining an area on the screen that methodThatDoesStuff gets triggered for - but it doesn’t work because if I resize the window, GUI items resize. Which means sometimes when I click on a GUI item, I’ll end up triggering methodThatDoesStuff

I need to find a way to check whether a click was on a GUI item, so I can suppress methodThatDoesStuff.

No idea what you actually want but it seems to besomething very unorthodox. Watching the pointer’s position is nonesense. That’s what the GUI objects in DirectGui are for.

If you want your buttons to do absolutely nothing, assign them a function that does nothing.

If you want to catch all mouse click events except those on your buttons, then watch for the mouse1 event and check in the called function if a button has been pressed. if so, do nothing.

If you want something else or don’t know what you want at all (happens to everybody), feel free to ask again with a bit more details.

Let me try…
So for example you have assigned an event to the left mouse button. When you click on a DirectButton with the left mouse button, your event is called as well. is that it?

Umm, now that you say that… I have no idea.
Let’s try.

EDIT: you’re right. GUI elements catch the mouse1 event (at least the DirectButton I just tested)

But considering this I am even more confused about what the OP is about.

Hmm, I’m pretty sure that when a DirectButton receives a mouse click, that mouse click should not be sent to any other listeners, by default:

[DirectGUI and event handling...)

Is this different than what you are seeing?

Okay, firstly

This works if i’m only talking about things like buttons and sliders.

I also have GUI elements that are DirectFrame, or DirectScrolledFrame

Yes, that’s exactly the problem… the mouse click still triggers stuff.

I wasn’t aware that when DirectButton receives a mouseclick, the click shouldn’t be sent anywhere else. Because in my program it defintely is >.<

Time to do some testing and see if I can replicate my problem in a small program.

However, let’s say I manage to get DirectButton to behave as it should - mouse clicks on it won’t trigger other events. I still have the problem of things like DirectFrames. A DirectFrame isn’t meant to accept mouse clicks, but when I click on a DirectFrame, I also don’t want the mouse event to be triggered.

DirectFrames are disabled by default, so they’re transparent to mouse events. If you want a DirectFrame to be opaque to mouse events, and prevent a mouse event from being sent elsewhere, you just have to pass state = DGG.NORMAL to the constructor.


Okay, thanks for that.

As for my problem with DirectButton not capture mouse clicks, I’ve realized what the issue is.

The code I have that responds to mouse clicks was not actually responding to the mouse1 event. It was tracking the position and state of the mouse buttons each frame.

Now that I know I can get GUI items to suppress mouse1 events, I should be able to change my code accordingly to take advantage of that.

Thanks for the help here, and sorry if my OP was not all that clear about what I needed.