| 1 | /**************************************************************************/ |
| 2 | /* display_server.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 | |
| 31 | #ifndef DISPLAY_SERVER_H |
| 32 | #define DISPLAY_SERVER_H |
| 33 | |
| 34 | #include "core/input/input.h" |
| 35 | #include "core/io/resource.h" |
| 36 | #include "core/os/os.h" |
| 37 | #include "core/variant/callable.h" |
| 38 | |
| 39 | class Texture2D; |
| 40 | |
| 41 | class DisplayServer : public Object { |
| 42 | GDCLASS(DisplayServer, Object) |
| 43 | |
| 44 | static DisplayServer *singleton; |
| 45 | static bool hidpi_allowed; |
| 46 | |
| 47 | public: |
| 48 | _FORCE_INLINE_ static DisplayServer *get_singleton() { |
| 49 | return singleton; |
| 50 | } |
| 51 | |
| 52 | enum WindowMode { |
| 53 | WINDOW_MODE_WINDOWED, |
| 54 | WINDOW_MODE_MINIMIZED, |
| 55 | WINDOW_MODE_MAXIMIZED, |
| 56 | WINDOW_MODE_FULLSCREEN, |
| 57 | WINDOW_MODE_EXCLUSIVE_FULLSCREEN, |
| 58 | }; |
| 59 | |
| 60 | // Keep the VSyncMode enum values in sync with the `display/window/vsync/vsync_mode` |
| 61 | // project setting hint. |
| 62 | enum VSyncMode { |
| 63 | VSYNC_DISABLED, |
| 64 | VSYNC_ENABLED, |
| 65 | VSYNC_ADAPTIVE, |
| 66 | VSYNC_MAILBOX |
| 67 | }; |
| 68 | |
| 69 | enum HandleType { |
| 70 | DISPLAY_HANDLE, |
| 71 | WINDOW_HANDLE, |
| 72 | WINDOW_VIEW, |
| 73 | OPENGL_CONTEXT, |
| 74 | }; |
| 75 | |
| 76 | typedef DisplayServer *(*CreateFunction)(const String &, WindowMode, VSyncMode, uint32_t, const Point2i *, const Size2i &, int p_screen, Error &r_error); |
| 77 | typedef Vector<String> (*GetRenderingDriversFunction)(); |
| 78 | |
| 79 | private: |
| 80 | static void _input_set_mouse_mode(Input::MouseMode p_mode); |
| 81 | static Input::MouseMode _input_get_mouse_mode(); |
| 82 | static void _input_warp(const Vector2 &p_to_pos); |
| 83 | static Input::CursorShape _input_get_current_cursor_shape(); |
| 84 | static void _input_set_custom_mouse_cursor_func(const Ref<Resource> &, Input::CursorShape, const Vector2 &p_hostspot); |
| 85 | |
| 86 | protected: |
| 87 | static void _bind_methods(); |
| 88 | |
| 89 | enum { |
| 90 | MAX_SERVERS = 64 |
| 91 | }; |
| 92 | |
| 93 | struct DisplayServerCreate { |
| 94 | const char *name; |
| 95 | CreateFunction create_function; |
| 96 | GetRenderingDriversFunction get_rendering_drivers_function; |
| 97 | }; |
| 98 | |
| 99 | static DisplayServerCreate server_create_functions[MAX_SERVERS]; |
| 100 | static int server_create_count; |
| 101 | |
| 102 | friend class RendererViewport; |
| 103 | |
| 104 | public: |
| 105 | enum Feature { |
| 106 | , |
| 107 | FEATURE_SUBWINDOWS, |
| 108 | FEATURE_TOUCHSCREEN, |
| 109 | FEATURE_MOUSE, |
| 110 | FEATURE_MOUSE_WARP, |
| 111 | FEATURE_CLIPBOARD, |
| 112 | FEATURE_VIRTUAL_KEYBOARD, |
| 113 | FEATURE_CURSOR_SHAPE, |
| 114 | FEATURE_CUSTOM_CURSOR_SHAPE, |
| 115 | FEATURE_NATIVE_DIALOG, |
| 116 | FEATURE_IME, |
| 117 | FEATURE_WINDOW_TRANSPARENCY, |
| 118 | FEATURE_HIDPI, |
| 119 | FEATURE_ICON, |
| 120 | FEATURE_NATIVE_ICON, |
| 121 | FEATURE_ORIENTATION, |
| 122 | FEATURE_SWAP_BUFFERS, |
| 123 | FEATURE_KEEP_SCREEN_ON, |
| 124 | FEATURE_CLIPBOARD_PRIMARY, |
| 125 | FEATURE_TEXT_TO_SPEECH, |
| 126 | FEATURE_EXTEND_TO_TITLE, |
| 127 | FEATURE_SCREEN_CAPTURE, |
| 128 | }; |
| 129 | |
| 130 | virtual bool has_feature(Feature p_feature) const = 0; |
| 131 | virtual String get_name() const = 0; |
| 132 | |
| 133 | virtual int (const String &, const String &p_label, const String &, int p_index = -1); |
| 134 | virtual int (const String &, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1); |
| 135 | virtual int (const String &, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1); |
| 136 | virtual int (const String &, const Ref<Texture2D> &p_icon, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1); |
| 137 | virtual int (const String &, const Ref<Texture2D> &p_icon, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1); |
| 138 | virtual int (const String &, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1); |
| 139 | virtual int (const String &, const Ref<Texture2D> &p_icon, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1); |
| 140 | virtual int (const String &, const String &p_label, int p_max_states, int p_default_state, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1); |
| 141 | virtual int (const String &, int p_index = -1); |
| 142 | |
| 143 | virtual int (const String &, const String &p_text) const; |
| 144 | virtual int (const String &, const Variant &p_tag) const; |
| 145 | |
| 146 | virtual bool (const String &, int p_idx) const; |
| 147 | virtual bool (const String &, int p_idx) const; |
| 148 | virtual bool (const String &, int p_idx) const; |
| 149 | virtual Callable (const String &, int p_idx) const; |
| 150 | virtual Callable (const String &, int p_idx) const; |
| 151 | virtual Variant (const String &, int p_idx) const; |
| 152 | virtual String (const String &, int p_idx) const; |
| 153 | virtual String (const String &, int p_idx) const; |
| 154 | virtual Key (const String &, int p_idx) const; |
| 155 | virtual bool (const String &, int p_idx) const; |
| 156 | virtual String (const String &, int p_idx) const; |
| 157 | virtual int (const String &, int p_idx) const; |
| 158 | virtual int (const String &, int p_idx) const; |
| 159 | virtual Ref<Texture2D> (const String &, int p_idx) const; |
| 160 | virtual int (const String &, int p_idx) const; |
| 161 | |
| 162 | virtual void (const String &, int p_idx, bool p_checked); |
| 163 | virtual void (const String &, int p_idx, bool p_checkable); |
| 164 | virtual void (const String &, int p_idx, bool p_checkable); |
| 165 | virtual void (const String &, int p_idx, const Callable &p_callback); |
| 166 | virtual void (const String &, int p_idx, const Callable &p_key_callback); |
| 167 | virtual void (const String &, int p_idx, const Variant &p_tag); |
| 168 | virtual void (const String &, int p_idx, const String &p_text); |
| 169 | virtual void (const String &, int p_idx, const String &); |
| 170 | virtual void (const String &, int p_idx, Key p_keycode); |
| 171 | virtual void (const String &, int p_idx, bool p_disabled); |
| 172 | virtual void (const String &, int p_idx, const String &p_tooltip); |
| 173 | virtual void (const String &, int p_idx, int p_state); |
| 174 | virtual void (const String &, int p_idx, int p_max_states); |
| 175 | virtual void (const String &, int p_idx, const Ref<Texture2D> &p_icon); |
| 176 | virtual void (const String &, int p_idx, int p_level); |
| 177 | |
| 178 | virtual int (const String &) const; |
| 179 | |
| 180 | virtual void (const String &, int p_idx); |
| 181 | virtual void (const String &); |
| 182 | |
| 183 | struct TTSUtterance { |
| 184 | String text; |
| 185 | String voice; |
| 186 | int volume = 50; |
| 187 | float pitch = 1.f; |
| 188 | float rate = 1.f; |
| 189 | int id = 0; |
| 190 | }; |
| 191 | |
| 192 | enum TTSUtteranceEvent { |
| 193 | TTS_UTTERANCE_STARTED, |
| 194 | TTS_UTTERANCE_ENDED, |
| 195 | TTS_UTTERANCE_CANCELED, |
| 196 | TTS_UTTERANCE_BOUNDARY, |
| 197 | TTS_UTTERANCE_MAX, |
| 198 | }; |
| 199 | |
| 200 | private: |
| 201 | Callable utterance_callback[TTS_UTTERANCE_MAX]; |
| 202 | |
| 203 | public: |
| 204 | virtual bool tts_is_speaking() const; |
| 205 | virtual bool tts_is_paused() const; |
| 206 | virtual TypedArray<Dictionary> tts_get_voices() const; |
| 207 | virtual PackedStringArray tts_get_voices_for_language(const String &p_language) const; |
| 208 | |
| 209 | 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); |
| 210 | virtual void tts_pause(); |
| 211 | virtual void tts_resume(); |
| 212 | virtual void tts_stop(); |
| 213 | |
| 214 | virtual void tts_set_utterance_callback(TTSUtteranceEvent p_event, const Callable &p_callable); |
| 215 | virtual void tts_post_utterance_event(TTSUtteranceEvent p_event, int p_id, int p_pos = 0); |
| 216 | |
| 217 | virtual bool is_dark_mode_supported() const { return false; }; |
| 218 | virtual bool is_dark_mode() const { return false; }; |
| 219 | virtual Color get_accent_color() const { return Color(0, 0, 0, 0); }; |
| 220 | |
| 221 | private: |
| 222 | static bool window_early_clear_override_enabled; |
| 223 | static Color window_early_clear_override_color; |
| 224 | |
| 225 | protected: |
| 226 | static bool _get_window_early_clear_override(Color &r_color); |
| 227 | |
| 228 | public: |
| 229 | static void set_early_window_clear_color_override(bool p_enabled, Color p_color = Color(0, 0, 0, 0)); |
| 230 | |
| 231 | enum MouseMode { |
| 232 | MOUSE_MODE_VISIBLE, |
| 233 | MOUSE_MODE_HIDDEN, |
| 234 | MOUSE_MODE_CAPTURED, |
| 235 | MOUSE_MODE_CONFINED, |
| 236 | MOUSE_MODE_CONFINED_HIDDEN, |
| 237 | }; |
| 238 | |
| 239 | virtual void mouse_set_mode(MouseMode p_mode); |
| 240 | virtual MouseMode mouse_get_mode() const; |
| 241 | |
| 242 | virtual void warp_mouse(const Point2i &p_position); |
| 243 | virtual Point2i mouse_get_position() const; |
| 244 | virtual BitField<MouseButtonMask> mouse_get_button_state() const; |
| 245 | |
| 246 | virtual void clipboard_set(const String &p_text); |
| 247 | virtual String clipboard_get() const; |
| 248 | virtual Ref<Image> clipboard_get_image() const; |
| 249 | virtual bool clipboard_has() const; |
| 250 | virtual bool clipboard_has_image() const; |
| 251 | virtual void clipboard_set_primary(const String &p_text); |
| 252 | virtual String clipboard_get_primary() const; |
| 253 | |
| 254 | virtual TypedArray<Rect2> get_display_cutouts() const { return TypedArray<Rect2>(); } |
| 255 | virtual Rect2i get_display_safe_area() const { return screen_get_usable_rect(); } |
| 256 | |
| 257 | enum { |
| 258 | SCREEN_WITH_MOUSE_FOCUS = -4, |
| 259 | SCREEN_WITH_KEYBOARD_FOCUS = -3, |
| 260 | SCREEN_PRIMARY = -2, |
| 261 | SCREEN_OF_MAIN_WINDOW = -1, // Note: for the main window, determine screen from position. |
| 262 | }; |
| 263 | |
| 264 | const float SCREEN_REFRESH_RATE_FALLBACK = -1.0; // Returned by screen_get_refresh_rate if the method fails. |
| 265 | |
| 266 | int _get_screen_index(int p_screen) const { |
| 267 | switch (p_screen) { |
| 268 | case SCREEN_WITH_MOUSE_FOCUS: { |
| 269 | const Rect2i rect = Rect2i(mouse_get_position(), Vector2i(1, 1)); |
| 270 | return get_screen_from_rect(rect); |
| 271 | } break; |
| 272 | case SCREEN_WITH_KEYBOARD_FOCUS: { |
| 273 | return get_keyboard_focus_screen(); |
| 274 | } break; |
| 275 | case SCREEN_PRIMARY: { |
| 276 | return get_primary_screen(); |
| 277 | } break; |
| 278 | case SCREEN_OF_MAIN_WINDOW: { |
| 279 | return window_get_current_screen(MAIN_WINDOW_ID); |
| 280 | } break; |
| 281 | default: { |
| 282 | return p_screen; |
| 283 | } break; |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | virtual int get_screen_count() const = 0; |
| 288 | virtual int get_primary_screen() const = 0; |
| 289 | virtual int get_keyboard_focus_screen() const { return get_primary_screen(); } |
| 290 | virtual int get_screen_from_rect(const Rect2 &p_rect) const; |
| 291 | virtual Point2i screen_get_position(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0; |
| 292 | virtual Size2i screen_get_size(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0; |
| 293 | virtual Rect2i screen_get_usable_rect(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0; |
| 294 | virtual int screen_get_dpi(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0; |
| 295 | virtual float screen_get_scale(int p_screen = SCREEN_OF_MAIN_WINDOW) const; |
| 296 | virtual float screen_get_max_scale() const { |
| 297 | float scale = 1.f; |
| 298 | int screen_count = get_screen_count(); |
| 299 | for (int i = 0; i < screen_count; i++) { |
| 300 | scale = fmax(scale, screen_get_scale(i)); |
| 301 | } |
| 302 | return scale; |
| 303 | } |
| 304 | virtual float screen_get_refresh_rate(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0; |
| 305 | virtual Color screen_get_pixel(const Point2i &p_position) const { return Color(); }; |
| 306 | virtual Ref<Image> screen_get_image(int p_screen = SCREEN_OF_MAIN_WINDOW) const { return Ref<Image>(); }; |
| 307 | virtual bool is_touchscreen_available() const; |
| 308 | |
| 309 | // Keep the ScreenOrientation enum values in sync with the `display/window/handheld/orientation` |
| 310 | // project setting hint. |
| 311 | enum ScreenOrientation { |
| 312 | SCREEN_LANDSCAPE, |
| 313 | SCREEN_PORTRAIT, |
| 314 | SCREEN_REVERSE_LANDSCAPE, |
| 315 | SCREEN_REVERSE_PORTRAIT, |
| 316 | SCREEN_SENSOR_LANDSCAPE, |
| 317 | SCREEN_SENSOR_PORTRAIT, |
| 318 | SCREEN_SENSOR, |
| 319 | }; |
| 320 | |
| 321 | virtual void screen_set_orientation(ScreenOrientation p_orientation, int p_screen = SCREEN_OF_MAIN_WINDOW); |
| 322 | virtual ScreenOrientation screen_get_orientation(int p_screen = SCREEN_OF_MAIN_WINDOW) const; |
| 323 | |
| 324 | virtual void screen_set_keep_on(bool p_enable); //disable screensaver |
| 325 | virtual bool screen_is_kept_on() const; |
| 326 | enum { |
| 327 | MAIN_WINDOW_ID = 0, |
| 328 | INVALID_WINDOW_ID = -1 |
| 329 | }; |
| 330 | |
| 331 | typedef int WindowID; |
| 332 | |
| 333 | virtual Vector<DisplayServer::WindowID> get_window_list() const = 0; |
| 334 | |
| 335 | enum WindowFlags { |
| 336 | WINDOW_FLAG_RESIZE_DISABLED, |
| 337 | WINDOW_FLAG_BORDERLESS, |
| 338 | WINDOW_FLAG_ALWAYS_ON_TOP, |
| 339 | WINDOW_FLAG_TRANSPARENT, |
| 340 | WINDOW_FLAG_NO_FOCUS, |
| 341 | , |
| 342 | WINDOW_FLAG_EXTEND_TO_TITLE, |
| 343 | WINDOW_FLAG_MOUSE_PASSTHROUGH, |
| 344 | WINDOW_FLAG_MAX, |
| 345 | }; |
| 346 | |
| 347 | // Separate enum otherwise we get warnings in switches not handling all values. |
| 348 | enum WindowFlagsBit { |
| 349 | WINDOW_FLAG_RESIZE_DISABLED_BIT = (1 << WINDOW_FLAG_RESIZE_DISABLED), |
| 350 | WINDOW_FLAG_BORDERLESS_BIT = (1 << WINDOW_FLAG_BORDERLESS), |
| 351 | WINDOW_FLAG_ALWAYS_ON_TOP_BIT = (1 << WINDOW_FLAG_ALWAYS_ON_TOP), |
| 352 | WINDOW_FLAG_TRANSPARENT_BIT = (1 << WINDOW_FLAG_TRANSPARENT), |
| 353 | WINDOW_FLAG_NO_FOCUS_BIT = (1 << WINDOW_FLAG_NO_FOCUS), |
| 354 | = (1 << WINDOW_FLAG_POPUP), |
| 355 | WINDOW_FLAG_EXTEND_TO_TITLE_BIT = (1 << WINDOW_FLAG_EXTEND_TO_TITLE), |
| 356 | WINDOW_FLAG_MOUSE_PASSTHROUGH_BIT = (1 << WINDOW_FLAG_MOUSE_PASSTHROUGH), |
| 357 | }; |
| 358 | |
| 359 | virtual WindowID create_sub_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect = Rect2i()); |
| 360 | virtual void show_window(WindowID p_id); |
| 361 | virtual void delete_sub_window(WindowID p_id); |
| 362 | |
| 363 | virtual WindowID () const { return INVALID_WINDOW_ID; }; |
| 364 | virtual void (WindowID p_window, const Rect2i &p_rect){}; |
| 365 | virtual Rect2i (WindowID p_window) const { return Rect2i(); }; |
| 366 | |
| 367 | virtual int64_t window_get_native_handle(HandleType p_handle_type, WindowID p_window = MAIN_WINDOW_ID) const; |
| 368 | |
| 369 | virtual WindowID get_window_at_screen_position(const Point2i &p_position) const = 0; |
| 370 | |
| 371 | virtual void window_attach_instance_id(ObjectID p_instance, WindowID p_window = MAIN_WINDOW_ID) = 0; |
| 372 | virtual ObjectID window_get_attached_instance_id(WindowID p_window = MAIN_WINDOW_ID) const = 0; |
| 373 | |
| 374 | virtual void window_set_rect_changed_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) = 0; |
| 375 | |
| 376 | enum WindowEvent { |
| 377 | WINDOW_EVENT_MOUSE_ENTER, |
| 378 | WINDOW_EVENT_MOUSE_EXIT, |
| 379 | WINDOW_EVENT_FOCUS_IN, |
| 380 | WINDOW_EVENT_FOCUS_OUT, |
| 381 | WINDOW_EVENT_CLOSE_REQUEST, |
| 382 | WINDOW_EVENT_GO_BACK_REQUEST, |
| 383 | WINDOW_EVENT_DPI_CHANGE, |
| 384 | WINDOW_EVENT_TITLEBAR_CHANGE, |
| 385 | }; |
| 386 | virtual void window_set_window_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) = 0; |
| 387 | virtual void window_set_input_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) = 0; |
| 388 | virtual void window_set_input_text_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) = 0; |
| 389 | |
| 390 | virtual void window_set_drop_files_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) = 0; |
| 391 | |
| 392 | virtual void window_set_title(const String &p_title, WindowID p_window = MAIN_WINDOW_ID) = 0; |
| 393 | |
| 394 | virtual void window_set_mouse_passthrough(const Vector<Vector2> &p_region, WindowID p_window = MAIN_WINDOW_ID); |
| 395 | |
| 396 | virtual int window_get_current_screen(WindowID p_window = MAIN_WINDOW_ID) const = 0; |
| 397 | virtual void window_set_current_screen(int p_screen, WindowID p_window = MAIN_WINDOW_ID) = 0; |
| 398 | |
| 399 | virtual Point2i window_get_position(WindowID p_window = MAIN_WINDOW_ID) const = 0; |
| 400 | virtual Point2i window_get_position_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const = 0; |
| 401 | virtual void window_set_position(const Point2i &p_position, WindowID p_window = MAIN_WINDOW_ID) = 0; |
| 402 | |
| 403 | virtual void window_set_transient(WindowID p_window, WindowID p_parent) = 0; |
| 404 | virtual void window_set_exclusive(WindowID p_window, bool p_exclusive); |
| 405 | |
| 406 | virtual void window_set_max_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) = 0; |
| 407 | virtual Size2i window_get_max_size(WindowID p_window = MAIN_WINDOW_ID) const = 0; |
| 408 | |
| 409 | virtual void window_set_min_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) = 0; |
| 410 | virtual Size2i window_get_min_size(WindowID p_window = MAIN_WINDOW_ID) const = 0; |
| 411 | |
| 412 | virtual void window_set_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) = 0; |
| 413 | virtual Size2i window_get_size(WindowID p_window = MAIN_WINDOW_ID) const = 0; |
| 414 | virtual Size2i window_get_size_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const = 0; |
| 415 | |
| 416 | virtual void window_set_mode(WindowMode p_mode, WindowID p_window = MAIN_WINDOW_ID) = 0; |
| 417 | virtual WindowMode window_get_mode(WindowID p_window = MAIN_WINDOW_ID) const = 0; |
| 418 | |
| 419 | virtual void window_set_vsync_mode(VSyncMode p_vsync_mode, WindowID p_window = MAIN_WINDOW_ID); |
| 420 | virtual VSyncMode window_get_vsync_mode(WindowID p_window) const; |
| 421 | |
| 422 | virtual bool window_is_maximize_allowed(WindowID p_window = MAIN_WINDOW_ID) const = 0; |
| 423 | |
| 424 | virtual void window_set_flag(WindowFlags p_flag, bool p_enabled, WindowID p_window = MAIN_WINDOW_ID) = 0; |
| 425 | virtual bool window_get_flag(WindowFlags p_flag, WindowID p_window = MAIN_WINDOW_ID) const = 0; |
| 426 | |
| 427 | virtual void window_request_attention(WindowID p_window = MAIN_WINDOW_ID) = 0; |
| 428 | virtual void window_move_to_foreground(WindowID p_window = MAIN_WINDOW_ID) = 0; |
| 429 | virtual bool window_is_focused(WindowID p_window = MAIN_WINDOW_ID) const = 0; |
| 430 | |
| 431 | virtual void window_set_window_buttons_offset(const Vector2i &p_offset, WindowID p_window = MAIN_WINDOW_ID) {} |
| 432 | virtual Vector3i window_get_safe_title_margins(WindowID p_window = MAIN_WINDOW_ID) const { return Vector3i(); } |
| 433 | |
| 434 | virtual bool window_can_draw(WindowID p_window = MAIN_WINDOW_ID) const = 0; |
| 435 | |
| 436 | virtual bool can_any_window_draw() const = 0; |
| 437 | |
| 438 | virtual void window_set_ime_active(const bool p_active, WindowID p_window = MAIN_WINDOW_ID); |
| 439 | virtual void window_set_ime_position(const Point2i &p_pos, WindowID p_window = MAIN_WINDOW_ID); |
| 440 | |
| 441 | virtual bool window_maximize_on_title_dbl_click() const { return false; } |
| 442 | virtual bool window_minimize_on_title_dbl_click() const { return false; } |
| 443 | |
| 444 | // necessary for GL focus, may be able to use one of the existing functions for this, not sure yet |
| 445 | virtual void gl_window_make_current(DisplayServer::WindowID p_window_id); |
| 446 | |
| 447 | virtual Point2i ime_get_selection() const; |
| 448 | virtual String ime_get_text() const; |
| 449 | |
| 450 | enum VirtualKeyboardType { |
| 451 | KEYBOARD_TYPE_DEFAULT, |
| 452 | KEYBOARD_TYPE_MULTILINE, |
| 453 | KEYBOARD_TYPE_NUMBER, |
| 454 | KEYBOARD_TYPE_NUMBER_DECIMAL, |
| 455 | KEYBOARD_TYPE_PHONE, |
| 456 | KEYBOARD_TYPE_EMAIL_ADDRESS, |
| 457 | KEYBOARD_TYPE_PASSWORD, |
| 458 | KEYBOARD_TYPE_URL |
| 459 | }; |
| 460 | |
| 461 | 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); |
| 462 | virtual void virtual_keyboard_hide(); |
| 463 | |
| 464 | // returns height of the currently shown virtual keyboard (0 if keyboard is hidden) |
| 465 | virtual int virtual_keyboard_get_height() const; |
| 466 | |
| 467 | enum CursorShape { |
| 468 | CURSOR_ARROW, |
| 469 | CURSOR_IBEAM, |
| 470 | CURSOR_POINTING_HAND, |
| 471 | CURSOR_CROSS, |
| 472 | CURSOR_WAIT, |
| 473 | CURSOR_BUSY, |
| 474 | CURSOR_DRAG, |
| 475 | CURSOR_CAN_DROP, |
| 476 | CURSOR_FORBIDDEN, |
| 477 | CURSOR_VSIZE, |
| 478 | CURSOR_HSIZE, |
| 479 | CURSOR_BDIAGSIZE, |
| 480 | CURSOR_FDIAGSIZE, |
| 481 | CURSOR_MOVE, |
| 482 | CURSOR_VSPLIT, |
| 483 | CURSOR_HSPLIT, |
| 484 | CURSOR_HELP, |
| 485 | CURSOR_MAX |
| 486 | }; |
| 487 | virtual void cursor_set_shape(CursorShape p_shape); |
| 488 | virtual CursorShape cursor_get_shape() const; |
| 489 | virtual void cursor_set_custom_image(const Ref<Resource> &p_cursor, CursorShape p_shape = CURSOR_ARROW, const Vector2 &p_hotspot = Vector2()); |
| 490 | |
| 491 | virtual bool get_swap_cancel_ok(); |
| 492 | |
| 493 | virtual void enable_for_stealing_focus(OS::ProcessID pid); |
| 494 | |
| 495 | virtual Error dialog_show(String p_title, String p_description, Vector<String> p_buttons, const Callable &p_callback); |
| 496 | virtual Error dialog_input_text(String p_title, String p_description, String p_partial, const Callable &p_callback); |
| 497 | |
| 498 | enum FileDialogMode { |
| 499 | FILE_DIALOG_MODE_OPEN_FILE, |
| 500 | FILE_DIALOG_MODE_OPEN_FILES, |
| 501 | FILE_DIALOG_MODE_OPEN_DIR, |
| 502 | FILE_DIALOG_MODE_OPEN_ANY, |
| 503 | FILE_DIALOG_MODE_SAVE_FILE |
| 504 | }; |
| 505 | virtual Error file_dialog_show(const String &p_title, const String &p_current_directory, const String &p_filename, bool p_show_hidden, FileDialogMode p_mode, const Vector<String> &p_filters, const Callable &p_callback); |
| 506 | |
| 507 | virtual int keyboard_get_layout_count() const; |
| 508 | virtual int keyboard_get_current_layout() const; |
| 509 | virtual void keyboard_set_current_layout(int p_index); |
| 510 | virtual String keyboard_get_layout_language(int p_index) const; |
| 511 | virtual String keyboard_get_layout_name(int p_index) const; |
| 512 | virtual Key keyboard_get_keycode_from_physical(Key p_keycode) const; |
| 513 | virtual Key keyboard_get_label_from_physical(Key p_keycode) const; |
| 514 | |
| 515 | virtual int tablet_get_driver_count() const { return 1; }; |
| 516 | virtual String tablet_get_driver_name(int p_driver) const { return "default" ; }; |
| 517 | virtual String tablet_get_current_driver() const { return "default" ; }; |
| 518 | virtual void tablet_set_current_driver(const String &p_driver){}; |
| 519 | |
| 520 | virtual void process_events() = 0; |
| 521 | |
| 522 | virtual void force_process_and_drop_events(); |
| 523 | |
| 524 | virtual void release_rendering_thread(); |
| 525 | virtual void make_rendering_thread(); |
| 526 | virtual void swap_buffers(); |
| 527 | |
| 528 | virtual void set_native_icon(const String &p_filename); |
| 529 | virtual void set_icon(const Ref<Image> &p_icon); |
| 530 | |
| 531 | enum Context { |
| 532 | CONTEXT_EDITOR, |
| 533 | CONTEXT_PROJECTMAN, |
| 534 | CONTEXT_ENGINE, |
| 535 | }; |
| 536 | |
| 537 | virtual void set_context(Context p_context); |
| 538 | |
| 539 | static void register_create_function(const char *p_name, CreateFunction p_function, GetRenderingDriversFunction p_get_drivers); |
| 540 | static int get_create_function_count(); |
| 541 | static const char *get_create_function_name(int p_index); |
| 542 | static Vector<String> get_create_function_rendering_drivers(int p_index); |
| 543 | static DisplayServer *create(int p_index, const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Error &r_error); |
| 544 | |
| 545 | DisplayServer(); |
| 546 | ~DisplayServer(); |
| 547 | }; |
| 548 | |
| 549 | VARIANT_ENUM_CAST(DisplayServer::WindowEvent) |
| 550 | VARIANT_ENUM_CAST(DisplayServer::Feature) |
| 551 | VARIANT_ENUM_CAST(DisplayServer::MouseMode) |
| 552 | VARIANT_ENUM_CAST(DisplayServer::ScreenOrientation) |
| 553 | VARIANT_ENUM_CAST(DisplayServer::WindowMode) |
| 554 | VARIANT_ENUM_CAST(DisplayServer::WindowFlags) |
| 555 | VARIANT_ENUM_CAST(DisplayServer::HandleType) |
| 556 | VARIANT_ENUM_CAST(DisplayServer::VirtualKeyboardType); |
| 557 | VARIANT_ENUM_CAST(DisplayServer::CursorShape) |
| 558 | VARIANT_ENUM_CAST(DisplayServer::VSyncMode) |
| 559 | VARIANT_ENUM_CAST(DisplayServer::TTSUtteranceEvent) |
| 560 | VARIANT_ENUM_CAST(DisplayServer::FileDialogMode) |
| 561 | |
| 562 | #endif // DISPLAY_SERVER_H |
| 563 | |