-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iMouse has normalized values [x, y, x_prev, y_prev]
- Loading branch information
1 parent
0590252
commit e537d66
Showing
8 changed files
with
110 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
let mouseX: number = -0; | ||
let mouseY: number = -0; | ||
let mouseBinded: boolean = false; | ||
|
||
export function bindMouseListener(container: HTMLElement) { | ||
if (mouseBinded) { | ||
return; | ||
} | ||
mouseBinded = true; | ||
container.addEventListener('mousemove', (event) => { | ||
mouseX = event.clientX; | ||
mouseY = event.clientY; | ||
}, {passive: true}); | ||
} | ||
|
||
export function getMousePosition(): [number, number] { | ||
return [mouseX, mouseY]; | ||
} | ||
|
||
export type Rect = { | ||
left: number, | ||
top: number, | ||
width: number, | ||
height: number, | ||
} | ||
|
||
export function getNormalizedMousePosition(container: Rect, mouse: [number, number]): [number, number] { | ||
const x = (mouse[0] - container.left) / container.width; | ||
const y = 1 - (mouse[1] - container.top) / container.height; | ||
return [x, y]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters