Skip to content

Commit

Permalink
attempt to reject invalid pointerType
Browse files Browse the repository at this point in the history
fix for wonderunit/storyboarder#927
#19

doesn't work reliably though, because `pointerType` is not reliable!
  • Loading branch information
audionerd committed Jun 1, 2018
1 parent 35f6fcc commit cfbd190
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ window.fetch('./example/brushes/brushes.json')
})

window.addEventListener('pointermove', function (e) {
console.log('pointermove', e.pointerType, e.timeStamp)
if (gui.domElement.contains(e.target)) return // ignore GUI pointer movement

// if (e.target.parentNode !== document.body) return
Expand Down
22 changes: 21 additions & 1 deletion src/ts/sketch-pane/sketch-pane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ interface IStrokeState {
lastStaticIndex?: number
lastSpacing?: number | undefined
grainOffset?: { x: number, y: number }
// snapshot brush configuration

pointerType: string, // 'mouse' | 'pen' | 'touch'

// snapshot brush configuration
size?: number
color?: number
opacity?: number
Expand Down Expand Up @@ -460,6 +463,16 @@ export default class SketchPane {
strokeContainer.addChild(sprite)
}

acceptsEvent (e: PointerEvent) {
// console.log('down?', this.pointerDown, 'type:', e.pointerType)
// reject if pointer is already down and event pointerType doesn't match initial pointerType
if (this.pointerDown && e.pointerType != this.strokeState.pointerType) {
return false
} else {
return true
}
}

pointerDown = false

down (e: PointerEvent, options = {}) {
Expand All @@ -471,6 +484,8 @@ export default class SketchPane {
}

move (e: PointerEvent) {
if (!this.acceptsEvent(e)) return

if (this.pointerDown) {
this.strokeContinue(e)
}
Expand All @@ -480,6 +495,8 @@ export default class SketchPane {
}

up (e: PointerEvent) {
if (!this.acceptsEvent(e)) return

if (this.pointerDown) {
this.strokeEnd(e)
}
Expand Down Expand Up @@ -509,6 +526,9 @@ export default class SketchPane {
? {x: Math.floor(Math.random() * 100), y: Math.floor(Math.random() * 100)}
: {x: 0, y: 0},

// initial pointer type
pointerType: e.pointerType,

// snapshot brush configuration
size: this.brushSize,
color: this.brushColor,
Expand Down

0 comments on commit cfbd190

Please sign in to comment.