Added missing summeries #1

This commit is contained in:
Michel Fedde 2021-03-17 17:09:59 +01:00
parent 03d99ea28e
commit 8665b5b709
104 changed files with 1165 additions and 821 deletions

View file

@ -1,18 +1,24 @@
using System;
#region usings
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Windows.Documents;
using System.Windows.Forms;
using OpenTK.Input;
using SharpDX.Win32;
#endregion
namespace SM.Base.Controls
{
public class Keyboard
/// <summary>
/// A static class to get keyboard inputs.
/// </summary>
public static class Keyboard
{
internal static KeyboardState? _keyboardState;
internal static List<Key> _lastPressedKeys = new List<Key>();
/// <summary>
/// True, when ANY key pressed.
/// </summary>
public static bool IsAnyKeyPressed => _keyboardState?.IsAnyKeyDown == true;
@ -23,18 +29,53 @@ namespace SM.Base.Controls
_lastPressedKeys = new List<Key>();
foreach (object o in Enum.GetValues(typeof(Key)))
{
if (_keyboardState.Value[(Key)o]) _lastPressedKeys.Add((Key)o);
}
if (_keyboardState.Value[(Key) o])
_lastPressedKeys.Add((Key) o);
}
_keyboardState = OpenTK.Input.Keyboard.GetState();
}
public static bool IsDown(Key key, bool once = false) => _keyboardState?[key] == true && !(once && _lastPressedKeys.Contains(key));
public static bool WasDown(Key key) => _keyboardState?[key] == false && _lastPressedKeys.Contains(key);
public static bool IsUp(Key key, bool once = false) => _keyboardState?[key] == false && !(once && !_lastPressedKeys.Contains(key));
/// <summary>
/// Checks if a key is down.
/// </summary>
/// <param name="key">The key</param>
/// <param name="once">If true, the method doesn't return true, when it was pressed one stage before.</param>
/// <returns></returns>
public static bool IsDown(Key key, bool once = false)
{
return _keyboardState?[key] == true && !(once && _lastPressedKeys.Contains(key));
}
/// <summary>
/// Checks if a key was down but not anymore.
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static bool WasDown(Key key)
{
return _keyboardState?[key] == false && _lastPressedKeys.Contains(key);
}
/// <summary>
/// Check if a is up.
/// </summary>
/// <param name="key"></param>
/// <param name="once">If true, the method doesn't return true, when it was up one stage before.</param>
/// <returns></returns>
public static bool IsUp(Key key, bool once = false)
{
return _keyboardState?[key] == false && !(once && !_lastPressedKeys.Contains(key));
}
/// <summary>
/// Checks if specific keys are down.
/// </summary>
/// <param name="startIndex">Startindex</param>
/// <param name="endIndex">Endindex</param>
/// <param name="once">If true, it ignores keys that were down a state before.</param>
/// <returns>True if any of the specific keys where found down.</returns>
/// <exception cref="ArgumentException">The start index can't be greater then the end index.</exception>
public static bool AreSpecificKeysPressed(int startIndex, int endIndex, bool once = false)
{
if (startIndex > endIndex)
@ -51,19 +92,42 @@ namespace SM.Base.Controls
return false;
}
public static bool AreSpecificKeysPressed(params Key[] keys) => AreSpecificKeysPressed(false, keys);
/// <summary>
/// Checks if any of the specific keys are pressed.
/// </summary>
/// <param name="keys"></param>
/// <returns></returns>
public static bool AreSpecificKeysPressed(params Key[] keys)
{
return AreSpecificKeysPressed(false, keys);
}
/// <summary>
/// Checks if any of the specific keys are pressed.
/// </summary>
/// <param name="once">If true, it ignores keys that were down a state before.</param>
/// <param name="keys"></param>
/// <returns></returns>
public static bool AreSpecificKeysPressed(bool once, params Key[] keys)
{
foreach (Key key in keys)
{
if (IsDown(key, once)) return true;
}
if (IsDown(key, once))
return true;
return false;
}
public static bool AreSpecificKeysPressed(int startIndex, int endIndex, out Key[] pressedKeys, bool once = false)
/// <summary>
/// Checks if specific keys are down and returns the pressed keys.
/// </summary>
/// <param name="startIndex">Startindex</param>
/// <param name="endIndex">Endindex</param>
/// <param name="pressedKeys"></param>
/// <param name="once">If true, it ignores keys that were down a state before.</param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
public static bool AreSpecificKeysPressed(int startIndex, int endIndex, out Key[] pressedKeys,
bool once = false)
{
if (startIndex > endIndex)
throw new ArgumentException("The startIndex is greater than the endIndex.", nameof(startIndex));
@ -75,34 +139,47 @@ namespace SM.Base.Controls
for (int i = 0; i < length; i++)
{
int actualIndex = i + startIndex;
Key key = (Key)actualIndex;
Key key = (Key) actualIndex;
if (IsDown(key, once))
{
keys.Add(key);
success = true;
}
}
pressedKeys = keys.ToArray();
return success;
}
public static bool AreSpecificKeysPressed(out Key[] pressedKey, params Key[] keys) => AreSpecificKeysPressed(false, out pressedKey, keys);
/// <summary>
/// Checks if any of the specific keys are pressed and returns them.
/// </summary>
/// <param name="pressedKey"></param>
/// <param name="keys"></param>
/// <returns></returns>
public static bool AreSpecificKeysPressed(out Key[] pressedKey, params Key[] keys)
{
return AreSpecificKeysPressed(false, out pressedKey, keys);
}
/// <summary>
/// Checks if any of the specific keys are pressed and returns them.
/// </summary>
/// <param name="once">If true, it ignores keys that were down a state before.</param>
/// <param name="pressedKeys"></param>
/// <param name="keys"></param>
/// <returns></returns>
public static bool AreSpecificKeysPressed(bool once, out Key[] pressedKeys, params Key[] keys)
{
List<Key> pressedKey = new List<Key>();
bool success = false;
foreach (Key key in keys)
{
if (IsDown(key, once))
{
pressedKey.Add(key);
success = true;
}
}
pressedKeys = pressedKey.ToArray();
return success;

View file

@ -2,10 +2,9 @@
using System;
using System.Collections.Generic;
using System.Windows.Documents;
using OpenTK;
using OpenTK.Input;
using SM.Base.Windows;
using SM.Base.Window;
#endregion
@ -14,7 +13,6 @@ namespace SM.Base.Controls
/// <summary>
/// Mouse controller
/// </summary>
/// <typeparam name="TWindow">The type of window this controller is connected to.</typeparam>
public class Mouse
{
internal static MouseState? _mouseState;
@ -37,7 +35,7 @@ namespace SM.Base.Controls
internal static void MouseMoveEvent(MouseMoveEventArgs mmea, IGenericWindow window)
{
InScreen = new Vector2(mmea.X, mmea.Y);
InScreenNormalized = new Vector2(mmea.X / (float)window.Width, mmea.Y / (float)window.Height);
InScreenNormalized = new Vector2(mmea.X / (float) window.Width, mmea.Y / (float) window.Height);
}
internal static void SetState()
@ -47,19 +45,21 @@ namespace SM.Base.Controls
_lastButtonsPressed = new List<MouseButton>();
foreach (object o in Enum.GetValues(typeof(MouseButton)))
{
if (_mouseState.Value[(MouseButton)o]) _lastButtonsPressed.Add((MouseButton)o);
}
if (_mouseState.Value[(MouseButton) o])
_lastButtonsPressed.Add((MouseButton) o);
}
_mouseState = OpenTK.Input.Mouse.GetState();
}
public static bool IsDown(MouseButton button, bool once = false) => _mouseState?[button] == true && !(once && _lastButtonsPressed.Contains(button));
public static bool IsUp(MouseButton button, bool once = false) =>
_mouseState?[button] == false && !(once && !_lastButtonsPressed.Contains(button));
public static bool IsDown(MouseButton button, bool once = false)
{
return _mouseState?[button] == true && !(once && _lastButtonsPressed.Contains(button));
}
public static bool IsUp(MouseButton button, bool once = false)
{
return _mouseState?[button] == false && !(once && !_lastButtonsPressed.Contains(button));
}
}
}