| 64 | |
| 65 | const HAND_STATE = {}; |
| 66 | export const fireHandEvent = (context, hand, eventName, args = {}) => { |
| 67 | let oldState = hand.state; |
| 68 | let newState = hand.state; |
| 69 | |
| 70 | // Keep firing state's events until the state stops changing |
| 71 | do { |
| 72 | oldState = newState; |
| 73 | const event = oldState[eventName]; |
| 74 | if (event === undefined) break; |
| 75 | newState = event({ context, hand, ...args }); |
| 76 | } while (oldState !== newState); |
| 77 | |
| 78 | // Update cursor if we need to |
| 79 | if (newState.cursor !== hand.cursor) { |
| 80 | context.canvas.style["cursor"] = newState.cursor; |
| 81 | hand.cursor = newState.cursor; |
| 82 | } |
| 83 | |
| 84 | if (hand.hidden) { |
| 85 | context.canvas.style["cursor"] = "crosshair"; |
| 86 | } |
| 87 | |
| 88 | hand.state = newState; |
| 89 | }; |
| 90 | |
| 91 | export const registerRightClick = () => { |
| 92 | on.contextmenu((e) => e.preventDefault(), { passive: false }); |