display_server_android.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /**************************************************************************/
  2. /* display_server_android.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 DISPLAY_SERVER_ANDROID_H
  31. #define DISPLAY_SERVER_ANDROID_H
  32. #include "servers/display_server.h"
  33. #if defined(RD_ENABLED)
  34. class RenderingContextDriver;
  35. class RenderingDevice;
  36. #endif
  37. class DisplayServerAndroid : public DisplayServer {
  38. // No need to register with GDCLASS, it's platform-specific and nothing is added.
  39. String rendering_driver;
  40. // https://developer.android.com/reference/android/view/PointerIcon
  41. // mapping between Godot's cursor shape to Android's'
  42. int android_cursors[CURSOR_MAX] = {
  43. 1000, //CURSOR_ARROW
  44. 1008, //CURSOR_IBEAM
  45. 1002, //CURSOR_POINTIN
  46. 1007, //CURSOR_CROSS
  47. 1004, //CURSOR_WAIT
  48. 1004, //CURSOR_BUSY
  49. 1021, //CURSOR_DRAG
  50. 1021, //CURSOR_CAN_DRO
  51. 1000, //CURSOR_FORBIDD (no corresponding icon in Android's icon so fallback to default)
  52. 1015, //CURSOR_VSIZE
  53. 1014, //CURSOR_HSIZE
  54. 1017, //CURSOR_BDIAGSI
  55. 1016, //CURSOR_FDIAGSI
  56. 1020, //CURSOR_MOVE
  57. 1015, //CURSOR_VSPLIT
  58. 1014, //CURSOR_HSPLIT
  59. 1003, //CURSOR_HELP
  60. };
  61. const int CURSOR_TYPE_NULL = 0;
  62. MouseMode mouse_mode = MouseMode::MOUSE_MODE_VISIBLE;
  63. bool keep_screen_on;
  64. bool swap_buffers_flag;
  65. CursorShape cursor_shape = CursorShape::CURSOR_ARROW;
  66. #if defined(RD_ENABLED)
  67. RenderingContextDriver *rendering_context = nullptr;
  68. RenderingDevice *rendering_device = nullptr;
  69. #endif
  70. NativeMenu *native_menu = nullptr;
  71. ObjectID window_attached_instance_id;
  72. Callable window_event_callback;
  73. Callable input_event_callback;
  74. Callable input_text_callback;
  75. Callable rect_changed_callback;
  76. Callable system_theme_changed;
  77. Callable input_dialog_callback;
  78. Callable file_picker_callback;
  79. void _window_callback(const Callable &p_callable, const Variant &p_arg, bool p_deferred = false) const;
  80. static void _dispatch_input_events(const Ref<InputEvent> &p_event);
  81. public:
  82. static DisplayServerAndroid *get_singleton();
  83. virtual bool has_feature(Feature p_feature) const override;
  84. virtual String get_name() const override;
  85. virtual bool tts_is_speaking() const override;
  86. virtual bool tts_is_paused() const override;
  87. virtual TypedArray<Dictionary> tts_get_voices() const override;
  88. virtual void tts_speak(const String &p_text, const String &p_voice, int p_volume = 50, float p_pitch = 1.f, float p_rate = 1.f, int p_utterance_id = 0, bool p_interrupt = false) override;
  89. virtual void tts_pause() override;
  90. virtual void tts_resume() override;
  91. virtual void tts_stop() override;
  92. void emit_system_theme_changed();
  93. virtual bool is_dark_mode_supported() const override;
  94. virtual bool is_dark_mode() const override;
  95. virtual void set_system_theme_change_callback(const Callable &p_callable) override;
  96. virtual void clipboard_set(const String &p_text) override;
  97. virtual String clipboard_get() const override;
  98. virtual bool clipboard_has() const override;
  99. virtual Error dialog_input_text(String p_title, String p_description, String p_partial, const Callable &p_callback) override;
  100. void emit_input_dialog_callback(String p_text);
  101. virtual Error file_dialog_show(const String &p_title, const String &p_current_directory, const String &p_filename, bool p_show_hidden, const FileDialogMode p_mode, const Vector<String> &p_filters, const Callable &p_callback) override;
  102. void emit_file_picker_callback(bool p_ok, const Vector<String> &p_selected_paths);
  103. virtual Color get_accent_color() const override;
  104. virtual TypedArray<Rect2> get_display_cutouts() const override;
  105. virtual Rect2i get_display_safe_area() const override;
  106. virtual void screen_set_keep_on(bool p_enable) override;
  107. virtual bool screen_is_kept_on() const override;
  108. virtual void screen_set_orientation(ScreenOrientation p_orientation, int p_screen = SCREEN_OF_MAIN_WINDOW) override;
  109. virtual ScreenOrientation screen_get_orientation(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
  110. virtual int get_screen_count() const override;
  111. virtual int get_primary_screen() const override;
  112. virtual Point2i screen_get_position(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
  113. virtual Size2i screen_get_size(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
  114. virtual Rect2i screen_get_usable_rect(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
  115. virtual int screen_get_dpi(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
  116. virtual float screen_get_scale(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
  117. virtual float screen_get_refresh_rate(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
  118. virtual bool is_touchscreen_available() const override;
  119. virtual void virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), VirtualKeyboardType p_type = KEYBOARD_TYPE_DEFAULT, int p_max_length = -1, int p_cursor_start = -1, int p_cursor_end = -1) override;
  120. virtual void virtual_keyboard_hide() override;
  121. virtual int virtual_keyboard_get_height() const override;
  122. virtual bool has_hardware_keyboard() const override;
  123. virtual void window_set_window_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override;
  124. virtual void window_set_input_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override;
  125. virtual void window_set_input_text_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override;
  126. virtual void window_set_rect_changed_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override;
  127. virtual void window_set_drop_files_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override;
  128. void send_window_event(WindowEvent p_event, bool p_deferred = false) const;
  129. void send_input_event(const Ref<InputEvent> &p_event) const;
  130. void send_input_text(const String &p_text) const;
  131. virtual Vector<WindowID> get_window_list() const override;
  132. virtual WindowID get_window_at_screen_position(const Point2i &p_position) const override;
  133. virtual int64_t window_get_native_handle(HandleType p_handle_type, WindowID p_window = MAIN_WINDOW_ID) const override;
  134. virtual void window_attach_instance_id(ObjectID p_instance, WindowID p_window = MAIN_WINDOW_ID) override;
  135. virtual ObjectID window_get_attached_instance_id(WindowID p_window = MAIN_WINDOW_ID) const override;
  136. virtual void window_set_title(const String &p_title, WindowID p_window = MAIN_WINDOW_ID) override;
  137. virtual int window_get_current_screen(WindowID p_window = MAIN_WINDOW_ID) const override;
  138. virtual void window_set_current_screen(int p_screen, WindowID p_window = MAIN_WINDOW_ID) override;
  139. virtual Point2i window_get_position(WindowID p_window = MAIN_WINDOW_ID) const override;
  140. virtual Point2i window_get_position_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override;
  141. virtual void window_set_position(const Point2i &p_position, WindowID p_window = MAIN_WINDOW_ID) override;
  142. virtual void window_set_transient(WindowID p_window, WindowID p_parent) override;
  143. virtual void window_set_max_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override;
  144. virtual Size2i window_get_max_size(WindowID p_window = MAIN_WINDOW_ID) const override;
  145. virtual void window_set_min_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override;
  146. virtual Size2i window_get_min_size(WindowID p_window = MAIN_WINDOW_ID) const override;
  147. virtual void window_set_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override;
  148. virtual Size2i window_get_size(WindowID p_window = MAIN_WINDOW_ID) const override;
  149. virtual Size2i window_get_size_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override;
  150. virtual void window_set_mode(WindowMode p_mode, WindowID p_window = MAIN_WINDOW_ID) override;
  151. virtual WindowMode window_get_mode(WindowID p_window = MAIN_WINDOW_ID) const override;
  152. virtual bool window_is_maximize_allowed(WindowID p_window = MAIN_WINDOW_ID) const override;
  153. virtual void window_set_flag(WindowFlags p_flag, bool p_enabled, WindowID p_window = MAIN_WINDOW_ID) override;
  154. virtual bool window_get_flag(WindowFlags p_flag, WindowID p_window = MAIN_WINDOW_ID) const override;
  155. virtual void window_request_attention(WindowID p_window = MAIN_WINDOW_ID) override;
  156. virtual void window_move_to_foreground(WindowID p_window = MAIN_WINDOW_ID) override;
  157. virtual bool window_is_focused(WindowID p_window = MAIN_WINDOW_ID) const override;
  158. virtual bool window_can_draw(WindowID p_window = MAIN_WINDOW_ID) const override;
  159. virtual bool can_any_window_draw() const override;
  160. virtual void window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window = MAIN_WINDOW_ID) override;
  161. virtual DisplayServer::VSyncMode window_get_vsync_mode(WindowID p_vsync_mode) const override;
  162. virtual void process_events() override;
  163. void process_accelerometer(const Vector3 &p_accelerometer);
  164. void process_gravity(const Vector3 &p_gravity);
  165. void process_magnetometer(const Vector3 &p_magnetometer);
  166. void process_gyroscope(const Vector3 &p_gyroscope);
  167. void _cursor_set_shape_helper(CursorShape p_shape, bool force = false);
  168. virtual void cursor_set_shape(CursorShape p_shape) override;
  169. virtual CursorShape cursor_get_shape() const override;
  170. virtual void cursor_set_custom_image(const Ref<Resource> &p_cursor, CursorShape p_shape = CURSOR_ARROW, const Vector2 &p_hotspot = Vector2()) override;
  171. virtual void mouse_set_mode(MouseMode p_mode) override;
  172. virtual MouseMode mouse_get_mode() const override;
  173. static DisplayServer *create_func(const String &p_rendering_driver, WindowMode p_mode, DisplayServer::VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Context p_context, Error &r_error);
  174. static Vector<String> get_rendering_drivers_func();
  175. static void register_android_driver();
  176. void reset_window();
  177. void notify_surface_changed(int p_width, int p_height);
  178. virtual Point2i mouse_get_position() const override;
  179. virtual BitField<MouseButtonMask> mouse_get_button_state() const override;
  180. void reset_swap_buffers_flag();
  181. bool should_swap_buffers() const;
  182. virtual void swap_buffers() override;
  183. virtual void set_native_icon(const String &p_filename) override;
  184. virtual void set_icon(const Ref<Image> &p_icon) override;
  185. DisplayServerAndroid(const String &p_rendering_driver, WindowMode p_mode, DisplayServer::VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Context p_context, Error &r_error);
  186. ~DisplayServerAndroid();
  187. };
  188. #endif // DISPLAY_SERVER_ANDROID_H