Skip to content

Commit

Permalink
Merge pull request #40302 from verdog/camera-bounds-fix
Browse files Browse the repository at this point in the history
Fix Camera2D Incorrect Preview Bounds
  • Loading branch information
akien-mga authored Aug 27, 2020
2 parents c59e939 + 79e44f4 commit 6875c9d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 0 additions & 2 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,6 @@ void EditorNode::_notification(int p_what) {

editor_selection->update();

//scene_root->set_size_override(true, Size2(ProjectSettings::get_singleton()->get("display/window/size/width"), ProjectSettings::get_singleton()->get("display/window/size/height")));

{ //TODO should only happen on settings changed
int current_filter = GLOBAL_GET("rendering/canvas_textures/default_texture_filter");
if (current_filter != scene_root->get_default_canvas_item_texture_filter()) {
Expand Down
18 changes: 13 additions & 5 deletions scene/2d/camera_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void Camera2D::_update_scroll() {

viewport->set_canvas_transform(xform);

Size2 screen_size = viewport->get_visible_rect().size;
Size2 screen_size = _get_camera_screen_size();
Point2 screen_offset = (anchor_mode == ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5) : Point2());

get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, group_name, "_camera_moved", xform, screen_offset);
Expand Down Expand Up @@ -94,7 +94,7 @@ Transform2D Camera2D::get_camera_transform() {

ERR_FAIL_COND_V(custom_viewport && !ObjectDB::get_instance(custom_viewport_id), Transform2D());

Size2 screen_size = viewport->get_visible_rect().size;
Size2 screen_size = _get_camera_screen_size();

Point2 new_camera_pos = get_global_transform().get_origin();
Point2 ret_camera_pos;
Expand Down Expand Up @@ -274,7 +274,7 @@ void Camera2D::_notification(int p_what) {
}

Transform2D inv_camera_transform = get_camera_transform().affine_inverse();
Size2 screen_size = get_viewport_rect().size;
Size2 screen_size = _get_camera_screen_size();

Vector2 screen_endpoints[4] = {
inv_camera_transform.xform(Vector2(0, 0)),
Expand Down Expand Up @@ -321,7 +321,7 @@ void Camera2D::_notification(int p_what) {
}

Transform2D inv_camera_transform = get_camera_transform().affine_inverse();
Size2 screen_size = get_viewport_rect().size;
Size2 screen_size = _get_camera_screen_size();

Vector2 margin_endpoints[4] = {
inv_camera_transform.xform(Vector2((screen_size.width / 2) - ((screen_size.width / 2) * drag_margin[MARGIN_LEFT]), (screen_size.height / 2) - ((screen_size.height / 2) * drag_margin[MARGIN_TOP]))),
Expand Down Expand Up @@ -469,7 +469,7 @@ void Camera2D::reset_smoothing() {
void Camera2D::align() {
ERR_FAIL_COND(custom_viewport && !ObjectDB::get_instance(custom_viewport_id));

Size2 screen_size = viewport->get_visible_rect().size;
Size2 screen_size = _get_camera_screen_size();

Point2 current_camera_pos = get_global_transform().get_origin();
if (anchor_mode == ANCHOR_MODE_DRAG_CENTER) {
Expand Down Expand Up @@ -507,6 +507,14 @@ Point2 Camera2D::get_camera_screen_center() const {
return camera_screen_center;
}

Size2 Camera2D::_get_camera_screen_size() const {
// special case if the camera2D is in the root viewport
if (Engine::get_singleton()->is_editor_hint() && get_viewport()->get_parent_viewport() == get_tree()->get_root()) {
return Size2(ProjectSettings::get_singleton()->get("display/window/size/width"), ProjectSettings::get_singleton()->get("display/window/size/height"));
}
return get_viewport_rect().size;
}

void Camera2D::set_h_drag_enabled(bool p_enabled) {
h_drag_enabled = p_enabled;
}
Expand Down
2 changes: 2 additions & 0 deletions scene/2d/camera_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class Camera2D : public Node2D {

Camera2DProcessMode process_mode;

Size2 _get_camera_screen_size() const;

protected:
virtual Transform2D get_camera_transform();
void _notification(int p_what);
Expand Down

0 comments on commit 6875c9d

Please sign in to comment.