refactor: Use a constant for the gamepad button deletion mask

Add Flags-Attribute to GamepadButtons enums.
This commit is contained in:
Chivalrik 2021-05-02 12:21:49 +02:00
parent 66d42a7cfd
commit d65f2c6cd9
2 changed files with 16 additions and 7 deletions

View file

@ -1,10 +1,18 @@
namespace Dalamud.Game.ClientState
using System;
namespace Dalamud.Game.ClientState
{
/// <summary>
/// Bitmask of the Button ushort used by the game.
/// </summary>
[Flags]
public enum GamepadButtons : ushort
{
/// <summary>
/// No buttons pressed.
/// </summary>
None = 0,
/// <summary>
/// Digipad up.
/// </summary>

View file

@ -228,12 +228,13 @@ namespace Dalamud.Game.ClientState
// `ButtonPressed` while ImGuiConfigFlags.NavEnableGamepad is set.
// This is debatable.
// ImGui itself does not care either way as it uses the Raw values and does its own state handling.
input->ButtonsRaw &= (ushort)~GamepadButtons.L2;
input->ButtonsRaw &= (ushort)~GamepadButtons.R2;
input->ButtonsRaw &= (ushort)~GamepadButtons.DpadDown;
input->ButtonsRaw &= (ushort)~GamepadButtons.DpadLeft;
input->ButtonsRaw &= (ushort)~GamepadButtons.DpadUp;
input->ButtonsRaw &= (ushort)~GamepadButtons.DpadRight;
const ushort deletionMask = (ushort)(~GamepadButtons.L2
& ~GamepadButtons.R2
& ~GamepadButtons.DpadDown
& ~GamepadButtons.DpadLeft
& ~GamepadButtons.DpadUp
& ~GamepadButtons.DpadRight);
input->ButtonsRaw &= deletionMask;
input->ButtonsPressed = 0;
input->ButtonsReleased = 0;
input->ButtonsRepeat = 0;