From eae177fe8d7e29b2bca16c63aff707d6e6c25fd6 Mon Sep 17 00:00:00 2001 From: "SND\\rene87_cp" Date: Sat, 5 Nov 2011 00:34:45 +0000 Subject: [PATCH] XInput Mouse.GetState(); --- .../ANX.InputSystem.Windows.XInput.csproj | 3 +++ ANX.InputSystem.Windows.XInput/Mouse.cs | 27 +++++++++++++++++-- Samples/SimpleSprite/Game1.cs | 11 +++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/ANX.InputSystem.Windows.XInput/ANX.InputSystem.Windows.XInput.csproj b/ANX.InputSystem.Windows.XInput/ANX.InputSystem.Windows.XInput.csproj index f0ea1700..3f394b1d 100644 --- a/ANX.InputSystem.Windows.XInput/ANX.InputSystem.Windows.XInput.csproj +++ b/ANX.InputSystem.Windows.XInput/ANX.InputSystem.Windows.XInput.csproj @@ -34,6 +34,9 @@ ..\lib\SharpDX\Bin\SharpDX.dll + + ..\lib\SharpDX\Bin\SharpDX.DirectInput.dll + ..\lib\SharpDX\Bin\SharpDX.XInput.dll diff --git a/ANX.InputSystem.Windows.XInput/Mouse.cs b/ANX.InputSystem.Windows.XInput/Mouse.cs index a1eadb7c..5a96c453 100644 --- a/ANX.InputSystem.Windows.XInput/Mouse.cs +++ b/ANX.InputSystem.Windows.XInput/Mouse.cs @@ -4,11 +4,16 @@ using System.Linq; using System.Text; using ANX.Framework.NonXNA; using ANX.Framework.Input; +using SharpDX.DirectInput; +using MouseX = SharpDX.DirectInput.Mouse; + namespace ANX.InputSystem.Windows.XInput { class Mouse:IMouse { + private DirectInput directInput; + private MouseX mouse; public IntPtr WindowHandle { get @@ -21,9 +26,27 @@ namespace ANX.InputSystem.Windows.XInput } } - public MouseState GetState() + public Mouse() { - throw new NotImplementedException(); + this.directInput = new DirectInput(); + this.mouse = new MouseX(this.directInput); + this.mouse.Acquire(); + } + + public ANX.Framework.Input.MouseState GetState() + { + var state = this.mouse.GetCurrentState(); + ButtonState left = new ButtonState(); + ButtonState middle = new ButtonState(); + ButtonState right = new ButtonState(); + ButtonState x1 = new ButtonState(); + ButtonState x2 = new ButtonState(); + if(state.Buttons[0]){left=ButtonState.Pressed;} + if(state.Buttons[1]){middle=ButtonState.Pressed;} + if(state.Buttons[2]){right=ButtonState.Pressed;} + if(state.Buttons[3]){x1=ButtonState.Pressed;} + if(state.Buttons[4]){x2=ButtonState.Pressed;} + return new ANX.Framework.Input.MouseState(state.X,state.Y,state.Z,left,middle,right,x1,x2); } public void SetPosition(int x, int y) diff --git a/Samples/SimpleSprite/Game1.cs b/Samples/SimpleSprite/Game1.cs index 4c159743..812380b9 100644 --- a/Samples/SimpleSprite/Game1.cs +++ b/Samples/SimpleSprite/Game1.cs @@ -146,7 +146,16 @@ namespace WindowsGame1 { GraphicsDevice.Clear(Color.Green); } else { - GraphicsDevice.Clear(Color.CornflowerBlue); + if (Mouse.GetState().XButton1 == ButtonState.Pressed) + { + GraphicsDevice.Clear(Color.Chocolate); + + } + else + { + GraphicsDevice.Clear(Color.CornflowerBlue); + + } } spriteBatch.Begin();