diff --git a/tools/brush/big_circle/big_circle.tres b/tools/brush/big_circle/big_circle.tres index a5439ba..23f5ebc 100644 --- a/tools/brush/big_circle/big_circle.tres +++ b/tools/brush/big_circle/big_circle.tres @@ -6,5 +6,5 @@ [resource] script = ExtResource("1_ipsu6") title = "Big Circle" -stamp = ExtResource("2_1qtbp") +original_stamp = ExtResource("2_1qtbp") metadata/_custom_type_script = "uid://bll2l6cggbn7b" diff --git a/tools/brush/big_semi_square/big_semi_square.tres b/tools/brush/big_semi_square/big_semi_square.tres index 534fff8..e69ec07 100644 --- a/tools/brush/big_semi_square/big_semi_square.tres +++ b/tools/brush/big_semi_square/big_semi_square.tres @@ -6,5 +6,5 @@ [resource] script = ExtResource("1_vlpet") title = "Big Semi-Square" -stamp = ExtResource("2_kemlt") +original_stamp = ExtResource("2_kemlt") metadata/_custom_type_script = "uid://bll2l6cggbn7b" diff --git a/tools/brush/big_square/big_square.tres b/tools/brush/big_square/big_square.tres index df7e6a6..02aaca6 100644 --- a/tools/brush/big_square/big_square.tres +++ b/tools/brush/big_square/big_square.tres @@ -1,10 +1,10 @@ [gd_resource type="Resource" script_class="Brush" format=3 uid="uid://e3thyxwo66gv"] [ext_resource type="Script" uid="uid://bll2l6cggbn7b" path="res://tools/brush/brush.gd" id="1_x2gwn"] -[ext_resource type="Texture2D" uid="uid://bwkygx605tohx" path="res://tools/brush/big_square/brush_template.png" id="2_43bw0"] +[ext_resource type="Texture2D" uid="uid://cn802kqvyqt0m" path="res://tools/brush/big_square/brush_template.png" id="2_43bw0"] [resource] script = ExtResource("1_x2gwn") title = "Big Square" -stamp = ExtResource("2_43bw0") +original_stamp = ExtResource("2_43bw0") metadata/_custom_type_script = "uid://bll2l6cggbn7b" diff --git a/tools/brush/brush.gd b/tools/brush/brush.gd index b378234..7f71f78 100644 --- a/tools/brush/brush.gd +++ b/tools/brush/brush.gd @@ -2,26 +2,24 @@ class_name Brush extends Tool @export var title: String = "Brush" -@export var stamp: Texture2D = PlaceholderTexture2D.new() -@export var width: float -@export var hardness: float -@export var color: Color -@export var scaling_filter: Image.Interpolation +@export var original_stamp: Texture2D = PlaceholderTexture2D.new() +var width: float +var hardness: float +var color: Color +var scaling_filter: Image.Interpolation +var stamp_tex: Texture2D var _stroke_node: Node2D -var _stamp_tex: Texture2D var _last_pos: Vector2 var _has_last = false -func _init() -> void: - name = "Brush" - +func _ready() -> void: + stamp_tex = generate_stamp() func on_pointer_down(_position: Vector2, _canvas: Canvas) -> void: _stroke_node = Node2D.new() _canvas.dynamic_node.add_child(_stroke_node) - _stamp_tex = generate_stamp() _has_last = true _last_pos = _position _place_stamp(_last_pos) @@ -37,10 +35,10 @@ func on_pointer_move(_position: Vector2, _canvas: Canvas) -> void: var t = 0.0 while t <= dist: - if (dir * t).length() > (width / _stamp_tex.get_width() * 10): + if (dir * t).length() > (width / stamp_tex.get_width() * 10): _place_stamp(_last_pos + dir * t) _last_pos = _position - t += (width / _stamp_tex.get_width() * 10) + t += (width / stamp_tex.get_width() * 10) func on_pointer_up(_position: Vector2, _canvas: Canvas) -> void: @@ -49,8 +47,11 @@ func on_pointer_up(_position: Vector2, _canvas: Canvas) -> void: func generate_stamp() -> Texture2D: - var size_px = stamp.get_height() * max(width * 2, 10) - var img = stamp.get_image() + if original_stamp == null or original_stamp.get_image() == null: + return + + var size_px = original_stamp.get_height() * max(width * 2, 10) + var img = original_stamp.get_image() var org_img = img img.resize(size_px, size_px, scaling_filter) var center = Vector2(size_px * 0.5, size_px * 0.5) @@ -80,11 +81,11 @@ func generate_stamp() -> Texture2D: func _place_stamp(_position: Vector2) -> void: var s = Sprite2D.new() - s.texture = _stamp_tex + s.texture = stamp_tex s.position = _position s.modulate = color - var tex_w = float(_stamp_tex.get_width()) + var tex_w = float(stamp_tex.get_width()) var scale_factor = width / tex_w s.scale = Vector2.ONE * scale_factor diff --git a/tools/eraser/big_circle/big_circle.tres b/tools/eraser/big_circle/big_circle.tres index 5a3499f..1da95f1 100644 --- a/tools/eraser/big_circle/big_circle.tres +++ b/tools/eraser/big_circle/big_circle.tres @@ -6,5 +6,5 @@ [resource] script = ExtResource("1_h7n6f") title = "Big Circle" -stamp = ExtResource("2_h7n6f") +original_stamp = ExtResource("2_h7n6f") metadata/_custom_type_script = "uid://bll2l6cggbn7b" diff --git a/tools/eraser/big_semi_square/big_semi_square.tres b/tools/eraser/big_semi_square/big_semi_square.tres index 60b0973..487152e 100644 --- a/tools/eraser/big_semi_square/big_semi_square.tres +++ b/tools/eraser/big_semi_square/big_semi_square.tres @@ -6,5 +6,5 @@ [resource] script = ExtResource("1_y22wk") title = "Big Semi-Square" -stamp = ExtResource("2_m5llq") +original_stamp = ExtResource("2_m5llq") metadata/_custom_type_script = "uid://bll2l6cggbn7b" diff --git a/tools/eraser/big_square/big_square.tres b/tools/eraser/big_square/big_square.tres index eb9efd7..1f88627 100644 --- a/tools/eraser/big_square/big_square.tres +++ b/tools/eraser/big_square/big_square.tres @@ -6,5 +6,5 @@ [resource] script = ExtResource("1_dt1qd") title = "Big Square" -stamp = ExtResource("2_dt1qd") +original_stamp = ExtResource("2_dt1qd") metadata/_custom_type_script = "uid://bll2l6cggbn7b" diff --git a/tools/eraser/eraser.gd b/tools/eraser/eraser.gd index ab0a09c..431d7e4 100644 --- a/tools/eraser/eraser.gd +++ b/tools/eraser/eraser.gd @@ -2,29 +2,28 @@ class_name Eraser extends Tool @export var title: String = "Eraser" -@export var stamp: Texture2D = PlaceholderTexture2D.new() -@export var width: float -@export var hardness: float -@export var scaling_filter: Image.Interpolation +@export var original_stamp: Texture2D = PlaceholderTexture2D.new() +var width: float +var hardness: float +var scaling_filter: Image.Interpolation +var filter: Texture2D -var _filter: Texture2D var _last_pos: Vector2 var _has_last = false -func _init() -> void: - name = "Eraser" +func _ready() -> void: + filter = generate_filter() func on_pointer_down(_position: Vector2, _canvas: Canvas) -> void: - _filter = generate_filter() _has_last = true _last_pos = _position _place_stamp(_last_pos, _canvas) func on_pointer_move(_position: Vector2, _canvas: Canvas) -> void: - if _filter == null or not _canvas._project or not _has_last: + if filter == null or not _canvas._project or not _has_last: return var delta = _last_pos - _position @@ -33,10 +32,10 @@ func on_pointer_move(_position: Vector2, _canvas: Canvas) -> void: var t = 0.0 while t <= dist: - if (dir * t).length() > (width / _filter.get_width() * 10): + if (dir * t).length() > (width / filter.get_width() * 10): _place_stamp(_last_pos + dir * t, _canvas) _last_pos = _position - t += (width / _filter.get_width() * 10) + t += (width / filter.get_width() * 10) func on_pointer_up(_position: Vector2, _canvas: Canvas) -> void: @@ -44,8 +43,11 @@ func on_pointer_up(_position: Vector2, _canvas: Canvas) -> void: func generate_filter() -> Texture2D: - var size_px = stamp.get_height() * max(width * 2, 10) - var img = stamp.get_image() + if original_stamp == null or original_stamp.get_image() == null: + return + + var size_px = original_stamp.get_height() * max(width * 2, 10) + var img = original_stamp.get_image() img.resize(size_px, size_px) var center = Vector2(size_px * 0.5, size_px * 0.5) var radius = size_px * 0.5 * sqrt(2) @@ -73,12 +75,12 @@ func generate_filter() -> Texture2D: func _place_stamp(_position: Vector2, _canvas: Canvas) -> void: - var tex_w = float(_filter.get_width()) + var tex_w = float(filter.get_width()) var scale_factor = width / tex_w - var img = _filter.get_image() + var img = filter.get_image() img.resize( - _filter.get_width() * scale_factor, - _filter.get_height() * scale_factor, + filter.get_width() * scale_factor, + filter.get_height() * scale_factor, Image.INTERPOLATE_LANCZOS ) diff --git a/views/editor/containers/edit_extras/brush_handler.gd b/views/editor/containers/edit_extras/brush_handler.gd index d2ecd29..4bfae16 100644 --- a/views/editor/containers/edit_extras/brush_handler.gd +++ b/views/editor/containers/edit_extras/brush_handler.gd @@ -8,7 +8,10 @@ extends PanelContainer @export var brush_list: ItemList @export var button_group: ButtonGroup @export var tool_manager: ToolManager -@export var tool: Tool +@export var tool: Brush +@export var default_brush_width = 2.5 +@export var default_brush_hardness = 1.0 +@export var default_brush_color = Color.BLACK var brushes = [ load("res://tools/brush/big_circle/big_circle.tres"), @@ -17,9 +20,6 @@ var brushes = [ ] var scale_filter = Image.INTERPOLATE_NEAREST -var brush_width = 2.5 -var brush_hardness = 1.0 -var brush_color = Color.BLACK var editor: Editor @@ -37,32 +37,31 @@ func _ready() -> void: brush_list.select(0) _on_brush_selected(0) - thick_sldr.value = brush_width - hard_sldr.value = brush_hardness - + thick_sldr.value = default_brush_width + hard_sldr.value = default_brush_hardness + color_picker.color = default_brush_color func _on_thickness_changed(value: float) -> void: - brush_width = value thick_label.text = "%dpx" % value - tool.width = brush_width + tool.width = value func _on_hardness_changed(value: float) -> void: - brush_hardness = value hard_label.text = "%d%%" % (value * 100) - tool.hardness = brush_hardness + tool.hardness = value + tool.stamp_tex = tool.generate_stamp() func _on_color_changed(color: Color) -> void: - brush_color = color - tool.color = brush_color + tool.color = color func _on_brush_selected(index: int) -> void: + brushes[index].hardness = tool.hardness + brushes[index].width = tool.width + brushes[index].color = tool.color tool = brushes[index] - tool.hardness = brush_hardness - tool.width = brush_width - tool.color = brush_color + tool.stamp_tex = tool.generate_stamp() editor.current_tool = tool diff --git a/views/editor/containers/edit_extras/dragger_handler.gd b/views/editor/containers/edit_extras/dragger_handler.gd index 6539099..2068f95 100644 --- a/views/editor/containers/edit_extras/dragger_handler.gd +++ b/views/editor/containers/edit_extras/dragger_handler.gd @@ -1,3 +1,3 @@ extends PanelContainer -@export var tool: Tool +@export var tool: Dragger \ No newline at end of file diff --git a/views/editor/containers/edit_extras/eraser_handler.gd b/views/editor/containers/edit_extras/eraser_handler.gd index 11eb946..0b7efd0 100644 --- a/views/editor/containers/edit_extras/eraser_handler.gd +++ b/views/editor/containers/edit_extras/eraser_handler.gd @@ -7,7 +7,9 @@ extends PanelContainer @export var eraser_list: ItemList @export var button_group: ButtonGroup @export var tool_manager: ToolManager -@export var tool: Tool +@export var tool: Eraser +@export var default_eraser_width = 2.5 +@export var default_eraser_hardness = 1.0 var erasers = [ load("res://tools/eraser/big_circle/big_circle.tres"), @@ -16,8 +18,6 @@ var erasers = [ ] var scale_filter = Image.INTERPOLATE_NEAREST -var eraser_width = 2.5 -var eraser_hardness = 1.0 var editor: Editor @@ -27,8 +27,8 @@ func _ready() -> void: thick_sldr.value_changed.connect(_on_thickness_changed) hard_sldr.value_changed.connect(_on_hardness_changed) - thick_sldr.value = eraser_width - hard_sldr.value = eraser_hardness + thick_sldr.value = default_eraser_width + hard_sldr.value = default_eraser_hardness for button in button_group.get_buttons(): button.pressed.connect(_on_filter_selected) @@ -37,26 +37,24 @@ func _ready() -> void: eraser_list.select(0) _on_eraser_selected(0) - thick_sldr.value = eraser_width - hard_sldr.value = eraser_hardness func _on_thickness_changed(value: float) -> void: - eraser_width = value thick_label.text = "%dpx" % value - tool.width = eraser_width + tool.width = value func _on_hardness_changed(value: float) -> void: - eraser_hardness = value hard_label.text = "%d%%" % (value * 100) - tool.hardness = eraser_hardness + tool.hardness = value + tool.filter = tool.generate_filter() func _on_eraser_selected(index: int) -> void: + erasers[index].hardness = tool.hardness + erasers[index].width = tool.width tool = erasers[index] - tool.hardness = eraser_hardness - tool.width = eraser_width + tool.filter = tool.generate_filter() editor.current_tool = tool diff --git a/views/editor/containers/edit_extras/paint_bucket_handler.gd b/views/editor/containers/edit_extras/paint_bucket_handler.gd index 0f5f22d..3e73727 100644 --- a/views/editor/containers/edit_extras/paint_bucket_handler.gd +++ b/views/editor/containers/edit_extras/paint_bucket_handler.gd @@ -3,7 +3,7 @@ extends PanelContainer @export var tolerance_sldr: Slider @export var tolerance_label: Label @export var color_picker: ColorPickerButton -@export var tool: Tool +@export var tool: PaintBucket var tolerance: float var fill_color: Color