From 0d6b140dea53940314eb3a8cdd78af2ea7ef2c59 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Fri, 15 Nov 2024 01:41:44 +0200 Subject: [PATCH] Add border selection, fix some missing translation strings --- Translations/Translations.pot | 37 +++++++++++++++++++ src/Classes/SelectionMap.gd | 22 ++++++++--- src/Shaders/Effects/OutlineInline.gdshader | 14 ++++--- src/UI/Dialogs/ImageEffects/OutlineDialog.gd | 2 +- .../Dialogs/ImageEffects/OutlineDialog.tscn | 5 +-- src/UI/Dialogs/ModifySelection.gd | 10 +++-- src/UI/TopMenuContainer/TopMenuContainer.gd | 1 + 7 files changed, 74 insertions(+), 17 deletions(-) diff --git a/Translations/Translations.pot b/Translations/Translations.pot index 5b0821833..0745815f1 100644 --- a/Translations/Translations.pot +++ b/Translations/Translations.pot @@ -205,6 +205,43 @@ msgstr "" msgid "Invert" msgstr "" +msgid "Modify" +msgstr "" + +#. Found under the Select menu, in the Modify submenu. When selected, it shows a window that lets users expand the active selection. +msgid "Expand" +msgstr "" + +#. Title of a window that lets users expand the active selection. +msgid "Expand Selection" +msgstr "" + +#. Found under the Select menu, in the Modify submenu. When selected, it shows a window that lets users shrink the active selection. +msgid "Shrink" +msgstr "" + +#. Title of a window that lets users shrink the active selection. +msgid "Shrink Selection" +msgstr "" + +#. Found under the Select menu, in the Modify submenu. When selected, it shows a window that lets users create a border of the active selection. +msgid "Border" +msgstr "" + +#. Title of a window that lets users create a border of the active selection. +msgid "Border Selection" +msgstr "" + +#. Refers to a diamond-like shape. +msgid "Diamond" +msgstr "" + +msgid "Circle" +msgstr "" + +msgid "Square" +msgstr "" + msgid "Grayscale View" msgstr "" diff --git a/src/Classes/SelectionMap.gd b/src/Classes/SelectionMap.gd index cfb9591ee..abdc3329c 100644 --- a/src/Classes/SelectionMap.gd +++ b/src/Classes/SelectionMap.gd @@ -185,22 +185,34 @@ func resize_bitmap_values( blit_rect(smaller_image, Rect2i(Vector2i.ZERO, new_bitmap_size), dst) -func expand(width: int, pattern: int) -> void: +func expand(width: int, brush: int) -> void: var params := { "color": Color(1, 1, 1, 1), "width": width, - "pattern": pattern, + "brush": brush, } var gen := ShaderImageEffect.new() gen.generate_image(self, OUTLINE_INLINE_SHADER, params, get_size()) -func shrink(width: int, pattern: int) -> void: +func shrink(width: int, brush: int) -> void: var params := { "color": Color(0), - "inside": true, "width": width, - "pattern": pattern, + "brush": brush, + "inside": true, + } + var gen := ShaderImageEffect.new() + gen.generate_image(self, OUTLINE_INLINE_SHADER, params, get_size()) + + +func border(width: int, brush: int) -> void: + var params := { + "color": Color(1, 1, 1, 1), + "width": width, + "brush": brush, + "inside": true, + "keep_border_only": true, } var gen := ShaderImageEffect.new() gen.generate_image(self, OUTLINE_INLINE_SHADER, params, get_size()) diff --git a/src/Shaders/Effects/OutlineInline.gdshader b/src/Shaders/Effects/OutlineInline.gdshader index 88325aa77..66a4f52c8 100644 --- a/src/Shaders/Effects/OutlineInline.gdshader +++ b/src/Shaders/Effects/OutlineInline.gdshader @@ -4,9 +4,10 @@ render_mode unshaded; uniform vec4 color : source_color = vec4(1.0); uniform float width : hint_range(0, 10, 1) = 1.0; -// uniform_data pattern type:: OptionButton [Diamond||Circle||Square] -uniform int pattern : hint_range(0, 2) = 0; +// uniform_data brush type:: OptionButton [Diamond||Circle||Square] +uniform int brush : hint_range(0, 2) = 0; uniform bool inside = false; +uniform bool keep_border_only = false; uniform sampler2D selection : filter_nearest; bool is_zero_approx(float num) { @@ -17,11 +18,11 @@ bool has_contrary_neighbour(vec2 uv, vec2 texture_pixel_size, sampler2D tex) { for (float i = -ceil(width); i <= ceil(width); i++) { float offset; - if (pattern == 0) { + if (brush == 0) { offset = width - abs(i); - } else if (pattern == 1) { + } else if (brush == 1) { offset = floor(sqrt(pow(width + 0.5, 2) - i * i)); - } else if (pattern == 2) { + } else if (brush == 2) { offset = width; } @@ -51,6 +52,9 @@ void fragment() { output.a += (1.0 - output.a) * color.a; } } + else if (keep_border_only) { + output.a = 0.0; + } COLOR = mix(original_color, output, selection_color.a); } diff --git a/src/UI/Dialogs/ImageEffects/OutlineDialog.gd b/src/UI/Dialogs/ImageEffects/OutlineDialog.gd index 8543ee4e2..f3b99c5c8 100644 --- a/src/UI/Dialogs/ImageEffects/OutlineDialog.gd +++ b/src/UI/Dialogs/ImageEffects/OutlineDialog.gd @@ -31,7 +31,7 @@ func commit_action(cel: Image, project := Global.current_project) -> void: var params := { "color": color, "width": anim_thickness, - "pattern": pattern, + "brush": pattern, "inside": inside_image, "selection": selection_tex } diff --git a/src/UI/Dialogs/ImageEffects/OutlineDialog.tscn b/src/UI/Dialogs/ImageEffects/OutlineDialog.tscn index 844a82515..7f9e1699d 100644 --- a/src/UI/Dialogs/ImageEffects/OutlineDialog.tscn +++ b/src/UI/Dialogs/ImageEffects/OutlineDialog.tscn @@ -51,16 +51,15 @@ size_flags_horizontal = 3 [node name="PatternLabel" type="Label" parent="VBoxContainer/OutlineOptions" index="4"] layout_mode = 2 size_flags_horizontal = 3 -text = "Pattern:" +text = "Brush:" [node name="PatternOptionButton" type="OptionButton" parent="VBoxContainer/OutlineOptions" index="5"] layout_mode = 2 size_flags_horizontal = 3 mouse_default_cursor_shape = 2 -item_count = 3 selected = 0 +item_count = 3 popup/item_0/text = "Diamond" -popup/item_0/id = 0 popup/item_1/text = "Circle" popup/item_1/id = 1 popup/item_2/text = "Square" diff --git a/src/UI/Dialogs/ModifySelection.gd b/src/UI/Dialogs/ModifySelection.gd index d0195d083..a4f656fe8 100644 --- a/src/UI/Dialogs/ModifySelection.gd +++ b/src/UI/Dialogs/ModifySelection.gd @@ -1,14 +1,16 @@ extends ConfirmationDialog -enum Types { EXPAND, SHRINK } +enum Types { EXPAND, SHRINK, BORDER } @export var type := Types.EXPAND: set(value): type = value if type == Types.EXPAND: title = "Expand Selection" - else: + elif type == Types.SHRINK: title = "Shrink Selection" + else: + title = "Border Selection" @onready var width_slider: ValueSlider = $GridContainer/WidthSlider @onready var brush_option_button: OptionButton = $GridContainer/BrushOptionButton @@ -31,8 +33,10 @@ func _on_confirmed() -> void: project.selection_map.crop(project.size.x, project.size.y) if type == Types.EXPAND: project.selection_map.expand(width, brush) - else: + elif type == Types.SHRINK: project.selection_map.shrink(width, brush) + else: + project.selection_map.border(width, brush) selection_node.big_bounding_rectangle = project.selection_map.get_used_rect() project.selection_offset = Vector2.ZERO selection_node.commit_undo("Modify Selection", undo_data_tmp) diff --git a/src/UI/TopMenuContainer/TopMenuContainer.gd b/src/UI/TopMenuContainer/TopMenuContainer.gd index a83257d54..43456a878 100644 --- a/src/UI/TopMenuContainer/TopMenuContainer.gd +++ b/src/UI/TopMenuContainer/TopMenuContainer.gd @@ -460,6 +460,7 @@ func _setup_selection_modify_submenu(item: String) -> void: selection_modify_submenu.set_name("selection_modify_submenu") selection_modify_submenu.add_item("Expand") selection_modify_submenu.add_item("Shrink") + selection_modify_submenu.add_item("Border") selection_modify_submenu.id_pressed.connect(_selection_modify_submenu_id_pressed) select_menu.add_child(selection_modify_submenu) select_menu.add_submenu_item(item, selection_modify_submenu.get_name())