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

UndoRedo vol 11 - Remove custom brush has UndoRedo

- Removing a custom brush can now be undone and redone.
- Fixed custom brush symmetry on mirrored drawing
This commit is contained in:
OverloadedOrama 2019-11-11 18:41:43 +02:00
parent 5896d1f06d
commit e6bd897d1f
3 changed files with 41 additions and 11 deletions

View file

@ -35,15 +35,26 @@ func _on_DeleteButton_pressed() -> void:
remove_child(Global.right_brush_indicator) remove_child(Global.right_brush_indicator)
file_hbox_container.get_child(0).add_child(Global.right_brush_indicator) file_hbox_container.get_child(0).add_child(Global.right_brush_indicator)
Global.undos += 1
Global.undo_redo.create_action("Delete Custom Brush")
for i in range(custom_brush_index - 1, custom_hbox_container.get_child_count()): for i in range(custom_brush_index - 1, custom_hbox_container.get_child_count()):
if Global.custom_left_brush_index == custom_hbox_container.get_child(i).custom_brush_index: var bb = custom_hbox_container.get_child(i)
if Global.custom_left_brush_index == bb.custom_brush_index:
Global.custom_left_brush_index -= 1 Global.custom_left_brush_index -= 1
if Global.custom_right_brush_index == custom_hbox_container.get_child(i).custom_brush_index: if Global.custom_right_brush_index == bb.custom_brush_index:
Global.custom_right_brush_index -= 1 Global.custom_right_brush_index -= 1
custom_hbox_container.get_child(i).custom_brush_index -= 1
Global.custom_brushes.remove(custom_brush_index) Global.undo_redo.add_do_property(bb, "custom_brush_index", bb.custom_brush_index - 1)
queue_free() Global.undo_redo.add_undo_property(bb, "custom_brush_index", bb.custom_brush_index)
var custom_brushes := Global.custom_brushes.duplicate()
custom_brushes.remove(custom_brush_index)
Global.undo_redo.add_do_property(Global, "custom_brushes", custom_brushes)
Global.undo_redo.add_undo_property(Global, "custom_brushes", Global.custom_brushes)
Global.undo_redo.add_do_method(Global, "redo_custom_brush", self)
Global.undo_redo.add_undo_method(Global, "undo_custom_brush", self)
Global.undo_redo.commit_action()
func _on_BrushButton_mouse_entered() -> void: func _on_BrushButton_mouse_entered() -> void:
if brush_type == Global.BRUSH_TYPES.CUSTOM: if brush_type == Global.BRUSH_TYPES.CUSTOM:

View file

@ -537,8 +537,8 @@ func draw_pixel(pos : Vector2, color : Color, current_mouse_button : String) ->
src_rect.size.y = min(src_rect.size.y, selection_rect.size.y) src_rect.size.y = min(src_rect.size.y, selection_rect.size.y)
#Handle mirroring #Handle mirroring
var mirror_x := east_limit + west_limit - dst.x - 1 var mirror_x := east_limit + west_limit - pos.x - (pos.x - dst.x) - 1
var mirror_y := south_limit + north_limit - dst.y - 1 var mirror_y := south_limit + north_limit - pos.y - (pos.y - dst.y) - 1
if color.a > 0: #If it's the pencil if color.a > 0: #If it's the pencil
layers[current_layer_index][0].blend_rect(custom_brush_image, src_rect, dst) layers[current_layer_index][0].blend_rect(custom_brush_image, src_rect, dst)

View file

@ -167,7 +167,7 @@ func find_node_by_name(root, node_name) -> Node:
func undo(_canvases : Array, layer_index : int = -1) -> void: func undo(_canvases : Array, layer_index : int = -1) -> void:
undos -= 1 undos -= 1
var action_name : String = undo_redo.get_current_action_name() var action_name := undo_redo.get_current_action_name()
if action_name == "Draw" || action_name == "Rectangle Select" || action_name == "Scale" || action_name == "Merge Layer": if action_name == "Draw" || action_name == "Rectangle Select" || action_name == "Scale" || action_name == "Merge Layer":
for c in _canvases: for c in _canvases:
if layer_index > -1: if layer_index > -1:
@ -207,7 +207,7 @@ func undo(_canvases : Array, layer_index : int = -1) -> void:
func redo(_canvases : Array, layer_index : int = -1) -> void: func redo(_canvases : Array, 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 := undo_redo.get_current_action_name()
if action_name == "Draw" || action_name == "Rectangle Select" || action_name == "Scale" || action_name == "Merge Layer": if action_name == "Draw" || action_name == "Rectangle Select" || action_name == "Scale" || action_name == "Merge Layer":
for c in _canvases: for c in _canvases:
if layer_index > -1: if layer_index > -1:
@ -292,8 +292,27 @@ func remove_brush_buttons() -> void:
current_right_brush_type = BRUSH_TYPES.PIXEL current_right_brush_type = BRUSH_TYPES.PIXEL
var hbox_container := find_node_by_name(get_tree().get_root(), "CustomBrushHBoxContainer") var hbox_container := find_node_by_name(get_tree().get_root(), "CustomBrushHBoxContainer")
for child in hbox_container.get_children(): for child in hbox_container.get_children():
if child.name != "PixelBrushButton": child.queue_free()
hbox_container.remove_child(child) #hbox_container.remove_child(child)
func undo_custom_brush(_brush_button : Button = null) -> void:
undos -= 1
var action_name := undo_redo.get_current_action_name()
var hbox_container := find_node_by_name(get_tree().get_root(), "CustomBrushHBoxContainer")
if action_name == "Delete Custom Brush":
hbox_container.add_child(_brush_button)
hbox_container.move_child(_brush_button, _brush_button.custom_brush_index - brushes_from_files)
_brush_button.get_node("DeleteButton").visible = false
print("Undo: ", action_name)
func redo_custom_brush(_brush_button : Button = null) -> void:
if undos < undo_redo.get_version(): #If we did undo and then redo
undos = undo_redo.get_version()
var action_name := undo_redo.get_current_action_name()
var hbox_container := find_node_by_name(get_tree().get_root(), "CustomBrushHBoxContainer")
if action_name == "Delete Custom Brush":
hbox_container.remove_child(_brush_button)
print("Redo: ", action_name)
func update_left_custom_brush() -> void: func update_left_custom_brush() -> void:
if custom_left_brush_index > -1: if custom_left_brush_index > -1: