Skip to content

Commit

Permalink
Merge pull request #1304 from mattzink/windx_mousetouch
Browse files Browse the repository at this point in the history
[WinDX] Support TouchPanel.MouseTouchPoint/MouseGestures
  • Loading branch information
tomspilman committed Feb 13, 2013
2 parents 3414b35 + e92a2c5 commit 27bc1a2
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion MonoGame.Framework/Windows/WinFormsGameWindow.cs
Expand Up @@ -39,13 +39,14 @@ 1. Definitions
#endregion License #endregion License


using System; using System;
using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Windows.Forms; using System.Windows.Forms;
using System.Collections.Generic;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using ButtonState = Microsoft.Xna.Framework.Input.ButtonState; using ButtonState = Microsoft.Xna.Framework.Input.ButtonState;
using Rectangle = Microsoft.Xna.Framework.Rectangle; using Rectangle = Microsoft.Xna.Framework.Rectangle;
using XnaKey = Microsoft.Xna.Framework.Input.Keys; using XnaKey = Microsoft.Xna.Framework.Input.Keys;
Expand Down Expand Up @@ -142,12 +143,26 @@ private void OnDeactivate(object sender, EventArgs eventArgs)


private void OnMouseState(object sender, MouseEventArgs mouseEventArgs) private void OnMouseState(object sender, MouseEventArgs mouseEventArgs)
{ {
var previousState = Mouse.State.LeftButton;

Mouse.State.X = mouseEventArgs.X; Mouse.State.X = mouseEventArgs.X;
Mouse.State.Y = mouseEventArgs.Y; Mouse.State.Y = mouseEventArgs.Y;
Mouse.State.LeftButton = (mouseEventArgs.Button & MouseButtons.Left) == MouseButtons.Left ? ButtonState.Pressed : ButtonState.Released; Mouse.State.LeftButton = (mouseEventArgs.Button & MouseButtons.Left) == MouseButtons.Left ? ButtonState.Pressed : ButtonState.Released;
Mouse.State.MiddleButton = (mouseEventArgs.Button & MouseButtons.Middle) == MouseButtons.Middle ? ButtonState.Pressed : ButtonState.Released; Mouse.State.MiddleButton = (mouseEventArgs.Button & MouseButtons.Middle) == MouseButtons.Middle ? ButtonState.Pressed : ButtonState.Released;
Mouse.State.RightButton = (mouseEventArgs.Button & MouseButtons.Right) == MouseButtons.Right ? ButtonState.Pressed : ButtonState.Released; Mouse.State.RightButton = (mouseEventArgs.Button & MouseButtons.Right) == MouseButtons.Right ? ButtonState.Pressed : ButtonState.Released;
Mouse.State.ScrollWheelValue = mouseEventArgs.Delta; Mouse.State.ScrollWheelValue = mouseEventArgs.Delta;

TouchLocationState? touchState = null;
if (Mouse.State.LeftButton == ButtonState.Pressed)
if (previousState == ButtonState.Released)
touchState = TouchLocationState.Pressed;
else
touchState = TouchLocationState.Moved;
else if (previousState == ButtonState.Pressed)
touchState = TouchLocationState.Released;

if (touchState.HasValue)
TouchPanel.AddEvent(0, touchState.Value, new Vector2(Mouse.State.X, Mouse.State.Y), true);
} }


private void OnKeyDown(object sender, KeyEventArgs keyEventArgs) private void OnKeyDown(object sender, KeyEventArgs keyEventArgs)
Expand Down

0 comments on commit 27bc1a2

Please sign in to comment.