input.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*************************************************************************/
  2. /* input.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef INPUT_H
  31. #define INPUT_H
  32. #include "core/object.h"
  33. #include "core/os/main_loop.h"
  34. #include "core/os/thread_safe.h"
  35. class Input : public Object {
  36. GDCLASS(Input, Object);
  37. static Input *singleton;
  38. protected:
  39. static void _bind_methods();
  40. public:
  41. enum MouseMode {
  42. MOUSE_MODE_VISIBLE,
  43. MOUSE_MODE_HIDDEN,
  44. MOUSE_MODE_CAPTURED,
  45. MOUSE_MODE_CONFINED
  46. };
  47. #undef CursorShape
  48. enum CursorShape {
  49. CURSOR_ARROW,
  50. CURSOR_IBEAM,
  51. CURSOR_POINTING_HAND,
  52. CURSOR_CROSS,
  53. CURSOR_WAIT,
  54. CURSOR_BUSY,
  55. CURSOR_DRAG,
  56. CURSOR_CAN_DROP,
  57. CURSOR_FORBIDDEN,
  58. CURSOR_VSIZE,
  59. CURSOR_HSIZE,
  60. CURSOR_BDIAGSIZE,
  61. CURSOR_FDIAGSIZE,
  62. CURSOR_MOVE,
  63. CURSOR_VSPLIT,
  64. CURSOR_HSPLIT,
  65. CURSOR_HELP,
  66. CURSOR_MAX
  67. };
  68. void set_mouse_mode(MouseMode p_mode);
  69. MouseMode get_mouse_mode() const;
  70. static Input *get_singleton();
  71. virtual bool is_key_pressed(int p_scancode) const = 0;
  72. virtual bool is_mouse_button_pressed(int p_button) const = 0;
  73. virtual bool is_joy_button_pressed(int p_device, int p_button) const = 0;
  74. virtual bool is_action_pressed(const StringName &p_action) const = 0;
  75. virtual bool is_action_just_pressed(const StringName &p_action) const = 0;
  76. virtual bool is_action_just_released(const StringName &p_action) const = 0;
  77. virtual float get_action_strength(const StringName &p_action) const = 0;
  78. virtual float get_joy_axis(int p_device, int p_axis) const = 0;
  79. virtual String get_joy_name(int p_idx) = 0;
  80. virtual Array get_connected_joypads() = 0;
  81. virtual void joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid) = 0;
  82. virtual void add_joy_mapping(String p_mapping, bool p_update_existing = false) = 0;
  83. virtual void remove_joy_mapping(String p_guid) = 0;
  84. virtual bool is_joy_known(int p_device) = 0;
  85. virtual String get_joy_guid(int p_device) const = 0;
  86. virtual Vector2 get_joy_vibration_strength(int p_device) = 0;
  87. virtual float get_joy_vibration_duration(int p_device) = 0;
  88. virtual uint64_t get_joy_vibration_timestamp(int p_device) = 0;
  89. virtual void start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration = 0) = 0;
  90. virtual void stop_joy_vibration(int p_device) = 0;
  91. virtual void vibrate_handheld(int p_duration_ms = 500) = 0;
  92. virtual Point2 get_mouse_position() const = 0;
  93. virtual Point2 get_last_mouse_speed() const = 0;
  94. virtual int get_mouse_button_mask() const = 0;
  95. virtual void warp_mouse_position(const Vector2 &p_to) = 0;
  96. virtual Point2i warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motion, const Rect2 &p_rect) = 0;
  97. virtual Vector3 get_gravity() const = 0;
  98. virtual Vector3 get_accelerometer() const = 0;
  99. virtual Vector3 get_magnetometer() const = 0;
  100. virtual Vector3 get_gyroscope() const = 0;
  101. virtual void action_press(const StringName &p_action, float p_strength = 1.f) = 0;
  102. virtual void action_release(const StringName &p_action) = 0;
  103. void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const;
  104. virtual bool is_emulating_touch_from_mouse() const = 0;
  105. virtual bool is_emulating_mouse_from_touch() const = 0;
  106. virtual CursorShape get_default_cursor_shape() const = 0;
  107. virtual void set_default_cursor_shape(CursorShape p_shape) = 0;
  108. virtual CursorShape get_current_cursor_shape() const = 0;
  109. virtual void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape = CURSOR_ARROW, const Vector2 &p_hotspot = Vector2()) = 0;
  110. virtual String get_joy_button_string(int p_button) = 0;
  111. virtual String get_joy_axis_string(int p_axis) = 0;
  112. virtual int get_joy_button_index_from_string(String p_button) = 0;
  113. virtual int get_joy_axis_index_from_string(String p_axis) = 0;
  114. virtual void parse_input_event(const Ref<InputEvent> &p_event) = 0;
  115. virtual void accumulate_input_event(const Ref<InputEvent> &p_event) = 0;
  116. virtual void flush_accumulated_events() = 0;
  117. virtual void set_use_accumulated_input(bool p_enable) = 0;
  118. Input();
  119. };
  120. VARIANT_ENUM_CAST(Input::MouseMode);
  121. VARIANT_ENUM_CAST(Input::CursorShape);
  122. #endif // INPUT_H