From 64eb4f27ceb252ff3a10d1b38a5910d91d228ed1 Mon Sep 17 00:00:00 2001 From: PinyaColada <72302480+PinyaColada@users.noreply.github.com> Date: Thu, 8 Oct 2020 17:05:33 +0200 Subject: [PATCH] Cut option (#345) * I Made the cut function, his respective shortcut and the appearence of the function in the top bar in edit. * Update Main.tscn --- project.godot | 5 +++++ src/SelectionRectangle.gd | 20 ++++++++++++++++++++ src/UI/TopMenuContainer.gd | 11 +++++++---- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/project.godot b/project.godot index 1423a953d..fdfc97db4 100644 --- a/project.godot +++ b/project.godot @@ -414,6 +414,11 @@ open_docs={ "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777255,"unicode":0,"echo":false,"script":null) ] } +cut={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":true,"meta":false,"command":true,"pressed":false,"scancode":88,"unicode":0,"echo":false,"script":null) + ] +} [locale] diff --git a/src/SelectionRectangle.gd b/src/SelectionRectangle.gd index 817130c8b..c8072d618 100644 --- a/src/SelectionRectangle.gd +++ b/src/SelectionRectangle.gd @@ -116,6 +116,26 @@ func copy() -> void: project.brushes.append(brush) Brushes.add_project_brush(brush) +func cut() -> void: # This is basically the same as copy + delete + if _selected_rect.has_no_area(): + return + + var undo_data = _get_undo_data(true) + var project := Global.current_project + var image : Image = project.frames[project.current_frame].cels[project.current_layer].image + var size := _selected_rect.size + var rect = Rect2(Vector2.ZERO, size) + _clipboard = image.get_rect(_selected_rect) + if _clipboard.is_invisible(): + return + + _clear_image.resize(size.x, size.y, Image.INTERPOLATE_NEAREST) + var brush = _clipboard.get_rect(_clipboard.get_used_rect()) + project.brushes.append(brush) + Brushes.add_project_brush(brush) + Global.selection_rectangle.move_end() #The selection_rectangle can be used while is moved, this prevents malfunctioning + image.blit_rect(_clear_image, rect, _selected_rect.position) + commit_undo("Draw", undo_data) func paste() -> void: if _clipboard.get_size() <= Vector2.ZERO: diff --git a/src/UI/TopMenuContainer.gd b/src/UI/TopMenuContainer.gd index c211f89ce..8caa649cc 100644 --- a/src/UI/TopMenuContainer.gd +++ b/src/UI/TopMenuContainer.gd @@ -43,6 +43,7 @@ func setup_edit_menu() -> void: "Undo" : InputMap.get_action_list("undo")[0].get_scancode_with_modifiers(), "Redo" : InputMap.get_action_list("redo")[0].get_scancode_with_modifiers(), "Copy" : InputMap.get_action_list("copy")[0].get_scancode_with_modifiers(), + "Cut" : InputMap.get_action_list("cut")[0].get_scancode_with_modifiers(), "Paste" : InputMap.get_action_list("paste")[0].get_scancode_with_modifiers(), "Delete" : InputMap.get_action_list("delete")[0].get_scancode_with_modifiers(), "Clear Selection" : 0, @@ -211,14 +212,16 @@ func edit_menu_id_pressed(id : int) -> void: Global.control.redone = false 2: # Copy Global.selection_rectangle.copy() - 3: # paste + 3: # cut + Global.selection_rectangle.cut() + 4: # paste Global.selection_rectangle.paste() - 4: # Delete + 5: # Delete Global.selection_rectangle.delete() - 5: # Clear selection + 6: # Clear selection Global.selection_rectangle.set_rect(Rect2(0, 0, 0, 0)) Global.selection_rectangle.select_rect() - 6: # Preferences + 7: # Preferences Global.preferences_dialog.popup_centered(Vector2(400, 280)) Global.dialog_open(true)