Game Development Reference
In-Depth Information
works a little differently than the gamepad, and it's not as straightforward to poll.
Windows Form controls are associated with mouse events. An event is a way to
call code when something happens; for instance, when the mouse moves, a but-
ton is clicked or double-clicked. These events can be hooked up to functions.
We'll use the click event to determine when the mouse buttons are pressed and
the up and down events to determine when the mouse button is held.
bool _leftClickDetect = false;
bool _rightClickDetect = false;
bool _middleClickDetect = false;
public bool MiddlePressed { get; private set; }
public bool LeftPressed { get; private set; }
public bool RightPressed { get; private set; }
public bool MiddleHeld { get; private set; }
public bool LeftHeld { get; private set; }
public bool RightHeld { get; set; }
public Mouse(Form form, Control openGLControl)
{
_parentForm = form;
_openGLControl = openGLControl;
_openGLControl.MouseClick += delegate(object obj, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
_leftClickDetect = true;
}
else if (e.Button == MouseButtons.Right)
{
_rightClickDetect = true;
}
else if (e.Button == MouseButtons.Middle)
{
_middleClickDetect = true;
}
};
_openGLControl.MouseDown += delegate(object obj, MouseEventArgs e)
{
Search WWH ::




Custom Search