From: Joe K. <kr...@ni...> - 2006-10-03 15:39:29
|
Fay John F Dr CTR USAF AFSEO/SK wrote: > Joe, > > I don't get how "freeglut" will send multiple callbacks per > event. The code is pretty straightforward, with a "switch" statement: > an event comes in from Windows, a callback goes out to the application. > Am I missing something? > > John F. Fay > Technical Fellow, Jacobs/Sverdrup TEAS Group > 850-883-1294 > joh...@eg... > ... OK, here is the code below. Before this, it converts a wheel delta into 'ticks' by dividing by 120, indicating that the actual delta could be fractional. Then, the code below invokes one callback per tick. Just to keep it confusing: if there is no MouseWheel callback, it converts wheel data into convoluted button events, which I think should be removed altogether. As for Wheel callbacks, I think the right way to do it is to either define a wheel callback with a float wheel-delta, or a DeviceGet value for divisions per wheel 'tick'. It may be good to have both, so that high-resolution events are possible, but the typical wheel-event user can assume the normal low-res wheel. Even without a float callback, the current code misses the fact that wheel events may not end on an integer value, and the remainder is not saved. This is probably overkill for normal wheel mice, but it's best to get thing right sooner than later. Joe if( ! FETCH_WCB( *window, MouseWheel ) && ! FETCH_WCB( *window, Mouse ) ) break; fgSetWindow( window ); fgState.Modifiers = fghGetWin32Modifiers( ); while( ticks-- ) if( FETCH_WCB( *window, MouseWheel ) ) INVOKE_WCB( *window, MouseWheel, ( wheel_number, direction, window->State.MouseX, window->State.MouseY ) ); else /* No mouse wheel, call the mouse button callback twice */ { /* * Map wheel zero to button 3 and 4; +1 to 3, -1 to 4 * " " one +1 to 5, -1 to 6, ... * * XXX The below assumes that you have no more than 3 mouse * XXX buttons. Sorry. */ int button = wheel_number * 2 + 3; if( direction < 0 ) ++button; INVOKE_WCB( *window, Mouse, ( button, GLUT_DOWN, window->State.MouseX, window->State.MouseY ) ); INVOKE_WCB( *window, Mouse, ( button, GLUT_UP, window->State.MouseX, window->State.MouseY ) ); } |