Skip to content

Commit

Permalink
Fixed not being able to draw simple dots with the brush
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrlabs committed Nov 6, 2023
1 parent aeb3a73 commit 7aceca3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fixed blurry interface on some macOS devices
- Fixed invisible cursor in some situations
- Fixed issue where moved brush strokes stayed in their original positions after exporting to SVG
- Fixed not being able to draw simple dots by just clicking/tapping the brush once

### Changed
- Changing the application language does not require a restart now
Expand Down
2 changes: 1 addition & 1 deletion lorien/BrushStroke/BrushStrokeOptimizer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func reset() -> void:

# -------------------------------------------------------------------------------------------------
func optimize(s: BrushStroke) -> void:
if s.points.size() < 3:
if s.points.size() < 8:
return

var max_angle_diff := ANGLE_THRESHOLD
Expand Down
38 changes: 36 additions & 2 deletions lorien/InfiniteCanvas/Tools/BrushTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extends CanvasTool
# -------------------------------------------------------------------------------------------------
const MOVEMENT_THRESHOLD := 1.0
const MIN_PRESSURE := 0.1
const DOT_MAX_DISTANCE_THRESHOLD := 4.0

# -------------------------------------------------------------------------------------------------
export var pressure_curve: Curve
Expand All @@ -30,6 +31,9 @@ func tool_event(event: InputEvent) -> void:
start_stroke()
_first_point = true
elif performing_stroke:
if _is_stroke_a_dot():
_canvas.remove_all_stroke_points()
_draw_point()
end_stroke()

# -------------------------------------------------------------------------------------------------
Expand All @@ -39,14 +43,14 @@ func _process(delta: float) -> void:
var diff := _current_position.distance_squared_to(_last_accepted_position)
if diff <= MOVEMENT_THRESHOLD || _current_pressure <= MIN_PRESSURE:
return

var sensitivity: float = Settings.get_value(Settings.GENERAL_PRESSURE_SENSITIVITY, Config.DEFAULT_PRESSURE_SENSITIVITY)
var point_pressure = pressure_curve.interpolate(_current_pressure) * sensitivity
if _first_point:
point_pressure *= 1.4
_first_point = false
var point_position := xform_vector2(_current_position)

var point_position := xform_vector2(_current_position)
add_stroke_point(point_position, point_pressure)

# If the brush stroke gets too long, we make a new one. This is necessary because Godot limits the number
Expand All @@ -58,3 +62,33 @@ func _process(delta: float) -> void:

_last_accepted_position = _current_position

# -------------------------------------------------------------------------------------------------
func _is_stroke_a_dot() -> bool:
var stroke := get_current_brush_stroke()

if stroke.points.size() < 2:
return true

if stroke.points.size() == 2:
var dist: float = stroke.points[0].distance_to(stroke.points[1])
if dist <= DOT_MAX_DISTANCE_THRESHOLD:
return true

if stroke.points.size() <= 6:
var dist := 0.0
for i in stroke.points.size() - 1:
dist += stroke.points[i].distance_to(stroke.points[i + 1])
if dist <= DOT_MAX_DISTANCE_THRESHOLD:
return true

return false

# -------------------------------------------------------------------------------------------------
func _draw_point() -> void:
var origin := xform_vector2(_current_position)
var pressure = 0.5
var offset := 1.5

add_stroke_point(origin, pressure)
add_stroke_point(origin + Vector2(0, offset), pressure)
add_stroke_point(origin + Vector2(-offset/2.0, offset/2.0), pressure)

0 comments on commit 7aceca3

Please sign in to comment.