From 876f1ef3268f2380d3fb7bb4ba52608de57bfebf Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Tue, 4 Jun 2024 17:31:19 +0200 Subject: [PATCH] Fix pressure (#3877) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR fixes pen pressure. Previously, `toFixed` loses the `z` of the point. ### Change Type - [x] `sdk` — Changes the tldraw SDK - [x] `bugfix` — Bug fix ### Test Plan 1. use a pen with pressure ### Release Notes - Fixes pen pressure. --- packages/tldraw/src/lib/shapes/draw/toolStates/Drawing.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/tldraw/src/lib/shapes/draw/toolStates/Drawing.ts b/packages/tldraw/src/lib/shapes/draw/toolStates/Drawing.ts index 2fc0c33aa..b72b10d0c 100644 --- a/packages/tldraw/src/lib/shapes/draw/toolStates/Drawing.ts +++ b/packages/tldraw/src/lib/shapes/draw/toolStates/Drawing.ts @@ -177,7 +177,8 @@ export class Drawing extends StateNode { // have our own value for this. The inputs.isPen is only if the input is a regular // pen, like an iPad pen, which needs to trigger "pen mode" in order to avoid // accidental palm touches. We don't have to worry about that with styluses though. - const z = this.info.point.z === undefined ? 0.5 : this.info.point.z + const { z = 0.5 } = this.info.point + this.isPen = isPen this.isPenOrStylus = isPen || (z > 0 && z < 0.5) || (z > 0.5 && z < 1) @@ -304,8 +305,8 @@ export class Drawing extends StateNode { const { segments } = shape.props const { x, y, z } = this.editor.getPointInShapeSpace(shape, inputs.currentPagePoint).toFixed() - - const newPoint = { x, y, z: this.isPenOrStylus ? +(z! * 1.25).toFixed(2) : 0.5 } + const pressure = this.isPenOrStylus ? +(inputs.currentPagePoint.z! * 1.25).toFixed(2) : 0.5 + const newPoint = { x, y, z: pressure } switch (this.segmentMode) { case 'starting_straight': {