Skip to content

Commit

Permalink
Fixed tool pressure
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrlabs committed Sep 29, 2024
1 parent 172e11a commit a0ce389
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
4 changes: 1 addition & 3 deletions lorien/BrushStroke/BrushStroke.gd
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ func enable_collider(enable: bool) -> void:

# ------------------------------------------------------------------------------------------------
func refresh() -> void:
var max_pressure := float(MAX_PRESSURE_VALUE)

_line2d.clear_points()
_line2d.width_curve.clear_points()

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

# Update the extreme values
Expand Down
2 changes: 2 additions & 0 deletions lorien/BrushStroke/BrushStrokeOptimizer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ func reset() -> void:

# -------------------------------------------------------------------------------------------------
func optimize(s: BrushStroke) -> void:
return

if s.points.size() < 8:
return

Expand Down
4 changes: 2 additions & 2 deletions lorien/Config.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const DEFAULT_BRUSH_COLOR := Color.WHITE
const DEFAULT_BRUSH_SIZE := 10
const DEFAULT_PRESSURE_SENSITIVITY := 1.0
const DEFAULT_CONSTANT_PRESSURE := false
const DEFAULT_TOOL_PRESSURE := 0.5
const DEFAULT_STABILIZER_STRENGTH := 0.5
const DEFAULT_SELECTION_COLOR := Color("#2a967c")
const DEFAULT_FOREGROUND_FPS := 144
const DEFAULT_BACKGROUND_FPS := 10
Expand All @@ -25,5 +27,3 @@ const DEFAULT_UI_SCALE_MODE := Types.UIScale.AUTO
const DEFAULT_UI_SCALE := 1.0
const DEFAULT_GRID_PATTERN := Types.GridPattern.DOTS
const DEFAULT_GRID_SIZE := 25.0
const DEFAULT_TOOL_PRESSURE := 0.5
const DEFAULT_STABILIZER_STRENGTH := 0.5
11 changes: 7 additions & 4 deletions lorien/InfiniteCanvas/Tools/CircleTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class_name CircleTool
extends CanvasTool

# -------------------------------------------------------------------------------------------------
const PRESSURE := 0.5
const STEP_IN_MOTION := 15
const STEP_STATIC := 4

Expand All @@ -25,14 +24,18 @@ func _init() -> void:
# -------------------------------------------------------------------------------------------------
func tool_event(event: InputEvent) -> void:
_cursor.set_pressure(1.0)
var pressure : float = Settings.get_value(
Settings.GENERAL_TOOL_PRESSURE,
Config.DEFAULT_TOOL_PRESSURE
)

var should_draw_circle := Input.is_key_pressed(KEY_SHIFT)

if event is InputEventMouseMotion:
if performing_stroke:
_cursor.set_pressure(event.pressure)
remove_all_stroke_points()
_make_ellipse(PRESSURE, STEP_IN_MOTION, should_draw_circle)
_make_ellipse(pressure, STEP_IN_MOTION, should_draw_circle)

# Start + End
elif event is InputEventMouseButton && !disable_stroke:
Expand All @@ -41,10 +44,10 @@ func tool_event(event: InputEvent) -> void:
start_stroke()
_start_position_top_left = _cursor.global_position
remove_all_stroke_points()
_make_ellipse(PRESSURE, STEP_IN_MOTION, should_draw_circle)
_make_ellipse(pressure, STEP_IN_MOTION, should_draw_circle)
elif !event.pressed && performing_stroke:
remove_all_stroke_points()
_make_ellipse(PRESSURE, STEP_STATIC, should_draw_circle)
_make_ellipse(pressure, STEP_STATIC, should_draw_circle)
end_stroke()

# -------------------------------------------------------------------------------------------------
Expand Down
14 changes: 9 additions & 5 deletions lorien/InfiniteCanvas/Tools/LineTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ var _tail: Vector2
# -------------------------------------------------------------------------------------------------
func tool_event(event: InputEvent) -> void:
_cursor.set_pressure(1.0)
var pressure : float = Settings.get_value(
Settings.GENERAL_TOOL_PRESSURE,
Config.DEFAULT_TOOL_PRESSURE
)

# Snap modifier
if event is InputEventKey:
Expand All @@ -25,20 +29,20 @@ func tool_event(event: InputEvent) -> void:
_cursor.set_pressure(event.pressure)
remove_last_stroke_point()
if _snapping_enabled:
_tail = _add_point_at_snap_pos(0.5)
_tail = _add_point_at_snap_pos(pressure)
else:
_tail = _add_point_at_mouse_pos(0.5)
_tail = _add_point_at_mouse_pos(pressure)

# Start + End
elif event is InputEventMouseButton && !disable_stroke:
if event.button_index == MOUSE_BUTTON_LEFT:
if event.pressed:
start_stroke()
_head = _add_point_at_mouse_pos(0.5)
_tail = _add_point_at_mouse_pos(0.5)
_head = _add_point_at_mouse_pos(pressure)
_tail = _add_point_at_mouse_pos(pressure)
elif !event.pressed && performing_stroke:
remove_last_stroke_point()
add_subdivided_line(_head, _tail, pressure_curve.sample(0.5))
add_subdivided_line(_head, _tail, pressure_curve.sample(pressure))
end_stroke()

# -------------------------------------------------------------------------------------------------
Expand Down
15 changes: 9 additions & 6 deletions lorien/InfiniteCanvas/Tools/RectangleTool.gd
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
class_name RectangleTool
extends CanvasTool

# -------------------------------------------------------------------------------------------------
const PRESSURE := 0.5

# -------------------------------------------------------------------------------------------------
@export var pressure_curve: Curve
var _start_position_top_left: Vector2

# -------------------------------------------------------------------------------------------------
func tool_event(event: InputEvent) -> void:
_cursor.set_pressure(1.0)
var pressure : float = Settings.get_value(
Settings.GENERAL_TOOL_PRESSURE,
Config.DEFAULT_TOOL_PRESSURE
)

if event is InputEventMouseMotion:
if performing_stroke:
_cursor.set_pressure(event.pressure)
remove_all_stroke_points()
_make_rectangle(PRESSURE)
_make_rectangle(pressure)

# Start + End
elif event is InputEventMouseButton && !disable_stroke:
if event.button_index == MOUSE_BUTTON_LEFT:
if event.pressed:
start_stroke()
_start_position_top_left = _cursor.global_position
_make_rectangle(PRESSURE)
_make_rectangle(pressure)
elif !event.pressed && performing_stroke:
remove_all_stroke_points()
_make_rectangle(PRESSURE)
_make_rectangle(pressure)
end_stroke()

# -------------------------------------------------------------------------------------------------
func _make_rectangle(pressure: float) -> void:
pressure = pressure_curve.sample(pressure)

var bottom_right_point := _cursor.global_position
var height := bottom_right_point.y - _start_position_top_left.y
var width := bottom_right_point.x - _start_position_top_left.x
Expand All @@ -41,6 +43,7 @@ func _make_rectangle(pressure: float) -> void:

var w_offset := width*0.02
var h_offset := height*0.02

add_subdivided_line(_start_position_top_left, top_right_point - Vector2(w_offset, 0), pressure)
add_subdivided_line(top_right_point, bottom_right_point - Vector2(0, h_offset), pressure)
add_subdivided_line(bottom_right_point, bottom_left_point + Vector2(w_offset, 0), pressure)
Expand Down

0 comments on commit a0ce389

Please sign in to comment.