From a77cc0544687a7df295527e5c257d843beffd062 Mon Sep 17 00:00:00 2001 From: Manolis Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Tue, 25 May 2021 22:48:37 +0300 Subject: [PATCH] Made brush creation from selection a separate menu option Also works with Ctrl+B. Copying no longer creates a project brush. --- Translations/Translations.pot | 3 +++ project.godot | 5 +++++ src/UI/Canvas/Selection.gd | 38 +++++++++++++++++++++++++++++++---- src/UI/TopMenuContainer.gd | 5 ++++- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/Translations/Translations.pot b/Translations/Translations.pot index 975e911b9..42f2605da 100644 --- a/Translations/Translations.pot +++ b/Translations/Translations.pot @@ -118,6 +118,9 @@ msgstr "" msgid "Delete" msgstr "" +msgid "New Brush" +msgstr "" + msgid "Scale Image" msgstr "" diff --git a/project.godot b/project.godot index 35781a47d..e32b6233d 100644 --- a/project.godot +++ b/project.godot @@ -596,6 +596,11 @@ right_polygon_select_tool={ "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":true,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":75,"unicode":0,"echo":false,"script":null) ] } +new_brush={ +"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":66,"unicode":0,"echo":false,"script":null) + ] +} [locale] diff --git a/src/UI/Canvas/Selection.gd b/src/UI/Canvas/Selection.gd index d1dc96055..c3bae5cb1 100644 --- a/src/UI/Canvas/Selection.gd +++ b/src/UI/Canvas/Selection.gd @@ -567,10 +567,6 @@ func copy() -> void: clipboard.big_bounding_rectangle = big_bounding_rectangle clipboard.selection_offset = project.selection_offset - var brush : Image = to_copy.get_rect(to_copy.get_used_rect()) - project.brushes.append(brush) - Brushes.add_project_brush(brush) - func paste() -> void: if !clipboard.image: @@ -620,6 +616,40 @@ func delete() -> void: commit_undo("Draw", _undo_data) +func new_brush() -> void: + var project := Global.current_project + if !project.has_selection: + return + + var image : Image = project.frames[project.current_frame].cels[project.current_layer].image + var brush := Image.new() + if is_moving_content: + brush.copy_from(preview_image) + var selected_bitmap_copy := project.selection_bitmap.duplicate() + project.move_bitmap_values(selected_bitmap_copy, false) + clipboard.selection_bitmap = selected_bitmap_copy + else: + brush = image.get_rect(big_bounding_rectangle) + brush.lock() + # Remove unincluded pixels if the selection is not a single rectangle + for x in brush.get_size().x: + for y in brush.get_size().y: + var pos := Vector2(x, y) + var offset_pos = big_bounding_rectangle.position + if offset_pos.x < 0: + offset_pos.x = 0 + if offset_pos.y < 0: + offset_pos.y = 0 + if not project.selection_bitmap.get_bit(pos + offset_pos): + brush.set_pixelv(pos, Color(0)) + brush.unlock() + + if !brush.is_invisible(): + var brush_used : Image = brush.get_rect(brush.get_used_rect()) + project.brushes.append(brush_used) + Brushes.add_project_brush(brush_used) + + func select_all() -> void: var project := Global.current_project var _undo_data = _get_undo_data(false) diff --git a/src/UI/TopMenuContainer.gd b/src/UI/TopMenuContainer.gd index c937a7385..931d20ea2 100644 --- a/src/UI/TopMenuContainer.gd +++ b/src/UI/TopMenuContainer.gd @@ -2,7 +2,7 @@ extends Panel enum FileMenuId {NEW, OPEN, OPEN_LAST_PROJECT, SAVE, SAVE_AS, EXPORT, EXPORT_AS, QUIT} -enum EditMenuId {UNDO, REDO, COPY, CUT, PASTE, DELETE, PREFERENCES} +enum EditMenuId {UNDO, REDO, COPY, CUT, PASTE, DELETE, NEW_BRUSH, PREFERENCES} enum ViewMenuId {TILE_MODE, WINDOW_TRANSPARENCY, PANEL_LAYOUT, MIRROR_VIEW, SHOW_GRID, SHOW_PIXEL_GRID, SHOW_RULERS, SHOW_GUIDES, SHOW_ANIMATION_TIMELINE, ZEN_MODE, FULLSCREEN_MODE} enum ImageMenuId {SCALE_IMAGE, CENTRALIZE_IMAGE, CROP_IMAGE, RESIZE_CANVAS, FLIP, ROTATE, INVERT_COLORS, DESATURATION, OUTLINE, HSV, GRADIENT, SHADER} enum SelectMenuId {SELECT_ALL, CLEAR_SELECTION, INVERT} @@ -81,6 +81,7 @@ func setup_edit_menu() -> void: "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(), + "New Brush" : InputMap.get_action_list("new_brush")[0].get_scancode_with_modifiers(), "Preferences" : 0 } var edit_menu : PopupMenu = edit_menu_button.get_popup() @@ -305,6 +306,8 @@ func edit_menu_id_pressed(id : int) -> void: Global.canvas.selection.paste() EditMenuId.DELETE: Global.canvas.selection.delete() + EditMenuId.NEW_BRUSH: + Global.canvas.selection.new_brush() EditMenuId.PREFERENCES: Global.preferences_dialog.popup_centered(Vector2(400, 280)) Global.dialog_open(true)