1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-31 07:29:49 +00:00

UndoRedo vol 6 - Scale Image now has undo/redo

This commit is contained in:
OverloadedOrama 2019-11-04 21:54:39 +02:00
parent 4ba2f3280a
commit 18d109f959
2 changed files with 28 additions and 14 deletions

View file

@ -162,19 +162,27 @@ func find_node_by_name(root, node_name) -> Node:
return found return found
return null return null
func undo(canvas : Canvas, layer_index : int) -> void: func undo(canvas : Canvas, layer_index : int = -1) -> void:
undos -= 1 undos -= 1
var action_name : String = undo_redo.get_current_action_name() var action_name : String = undo_redo.get_current_action_name()
if action_name == "Draw" || action_name == "Rectangle Select": if action_name == "Draw" || action_name == "Rectangle Select" || action_name == "Scale":
canvas.update_texture(layer_index) if layer_index > -1:
canvas.update_texture(layer_index)
else:
for i in canvas.layers.size():
canvas.update_texture(i)
print("Undo: ", action_name) print("Undo: ", action_name)
func redo(canvas : Canvas, layer_index : int) -> void: func redo(canvas : Canvas, layer_index : int = -1) -> void:
if undos < undo_redo.get_version(): #If we did undo and then redo if undos < undo_redo.get_version(): #If we did undo and then redo
undos = undo_redo.get_version() undos = undo_redo.get_version()
var action_name : String = undo_redo.get_current_action_name() var action_name : String = undo_redo.get_current_action_name()
if action_name == "Draw" || action_name == "Rectangle Select": if action_name == "Draw" || action_name == "Rectangle Select" || action_name == "Scale":
canvas.update_texture(layer_index) if layer_index > -1:
canvas.update_texture(layer_index)
else:
for i in canvas.layers.size():
canvas.update_texture(i)
print("Redo: ", action_name) print("Redo: ", action_name)
func change_frame() -> void: func change_frame() -> void:

View file

@ -497,15 +497,21 @@ func _on_ScaleImage_confirmed() -> void:
var width = $ScaleImage/VBoxContainer/WidthCont/WidthValue.value var width = $ScaleImage/VBoxContainer/WidthCont/WidthValue.value
var height = $ScaleImage/VBoxContainer/HeightCont/HeightValue.value var height = $ScaleImage/VBoxContainer/HeightCont/HeightValue.value
var interpolation = $ScaleImage/VBoxContainer/InterpolationContainer/InterpolationType.selected var interpolation = $ScaleImage/VBoxContainer/InterpolationContainer/InterpolationType.selected
for i in range(Global.canvas.layers.size() - 1, -1, -1): Global.undos += 1
var sprite := Image.new() Global.undo_redo.create_action("Scale")
sprite = Global.canvas.layers[i][1].get_data() Global.undo_redo.add_do_property(Global.canvas, "size", Vector2(width, height).floor())
sprite.resize(width, height, interpolation)
Global.canvas.layers[i][0] = sprite
Global.canvas.layers[i][0].lock()
Global.canvas.update_texture(i)
Global.canvas.size = Vector2(width, height).floor() for i in range(Global.canvas.layers.size() - 1, -1, -1):
var sprite : Image = Global.canvas.layers[i][1].get_data()
sprite.resize(width, height, interpolation)
Global.undo_redo.add_do_property(Global.canvas.layers[i][0], "data", sprite.data)
Global.undo_redo.add_undo_property(Global.canvas.layers[i][0], "data", Global.canvas.layers[i][0].data)
Global.canvas.layers[i][0].lock()
Global.undo_redo.add_undo_property(Global.canvas, "size", Global.canvas.size)
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()
Global.canvas.camera_zoom() Global.canvas.camera_zoom()
func add_layer(is_new := true) -> void: func add_layer(is_new := true) -> void: