input.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. struct Input;
  2. struct InputDriver {
  3. InputDriver(Input& super) : super(super) {}
  4. virtual ~InputDriver() = default;
  5. virtual auto create() -> bool { return true; }
  6. virtual auto driver() -> string { return "None"; }
  7. virtual auto ready() -> bool { return true; }
  8. virtual auto hasContext() -> bool { return false; }
  9. virtual auto setContext(uintptr context) -> bool { return true; }
  10. virtual auto acquired() -> bool { return false; }
  11. virtual auto acquire() -> bool { return false; }
  12. virtual auto release() -> bool { return false; }
  13. virtual auto poll() -> vector<shared_pointer<nall::HID::Device>> { return {}; }
  14. virtual auto rumble(uint64_t id, bool enable) -> bool { return false; }
  15. protected:
  16. Input& super;
  17. friend class Input;
  18. uintptr context = 0;
  19. };
  20. struct Input {
  21. static auto hasDrivers() -> vector<string>;
  22. static auto hasDriver(string driver) -> bool { return (bool)hasDrivers().find(driver); }
  23. static auto optimalDriver() -> string;
  24. static auto safestDriver() -> string;
  25. Input() : self(*this) { reset(); }
  26. explicit operator bool() { return instance->driver() != "None"; }
  27. auto reset() -> void { instance = new InputDriver(*this); }
  28. auto create(string driver = "") -> bool;
  29. auto driver() -> string { return instance->driver(); }
  30. auto ready() -> bool { return instance->ready(); }
  31. auto hasContext() -> bool { return instance->hasContext(); }
  32. auto context() -> uintptr { return instance->context; }
  33. auto setContext(uintptr context) -> bool;
  34. auto acquired() -> bool;
  35. auto acquire() -> bool;
  36. auto release() -> bool;
  37. auto poll() -> vector<shared_pointer<nall::HID::Device>>;
  38. auto rumble(uint64_t id, bool enable) -> bool;
  39. auto onChange(const function<void (shared_pointer<nall::HID::Device>, uint, uint, int16_t, int16_t)>&) -> void;
  40. auto doChange(shared_pointer<nall::HID::Device> device, uint group, uint input, int16_t oldValue, int16_t newValue) -> void;
  41. protected:
  42. Input& self;
  43. unique_pointer<InputDriver> instance;
  44. function<void (shared_pointer<nall::HID::Device> device, uint group, uint input, int16_t oldValue, int16_t newValue)> change;
  45. };