1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

Added smooth zooming

Camera zooming with the help of a Tween node, toggle-able in the Preferences
This commit is contained in:
OverloadedOrama 2020-02-07 03:27:11 +02:00
parent 12fb8b02c8
commit e677824f48
5 changed files with 56 additions and 11 deletions

View file

@ -5,7 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [v0.6.2] - Unreleased ## [v0.6.2] - Unreleased
## Added ### Added
- Image layer rotation! Choose between 2 rotation algorithms, Rotxel and Nearest Neighbour - Thanks to azagaya! - Image layer rotation! Choose between 2 rotation algorithms, Rotxel and Nearest Neighbour - Thanks to azagaya!
- Crowdin integration for contributing translations! - Crowdin integration for contributing translations!
- Spanish translation - thanks to azagaya! - Spanish translation - thanks to azagaya!
@ -14,7 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Added HSV mode to the color picker. (Added automatically because of the Godot 3.2 update) - Added HSV mode to the color picker. (Added automatically because of the Godot 3.2 update)
- Lanczos scaling interpolation. (Added because of the Godot 3.2 update) - Lanczos scaling interpolation. (Added because of the Godot 3.2 update)
## Changed ### Changed
- Updates to the Greek, Russian and Traditional Chinese translations. - Updates to the Greek, Russian and Traditional Chinese translations.
- Replaced some OS alerts with a custom made error dialog. - Replaced some OS alerts with a custom made error dialog.
- Made the "X" button on the custom brushes a little smaller. - Made the "X" button on the custom brushes a little smaller.

View file

@ -40,6 +40,17 @@ margin_right = 205.0
margin_bottom = 758.0 margin_bottom = 758.0
size_flags_horizontal = 3 size_flags_horizontal = 3
[node name="General" type="VBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer"]
margin_right = 40.0
margin_bottom = 40.0
[node name="SmoothZoom" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/General"]
margin_right = 24.0
margin_bottom = 24.0
mouse_default_cursor_shape = 2
pressed = true
text = "Smooth Zoom"
[node name="Languages" type="VBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer"] [node name="Languages" type="VBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer"]
margin_right = 205.0 margin_right = 205.0
margin_bottom = 338.0 margin_bottom = 338.0
@ -205,6 +216,7 @@ text = "Width:"
margin_left = 82.0 margin_left = 82.0
margin_right = 156.0 margin_right = 156.0
margin_bottom = 24.0 margin_bottom = 24.0
mouse_default_cursor_shape = 2
min_value = 1.0 min_value = 1.0
max_value = 16384.0 max_value = 16384.0
value = 1.0 value = 1.0
@ -221,6 +233,7 @@ margin_left = 82.0
margin_top = 28.0 margin_top = 28.0
margin_right = 156.0 margin_right = 156.0
margin_bottom = 52.0 margin_bottom = 52.0
mouse_default_cursor_shape = 2
min_value = 1.0 min_value = 1.0
max_value = 16384.0 max_value = 16384.0
value = 1.0 value = 1.0
@ -238,6 +251,7 @@ margin_top = 56.0
margin_right = 156.0 margin_right = 156.0
margin_bottom = 76.0 margin_bottom = 76.0
rect_min_size = Vector2( 64, 20 ) rect_min_size = Vector2( 64, 20 )
mouse_default_cursor_shape = 2
[node name="GuideColorLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides/GridOptions"] [node name="GuideColorLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides/GridOptions"]
margin_top = 83.0 margin_top = 83.0
@ -251,6 +265,7 @@ margin_top = 80.0
margin_right = 156.0 margin_right = 156.0
margin_bottom = 100.0 margin_bottom = 100.0
rect_min_size = Vector2( 64, 20 ) rect_min_size = Vector2( 64, 20 )
mouse_default_cursor_shape = 2
color = Color( 0.63, 0.13, 0.94, 1 ) color = Color( 0.63, 0.13, 0.94, 1 )
[node name="Image" type="VBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer"] [node name="Image" type="VBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer"]
@ -282,6 +297,7 @@ text = "Default Width:"
margin_left = 114.0 margin_left = 114.0
margin_right = 188.0 margin_right = 188.0
margin_bottom = 24.0 margin_bottom = 24.0
mouse_default_cursor_shape = 2
min_value = 1.0 min_value = 1.0
max_value = 16384.0 max_value = 16384.0
value = 32.0 value = 32.0
@ -298,6 +314,7 @@ margin_left = 114.0
margin_top = 28.0 margin_top = 28.0
margin_right = 188.0 margin_right = 188.0
margin_bottom = 52.0 margin_bottom = 52.0
mouse_default_cursor_shape = 2
min_value = 1.0 min_value = 1.0
max_value = 16384.0 max_value = 16384.0
value = 32.0 value = 32.0
@ -315,10 +332,12 @@ margin_top = 56.0
margin_right = 188.0 margin_right = 188.0
margin_bottom = 76.0 margin_bottom = 76.0
rect_min_size = Vector2( 64, 20 ) rect_min_size = Vector2( 64, 20 )
mouse_default_cursor_shape = 2
color = Color( 0, 0, 0, 0 ) color = Color( 0, 0, 0, 0 )
[connection signal="about_to_show" from="." to="." method="_on_PreferencesDialog_about_to_show"] [connection signal="about_to_show" from="." to="." method="_on_PreferencesDialog_about_to_show"]
[connection signal="popup_hide" from="." to="." method="_on_PreferencesDialog_popup_hide"] [connection signal="popup_hide" from="." to="." method="_on_PreferencesDialog_popup_hide"]
[connection signal="item_selected" from="HSplitContainer/Tree" to="." method="_on_Tree_item_selected"] [connection signal="item_selected" from="HSplitContainer/Tree" to="." method="_on_Tree_item_selected"]
[connection signal="pressed" from="HSplitContainer/ScrollContainer/VBoxContainer/General/SmoothZoom" to="." method="_on_SmoothZoom_pressed"]
[connection signal="value_changed" from="HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides/GridOptions/GridWidthValue" to="." method="_on_GridWidthValue_value_changed"] [connection signal="value_changed" from="HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides/GridOptions/GridWidthValue" to="." method="_on_GridWidthValue_value_changed"]
[connection signal="value_changed" from="HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides/GridOptions/GridHeightValue" to="." method="_on_GridHeightValue_value_changed"] [connection signal="value_changed" from="HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides/GridOptions/GridHeightValue" to="." method="_on_GridHeightValue_value_changed"]
[connection signal="color_changed" from="HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides/GridOptions/GridColor" to="." method="_on_GridColor_color_changed"] [connection signal="color_changed" from="HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides/GridOptions/GridColor" to="." method="_on_GridColor_color_changed"]

View file

@ -1,5 +1,6 @@
extends Camera2D extends Camera2D
var tween : Tween
var zoom_min := Vector2(0.005, 0.005) var zoom_min := Vector2(0.005, 0.005)
var zoom_max := Vector2.ONE var zoom_max := Vector2.ONE
var viewport_container : ViewportContainer var viewport_container : ViewportContainer
@ -7,6 +8,8 @@ var drag := false
func _ready() -> void: func _ready() -> void:
viewport_container = get_parent().get_parent() viewport_container = get_parent().get_parent()
tween = Tween.new()
add_child(tween)
func _input(event : InputEvent) -> void: func _input(event : InputEvent) -> void:
var mouse_pos := viewport_container.get_local_mouse_position() var mouse_pos := viewport_container.get_local_mouse_position()
@ -26,11 +29,22 @@ func _input(event : InputEvent) -> void:
# Zoom Camera # Zoom Camera
func zoom_camera(dir : int) -> void: func zoom_camera(dir : int) -> void:
var zoom_margin = zoom * dir / 10 if Global.smooth_zoom:
if zoom + zoom_margin > zoom_min: var zoom_margin = zoom * dir / 5
zoom += zoom_margin 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: if zoom > zoom_max:
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": if name == "Camera2D":
Global.zoom_level_label.text = str(round(100 / Global.camera.zoom.x)) + " %" Global.zoom_level_label.text = str(round(100 / Global.camera.zoom.x)) + " %"

View file

@ -2,6 +2,7 @@ extends AcceptDialog
onready var tree : Tree = $HSplitContainer/Tree onready var tree : Tree = $HSplitContainer/Tree
onready var right_side : VBoxContainer = $HSplitContainer/ScrollContainer/VBoxContainer onready var right_side : VBoxContainer = $HSplitContainer/ScrollContainer/VBoxContainer
onready var general = $HSplitContainer/ScrollContainer/VBoxContainer/General
onready var languages = $HSplitContainer/ScrollContainer/VBoxContainer/Languages onready var languages = $HSplitContainer/ScrollContainer/VBoxContainer/Languages
onready var themes = $HSplitContainer/ScrollContainer/VBoxContainer/Themes onready var themes = $HSplitContainer/ScrollContainer/VBoxContainer/Themes
onready var grid_guides = $"HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides" onready var grid_guides = $"HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides"
@ -72,15 +73,17 @@ func _ready() -> void:
func _on_PreferencesDialog_about_to_show() -> void: func _on_PreferencesDialog_about_to_show() -> void:
var root := tree.create_item() var root := tree.create_item()
var general_button := tree.create_item(root)
var language_button := tree.create_item(root) var language_button := tree.create_item(root)
var theme_button := tree.create_item(root) var theme_button := tree.create_item(root)
var grid_button := tree.create_item(root) var grid_button := tree.create_item(root)
var image_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 # 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.set_metadata(0, "Language")
language_button.select(0)
theme_button.set_text(0, " " + tr("Themes")) theme_button.set_text(0, " " + tr("Themes"))
theme_button.set_metadata(0, "Themes") theme_button.set_metadata(0, "Themes")
grid_button.set_text(0, " " + tr("Guides & Grid")) 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_text(0, " " + tr("Image"))
image_button.set_metadata(0, "Image") image_button.set_metadata(0, "Image")
general_button.select(0)
func _on_PreferencesDialog_popup_hide() -> void: func _on_PreferencesDialog_popup_hide() -> void:
tree.clear() tree.clear()
@ -96,7 +101,9 @@ func _on_Tree_item_selected() -> void:
for child in right_side.get_children(): for child in right_side.get_children():
child.visible = false child.visible = false
var selected : String = tree.get_selected().get_metadata(0) 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 languages.visible = true
elif "Themes" in selected: elif "Themes" in selected:
themes.visible = true themes.visible = true
@ -105,6 +112,9 @@ func _on_Tree_item_selected() -> void:
elif "Image" in selected: elif "Image" in selected:
image.visible = true image.visible = true
func _on_SmoothZoom_pressed() -> void:
Global.smooth_zoom = !Global.smooth_zoom
func _on_Language_pressed(button : Button) -> void: func _on_Language_pressed(button : Button) -> void:
var index := 0 var index := 0
var i := -1 var i := -1
@ -263,4 +273,3 @@ func _on_DefaultBackground_color_changed(color: Color) -> void:
Global.default_fill_color = color Global.default_fill_color = color
Global.config_cache.set_value("preferences", "default_fill_color", color) Global.config_cache.set_value("preferences", "default_fill_color", color)
Global.config_cache.save("user://cache.ini") Global.config_cache.save("user://cache.ini")

View file

@ -15,6 +15,9 @@ var has_focus := false
var canvases := [] var canvases := []
# warning-ignore:unused_class_variable # warning-ignore:unused_class_variable
var hidden_canvases := [] 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 left_cursor_tool_texture : ImageTexture
var right_cursor_tool_texture : ImageTexture var right_cursor_tool_texture : ImageTexture
var transparent_background : ImageTexture var transparent_background : ImageTexture