gl2d
Version:
2D graphics package for WebGL
50 lines • 2.06 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var mouseOrTouch_1 = require("./mouseOrTouch");
var vec2_1 = require("../struct/vec2");
var PanTool = (function (_super) {
__extends(PanTool, _super);
function PanTool() {
return _super !== null && _super.apply(this, arguments) || this;
}
PanTool.prototype.onSurfaceEvent = function (event) {
// Check previous point is set
if (!this.previous) {
return this.onStart(event);
}
// Delegate based on status of action
switch (event.status) {
case 0 /* Start */:
return this.onStart(event);
case 2 /* Drag */:
return this.onDrag(event);
case 4 /* End */:
this.previous = null;
}
};
PanTool.prototype.onStart = function (event) {
this.previous = this.getPrimaryPointer(event);
};
PanTool.prototype.onDrag = function (event) {
var current = this.getPrimaryPointer(event);
// Translate by vector from current point to previous point (reverse direction)
var toPrevious = vec2_1.Vec2.fromPointToPoint(current, this.previous);
var actual = event.target.offset(toPrevious);
// Keep track of previous point
this.previous.x = current.x + actual.x;
this.previous.y = current.y + actual.y;
};
return PanTool;
}(mouseOrTouch_1._MouseOrTouchTool));
exports.PanTool = PanTool;
//# sourceMappingURL=pan.js.map