SND\AstrorEnales_cp 5505f7dcbf - Added PlatformSystem Plugins layer
- Started Windows, Metro and Linux Platform-Plugins
- Moved the RecordingSample to the Samples folder
- Started two samples for using the graphics device in a WinForms and Wpf Editor
- Refactorings in the AddIn-System
- Moved the Window initialization-code to the Platform modules
- Changed the License text in all code files which is now way smaller
- Started ProjectConverter tool which converts all the projects and solution to the target configuration
- Changed the SupportedPlatform names in the Resource files
- Changed the WIN8 define to WINDOWSMETRO which is actually meant
- Removed NLog and started our own Logger class
- Many more stuff...
2012-08-09 09:45:04 +00:00

95 lines
2.9 KiB
C#

#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ANX.Framework.NonXNA;
using ANX.Framework.Input;
using SharpDX.DirectInput;
using System.Runtime.InteropServices;
using ANX.Framework;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
using MouseX = SharpDX.DirectInput.Mouse;
namespace ANX.InputDevices.Windows.XInput
{
class Mouse : IMouse
{
#region Interop
[DllImport("user32.dll")]
static extern bool GetCursorPos(ref Point lpPoint);
[DllImport("user32.dll")]
static extern void SetCursorPos(int x, int y);
[DllImport("user32.dll")]
static extern bool ScreenToClient(IntPtr hWnd, ref Point lpPoint);
#endregion // Interop
#region Private Members
private DirectInput directInput;
private MouseX mouse;
#endregion // Private Members
public IntPtr WindowHandle
{
get;
set;
}
public Mouse()
{
this.directInput = new DirectInput();
this.mouse = new MouseX(this.directInput);
this.mouse.Properties.AxisMode = DeviceAxisMode.Absolute;
this.mouse.Acquire();
}
public ANX.Framework.Input.MouseState GetState()
{
var state = this.mouse.GetCurrentState();
Point cursorPos = new Point();
GetCursorPos(ref cursorPos);
if (WindowHandle != IntPtr.Zero)
{
ScreenToClient(WindowHandle, ref cursorPos);
}
state.X = cursorPos.X;
state.Y = cursorPos.Y;
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)
{
Point currentPosition = new Point(x, y);
GetCursorPos(ref currentPosition);
if (WindowHandle != IntPtr.Zero)
{
ScreenToClient(WindowHandle, ref currentPosition);
}
SetCursorPos(currentPosition.X, currentPosition.Y);
}
}
}