main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1010 bytes
|
Line | |
---|
1 | import { CoordinatesEngine } from './CoordinatesEngine'
|
---|
2 | import { pointerValues } from '../utils/events'
|
---|
3 | import { V } from '../utils/maths'
|
---|
4 |
|
---|
5 | export class HoverEngine extends CoordinatesEngine<'hover'> {
|
---|
6 | ingKey = 'hovering' as const
|
---|
7 |
|
---|
8 | enter(event: PointerEvent) {
|
---|
9 | if (this.config.mouseOnly && event.pointerType !== 'mouse') return
|
---|
10 | this.start(event)
|
---|
11 | this.computeValues(pointerValues(event))
|
---|
12 |
|
---|
13 | this.compute(event)
|
---|
14 | this.emit()
|
---|
15 | }
|
---|
16 |
|
---|
17 | leave(event: PointerEvent) {
|
---|
18 | if (this.config.mouseOnly && event.pointerType !== 'mouse') return
|
---|
19 |
|
---|
20 | const state = this.state
|
---|
21 | if (!state._active) return
|
---|
22 |
|
---|
23 | state._active = false
|
---|
24 | const values = pointerValues(event)
|
---|
25 | state._movement = state._delta = V.sub(values, state._values)
|
---|
26 |
|
---|
27 | this.computeValues(values)
|
---|
28 | this.compute(event)
|
---|
29 |
|
---|
30 | state.delta = state.movement
|
---|
31 | this.emit()
|
---|
32 | }
|
---|
33 |
|
---|
34 | bind(bindFunction: any) {
|
---|
35 | bindFunction('pointer', 'enter', this.enter.bind(this))
|
---|
36 | bindFunction('pointer', 'leave', this.leave.bind(this))
|
---|
37 | }
|
---|
38 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.