diff options
Diffstat (limited to 'servers/display_server.cpp')
-rw-r--r-- | servers/display_server.cpp | 52 |
1 files changed, 47 insertions, 5 deletions
diff --git a/servers/display_server.cpp b/servers/display_server.cpp index 734b4d0f1f..39f14439f4 100644 --- a/servers/display_server.cpp +++ b/servers/display_server.cpp @@ -38,6 +38,9 @@ DisplayServer *DisplayServer::singleton = nullptr; bool DisplayServer::hidpi_allowed = false; +bool DisplayServer::window_early_clear_override_enabled = false; +Color DisplayServer::window_early_clear_override_color = Color(0, 0, 0, 0); + DisplayServer::DisplayServerCreate DisplayServer::server_create_functions[DisplayServer::MAX_SERVERS] = { { "headless", &DisplayServerHeadless::create_func, &DisplayServerHeadless::get_rendering_drivers_func } }; @@ -315,6 +318,23 @@ void DisplayServer::tts_post_utterance_event(TTSUtteranceEvent p_event, int p_id } } +bool DisplayServer::_get_window_early_clear_override(Color &r_color) { + if (window_early_clear_override_enabled) { + r_color = window_early_clear_override_color; + return true; + } else if (RenderingServer::get_singleton()) { + r_color = RenderingServer::get_singleton()->get_default_clear_color(); + return true; + } else { + return false; + } +} + +void DisplayServer::set_early_window_clear_color_override(bool p_enabled, Color p_color) { + window_early_clear_override_enabled = p_enabled; + window_early_clear_override_color = p_color; +} + void DisplayServer::mouse_set_mode(MouseMode p_mode) { WARN_PRINT("Mouse is not supported by this display server."); } @@ -331,8 +351,8 @@ Point2i DisplayServer::mouse_get_position() const { ERR_FAIL_V_MSG(Point2i(), "Mouse is not supported by this display server."); } -MouseButton DisplayServer::mouse_get_button_state() const { - ERR_FAIL_V_MSG(MouseButton::NONE, "Mouse is not supported by this display server."); +BitField<MouseButtonMask> DisplayServer::mouse_get_button_state() const { + ERR_FAIL_V_MSG(0, "Mouse is not supported by this display server."); } void DisplayServer::clipboard_set(const String &p_text) { @@ -379,7 +399,24 @@ bool DisplayServer::screen_is_kept_on() const { return false; } -DisplayServer::WindowID DisplayServer::create_sub_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect, int p_screen) { +int DisplayServer::get_screen_from_rect(const Rect2 &p_rect) const { + int nearest_area = 0; + int pos_screen = -1; + for (int i = 0; i < get_screen_count(); i++) { + Rect2i r; + r.position = screen_get_position(i); + r.size = screen_get_size(i); + Rect2 inters = r.intersection(p_rect); + int area = inters.size.width * inters.size.height; + if (area > nearest_area) { + pos_screen = i; + nearest_area = area; + } + } + return pos_screen; +} + +DisplayServer::WindowID DisplayServer::create_sub_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect) { ERR_FAIL_V_MSG(INVALID_WINDOW_ID, "Sub-windows not supported by this display server."); } @@ -612,6 +649,8 @@ void DisplayServer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_display_safe_area"), &DisplayServer::get_display_safe_area); ClassDB::bind_method(D_METHOD("get_screen_count"), &DisplayServer::get_screen_count); + ClassDB::bind_method(D_METHOD("get_primary_screen"), &DisplayServer::get_primary_screen); + ClassDB::bind_method(D_METHOD("get_screen_from_rect", "rect"), &DisplayServer::get_screen_from_rect); ClassDB::bind_method(D_METHOD("screen_get_position", "screen"), &DisplayServer::screen_get_position, DEFVAL(SCREEN_OF_MAIN_WINDOW)); ClassDB::bind_method(D_METHOD("screen_get_size", "screen"), &DisplayServer::screen_get_size, DEFVAL(SCREEN_OF_MAIN_WINDOW)); ClassDB::bind_method(D_METHOD("screen_get_usable_rect", "screen"), &DisplayServer::screen_get_usable_rect, DEFVAL(SCREEN_OF_MAIN_WINDOW)); @@ -754,7 +793,9 @@ void DisplayServer::_bind_methods() { BIND_ENUM_CONSTANT(MOUSE_MODE_CONFINED); BIND_ENUM_CONSTANT(MOUSE_MODE_CONFINED_HIDDEN); + BIND_CONSTANT(SCREEN_PRIMARY); BIND_CONSTANT(SCREEN_OF_MAIN_WINDOW); + BIND_CONSTANT(MAIN_WINDOW_ID); BIND_CONSTANT(INVALID_WINDOW_ID); @@ -807,6 +848,7 @@ void DisplayServer::_bind_methods() { BIND_ENUM_CONSTANT(WINDOW_FLAG_NO_FOCUS); BIND_ENUM_CONSTANT(WINDOW_FLAG_POPUP); BIND_ENUM_CONSTANT(WINDOW_FLAG_EXTEND_TO_TITLE); + BIND_ENUM_CONSTANT(WINDOW_FLAG_MOUSE_PASSTHROUGH); BIND_ENUM_CONSTANT(WINDOW_FLAG_MAX); BIND_ENUM_CONSTANT(WINDOW_EVENT_MOUSE_ENTER); @@ -858,9 +900,9 @@ Vector<String> DisplayServer::get_create_function_rendering_drivers(int p_index) return server_create_functions[p_index].get_rendering_drivers_function(); } -DisplayServer *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, Error &r_error) { +DisplayServer *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) { ERR_FAIL_INDEX_V(p_index, server_create_count, nullptr); - return server_create_functions[p_index].create_function(p_rendering_driver, p_mode, p_vsync_mode, p_flags, p_position, p_resolution, r_error); + return server_create_functions[p_index].create_function(p_rendering_driver, p_mode, p_vsync_mode, p_flags, p_position, p_resolution, p_screen, r_error); } void DisplayServer::_input_set_mouse_mode(Input::MouseMode p_mode) { |