Adds time data to draw points.

Not sure if I'll keep this, but together with the improved trimming it actually reduces the size of these arrays.
pull/71/head
Steve Ruiz 2021-08-31 16:20:01 +01:00
rodzic 2771ae986f
commit db13880ceb
4 zmienionych plików z 18 dodań i 5 usunięć

Wyświetl plik

@ -267,10 +267,14 @@ export class Draw extends TLDrawShapeUtil<DrawShape> {
onSessionComplete(shape: DrawShape): Partial<DrawShape> {
const bounds = this.getBounds(shape)
const [x1, y1] = Vec.sub([bounds.minX, bounds.minY], shape.point)
const [x1, y1] = Vec.round(Vec.sub([bounds.minX, bounds.minY], shape.point))
const points = shape.points.map(([x0, y0, p, t]) => Vec.round([x0 - x1, y0 - y1]).concat(p, t))
console.log(points)
return {
points: shape.points.map(([x0, y0, p]) => [x0 - x1, y0 - y1, p]),
points,
point: Vec.add(shape.point, [x1, y1]),
}
}

Wyświetl plik

@ -245,7 +245,6 @@ export class Text extends TLDrawShapeUtil<TextShape> {
getBounds(shape: TextShape): TLBounds {
const bounds = Utils.getFromCache(this.boundsCache, shape, () => {
if (!melm) {
console.log('no melm!')
// We're in SSR
return { minX: 0, minY: 0, maxX: 0, maxY: 0, width: 0, height: 0 }
}

Wyświetl plik

@ -12,6 +12,7 @@ export class DrawSession implements Session {
snapshot: DrawSnapshot
isLocked?: boolean
lockedDirection?: 'horizontal' | 'vertical'
startTime: number
constructor(data: Data, id: string, point: number[]) {
this.origin = point
@ -24,6 +25,7 @@ export class DrawSession implements Session {
// when the draw session ends; if the user hasn't added additional
// points, this single point will be interpreted as a "dot" shape.
this.points = []
this.startTime = 0
}
start = () => void null
@ -33,7 +35,8 @@ export class DrawSession implements Session {
// Roundabout way of preventing the "dot" from showing while drawing
if (this.points.length === 0) {
this.points.push([0, 0, pressure])
this.startTime = Date.now()
this.points.push([0, 0, pressure, 0])
}
// Drawing while holding shift will "lock" the pen to either the
@ -81,7 +84,10 @@ export class DrawSession implements Session {
// Don't add duplicate points. It's important to test against the
// adjusted (low-passed) point rather than the input point.
const newPoint = Vec.round([...Vec.sub(this.previous, this.origin), pressure])
const newPoint = Vec.round(Vec.sub(this.previous, this.origin)).concat(
pressure,
Date.now() - this.startTime
)
if (Vec.isEqual(this.last, newPoint)) return

Wyświetl plik

@ -982,8 +982,12 @@ export class TLDrawState extends StateManager<Data> {
}
selectAll = () => {
if (this.session) return
this.setSelectedIds(Object.keys(this.page.shapes))
this.addToSelectHistory(this.selectedIds)
if (this.appState.activeTool !== 'select') {
this.selectTool('select')
}
return this
}