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

Camera zoom and offset are now project properites

The zoom/offset of the three cameras now get saved in each project, and change when you change project.
This commit is contained in:
OverloadedOrama 2020-06-05 21:03:34 +03:00
parent 9ffce37c0b
commit 2c409ab025
4 changed files with 34 additions and 13 deletions

View file

@ -124,6 +124,7 @@ func _input(event : InputEvent) -> void:
Global.horizontal_ruler.update()
Global.vertical_ruler.update()
save_values_to_project()
# Zoom Camera
@ -185,3 +186,15 @@ func fit_to_frame(size : Vector2) -> void:
Global.zoom_level_label.text = str(round(100 / Global.camera.zoom.x)) + " %"
Global.horizontal_ruler.update()
Global.vertical_ruler.update()
func save_values_to_project() -> void:
if name == "Camera2D":
Global.current_project.cameras_zoom[0] = zoom
Global.current_project.cameras_offset[0] = offset
if name == "Camera2D2":
Global.current_project.cameras_zoom[1] = zoom
Global.current_project.cameras_offset[1] = offset
if name == "CameraPreview":
Global.current_project.cameras_zoom[2] = zoom
Global.current_project.cameras_offset[2] = offset

View file

@ -230,18 +230,15 @@ func camera_zoom() -> void:
# Set camera zoom based on the sprite size
var bigger_canvas_axis = max(Global.current_project.size.x, Global.current_project.size.y)
var zoom_max := Vector2(bigger_canvas_axis, bigger_canvas_axis) * 0.01
var cameras = [Global.camera, Global.camera2, Global.camera_preview]
for camera in cameras:
if zoom_max > Vector2.ONE:
Global.camera.zoom_max = zoom_max
Global.camera2.zoom_max = zoom_max
Global.camera_preview.zoom_max = zoom_max
camera.zoom_max = zoom_max
else:
Global.camera.zoom_max = Vector2.ONE
Global.camera2.zoom_max = Vector2.ONE
Global.camera_preview.zoom_max = Vector2.ONE
camera.zoom_max = Vector2.ONE
Global.camera.fit_to_frame(Global.current_project.size)
Global.camera2.fit_to_frame(Global.current_project.size)
Global.camera_preview.fit_to_frame(Global.current_project.size)
camera.fit_to_frame(Global.current_project.size)
camera.save_values_to_project()
Global.transparent_checker._ready() # To update the rect size

View file

@ -22,6 +22,10 @@ var x_max := 64
var y_min := 0
var y_max := 64
# For every camera (currently there are 3)
var cameras_zoom := [Vector2(0.15, 0.15), Vector2(0.15, 0.15), Vector2(0.15, 0.15)] # Array of Vector2
var cameras_offset := [Vector2.ZERO, Vector2.ZERO, Vector2.ZERO] # Array of Vector2
func _init(_frames := [], _name := tr("untitled"), _size := Vector2(64, 64)) -> void:
frames = _frames
@ -115,6 +119,13 @@ func change_project() -> void:
for brush in brushes:
Global.create_brush_button(brush)
var cameras = [Global.camera, Global.camera2, Global.camera_preview]
var i := 0
for camera in cameras:
camera.zoom = cameras_zoom[i]
camera.offset = cameras_offset[i]
i += 1
Global.zoom_level_label.text = str(round(100 / Global.camera.zoom.x)) + " %"
Global.canvas.update()
Global.transparent_checker._ready()
Global.window_title = "%s - Pixelorama %s" % [name, Global.current_version]

View file

@ -6,7 +6,7 @@ func _on_Tabs_tab_changed(tab : int) -> void:
func _on_Tabs_tab_close(tab : int) -> void:
if Global.projects.size() == 1:
if Global.projects.size() == 1 or Global.current_project_index != tab:
return
if Global.current_project.has_changed:
@ -26,7 +26,7 @@ func _on_Tabs_reposition_active_tab_request(idx_to : int) -> void:
func delete_tab(tab : int) -> void:
remove_tab(tab)
Global.current_project.undo_redo.free()
Global.projects[tab].undo_redo.free()
Global.projects.remove(tab)
if tab > 0:
Global.current_project_index -= 1