Added literallycanvas and react libraries.
[openemr.git] / library / js / literallycanvas / js / tools / Pencil.js
blob1003128e7e76c9773bec801d436df1cfaf12dd11
1 var Pencil, ToolWithStroke, createShape,
2   extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
3   hasProp = {}.hasOwnProperty;
5 ToolWithStroke = require('./base').ToolWithStroke;
7 createShape = require('../core/shapes').createShape;
9 module.exports = Pencil = (function(superClass) {
10   extend(Pencil, superClass);
12   function Pencil() {
13     return Pencil.__super__.constructor.apply(this, arguments);
14   }
16   Pencil.prototype.name = 'Pencil';
18   Pencil.prototype.iconName = 'pencil';
20   Pencil.prototype.eventTimeThreshold = 10;
22   Pencil.prototype.begin = function(x, y, lc) {
23     this.color = lc.getColor('primary');
24     this.currentShape = this.makeShape();
25     this.currentShape.addPoint(this.makePoint(x, y, lc));
26     return this.lastEventTime = Date.now();
27   };
29   Pencil.prototype["continue"] = function(x, y, lc) {
30     var timeDiff;
31     timeDiff = Date.now() - this.lastEventTime;
32     if (timeDiff > this.eventTimeThreshold) {
33       this.lastEventTime += timeDiff;
34       this.currentShape.addPoint(this.makePoint(x, y, lc));
35       return lc.drawShapeInProgress(this.currentShape);
36     }
37   };
39   Pencil.prototype.end = function(x, y, lc) {
40     lc.saveShape(this.currentShape);
41     return this.currentShape = void 0;
42   };
44   Pencil.prototype.makePoint = function(x, y, lc) {
45     return createShape('Point', {
46       x: x,
47       y: y,
48       size: this.strokeWidth,
49       color: this.color
50     });
51   };
53   Pencil.prototype.makeShape = function() {
54     return createShape('LinePath');
55   };
57   return Pencil;
59 })(ToolWithStroke);