Fix pressure (#3877)

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.
This commit is contained in:
Steve Ruiz 2024-06-04 17:31:19 +02:00 committed by GitHub
parent 15f1d82e7d
commit 876f1ef326
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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 // 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 // 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. // 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.isPen = isPen
this.isPenOrStylus = isPen || (z > 0 && z < 0.5) || (z > 0.5 && z < 1) 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 { segments } = shape.props
const { x, y, z } = this.editor.getPointInShapeSpace(shape, inputs.currentPagePoint).toFixed() const { x, y, z } = this.editor.getPointInShapeSpace(shape, inputs.currentPagePoint).toFixed()
const pressure = this.isPenOrStylus ? +(inputs.currentPagePoint.z! * 1.25).toFixed(2) : 0.5
const newPoint = { x, y, z: this.isPenOrStylus ? +(z! * 1.25).toFixed(2) : 0.5 } const newPoint = { x, y, z: pressure }
switch (this.segmentMode) { switch (this.segmentMode) {
case 'starting_straight': { case 'starting_straight': {