1
1
class_name RectangleTool
2
2
extends CanvasTool
3
3
4
- # -------------------------------------------------------------------------------------------------
5
- const PRESSURE := 0.5
6
-
7
4
# -------------------------------------------------------------------------------------------------
8
5
@export var pressure_curve : Curve
9
6
var _start_position_top_left : Vector2
10
7
11
8
# -------------------------------------------------------------------------------------------------
12
9
func tool_event (event : InputEvent ) -> void :
13
10
_cursor .set_pressure (1.0 )
11
+ var pressure : float = Settings .get_value (
12
+ Settings .GENERAL_TOOL_PRESSURE ,
13
+ Config .DEFAULT_TOOL_PRESSURE
14
+ )
14
15
15
16
if event is InputEventMouseMotion :
16
17
if performing_stroke :
17
18
_cursor .set_pressure (event .pressure )
18
19
remove_all_stroke_points ()
19
- _make_rectangle (PRESSURE )
20
+ _make_rectangle (pressure )
20
21
21
22
# Start + End
22
23
elif event is InputEventMouseButton && ! disable_stroke :
23
24
if event .button_index == MOUSE_BUTTON_LEFT :
24
25
if event .pressed :
25
26
start_stroke ()
26
27
_start_position_top_left = _cursor .global_position
27
- _make_rectangle (PRESSURE )
28
+ _make_rectangle (pressure )
28
29
elif ! event .pressed && performing_stroke :
29
30
remove_all_stroke_points ()
30
- _make_rectangle (PRESSURE )
31
+ _make_rectangle (pressure )
31
32
end_stroke ()
32
33
33
34
# -------------------------------------------------------------------------------------------------
34
35
func _make_rectangle (pressure : float ) -> void :
35
36
pressure = pressure_curve .sample (pressure )
37
+
36
38
var bottom_right_point := _cursor .global_position
37
39
var height := bottom_right_point .y - _start_position_top_left .y
38
40
var width := bottom_right_point .x - _start_position_top_left .x
@@ -41,6 +43,7 @@ func _make_rectangle(pressure: float) -> void:
41
43
42
44
var w_offset := width * 0.02
43
45
var h_offset := height * 0.02
46
+
44
47
add_subdivided_line (_start_position_top_left , top_right_point - Vector2 (w_offset , 0 ), pressure )
45
48
add_subdivided_line (top_right_point , bottom_right_point - Vector2 (0 , h_offset ), pressure )
46
49
add_subdivided_line (bottom_right_point , bottom_left_point + Vector2 (w_offset , 0 ), pressure )
0 commit comments