summaryrefslogtreecommitdiff
path: root/scene/main
diff options
context:
space:
mode:
Diffstat (limited to 'scene/main')
-rw-r--r--scene/main/canvas_item.cpp6
-rw-r--r--scene/main/viewport.cpp22
-rw-r--r--scene/main/window.cpp35
-rw-r--r--scene/main/window.h2
4 files changed, 41 insertions, 24 deletions
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp
index e5dcdd2afd..b36353158b 100644
--- a/scene/main/canvas_item.cpp
+++ b/scene/main/canvas_item.cpp
@@ -513,14 +513,16 @@ bool CanvasItem::is_y_sort_enabled() const {
void CanvasItem::draw_dashed_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, real_t p_width, real_t p_dash, bool p_aligned) {
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
+ ERR_FAIL_COND(p_dash <= 0.0);
float length = (p_to - p_from).length();
- if (length < p_dash) {
+ Vector2 step = p_dash * (p_to - p_from).normalized();
+
+ if (length < p_dash || step == Vector2()) {
RenderingServer::get_singleton()->canvas_item_add_line(canvas_item, p_from, p_to, p_color, p_width);
return;
}
- Vector2 step = p_dash * (p_to - p_from).normalized();
int steps = (p_aligned) ? Math::ceil(length / p_dash) : Math::floor(length / p_dash);
if (steps % 2 == 0) {
steps--;
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 23b7c072be..244e0d5b93 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -166,6 +166,24 @@ ViewportTexture::~ViewportTexture() {
}
void Viewport::_sub_window_update_order() {
+ if (gui.sub_windows.size() < 2) {
+ return;
+ }
+
+ if (!gui.sub_windows[gui.sub_windows.size() - 1].window->get_flag(Window::FLAG_ALWAYS_ON_TOP)) {
+ int index = gui.sub_windows.size() - 1;
+
+ while (index > 0 && gui.sub_windows[index - 1].window->get_flag(Window::FLAG_ALWAYS_ON_TOP)) {
+ --index;
+ }
+
+ if (index != (gui.sub_windows.size() - 1)) {
+ SubWindow sw = gui.sub_windows[gui.sub_windows.size() - 1];
+ gui.sub_windows.remove_at(gui.sub_windows.size() - 1);
+ gui.sub_windows.insert(index, sw);
+ }
+ }
+
for (int i = 0; i < gui.sub_windows.size(); i++) {
RS::get_singleton()->canvas_item_set_draw_index(gui.sub_windows[i].canvas_item, i);
}
@@ -1312,7 +1330,7 @@ void Viewport::_gui_show_tooltip() {
Window *window = gui.tooltip_popup->get_parent_visible_window();
Rect2i vr;
if (gui.tooltip_popup->is_embedded()) {
- vr = gui.tooltip_popup->_get_embedder()->get_visible_rect();
+ vr = gui.tooltip_popup->get_embedder()->get_visible_rect();
} else {
vr = window->get_usable_parent_rect();
}
@@ -1833,7 +1851,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
Window *w = Object::cast_to<Window>(this);
if (w) {
if (w->is_embedded()) {
- embedder = w->_get_embedder();
+ embedder = w->get_embedder();
viewport_pos = get_final_transform().xform(mpos) + w->get_position(); // To parent coords.
}
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 9092be93e6..59e3d307c6 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -485,7 +485,7 @@ void Window::set_ime_position(const Point2i &p_pos) {
bool Window::is_embedded() const {
ERR_FAIL_COND_V(!is_inside_tree(), false);
- return _get_embedder() != nullptr;
+ return get_embedder() != nullptr;
}
bool Window::is_in_edited_scene_root() const {
@@ -710,7 +710,7 @@ void Window::set_visible(bool p_visible) {
// Stop any queued resizing, as the window will be resized right now.
updating_child_controls = false;
- Viewport *embedder_vp = _get_embedder();
+ Viewport *embedder_vp = get_embedder();
if (!embedder_vp) {
if (!p_visible && window_id != DisplayServer::INVALID_WINDOW_ID) {
@@ -984,17 +984,13 @@ void Window::_update_viewport_size() {
Size2 margin;
Size2 offset;
- //black bars and margin
+
if (content_scale_aspect != CONTENT_SCALE_ASPECT_EXPAND && screen_size.x < video_mode.x) {
margin.x = Math::round((video_mode.x - screen_size.x) / 2.0);
- //RenderingServer::get_singleton()->black_bars_set_margins(margin.x, 0, margin.x, 0);
offset.x = Math::round(margin.x * viewport_size.y / screen_size.y);
} else if (content_scale_aspect != CONTENT_SCALE_ASPECT_EXPAND && screen_size.y < video_mode.y) {
margin.y = Math::round((video_mode.y - screen_size.y) / 2.0);
- //RenderingServer::get_singleton()->black_bars_set_margins(0, margin.y, 0, margin.y);
offset.y = Math::round(margin.y * viewport_size.x / screen_size.x);
- } else {
- //RenderingServer::get_singleton()->black_bars_set_margins(0, 0, 0, 0);
}
switch (content_scale_mode) {
@@ -1057,7 +1053,7 @@ void Window::_update_window_callbacks() {
DisplayServer::get_singleton()->window_set_drop_files_callback(callable_mp(this, &Window::_window_drop_files), window_id);
}
-Viewport *Window::_get_embedder() const {
+Viewport *Window::get_embedder() const {
Viewport *vp = get_parent_viewport();
while (vp) {
@@ -1092,7 +1088,7 @@ void Window::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
bool embedded = false;
{
- embedder = _get_embedder();
+ embedder = get_embedder();
if (embedder) {
embedded = true;
if (!visible) {
@@ -1121,6 +1117,7 @@ void Window::_notification(int p_what) {
position = DisplayServer::get_singleton()->window_get_position(window_id);
size = DisplayServer::get_singleton()->window_get_size(window_id);
}
+ _update_window_size(); // Inform DisplayServer of minimum and maximum size.
_update_viewport_size(); // Then feed back to the viewport.
_update_window_callbacks();
RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_VISIBLE);
@@ -1434,7 +1431,7 @@ void Window::popup_centered_clamped(const Size2i &p_size, float p_fallback_ratio
Rect2 parent_rect;
if (is_embedded()) {
- parent_rect = _get_embedder()->get_visible_rect();
+ parent_rect = get_embedder()->get_visible_rect();
} else {
DisplayServer::WindowID parent_id = get_parent_visible_window()->get_window_id();
int parent_screen = DisplayServer::get_singleton()->window_get_current_screen(parent_id);
@@ -1465,7 +1462,7 @@ void Window::popup_centered(const Size2i &p_minsize) {
Rect2 parent_rect;
if (is_embedded()) {
- parent_rect = _get_embedder()->get_visible_rect();
+ parent_rect = get_embedder()->get_visible_rect();
} else {
DisplayServer::WindowID parent_id = get_parent_visible_window()->get_window_id();
int parent_screen = DisplayServer::get_singleton()->window_get_current_screen(parent_id);
@@ -1491,7 +1488,7 @@ void Window::popup_centered_ratio(float p_ratio) {
Rect2 parent_rect;
if (is_embedded()) {
- parent_rect = _get_embedder()->get_visible_rect();
+ parent_rect = get_embedder()->get_visible_rect();
} else {
DisplayServer::WindowID parent_id = get_parent_visible_window()->get_window_id();
int parent_screen = DisplayServer::get_singleton()->window_get_current_screen(parent_id);
@@ -1512,7 +1509,7 @@ void Window::popup_centered_ratio(float p_ratio) {
void Window::popup(const Rect2i &p_screen_rect) {
emit_signal(SNAME("about_to_popup"));
- if (!_get_embedder() && get_flag(FLAG_POPUP)) {
+ if (!get_embedder() && get_flag(FLAG_POPUP)) {
// Send a focus-out notification when opening a Window Manager Popup.
SceneTree *scene_tree = get_tree();
if (scene_tree) {
@@ -1548,7 +1545,7 @@ void Window::popup(const Rect2i &p_screen_rect) {
Rect2i parent_rect;
if (is_embedded()) {
- parent_rect = _get_embedder()->get_visible_rect();
+ parent_rect = get_embedder()->get_visible_rect();
} else {
int screen_id = DisplayServer::get_singleton()->window_get_current_screen(get_window_id());
parent_rect = DisplayServer::get_singleton()->screen_get_usable_rect(screen_id);
@@ -1590,7 +1587,7 @@ Rect2i Window::get_usable_parent_rect() const {
ERR_FAIL_COND_V(!is_inside_tree(), Rect2());
Rect2i parent_rect;
if (is_embedded()) {
- parent_rect = _get_embedder()->get_visible_rect();
+ parent_rect = get_embedder()->get_visible_rect();
} else {
const Window *w = is_visible() ? this : get_parent_visible_window();
//find a parent that can contain us
@@ -2157,9 +2154,9 @@ Transform2D Window::get_final_transform() const {
Transform2D Window::get_screen_transform_internal(bool p_absolute_position) const {
Transform2D embedder_transform;
- if (_get_embedder()) {
+ if (get_embedder()) {
embedder_transform.translate_local(get_position());
- embedder_transform = _get_embedder()->get_screen_transform_internal(p_absolute_position) * embedder_transform;
+ embedder_transform = get_embedder()->get_screen_transform_internal(p_absolute_position) * embedder_transform;
} else if (p_absolute_position) {
embedder_transform.translate_local(get_position());
}
@@ -2173,8 +2170,8 @@ Transform2D Window::get_popup_base_transform() const {
Transform2D popup_base_transform;
popup_base_transform.set_origin(get_position());
popup_base_transform *= get_final_transform();
- if (_get_embedder()) {
- return _get_embedder()->get_popup_base_transform() * popup_base_transform;
+ if (get_embedder()) {
+ return get_embedder()->get_popup_base_transform() * popup_base_transform;
}
return popup_base_transform;
}
diff --git a/scene/main/window.h b/scene/main/window.h
index 5359c37e9a..40b629ed11 100644
--- a/scene/main/window.h
+++ b/scene/main/window.h
@@ -192,7 +192,6 @@ private:
Ref<Shortcut> debugger_stop_shortcut;
protected:
- Viewport *_get_embedder() const;
virtual Rect2i _popup_adjust_rect() const { return Rect2i(); }
virtual void _update_theme_item_cache();
@@ -278,6 +277,7 @@ public:
void set_ime_position(const Point2i &p_pos);
bool is_embedded() const;
+ Viewport *get_embedder() const;
void set_content_scale_size(const Size2i &p_size);
Size2i get_content_scale_size() const;