gl2d
Version:
2D graphics package for WebGL
32 lines • 1.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Tool for zooming in and out of a surface based on scroll events and cursor position.
*/
var WheelZoomTool = (function () {
/**
* @param scaleFactor The scale applied to the surface whene scrolling in. The inverse is applied when scrolling out.
* @param minTimeEllapse The minimum number of milliseconds that must elapse between scroll events in order for the scale to be applied.
*/
function WheelZoomTool(scaleFactor, minTimeElapse) {
/**
* The time of the last scale in milliseconds.
*/
this.timeOfLastScale = 0;
this.scaleFactor = scaleFactor;
this.minTimeElapse = minTimeElapse;
}
WheelZoomTool.prototype.onSurfaceEvent = function (event) {
var surface = event.target;
var currentTime = Date.now();
var timeEllapsed = currentTime - this.timeOfLastScale;
if (timeEllapsed > this.minTimeElapse) {
var scaleFactor = event.isUpward ? this.scaleFactor : 1 / this.scaleFactor;
surface.zoomToPoint(scaleFactor, event.cursor);
this.timeOfLastScale = currentTime;
}
};
return WheelZoomTool;
}());
exports.WheelZoomTool = WheelZoomTool;
//# sourceMappingURL=wheelZoom.js.map