Sign in to follow this  

Mouse click on multitouch screen

This topic is 2633 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

I made a GUI for OpenGL. Everything in there uses SDL and OpenGL, and so for example something like clicking on a button, is implemented by using SDL_GetMouseState to check at what X, Y coordinate the mouse currently is, which mouse buttons are down, etc...

I have defined two different mouse related functions to a button. A button is a rectangular area, and if you do something in that rectangular area with the mouse buttons, the function will return "true".

The functions are: pressed() and clicked().

pressed() will return true if, in the previous frame, the mouse button wasn't down, and this is the first frame where the mouse button is down. So when a user presses the mouse, this function will return true exactly once during one frame.

clicked() returns true if the mouse button was down, and this is the first frame where the mouse button is up again. So, this is similar to pressed(), but it triggers only when you release the mouse button again, like buttons in e.g. MS Windows do.

Of course these functions keep some state variables, to remember what state the mouse had the previous frame and such. Note also that this GUI works like a computer game, that is, per frame, not with events and such.

Anyway, now there is a problem with this:

I don't have a computer with multitouch screen myself, but a friend has one (with Windows 7 and a multitouch screen). If I try my GUI on his multitouch computer, then some things work, some don't. It appears that the clicked() function usually doesn't work, except very rarely. So apparently, if you put your finger on the screen and release it again, the system in clicked() that I described above doesn't trigger.

What could be the cause of this? Does a multitouch computer register the "mouse button down" and "mouse button released" events in a faster succession than one frame takes in my program maybe? Or what could be happening?

Thanks.

Share this post


Link to post
Share on other sites
That's possible. I'm surprised that has worked on your own computer. There's nothing about a game that prevents you from using SDL's event-based input handling. You just check for events every frame.

Share this post


Link to post
Share on other sites
I had this behavior occur in my DirectX GUI experimentation when I was using polling input (Testing with a Lenovo X60T which has a single-touch panel).

The problem in my case was that the down/up occured within a VERY short span of time (perhaps the driver sends both messages in a single call with no artificial delay?), so polling would miss the down state every single time. My GUI buttons just wouldn't work at all.

I ended up switching to windows-message-queue handling which gets guaranteed mousedown/mouseup messages, and that fixed the issue for me.

Share this post


Link to post
Share on other sites
Quote:
Original post by Nypyren
I had this behavior occur in my DirectX GUI experimentation when I was using polling input (Testing with a Lenovo X60T which has a single-touch panel).

The problem in my case was that the down/up occured within a VERY short span of time (perhaps the driver sends both messages in a single call with no artificial delay?), so polling would miss the down state every single time. My GUI buttons just wouldn't work at all.

I ended up switching to windows-message-queue handling which gets guaranteed mousedown/mouseup messages, and that fixed the issue for me.


But relying on windows based messages would remove the point of using SDL, which allows my code to work on Linux, Windows, Macintosh and Amiga...

Is this maybe an SDL bug? In that case I should have posted this on the alternative libraries instead of general programming :)

Share this post


Link to post
Share on other sites
Are you using this?

//event loop, do every frame
SDL_Event event;
while(SDL_PollEvent(&event)){
switch(event.type){
//I probably don't have all the names right
case SDL_KEYDOWN:
...
case SDL_KEYUP:
...
case SDL_MOUSEBUTTONDOWN:
...
case SDL_MOUSEBUTTONUP:
}
}

If not, that will probably solve your problem.

Share this post


Link to post
Share on other sites

This topic is 2633 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this