os_android.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*************************************************************************/
  2. /* os_android.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 OS_ANDROID_H
  31. #define OS_ANDROID_H
  32. #include "audio_driver_jandroid.h"
  33. #include "audio_driver_opensl.h"
  34. #include "core/os/input.h"
  35. #include "core/os/main_loop.h"
  36. #include "drivers/unix/os_unix.h"
  37. #include "main/input_default.h"
  38. //#include "power_android.h"
  39. #include "servers/audio_server.h"
  40. #include "servers/visual/rasterizer.h"
  41. typedef void (*GFXInitFunc)(void *ud, bool gl2);
  42. typedef int (*OpenURIFunc)(const String &);
  43. typedef String (*GetUserDataDirFunc)();
  44. typedef String (*GetLocaleFunc)();
  45. typedef void (*SetClipboardFunc)(const String &);
  46. typedef String (*GetClipboardFunc)();
  47. typedef String (*GetModelFunc)();
  48. typedef int (*GetScreenDPIFunc)();
  49. typedef String (*GetUniqueIDFunc)();
  50. typedef void (*ShowVirtualKeyboardFunc)(const String &);
  51. typedef void (*HideVirtualKeyboardFunc)();
  52. typedef void (*SetScreenOrientationFunc)(int);
  53. typedef String (*GetSystemDirFunc)(int);
  54. typedef int (*GetGLVersionCodeFunc)();
  55. typedef void (*VideoPlayFunc)(const String &);
  56. typedef bool (*VideoIsPlayingFunc)();
  57. typedef void (*VideoPauseFunc)();
  58. typedef void (*VideoStopFunc)();
  59. typedef void (*SetKeepScreenOnFunc)(bool p_enabled);
  60. typedef void (*AlertFunc)(const String &, const String &);
  61. typedef int (*VirtualKeyboardHeightFunc)();
  62. typedef bool (*RequestPermissionFunc)(const String &);
  63. typedef void (*VibrateFunc)(int);
  64. class OS_Android : public OS_Unix {
  65. public:
  66. struct TouchPos {
  67. int id;
  68. Point2 pos;
  69. };
  70. enum {
  71. JOY_EVENT_BUTTON = 0,
  72. JOY_EVENT_AXIS = 1,
  73. JOY_EVENT_HAT = 2
  74. };
  75. struct JoypadEvent {
  76. int device;
  77. int type;
  78. int index;
  79. bool pressed;
  80. float value;
  81. int hat;
  82. };
  83. private:
  84. Vector<TouchPos> touch;
  85. GFXInitFunc gfx_init_func;
  86. void *gfx_init_ud;
  87. bool use_gl2;
  88. bool use_apk_expansion;
  89. bool use_16bits_fbo;
  90. VisualServer *visual_server;
  91. mutable String data_dir_cache;
  92. //AudioDriverAndroid audio_driver_android;
  93. AudioDriverOpenSL audio_driver_android;
  94. const char *gl_extensions;
  95. InputDefault *input;
  96. VideoMode default_videomode;
  97. MainLoop *main_loop;
  98. OpenURIFunc open_uri_func;
  99. GetUserDataDirFunc get_user_data_dir_func;
  100. GetLocaleFunc get_locale_func;
  101. SetClipboardFunc set_clipboard_func;
  102. GetClipboardFunc get_clipboard_func;
  103. GetModelFunc get_model_func;
  104. GetScreenDPIFunc get_screen_dpi_func;
  105. ShowVirtualKeyboardFunc show_virtual_keyboard_func;
  106. HideVirtualKeyboardFunc hide_virtual_keyboard_func;
  107. VirtualKeyboardHeightFunc get_virtual_keyboard_height_func;
  108. SetScreenOrientationFunc set_screen_orientation_func;
  109. GetUniqueIDFunc get_unique_id_func;
  110. GetSystemDirFunc get_system_dir_func;
  111. GetGLVersionCodeFunc get_gl_version_code_func;
  112. VideoPlayFunc video_play_func;
  113. VideoIsPlayingFunc video_is_playing_func;
  114. VideoPauseFunc video_pause_func;
  115. VideoStopFunc video_stop_func;
  116. SetKeepScreenOnFunc set_keep_screen_on_func;
  117. AlertFunc alert_func;
  118. RequestPermissionFunc request_permission_func;
  119. VibrateFunc vibrate_func;
  120. //PowerAndroid *power_manager;
  121. int video_driver_index;
  122. public:
  123. // functions used by main to initialize/deinitialize the OS
  124. virtual int get_video_driver_count() const;
  125. virtual const char *get_video_driver_name(int p_driver) const;
  126. virtual int get_audio_driver_count() const;
  127. virtual const char *get_audio_driver_name(int p_driver) const;
  128. virtual int get_current_video_driver() const;
  129. virtual void initialize_core();
  130. virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
  131. virtual void set_main_loop(MainLoop *p_main_loop);
  132. virtual void delete_main_loop();
  133. virtual void finalize();
  134. typedef int64_t ProcessID;
  135. static OS *get_singleton();
  136. virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
  137. virtual bool request_permission(const String &p_name);
  138. virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false);
  139. virtual void set_mouse_show(bool p_show);
  140. virtual void set_mouse_grab(bool p_grab);
  141. virtual bool is_mouse_grab_enabled() const;
  142. virtual Point2 get_mouse_position() const;
  143. virtual int get_mouse_button_state() const;
  144. virtual void set_window_title(const String &p_title);
  145. virtual void set_video_mode(const VideoMode &p_video_mode, int p_screen = 0);
  146. virtual VideoMode get_video_mode(int p_screen = 0) const;
  147. virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const;
  148. virtual void set_keep_screen_on(bool p_enabled);
  149. virtual Size2 get_window_size() const;
  150. virtual String get_name();
  151. virtual MainLoop *get_main_loop() const;
  152. virtual bool can_draw() const;
  153. void main_loop_begin();
  154. bool main_loop_iterate();
  155. void main_loop_request_go_back();
  156. void main_loop_end();
  157. void main_loop_focusout();
  158. void main_loop_focusin();
  159. virtual bool has_touchscreen_ui_hint() const;
  160. virtual bool has_virtual_keyboard() const;
  161. virtual void show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2());
  162. virtual void hide_virtual_keyboard();
  163. virtual int get_virtual_keyboard_height() const;
  164. void set_opengl_extensions(const char *p_gl_extensions);
  165. void set_display_size(Size2 p_size);
  166. void set_context_is_16_bits(bool p_is_16);
  167. virtual void set_screen_orientation(ScreenOrientation p_orientation);
  168. virtual Error shell_open(String p_uri);
  169. virtual String get_user_data_dir() const;
  170. virtual String get_resource_dir() const;
  171. virtual String get_locale() const;
  172. virtual void set_clipboard(const String &p_text);
  173. virtual String get_clipboard() const;
  174. virtual String get_model_name() const;
  175. virtual int get_screen_dpi(int p_screen = 0) const;
  176. virtual String get_unique_id() const;
  177. virtual String get_system_dir(SystemDir p_dir) const;
  178. void process_accelerometer(const Vector3 &p_accelerometer);
  179. void process_gravity(const Vector3 &p_gravity);
  180. void process_magnetometer(const Vector3 &p_magnetometer);
  181. void process_gyroscope(const Vector3 &p_gyroscope);
  182. void process_touch(int p_what, int p_pointer, const Vector<TouchPos> &p_points);
  183. void process_joy_event(JoypadEvent p_event);
  184. void process_event(Ref<InputEvent> p_event);
  185. void init_video_mode(int p_video_width, int p_video_height);
  186. virtual Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track);
  187. virtual bool native_video_is_playing() const;
  188. virtual void native_video_pause();
  189. virtual void native_video_stop();
  190. virtual bool is_joy_known(int p_device);
  191. virtual String get_joy_guid(int p_device) const;
  192. void joy_connection_changed(int p_device, bool p_connected, String p_name);
  193. void vibrate_handheld(int p_duration_ms = 500);
  194. virtual bool _check_internal_feature_support(const String &p_feature);
  195. OS_Android(GFXInitFunc p_gfx_init_func, void *p_gfx_init_ud, OpenURIFunc p_open_uri_func, GetUserDataDirFunc p_get_user_data_dir_func, GetLocaleFunc p_get_locale_func, GetModelFunc p_get_model_func, GetScreenDPIFunc p_get_screen_dpi_func, ShowVirtualKeyboardFunc p_show_vk, HideVirtualKeyboardFunc p_hide_vk, VirtualKeyboardHeightFunc p_vk_height_func, SetScreenOrientationFunc p_screen_orient, GetUniqueIDFunc p_get_unique_id, GetSystemDirFunc p_get_sdir_func, GetGLVersionCodeFunc p_get_gl_version_func, VideoPlayFunc p_video_play_func, VideoIsPlayingFunc p_video_is_playing_func, VideoPauseFunc p_video_pause_func, VideoStopFunc p_video_stop_func, SetKeepScreenOnFunc p_set_keep_screen_on_func, AlertFunc p_alert_func, SetClipboardFunc p_set_clipboard, GetClipboardFunc p_get_clipboard, RequestPermissionFunc p_request_permission, VibrateFunc p_vibrate_func, bool p_use_apk_expansion);
  196. ~OS_Android();
  197. };
  198. #endif