os_android.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*************************************************************************/
  2. /* os_android.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. #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. public:
  82. // functions used by main to initialize/deinitialize the OS
  83. virtual int get_video_driver_count() const;
  84. virtual const char *get_video_driver_name(int p_driver) const;
  85. virtual int get_audio_driver_count() const;
  86. virtual const char *get_audio_driver_name(int p_driver) const;
  87. virtual int get_current_video_driver() const;
  88. virtual void initialize_core();
  89. virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
  90. virtual void set_main_loop(MainLoop *p_main_loop);
  91. virtual void delete_main_loop();
  92. virtual void finalize();
  93. typedef int64_t ProcessID;
  94. static OS *get_singleton();
  95. GodotJavaWrapper *get_godot_java();
  96. GodotIOJavaWrapper *get_godot_io_java();
  97. virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
  98. virtual bool request_permission(const String &p_name);
  99. virtual bool request_permissions();
  100. virtual Vector<String> get_granted_permissions() const;
  101. virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false);
  102. virtual void set_mouse_show(bool p_show);
  103. virtual void set_mouse_grab(bool p_grab);
  104. virtual bool is_mouse_grab_enabled() const;
  105. virtual Point2 get_mouse_position() const;
  106. virtual int get_mouse_button_state() const;
  107. virtual void set_window_title(const String &p_title);
  108. virtual void set_video_mode(const VideoMode &p_video_mode, int p_screen = 0);
  109. virtual VideoMode get_video_mode(int p_screen = 0) const;
  110. virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const;
  111. virtual void set_keep_screen_on(bool p_enabled);
  112. virtual Size2 get_window_size() const;
  113. virtual String get_name() const;
  114. virtual MainLoop *get_main_loop() const;
  115. virtual bool can_draw() const;
  116. void main_loop_begin();
  117. bool main_loop_iterate();
  118. void main_loop_request_go_back();
  119. void main_loop_end();
  120. void main_loop_focusout();
  121. void main_loop_focusin();
  122. virtual bool has_touchscreen_ui_hint() const;
  123. virtual bool has_virtual_keyboard() const;
  124. 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);
  125. virtual void hide_virtual_keyboard();
  126. virtual int get_virtual_keyboard_height() const;
  127. void set_opengl_extensions(const char *p_gl_extensions);
  128. void set_display_size(Size2 p_size);
  129. void set_context_is_16_bits(bool p_is_16);
  130. virtual void set_screen_orientation(ScreenOrientation p_orientation);
  131. virtual Error shell_open(String p_uri);
  132. virtual String get_user_data_dir() const;
  133. virtual String get_resource_dir() const;
  134. virtual String get_locale() const;
  135. virtual void set_clipboard(const String &p_text);
  136. virtual String get_clipboard() const;
  137. virtual String get_model_name() const;
  138. virtual int get_screen_dpi(int p_screen = 0) const;
  139. virtual String get_unique_id() const;
  140. virtual String get_system_dir(SystemDir p_dir) const;
  141. void process_accelerometer(const Vector3 &p_accelerometer);
  142. void process_gravity(const Vector3 &p_gravity);
  143. void process_magnetometer(const Vector3 &p_magnetometer);
  144. void process_gyroscope(const Vector3 &p_gyroscope);
  145. void process_touch(int p_what, int p_pointer, const Vector<TouchPos> &p_points);
  146. void process_hover(int p_type, Point2 p_pos);
  147. void process_double_tap(Point2 p_pos);
  148. void process_scroll(Point2 p_pos);
  149. void process_joy_event(JoypadEvent p_event);
  150. void process_event(Ref<InputEvent> p_event);
  151. void init_video_mode(int p_video_width, int p_video_height);
  152. virtual Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track);
  153. virtual bool native_video_is_playing() const;
  154. virtual void native_video_pause();
  155. virtual void native_video_stop();
  156. virtual bool is_joy_known(int p_device);
  157. virtual String get_joy_guid(int p_device) const;
  158. void joy_connection_changed(int p_device, bool p_connected, String p_name);
  159. void vibrate_handheld(int p_duration_ms);
  160. virtual bool _check_internal_feature_support(const String &p_feature);
  161. OS_Android(GodotJavaWrapper *p_godot_java, GodotIOJavaWrapper *p_godot_io_java, bool p_use_apk_expansion);
  162. ~OS_Android();
  163. };
  164. #endif