mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 01:29:49 +00:00
953d002d91
Trying to merge layers into the timeline, and eventually add more features like "share layer with all frames", among others. THIS IS NOT FINISHED, IT WILL *NOT* WORK PROPERLY. Once it is finished, this branch will be merged onto master. So far only add layer and add frame work, and even they may have some issues. Undoing also does not work properly yet. The UI is also not finished, as it currently has problems with the scroll containers.
243 lines
9.5 KiB
GDScript
243 lines
9.5 KiB
GDScript
extends Panel
|
|
|
|
var fps := 6.0
|
|
var animation_loop := 0 # 0 is no loop, 1 is cycle loop, 2 is ping-pong loop
|
|
var animation_forward := true
|
|
|
|
func add_frame() -> void:
|
|
var new_canvas : Canvas = load("res://Prefabs/Canvas.tscn").instance()
|
|
new_canvas.size = Global.canvas.size
|
|
new_canvas.frame = Global.canvases.size()
|
|
|
|
var new_canvases: Array = Global.canvases.duplicate()
|
|
new_canvases.append(new_canvas)
|
|
var new_hidden_canvases: Array = Global.hidden_canvases.duplicate()
|
|
new_hidden_canvases.append(new_canvas)
|
|
|
|
Global.undos += 1
|
|
Global.undo_redo.create_action("Add Frame")
|
|
Global.undo_redo.add_do_method(Global, "redo", [new_canvas])
|
|
Global.undo_redo.add_undo_method(Global, "undo", [new_canvas])
|
|
|
|
Global.undo_redo.add_do_property(Global, "canvases", new_canvases)
|
|
Global.undo_redo.add_do_property(Global, "hidden_canvases", Global.hidden_canvases)
|
|
Global.undo_redo.add_do_property(Global, "canvas", new_canvas)
|
|
Global.undo_redo.add_do_property(Global, "current_frame", new_canvases.size() - 1)
|
|
for i in range(Global.layers.size()):
|
|
for child in Global.layers[i][1].get_children():
|
|
Global.undo_redo.add_do_property(child, "pressed", false)
|
|
Global.undo_redo.add_undo_property(child, "pressed", child.pressed)
|
|
for c in Global.canvases:
|
|
Global.undo_redo.add_do_property(c, "visible", false)
|
|
Global.undo_redo.add_undo_property(c, "visible", c.visible)
|
|
|
|
Global.undo_redo.add_undo_property(Global, "canvases", Global.canvases)
|
|
Global.undo_redo.add_undo_property(Global, "hidden_canvases", new_hidden_canvases)
|
|
Global.undo_redo.add_undo_property(Global, "canvas", Global.canvas)
|
|
Global.undo_redo.add_undo_property(Global, "current_frame", Global.current_frame)
|
|
Global.undo_redo.commit_action()
|
|
|
|
func _on_LoopAnim_pressed() -> void:
|
|
match animation_loop:
|
|
0: # Make it loop
|
|
animation_loop = 1
|
|
Global.loop_animation_button.texture_normal = load("res://Assets/Graphics/%s Themes/Timeline/Loop.png" % Global.theme_type)
|
|
Global.loop_animation_button.hint_tooltip = "Cycle loop"
|
|
1: # Make it ping-pong
|
|
animation_loop = 2
|
|
Global.loop_animation_button.texture_normal = load("res://Assets/Graphics/%s Themes/Timeline/Loop_PingPong.png" % Global.theme_type)
|
|
Global.loop_animation_button.hint_tooltip = "Ping-pong loop"
|
|
2: # Make it stop
|
|
animation_loop = 0
|
|
Global.loop_animation_button.texture_normal = load("res://Assets/Graphics/%s Themes/Timeline/Loop_None.png" % Global.theme_type)
|
|
Global.loop_animation_button.hint_tooltip = "No loop"
|
|
|
|
func _on_PlayForward_toggled(button_pressed : bool) -> void:
|
|
Global.play_backwards.pressed = false
|
|
if Global.canvases.size() == 1:
|
|
Global.play_forward.pressed = false
|
|
return
|
|
|
|
if button_pressed:
|
|
Global.animation_timer.wait_time = 1 / fps
|
|
Global.animation_timer.start()
|
|
animation_forward = true
|
|
else:
|
|
Global.animation_timer.stop()
|
|
|
|
func _on_PlayBackwards_toggled(button_pressed : bool) -> void:
|
|
Global.play_forward.pressed = false
|
|
if Global.canvases.size() == 1:
|
|
Global.play_backwards.pressed = false
|
|
return
|
|
|
|
if button_pressed:
|
|
Global.animation_timer.wait_time = 1 / fps
|
|
Global.animation_timer.start()
|
|
animation_forward = false
|
|
else:
|
|
Global.animation_timer.stop()
|
|
|
|
func _on_NextFrame_pressed() -> void:
|
|
if Global.current_frame < Global.canvases.size() - 1:
|
|
Global.current_frame += 1
|
|
|
|
func _on_PreviousFrame_pressed() -> void:
|
|
if Global.current_frame > 0:
|
|
Global.current_frame -= 1
|
|
|
|
func _on_LastFrame_pressed() -> void:
|
|
Global.current_frame = Global.canvases.size() - 1
|
|
|
|
func _on_FirstFrame_pressed() -> void:
|
|
Global.current_frame = 0
|
|
|
|
func _on_AnimationTimer_timeout() -> void:
|
|
if animation_forward:
|
|
if Global.current_frame < Global.canvases.size() - 1:
|
|
Global.current_frame += 1
|
|
else:
|
|
match animation_loop:
|
|
0: # No loop
|
|
Global.play_forward.pressed = false
|
|
Global.play_backwards.pressed = false
|
|
Global.animation_timer.stop()
|
|
1: # Cycle loop
|
|
Global.current_frame = 0
|
|
2: # Ping pong loop
|
|
animation_forward = false
|
|
_on_AnimationTimer_timeout()
|
|
|
|
else:
|
|
if Global.current_frame > 0:
|
|
Global.current_frame -= 1
|
|
else:
|
|
match animation_loop:
|
|
0: # No loop
|
|
Global.play_backwards.pressed = false
|
|
Global.play_forward.pressed = false
|
|
Global.animation_timer.stop()
|
|
1: # Cycle loop
|
|
Global.current_frame = Global.canvases.size() - 1
|
|
2: # Ping pong loop
|
|
animation_forward = true
|
|
_on_AnimationTimer_timeout()
|
|
|
|
func _on_FPSValue_value_changed(value) -> void:
|
|
fps = float(value)
|
|
Global.animation_timer.wait_time = 1 / fps
|
|
Global.timeline_seconds.update()
|
|
|
|
func _on_PastOnionSkinning_value_changed(value) -> void:
|
|
Global.onion_skinning_past_rate = int(value)
|
|
Global.canvas.update()
|
|
|
|
func _on_FutureOnionSkinning_value_changed(value) -> void:
|
|
Global.onion_skinning_future_rate = int(value)
|
|
Global.canvas.update()
|
|
|
|
func _on_BlueRedMode_toggled(button_pressed) -> void:
|
|
Global.onion_skinning_blue_red = button_pressed
|
|
Global.canvas.update()
|
|
|
|
# Layer buttons
|
|
|
|
func add_layer(is_new := true) -> void:
|
|
var new_layer := Image.new()
|
|
var layer_name = null
|
|
if is_new:
|
|
new_layer.create(Global.canvas.size.x, Global.canvas.size.y, false, Image.FORMAT_RGBA8)
|
|
else: # clone layer
|
|
new_layer.copy_from(Global.canvas.layers[Global.current_layer][0])
|
|
layer_name = Global.canvas.layers[Global.current_layer][2] + " (" + tr("copy") + ")"
|
|
new_layer.lock()
|
|
var new_layer_tex := ImageTexture.new()
|
|
new_layer_tex.create_from_image(new_layer, 0)
|
|
|
|
var new_layers : Array = Global.layers.duplicate()
|
|
|
|
# Store [layer name, frame container]
|
|
new_layers.append([layer_name, HBoxContainer.new()])
|
|
|
|
Global.undos += 1
|
|
Global.undo_redo.create_action("Add Layer")
|
|
Global.undo_redo.add_do_property(Global, "current_layer", Global.current_layer + 1)
|
|
Global.undo_redo.add_do_property(Global, "layers", new_layers)
|
|
|
|
for c in Global.canvases:
|
|
var new_canvas_layers : Array = c.layers.duplicate()
|
|
# Store [Image, ImageTexture, Visibity boolean, Opacity]
|
|
new_canvas_layers.append([new_layer, new_layer_tex, true, 1])
|
|
Global.undo_redo.add_do_property(c, "layers", new_canvas_layers)
|
|
Global.undo_redo.add_undo_property(c, "layers", c.layers)
|
|
|
|
Global.undo_redo.add_undo_property(Global, "current_layer", Global.current_layer)
|
|
Global.undo_redo.add_undo_property(Global, "layers", Global.layers)
|
|
|
|
Global.undo_redo.add_undo_method(Global, "undo", [Global.canvas])
|
|
Global.undo_redo.add_do_method(Global, "redo", [Global.canvas])
|
|
Global.undo_redo.commit_action()
|
|
|
|
func _on_RemoveLayer_pressed() -> void:
|
|
var new_layers : Array = Global.canvas.layers.duplicate()
|
|
new_layers.remove(Global.canvas.current_layer_index)
|
|
Global.undos += 1
|
|
Global.undo_redo.create_action("Remove Layer")
|
|
Global.undo_redo.add_do_property(Global.canvas, "layers", new_layers)
|
|
Global.undo_redo.add_undo_property(Global.canvas, "layers", Global.canvas.layers)
|
|
|
|
Global.undo_redo.add_undo_method(Global, "undo", [Global.canvas])
|
|
Global.undo_redo.add_do_method(Global, "redo", [Global.canvas])
|
|
Global.undo_redo.commit_action()
|
|
|
|
func change_layer_order(rate : int) -> void:
|
|
var change = Global.canvas.current_layer_index + rate
|
|
|
|
var new_layers : Array = Global.canvas.layers.duplicate()
|
|
var temp = new_layers[Global.canvas.current_layer_index]
|
|
new_layers[Global.canvas.current_layer_index] = new_layers[change]
|
|
new_layers[change] = temp
|
|
Global.undo_redo.create_action("Change Layer Order")
|
|
Global.undo_redo.add_do_property(Global.canvas, "layers", new_layers)
|
|
Global.undo_redo.add_do_property(Global.canvas, "current_layer_index", change)
|
|
Global.undo_redo.add_undo_property(Global.canvas, "layers", Global.canvas.layers)
|
|
Global.undo_redo.add_undo_property(Global.canvas, "current_layer_index", Global.canvas.current_layer_index)
|
|
|
|
Global.undo_redo.add_undo_method(Global, "undo", [Global.canvas])
|
|
Global.undo_redo.add_do_method(Global, "redo", [Global.canvas])
|
|
Global.undo_redo.commit_action()
|
|
|
|
func _on_MergeDownLayer_pressed() -> void:
|
|
var new_layers : Array = Global.canvas.layers.duplicate()
|
|
new_layers.remove(Global.canvas.current_layer_index)
|
|
var selected_layer = Global.canvas.layers[Global.canvas.current_layer_index][0]
|
|
if Global.canvas.layers[Global.canvas.current_layer_index][4] < 1: # If we have layer transparency
|
|
for xx in selected_layer.get_size().x:
|
|
for yy in selected_layer.get_size().y:
|
|
var pixel_color : Color = selected_layer.get_pixel(xx, yy)
|
|
var alpha : float = pixel_color.a * Global.canvas.layers[Global.canvas.current_layer_index][4]
|
|
selected_layer.set_pixel(xx, yy, Color(pixel_color.r, pixel_color.g, pixel_color.b, alpha))
|
|
|
|
var new_layer := Image.new()
|
|
new_layer.copy_from(Global.canvas.layers[Global.canvas.current_layer_index - 1][0])
|
|
new_layer.lock()
|
|
|
|
Global.canvas.blend_rect(new_layer, selected_layer, Rect2(Global.canvas.position, Global.canvas.size), Vector2.ZERO)
|
|
|
|
Global.undos += 1
|
|
Global.undo_redo.create_action("Merge Layer")
|
|
Global.undo_redo.add_do_property(Global.canvas, "layers", new_layers)
|
|
Global.undo_redo.add_do_property(Global.canvas.layers[Global.canvas.current_layer_index - 1][0], "data", new_layer.data)
|
|
Global.undo_redo.add_undo_property(Global.canvas, "layers", Global.canvas.layers)
|
|
Global.undo_redo.add_undo_property(Global.canvas.layers[Global.canvas.current_layer_index - 1][0], "data", Global.canvas.layers[Global.canvas.current_layer_index - 1][0].data)
|
|
|
|
Global.undo_redo.add_undo_method(Global, "undo", [Global.canvas])
|
|
Global.undo_redo.add_do_method(Global, "redo", [Global.canvas])
|
|
Global.undo_redo.commit_action()
|
|
|
|
func _on_OpacitySlider_value_changed(value) -> void:
|
|
Global.canvas.layers[Global.current_layer][3] = value / 100
|
|
Global.layer_opacity_slider.value = value
|
|
Global.layer_opacity_spinbox.value = value
|
|
Global.canvas.update()
|