💿🐜 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.

131 lines
3.0 KiB

  1. /*
  2. * Copyright (C) 2020 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_MOUSE_HPP
  20. #define ANTKEEPER_MOUSE_HPP
  21. #include "input-device.hpp"
  22. #include <tuple>
  23. /**
  24. * Enumerates the mouse motion axes.
  25. */
  26. enum class mouse_motion_axis
  27. {
  28. /// Indicates the positive X-axis.
  29. positive_x,
  30. /// Indicates the negative X-axis.
  31. negative_x,
  32. /// Indicates the positive Y-axis.
  33. positive_y,
  34. /// Indicates the negative Y-axis.
  35. negative_y
  36. };
  37. /**
  38. * Enumerates the mouse wheel axes.
  39. */
  40. enum class mouse_wheel_axis
  41. {
  42. /// Indicates the positive X-axis.
  43. positive_x,
  44. /// Indicates the negative X-axis.
  45. negative_x,
  46. /// Indicates the positive Y-axis.
  47. positive_y,
  48. /// Indicates the negative Y-axis.
  49. negative_y
  50. };
  51. /**
  52. * A virtual mouse which can generate mouse-related input events and pass them to an event dispatcher.
  53. */
  54. class mouse: public input_device
  55. {
  56. public:
  57. /**
  58. * Creates a mouse input device.
  59. */
  60. mouse();
  61. /// Destroys a mouse input device.
  62. virtual ~mouse() = default;
  63. /**
  64. * Simulates a mouse button press.
  65. *
  66. * @param button Index of the pressed button.
  67. * @param x X-coordinate of the mouse position.
  68. * @param y Y-coordinate of the mouse position.
  69. */
  70. void press(int button, int x, int y);
  71. /**
  72. * Simulates a mouse button release.
  73. *
  74. * @param button Index of the released button.
  75. * @param x X-coordinate of the mouse position.
  76. * @param y Y-coordinate of the mouse position.
  77. */
  78. void release(int button, int x, int y);
  79. /**
  80. * Simulates mouse movement.
  81. *
  82. * @param x X-coordinate of the mouse position.
  83. * @param y Y-coordinate of the mouse position.
  84. * @param dx Relative movement on the X-axis.
  85. * @param dy Relative movement on the Y-axis.
  86. */
  87. void move(int x, int y, int dx, int dy);
  88. /**
  89. * Simulates mouse wheel scrolling.
  90. */
  91. void scroll(int x, int y);
  92. /// Returns the current mouse position.
  93. const std::tuple<int, int>& get_current_position() const;
  94. /// Returns the previous mouse position.
  95. const std::tuple<int, int>& get_previous_position() const;
  96. private:
  97. std::tuple<int, int> current_position;
  98. std::tuple<int, int> previous_position;
  99. };
  100. inline const std::tuple<int, int>& mouse::get_current_position() const
  101. {
  102. return current_position;
  103. }
  104. inline const std::tuple<int, int>& mouse::get_previous_position() const
  105. {
  106. return previous_position;
  107. }
  108. #endif // ANTKEEPER_MOUSE_HPP