Game Development Reference
In-Depth Information
UpdateMouseButtons();
}
private void UpdateMouseButtons()
{
// Reset buttons
MiddlePressed = false;
LeftPressed = false;
RightPressed = false;
if (_leftClickDetect)
{
LeftPressed = true;
_leftClickDetect = false;
}
if (_rightClickDetect)
{
RightPressed = true;
_rightClickDetect = false;
}
if (_middleClickDetect)
{
MiddlePressed = true;
_middleClickDetect = false;
}
}
In the constructor of the mouse, four OpenGL control events have an anon-
ymous delegate attached to them. The mouse click event detects if the left, right,
or middle mouse buttons have been pressed, and this sets a boolean to report if
the event occurred. In the
UpdateMouseButtons
function, the detect boo-
leans are used to set the public
MiddlePressed
,
LeftPressed
, and
RightPressed
variables. Presses should only occur for one frame, so at the
start of the function all the button press flags are set to
false
. After the reset,
the detect variables are checked, and if a press is detected, they are set back to
true. The double-click event could be supported in a similar way.
The next three events determine if any of the mouse buttons are being held
down. The down event detects when the mouse button is pressed down, and the
Search WWH ::
Custom Search