mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-03-13 06:45:17 +00:00
Editable zoom (#523)
* editable zoom change 1 * editable zoom change 2 * editable zoom change 3 * editable zoom change 4 * editable zoom change 4 part b added upper limit automation for zoom
This commit is contained in:
parent
4e51b7211e
commit
ddc69b8282
3 changed files with 58 additions and 1 deletions
|
@ -134,6 +134,7 @@ var transparent_checker : ColorRect
|
||||||
|
|
||||||
var cursor_position_label : Label
|
var cursor_position_label : Label
|
||||||
var zoom_level_label : Label
|
var zoom_level_label : Label
|
||||||
|
var zoom_level_spinbox : SpinBox
|
||||||
|
|
||||||
var tool_panel : Panel
|
var tool_panel : Panel
|
||||||
var right_panel : Panel
|
var right_panel : Panel
|
||||||
|
@ -232,6 +233,7 @@ func _ready() -> void:
|
||||||
|
|
||||||
cursor_position_label = control.find_node("CursorPosition")
|
cursor_position_label = control.find_node("CursorPosition")
|
||||||
zoom_level_label = control.find_node("ZoomLevel")
|
zoom_level_label = control.find_node("ZoomLevel")
|
||||||
|
zoom_level_spinbox = control.find_node("ZoomSpinbox")
|
||||||
|
|
||||||
tool_panel = control.find_node("ToolPanel")
|
tool_panel = control.find_node("ToolPanel")
|
||||||
right_panel = control.find_node("RightPanel")
|
right_panel = control.find_node("RightPanel")
|
||||||
|
|
|
@ -17,6 +17,36 @@ func _ready() -> void:
|
||||||
add_child(tween)
|
add_child(tween)
|
||||||
tween.connect("tween_step", self, "_on_tween_step")
|
tween.connect("tween_step", self, "_on_tween_step")
|
||||||
update_transparent_checker_offset()
|
update_transparent_checker_offset()
|
||||||
|
|
||||||
|
# signals regarding zoom stats
|
||||||
|
Global.zoom_level_label.connect("gui_input",self,"zoom_label_clicked")
|
||||||
|
Global.zoom_level_spinbox.connect("value_changed", self, "zoom_value_changed")
|
||||||
|
Global.zoom_level_spinbox.max_value = 100.0/zoom_min.x
|
||||||
|
Global.zoom_level_spinbox.get_child(0).connect("focus_exited", self, "zoom_focus_exited")
|
||||||
|
|
||||||
|
|
||||||
|
func zoom_label_clicked(event :InputEvent):
|
||||||
|
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
|
||||||
|
if event.doubleclick:
|
||||||
|
Global.zoom_level_label.visible = false
|
||||||
|
Global.zoom_level_spinbox.visible = true
|
||||||
|
Global.zoom_level_spinbox.editable = true
|
||||||
|
Global.zoom_level_spinbox.value = str2var(Global.zoom_level_label.text.replace("%",""))
|
||||||
|
Global.zoom_level_spinbox.get_child(0).grab_focus() #since the actual lineedit is the first child of spinbox
|
||||||
|
|
||||||
|
|
||||||
|
func zoom_value_changed(value):
|
||||||
|
if name == "Camera2D":
|
||||||
|
zoom_camera_percent(value)
|
||||||
|
|
||||||
|
|
||||||
|
func zoom_focus_exited():
|
||||||
|
if Global.zoom_level_spinbox.value != round(100 / zoom.x): #If user pressed enter while editing
|
||||||
|
if name == "Camera2D":
|
||||||
|
zoom_camera_percent(Global.zoom_level_spinbox.value)
|
||||||
|
Global.zoom_level_label.visible = true
|
||||||
|
Global.zoom_level_spinbox.visible = false
|
||||||
|
Global.zoom_level_spinbox.editable = false
|
||||||
|
|
||||||
|
|
||||||
func update_transparent_checker_offset() -> void:
|
func update_transparent_checker_offset() -> void:
|
||||||
|
@ -175,6 +205,15 @@ func zoom_camera(dir : int) -> void:
|
||||||
offset = offset + (-0.5 * viewport_size + mouse_pos) * (prev_zoom - zoom)
|
offset = offset + (-0.5 * viewport_size + mouse_pos) * (prev_zoom - zoom)
|
||||||
zoom_changed()
|
zoom_changed()
|
||||||
|
|
||||||
|
func zoom_camera_percent(value :float):
|
||||||
|
var percent :float = (100.0 / value)
|
||||||
|
var new_zoom = Vector2(percent, percent)
|
||||||
|
if Global.smooth_zoom:
|
||||||
|
tween.interpolate_property(self, "zoom", zoom, new_zoom, 0.05, Tween.TRANS_LINEAR, Tween.EASE_IN)
|
||||||
|
tween.start()
|
||||||
|
else:
|
||||||
|
zoom = new_zoom
|
||||||
|
zoom_changed()
|
||||||
|
|
||||||
func zoom_changed() -> void:
|
func zoom_changed() -> void:
|
||||||
update_transparent_checker_offset()
|
update_transparent_checker_offset()
|
||||||
|
|
|
@ -77,14 +77,30 @@ __meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="ZoomLevel" type="Label" parent="TopLabels"]
|
[node name="ZoomStats" type="HBoxContainer" parent="TopLabels"]
|
||||||
|
margin_right = 60.0
|
||||||
|
margin_bottom = 28.0
|
||||||
|
alignment = 1
|
||||||
|
|
||||||
|
[node name="ZoomLevel" type="Label" parent="TopLabels/ZoomStats"]
|
||||||
margin_top = 7.0
|
margin_top = 7.0
|
||||||
margin_right = 60.0
|
margin_right = 60.0
|
||||||
margin_bottom = 21.0
|
margin_bottom = 21.0
|
||||||
rect_min_size = Vector2( 60, 0 )
|
rect_min_size = Vector2( 60, 0 )
|
||||||
|
mouse_filter = 1
|
||||||
text = "781 %"
|
text = "781 %"
|
||||||
align = 2
|
align = 2
|
||||||
|
|
||||||
|
[node name="ZoomSpinbox" type="SpinBox" parent="TopLabels/ZoomStats"]
|
||||||
|
visible = false
|
||||||
|
margin_left = 64.0
|
||||||
|
margin_right = 138.0
|
||||||
|
margin_bottom = 28.0
|
||||||
|
min_value = 100.0
|
||||||
|
max_value = 2000.0
|
||||||
|
value = 100.0
|
||||||
|
suffix = "%"
|
||||||
|
|
||||||
[node name="CursorPosition" type="Label" parent="TopLabels"]
|
[node name="CursorPosition" type="Label" parent="TopLabels"]
|
||||||
margin_left = 80.0
|
margin_left = 80.0
|
||||||
margin_top = 7.0
|
margin_top = 7.0
|
||||||
|
|
Loading…
Add table
Reference in a new issue