display_server_ios.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /**************************************************************************/
  2. /* display_server_ios.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_IOS_H
  31. #define DISPLAY_SERVER_IOS_H
  32. #include "core/input/input.h"
  33. #include "servers/display_server.h"
  34. #if defined(RD_ENABLED)
  35. #include "servers/rendering/renderer_rd/renderer_compositor_rd.h"
  36. #include "servers/rendering/rendering_device.h"
  37. #if defined(VULKAN_ENABLED)
  38. #import "rendering_context_driver_vulkan_ios.h"
  39. #include "drivers/vulkan/godot_vulkan.h"
  40. #endif // VULKAN_ENABLED
  41. #if defined(METAL_ENABLED)
  42. #include "drivers/metal/rendering_context_driver_metal.h"
  43. #endif // METAL_ENABLED
  44. #endif // RD_ENABLED
  45. #if defined(GLES3_ENABLED)
  46. #include "drivers/gles3/rasterizer_gles3.h"
  47. #endif // GLES3_ENABLED
  48. #import <Foundation/Foundation.h>
  49. #import <QuartzCore/CAMetalLayer.h>
  50. class DisplayServerIOS : public DisplayServer {
  51. // No need to register with GDCLASS, it's platform-specific and nothing is added.
  52. _THREAD_SAFE_CLASS_
  53. #if defined(RD_ENABLED)
  54. RenderingContextDriver *rendering_context = nullptr;
  55. RenderingDevice *rendering_device = nullptr;
  56. #endif
  57. NativeMenu *native_menu = nullptr;
  58. id tts = nullptr;
  59. DisplayServer::ScreenOrientation screen_orientation;
  60. ObjectID window_attached_instance_id;
  61. Callable window_event_callback;
  62. Callable window_resize_callback;
  63. Callable input_event_callback;
  64. Callable input_text_callback;
  65. Callable system_theme_changed;
  66. int virtual_keyboard_height = 0;
  67. void perform_event(const Ref<InputEvent> &p_event);
  68. DisplayServerIOS(const String &p_rendering_driver, DisplayServer::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);
  69. ~DisplayServerIOS();
  70. public:
  71. String rendering_driver;
  72. static DisplayServerIOS *get_singleton();
  73. static void register_ios_driver();
  74. 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);
  75. static Vector<String> get_rendering_drivers_func();
  76. // MARK: - Events
  77. virtual void process_events() override;
  78. virtual void window_set_rect_changed_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override;
  79. virtual void window_set_window_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override;
  80. virtual void window_set_input_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override;
  81. virtual void window_set_input_text_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override;
  82. virtual void window_set_drop_files_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override;
  83. static void _dispatch_input_events(const Ref<InputEvent> &p_event);
  84. void send_input_event(const Ref<InputEvent> &p_event) const;
  85. void send_input_text(const String &p_text) const;
  86. void send_window_event(DisplayServer::WindowEvent p_event) const;
  87. void _window_callback(const Callable &p_callable, const Variant &p_arg) const;
  88. void emit_system_theme_changed();
  89. // MARK: - Input
  90. // MARK: Touches and Apple Pencil
  91. void touch_press(int p_idx, int p_x, int p_y, bool p_pressed, bool p_double_click);
  92. void touch_drag(int p_idx, int p_prev_x, int p_prev_y, int p_x, int p_y, float p_pressure, Vector2 p_tilt);
  93. void touches_canceled(int p_idx);
  94. // MARK: Keyboard
  95. void key(Key p_key, char32_t p_char, Key p_unshifted, Key p_physical, NSInteger p_modifier, bool p_pressed, KeyLocation p_location);
  96. bool is_keyboard_active() const;
  97. // MARK: Motion
  98. void update_gravity(const Vector3 &p_gravity);
  99. void update_accelerometer(const Vector3 &p_accelerometer);
  100. void update_magnetometer(const Vector3 &p_magnetometer);
  101. void update_gyroscope(const Vector3 &p_gyroscope);
  102. // MARK: -
  103. virtual bool has_feature(Feature p_feature) const override;
  104. virtual String get_name() const override;
  105. virtual bool tts_is_speaking() const override;
  106. virtual bool tts_is_paused() const override;
  107. virtual TypedArray<Dictionary> tts_get_voices() const override;
  108. 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;
  109. virtual void tts_pause() override;
  110. virtual void tts_resume() override;
  111. virtual void tts_stop() override;
  112. virtual bool is_dark_mode_supported() const override;
  113. virtual bool is_dark_mode() const override;
  114. virtual void set_system_theme_change_callback(const Callable &p_callable) override;
  115. virtual Rect2i get_display_safe_area() const override;
  116. virtual int get_screen_count() const override;
  117. virtual int get_primary_screen() const override;
  118. virtual Point2i screen_get_position(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
  119. virtual Size2i screen_get_size(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
  120. virtual Rect2i screen_get_usable_rect(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
  121. virtual int screen_get_dpi(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
  122. virtual float screen_get_scale(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
  123. virtual float screen_get_refresh_rate(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
  124. virtual Vector<DisplayServer::WindowID> get_window_list() const override;
  125. virtual WindowID get_window_at_screen_position(const Point2i &p_position) const override;
  126. virtual int64_t window_get_native_handle(HandleType p_handle_type, WindowID p_window = MAIN_WINDOW_ID) const override;
  127. virtual void window_attach_instance_id(ObjectID p_instance, WindowID p_window = MAIN_WINDOW_ID) override;
  128. virtual ObjectID window_get_attached_instance_id(WindowID p_window = MAIN_WINDOW_ID) const override;
  129. virtual void window_set_title(const String &p_title, WindowID p_window = MAIN_WINDOW_ID) override;
  130. virtual int window_get_current_screen(WindowID p_window = MAIN_WINDOW_ID) const override;
  131. virtual void window_set_current_screen(int p_screen, WindowID p_window = MAIN_WINDOW_ID) override;
  132. virtual Point2i window_get_position(WindowID p_window = MAIN_WINDOW_ID) const override;
  133. virtual Point2i window_get_position_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override;
  134. virtual void window_set_position(const Point2i &p_position, WindowID p_window = MAIN_WINDOW_ID) override;
  135. virtual void window_set_transient(WindowID p_window, WindowID p_parent) override;
  136. virtual void window_set_max_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override;
  137. virtual Size2i window_get_max_size(WindowID p_window = MAIN_WINDOW_ID) const override;
  138. virtual void window_set_min_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override;
  139. virtual Size2i window_get_min_size(WindowID p_window = MAIN_WINDOW_ID) const override;
  140. virtual void window_set_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override;
  141. virtual Size2i window_get_size(WindowID p_window = MAIN_WINDOW_ID) const override;
  142. virtual Size2i window_get_size_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override;
  143. virtual void window_set_mode(WindowMode p_mode, WindowID p_window = MAIN_WINDOW_ID) override;
  144. virtual WindowMode window_get_mode(WindowID p_window = MAIN_WINDOW_ID) const override;
  145. virtual bool window_is_maximize_allowed(WindowID p_window = MAIN_WINDOW_ID) const override;
  146. virtual void window_set_flag(WindowFlags p_flag, bool p_enabled, WindowID p_window = MAIN_WINDOW_ID) override;
  147. virtual bool window_get_flag(WindowFlags p_flag, WindowID p_window = MAIN_WINDOW_ID) const override;
  148. virtual void window_request_attention(WindowID p_window = MAIN_WINDOW_ID) override;
  149. virtual void window_move_to_foreground(WindowID p_window = MAIN_WINDOW_ID) override;
  150. virtual bool window_is_focused(WindowID p_window = MAIN_WINDOW_ID) const override;
  151. virtual float screen_get_max_scale() const override;
  152. virtual void screen_set_orientation(DisplayServer::ScreenOrientation p_orientation, int p_screen) override;
  153. virtual DisplayServer::ScreenOrientation screen_get_orientation(int p_screen) const override;
  154. virtual bool window_can_draw(WindowID p_window = MAIN_WINDOW_ID) const override;
  155. virtual bool can_any_window_draw() const override;
  156. virtual void window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window = MAIN_WINDOW_ID) override;
  157. virtual DisplayServer::VSyncMode window_get_vsync_mode(WindowID p_vsync_mode) const override;
  158. virtual bool is_touchscreen_available() const override;
  159. virtual void virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect, VirtualKeyboardType p_type, int p_max_length, int p_cursor_start, int p_cursor_end) override;
  160. virtual void virtual_keyboard_hide() override;
  161. void virtual_keyboard_set_height(int height);
  162. virtual int virtual_keyboard_get_height() const override;
  163. virtual bool has_hardware_keyboard() const override;
  164. virtual void clipboard_set(const String &p_text) override;
  165. virtual String clipboard_get() const override;
  166. virtual void screen_set_keep_on(bool p_enable) override;
  167. virtual bool screen_is_kept_on() const override;
  168. void resize_window(CGSize size);
  169. virtual void swap_buffers() override {}
  170. };
  171. #endif // DISPLAY_SERVER_IOS_H