I don't have the book yet ( though it's due to arrive today ), so appologies if this is covered in there )
I'm in the process of writing yet another XNA Input Manager that aggregates access to the GamePad, Keyboard and Mouse.
The classes fire off Down, Up and Clicked events respectively.
I'm in the process of completing the Mouse class and the only thing left is to handle double clicks. How have others coded this?
I've kept a variable that stores the last click and the time it was clicked then perform the following every time Update is called...
Code:
DoubleClicked = ( ( PreviousClicked && (CurrentState.LeftButton == ButtonState.Released && PreviousState.LeftButton == ButtonState.Pressed) ) && ( aGameTime.TotalGameTime.Milliseconds - PreviousGameTime < 100 ) );
if (DoubleClicked)
{
// Fire off those events
DoMouseDoubleClick();
}
else if (FCurrentState.LeftButton == ButtonState.Released && FPreviousState.LeftButton == ButtonState.Pressed)
{
PreviousGameTime = aGameTime.TotalGameTime.Milliseconds;
PreviousClicked = (FCurrentState.LeftButton == ButtonState.Released && FPreviousState.LeftButton == ButtonState.Pressed);
// Fire off those events
DoMouseClick();
}
but DoubleClicked is always false. Can anyone spot the flaw in my logic?