Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cut option #345

Merged
merged 2 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
20 changes: 20 additions & 0 deletions src/SelectionRectangle.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 7 additions & 4 deletions src/UI/TopMenuContainer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down