Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/brush/big_circle/big_circle.tres
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion tools/brush/big_semi_square/big_semi_square.tres
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions tools/brush/big_square/big_square.tres
Original file line number Diff line number Diff line change
@@ -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"
33 changes: 17 additions & 16 deletions tools/brush/brush.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tools/eraser/big_circle/big_circle.tres
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion tools/eraser/big_semi_square/big_semi_square.tres
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion tools/eraser/big_square/big_square.tres
Original file line number Diff line number Diff line change
Expand Up @@ -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"
36 changes: 19 additions & 17 deletions tools/eraser/eraser.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,19 +32,22 @@ 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:
_has_last = false


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)
Expand Down Expand Up @@ -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
)

Expand Down
31 changes: 15 additions & 16 deletions views/editor/containers/edit_extras/brush_handler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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


Expand All @@ -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


Expand Down
2 changes: 1 addition & 1 deletion views/editor/containers/edit_extras/dragger_handler.gd
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
extends PanelContainer

@export var tool: Tool
@export var tool: Dragger
24 changes: 11 additions & 13 deletions views/editor/containers/edit_extras/eraser_handler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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


Expand All @@ -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)
Expand All @@ -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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading