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

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