From cba301f911d8d9ac5cf69f705489f14505ddeaa6 Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Sat, 18 Apr 2020 20:38:59 +0300 Subject: [PATCH] Zoom label now shows the correct zoom value on smooth zoom --- Changelog.md | 1 + Scripts/CameraMovement.gd | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Changelog.md b/Changelog.md index ababa4358..1df4c3ed1 100644 --- a/Changelog.md +++ b/Changelog.md @@ -55,6 +55,7 @@ Martin Novák (novhack), luiq54, Schweini07, Marco Galli (Gaarco), Matheus Peseg - Fixed issue with LineEdits not letting go of focus when the user clicked somewhere else.! (Issue #167) - When the palette, outline and rotate image dialogs are open, the user can't zoom in the canvas anymore. - Fixed bug where the user could drag the selection and the guides when the canvas had no focus. +- The zoom label on the top bar now shows the correct zoom value when smooth zoom is enabled. ### Removed - It's no longer possible for frames to have different amounts of layers. All frames have the same amount. diff --git a/Scripts/CameraMovement.gd b/Scripts/CameraMovement.gd index 161a46c9a..c5da74a0e 100644 --- a/Scripts/CameraMovement.gd +++ b/Scripts/CameraMovement.gd @@ -42,6 +42,7 @@ func is_action_direction_pressed(event : InputEvent, allow_echo: bool = true) -> return true return false + # Check if an event is a ui_up/down/left/right event release nya func is_action_direction_released(event: InputEvent) -> bool: for action in key_move_action_names: @@ -49,6 +50,7 @@ func is_action_direction_released(event: InputEvent) -> bool: return true return false + # get the Direction associated with the event. # if not a direction event return null func get_action_direction(event: InputEvent): # -> Optional[Direction] @@ -62,6 +64,7 @@ func get_action_direction(event: InputEvent): # -> Optional[Direction] return Global.Direction.RIGHT return null + # Holds sign multipliers for the given directions nyaa # (per the indices in Global.gd defined by Direction) # UP, DOWN, LEFT, RIGHT in that order @@ -85,6 +88,7 @@ func process_direction_action_pressed(event: InputEvent) -> void: var move_speed := dir_move_zoom_multiplier(this_direction_press_time) offset = offset + move_speed * increment * directional_sign_multipliers[dir] * zoom + # Process an action for a release direction action func process_direction_action_released(event: InputEvent) -> void: var dir = get_action_direction(event) @@ -92,6 +96,7 @@ func process_direction_action_released(event: InputEvent) -> void: return reset_dir_move_time(dir) + func _input(event : InputEvent) -> void: mouse_pos = viewport_container.get_local_mouse_position() var viewport_size := viewport_container.rect_size @@ -125,6 +130,9 @@ func zoom_camera(dir : int) -> void: tween.interpolate_property(self, "offset", offset, new_offset, 0.05, Tween.TRANS_LINEAR, Tween.EASE_IN) tween.start() + if name == "Camera2D": + Global.zoom_level_label.text = str(round(100 / new_zoom.x)) + " %" + else: var prev_zoom := zoom var zoom_margin = zoom * dir / 10 @@ -135,6 +143,5 @@ func zoom_camera(dir : int) -> void: zoom = zoom_max offset = offset + (-0.5 * viewport_size + mouse_pos) * (prev_zoom - zoom) - - if name == "Camera2D": - Global.zoom_level_label.text = str(round(100 / Global.camera.zoom.x)) + " %" + if name == "Camera2D": + Global.zoom_level_label.text = str(round(100 / Global.camera.zoom.x)) + " %"