From 358a95f7090040694d472af75d80a343e62a0128 Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Mon, 11 May 2020 16:33:44 +0300 Subject: [PATCH] Changed CameraMovement.fit_to_frame() to get a Vector2 as an argument for the canvas size This fixes the issue when importing an image, not as a new frame, that did not get fitted to frame. --- src/CameraMovement.gd | 16 ++++++++-------- src/Canvas.gd | 6 +++--- src/Main.gd | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/CameraMovement.gd b/src/CameraMovement.gd index 5cbc0742c..6140e92e3 100644 --- a/src/CameraMovement.gd +++ b/src/CameraMovement.gd @@ -161,26 +161,26 @@ func _on_tween_step(_object: Object, _key: NodePath, _elapsed: float, _value: Ob Global.vertical_ruler.update() -func fit_to_frame() -> void: +func fit_to_frame(size : Vector2) -> void: viewport_container = get_parent().get_parent() - var h_ratio := viewport_container.rect_size.x / Global.canvas.size.x - var v_ratio := viewport_container.rect_size.y / Global.canvas.size.y + var h_ratio := viewport_container.rect_size.x / size.x + var v_ratio := viewport_container.rect_size.y / size.y var ratio := min(h_ratio, v_ratio) if ratio == 0: ratio = 0.1 # Set it to a non-zero value just in case # If the ratio is 0, it means that the viewport container is hidden # in that case, use the other viewport to get the ratio if name == "Camera2D": - h_ratio = Global.second_viewport.rect_size.x / Global.canvas.size.x - v_ratio = Global.second_viewport.rect_size.y / Global.canvas.size.y + h_ratio = Global.second_viewport.rect_size.x / size.x + v_ratio = Global.second_viewport.rect_size.y / size.y ratio = min(h_ratio, v_ratio) elif name == "Camera2D2": - h_ratio = Global.main_viewport.rect_size.x / Global.canvas.size.x - v_ratio = Global.main_viewport.rect_size.y / Global.canvas.size.y + h_ratio = Global.main_viewport.rect_size.x / size.x + v_ratio = Global.main_viewport.rect_size.y / size.y ratio = min(h_ratio, v_ratio) zoom = Vector2(1 / ratio, 1 / ratio) - offset = Global.canvas.size / 2 + offset = size / 2 if name == "Camera2D": Global.zoom_level_label.text = str(round(100 / Global.camera.zoom.x)) + " %" Global.horizontal_ruler.update() diff --git a/src/Canvas.gd b/src/Canvas.gd index 29f7c43b8..b997b554d 100644 --- a/src/Canvas.gd +++ b/src/Canvas.gd @@ -542,9 +542,9 @@ func camera_zoom() -> void: Global.camera2.zoom_max = Vector2.ONE Global.camera_preview.zoom_max = Vector2.ONE - Global.camera.fit_to_frame() - Global.camera2.fit_to_frame() - Global.camera_preview.fit_to_frame() + Global.camera.fit_to_frame(size) + Global.camera2.fit_to_frame(size) + Global.camera_preview.fit_to_frame(size) Global.transparent_checker._ready() # To update the rect size diff --git a/src/Main.gd b/src/Main.gd index 6cd66e5d5..374acd97c 100644 --- a/src/Main.gd +++ b/src/Main.gd @@ -785,7 +785,7 @@ func _on_RightZoomModeOptions_item_selected(ID : int) -> void: func _on_FitToFrameButton_pressed() -> void: - Global.camera.fit_to_frame() + Global.camera.fit_to_frame(Global.canvas.size) func _on_100ZoomButton_pressed() -> void: