mirror of
https://github.com/tonytins/CozyPixelStudio.git
synced 2025-06-25 06:44:42 -04:00
Added smooth zooming
Camera zooming with the help of a Tween node, toggle-able in the Preferences
This commit is contained in:
parent
12fb8b02c8
commit
e677824f48
5 changed files with 56 additions and 11 deletions
|
@ -1,5 +1,6 @@
|
|||
extends Camera2D
|
||||
|
||||
var tween : Tween
|
||||
var zoom_min := Vector2(0.005, 0.005)
|
||||
var zoom_max := Vector2.ONE
|
||||
var viewport_container : ViewportContainer
|
||||
|
@ -7,6 +8,8 @@ var drag := false
|
|||
|
||||
func _ready() -> void:
|
||||
viewport_container = get_parent().get_parent()
|
||||
tween = Tween.new()
|
||||
add_child(tween)
|
||||
|
||||
func _input(event : InputEvent) -> void:
|
||||
var mouse_pos := viewport_container.get_local_mouse_position()
|
||||
|
@ -26,11 +29,22 @@ func _input(event : InputEvent) -> void:
|
|||
|
||||
# Zoom Camera
|
||||
func zoom_camera(dir : int) -> void:
|
||||
var zoom_margin = zoom * dir / 10
|
||||
if zoom + zoom_margin > zoom_min:
|
||||
zoom += zoom_margin
|
||||
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)
|
||||
tween.start()
|
||||
|
||||
if zoom > zoom_max:
|
||||
zoom = zoom_max
|
||||
if zoom > zoom_max:
|
||||
tween.stop_all()
|
||||
zoom = zoom_max
|
||||
|
||||
else:
|
||||
var zoom_margin = zoom * dir / 10
|
||||
if zoom + zoom_margin > zoom_min:
|
||||
zoom += zoom_margin
|
||||
|
||||
if zoom > zoom_max:
|
||||
zoom = zoom_max
|
||||
if name == "Camera2D":
|
||||
Global.zoom_level_label.text = str(round(100 / Global.camera.zoom.x)) + " %"
|
||||
|
|
|
@ -2,6 +2,7 @@ extends AcceptDialog
|
|||
|
||||
onready var tree : Tree = $HSplitContainer/Tree
|
||||
onready var right_side : VBoxContainer = $HSplitContainer/ScrollContainer/VBoxContainer
|
||||
onready var general = $HSplitContainer/ScrollContainer/VBoxContainer/General
|
||||
onready var languages = $HSplitContainer/ScrollContainer/VBoxContainer/Languages
|
||||
onready var themes = $HSplitContainer/ScrollContainer/VBoxContainer/Themes
|
||||
onready var grid_guides = $"HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides"
|
||||
|
@ -72,15 +73,17 @@ func _ready() -> void:
|
|||
|
||||
func _on_PreferencesDialog_about_to_show() -> void:
|
||||
var root := tree.create_item()
|
||||
var general_button := tree.create_item(root)
|
||||
var language_button := tree.create_item(root)
|
||||
var theme_button := tree.create_item(root)
|
||||
var grid_button := tree.create_item(root)
|
||||
var image_button := tree.create_item(root)
|
||||
|
||||
language_button.set_text(0, " " + tr("Language"))
|
||||
general_button.set_text(0, " " + tr("General"))
|
||||
# We use metadata to avoid being affected by translations
|
||||
general_button.set_metadata(0, "General")
|
||||
language_button.set_text(0, " " + tr("Language"))
|
||||
language_button.set_metadata(0, "Language")
|
||||
language_button.select(0)
|
||||
theme_button.set_text(0, " " + tr("Themes"))
|
||||
theme_button.set_metadata(0, "Themes")
|
||||
grid_button.set_text(0, " " + tr("Guides & Grid"))
|
||||
|
@ -88,6 +91,8 @@ func _on_PreferencesDialog_about_to_show() -> void:
|
|||
image_button.set_text(0, " " + tr("Image"))
|
||||
image_button.set_metadata(0, "Image")
|
||||
|
||||
general_button.select(0)
|
||||
|
||||
|
||||
func _on_PreferencesDialog_popup_hide() -> void:
|
||||
tree.clear()
|
||||
|
@ -96,7 +101,9 @@ func _on_Tree_item_selected() -> void:
|
|||
for child in right_side.get_children():
|
||||
child.visible = false
|
||||
var selected : String = tree.get_selected().get_metadata(0)
|
||||
if "Language" in selected:
|
||||
if "General" in selected:
|
||||
general.visible = true
|
||||
elif "Language" in selected:
|
||||
languages.visible = true
|
||||
elif "Themes" in selected:
|
||||
themes.visible = true
|
||||
|
@ -105,6 +112,9 @@ func _on_Tree_item_selected() -> void:
|
|||
elif "Image" in selected:
|
||||
image.visible = true
|
||||
|
||||
func _on_SmoothZoom_pressed() -> void:
|
||||
Global.smooth_zoom = !Global.smooth_zoom
|
||||
|
||||
func _on_Language_pressed(button : Button) -> void:
|
||||
var index := 0
|
||||
var i := -1
|
||||
|
@ -263,4 +273,3 @@ func _on_DefaultBackground_color_changed(color: Color) -> void:
|
|||
Global.default_fill_color = color
|
||||
Global.config_cache.set_value("preferences", "default_fill_color", color)
|
||||
Global.config_cache.save("user://cache.ini")
|
||||
|
||||
|
|
|
@ -15,6 +15,9 @@ var has_focus := false
|
|||
var canvases := []
|
||||
# warning-ignore:unused_class_variable
|
||||
var hidden_canvases := []
|
||||
enum PRESSURE_SENSITIVITY {NONE, ALPHA, SIZE}
|
||||
var pressure_sensitivity_mode = PRESSURE_SENSITIVITY.NONE
|
||||
var smooth_zoom := true
|
||||
var left_cursor_tool_texture : ImageTexture
|
||||
var right_cursor_tool_texture : ImageTexture
|
||||
var transparent_background : ImageTexture
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue