InputState.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "InputState.h"
  2. #include <windows.h>
  3. #include <stdio.h>
  4. namespace TLAC::Components
  5. {
  6. void InputState::ClearState()
  7. {
  8. memset(this, 0, sizeof(InputState));
  9. }
  10. void InputState::HideCursor()
  11. {
  12. MouseX = INT32_MIN;
  13. MouseY = INT32_MIN;
  14. MouseDeltaX = 0;
  15. MouseDeltaY = 0;
  16. }
  17. void InputState::SetBit(uint32_t bit, bool value, InputBufferType inputType)
  18. {
  19. uint8_t* data = GetInputBuffer(inputType);
  20. if (data == nullptr || bit < 0 || bit >= MAX_BUTTON_BIT)
  21. return;
  22. int byteIndex = (bit / 8);
  23. int bitIndex = (bit % 8);
  24. BYTE mask = (1 << bitIndex);
  25. data[byteIndex] = value ? (data[byteIndex] | mask) : (data[byteIndex] & ~mask);
  26. }
  27. uint8_t* InputState::GetInputBuffer(InputBufferType inputType)
  28. {
  29. switch (inputType)
  30. {
  31. case InputBufferType_Tapped:
  32. return (uint8_t*)&Tapped;
  33. case InputBufferType_Released:
  34. return (uint8_t*)&Released;
  35. case InputBufferType_Down:
  36. return (uint8_t*)&Down;
  37. case InputBufferType_DoubleTapped:
  38. return (uint8_t*)&DoubleTapped;
  39. case InputBufferType_IntervalTapped:
  40. return (uint8_t*)&IntervalTapped;
  41. default:
  42. return nullptr;
  43. }
  44. }
  45. }