/// <summary>
 ///		Constructor.
 /// </summary>
 /// <param name="button">Mouse button pressed.</param>
 /// <param name="modifiers">Any modifier keys that are down.</param>
 /// <param name="x">Mouse X position.</param>
 /// <param name="y">Mouse Y position.</param>
 /// <param name="z">Mouse Z position.</param>
 /// <param name="relX">Relative mouse X position.</param>
 /// <param name="relY">Relative mouse Y position.</param>
 /// <param name="relZ">Relative mouse Z position.</param>
 public MouseEventArgs(MouseButtons button, ModifierKeys modifiers, float x, float y, float z, float relX, float relY, float relZ)
     : base(modifiers)
 {
     this.mouseData      = new MouseData();
     mouseData.button    = button;
     mouseData.x         = x;
     mouseData.y         = y;
     mouseData.z         = z;
     mouseData.relativeX = relX;
     mouseData.relativeY = relY;
     mouseData.relativeZ = relZ;
 }
 /// <summary>
 ///		Helper method for running logic on a mouse change.
 /// </summary>
 /// <param name="mouse">Data for the set of mouse events</param>
 protected void MouseChanged(MouseData mouseData)
 {
     if (mouseData.button != MouseButtons.None)
     {
         if (mouseData.down)
         {
             Axiom.Input.MouseEventArgs e =
                 new Axiom.Input.MouseEventArgs(mouseData, modifiers);
             if ((mouseData.button & MouseButtons.Left) != 0)
             {
                 modifiers |= ModifierKeys.MouseButton0;
             }
             if ((mouseData.button & MouseButtons.Right) != 0)
             {
                 modifiers |= ModifierKeys.MouseButton1;
             }
             if ((mouseData.button & MouseButtons.Middle) != 0)
             {
                 modifiers |= ModifierKeys.MouseButton2;
             }
             OnMouseDown(e);
         }
         else
         {
             if ((mouseData.button & MouseButtons.Left) != 0)
             {
                 modifiers &= ~ModifierKeys.MouseButton0;
             }
             if ((mouseData.button & MouseButtons.Right) != 0)
             {
                 modifiers &= ~ModifierKeys.MouseButton1;
             }
             if ((mouseData.button & MouseButtons.Middle) != 0)
             {
                 modifiers &= ~ModifierKeys.MouseButton2;
             }
             Axiom.Input.MouseEventArgs e =
                 new Axiom.Input.MouseEventArgs(mouseData, modifiers);
             OnMouseUp(e);
         }
     }
     if (mouseData.relativeX != 0 ||
         mouseData.relativeY != 0 ||
         mouseData.relativeZ != 0)
     {
         Axiom.Input.MouseEventArgs e =
             new Axiom.Input.MouseEventArgs(mouseData, modifiers);
         OnMouseMoved(e);
     }
 }
 public MouseEventArgs(MouseData mouseData, ModifierKeys modifiers)
     : base(modifiers)
 {
     this.mouseData = mouseData;
 }
 public MouseEventArgs(MouseData mouseData, ModifierKeys modifiers)
     : base(modifiers)
 {
     this.mouseData = mouseData;
 }
 /// <summary>
 ///		Constructor.
 /// </summary>
 /// <param name="button">Mouse button pressed.</param>
 /// <param name="modifiers">Any modifier keys that are down.</param>
 /// <param name="x">Mouse X position.</param>
 /// <param name="y">Mouse Y position.</param>
 /// <param name="z">Mouse Z position.</param>
 /// <param name="relX">Relative mouse X position.</param>
 /// <param name="relY">Relative mouse Y position.</param>
 /// <param name="relZ">Relative mouse Z position.</param>
 public MouseEventArgs(MouseButtons button, ModifierKeys modifiers, float x, float y, float z, float relX, float relY, float relZ)
     : base(modifiers)
 {
     this.mouseData = new MouseData();
     mouseData.button = button;
     mouseData.x = x;
     mouseData.y = y;
     mouseData.z = z;
     mouseData.relativeX = relX;
     mouseData.relativeY = relY;
     mouseData.relativeZ = relZ;
 }
 /// <summary>
 ///   If the cursor is enabled, set our mouseAbs variables based
 ///   on the data in mousePoint.  If the cursor is disabled and
 ///   we are using the hardware cursor, move the cursor back to the
 ///   point where the cursor was disabled.
 /// </summary>
 /// <param name="mousePoint"></param>
 public void HandleMouseMoved(Point mousePoint)
 {
     // If we are using a hardware cursor, ignore the relative
     // data from the event, and regenerate the relative data
     // based on the current position and our previous position.
     if (this.CursorEnabled) {
         if (mouseAbsX != mousePoint.X || mouseAbsY != mousePoint.Y) {
             // Inject the mouse event that will go beyond our buffered data
             // to adjust the cursor to its current position.
             MouseData mouseData = new MouseData();
             mouseData.x = mousePoint.X;
             mouseData.y = mousePoint.Y;
             mouseData.relativeX = mousePoint.X - mouseAbsX;
             mouseData.relativeY = mousePoint.Y - mouseAbsY;
             Axiom.Input.MouseEventArgs e =
                 new Axiom.Input.MouseEventArgs(mouseData, modifiers);
             OnMouseMoved(e);
         }
         mouseAbsX = mousePoint.X;
         mouseAbsY = mousePoint.Y;
         // Now that the cursor size has been scaled to 32x32 in full
         // screen mode, I don't ever expect to not be able to rely on
         // the operating system to update the cursor.  Nonetheless,
         // it's possible that there are still cases out there.  Until
         // we encounter one of those cases though, I'm leaving this
         // ifdeffed out because I hate to waste the work updating the
         // cursor if I don't need to.
     #if UPDATE_CURSOR_MANUALLY
         // If we can't use the operating system to update our cursor, we will
         // need to do it ourselves.
         if (hardwareCursor) {
             Point screenPoint = control.PointToScreen(mousePoint);
             Root.Instance.RenderSystem.SetCursorPosition(screenPoint.X, screenPoint.Y);
         }
     #endif
     } else {
         if (HasFocus())
         {
             if (hardwareCursor && control != null && control.Capture)
             {
                 log.DebugFormat("Restoring cursor to: {0}", cursorDisabledPosition);
                 Cursor.Position = control.PointToScreen(cursorDisabledPosition);
             }
             else if (hardwareCursor && control != null)
             {
                 // Our app has focus, but doesn't have mouse capture (and should).. grab it.
                 control.Capture = true;
                 log.DebugFormat("Restoring cursor (and recapturing) to: {0}", cursorDisabledPosition);
                 Cursor.Position = control.PointToScreen(cursorDisabledPosition);
             }
             else
             {
                 log.DebugFormat("Cannot restore cursor; control {0}; {1}", control, (control == null) ? false : control.Capture);
             }
         }
     }
 }
 /// <summary>
 ///		Reads buffered input data when in buffered mode.
 /// </summary>
 private void ReadMouseEvent(List<BufferedData> bufferedDataList,
                             MouseData mouseData)
 {
     foreach (BufferedData data in bufferedDataList) {
         mouseData.timeStamp = data.TimeStamp;
         switch ((DInput.MouseOffset)data.Offset) {
             case MouseOffset.X:
                 mouseData.relativeX = data.Data;
                 break;
             case MouseOffset.Y:
                 mouseData.relativeY = data.Data;
                 break;
             case MouseOffset.Z:
                 mouseData.relativeZ = data.Data;
                 break;
             case MouseOffset.Button0:
                 mouseData.button = Axiom.Input.MouseButtons.Left;
                 mouseData.down = (data.ButtonPressedData == 1);
                 break;
             case MouseOffset.Button1:
                 mouseData.button = Axiom.Input.MouseButtons.Right;
                 mouseData.down = (data.ButtonPressedData == 1);
                 break;
             case MouseOffset.Button2:
                 mouseData.button = Axiom.Input.MouseButtons.Middle;
                 mouseData.down = (data.ButtonPressedData == 1);
                 break;
         }
     }
     return;
 }
        /// <summary>
        ///		Reads buffered input data when in buffered mode.
        /// </summary>
        private void ReadBufferedMouseData()
        {
            // grab the collection of buffered data
            BufferedDataCollection bufferedData = mouseDevice.GetBufferedData();
            if (bufferedData == null)
                return;
            if (bufferedData.Count >= BufferSize - 1)
                log.Warn("Exceeded mouse buffer.  Input data lost");
            bufferedData.SortBySequence();
            Dictionary<int, List<BufferedData>> bufferedDataDict = new Dictionary<int, List<BufferedData>>();
            List<int> sequenceNumbers = new List<int>();
            int currentSequence = -1;
            List<BufferedData> currentData = null;
            foreach (BufferedData data in bufferedData) {
                if (currentSequence != data.Sequence) {
                    currentData = new List<BufferedData>();
                    currentSequence = data.Sequence;
                    bufferedDataDict[currentSequence] = currentData;
                    sequenceNumbers.Add(currentSequence);
                }
                currentData.Add(data);
            }
            foreach (int eventSequence in sequenceNumbers) {
                MouseData mouseData = new MouseData();
                // Grab all the events with that sequence number, and use them to
                // populate the mouseData and down structures.
                ReadMouseEvent(bufferedDataDict[eventSequence], mouseData);

                //if (control != null && !control.Capture)
                //    return;
                Point mousePoint = new Point(0, 0);
                if (!hardwareCursor) {
                    // If we are using a software cursor, use the relative
                    // data from the event and our previous position to
                    // compute the current position.
                    mousePoint.X = mouseAbsX + (int)mouseData.relativeX;
                    mousePoint.Y = mouseAbsY + (int)mouseData.relativeY;
                    HandleMouseMoved(mousePoint);
                }
                mouseAbsZ += (int)mouseData.relativeZ;
                mouseData.x = mouseAbsX;
                mouseData.y = mouseAbsY;
                mouseData.z = mouseAbsZ;

                MouseChanged(mouseData);
            }
        }