summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/3d/audio_stream_player_3d.cpp11
-rw-r--r--scene/animation/animation_player.cpp2
-rw-r--r--scene/gui/dialogs.cpp4
-rw-r--r--scene/main/viewport.cpp33
-rw-r--r--scene/main/viewport.h5
-rw-r--r--scene/main/window.cpp106
-rw-r--r--scene/main/window.h8
-rw-r--r--scene/resources/resource_format_text.cpp8
8 files changed, 104 insertions, 73 deletions
diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp
index 436b936586..77bf15125e 100644
--- a/scene/3d/audio_stream_player_3d.cpp
+++ b/scene/3d/audio_stream_player_3d.cpp
@@ -162,12 +162,10 @@ void AudioStreamPlayer3D::_calc_reverb_vol(Area3D *area, Vector3 listener_area_p
rev_pos.y = 0;
rev_pos.normalize();
- if (channel_count >= 1) {
- // Stereo pair
- float c = rev_pos.x * 0.5 + 0.5;
- reverb_vol.write[0].l = 1.0 - c;
- reverb_vol.write[0].r = c;
- }
+ // Stereo pair.
+ float c = rev_pos.x * 0.5 + 0.5;
+ reverb_vol.write[0].l = 1.0 - c;
+ reverb_vol.write[0].r = c;
if (channel_count >= 3) {
// Center pair + Side pair
@@ -183,7 +181,6 @@ void AudioStreamPlayer3D::_calc_reverb_vol(Area3D *area, Vector3 listener_area_p
if (channel_count >= 4) {
// Rear pair
// FIXME: Not sure what math should be done here
- float c = rev_pos.x * 0.5 + 0.5;
reverb_vol.write[3].l = 1.0 - c;
reverb_vol.write[3].r = c;
}
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp
index 8087ac6250..ad0c19b1e6 100644
--- a/scene/animation/animation_player.cpp
+++ b/scene/animation/animation_player.cpp
@@ -1233,7 +1233,7 @@ void AnimationPlayer::_animation_update_transforms() {
if (aa->time < pasi.start) {
stop = true;
}
- } else if (aa->backward) {
+ } else {
if (aa->time > pasi.start) {
stop = true;
}
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp
index dfe9ea3b08..760c86b2cc 100644
--- a/scene/gui/dialogs.cpp
+++ b/scene/gui/dialogs.cpp
@@ -276,10 +276,6 @@ Size2 AcceptDialog::_get_contents_minimum_size() const {
// Plus there is a separation size added on top.
content_minsize.y += theme_cache.buttons_separation;
- // Last, we make sure that we aren't below the minimum window size.
- Size2 window_minsize = get_min_size();
- content_minsize.x = MAX(window_minsize.x, content_minsize.x);
- content_minsize.y = MAX(window_minsize.y, content_minsize.y);
return content_minsize;
}
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index cbb34a480b..a1e7555a5d 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -380,7 +380,7 @@ void Viewport::_notification(int p_what) {
if (get_tree()->is_debugging_collisions_hint()) {
PhysicsServer2D::get_singleton()->space_set_debug_contacts(find_world_2d()->get_space(), get_tree()->get_collision_debug_contact_count());
contact_2d_debug = RenderingServer::get_singleton()->canvas_item_create();
- RenderingServer::get_singleton()->canvas_item_set_parent(contact_2d_debug, find_world_2d()->get_canvas());
+ RenderingServer::get_singleton()->canvas_item_set_parent(contact_2d_debug, current_canvas);
#ifndef _3D_DISABLED
PhysicsServer3D::get_singleton()->space_set_debug_contacts(find_world_3d()->get_space(), get_tree()->get_collision_debug_contact_count());
contact_3d_debug_multimesh = RenderingServer::get_singleton()->multimesh_create();
@@ -1172,11 +1172,16 @@ Ref<InputEvent> Viewport::_make_input_local(const Ref<InputEvent> &ev) {
}
Vector2 Viewport::get_mouse_position() const {
- return gui.last_mouse_pos;
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_MOUSE)) {
+ return get_screen_transform_internal(true).affine_inverse().xform(DisplayServer::get_singleton()->mouse_get_position());
+ } else {
+ // Fallback to Input for getting mouse position in case of emulated mouse.
+ return get_screen_transform_internal().affine_inverse().xform(Input::get_singleton()->get_mouse_position());
+ }
}
void Viewport::warp_mouse(const Vector2 &p_position) {
- Transform2D xform = get_screen_transform();
+ Transform2D xform = get_screen_transform_internal();
Vector2 gpos = xform.xform(p_position);
Input::get_singleton()->warp_mouse(gpos);
}
@@ -2556,20 +2561,14 @@ bool Viewport::_sub_windows_forward_input(const Ref<InputEvent> &p_event) {
if (gui.subwindow_drag == SUB_WINDOW_DRAG_RESIZE) {
Vector2i diff = mm->get_position() - gui.subwindow_drag_from;
Size2i min_size = gui.subwindow_focused->get_min_size();
+ Size2i min_size_clamped = gui.subwindow_focused->get_clamped_minimum_size();
- Size2i min_size_adjusted = min_size;
- if (gui.subwindow_focused->is_wrapping_controls()) {
- Size2i cms = gui.subwindow_focused->get_contents_minimum_size();
- min_size_adjusted.x = MAX(cms.x, min_size.x);
- min_size_adjusted.y = MAX(cms.y, min_size.y);
- }
-
- min_size_adjusted.x = MAX(min_size_adjusted.x, 1);
- min_size_adjusted.y = MAX(min_size_adjusted.y, 1);
+ min_size_clamped.x = MAX(min_size_clamped.x, 1);
+ min_size_clamped.y = MAX(min_size_clamped.y, 1);
Rect2i r = gui.subwindow_resize_from_rect;
- Size2i limit = r.size - min_size_adjusted;
+ Size2i limit = r.size - min_size_clamped;
switch (gui.subwindow_resize_mode) {
case SUB_WINDOW_RESIZE_TOP_LEFT: {
@@ -3288,6 +3287,10 @@ Viewport::SDFScale Viewport::get_sdf_scale() const {
}
Transform2D Viewport::get_screen_transform() const {
+ return get_screen_transform_internal();
+}
+
+Transform2D Viewport::get_screen_transform_internal(bool p_absolute_position) const {
return get_final_transform();
}
@@ -4226,14 +4229,14 @@ DisplayServer::WindowID SubViewport::get_window_id() const {
return DisplayServer::INVALID_WINDOW_ID;
}
-Transform2D SubViewport::get_screen_transform() const {
+Transform2D SubViewport::get_screen_transform_internal(bool p_absolute_position) const {
Transform2D container_transform;
SubViewportContainer *c = Object::cast_to<SubViewportContainer>(get_parent());
if (c) {
if (c->is_stretch_enabled()) {
container_transform.scale(Vector2(c->get_stretch_shrink(), c->get_stretch_shrink()));
}
- container_transform = c->get_viewport()->get_screen_transform() * c->get_global_transform_with_canvas() * container_transform;
+ container_transform = c->get_viewport()->get_screen_transform_internal(p_absolute_position) * c->get_global_transform_with_canvas() * container_transform;
} else {
WARN_PRINT_ONCE("SubViewport is not a child of a SubViewportContainer. get_screen_transform doesn't return the actual screen position.");
}
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 4144eaabb9..055fad5369 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -651,7 +651,8 @@ public:
virtual bool is_size_2d_override_stretch_enabled() const { return true; }
- virtual Transform2D get_screen_transform() const;
+ Transform2D get_screen_transform() const;
+ virtual Transform2D get_screen_transform_internal(bool p_absolute_position = false) const;
virtual Transform2D get_popup_base_transform() const { return Transform2D(); }
#ifndef _3D_DISABLED
@@ -780,7 +781,7 @@ public:
void set_clear_mode(ClearMode p_mode);
ClearMode get_clear_mode() const;
- virtual Transform2D get_screen_transform() const override;
+ virtual Transform2D get_screen_transform_internal(bool p_absolute_position = false) const override;
virtual Transform2D get_popup_base_transform() const override;
SubViewport();
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 9fcfb29ef7..44df648552 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -349,8 +349,30 @@ Size2i Window::get_size_with_decorations() const {
return size;
}
+Size2i Window::_clamp_limit_size(const Size2i &p_limit_size) {
+ // Force window limits to respect size limitations of rendering server.
+ Size2i max_window_size = RS::get_singleton()->get_maximum_viewport_size();
+ if (max_window_size != Size2i()) {
+ return p_limit_size.clamp(Vector2i(), max_window_size);
+ } else {
+ return p_limit_size.max(Vector2i());
+ }
+}
+
+void Window::_validate_limit_size() {
+ // When max_size is invalid, max_size_used falls back to respect size limitations of rendering server.
+ bool max_size_valid = (max_size.x > 0 || max_size.y > 0) && max_size.x >= min_size.x && max_size.y >= min_size.y;
+ max_size_used = max_size_valid ? max_size : RS::get_singleton()->get_maximum_viewport_size();
+}
+
void Window::set_max_size(const Size2i &p_max_size) {
- max_size = p_max_size;
+ Size2i max_size_clamped = _clamp_limit_size(p_max_size);
+ if (max_size == max_size_clamped) {
+ return;
+ }
+ max_size = max_size_clamped;
+
+ _validate_limit_size();
_update_window_size();
}
@@ -359,7 +381,13 @@ Size2i Window::get_max_size() const {
}
void Window::set_min_size(const Size2i &p_min_size) {
- min_size = p_min_size;
+ Size2i min_size_clamped = _clamp_limit_size(p_min_size);
+ if (min_size == min_size_clamped) {
+ return;
+ }
+ min_size = min_size_clamped;
+
+ _validate_limit_size();
_update_window_size();
}
@@ -833,49 +861,35 @@ bool Window::is_visible() const {
return visible;
}
-void Window::_update_window_size() {
- // Force window to respect size limitations of rendering server.
- RenderingServer *rendering_server = RenderingServer::get_singleton();
- if (rendering_server) {
- Size2i max_window_size = rendering_server->get_maximum_viewport_size();
+Size2i Window::_clamp_window_size(const Size2i &p_size) {
+ Size2i window_size_clamped = p_size;
+ Size2 minsize = get_clamped_minimum_size();
+ window_size_clamped = window_size_clamped.max(minsize);
- if (max_window_size != Size2i()) {
- size = size.min(max_window_size);
- min_size = min_size.min(max_window_size);
- max_size = max_size.min(max_window_size);
- }
+ if (max_size_used != Size2i()) {
+ window_size_clamped = window_size_clamped.min(max_size_used);
}
- Size2i size_limit;
- if (wrap_controls) {
- size_limit = get_contents_minimum_size();
- }
+ return window_size_clamped;
+}
- size_limit.x = MAX(size_limit.x, min_size.x);
- size_limit.y = MAX(size_limit.y, min_size.y);
+void Window::_update_window_size() {
+ Size2i size_limit = get_clamped_minimum_size();
- size.x = MAX(size_limit.x, size.x);
- size.y = MAX(size_limit.y, size.y);
+ size = size.max(size_limit);
bool reset_min_first = false;
- bool max_size_valid = false;
- if ((max_size.x > 0 || max_size.y > 0) && (max_size.x >= min_size.x && max_size.y >= min_size.y)) {
- max_size_valid = true;
+ if (max_size_used != Size2i()) {
+ // Force window size to respect size limitations of max_size_used.
+ size = size.min(max_size_used);
- if (size.x > max_size.x) {
- size.x = max_size.x;
- }
- if (size_limit.x > max_size.x) {
- size_limit.x = max_size.x;
+ if (size_limit.x > max_size_used.x) {
+ size_limit.x = max_size_used.x;
reset_min_first = true;
}
-
- if (size.y > max_size.y) {
- size.y = max_size.y;
- }
- if (size_limit.y > max_size.y) {
- size_limit.y = max_size.y;
+ if (size_limit.y > max_size_used.y) {
+ size_limit.y = max_size_used.y;
reset_min_first = true;
}
}
@@ -891,7 +905,7 @@ void Window::_update_window_size() {
DisplayServer::get_singleton()->window_set_min_size(Size2i(), window_id);
}
- DisplayServer::get_singleton()->window_set_max_size(max_size_valid ? max_size : Size2i(), window_id);
+ DisplayServer::get_singleton()->window_set_max_size(max_size_used, window_id);
DisplayServer::get_singleton()->window_set_min_size(size_limit, window_id);
DisplayServer::get_singleton()->window_set_size(size, window_id);
}
@@ -1423,6 +1437,8 @@ void Window::popup_centered_clamped(const Size2i &p_size, float p_fallback_ratio
Rect2i popup_rect;
popup_rect.size = Vector2i(MIN(size_ratio.x, p_size.x), MIN(size_ratio.y, p_size.y));
+ popup_rect.size = _clamp_window_size(popup_rect.size);
+
if (parent_rect != Rect2()) {
popup_rect.position = parent_rect.position + (parent_rect.size - popup_rect.size) / 2;
}
@@ -1446,9 +1462,7 @@ void Window::popup_centered(const Size2i &p_minsize) {
}
Rect2i popup_rect;
- Size2 contents_minsize = _get_contents_minimum_size();
- popup_rect.size.x = MAX(p_minsize.x, contents_minsize.x);
- popup_rect.size.y = MAX(p_minsize.y, contents_minsize.y);
+ popup_rect.size = _clamp_window_size(p_minsize);
if (parent_rect != Rect2()) {
popup_rect.position = parent_rect.position + (parent_rect.size - popup_rect.size) / 2;
@@ -1476,6 +1490,7 @@ void Window::popup_centered_ratio(float p_ratio) {
Rect2i popup_rect;
if (parent_rect != Rect2()) {
popup_rect.size = parent_rect.size * p_ratio;
+ popup_rect.size = _clamp_window_size(popup_rect.size);
popup_rect.position = parent_rect.position + (parent_rect.size - popup_rect.size) / 2;
}
@@ -1539,6 +1554,14 @@ Size2 Window::get_contents_minimum_size() const {
return _get_contents_minimum_size();
}
+Size2 Window::get_clamped_minimum_size() const {
+ if (!wrap_controls) {
+ return min_size;
+ }
+
+ return min_size.max(get_contents_minimum_size());
+}
+
void Window::grab_focus() {
if (embedder) {
embedder->_sub_window_grab_focus(this);
@@ -2120,11 +2143,13 @@ Transform2D Window::get_final_transform() const {
return window_transform * stretch_transform * global_canvas_transform;
}
-Transform2D Window::get_screen_transform() const {
+Transform2D Window::get_screen_transform_internal(bool p_absolute_position) const {
Transform2D embedder_transform;
if (_get_embedder()) {
embedder_transform.translate_local(get_position());
- embedder_transform = _get_embedder()->get_screen_transform() * 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());
}
return embedder_transform * get_final_transform();
}
@@ -2389,6 +2414,7 @@ Window::Window() {
RenderingServer *rendering_server = RenderingServer::get_singleton();
if (rendering_server) {
max_size = rendering_server->get_maximum_viewport_size();
+ max_size_used = max_size; // Update max_size_used.
}
theme_owner = memnew(ThemeOwner);
diff --git a/scene/main/window.h b/scene/main/window.h
index 9861fefc68..5359c37e9a 100644
--- a/scene/main/window.h
+++ b/scene/main/window.h
@@ -135,6 +135,11 @@ private:
void _clear_window();
void _update_from_window();
+ Size2i max_size_used;
+
+ Size2i _clamp_limit_size(const Size2i &p_limit_size);
+ Size2i _clamp_window_size(const Size2i &p_size);
+ void _validate_limit_size();
void _update_viewport_size();
void _update_window_size();
@@ -306,6 +311,7 @@ public:
void popup_centered_clamped(const Size2i &p_size = Size2i(), float p_fallback_ratio = 0.75);
Size2 get_contents_minimum_size() const;
+ Size2 get_clamped_minimum_size() const;
void grab_focus();
bool has_focus() const;
@@ -377,7 +383,7 @@ public:
//
virtual Transform2D get_final_transform() const override;
- virtual Transform2D get_screen_transform() const override;
+ virtual Transform2D get_screen_transform_internal(bool p_absolute_position = false) const override;
virtual Transform2D get_popup_base_transform() const override;
Rect2i get_parent_rect() const;
diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp
index 3006da5309..448e800900 100644
--- a/scene/resources/resource_format_text.cpp
+++ b/scene/resources/resource_format_text.cpp
@@ -601,9 +601,11 @@ Error ResourceLoaderText::load() {
*progress = resource_current / float(resources_total);
}
- int_resources[id] = res; //always assign int resources
- if (do_assign && cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) {
- res->set_path(path, cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE);
+ int_resources[id] = res; // Always assign int resources.
+ if (do_assign) {
+ if (cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) {
+ res->set_path(path, cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE);
+ }
res->set_scene_unique_id(id);
}