mouse.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright 2021 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included
  4. #pragma once
  5. #include <stop_token>
  6. #include <thread>
  7. #include "common/vector_math.h"
  8. #include "input_common/input_engine.h"
  9. namespace InputCommon {
  10. enum class MouseButton {
  11. Left,
  12. Right,
  13. Wheel,
  14. Backward,
  15. Forward,
  16. Task,
  17. Extra,
  18. Undefined,
  19. };
  20. /**
  21. * A button device factory representing a keyboard. It receives keyboard events and forward them
  22. * to all button devices it created.
  23. */
  24. class Mouse final : public InputEngine {
  25. public:
  26. explicit Mouse(std::string input_engine_);
  27. /**
  28. * Signals that mouse has moved.
  29. * @param x the x-coordinate of the cursor
  30. * @param y the y-coordinate of the cursor
  31. * @param center_x the x-coordinate of the middle of the screen
  32. * @param center_y the y-coordinate of the middle of the screen
  33. */
  34. void MouseMove(int x, int y, f32 touch_x, f32 touch_y, int center_x, int center_y);
  35. /**
  36. * Sets the status of all buttons bound with the key to pressed
  37. * @param key_code the code of the key to press
  38. */
  39. void PressButton(int x, int y, f32 touch_x, f32 touch_y, MouseButton button);
  40. /**
  41. * Sets the status of all buttons bound with the key to released
  42. * @param key_code the code of the key to release
  43. */
  44. void ReleaseButton(MouseButton button);
  45. /**
  46. * Sets the status of the mouse wheel
  47. * @param x delta movement in the x direction
  48. * @param y delta movement in the y direction
  49. */
  50. void MouseWheelChange(int x, int y);
  51. void ReleaseAllButtons();
  52. std::vector<Common::ParamPackage> GetInputDevices() const override;
  53. AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) override;
  54. Common::Input::ButtonNames GetUIName(const Common::ParamPackage& params) const override;
  55. private:
  56. void UpdateThread(std::stop_token stop_token);
  57. void StopPanning();
  58. Common::Input::ButtonNames GetUIButtonName(const Common::ParamPackage& params) const;
  59. Common::Vec2<int> mouse_origin;
  60. Common::Vec2<int> last_mouse_position;
  61. Common::Vec2<float> last_mouse_change;
  62. Common::Vec2<int> wheel_position;
  63. bool button_pressed;
  64. int mouse_panning_timout{};
  65. std::jthread update_thread;
  66. };
  67. } // namespace InputCommon