From e82990eeafdf0be5d42d8aaa9b7fb6091e0d8435 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 13 Oct 2024 11:14:43 +0200 Subject: next commit --- UI/Camera.gd | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'UI/Camera.gd') diff --git a/UI/Camera.gd b/UI/Camera.gd index 6c22d44..926ab36 100644 --- a/UI/Camera.gd +++ b/UI/Camera.gd @@ -2,6 +2,8 @@ class_name Camera extends Camera2D +signal zoomed(zoom: Vector2) + var is_in_drag_mode = false var drag_anchor = Vector2.ZERO @@ -17,28 +19,31 @@ func _ready(): get_viewport().size_changed.connect(func(): set_new_position(global_position) var new_zoom = Vector2( - get_rect().size.x / limit_right, - get_rect().size.y / limit_bottom + (limit_right - limit_left) / get_viewport_rect().size.x, + (limit_bottom - limit_top) / get_viewport_rect().size.y ) zoom = Vector2( new_zoom[new_zoom.max_axis_index()], new_zoom[new_zoom.max_axis_index()] ) + zoomed.emit(zoom) ) func _input(event): if event.is_action("camera_zoom_out"): var can_zoom_out = ( - limit_right / get_rect().end.x > 1.0 and - limit_bottom / get_rect().end.y > 1.0 + (limit_right - limit_left) / get_rect().size.x > 1.0 and + (limit_bottom - limit_top) / get_rect().size.y > 1.0 ) if can_zoom_out: var new_zoom = max(zoom.x - zoom_step, zoom_min) zoom = Vector2(new_zoom, new_zoom) + zoomed.emit(zoom) if event.is_action("camera_zoom_in"): var new_zoom = min(zoom.x + zoom_step, zoom_max) zoom = Vector2(new_zoom, new_zoom) + zoomed.emit(zoom) if event.is_action_pressed("camera_drag"): is_in_drag_mode = true -- cgit v1.2.3