os_iphone.h 7.1 KB

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