2
0

os_android.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*************************************************************************/
  2. /* os_android.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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. class GodotJavaWrapper;
  42. class GodotIOJavaWrapper;
  43. class OS_Android : public OS_Unix {
  44. public:
  45. struct TouchPos {
  46. int id;
  47. Point2 pos;
  48. };
  49. enum {
  50. JOY_EVENT_BUTTON = 0,
  51. JOY_EVENT_AXIS = 1,
  52. JOY_EVENT_HAT = 2
  53. };
  54. struct JoypadEvent {
  55. int device;
  56. int type;
  57. int index;
  58. bool pressed;
  59. float value;
  60. int hat;
  61. };
  62. private:
  63. Vector<TouchPos> touch;
  64. Point2 hover_prev_pos; // needed to calculate the relative position on hover events
  65. Point2 scroll_prev_pos; // needed to calculate the relative position on scroll events
  66. bool use_gl2;
  67. bool use_apk_expansion;
  68. bool use_16bits_fbo;
  69. VisualServer *visual_server;
  70. mutable String data_dir_cache;
  71. //AudioDriverAndroid audio_driver_android;
  72. AudioDriverOpenSL audio_driver_android;
  73. const char *gl_extensions;
  74. InputDefault *input;
  75. VideoMode default_videomode;
  76. MainLoop *main_loop;
  77. GodotJavaWrapper *godot_java;
  78. GodotIOJavaWrapper *godot_io_java;
  79. //PowerAndroid *power_manager_func;
  80. int video_driver_index;
  81. bool alt_mem = false;
  82. bool shift_mem = false;
  83. bool control_mem = false;
  84. bool meta_mem = false;
  85. int buttons_state;
  86. void _set_key_modifier_state(Ref<InputEventWithModifiers> ev) const;
  87. static int _button_index_from_mask(int button_mask);
  88. static int _android_button_mask_to_godot_button_mask(int android_button_mask);
  89. void _wheel_button_click(int event_buttons_mask, const Ref<InputEventMouseButton> &ev, int wheel_button, float factor);
  90. public:
  91. // functions used by main to initialize/deinitialize the OS
  92. virtual int get_video_driver_count() const;
  93. virtual const char *get_video_driver_name(int p_driver) const;
  94. virtual int get_audio_driver_count() const;
  95. virtual const char *get_audio_driver_name(int p_driver) const;
  96. virtual int get_current_video_driver() const;
  97. virtual void initialize_core();
  98. virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
  99. virtual void set_main_loop(MainLoop *p_main_loop);
  100. virtual void delete_main_loop();
  101. virtual void finalize();
  102. typedef int64_t ProcessID;
  103. static OS *get_singleton();
  104. GodotJavaWrapper *get_godot_java();
  105. GodotIOJavaWrapper *get_godot_io_java();
  106. virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
  107. virtual bool request_permission(const String &p_name);
  108. virtual bool request_permissions();
  109. virtual Vector<String> get_granted_permissions() const;
  110. virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false);
  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 set_video_mode(const VideoMode &p_video_mode, int p_screen = 0);
  118. virtual VideoMode get_video_mode(int p_screen = 0) const;
  119. virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const;
  120. virtual void set_keep_screen_on(bool p_enabled);
  121. virtual Size2 get_window_size() const;
  122. virtual Rect2 get_window_safe_area() const;
  123. virtual String get_name() const;
  124. virtual MainLoop *get_main_loop() const;
  125. virtual bool can_draw() const;
  126. void main_loop_begin();
  127. bool main_loop_iterate();
  128. void main_loop_request_go_back();
  129. void main_loop_end();
  130. void main_loop_focusout();
  131. void main_loop_focusin();
  132. virtual bool has_touchscreen_ui_hint() const;
  133. virtual bool has_virtual_keyboard() const;
  134. 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);
  135. virtual void hide_virtual_keyboard();
  136. virtual int get_virtual_keyboard_height() const;
  137. void set_opengl_extensions(const char *p_gl_extensions);
  138. void set_display_size(Size2 p_size);
  139. void set_context_is_16_bits(bool p_is_16);
  140. virtual void set_screen_orientation(ScreenOrientation p_orientation);
  141. virtual ScreenOrientation get_screen_orientation() const;
  142. virtual Error shell_open(String p_uri);
  143. virtual String get_user_data_dir() const;
  144. virtual String get_data_path() const;
  145. virtual String get_cache_path() const;
  146. virtual String get_resource_dir() const;
  147. virtual String get_locale() const;
  148. virtual void set_clipboard(const String &p_text);
  149. virtual String get_clipboard() const;
  150. virtual String get_model_name() const;
  151. virtual int get_screen_dpi(int p_screen = 0) const;
  152. virtual String get_unique_id() const;
  153. virtual String get_system_dir(SystemDir p_dir, bool p_shared_storage = true) const;
  154. void process_accelerometer(const Vector3 &p_accelerometer);
  155. void process_gravity(const Vector3 &p_gravity);
  156. void process_magnetometer(const Vector3 &p_magnetometer);
  157. void process_gyroscope(const Vector3 &p_gyroscope);
  158. void process_touch(int p_event, int p_pointer, const Vector<TouchPos> &p_points);
  159. void process_hover(int p_type, Point2 p_pos);
  160. void process_mouse_event(int event_action, int event_android_buttons_mask, Point2 event_pos, float event_vertical_factor = 0, float event_horizontal_factor = 0);
  161. void process_double_tap(int event_android_button_mask, Point2 p_pos);
  162. void process_scroll(Point2 p_pos);
  163. void process_joy_event(JoypadEvent p_event);
  164. void process_key_event(int p_scancode, int p_unicode_char, bool p_pressed);
  165. void process_event(Ref<InputEvent> p_event);
  166. void init_video_mode(int p_video_width, int p_video_height);
  167. virtual Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track);
  168. virtual bool native_video_is_playing() const;
  169. virtual void native_video_pause();
  170. virtual void native_video_stop();
  171. virtual bool is_joy_known(int p_device);
  172. virtual String get_joy_guid(int p_device) const;
  173. void joy_connection_changed(int p_device, bool p_connected, String p_name);
  174. void vibrate_handheld(int p_duration_ms);
  175. virtual bool _check_internal_feature_support(const String &p_feature);
  176. OS_Android(GodotJavaWrapper *p_godot_java, GodotIOJavaWrapper *p_godot_io_java, bool p_use_apk_expansion);
  177. ~OS_Android();
  178. };
  179. #endif