- 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...
118 lines
3.0 KiB
C#
118 lines
3.0 KiB
C#
#region Using Statements
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
#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
|
|
|
|
namespace ANX.Framework.Input
|
|
{
|
|
public struct KeyboardState
|
|
{
|
|
#region Private Members
|
|
private KeyState[] keyState;
|
|
private List<Keys> pressedKeys;
|
|
|
|
#endregion // Private Members
|
|
|
|
public KeyboardState(params Keys[] keys)
|
|
{
|
|
pressedKeys = new List<Keys>();
|
|
pressedKeys.AddRange(keys);
|
|
|
|
keyState = new KeyState[255];
|
|
keyState.Initialize();
|
|
|
|
for (int i = 0; i < keys.Length; i++)
|
|
{
|
|
keyState[(int)keys[i]] = KeyState.Down;
|
|
}
|
|
}
|
|
|
|
public bool IsKeyDown(Keys key)
|
|
{
|
|
return keyState != null ? keyState[(int)key] == KeyState.Down : false;
|
|
}
|
|
|
|
public bool IsKeyUp(Keys key)
|
|
{
|
|
return keyState != null ? keyState[(int)key] == KeyState.Up : true;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
if (obj != null && obj.GetType() == typeof(KeyboardState))
|
|
{
|
|
return this == (KeyboardState)obj;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public static bool operator ==(KeyboardState lhs, KeyboardState rhs)
|
|
{
|
|
if (lhs.keyState.Length != rhs.keyState.Length)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
for (int i = 0; i < lhs.keyState.Length; i++)
|
|
{
|
|
if (lhs.keyState[i] != rhs.keyState[i])
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public static bool operator !=(KeyboardState lhs, KeyboardState rhs)
|
|
{
|
|
return !(lhs == rhs);
|
|
}
|
|
|
|
public KeyState this[Keys key]
|
|
{
|
|
get
|
|
{
|
|
return keyState[(int)key];
|
|
}
|
|
}
|
|
|
|
public Keys[] GetPressedKeys()
|
|
{
|
|
List<Keys> value = new List<Keys>();
|
|
for (int i = 0; i < keyState.Length; ++i)
|
|
{
|
|
if (keyState[i] == KeyState.Down)
|
|
{
|
|
value.Add((Keys)i);
|
|
}
|
|
}
|
|
return value.ToArray();
|
|
}
|
|
|
|
internal void AddPressedKey(Keys key)
|
|
{
|
|
this.pressedKeys.Add(key);
|
|
this.keyState[(int)key] = KeyState.Down;
|
|
}
|
|
|
|
internal void RemovePressedKey(Keys key)
|
|
{
|
|
this.pressedKeys.Remove(key);
|
|
this.keyState[(int)key] = KeyState.Up;
|
|
}
|
|
|
|
}
|
|
}
|