💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
3.1 KiB

  1. /*
  2. * Copyright (C) 2021 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_INPUT_MOUSE_HPP
  20. #define ANTKEEPER_INPUT_MOUSE_HPP
  21. #include "device.hpp"
  22. #include <tuple>
  23. namespace input {
  24. /**
  25. * Enumerates the mouse motion axes.
  26. */
  27. enum class mouse_motion_axis
  28. {
  29. /// Indicates the positive X-axis.
  30. positive_x,
  31. /// Indicates the negative X-axis.
  32. negative_x,
  33. /// Indicates the positive Y-axis.
  34. positive_y,
  35. /// Indicates the negative Y-axis.
  36. negative_y
  37. };
  38. /**
  39. * Enumerates the mouse wheel axes.
  40. */
  41. enum class mouse_wheel_axis
  42. {
  43. /// Indicates the positive X-axis.
  44. positive_x,
  45. /// Indicates the negative X-axis.
  46. negative_x,
  47. /// Indicates the positive Y-axis.
  48. positive_y,
  49. /// Indicates the negative Y-axis.
  50. negative_y
  51. };
  52. /**
  53. * A virtual mouse which can generate mouse-related input events and pass them to an event dispatcher.
  54. */
  55. class mouse: public device
  56. {
  57. public:
  58. /**
  59. * Creates a mouse input device.
  60. */
  61. mouse();
  62. /// Destroys a mouse input device.
  63. virtual ~mouse() = default;
  64. /**
  65. * Simulates a mouse button press.
  66. *
  67. * @param button Index of the pressed button.
  68. * @param x X-coordinate of the mouse position.
  69. * @param y Y-coordinate of the mouse position.
  70. */
  71. void press(int button, int x, int y);
  72. /**
  73. * Simulates a mouse button release.
  74. *
  75. * @param button Index of the released button.
  76. * @param x X-coordinate of the mouse position.
  77. * @param y Y-coordinate of the mouse position.
  78. */
  79. void release(int button, int x, int y);
  80. /**
  81. * Simulates mouse movement.
  82. *
  83. * @param x X-coordinate of the mouse position.
  84. * @param y Y-coordinate of the mouse position.
  85. * @param dx Relative movement on the X-axis.
  86. * @param dy Relative movement on the Y-axis.
  87. */
  88. void move(int x, int y, int dx, int dy);
  89. /**
  90. * Simulates mouse wheel scrolling.
  91. */
  92. void scroll(int x, int y);
  93. /// Returns the current mouse position.
  94. const std::tuple<int, int>& get_current_position() const;
  95. /// Returns the previous mouse position.
  96. const std::tuple<int, int>& get_previous_position() const;
  97. private:
  98. std::tuple<int, int> current_position;
  99. std::tuple<int, int> previous_position;
  100. };
  101. inline const std::tuple<int, int>& mouse::get_current_position() const
  102. {
  103. return current_position;
  104. }
  105. inline const std::tuple<int, int>& mouse::get_previous_position() const
  106. {
  107. return previous_position;
  108. }
  109. } // namespace input
  110. #endif // ANTKEEPER_INPUT_MOUSE_HPP