input.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 "object.h"
  33. #include "os/main_loop.h"
  34. #include "os/thread_safe.h"
  35. class Input : public Object {
  36. OBJ_TYPE(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. };
  46. #undef CursorShape
  47. enum CursorShape {
  48. CURSOR_ARROW,
  49. CURSOR_IBEAM,
  50. CURSOR_POINTING_HAND,
  51. CURSOR_CROSS,
  52. CURSOR_WAIT,
  53. CURSOR_BUSY,
  54. CURSOR_DRAG,
  55. CURSOR_CAN_DROP,
  56. CURSOR_FORBIDDEN,
  57. CURSOR_VSIZE,
  58. CURSOR_HSIZE,
  59. CURSOR_BDIAGSIZE,
  60. CURSOR_FDIAGSIZE,
  61. CURSOR_MOVE,
  62. CURSOR_VSPLIT,
  63. CURSOR_HSPLIT,
  64. CURSOR_HELP,
  65. CURSOR_MAX
  66. };
  67. void set_mouse_mode(MouseMode p_mode);
  68. MouseMode get_mouse_mode() const;
  69. static Input *get_singleton();
  70. virtual bool is_key_pressed(int p_scancode) = 0;
  71. virtual bool is_mouse_button_pressed(int p_button) = 0;
  72. virtual bool is_joy_button_pressed(int p_device, int p_button) = 0;
  73. virtual bool is_action_pressed(const StringName &p_action) = 0;
  74. virtual float get_joy_axis(int p_device, int p_axis) = 0;
  75. virtual String get_joy_name(int p_idx) = 0;
  76. virtual Array get_connected_joysticks() = 0;
  77. virtual void joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid) = 0;
  78. virtual void add_joy_mapping(String p_mapping, bool p_update_existing = false) = 0;
  79. virtual void remove_joy_mapping(String p_guid) = 0;
  80. virtual bool is_joy_known(int p_device) = 0;
  81. virtual String get_joy_guid(int p_device) const = 0;
  82. virtual Vector2 get_joy_vibration_strength(int p_device) = 0;
  83. virtual float get_joy_vibration_duration(int p_device) = 0;
  84. virtual uint64_t get_joy_vibration_timestamp(int p_device) = 0;
  85. virtual void start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration = 0) = 0;
  86. virtual void stop_joy_vibration(int p_device) = 0;
  87. virtual Point2 get_mouse_pos() const = 0;
  88. virtual Point2 get_mouse_speed() const = 0;
  89. virtual int get_mouse_button_mask() const = 0;
  90. virtual void warp_mouse_pos(const Vector2 &p_to) = 0;
  91. virtual Point2i warp_mouse_motion(const InputEventMouseMotion &p_motion, const Rect2 &p_rect) = 0;
  92. virtual Vector3 get_gravity() = 0;
  93. virtual Vector3 get_accelerometer() = 0;
  94. virtual Vector3 get_magnetometer() = 0;
  95. virtual Vector3 get_gyroscope() = 0;
  96. virtual void action_press(const StringName &p_action) = 0;
  97. virtual void action_release(const StringName &p_action) = 0;
  98. void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const;
  99. virtual bool is_emulating_touchscreen() const = 0;
  100. virtual void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape = CURSOR_ARROW, const Vector2 &p_hotspot = Vector2()) = 0;
  101. virtual String get_joy_button_string(int p_button) = 0;
  102. virtual String get_joy_axis_string(int p_axis) = 0;
  103. virtual int get_joy_button_index_from_string(String p_button) = 0;
  104. virtual int get_joy_axis_index_from_string(String p_axis) = 0;
  105. virtual void parse_input_event(const InputEvent &p_event) = 0;
  106. Input();
  107. };
  108. VARIANT_ENUM_CAST(Input::MouseMode);
  109. VARIANT_ENUM_CAST(Input::CursorShape);
  110. #endif // INPUT_H