Files
image-editor/src/GoreHandler.js
T

71 lines
1.5 KiB
JavaScript

'use strict';
function GoreHandler(viewport) {
var _enabled = false;
var _lines = [];
/**
* @return {fabric.Line}
*/
function getLine(left) {
return new fabric.Line([0, 0, 0, viewport.getData().height], {
evented: false,
strokeDashArray: [5, 5],
stroke: '#F31FB3',
strokeWidth: 1,
left: left,
top: viewport.getBounds().top
});
}
/**
* @return {GoreHandler}
*/
this.clear = function () {
_lines.forEach(function (line) {
viewport.canvas.remove(line);
});
_lines = [];
return this;
};
/**
* @param {Boolean} enabled
* @return {GoreHandler}
*/
this.enable = function (enabled) {
_enabled = enabled;
this.clear();
if (!_enabled) {
viewport.canvas.renderAll();
return;
}
var bounds = viewport.getBounds();
var step = viewport.getData().ppmm * 450;
var count = Math.ceil(bounds.width / step);
for (var i = 1; i < count; i++) {
_lines.push(getLine(bounds.left + step * i));
}
_lines.forEach(function (o) {
viewport.canvas.add(o);
});
viewport.canvas.renderAll();
return this;
};
/**
* @return {GoreHandler}
*/
this.reset = function () {
return this.enable(_enabled);
};
}
module.exports = GoreHandler;