Archived

This topic is now archived and is closed to further replies.

mstein

double click with glut

Recommended Posts

mstein    122
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.

Share this post


Link to post
Share on other sites
mstein    122
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.

Share this post


Link to post
Share on other sites
Kuladus    380
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.

Share this post


Link to post
Share on other sites
mstein    122
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.

Share this post


Link to post
Share on other sites
Fruny    1658
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 ]

Share this post


Link to post
Share on other sites
mstein    122
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. . .

Share this post


Link to post
Share on other sites
Fruny    1658
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 ]

Share this post


Link to post
Share on other sites
mstein    122
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.

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.

Share this post


Link to post
Share on other sites
Fruny    1658
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]

Share this post


Link to post
Share on other sites