import { IExample } from "../app" ; export default class InputHandler { protected example : IExample ; protected isMouseDown : boolean = false ; protected lastMouseX : number ; protected lastMouseY : number ; public constructor ( example ) { let self = this ; this . example = example ; window . onmousedown = function ( e ) { self . onMouseDown ( e . clientX , e . clientY ) ; } ; window . onmousemove = function ( e ) { self . onMouseMove ( e . clientX , e . clientY ) ; } ; window . onmouseup = function ( e ) { self . onMouseUp ( e . clientX , e . clientY ) ; } ; window . onmousewheel = function ( e ) { self . onMouseWheel ( e . deltaY ) ; } ; } protected onMouseDown ( x , y ) { this . isMouseDown = true ; this . lastMouseX = x ; this . lastMouseY = y ; } protected onMouseMove ( x , y ) { if ( this . isMouseDown ) { let deltaX = x - this . lastMouseX ; let deltaY = y - this . lastMouseY ; this . example . onMove ( deltaX , deltaY ) ; this . lastMouseY = y ; this . lastMouseX = x ; } } protected onMouseUp ( x , y ) { this . isMouseDown = false ; } protected onMouseWheel ( delta ) { if ( this . example . onWheel ) { this . example . onWheel ( delta ) ; } } }