|
1086 | 1086 | } |
1087 | 1087 | exports.changeMode = changeMode; |
1088 | 1088 | function clear() { |
1089 | | - this._strokeHappening = false; |
1090 | 1089 | this._drawnPaths = []; |
1091 | 1090 | this._pathIndex = -1; |
1092 | 1091 | this._lastCoords.clear(); |
|
1104 | 1103 | this.eraserSize = this.options.eraserSize; |
1105 | 1104 | this.mode = this.options.mode; |
1106 | 1105 | this._isDrawing = false; |
1107 | | - this._strokeHappening = false; |
1108 | 1106 | this._drawnPaths = []; |
1109 | 1107 | this._pathIndex = -1; |
1110 | 1108 | this._lastCoords.clear(); |
|
1142 | 1140 | }; |
1143 | 1141 | Object.defineProperty(exports, "__esModule", { value: true }); |
1144 | 1142 | exports._doStroke = exports._endStroke = exports._startStroke = void 0; |
1145 | | - function _startStroke(coords) { |
1146 | | - this._strokeHappening = true; |
| 1143 | + function _startStroke(coords, identifier) { |
1147 | 1144 | this._drawnPaths[this._pathIndex + 1] = { |
1148 | 1145 | pathCoords: [], |
1149 | 1146 | color: this.brushColor.map(function (x) { return x; }), |
1150 | 1147 | mode: this.mode, |
1151 | 1148 | brushSize: this.brushSize, |
1152 | 1149 | eraserSize: this.eraserSize |
1153 | 1150 | }; |
1154 | | - this._lastCoords.set('mouse', coords); |
| 1151 | + this._lastCoords.set(identifier, coords); |
1155 | 1152 | } |
1156 | 1153 | exports._startStroke = _startStroke; |
1157 | | - function _endStroke(endCoords) { |
1158 | | - if (this._lastCoords.get('mouse')[0] === endCoords[0] && |
1159 | | - this._lastCoords.get('mouse')[1] === endCoords[1]) { |
| 1154 | + function _endStroke(endCoords, identifier) { |
| 1155 | + if (this._lastCoords.get(identifier)[0] === endCoords[0] && |
| 1156 | + this._lastCoords.get(identifier)[1] === endCoords[1]) { |
1160 | 1157 | this._plot.apply(this, endCoords); |
1161 | 1158 | this._drawnPaths[this._pathIndex + 1].pathCoords.push(__spreadArrays(endCoords, [true])); |
1162 | 1159 | } |
1163 | | - if (this._strokeHappening) { |
1164 | | - this._lastCoords.delete('mouse'); |
1165 | | - if (this._drawnPaths[this._pathIndex + 1].pathCoords.length === 0) |
1166 | | - this._drawnPaths.splice(-1, 1); |
1167 | | - else { |
1168 | | - this._drawnPaths = this._drawnPaths.slice(0, this._pathIndex + 2); // Overwrite further paths to prevent wrong redos |
1169 | | - this._pathIndex++; |
1170 | | - } |
1171 | | - this._strokeHappening = false; |
| 1160 | + this._lastCoords.delete(identifier); |
| 1161 | + if (this._drawnPaths[this._pathIndex + 1].pathCoords.length === 0) |
| 1162 | + this._drawnPaths.splice(-1, 1); |
| 1163 | + else { |
| 1164 | + this._drawnPaths = this._drawnPaths.slice(0, this._pathIndex + 2); // Overwrite further paths to prevent wrong redos |
| 1165 | + this._pathIndex++; |
1172 | 1166 | } |
1173 | 1167 | } |
1174 | 1168 | exports._endStroke = _endStroke; |
1175 | | - function _doStroke(coords) { |
1176 | | - this._strokeHappening = true; |
| 1169 | + function _doStroke(coords, identifier) { |
1177 | 1170 | this._drawnPaths[this._pathIndex + 1].pathCoords.push(__spreadArrays(coords, [false])); |
1178 | 1171 | this._stroke.apply(this, coords); |
1179 | | - this._lastCoords.set('mouse', coords); |
| 1172 | + this._lastCoords.set(identifier, coords); |
1180 | 1173 | } |
1181 | 1174 | exports._doStroke = _doStroke; |
1182 | 1175 | }); |
|
1263 | 1256 | // *****DEFAULTS***** |
1264 | 1257 | _super.call(this, options) || this; |
1265 | 1258 | _this._isDrawing = false; |
1266 | | - _this._strokeHappening = false; |
1267 | 1259 | _this._drawnPaths = []; |
1268 | 1260 | _this._pathIndex = -1; // Index of path in _drawnPaths |
1269 | 1261 | /** key -> identifier, value -> coordinate |
|
1293 | 1285 | _this._mouseDownEventListener = function (e) { |
1294 | 1286 | if (e.button === 0 /* Left Click */) { |
1295 | 1287 | _this.canvas.addEventListener('mousemove', _this._mouseMoveEventListener); |
1296 | | - _this._startStroke(_this._getMouseCoords(e)); |
| 1288 | + _this._startStroke(_this._getMouseCoords(e), 'mouse'); |
1297 | 1289 | } |
1298 | 1290 | }; |
1299 | 1291 | _this._mouseUpEventListener = function (e) { |
1300 | 1292 | if (e.button === 0 /* Left Click */) { |
1301 | 1293 | var endCoords = _this._getMouseCoords(e); |
1302 | | - _this._endStroke(endCoords); |
1303 | | - if (!_this._strokeHappening) |
1304 | | - _this.canvas.removeEventListener('mousemove', _this._mouseMoveEventListener); |
| 1294 | + _this._endStroke(endCoords, 'mouse'); |
| 1295 | + _this.canvas.removeEventListener('mousemove', _this._mouseMoveEventListener); |
1305 | 1296 | } |
1306 | 1297 | }; |
1307 | 1298 | _this._mouseEnterEventListener = function (e) { |
1308 | 1299 | _this._lastCoords.set('mouse', _this._getMouseCoords(e)); |
1309 | 1300 | }; |
1310 | 1301 | _this._mouseLeaveEventListener = function (e) { |
1311 | | - _this._endStroke(_this._getMouseCoords(e)); |
| 1302 | + _this._endStroke(_this._getMouseCoords(e), 'mouse'); |
1312 | 1303 | }; |
1313 | 1304 | _this._mouseMoveEventListener = function (e) { |
1314 | 1305 | var coords = _this._getMouseCoords(e); |
1315 | | - _this._doStroke(coords); |
| 1306 | + _this._doStroke(coords, 'mouse'); |
1316 | 1307 | }; |
1317 | 1308 | // --- Mouse Events --- |
1318 | 1309 | // --- Touch Events --- |
|
1321 | 1312 | }; |
1322 | 1313 | _this._touchEndEventListener = function (e) { |
1323 | 1314 | var endCoords = _this._getTouchCoords(e)[0]; |
1324 | | - _this._endStroke(endCoords); |
| 1315 | + _this._endStroke(endCoords, 'mouse'); |
1325 | 1316 | }; |
1326 | 1317 | _this._touchMoveEventListener = function (e) { |
1327 | 1318 | }; |
|
0 commit comments