1 /*************************************************************************/
2 /*  os_iphone.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 
31 #ifdef IPHONE_ENABLED
32 
33 #ifndef OS_IPHONE_H
34 #define OS_IPHONE_H
35 
36 #include "core/os/input.h"
37 #include "drivers/coreaudio/audio_driver_coreaudio.h"
38 #include "drivers/unix/os_unix.h"
39 
40 #include "game_center.h"
41 #include "icloud.h"
42 #include "in_app_store.h"
43 #include "ios.h"
44 #include "main/input_default.h"
45 #include "servers/audio_server.h"
46 #include "servers/visual/rasterizer.h"
47 #include "servers/visual_server.h"
48 
49 class OSIPhone : public OS_Unix {
50 
51 private:
52 	enum {
53 		MAX_MOUSE_COUNT = 8,
54 		MAX_EVENTS = 64,
55 	};
56 
57 	static HashMap<String, void *> dynamic_symbol_lookup_table;
58 	friend void register_dynamic_symbol(char *name, void *address);
59 
60 	VisualServer *visual_server;
61 
62 	AudioDriverCoreAudio audio_driver;
63 
64 #ifdef GAME_CENTER_ENABLED
65 	GameCenter *game_center;
66 #endif
67 #ifdef STOREKIT_ENABLED
68 	InAppStore *store_kit;
69 #endif
70 #ifdef ICLOUD_ENABLED
71 	ICloud *icloud;
72 #endif
73 	iOS *ios;
74 
75 	MainLoop *main_loop;
76 
77 	VideoMode video_mode;
78 
79 	virtual int get_video_driver_count() const;
80 	virtual const char *get_video_driver_name(int p_driver) const;
81 
82 	virtual int get_current_video_driver() const;
83 
84 	virtual void initialize_core();
85 	virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
86 
87 	virtual void set_main_loop(MainLoop *p_main_loop);
88 	virtual MainLoop *get_main_loop() const;
89 
90 	virtual void delete_main_loop();
91 
92 	virtual void finalize();
93 
94 	struct MouseList {
95 
96 		bool pressed[MAX_MOUSE_COUNT];
MouseListMouseList97 		MouseList() {
98 			for (int i = 0; i < MAX_MOUSE_COUNT; i++)
99 				pressed[i] = false;
100 		};
101 	};
102 
103 	MouseList touch_list;
104 
105 	Vector3 last_accel;
106 
107 	Ref<InputEvent> event_queue[MAX_EVENTS];
108 	int event_count;
109 	void queue_event(const Ref<InputEvent> &p_event);
110 
111 	String data_dir;
112 	String unique_id;
113 	String locale_code;
114 
115 	InputDefault *input;
116 
117 	int virtual_keyboard_height;
118 
119 	int video_driver_index;
120 
121 public:
122 	bool iterate();
123 
124 	uint8_t get_orientations() const;
125 
126 	void touch_press(int p_idx, int p_x, int p_y, bool p_pressed, bool p_doubleclick);
127 	void touch_drag(int p_idx, int p_prev_x, int p_prev_y, int p_x, int p_y);
128 	void touches_cancelled();
129 	void key(uint32_t p_key, bool p_pressed);
130 	void set_virtual_keyboard_height(int p_height);
131 
132 	int set_base_framebuffer(int p_fb);
133 
134 	void update_gravity(float p_x, float p_y, float p_z);
135 	void update_accelerometer(float p_x, float p_y, float p_z);
136 	void update_magnetometer(float p_x, float p_y, float p_z);
137 	void update_gyroscope(float p_x, float p_y, float p_z);
138 
139 	int get_unused_joy_id();
140 	void joy_connection_changed(int p_idx, bool p_connected, String p_name);
141 	void joy_button(int p_device, int p_button, bool p_pressed);
142 	void joy_axis(int p_device, int p_axis, const InputDefault::JoyAxis &p_value);
143 
144 	static OSIPhone *get_singleton();
145 
146 	virtual void set_mouse_show(bool p_show);
147 	virtual void set_mouse_grab(bool p_grab);
148 	virtual bool is_mouse_grab_enabled() const;
149 	virtual Point2 get_mouse_position() const;
150 	virtual int get_mouse_button_state() const;
151 	virtual void set_window_title(const String &p_title);
152 
153 	virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
154 
155 	virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false);
156 	virtual Error close_dynamic_library(void *p_library_handle);
157 	virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional = false);
158 
159 	virtual void set_video_mode(const VideoMode &p_video_mode, int p_screen = 0);
160 	virtual VideoMode get_video_mode(int p_screen = 0) const;
161 	virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const;
162 
163 	virtual void set_keep_screen_on(bool p_enabled);
164 
165 	virtual bool can_draw() const;
166 
167 	virtual bool has_virtual_keyboard() const;
168 	virtual void show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), bool p_multiline = false, int p_max_input_length = -1, int p_cursor_start = -1, int p_cursor_end = -1);
169 	virtual void hide_virtual_keyboard();
170 	virtual int get_virtual_keyboard_height() const;
171 
172 	virtual Size2 get_window_size() const;
173 	virtual Rect2 get_window_safe_area() const;
174 
175 	virtual bool has_touchscreen_ui_hint() const;
176 
177 	void set_data_dir(String p_dir);
178 
179 	virtual String get_name() const;
180 	virtual String get_model_name() const;
181 
182 	Error shell_open(String p_uri);
183 
184 	String get_user_data_dir() const;
185 
186 	void set_locale(String p_locale);
187 	String get_locale() const;
188 
189 	void set_unique_id(String p_id);
190 	String get_unique_id() const;
191 
192 	virtual Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track);
193 	virtual bool native_video_is_playing() const;
194 	virtual void native_video_pause();
195 	virtual void native_video_unpause();
196 	virtual void native_video_focus_out();
197 	virtual void native_video_stop();
198 	virtual void vibrate_handheld(int p_duration_ms = 500);
199 
200 	virtual bool _check_internal_feature_support(const String &p_feature);
201 	OSIPhone(int width, int height, String p_data_dir);
202 	~OSIPhone();
203 };
204 
205 #endif // OS_IPHONE_H
206 
207 #endif
208