From bdd3cdf45eca949fa9fb554ac159b9d95161c881 Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Mon, 13 Apr 2020 16:39:18 +0300 Subject: [PATCH] Improved the "fit to frame" zoom button The resulting camera zoom now depends on the window size. More specifically, the main viewport's x size. This formula is purely trial-and-error, and it may not work perfectly, or properly for some screen sizes. If anyone wants to improve it, feel free to do so! --- Scripts/CameraMovement.gd | 14 +++++++------- Scripts/Global.gd | 2 +- Scripts/Main.gd | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Scripts/CameraMovement.gd b/Scripts/CameraMovement.gd index f029b3ec6..161a46c9a 100644 --- a/Scripts/CameraMovement.gd +++ b/Scripts/CameraMovement.gd @@ -28,10 +28,10 @@ func dir_move_zoom_multiplier(press_time : float) -> float: return Global.low_speed_move_rate else: return 0.0 - + func reset_dir_move_time(direction) -> void: Global.key_move_press_time[direction] = 0.0 - + const key_move_action_names := ["ui_up", "ui_down", "ui_left", "ui_right"] @@ -41,7 +41,7 @@ func is_action_direction_pressed(event : InputEvent, allow_echo: bool = true) -> if event.is_action_pressed(action, allow_echo): 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: @@ -51,7 +51,7 @@ func is_action_direction_released(event: InputEvent) -> bool: # get the Direction associated with the event. # if not a direction event return null -func get_action_direction(event: InputEvent): # -> Optional[Direction] +func get_action_direction(event: InputEvent): # -> Optional[Direction] if event.is_action("ui_up"): return Global.Direction.UP elif event.is_action("ui_down"): @@ -72,7 +72,7 @@ const directional_sign_multipliers := [ Vector2(1.0, 0.0) ] -# Process an action event for a pressed direction +# Process an action event for a pressed direction # action func process_direction_action_pressed(event: InputEvent) -> void: var dir = get_action_direction(event) @@ -96,7 +96,7 @@ func _input(event : InputEvent) -> void: mouse_pos = viewport_container.get_local_mouse_position() var viewport_size := viewport_container.rect_size if event.is_action_pressed("middle_mouse") || event.is_action_pressed("space"): - drag = true + drag = true elif event.is_action_released("middle_mouse") || event.is_action_released("space"): drag = false @@ -111,7 +111,7 @@ func _input(event : InputEvent) -> void: process_direction_action_pressed(event) elif is_action_direction_released(event): process_direction_action_released(event) - + # Zoom Camera func zoom_camera(dir : int) -> void: diff --git a/Scripts/Global.gd b/Scripts/Global.gd index 70ac24555..6b0905b0f 100644 --- a/Scripts/Global.gd +++ b/Scripts/Global.gd @@ -23,7 +23,7 @@ enum Direction { } # Indices are as in the Direction enum -# This is the total time the key for +# This is the total time the key for # that direction has been pressed. var key_move_press_time := [0.0, 0.0, 0.0, 0.0] diff --git a/Scripts/Main.gd b/Scripts/Main.gd index cd5e0609b..6bd3248c5 100644 --- a/Scripts/Main.gd +++ b/Scripts/Main.gd @@ -654,7 +654,7 @@ func _on_RightZoomModeOptions_item_selected(ID : int) -> void: func _on_FitToFrameButton_pressed() -> void: var bigger = max(Global.canvas.size.x, Global.canvas.size.y) - Global.camera.zoom = Vector2(bigger, bigger) * 0.002 + Global.camera.zoom = (Vector2(bigger, bigger) * 0.004) / (Global.main_viewport.rect_size.x * 0.002) Global.camera.offset = Global.canvas.size / 2 Global.zoom_level_label.text = str(round(100 / Global.camera.zoom.x)) + " %"