Created
November 16, 2016 20:44
-
-
Save avnik/633c1fc49a19b0406dca51bfcf6ed8fd to your computer and use it in GitHub Desktop.
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
let get_mouse_pos (canvas:Html.canvasElement) event = | |
let rect = canvas##getBoundingClientRect() in | |
let top = rect##.top | |
and bottom = rect##.bottom | |
and right = rect##.right | |
and left = rect##.left | |
and clientX = event##.clientX | |
and clientY = event##.clientY | |
and width = canvas##.width | |
and height = canvas##.height in | |
let x = (clientX - left)/(right - left)*width | |
and y = (clientY - top)/(bottom - top)*height | |
in x, y | |
;; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment