MCPcopy Create free account
hub / github.com/devforth/painterro / drawBrushPath

Method drawBrushPath

js/primitive.js:75–121  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

73 }
74
75 drawBrushPath() {
76 const smPoints = this.points;
77 let lineFill;
78 const origComposition = this.ctx.globalCompositeOperation;
79 const isEraser = this.type === 'eraser';
80 lineFill = this.main.colorWidgetState.line.alphaColor;
81 const bgIsTransparent = this.main.currentBackgroundAlpha !== 1.0;
82 for (let i = 1; i <= (isEraser && bgIsTransparent ? 2 : 1); i += 1) {
83 if (isEraser) {
84 this.ctx.globalCompositeOperation = i === 1 && bgIsTransparent ? 'destination-out' : origComposition;
85 lineFill = i === 1 && bgIsTransparent ? 'rgba(0,0,0,1)' : this.main.currentBackground;
86 }
87 if (smPoints.length === 1) {
88 this.ctx.beginPath();
89 this.ctx.lineWidth = 0;
90 this.ctx.fillStyle = lineFill;
91 this.ctx.arc(
92 this.points[0].x, this.points[0].y,
93 this.lineWidth / 2, this.lineWidth / 2,
94 0, 2 * Math.PI);
95 this.ctx.fill();
96 this.ctx.closePath();
97 } else {
98 this.ctx.beginPath();
99 if (this.type === 'eraser') {
100 this.ctx.lineWidth = this.eraserWidth;
101 } else {
102 this.ctx.lineWidth = this.lineWidth;
103 }
104 this.ctx.strokeStyle = lineFill;
105 this.ctx.fillStyle = this.main.colorWidgetState.fill.alphaColor;
106
107 this.ctx.moveTo(this.points[0].x, this.points[0].y);
108 let last;
109 smPoints.slice(1).forEach((p) => {
110 this.ctx.lineTo(p.x, p.y);
111 last = p;
112 });
113 if (last) {
114 this.ctx.moveTo(last.x, last.y);
115 }
116 this.ctx.stroke();
117 this.ctx.closePath();
118 }
119 }
120 this.ctx.globalCompositeOperation = origComposition;
121 }
122
123 handleMouseMove(event) {
124 const ctx = this.ctx;

Callers 2

handleMouseDownMethod · 0.95
handleMouseMoveMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected