|
1007 | 1007 | return this; |
1008 | 1008 | } |
1009 | 1009 | exports._plot = _plot; |
1010 | | - function _stroke(x, y) { |
1011 | | - if (!this._lastCoords.has('mouse')) |
1012 | | - this._lastCoords.set('mouse', [x, y]); |
1013 | | - this.graphPixels = this._strokeKernel(this._cloneTexture(this.graphPixels), this._lastCoords.get('mouse'), [x, y], this.mode === 'paint' ? this.brushSize : this.eraserSize, this.mode === 'paint' ? this.brushColor : this.bgColor); |
| 1010 | + function _stroke(x, y, identifier) { |
| 1011 | + if (!this._lastCoords.has(identifier)) |
| 1012 | + this._lastCoords.set(identifier, [x, y]); |
| 1013 | + this.graphPixels = this._strokeKernel(this._cloneTexture(this.graphPixels), this._lastCoords.get(identifier), [x, y], this.mode === 'paint' ? this.brushSize : this.eraserSize, this.mode === 'paint' ? this.brushColor : this.bgColor); |
1014 | 1014 | this._display(this.graphPixels); |
1015 | 1015 | } |
1016 | 1016 | exports._stroke = _stroke; |
|
1031 | 1031 | _this.brushColor = path.color; |
1032 | 1032 | _this.brushSize = path.brushSize; |
1033 | 1033 | _this.eraserSize = path.eraserSize; |
1034 | | - _this._lastCoords.delete('mouse'); |
| 1034 | + _this._lastCoords.delete('temp'); |
1035 | 1035 | path.pathCoords.forEach(function (coord) { |
1036 | 1036 | if (coord[2] === false) { |
1037 | | - _this._stroke(coord[0], coord[1]); // Replay all strokes |
1038 | | - _this._lastCoords.set('mouse', [coord[0], coord[1]]); |
| 1037 | + _this._stroke(coord[0], coord[1], 'temp'); // Replay all strokes |
| 1038 | + _this._lastCoords.set('temp', [coord[0], coord[1]]); |
1039 | 1039 | } |
1040 | 1040 | else |
1041 | 1041 | _this._plot(coord[0], coord[1]); |
|
1046 | 1046 | this.brushSize = originalBrushSize; |
1047 | 1047 | this.eraserSize = originalEraserSize; |
1048 | 1048 | this._pathIndex -= numUndo; |
1049 | | - this._lastCoords.delete('mouse'); |
| 1049 | + this._lastCoords.delete('temp'); |
1050 | 1050 | this._display(this.graphPixels); |
1051 | 1051 | if (this._isDrawing) |
1052 | 1052 | this.startRender(); |
|
1119 | 1119 | this.canvas.addEventListener('mouseup', this._mouseUpEventListener); |
1120 | 1120 | this.canvas.addEventListener('mouseenter', this._mouseEnterEventListener); |
1121 | 1121 | this.canvas.addEventListener('mouseleave', this._mouseLeaveEventListener); |
| 1122 | + this.canvas.addEventListener('touchstart', this._touchStartEventListener); |
| 1123 | + this.canvas.addEventListener('touchmove', this._touchMoveEventListener); |
| 1124 | + this.canvas.addEventListener('touchend', this._touchEndEventListener); |
1122 | 1125 | } |
1123 | 1126 | exports._addDOMEvents = _addDOMEvents; |
1124 | 1127 | function _removeDOMEvents() { |
1125 | 1128 | this.canvas.removeEventListener('mousedown', this._mouseDownEventListener); |
1126 | 1129 | this.canvas.removeEventListener('mouseup', this._mouseUpEventListener); |
1127 | 1130 | this.canvas.removeEventListener('mouseenter', this._mouseEnterEventListener); |
1128 | 1131 | this.canvas.removeEventListener('mouseexit', this._mouseLeaveEventListener); |
| 1132 | + this.canvas.removeEventListener('touchstart', this._touchStartEventListener); |
| 1133 | + this.canvas.removeEventListener('touchmove', this._touchMoveEventListener); |
| 1134 | + this.canvas.removeEventListener('touchend', this._touchEndEventListener); |
1129 | 1135 | } |
1130 | 1136 | exports._removeDOMEvents = _removeDOMEvents; |
1131 | 1137 | }); |
|
1168 | 1174 | exports._endStroke = _endStroke; |
1169 | 1175 | function _doStroke(coords, identifier) { |
1170 | 1176 | this._drawnPaths[this._pathIndex + 1].pathCoords.push(__spreadArrays(coords, [false])); |
1171 | | - this._stroke.apply(this, coords); |
| 1177 | + this._stroke(coords[0], coords[1], identifier); |
1172 | 1178 | this._lastCoords.set(identifier, coords); |
1173 | 1179 | } |
1174 | 1180 | exports._doStroke = _doStroke; |
|
1185 | 1191 | return [x, y]; // In graph coordinates |
1186 | 1192 | } |
1187 | 1193 | exports._getMouseCoords = _getMouseCoords; |
1188 | | - function _getTouchCoords(e) { |
1189 | | - var allCoords = []; |
1190 | | - for (var i = 0; i < e.touches.length; i++) { |
1191 | | - var touch = e.touches.item(i); |
1192 | | - var x = touch.clientX - this.canvas.getBoundingClientRect().left; |
1193 | | - var y = this.dimensions[1] - (touch.clientY - this.canvas.getBoundingClientRect().top); |
1194 | | - x = x / this.xScaleFactor - (this.dimensions[0] * (this.yOffset / 100)) / this.xScaleFactor; |
1195 | | - y = y / this.yScaleFactor - (this.dimensions[1] * (this.xOffset / 100)) / this.yScaleFactor; |
1196 | | - allCoords.push([x, y]); |
1197 | | - } |
1198 | | - return allCoords; |
| 1194 | + function _getTouchCoords(touch) { |
| 1195 | + var x = touch.clientX - this.canvas.getBoundingClientRect().left; |
| 1196 | + var y = this.dimensions[1] - (touch.clientY - this.canvas.getBoundingClientRect().top); |
| 1197 | + x = x / this.xScaleFactor - (this.dimensions[0] * (this.yOffset / 100)) / this.xScaleFactor; |
| 1198 | + y = y / this.yScaleFactor - (this.dimensions[1] * (this.xOffset / 100)) / this.yScaleFactor; |
| 1199 | + return [x, y]; |
1199 | 1200 | } |
1200 | 1201 | exports._getTouchCoords = _getTouchCoords; |
1201 | 1202 | }); |
|
1299 | 1300 | _this._lastCoords.set('mouse', _this._getMouseCoords(e)); |
1300 | 1301 | }; |
1301 | 1302 | _this._mouseLeaveEventListener = function (e) { |
| 1303 | + _this.canvas.removeEventListener('mousemove', _this._mouseMoveEventListener); |
1302 | 1304 | _this._endStroke(_this._getMouseCoords(e), 'mouse'); |
1303 | 1305 | }; |
1304 | 1306 | _this._mouseMoveEventListener = function (e) { |
|
1308 | 1310 | // --- Mouse Events --- |
1309 | 1311 | // --- Touch Events --- |
1310 | 1312 | _this._touchStartEventListener = function (e) { |
1311 | | - // this.canvas.addEventListener(); |
| 1313 | + e.preventDefault(); |
| 1314 | + for (var i = 0; i < e.touches.length; i++) { |
| 1315 | + _this._startStroke(_this._getTouchCoords(e.touches.item(i)), e.touches.item(i).identifier.toString()); |
| 1316 | + } |
1312 | 1317 | }; |
1313 | 1318 | _this._touchEndEventListener = function (e) { |
1314 | | - var endCoords = _this._getTouchCoords(e)[0]; |
1315 | | - _this._endStroke(endCoords, 'mouse'); |
| 1319 | + e.preventDefault(); |
| 1320 | + for (var i = 0; i < e.changedTouches.length; i++) { |
| 1321 | + _this._endStroke(_this._getTouchCoords(e.changedTouches.item(i)), e.changedTouches.item(i).identifier.toString()); |
| 1322 | + } |
1316 | 1323 | }; |
1317 | 1324 | _this._touchMoveEventListener = function (e) { |
| 1325 | + e.preventDefault(); |
| 1326 | + for (var i = 0; i < e.touches.length; i++) { |
| 1327 | + _this._doStroke(_this._getTouchCoords(e.touches.item(i)), e.touches.item(i).identifier.toString()); |
| 1328 | + } |
1318 | 1329 | }; |
1319 | 1330 | options = __assign(__assign({}, RealDrawBoardDefaults.RealDrawBoardDefaults), options); |
1320 | 1331 | _this.options = options; |
|
0 commit comments