diff --git a/src/Autoload/Tools.gd b/src/Autoload/Tools.gd index 638dea46a9fa..11bf3d63f5d2 100644 --- a/src/Autoload/Tools.gd +++ b/src/Autoload/Tools.gd @@ -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 @@ -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 @@ -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) diff --git a/src/Tools/DesignTools/Eraser.gd b/src/Tools/DesignTools/Eraser.gd index f48bbffd6fce..4a4004b92f75 100644 --- a/src/Tools/DesignTools/Eraser.gd +++ b/src/Tools/DesignTools/Eraser.gd @@ -1,6 +1,6 @@ extends BaseDrawTool -var _last_position := Vector2.INF +var _last_position := Vector2i(Vector2.INF) var _clear_image: Image var _changed := false @@ -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 diff --git a/src/Tools/DesignTools/Pencil.gd b/src/Tools/DesignTools/Pencil.gd index 0416d5416507..bbbcacdc1226 100644 --- a/src/Tools/DesignTools/Pencil.gd +++ b/src/Tools/DesignTools/Pencil.gd @@ -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