diff --git a/src/Tools/BaseTool.gd b/src/Tools/BaseTool.gd index b1fe24f25..3c347acb1 100644 --- a/src/Tools/BaseTool.gd +++ b/src/Tools/BaseTool.gd @@ -19,7 +19,7 @@ func _ready() -> void: color_rect.color = Global.left_tool_color else: color_rect.color = Global.right_tool_color - $Header/Label.text = Tools.tools[name].display_name + $Label.text = Tools.tools[name].display_name load_config() diff --git a/src/Tools/BaseTool.tscn b/src/Tools/BaseTool.tscn index eae095053..f275a2ac1 100644 --- a/src/Tools/BaseTool.tscn +++ b/src/Tools/BaseTool.tscn @@ -15,26 +15,11 @@ margin_right = 116.0 margin_bottom = 4.0 rect_min_size = Vector2( 0, 4 ) -[node name="Header" type="HBoxContainer" parent="."] +[node name="Label" type="Label" parent="."] margin_top = 8.0 margin_right = 116.0 margin_bottom = 22.0 -custom_constants/separation = 0 - -[node name="HSeparator2" type="HSeparator" parent="Header"] -margin_right = 23.0 -margin_bottom = 14.0 -size_flags_horizontal = 3 - -[node name="Label" type="Label" parent="Header"] -margin_left = 23.0 -margin_right = 92.0 -margin_bottom = 14.0 theme_type_variation = "Header" text = "Tool Name" - -[node name="HSeparator" type="HSeparator" parent="Header"] -margin_left = 92.0 -margin_right = 116.0 -margin_bottom = 14.0 -size_flags_horizontal = 3 +align = 1 +autowrap = true diff --git a/src/Tools/SelectionTools/ColorSelect.gd b/src/Tools/SelectionTools/ColorSelect.gd index 3e7736cb2..d829c867a 100644 --- a/src/Tools/SelectionTools/ColorSelect.gd +++ b/src/Tools/SelectionTools/ColorSelect.gd @@ -5,7 +5,9 @@ var _similarity := 100 func get_config() -> Dictionary: - return {"similarity": _similarity} + var config := .get_config() + config["similarity"] = _similarity + return config func set_config(config: Dictionary) -> void: @@ -23,6 +25,7 @@ func _on_Similarity_value_changed(value: float) -> void: func apply_selection(position: Vector2) -> void: + .apply_selection(position) var project: Project = Global.current_project if position.x < 0 or position.y < 0: return diff --git a/src/Tools/SelectionTools/EllipseSelect.gd b/src/Tools/SelectionTools/EllipseSelect.gd index bdbd459bf..e4a3c7434 100644 --- a/src/Tools/SelectionTools/EllipseSelect.gd +++ b/src/Tools/SelectionTools/EllipseSelect.gd @@ -65,6 +65,7 @@ func draw_preview() -> void: func apply_selection(_position: Vector2) -> void: + .apply_selection(_position) var project: Project = Global.current_project if !_add and !_subtract and !_intersect: Global.canvas.selection.clear_selection() diff --git a/src/Tools/SelectionTools/Lasso.gd b/src/Tools/SelectionTools/Lasso.gd index ccce7f5a7..7c7c5cef6 100644 --- a/src/Tools/SelectionTools/Lasso.gd +++ b/src/Tools/SelectionTools/Lasso.gd @@ -71,6 +71,7 @@ func draw_preview() -> void: func apply_selection(_position) -> void: + .apply_selection(_position) var project: Project = Global.current_project var cleared := false if !_add and !_subtract and !_intersect: diff --git a/src/Tools/SelectionTools/MagicWand.gd b/src/Tools/SelectionTools/MagicWand.gd index cf3310847..210e49789 100644 --- a/src/Tools/SelectionTools/MagicWand.gd +++ b/src/Tools/SelectionTools/MagicWand.gd @@ -7,6 +7,7 @@ var _allegro_image_segments: Array func apply_selection(position: Vector2) -> void: + .apply_selection(position) var project: Project = Global.current_project var size: Vector2 = project.size if position.x < 0 or position.y < 0 or position.x >= size.x or position.y >= size.y: diff --git a/src/Tools/SelectionTools/PaintSelect.gd b/src/Tools/SelectionTools/PaintSelect.gd index 2f58cdefd..10439aafd 100644 --- a/src/Tools/SelectionTools/PaintSelect.gd +++ b/src/Tools/SelectionTools/PaintSelect.gd @@ -13,11 +13,11 @@ var _draw_points := [] func get_config() -> Dictionary: - return { - "brush_type": _brush.type, - "brush_index": _brush.index, - "brush_size": _brush_size, - } + var config := .get_config() + config["brush_type"] = _brush.type + config["brush_index"] = _brush.index + config["brush_size"] = _brush_size + return config func set_config(config: Dictionary) -> void: @@ -99,12 +99,14 @@ func draw_preview() -> void: func apply_selection(_position) -> void: + .apply_selection(_position) var project: Project = Global.current_project var cleared := false if !_add and !_subtract and !_intersect: cleared = true Global.canvas.selection.clear_selection() - if _draw_points.size() > 1: + # This is paint selection so we've done >= 1 nstead of > 1 + if _draw_points.size() >= 1: var selection_map_copy := SelectionMap.new() selection_map_copy.copy_from(project.selection_map) if _intersect: diff --git a/src/Tools/SelectionTools/PolygonSelect.gd b/src/Tools/SelectionTools/PolygonSelect.gd index ee66d799d..82cdeaf3f 100644 --- a/src/Tools/SelectionTools/PolygonSelect.gd +++ b/src/Tools/SelectionTools/PolygonSelect.gd @@ -105,6 +105,7 @@ func draw_preview() -> void: func apply_selection(_position) -> void: + .apply_selection(_position) if !_ready_to_apply: return var project: Project = Global.current_project diff --git a/src/Tools/SelectionTools/RectSelect.gd b/src/Tools/SelectionTools/RectSelect.gd index d26bc9a65..a607f5003 100644 --- a/src/Tools/SelectionTools/RectSelect.gd +++ b/src/Tools/SelectionTools/RectSelect.gd @@ -88,6 +88,7 @@ func draw_preview() -> void: func apply_selection(_position: Vector2) -> void: + .apply_selection(_position) var project: Project = Global.current_project if !_add and !_subtract and !_intersect: Global.canvas.selection.clear_selection() diff --git a/src/Tools/SelectionTools/SelectionTool.gd b/src/Tools/SelectionTools/SelectionTool.gd index 03af95838..86b085141 100644 --- a/src/Tools/SelectionTools/SelectionTool.gd +++ b/src/Tools/SelectionTools/SelectionTool.gd @@ -1,6 +1,8 @@ class_name SelectionTool extends BaseTool +enum Mode { DEFAULT, ADD, SUBTRACT, INTERSECT } + var undo_data: Dictionary var _move := false var _move_content := true @@ -10,6 +12,7 @@ var _offset := Vector2.ZERO # click multiple times to create a selection var _ongoing_selection := false +var _mode_selected := 0 var _add := false # Shift + Mouse Click var _subtract := false # Ctrl + Mouse Click var _intersect := false # Shift + Ctrl + Mouse Click @@ -28,6 +31,32 @@ onready var timer: Timer = $Timer func _ready() -> void: set_spinbox_values() + refresh_options() + + +func refresh_options(): + # The existence of this function is to ensure all items + # are added when we are selecting an option (Bad things will happen if i dont do this...) + $Modes.clear() + $Modes.add_item("Default (New Selection)") + $Modes.add_item("Add to Selection") + $Modes.add_item("Subtract from Selection") + $Modes.add_item("Intersection of Selections") + $Modes.select(_mode_selected) + + +func get_config() -> Dictionary: + var config := .get_config() + config["mode_selected"] = _mode_selected + return config + + +func set_config(config: Dictionary) -> void: + _mode_selected = config.get("mode_selected", 0) + + +func update_config() -> void: + refresh_options() func set_spinbox_values() -> void: @@ -173,7 +202,22 @@ func draw_end(position: Vector2) -> void: func apply_selection(_position: Vector2) -> void: - pass + # if a shortcut is activated then that will be obeyed instead + match _mode_selected: + Mode.ADD: + if !_subtract && !_intersect: + _add = true + Mode.SUBTRACT: + if !_add && !_intersect: + _subtract = true + Mode.INTERSECT: + if !_add && !_subtract: + _intersect = true + + +func _on_Modes_item_selected(index: int) -> void: + _mode_selected = index + save_config() func _set_cursor_text(rect: Rect2) -> void: diff --git a/src/Tools/SelectionTools/SelectionTool.tscn b/src/Tools/SelectionTools/SelectionTool.tscn index cdd20a2f2..341ca4728 100644 --- a/src/Tools/SelectionTools/SelectionTool.tscn +++ b/src/Tools/SelectionTools/SelectionTool.tscn @@ -7,60 +7,73 @@ [node name="ToolOptions" instance=ExtResource( 1 )] script = ExtResource( 2 ) -[node name="PositionLabel" type="Label" parent="." index="2"] +[node name="ModeLabel" type="Label" parent="." index="2"] margin_top = 26.0 margin_right = 116.0 margin_bottom = 40.0 -text = "Position:" +text = "Mode:" -[node name="XSpinBox" parent="." index="3" instance=ExtResource( 3 )] +[node name="Modes" type="OptionButton" parent="." index="3"] margin_top = 44.0 margin_right = 116.0 -margin_bottom = 68.0 +margin_bottom = 64.0 +align = 1 + +[node name="PositionLabel" type="Label" parent="." index="4"] +margin_top = 68.0 +margin_right = 116.0 +margin_bottom = 82.0 +text = "Position:" + +[node name="XSpinBox" parent="." index="5" instance=ExtResource( 3 )] +margin_top = 86.0 +margin_right = 116.0 +margin_bottom = 110.0 hint_tooltip = "X coordinate of the top left corner" allow_greater = true allow_lesser = true prefix = "X:" -[node name="YSpinBox" parent="." index="4" instance=ExtResource( 3 )] -margin_top = 72.0 +[node name="YSpinBox" parent="." index="6" instance=ExtResource( 3 )] +margin_top = 114.0 margin_right = 116.0 -margin_bottom = 96.0 +margin_bottom = 138.0 hint_tooltip = "Y coordinate of the top left corner" allow_greater = true allow_lesser = true prefix = "Y:" -[node name="SizeLabel" type="Label" parent="." index="5"] -margin_top = 100.0 +[node name="SizeLabel" type="Label" parent="." index="7"] +margin_top = 142.0 margin_right = 116.0 -margin_bottom = 114.0 +margin_bottom = 156.0 text = "Size:" -[node name="WSpinBox" parent="." index="6" instance=ExtResource( 3 )] -margin_top = 118.0 +[node name="WSpinBox" parent="." index="8" instance=ExtResource( 3 )] +margin_top = 160.0 margin_right = 116.0 -margin_bottom = 142.0 +margin_bottom = 184.0 hint_tooltip = "Width of selection" min_value = 1.0 value = 1.0 allow_greater = true prefix = "W:" -[node name="HSpinBox" parent="." index="7" instance=ExtResource( 3 )] -margin_top = 146.0 +[node name="HSpinBox" parent="." index="9" instance=ExtResource( 3 )] +margin_top = 188.0 margin_right = 116.0 -margin_bottom = 170.0 +margin_bottom = 212.0 hint_tooltip = "Height of selection" min_value = 1.0 value = 1.0 allow_greater = true prefix = "H:" -[node name="Timer" type="Timer" parent="." index="8"] +[node name="Timer" type="Timer" parent="." index="10"] wait_time = 0.2 one_shot = true +[connection signal="item_selected" from="Modes" to="." method="_on_Modes_item_selected"] [connection signal="value_changed" from="XSpinBox" to="." method="_on_position_value_changed" binds= [ true ]] [connection signal="value_changed" from="YSpinBox" to="." method="_on_position_value_changed" binds= [ false ]] [connection signal="value_changed" from="WSpinBox" to="." method="_on_size_value_changed" binds= [ true ]]