Skip to content

Commit 1074e0a

Browse files
committed
Fixed tool pressure
1 parent 172e11a commit 1074e0a

File tree

5 files changed

+28
-20
lines changed

5 files changed

+28
-20
lines changed

lorien/BrushStroke/BrushStroke.gd

+1-3
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ func enable_collider(enable: bool) -> void:
103103

104104
# ------------------------------------------------------------------------------------------------
105105
func refresh() -> void:
106-
var max_pressure := float(MAX_PRESSURE_VALUE)
107-
108106
_line2d.clear_points()
109107
_line2d.width_curve.clear_points()
110108

@@ -122,7 +120,7 @@ func refresh() -> void:
122120
# Add the point
123121
_line2d.add_point(point)
124122
var pressure: float = pressures[p_idx]
125-
_line2d.width_curve.add_point(Vector2(curve_step * p_idx, pressure / max_pressure))
123+
_line2d.width_curve.add_point(Vector2(curve_step * p_idx, pressure / MAX_PRESSURE_VALUE))
126124
p_idx += 1
127125

128126
# Update the extreme values

lorien/Config.gd

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const DEFAULT_BRUSH_COLOR := Color.WHITE
1717
const DEFAULT_BRUSH_SIZE := 10
1818
const DEFAULT_PRESSURE_SENSITIVITY := 1.0
1919
const DEFAULT_CONSTANT_PRESSURE := false
20+
const DEFAULT_TOOL_PRESSURE := 0.5
21+
const DEFAULT_STABILIZER_STRENGTH := 0.5
2022
const DEFAULT_SELECTION_COLOR := Color("#2a967c")
2123
const DEFAULT_FOREGROUND_FPS := 144
2224
const DEFAULT_BACKGROUND_FPS := 10
@@ -25,5 +27,3 @@ const DEFAULT_UI_SCALE_MODE := Types.UIScale.AUTO
2527
const DEFAULT_UI_SCALE := 1.0
2628
const DEFAULT_GRID_PATTERN := Types.GridPattern.DOTS
2729
const DEFAULT_GRID_SIZE := 25.0
28-
const DEFAULT_TOOL_PRESSURE := 0.5
29-
const DEFAULT_STABILIZER_STRENGTH := 0.5

lorien/InfiniteCanvas/Tools/CircleTool.gd

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ class_name CircleTool
22
extends CanvasTool
33

44
# -------------------------------------------------------------------------------------------------
5-
const PRESSURE := 0.5
65
const STEP_IN_MOTION := 15
76
const STEP_STATIC := 4
87

@@ -25,14 +24,18 @@ func _init() -> void:
2524
# -------------------------------------------------------------------------------------------------
2625
func tool_event(event: InputEvent) -> void:
2726
_cursor.set_pressure(1.0)
27+
var pressure : float = Settings.get_value(
28+
Settings.GENERAL_TOOL_PRESSURE,
29+
Config.DEFAULT_TOOL_PRESSURE
30+
)
2831

2932
var should_draw_circle := Input.is_key_pressed(KEY_SHIFT)
3033

3134
if event is InputEventMouseMotion:
3235
if performing_stroke:
3336
_cursor.set_pressure(event.pressure)
3437
remove_all_stroke_points()
35-
_make_ellipse(PRESSURE, STEP_IN_MOTION, should_draw_circle)
38+
_make_ellipse(pressure, STEP_IN_MOTION, should_draw_circle)
3639

3740
# Start + End
3841
elif event is InputEventMouseButton && !disable_stroke:
@@ -41,10 +44,10 @@ func tool_event(event: InputEvent) -> void:
4144
start_stroke()
4245
_start_position_top_left = _cursor.global_position
4346
remove_all_stroke_points()
44-
_make_ellipse(PRESSURE, STEP_IN_MOTION, should_draw_circle)
47+
_make_ellipse(pressure, STEP_IN_MOTION, should_draw_circle)
4548
elif !event.pressed && performing_stroke:
4649
remove_all_stroke_points()
47-
_make_ellipse(PRESSURE, STEP_STATIC, should_draw_circle)
50+
_make_ellipse(pressure, STEP_STATIC, should_draw_circle)
4851
end_stroke()
4952

5053
# -------------------------------------------------------------------------------------------------

lorien/InfiniteCanvas/Tools/LineTool.gd

+9-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ var _tail: Vector2
1313
# -------------------------------------------------------------------------------------------------
1414
func tool_event(event: InputEvent) -> void:
1515
_cursor.set_pressure(1.0)
16+
var pressure : float = Settings.get_value(
17+
Settings.GENERAL_TOOL_PRESSURE,
18+
Config.DEFAULT_TOOL_PRESSURE
19+
)
1620

1721
# Snap modifier
1822
if event is InputEventKey:
@@ -25,20 +29,20 @@ func tool_event(event: InputEvent) -> void:
2529
_cursor.set_pressure(event.pressure)
2630
remove_last_stroke_point()
2731
if _snapping_enabled:
28-
_tail = _add_point_at_snap_pos(0.5)
32+
_tail = _add_point_at_snap_pos(pressure)
2933
else:
30-
_tail = _add_point_at_mouse_pos(0.5)
34+
_tail = _add_point_at_mouse_pos(pressure)
3135

3236
# Start + End
3337
elif event is InputEventMouseButton && !disable_stroke:
3438
if event.button_index == MOUSE_BUTTON_LEFT:
3539
if event.pressed:
3640
start_stroke()
37-
_head = _add_point_at_mouse_pos(0.5)
38-
_tail = _add_point_at_mouse_pos(0.5)
41+
_head = _add_point_at_mouse_pos(pressure)
42+
_tail = _add_point_at_mouse_pos(pressure)
3943
elif !event.pressed && performing_stroke:
4044
remove_last_stroke_point()
41-
add_subdivided_line(_head, _tail, pressure_curve.sample(0.5))
45+
add_subdivided_line(_head, _tail, pressure_curve.sample(pressure))
4246
end_stroke()
4347

4448
# -------------------------------------------------------------------------------------------------

lorien/InfiniteCanvas/Tools/RectangleTool.gd

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,40 @@
11
class_name RectangleTool
22
extends CanvasTool
33

4-
# -------------------------------------------------------------------------------------------------
5-
const PRESSURE := 0.5
6-
74
# -------------------------------------------------------------------------------------------------
85
@export var pressure_curve: Curve
96
var _start_position_top_left: Vector2
107

118
# -------------------------------------------------------------------------------------------------
129
func tool_event(event: InputEvent) -> void:
1310
_cursor.set_pressure(1.0)
11+
var pressure : float = Settings.get_value(
12+
Settings.GENERAL_TOOL_PRESSURE,
13+
Config.DEFAULT_TOOL_PRESSURE
14+
)
1415

1516
if event is InputEventMouseMotion:
1617
if performing_stroke:
1718
_cursor.set_pressure(event.pressure)
1819
remove_all_stroke_points()
19-
_make_rectangle(PRESSURE)
20+
_make_rectangle(pressure)
2021

2122
# Start + End
2223
elif event is InputEventMouseButton && !disable_stroke:
2324
if event.button_index == MOUSE_BUTTON_LEFT:
2425
if event.pressed:
2526
start_stroke()
2627
_start_position_top_left = _cursor.global_position
27-
_make_rectangle(PRESSURE)
28+
_make_rectangle(pressure)
2829
elif !event.pressed && performing_stroke:
2930
remove_all_stroke_points()
30-
_make_rectangle(PRESSURE)
31+
_make_rectangle(pressure)
3132
end_stroke()
3233

3334
# -------------------------------------------------------------------------------------------------
3435
func _make_rectangle(pressure: float) -> void:
3536
pressure = pressure_curve.sample(pressure)
37+
3638
var bottom_right_point := _cursor.global_position
3739
var height := bottom_right_point.y - _start_position_top_left.y
3840
var width := bottom_right_point.x - _start_position_top_left.x
@@ -41,6 +43,7 @@ func _make_rectangle(pressure: float) -> void:
4143

4244
var w_offset := width*0.02
4345
var h_offset := height*0.02
46+
4447
add_subdivided_line(_start_position_top_left, top_right_point - Vector2(w_offset, 0), pressure)
4548
add_subdivided_line(top_right_point, bottom_right_point - Vector2(0, h_offset), pressure)
4649
add_subdivided_line(bottom_right_point, bottom_left_point + Vector2(w_offset, 0), pressure)

0 commit comments

Comments
 (0)