var Class = require('../utils/Class'); var Pointer = new Class({ initialize: function Pointer(manager, id){ this.manager = manager; this.id = id; this.event; this.camera = null ; this.buttons = 0; this.x = 0; this.y = 0; this.downX = 0; this.downY = 0; this.downTime = 0; this.upX = 0; this.upY = 0; this.upTime = 0; this.primaryDown = false ; this.dragState = 0; this.isDown = false ; this.dirty = false ; this.justDown = false ; this.justUp = false ; this.justMoved = false ; } , reset: function (){ this.buttons = 0; this.dirty = false ; this.isDown = false ; this.justDown = false ; this.justUp = false ; this.justMoved = false ; } , touchmove: function (event, time){ this.event = event; this.x = this.manager.transformX(event.changedTouches[0].pageX); this.y = this.manager.transformY(event.changedTouches[0].pageY); this.justMoved = true ; this.dirty = true ; } , move: function (event, time){ if (event.buttons) { this.buttons = event.buttons; } this.event = event; this.x = this.manager.transformX(event.pageX); this.y = this.manager.transformY(event.pageY); this.justMoved = true ; this.dirty = true ; } , down: function (event, time){ if (event.buttons) { this.buttons = event.buttons; } this.event = event; this.x = this.manager.transformX(event.pageX); this.y = this.manager.transformY(event.pageY); if (event.button === 0) { this.primaryDown = true ; this.downX = this.x; this.downY = this.y; this.downTime = time; } this.justDown = true ; this.isDown = true ; this.dirty = true ; } , touchstart: function (event, time){ this.buttons = 1; this.event = event; this.x = this.manager.transformX(event.changedTouches[0].pageX); this.y = this.manager.transformY(event.changedTouches[0].pageY); this.primaryDown = true ; this.downX = this.x; this.downY = this.y; this.downTime = time; this.justDown = true ; this.isDown = true ; this.dirty = true ; } , up: function (event, time){ if (event.buttons) { this.buttons = event.buttons; } this.event = event; this.x = this.manager.transformX(event.pageX); this.y = this.manager.transformY(event.pageY); if (event.button === 0) { this.primaryDown = false ; this.upX = this.x; this.upY = this.y; this.upTime = time; } this.justUp = true ; this.isDown = false ; this.dirty = true ; } , touchend: function (event, time){ this.buttons = 0; this.event = event; this.x = this.manager.transformX(event.changedTouches[0].pageX); this.y = this.manager.transformY(event.changedTouches[0].pageY); this.primaryDown = false ; this.upX = this.x; this.upY = this.y; this.upTime = time; this.justUp = true ; this.isDown = false ; this.dirty = true ; } , noButtonDown: function (){ return (this.buttons === 0); } , leftButtonDown: function (){ return (this.buttons & 1); } , rightButtonDown: function (){ return (this.buttons & 2); } , middleButtonDown: function (){ return (this.buttons & 4); } , backButtonDown: function (){ return (this.buttons & 8); } , forwardButtonDown: function (){ return (this.buttons & 16); } } ); module.exports = Pointer;