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:
parent
4ba2f3280a
commit
18d109f959
|
@ -162,19 +162,27 @@ func find_node_by_name(root, node_name) -> Node:
|
|||
return found
|
||||
return null
|
||||
|
||||
func undo(canvas : Canvas, layer_index : int) -> void:
|
||||
func undo(canvas : Canvas, layer_index : int = -1) -> void:
|
||||
undos -= 1
|
||||
var action_name : String = undo_redo.get_current_action_name()
|
||||
if action_name == "Draw" || action_name == "Rectangle Select":
|
||||
canvas.update_texture(layer_index)
|
||||
if action_name == "Draw" || action_name == "Rectangle Select" || action_name == "Scale":
|
||||
if layer_index > -1:
|
||||
canvas.update_texture(layer_index)
|
||||
else:
|
||||
for i in canvas.layers.size():
|
||||
canvas.update_texture(i)
|
||||
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
|
||||
undos = undo_redo.get_version()
|
||||
var action_name : String = undo_redo.get_current_action_name()
|
||||
if action_name == "Draw" || action_name == "Rectangle Select":
|
||||
canvas.update_texture(layer_index)
|
||||
if action_name == "Draw" || action_name == "Rectangle Select" || action_name == "Scale":
|
||||
if layer_index > -1:
|
||||
canvas.update_texture(layer_index)
|
||||
else:
|
||||
for i in canvas.layers.size():
|
||||
canvas.update_texture(i)
|
||||
print("Redo: ", action_name)
|
||||
|
||||
func change_frame() -> void:
|
||||
|
|
|
@ -497,15 +497,21 @@ func _on_ScaleImage_confirmed() -> void:
|
|||
var width = $ScaleImage/VBoxContainer/WidthCont/WidthValue.value
|
||||
var height = $ScaleImage/VBoxContainer/HeightCont/HeightValue.value
|
||||
var interpolation = $ScaleImage/VBoxContainer/InterpolationContainer/InterpolationType.selected
|
||||
for i in range(Global.canvas.layers.size() - 1, -1, -1):
|
||||
var sprite := Image.new()
|
||||
sprite = Global.canvas.layers[i][1].get_data()
|
||||
sprite.resize(width, height, interpolation)
|
||||
Global.canvas.layers[i][0] = sprite
|
||||
Global.canvas.layers[i][0].lock()
|
||||
Global.canvas.update_texture(i)
|
||||
Global.undos += 1
|
||||
Global.undo_redo.create_action("Scale")
|
||||
Global.undo_redo.add_do_property(Global.canvas, "size", Vector2(width, height).floor())
|
||||
|
||||
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()
|
||||
|
||||
func add_layer(is_new := true) -> void:
|
||||
|
|
Loading…
Reference in a new issue