mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
The camera now zooms at the mouse's position.
This commit is contained in:
parent
f28a3a4405
commit
3fbd1d35eb
|
@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
- Major changes to alpha blending behavior. The alpha values now get added/blended together instead of just replacing the pixel with the new value.
|
||||
- Replaced some OS alerts with a custom made error dialog.
|
||||
- Made the zooming smoother, is toggleable in Preferences whether to keep the new zooming or the old one.
|
||||
- The camera now zooms at the mouse's position.
|
||||
- Made the "X" button on the custom brushes a little smaller.
|
||||
- The color picker will now have a small white triangle on the top left of the color preview if at least one of its RGB values are above 1 in Raw mode. (Added automatically because of the Godot 3.2 update)
|
||||
- You can now toggle the visibility of hidden items on and off in the file dialogs. (Added automatically because of the Godot 3.2 update)
|
||||
|
|
|
@ -4,6 +4,7 @@ var tween : Tween
|
|||
var zoom_min := Vector2(0.005, 0.005)
|
||||
var zoom_max := Vector2.ONE
|
||||
var viewport_container : ViewportContainer
|
||||
var mouse_pos := Vector2.ZERO
|
||||
var drag := false
|
||||
|
||||
func _ready() -> void:
|
||||
|
@ -12,7 +13,7 @@ func _ready() -> void:
|
|||
add_child(tween)
|
||||
|
||||
func _input(event : InputEvent) -> void:
|
||||
var mouse_pos := viewport_container.get_local_mouse_position()
|
||||
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
|
||||
|
@ -29,22 +30,26 @@ func _input(event : InputEvent) -> void:
|
|||
|
||||
# Zoom Camera
|
||||
func zoom_camera(dir : int) -> void:
|
||||
var viewport_size := viewport_container.rect_size
|
||||
if Global.smooth_zoom:
|
||||
var zoom_margin = zoom * dir / 5
|
||||
if zoom + zoom_margin > zoom_min:
|
||||
tween.interpolate_property(self, "zoom", zoom, zoom + zoom_margin, 0.05, Tween.TRANS_LINEAR, Tween.EASE_IN)
|
||||
var new_zoom = zoom + zoom_margin
|
||||
if new_zoom > zoom_min && new_zoom < zoom_max:
|
||||
var new_offset = offset + (-0.5 * viewport_size + mouse_pos) * (zoom - new_zoom)
|
||||
tween.interpolate_property(self, "zoom", zoom, new_zoom, 0.05, Tween.TRANS_LINEAR, Tween.EASE_IN)
|
||||
tween.interpolate_property(self, "offset", offset, new_offset, 0.05, Tween.TRANS_LINEAR, Tween.EASE_IN)
|
||||
tween.start()
|
||||
|
||||
if zoom > zoom_max:
|
||||
tween.stop_all()
|
||||
zoom = zoom_max
|
||||
|
||||
else:
|
||||
var prev_zoom := zoom
|
||||
var zoom_margin = zoom * dir / 10
|
||||
if zoom + zoom_margin > zoom_min:
|
||||
zoom += zoom_margin
|
||||
|
||||
if zoom > zoom_max:
|
||||
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)) + " %"
|
||||
|
|
Loading…
Reference in a new issue