Skip to content

Commit b78b595

Browse files
authored
feat: Brush Tool Update (#10)
* Paint Update Everything works as expected technically. However, although the texture for the line is set up, it didn't work as expected. Round texture doesn't appear at all, and square textures are like normal lines. It's probably caused by the logic of adding lines to Canvas. The following functions work well: 1 editing thickness 2 change color To test out these functions, you can set the texture to either square or semi-square. Circle texture can't print anything for unknown reasons. * Update brush.gd Problem Fixed. All implemented features in the brush menu work well. * Update brush menu
1 parent a867696 commit b78b595

9 files changed

Lines changed: 164 additions & 10 deletions

File tree

system/canvas/canvas.tscn

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ grow_vertical = 2
2727

2828
[node name="Layers" type="Node2D" parent="Control" unique_id=760557918]
2929

30-
[node name="OnionSkin" type="Node2D" parent="Control"]
30+
[node name="OnionSkin" type="Node2D" parent="Control" unique_id=290639511]
3131
script = ExtResource("3_onion")
3232

33-
3433
[node name="Dynamic" type="Node2D" parent="Control" unique_id=356778995]
3534

3635
[node name="BakeViewport" type="SubViewport" parent="." unique_id=1325751403]

tools/brush/brush.gd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ extends Tool
66
@export var width: float = 1.0
77

88
var _line: Line2D
9+
var color: Color
910

1011
func _init() -> void:
1112
name = "Brush"
1213

1314
func on_pointer_down(_position: Vector2, _canvas: Canvas) -> void:
1415
_line = Line2D.new()
15-
_line.width = 2.0
16-
_line.default_color = Color.BLACK
16+
_line.width = width
17+
_line.default_color = color
1718
_canvas.dynamic_node.add_child(_line)
1819

1920
func on_pointer_move(_position: Vector2, _canvas: Canvas) -> void:
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
extends PanelContainer
2+
3+
@export var thick_sldr: Slider
4+
@export var hard_sldr: Slider
5+
@export var color_picker: ColorPickerButton
6+
@export var brush_list: ItemList
7+
@onready var root: Node = get_tree().current_scene
8+
9+
var brushes =[
10+
load("res://tools/brush/big_circle/big_circle.tres"),
11+
load("res://tools/brush/big_semi_square/big_semi_square.tres"),
12+
load("res://tools/brush/big_square/big_square.tres")
13+
]
14+
15+
var brush_width = 2.5
16+
var brush_color = Color.BLACK
17+
18+
func _ready() -> void:
19+
20+
brush_list.item_selected.connect(_on_brush_selected)
21+
thick_sldr.value_changed.connect(_on_thickness_changed)
22+
color_picker.color_changed.connect(_on_color_changed)
23+
24+
brush_list.select(0)
25+
_on_brush_selected(0)
26+
thick_sldr.value = brush_width
27+
28+
func _on_thickness_changed(value: float) -> void:
29+
brush_width = thick_sldr.value
30+
root.current_tool.width = brush_width
31+
32+
func _on_color_changed(color: Color) -> void:
33+
brush_color = color
34+
root.current_tool.color = brush_color
35+
36+
func _on_brush_selected(index: int) -> void:
37+
root.current_tool = brushes[index]
38+
root.current_tool.width = brush_width
39+
root.current_tool.color = brush_color
40+
41+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://dfxrwhc6j411j

views/editor/containers/edit_extras/edit_extras.tscn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ theme_override_constants/separation = 0
4040
[node name="TabContainer" type="TabContainer" parent="Panel/VBoxContainer" unique_id=1268311807]
4141
layout_mode = 2
4242
size_flags_vertical = 3
43-
current_tab = 0
43+
current_tab = 1
4444

4545
[node name="Project" parent="Panel/VBoxContainer/TabContainer" unique_id=1631588843 instance=ExtResource("1_xequw")]
46+
visible = false
4647
layout_mode = 2
4748
metadata/_tab_index = 0
4849

4950
[node name="Tools" parent="Panel/VBoxContainer/TabContainer" unique_id=1657501930 instance=ExtResource("2_0ld5u")]
50-
visible = false
5151
layout_mode = 2
5252
metadata/_tab_index = 1
5353

views/editor/containers/page_controls/page_controls.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ horizontal_alignment = 1
8383
layout_mode = 2
8484
text = "Play"
8585

86-
[node name="OnionSkinButton" type="Button" parent="Panel/ToolbarContents/FrameControls"]
86+
[node name="OnionSkinButton" type="Button" parent="Panel/ToolbarContents/FrameControls" unique_id=1585426574]
8787
layout_mode = 2
8888
toggle_mode = true
8989
text = "Onion Skin"
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
[gd_scene format=3 uid="uid://dm0t60quyv3bj"]
2+
3+
[ext_resource type="Script" uid="uid://dfxrwhc6j411j" path="res://views/editor/containers/edit_extras/brush_handler.gd" id="1_8f4qj"]
4+
[ext_resource type="Texture2D" uid="uid://whaa4jwoxw6m" path="res://tools/brush/big_circle/brush_template.png" id="2_6f1ni"]
5+
[ext_resource type="Texture2D" uid="uid://jfxxbdi7fdi2" path="res://tools/brush/big_semi_square/brush_template.png" id="3_iesae"]
6+
[ext_resource type="Texture2D" uid="uid://bwkygx605tohx" path="res://tools/brush/big_square/brush_template.png" id="4_781lx"]
7+
8+
[node name="BrushMenu" type="PanelContainer" unique_id=1654936513 node_paths=PackedStringArray("thick_sldr", "hard_sldr", "color_picker", "brush_list")]
9+
script = ExtResource("1_8f4qj")
10+
thick_sldr = NodePath("VBoxContainer/HBoxContainer/BrushSetting/TkSldrContainer/ThicknessSlider")
11+
hard_sldr = NodePath("VBoxContainer/HBoxContainer/BrushSetting/HdSldrContainer/HardnessSlider")
12+
color_picker = NodePath("VBoxContainer/HBoxContainer/ColorHeader/ColorPickerButton")
13+
brush_list = NodePath("VBoxContainer/BrushesHeader/BrushList")
14+
metadata/_tab_index = 0
15+
16+
[node name="VBoxContainer" type="VBoxContainer" parent="." unique_id=1225038371]
17+
layout_mode = 2
18+
19+
[node name="BrushesHeader" type="VBoxContainer" parent="VBoxContainer" unique_id=380219836]
20+
layout_mode = 2
21+
size_flags_vertical = 3
22+
23+
[node name="Label" type="Label" parent="VBoxContainer/BrushesHeader" unique_id=1464163878]
24+
layout_mode = 2
25+
text = "Brushes"
26+
27+
[node name="BrushList" type="ItemList" parent="VBoxContainer/BrushesHeader" unique_id=1189968663]
28+
layout_mode = 2
29+
size_flags_vertical = 3
30+
item_count = 3
31+
item_0/text = "Big Circle"
32+
item_0/icon = ExtResource("2_6f1ni")
33+
item_1/text = "Big Semisquare"
34+
item_1/icon = ExtResource("3_iesae")
35+
item_2/text = "Big Square"
36+
item_2/icon = ExtResource("4_781lx")
37+
38+
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer" unique_id=544748102]
39+
layout_mode = 2
40+
41+
[node name="VSeparator" type="VSeparator" parent="VBoxContainer/HBoxContainer" unique_id=194385954]
42+
layout_mode = 2
43+
size_flags_horizontal = 3
44+
size_flags_stretch_ratio = 0.3
45+
46+
[node name="BrushSetting" type="VBoxContainer" parent="VBoxContainer/HBoxContainer" unique_id=768236304]
47+
layout_mode = 2
48+
size_flags_horizontal = 3
49+
50+
[node name="TkSldrContainer" type="VBoxContainer" parent="VBoxContainer/HBoxContainer/BrushSetting" unique_id=577021794]
51+
layout_mode = 2
52+
53+
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer/BrushSetting/TkSldrContainer" unique_id=2016760910]
54+
layout_mode = 2
55+
text = "Thickness"
56+
57+
[node name="ThicknessSlider" type="HSlider" parent="VBoxContainer/HBoxContainer/BrushSetting/TkSldrContainer" unique_id=65607546]
58+
layout_mode = 2
59+
min_value = 1.0
60+
max_value = 50.0
61+
step = 0.1
62+
value = 1.0
63+
64+
[node name="HdSldrContainer" type="VBoxContainer" parent="VBoxContainer/HBoxContainer/BrushSetting" unique_id=2083122033]
65+
layout_mode = 2
66+
67+
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer/BrushSetting/HdSldrContainer" unique_id=1612079100]
68+
layout_mode = 2
69+
text = "Hardness (Not Implemented)"
70+
71+
[node name="HardnessSlider" type="HSlider" parent="VBoxContainer/HBoxContainer/BrushSetting/HdSldrContainer" unique_id=1560819494]
72+
layout_mode = 2
73+
74+
[node name="VSeparator2" type="VSeparator" parent="VBoxContainer/HBoxContainer" unique_id=900005814]
75+
layout_mode = 2
76+
size_flags_horizontal = 3
77+
size_flags_stretch_ratio = 0.3
78+
79+
[node name="ColorHeader" type="VBoxContainer" parent="VBoxContainer/HBoxContainer" unique_id=895090855]
80+
layout_mode = 2
81+
size_flags_horizontal = 3
82+
83+
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer/ColorHeader" unique_id=1775548022]
84+
layout_mode = 2
85+
text = "Color"
86+
87+
[node name="ColorPickerButton" type="ColorPickerButton" parent="VBoxContainer/HBoxContainer/ColorHeader" unique_id=673755781]
88+
layout_mode = 2
89+
size_flags_vertical = 3
90+
size_flags_stretch_ratio = 0.0
91+
text = "a"
92+
93+
[node name="VSeparator3" type="VSeparator" parent="VBoxContainer/HBoxContainer" unique_id=1656032359]
94+
layout_mode = 2
95+
size_flags_horizontal = 3
96+
size_flags_stretch_ratio = 0.3
97+
98+
[node name="HSeparator" type="HSeparator" parent="VBoxContainer" unique_id=2040615261]
99+
layout_mode = 2
100+
size_flags_vertical = 3
101+
size_flags_stretch_ratio = 0.1
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
[gd_scene format=3 uid="uid://cloa3c54w8ah8"]
22

3+
[ext_resource type="PackedScene" uid="uid://dm0t60quyv3bj" path="res://views/editor/containers/tool_manager/brush_menu.tscn" id="1_omk8e"]
4+
35
[node name="Tools" type="Control" unique_id=1657501930]
46
layout_mode = 3
57
anchors_preset = 15
68
anchor_right = 1.0
79
anchor_bottom = 1.0
810
grow_horizontal = 2
911
grow_vertical = 2
12+
13+
[node name="ToolList" type="TabContainer" parent="." unique_id=1300534775]
14+
layout_mode = 1
15+
anchors_preset = 15
16+
anchor_right = 1.0
17+
anchor_bottom = 1.0
18+
grow_horizontal = 2
19+
grow_vertical = 2
20+
current_tab = 0
21+
22+
[node name="BrushMenu" parent="ToolList" unique_id=1654936513 instance=ExtResource("1_omk8e")]
23+
layout_mode = 2

views/editor/editor.gd

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ extends Node
77

88
var project: Project
99
var current_page: Page
10-
1110
var current_tool: Tool
1211

1312
func _ready() -> void:
@@ -28,8 +27,6 @@ func _ready() -> void:
2827

2928
project.new_project(256, 192)
3029

31-
current_tool = Brush.new() # Placeholder for now.
32-
3330
func _handle_canvas_input(event: InputEvent) -> void:
3431
if event is InputEventMouse:
3532
var canvas_pos = canvas.dynamic_node.get_local_mouse_position()

0 commit comments

Comments
 (0)