Skip to content

Commit

Permalink
Add border selection, fix some missing translation strings
Browse files Browse the repository at this point in the history
  • Loading branch information
OverloadedOrama committed Nov 14, 2024
1 parent dec6980 commit 0d6b140
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 16 deletions.
37 changes: 37 additions & 0 deletions Translations/Translations.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""

Expand Down
20 changes: 16 additions & 4 deletions src/Classes/SelectionMap.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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),
"width": width,
"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,
"pattern": pattern,
"brush": brush,
"inside": true,
"keep_border_only": true,
}
var gen := ShaderImageEffect.new()
gen.generate_image(self, OUTLINE_INLINE_SHADER, params, get_size())
14 changes: 9 additions & 5 deletions src/Shaders/Effects/OutlineInline.gdshader
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion src/UI/Dialogs/ImageEffects/OutlineDialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions src/UI/Dialogs/ImageEffects/OutlineDialog.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 7 additions & 3 deletions src/UI/Dialogs/ModifySelection.gd
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/UI/TopMenuContainer/TopMenuContainer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 0d6b140

Please sign in to comment.