mouse input problem
I have to make a grid that appears/disappears when i right-click with my mouse
I have two booleans (left_mouse_pressed, and right) and I make a check
if(right_mouse_button) drawgrid();
the problem is that it acts as if I keep the button pressed even if I click as fast as I can
so I've tried to add a timer like this
but the problem is still there (altough less evident): the grid flashes for some ms and then randomly choose to show up or not
I hope I was enough clear
thank you
I have two booleans (left_mouse_pressed, and right) and I make a check
if(right_mouse_button) drawgrid();
the problem is that it acts as if I keep the button pressed even if I click as fast as I can
so I've tried to add a timer like this
Code:
if mouse button down
if x ms have elapsed
mouse_button = true;
I haven't put a timer in the button up part
if mouse button up
mouse_button = false;but the problem is still there (altough less evident): the grid flashes for some ms and then randomly choose to show up or not
I hope I was enough clear

thank you
You want to do this:
Substituting in the button number as necessary, 1-3 for left, middle, right. 4 and 5 for scroll up/down.
Code:
if( SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(**the button number**))
I'm not sure I understand exactly what your pseudocode is doing, but it looks like you're checking the mouse state (SDL_GetMouseState(), as Skorche described) when you should be getting mousedown and mouseup events. Look up event handling and SDL_MouseButtonEvent in the SDL documentation. You shouldn't need a timer for this purpose.
Once you're using mouse button events, you simply reverse the value of the grid boolean when you get a mousedown event.
Once you're using mouse button events, you simply reverse the value of the grid boolean when you get a mousedown event.
Come to think of it, I think I misunderstood what you were asking too.
What you really want to do is let SDL take care of all the events for you. SDL_PollEvents() If you do things the event way, SDL will only tell you once that the mouse was pushed, and once when it's let back up.
What you really want to do is let SDL take care of all the events for you. SDL_PollEvents() If you do things the event way, SDL will only tell you once that the mouse was pushed, and once when it's let back up.
Skorche Wrote:Come to think of it, I think I misunderstood what you were asking too.
What you really want to do is let SDL take care of all the events for you. SDL_PollEvents() If you do things the event way, SDL will only tell you once that the mouse was pushed, and once when it's let back up.
yeah I wasn't very clear

I'm using SDL_PollEvents
this for mouse up (and similar code for mouse down)
Code:
case SDL_MOUSEBUTTONUP: {
SDL_MouseButtonEvent * e = (SDL_MouseButtonEvent*)&event;
if(e->button == SDL_BUTTON_LEFT)
left_mouse_pressed = false;
if(e->button == SDL_BUTTON_RIGHT)
right_mouse_pressed = false;
break;
}when I push a mouse button the grid flashes as if it was pressed many times
I've also tried using switch(event.button.button) instead of the pointer
ok here's the program
on my mac there is a strange problem: the mouse y is inverted :/
it was all ok on my pc...
left click to go past the splash screen, and then right click to toggle the grid
edit:
forgot the link
link
on my mac there is a strange problem: the mouse y is inverted :/
it was all ok on my pc...
left click to go past the splash screen, and then right click to toggle the grid
edit:
forgot the link

link
Your problem, I think, is that you're effectively converting the events back into state variables, and that's not helpful in this instance. You need to do something like this instead:
Put the code directly in the event handler (or in a function called from the event handler) so that you can react to it immediately, instead of trying to record its value and reacting to it somewhere else.
Code:
case SDL_MOUSEBUTTONUP:
{
SDL_MouseButtonEvent * e = (SDL_MouseButtonEvent*)&event;
if(e->button == SDL_BUTTON_RIGHT)
show_grid_boolean = !show_grid_boolean; // Flip the grid on or off
break;
}NCarter Wrote:Your problem, I think, is that you're effectively converting the events back into state variables, and that's not helpful in this instance. You need to do something like this instead:
Put the code directly in the event handler (or in a function called from the event handler) so that you can react to it immediately, instead of trying to record its value and reacting to it somewhere else.Code:
case SDL_MOUSEBUTTONUP:
{
SDL_MouseButtonEvent * e = (SDL_MouseButtonEvent*)&event;
if(e->button == SDL_BUTTON_RIGHT)
show_grid_boolean = !show_grid_boolean; // Flip the grid on or off
break;
}
umm I'll try, thank you
the fact is that I need the buttons to do different actions depending on the level/position/etc...
so I wanted to make each function check if the button is pressed and react accordingly
EDIT:
it works perfectly this way... the only problem is that I'll need a lot of global variables to handle everything inside SDL_PollEvent
anyone can suggest me a better solution?
p.s. any idea why the mouse motion tracking works ok in win and is flipped in mac os x ?
Quote:p.s. any idea why the mouse motion tracking works ok in win and is flipped in mac os x ?This is a known issue, although I can't remember the cause or the fix; I think it also only affects OS X 10.2 - I've never encountered the problem in 10.1 or 10.3.
Mark Bishop
I have, and it only seems to occur in when openGL is active and full screen. I simply just flip the y coordinate if a boolean for fullscreen is set.
Skorche Wrote:I have, and it only seems to occur in when openGL is active and full screen. I simply just flip the y coordinate if a boolean for fullscreen is set.
my app is not fullscreen
however the other problem is more urgent right now
plz help me
leggo Wrote:it works perfectly this way... the only problem is that I'll need a lot of global variables to handle everything inside SDL_PollEventWhy would that require lots of global variables? Can't you have your event handler use a single (global?) variable to detect which mode you're in, then call an appropriate function to inform the associated part of the program about the mouse up event?![]()
anyone can suggest me a better solution?
Failing that, you could try using SDL_GetMouseState() to detect the current mouse button state and write a routine which prevents it from toggling the grid more than once until it's released. I could write some example code but I'm too tired right now... try it yourself first, and I'll try to help later if you can't crack it.

By the way, it would be better if you did it the first way, because otherwise you're redundantly turning events into state and then back into events again, which is silly. If you can't implement it directly with events without requiring loads of global variables you may have a deeper design problem....
NCarter Wrote:Why would that require lots of global variables? Can't you have your event handler use a single (global?) variable to detect which mode you're in, then call an appropriate function to inform the associated part of the program about the mouse up event?
Failing that, you could try using SDL_GetMouseState() to detect the current mouse button state and write a routine which prevents it from toggling the grid more than once until it's released. I could write some example code but I'm too tired right now... try it yourself first, and I'll try to help later if you can't crack it.
By the way, it would be better if you did it the first way, because otherwise you're redundantly turning events into state and then back into events again, which is silly. If you can't implement it directly with events without requiring loads of global variables you may have a deeper design problem....
ok I did as you suggested and it's all ok now!
this project has a LOT of design problems... in fact I started it almost randomly

now I want to finish it, as it would be my first full game
Inverted y is fixed in the CVS version of SDL. Next major update will include the fix if you want to wait for a stable release.
"Pay no attention to that man behind the curtain." - Wizard of Oz
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| annoying mouse clicks and GLUT problem | WhatMeWorry | 1 | 2,219 |
Nov 6, 2005 01:12 AM Last Post: OneSadCookie |
|
| sdl key input problem | leggo | 6 | 3,627 |
Aug 18, 2004 04:48 PM Last Post: aaronsullivan |
|

