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

122 lines
3.5 KiB

  1. /*
  2. * Copyright (C) 2023 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 "input/device.hpp"
  22. #include "input/input-events.hpp"
  23. #include "input/mouse-button.hpp"
  24. #include "event/publisher.hpp"
  25. #include "math/vector.hpp"
  26. #include <cstdint>
  27. namespace input {
  28. /**
  29. * A virtual mouse which generates mouse-related input events.
  30. */
  31. class mouse: public device
  32. {
  33. public:
  34. /**
  35. * Constructs a mouse input device.
  36. */
  37. mouse() = default;
  38. /// Destructs a mouse input device.
  39. virtual ~mouse() = default;
  40. /**
  41. * Simulates a mouse button press.
  42. *
  43. * @param button Button to press.
  44. */
  45. void press(mouse_button button);
  46. /**
  47. * Simulates a mouse button release.
  48. *
  49. * @param button Button to release.
  50. */
  51. void release(mouse_button button);
  52. /**
  53. * Simulates mouse movement.
  54. *
  55. * @param position Mouse position, in pixels, relative to the window.
  56. * @param difference Relative movement of the mouse, in pixels.
  57. */
  58. void move(const math::vector<std::int32_t, 2>& position, const math::vector<std::int32_t, 2>& difference);
  59. /**
  60. * Simulates mouse scrolling.
  61. *
  62. * @param velocity Scroll velocity.
  63. */
  64. void scroll(const math::vector<float, 2>& velocity);
  65. /// Returns the current mouse position, in pixels, relative to the window.
  66. [[nodiscard]] inline const math::vector<std::int32_t, 2>& get_position() const noexcept
  67. {
  68. return position;
  69. }
  70. /// Returns the channel through which mouse button pressed events are published.
  71. [[nodiscard]] inline ::event::channel<mouse_button_pressed_event>& get_button_pressed_channel() noexcept
  72. {
  73. return button_pressed_publisher.channel();
  74. }
  75. /// Returns the channel through which mouse button released events are published.
  76. [[nodiscard]] inline ::event::channel<mouse_button_released_event>& get_button_released_channel() noexcept
  77. {
  78. return button_released_publisher.channel();
  79. }
  80. /// Returns the channel through which mouse moved events are published.
  81. [[nodiscard]] inline ::event::channel<mouse_moved_event>& get_moved_channel() noexcept
  82. {
  83. return moved_publisher.channel();
  84. }
  85. /// Returns the channel through which mouse scrolled events are published.
  86. [[nodiscard]] inline ::event::channel<mouse_scrolled_event>& get_scrolled_channel() noexcept
  87. {
  88. return scrolled_publisher.channel();
  89. }
  90. /// Returns device_type::mouse.
  91. [[nodiscard]] inline virtual constexpr device_type get_device_type() const noexcept
  92. {
  93. return device_type::mouse;
  94. }
  95. private:
  96. math::vector<std::int32_t, 2> position;
  97. ::event::publisher<mouse_button_pressed_event> button_pressed_publisher;
  98. ::event::publisher<mouse_button_released_event> button_released_publisher;
  99. ::event::publisher<mouse_moved_event> moved_publisher;
  100. ::event::publisher<mouse_scrolled_event> scrolled_publisher;
  101. };
  102. } // namespace input
  103. #endif // ANTKEEPER_INPUT_MOUSE_HPP