double click with glut
I am trying to implement a double click while using GLUT, any ideas. . .
I know how to see if the mouse has been clicked twice in a given time frame. I use the ftime function for that. But my problem comes when the user has single clicked, does not double click, and then i have to send the single click event off.
Confused . . . me too.
okay i will elaborate more.
i have my glutMouseFunc --> mouse()
whenever the mouse is clicked, i call a function in one of my objects, we will call board. THe thing is i want to be able to differentiate between single and doubleclicks. So if the user single clicks, i can pass something like dclick=false to board and if the user doubleclicks i can send dclick = true. Problem is, whenever any click occurs the function of board is called. So if the user does double-click, the function in board will receive a single click event and a double click event. Is there anyway I can wait a half-second after a single-click to see if the user double clicks, and then if they dont, just behave as though the single click occurred, albeit, half a second later.
i have my glutMouseFunc --> mouse()
whenever the mouse is clicked, i call a function in one of my objects, we will call board. THe thing is i want to be able to differentiate between single and doubleclicks. So if the user single clicks, i can pass something like dclick=false to board and if the user doubleclicks i can send dclick = true. Problem is, whenever any click occurs the function of board is called. So if the user does double-click, the function in board will receive a single click event and a double click event. Is there anyway I can wait a half-second after a single-click to see if the user double clicks, and then if they dont, just behave as though the single click occurred, albeit, half a second later.
the way i would do that is to start a new timer function when the callback for a click is executed. so...
start of program: start clickTimer;
CLICK-> mouse()....check clickTimer; restart clickTimer;
if checkTimer is less then 0.1s then send dbClick to board;
else send singleClick to board;
so you need a timing function called clickTimer obviously. this should be adequate for your needs.
start of program: start clickTimer;
CLICK-> mouse()....check clickTimer; restart clickTimer;
if checkTimer is less then 0.1s then send dbClick to board;
else send singleClick to board;
so you need a timing function called clickTimer obviously. this should be adequate for your needs.
i guess i still do not understand how that separates the first click (which may be part of a doubleclick) not getting sent during the callback.
quote:Original post by mstein
i guess i still do not understand how that separates the first click (which may be part of a doubleclick) not getting sent during the callback.
It does not. GUIs do process the first click as if it was a single click, and then the double click if/when it comes.
An alternative solution would be to register a timer on the first click, and if it expires without a second click being sent, then you process the double click. Otherwise, you process a single click. Of course, the disadvantage is that the GUI would respond immediately to single clicks (latency is a bad thing.)
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
quote:Of course, the disadvantage is that the GUI would respond immediately to single clicks (latency is a bad thing.)
I assume you mean "wouldn''t".
I am personally lost on the implementation of a timer function. I have used Gluts once, but it seems that for this it would perhaps have to be multi-threaded, so that the mouse event can still get picked up. Please stop me if I am running from the path here. . .
quote:Original post by mstein
I assume you mean "wouldn''t".
Yes.
quote:
I am personally lost on the implementation of a timer function.
You have no excuse not to learn, it really is trivial.
quote:
I have used Gluts once, but it seems that for this it would perhaps have to be multi-threaded, so that the mouse event can still get picked up.
No.
quote:
Please stop me if I am running from the path here. . .
Stop! Use glutTimerFunc().
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
got it working . .. my glutMouseFunc just keeps track of clicks and launches the timer . . . the timer it self sends out the click event to my board object.
Yes, right now the doubleclickspeed is at 500 ms and that was way to slow (well a half second of waiting) . . . when you all doubleclick, how fast do you expect to have to click. I set it to 100 ms and that was too fast. I can do 200 ms just fine, what do you all think.
quote:
Of course, the disadvantage is that the GUI would respond immediately to single clicks (latency is a bad thing.)
Yes, right now the doubleclickspeed is at 500 ms and that was way to slow (well a half second of waiting) . . . when you all doubleclick, how fast do you expect to have to click. I set it to 100 ms and that was too fast. I can do 200 ms just fine, what do you all think.
My machine is set at 250ms. Of course, a single-click is also generated each time.
Edit: Yeah 3600th post !
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
[edited by - Fruny on March 16, 2003 4:59:43 PM]
Edit: Yeah 3600th post !
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
[edited by - Fruny on March 16, 2003 4:59:43 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement