display_server_android.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*************************************************************************/
  2. /* display_server_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 DISPLAY_SERVER_ANDROID_H
  31. #define DISPLAY_SERVER_ANDROID_H
  32. #include "servers/display_server.h"
  33. #if defined(VULKAN_ENABLED)
  34. class VulkanContextAndroid;
  35. class RenderingDeviceVulkan;
  36. #endif
  37. class DisplayServerAndroid : public DisplayServer {
  38. public:
  39. struct TouchPos {
  40. int id = 0;
  41. Point2 pos;
  42. };
  43. enum {
  44. JOY_EVENT_BUTTON = 0,
  45. JOY_EVENT_AXIS = 1,
  46. JOY_EVENT_HAT = 2
  47. };
  48. struct JoypadEvent {
  49. int device = 0;
  50. int type = 0;
  51. int index = 0;
  52. bool pressed = false;
  53. float value = 0;
  54. int hat = 0;
  55. };
  56. private:
  57. String rendering_driver;
  58. bool alt_mem = false;
  59. bool shift_mem = false;
  60. bool control_mem = false;
  61. bool meta_mem = false;
  62. int buttons_state;
  63. MouseMode mouse_mode;
  64. bool keep_screen_on;
  65. Vector<TouchPos> touch;
  66. Point2 hover_prev_pos; // needed to calculate the relative position on hover events
  67. Point2 scroll_prev_pos; // needed to calculate the relative position on scroll events
  68. #if defined(VULKAN_ENABLED)
  69. VulkanContextAndroid *context_vulkan;
  70. RenderingDeviceVulkan *rendering_device_vulkan;
  71. #endif
  72. ObjectID window_attached_instance_id;
  73. Callable window_event_callback;
  74. Callable input_event_callback;
  75. Callable input_text_callback;
  76. void _window_callback(const Callable &p_callable, const Variant &p_arg) const;
  77. static void _dispatch_input_events(const Ref<InputEvent> &p_event);
  78. void _set_key_modifier_state(Ref<InputEventWithModifiers> ev);
  79. static int _button_index_from_mask(int button_mask);
  80. static int _android_button_mask_to_godot_button_mask(int android_button_mask);
  81. void _wheel_button_click(int event_buttons_mask, const Ref<InputEventMouseButton> &ev, int wheel_button, float factor);
  82. public:
  83. static DisplayServerAndroid *get_singleton();
  84. virtual bool has_feature(Feature p_feature) const;
  85. virtual String get_name() const;
  86. virtual void clipboard_set(const String &p_text);
  87. virtual String clipboard_get() const;
  88. virtual void screen_set_keep_on(bool p_enable);
  89. virtual bool screen_is_kept_on() const;
  90. virtual void screen_set_orientation(ScreenOrientation p_orientation, int p_screen = SCREEN_OF_MAIN_WINDOW);
  91. virtual ScreenOrientation screen_get_orientation(int p_screen = SCREEN_OF_MAIN_WINDOW) const;
  92. virtual int get_screen_count() const;
  93. virtual Point2i screen_get_position(int p_screen = SCREEN_OF_MAIN_WINDOW) const;
  94. virtual Size2i screen_get_size(int p_screen = SCREEN_OF_MAIN_WINDOW) const;
  95. virtual Rect2i screen_get_usable_rect(int p_screen = SCREEN_OF_MAIN_WINDOW) const;
  96. virtual int screen_get_dpi(int p_screen = SCREEN_OF_MAIN_WINDOW) const;
  97. virtual bool screen_is_touchscreen(int p_screen = SCREEN_OF_MAIN_WINDOW) const;
  98. virtual void virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), bool p_multiline = false, int p_max_length = -1, int p_cursor_start = -1, int p_cursor_end = -1);
  99. virtual void virtual_keyboard_hide();
  100. virtual int virtual_keyboard_get_height() const;
  101. virtual void window_set_window_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID);
  102. virtual void window_set_input_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID);
  103. virtual void window_set_input_text_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID);
  104. virtual void window_set_rect_changed_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID);
  105. virtual void window_set_drop_files_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID);
  106. void send_window_event(WindowEvent p_event) const;
  107. void send_input_event(const Ref<InputEvent> &p_event) const;
  108. void send_input_text(const String &p_text) const;
  109. virtual Vector<WindowID> get_window_list() const;
  110. virtual WindowID get_window_at_screen_position(const Point2i &p_position) const;
  111. virtual void window_attach_instance_id(ObjectID p_instance, WindowID p_window = MAIN_WINDOW_ID);
  112. virtual ObjectID window_get_attached_instance_id(WindowID p_window = MAIN_WINDOW_ID) const;
  113. virtual void window_set_title(const String &p_title, WindowID p_window = MAIN_WINDOW_ID);
  114. virtual int window_get_current_screen(WindowID p_window = MAIN_WINDOW_ID) const;
  115. virtual void window_set_current_screen(int p_screen, WindowID p_window = MAIN_WINDOW_ID);
  116. virtual Point2i window_get_position(WindowID p_window = MAIN_WINDOW_ID) const;
  117. virtual void window_set_position(const Point2i &p_position, WindowID p_window = MAIN_WINDOW_ID);
  118. virtual void window_set_transient(WindowID p_window, WindowID p_parent);
  119. virtual void window_set_max_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID);
  120. virtual Size2i window_get_max_size(WindowID p_window = MAIN_WINDOW_ID) const;
  121. virtual void window_set_min_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID);
  122. virtual Size2i window_get_min_size(WindowID p_window = MAIN_WINDOW_ID) const;
  123. virtual void window_set_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID);
  124. virtual Size2i window_get_size(WindowID p_window = MAIN_WINDOW_ID) const;
  125. virtual Size2i window_get_real_size(WindowID p_window = MAIN_WINDOW_ID) const;
  126. virtual void window_set_mode(WindowMode p_mode, WindowID p_window = MAIN_WINDOW_ID);
  127. virtual WindowMode window_get_mode(WindowID p_window = MAIN_WINDOW_ID) const;
  128. virtual bool window_is_maximize_allowed(WindowID p_window = MAIN_WINDOW_ID) const;
  129. virtual void window_set_flag(WindowFlags p_flag, bool p_enabled, WindowID p_window = MAIN_WINDOW_ID);
  130. virtual bool window_get_flag(WindowFlags p_flag, WindowID p_window = MAIN_WINDOW_ID) const;
  131. virtual void window_request_attention(WindowID p_window = MAIN_WINDOW_ID);
  132. virtual void window_move_to_foreground(WindowID p_window = MAIN_WINDOW_ID);
  133. virtual bool window_can_draw(WindowID p_window = MAIN_WINDOW_ID) const;
  134. virtual bool can_any_window_draw() const;
  135. virtual void alert(const String &p_alert, const String &p_title);
  136. virtual void process_events();
  137. void process_accelerometer(const Vector3 &p_accelerometer);
  138. void process_gravity(const Vector3 &p_gravity);
  139. void process_magnetometer(const Vector3 &p_magnetometer);
  140. void process_gyroscope(const Vector3 &p_gyroscope);
  141. void process_touch(int p_event, int p_pointer, const Vector<TouchPos> &p_points);
  142. void process_hover(int p_type, Point2 p_pos);
  143. void process_mouse_event(int input_device, int event_action, int event_android_buttons_mask, Point2 event_pos, float event_vertical_factor = 0, float event_horizontal_factor = 0);
  144. void process_double_tap(int event_android_button_mask, Point2 p_pos);
  145. void process_scroll(Point2 p_pos);
  146. void process_joy_event(JoypadEvent p_event);
  147. void process_key_event(int p_keycode, int p_scancode, int p_unicode_char, bool p_pressed);
  148. void mouse_set_mode(MouseMode p_mode);
  149. MouseMode mouse_get_mode() const;
  150. static DisplayServer *create_func(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error);
  151. static Vector<String> get_rendering_drivers_func();
  152. static void register_android_driver();
  153. void reset_window();
  154. virtual Point2i mouse_get_position() const;
  155. virtual int mouse_get_button_state() const;
  156. DisplayServerAndroid(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error);
  157. ~DisplayServerAndroid();
  158. };
  159. #endif // DISPLAY_SERVER_ANDROID_H