TouchSliderEmulator.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #include "../EmulatorComponent.h"
  3. #include "TouchSliderState.h"
  4. #include "../../Input/Bindings/Binding.h"
  5. namespace TLAC::Components
  6. {
  7. constexpr int SLIDER_INPUTS = 4;
  8. constexpr int CONTACT_POINTS = 2;
  9. struct ContactPoint
  10. {
  11. float Position;
  12. bool InContact;
  13. };
  14. class TouchSliderEmulator : public EmulatorComponent
  15. {
  16. public:
  17. static TouchSliderEmulator* LatestInstance;
  18. Input::Binding* LeftSideSlideLeft;
  19. Input::Binding* LeftSideSlideRight;
  20. Input::Binding* RightSideSlideLeft;
  21. Input::Binding* RightSideSlideRight;
  22. bool usePs4OfficialSlider;
  23. bool enableInMenus;
  24. TouchSliderEmulator();
  25. ~TouchSliderEmulator();
  26. virtual const char* GetDisplayName() override;
  27. virtual void Initialize(ComponentsManager*) override;
  28. virtual void Update() override;
  29. virtual void UpdateInput() override;
  30. virtual void OnFocusLost() override;
  31. bool isSliderTouched()
  32. {
  33. for (int i = 0; i < 32; i++)
  34. if (sliderState->SensorTouched[i].IsTouched) return true;
  35. return false;
  36. }
  37. private:
  38. ComponentsManager* componentsManager;
  39. float sliderSpeed = 750.0f;
  40. float sliderIncrement;
  41. TouchSliderState *sliderState;
  42. ContactPoint ContactPoints[CONTACT_POINTS];
  43. void EmulateSliderInput(Input::Binding *leftBinding, Input::Binding *rightBinding, ContactPoint &contactPoint, float start, float end);
  44. void ApplyContactPoint(ContactPoint &contactPoint, int section);
  45. void ApplyBitfieldState(uint32_t state);
  46. };
  47. inline bool touchSliderEmulatorIsEnabled = false;
  48. }