Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Autoload/Tools.gd
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ var pen_pressure_min := 0.2
var pen_pressure_max := 0.8
var pressure_buf := [0, 0] # past pressure value buffer
var pen_inverted := false
## Checks if pen pressure caused a change in brush size in the current frame.
var pressure_changed_size := false
var mouse_velocity := 0.0
var mouse_velocity_min_thres := 0.2
var mouse_velocity_max_thres := 0.8
Expand Down Expand Up @@ -832,6 +834,7 @@ func handle_draw(position: Vector2i, event: InputEvent) -> void:
active_button = -1

if event is InputEventMouseMotion:
var last_pressure_increment := roundi(lerpf(0, brush_size_max_increment, pen_pressure))
pen_pressure = event.pressure
# Workaround https://github.com/godotengine/godot/issues/53033#issuecomment-930409407
# If a pressure value of 1 is encountered, "correct" the value by
Expand All @@ -857,7 +860,11 @@ func handle_draw(position: Vector2i, event: InputEvent) -> void:
mouse_velocity = 1.0
if active_button == -1: # there is no meaning of velocity without an active tool
mouse_velocity = 0.0
if not position == _last_position:
# Check if we should update with new brush size if pressure is changed enough, or if the
# mouse was moved by an entire pixel
var dynamic_pressure_increment := roundi(lerpf(0, brush_size_max_increment, pen_pressure))
pressure_changed_size = last_pressure_increment != dynamic_pressure_increment
if not position == _last_position or pressure_changed_size:
_last_position = position
_slots[MOUSE_BUTTON_LEFT].tool_node.cursor_move(position)
_slots[MOUSE_BUTTON_RIGHT].tool_node.cursor_move(position)
Expand Down
10 changes: 8 additions & 2 deletions src/Tools/DesignTools/Eraser.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extends BaseDrawTool

var _last_position := Vector2.INF
var _last_position := Vector2i(Vector2.INF)
var _clear_image: Image
var _changed := false

Expand Down Expand Up @@ -83,7 +83,13 @@ func draw_move(pos_i: Vector2i) -> void:
cursor_text = d.text
update_line_polylines(_line_start, _line_end)
else:
draw_fill_gap(_last_position, pos)
# If the tool moved, fill the middle points between last (exclusive)
# and new (inclusive) pixel position.
if _last_position != Vector2i(pos):
draw_fill_gap(_last_position, pos)
# If tool didn't move but pressure changed we still need to re-draw with new size
elif Tools.pressure_changed_size:
draw_tool(pos)
_last_position = pos
cursor_text = ""
Global.canvas.sprite_changed_this_frame = true
Expand Down
8 changes: 7 additions & 1 deletion src/Tools/DesignTools/Pencil.gd
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,13 @@ func draw_move(pos_i: Vector2i) -> void:
cursor_text = d.text
update_line_polylines(_line_start, _line_end)
else:
draw_fill_gap(_last_position, pos)
# If the tool moved, fill the middle points between last (exclusive)
# and new (inclusive) pixel position.
if _last_position != Vector2i(pos):
draw_fill_gap(_last_position, pos)
# If tool didn't move but pressure changed we still need to re-draw with new size
elif Tools.pressure_changed_size:
draw_tool(pos)
_last_position = pos
cursor_text = ""
Global.canvas.sprite_changed_this_frame = true
Expand Down
Loading