diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-10-13 11:14:43 +0200 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-10-13 11:14:43 +0200 |
commit | e82990eeafdf0be5d42d8aaa9b7fb6091e0d8435 (patch) | |
tree | ced53c3ec6168c68e63ae1083f6c6a34f99f4fa1 /UI/Camera.gd | |
parent | 0697f674ec33f8381ba68cf064732ee40e6e584f (diff) |
Diffstat (limited to 'UI/Camera.gd')
-rw-r--r-- | UI/Camera.gd | 13 |
1 files changed, 9 insertions, 4 deletions
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 |