Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions src/KappaDuck.Quack/Events/EventExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,61 @@ public static class EventExtensions
/// Determines whether the specified key is currently pressed and the event is a <see cref="EventType.KeyDown"/>.
/// </summary>
/// <param name="code">The code to compare.</param>
/// <returns><see langword="true"/> if the specified key is pressed; otherwise, <see langword="false"/>.</returns>
public bool IsKeyDown(Scancode code) => e.Type is EventType.KeyDown && e.Keyboard.Code == code;

/// <summary>
/// Determines whether the specified key is currently pressed and the event is a <see cref="EventType.KeyDown"/>.
/// </summary>
/// <param name="mod">The modifier to compare.</param>
/// <param name="code">The code to compare.</param>
/// <returns><see langword="true"/> if the specified key is pressed; otherwise, <see langword="false"/>.</returns>
public bool IsKeyDown(Scancode code, Modifier mod = Modifier.None) => e.Type is EventType.KeyDown && e.Keyboard.Code == code && (e.Keyboard.Modifiers & mod) == mod;
public bool IsKeyDown(Modifier mod, Scancode code) => e.Type is EventType.KeyDown && e.Keyboard.Code == code && (e.Keyboard.Modifiers & mod) == mod;

/// <summary>
/// Determines whether the specified key is currently pressed and the event is a <see cref="EventType.KeyDown"/>.
/// </summary>
/// <param name="key">The key to compare.</param>
/// <returns><see langword="true"/> if the specified key is pressed; otherwise, <see langword="false"/>.</returns>
public bool IsKeyDown(Keycode key) => e.Type is EventType.KeyDown && e.Keyboard.Key == key;

/// <summary>
/// Determines whether the specified key is currently pressed and the event is a <see cref="EventType.KeyDown"/>.
/// </summary>
/// <param name="mod">The modifier to compare.</param>
/// <param name="key">The key to compare.</param>
/// <returns><see langword="true"/> if the specified key is pressed; otherwise, <see langword="false"/>.</returns>
public bool IsKeyDown(Keycode key, Modifier mod = Modifier.None) => e.Type is EventType.KeyDown && e.Keyboard.Key == key && (e.Keyboard.Modifiers & mod) == mod;
public bool IsKeyDown(Modifier mod, Keycode key) => e.Type is EventType.KeyDown && e.Keyboard.Key == key && (e.Keyboard.Modifiers & mod) == mod;

/// <summary>
/// Determines whether the specified key was released and the event is a <see cref="EventType.KeyUp"/>.
/// </summary>
/// <param name="code">The code to compare.</param>
/// <returns><see langword="true"/> if the specified key is released; otherwise, <see langword="false"/>.</returns>
public bool IsKeyUp(Scancode code) => e.Type is EventType.KeyUp && e.Keyboard.Code == code;

/// <summary>
/// Determines whether the specified key was released and the event is a <see cref="EventType.KeyUp"/>.
/// </summary>
/// <param name="mod">The modifier to compare.</param>
/// <param name="code">The code to compare.</param>
/// <returns><see langword="true"/> if the specified key is released; otherwise, <see langword="false"/>.</returns>
public bool IsKeyUp(Scancode code, Modifier mod = Modifier.None) => e.Type is EventType.KeyUp && e.Keyboard.Code == code && (e.Keyboard.Modifiers & mod) == mod;
public bool IsKeyUp(Modifier mod, Scancode code) => e.Type is EventType.KeyUp && e.Keyboard.Code == code && (e.Keyboard.Modifiers & mod) == mod;

/// <summary>
/// Determines whether the specified key was released and the event is a <see cref="EventType.KeyUp"/>.
/// </summary>
/// <param name="key">The key to compare.</param>
/// <returns><see langword="true"/> if the specified key is released; otherwise, <see langword="false"/>.</returns>
public bool IsKeyUp(Keycode key) => e.Type is EventType.KeyUp && e.Keyboard.Key == key;

/// <summary>
/// Determines whether the specified key was released and the event is a <see cref="EventType.KeyUp"/>.
/// </summary>
/// <param name="mod">The modifier to compare.</param>
/// <param name="key">The key to compare.</param>
/// <returns><see langword="true"/> if the specified key is released; otherwise, <see langword="false"/>.</returns>
public bool IsKeyUp(Keycode key, Modifier mod = Modifier.None) => e.Type is EventType.KeyUp && e.Keyboard.Key == key && (e.Keyboard.Modifiers & mod) == mod;
public bool IsKeyUp(Modifier mod, Keycode key) => e.Type is EventType.KeyUp && e.Keyboard.Key == key && (e.Keyboard.Modifiers & mod) == mod;

/// <summary>
/// Determines whether the specified mouse button is currently pressed and the event is a <see cref="EventType.MouseButtonDown"/>.
Expand Down
3 changes: 3 additions & 0 deletions src/KappaDuck.Quack/Exceptions/QuackNativeException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ internal static void ThrowIfNegative<T>(T value, [CallerMemberName] string membe
internal static unsafe void ThrowIfNull<T>(T* value, [CallerMemberName] string memberName = "") where T : unmanaged
=> ThrowIf(value is null, memberName);

internal static unsafe void ThrowIfNull<T>(T** value, [CallerMemberName] string memberName = "") where T : unmanaged
=> ThrowIf(value is null, memberName);

internal static void ThrowIfZero<T>(T value, [CallerMemberName] string memberName = "") where T : INumber<T>
=> ThrowIf(T.IsZero(value), memberName);

Expand Down
Loading