1 /*************************************************************************/
2 /*  input.h                                                              */
3 /*************************************************************************/
4 /*                       This file is part of:                           */
5 /*                           GODOT ENGINE                                */
6 /*                      https://godotengine.org                          */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur.                 */
9 /* Copyright (c) 2014-2019 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 
33 #include "object.h"
34 #include "os/main_loop.h"
35 #include "os/thread_safe.h"
36 
37 class Input : public Object {
38 
39 	OBJ_TYPE(Input, Object);
40 
41 	static Input *singleton;
42 
43 protected:
44 	static void _bind_methods();
45 
46 public:
47 	enum MouseMode {
48 		MOUSE_MODE_VISIBLE,
49 		MOUSE_MODE_HIDDEN,
50 		MOUSE_MODE_CAPTURED
51 	};
52 
53 #undef CursorShape
54 	enum CursorShape {
55 		CURSOR_ARROW,
56 		CURSOR_IBEAM,
57 		CURSOR_POINTING_HAND,
58 		CURSOR_CROSS,
59 		CURSOR_WAIT,
60 		CURSOR_BUSY,
61 		CURSOR_DRAG,
62 		CURSOR_CAN_DROP,
63 		CURSOR_FORBIDDEN,
64 		CURSOR_VSIZE,
65 		CURSOR_HSIZE,
66 		CURSOR_BDIAGSIZE,
67 		CURSOR_FDIAGSIZE,
68 		CURSOR_MOVE,
69 		CURSOR_VSPLIT,
70 		CURSOR_HSPLIT,
71 		CURSOR_HELP,
72 		CURSOR_MAX
73 	};
74 
75 	void set_mouse_mode(MouseMode p_mode);
76 	MouseMode get_mouse_mode() const;
77 
78 	static Input *get_singleton();
79 
80 	virtual bool is_key_pressed(int p_scancode) = 0;
81 	virtual bool is_mouse_button_pressed(int p_button) = 0;
82 	virtual bool is_joy_button_pressed(int p_device, int p_button) = 0;
83 	virtual bool is_action_pressed(const StringName &p_action) = 0;
84 
85 	virtual float get_joy_axis(int p_device, int p_axis) = 0;
86 	virtual String get_joy_name(int p_idx) = 0;
87 	virtual Array get_connected_joysticks() = 0;
88 	virtual void joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid) = 0;
89 	virtual void add_joy_mapping(String p_mapping, bool p_update_existing = false) = 0;
90 	virtual void remove_joy_mapping(String p_guid) = 0;
91 	virtual bool is_joy_known(int p_device) = 0;
92 	virtual String get_joy_guid(int p_device) const = 0;
93 	virtual Vector2 get_joy_vibration_strength(int p_device) = 0;
94 	virtual float get_joy_vibration_duration(int p_device) = 0;
95 	virtual uint64_t get_joy_vibration_timestamp(int p_device) = 0;
96 	virtual void start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration = 0) = 0;
97 	virtual void stop_joy_vibration(int p_device) = 0;
98 
99 	virtual Point2 get_mouse_pos() const = 0;
100 	virtual Point2 get_mouse_speed() const = 0;
101 	virtual int get_mouse_button_mask() const = 0;
102 
103 	virtual void warp_mouse_pos(const Vector2 &p_to) = 0;
104 	virtual Point2i warp_mouse_motion(const InputEventMouseMotion &p_motion, const Rect2 &p_rect) = 0;
105 
106 	virtual Vector3 get_gravity() = 0;
107 	virtual Vector3 get_accelerometer() = 0;
108 	virtual Vector3 get_magnetometer() = 0;
109 	virtual Vector3 get_gyroscope() = 0;
110 
111 	virtual void action_press(const StringName &p_action) = 0;
112 	virtual void action_release(const StringName &p_action) = 0;
113 
114 	void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const;
115 
116 	virtual bool is_emulating_touchscreen() const = 0;
117 
118 	virtual void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape = CURSOR_ARROW, const Vector2 &p_hotspot = Vector2()) = 0;
119 
120 	virtual String get_joy_button_string(int p_button) = 0;
121 	virtual String get_joy_axis_string(int p_axis) = 0;
122 	virtual int get_joy_button_index_from_string(String p_button) = 0;
123 	virtual int get_joy_axis_index_from_string(String p_axis) = 0;
124 
125 	virtual void parse_input_event(const InputEvent &p_event) = 0;
126 
127 	Input();
128 };
129 
130 VARIANT_ENUM_CAST(Input::MouseMode);
131 VARIANT_ENUM_CAST(Input::CursorShape);
132 
133 #endif // INPUT_H
134