mouse.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 InputCommon::InputEngine {
  25. public:
  26. explicit Mouse(const 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. void ReleaseAllButtons();
  46. std::vector<Common::ParamPackage> GetInputDevices() const override;
  47. std::string GetUIName(const Common::ParamPackage& params) const override;
  48. private:
  49. void UpdateThread(std::stop_token stop_token);
  50. void StopPanning();
  51. const PadIdentifier identifier = {
  52. .guid = Common::UUID{""},
  53. .port = 0,
  54. .pad = 0,
  55. };
  56. Common::Vec2<int> mouse_origin;
  57. Common::Vec2<int> last_mouse_position;
  58. Common::Vec2<float> last_mouse_change;
  59. bool button_pressed;
  60. int mouse_panning_timout{};
  61. std::jthread update_thread;
  62. };
  63. } // namespace InputCommon