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

Method handleMouseMove

js/primitive.js:123–345  ·  view source on GitHub ↗
(event)

Source from the content-addressed store, hash-verified

121 }
122
123 handleMouseMove(event) {
124 const ctx = this.ctx;
125 if (this.state.cornerMarked) {
126 this.ctx.putImageData(this.tmpData, 0, 0);
127 this.curCord = [
128 (event.clientX - this.main.elLeft()) + this.main.scroller.scrollLeft,
129 (event.clientY - this.main.elTop()) + this.main.scroller.scrollTop,
130 ];
131 const scale = this.main.getScale();
132 this.curCord = [this.curCord[0] * scale, this.curCord[1] * scale];
133
134 if (this.type === 'brush' || this.type === 'eraser') {
135 // const prevLast = this.points.slice(-1)[0];
136 const cur = {
137 x: this.curCord[0],
138 y: this.curCord[1],
139 };
140 this.points.push(cur);
141 this.drawBrushPath();
142 } else if (this.type === 'line') {
143 if (event.ctrlKey || event.shiftKey) {
144 const deg = (Math.atan(
145 -(this.curCord[1] - this.centerCord[1]) / (this.curCord[0] - this.centerCord[0]),
146 ) * 180) / Math.PI;
147 if (Math.abs(deg) < 45.0 / 2) {
148 this.curCord[1] = this.centerCord[1];
149 } else if (Math.abs(deg) > 45.0 + (45.0 / 2)) {
150 this.curCord[0] = this.centerCord[0];
151 } else {
152 const base = (Math.abs(this.curCord[0] - this.centerCord[0])
153 - Math.abs(this.centerCord[1] - this.curCord[1])) / 2;
154
155 this.curCord[0] -= base * (this.centerCord[0] < this.curCord[0] ? 1 : -1);
156 this.curCord[1] -= base * (this.centerCord[1] > this.curCord[1] ? 1 : -1);
157 }
158 }
159 ctx.beginPath();
160 ctx.moveTo(this.centerCord[0], this.centerCord[1]);
161 ctx.lineTo(this.curCord[0], this.curCord[1]);
162 ctx.closePath();
163 const origShadowColor = ctx.shadowColor;
164 if (this.shadowOn) {
165 ctx.shadowColor = 'rgba(0,0,0,0.7)';
166 ctx.shadowBlur = this.lineWidth;
167 ctx.shadowOffsetX = this.lineWidth / 2.0;
168 ctx.shadowOffsetY = this.lineWidth / 2.0;
169 }
170 ctx.stroke();
171 ctx.shadowColor = origShadowColor;
172 } else if (this.type === 'arrow') {
173 let deg = (Math.atan(
174 -(this.curCord[1] - this.centerCord[1]) / (this.curCord[0] - this.centerCord[0]),
175 ) * 180) / Math.PI;
176 if (event.ctrlKey || event.shiftKey) {
177 if (Math.abs(deg) < 45.0 / 2) {
178 this.curCord[1] = this.centerCord[1];
179 } else if (Math.abs(deg) > 45.0 + (45.0 / 2)) {
180 this.curCord[0] = this.centerCord[0];

Callers

nothing calls this directly

Calls 5

drawBrushPathMethod · 0.95
elLeftMethod · 0.80
elTopMethod · 0.80
saveMethod · 0.80
getScaleMethod · 0.45

Tested by

no test coverage detected