|
1104 | 1104 | this._lastCoords.set(identifier, coords); |
1105 | 1105 | } |
1106 | 1106 | exports._doStroke = _doStroke; |
1107 | | - function _toolPreview(coords) { |
| 1107 | + function _toolPreview(coords, identifier) { |
1108 | 1108 | return this._previewPlot(this.graphPixels, coords[0], coords[1], this.brushSize, this.brushColor); |
1109 | 1109 | } |
1110 | 1110 | exports._toolPreview = _toolPreview; |
|
1138 | 1138 | this._lastCoords.set(identifier, coords); |
1139 | 1139 | } |
1140 | 1140 | exports._doStroke = _doStroke; |
1141 | | - function _toolPreview(coords) { |
| 1141 | + function _toolPreview(coords, identifier) { |
1142 | 1142 | return this._previewPlot(this.graphPixels, coords[0], coords[1], this.eraserSize, this.bgColor); |
1143 | 1143 | } |
1144 | 1144 | exports._toolPreview = _toolPreview; |
1145 | 1145 | }); |
1146 | 1146 |
|
| 1147 | + var line = createCommonjsModule(function (module, exports) { |
| 1148 | + Object.defineProperty(exports, "__esModule", { value: true }); |
| 1149 | + exports._toolPreview = exports._doStroke = exports._endStroke = exports._startStroke = exports.name = void 0; |
| 1150 | + exports.name = 'line'; |
| 1151 | + /** key -> identifier, value -> coordinate |
| 1152 | + * For mouse, the key is 'mouse', for touches, stringified identifier -> https://developer.mozilla.org/en-US/docs/Web/API/Touch/identifier |
| 1153 | + */ |
| 1154 | + var _startCoords = new Map(); /* key -> identifier, value -> coordinate*/ |
| 1155 | + function _startStroke(coords, identifier) { |
| 1156 | + if (this._currentSnapshotIndex < this._snapshots.length - 1 && this._maxSnapshots > 0) |
| 1157 | + this._snapshots.splice(this._currentSnapshotIndex + 1); // Delete all redo snapshots |
| 1158 | + this._plot(coords[0], coords[1], this.brushSize, this.brushColor); |
| 1159 | + this._lastCoords.set(identifier, coords); |
| 1160 | + _startCoords.set(identifier, coords); |
| 1161 | + } |
| 1162 | + exports._startStroke = _startStroke; |
| 1163 | + function _endStroke(endCoords, identifier) { |
| 1164 | + this.graphPixels = this._strokeKernel(this._cloneTexture(this.graphPixels), _startCoords.get(identifier), endCoords, this.brushSize, this.brushColor); |
| 1165 | + this._plot(endCoords[0], endCoords[1], this.brushSize, this.brushColor); |
| 1166 | + this._lastCoords.delete(identifier); |
| 1167 | + _startCoords.delete(identifier); |
| 1168 | + } |
| 1169 | + exports._endStroke = _endStroke; |
| 1170 | + function _doStroke(coords, identifier) { |
| 1171 | + this._lastCoords.set(identifier, coords); |
| 1172 | + } |
| 1173 | + exports._doStroke = _doStroke; |
| 1174 | + function _toolPreview(coords, identifier) { |
| 1175 | + if (_startCoords.has(identifier)) { |
| 1176 | + return this._strokeKernel(this._cloneTexture(this.graphPixels), _startCoords.get(identifier), coords, this.brushSize, this.brushColor); |
| 1177 | + } |
| 1178 | + else |
| 1179 | + return this.graphPixels; |
| 1180 | + } |
| 1181 | + exports._toolPreview = _toolPreview; |
| 1182 | + }); |
| 1183 | + |
1147 | 1184 | var tools = createCommonjsModule(function (module, exports) { |
1148 | 1185 | Object.defineProperty(exports, "__esModule", { value: true }); |
1149 | 1186 | exports.tools = void 0; |
1150 | 1187 |
|
1151 | 1188 |
|
| 1189 | + |
1152 | 1190 | exports.tools = { |
1153 | 1191 | brush: brush, |
1154 | | - eraser: eraser |
| 1192 | + eraser: eraser, |
| 1193 | + line: line |
1155 | 1194 | }; |
1156 | 1195 | }); |
1157 | 1196 |
|
|
1221 | 1260 | this.canvas.addEventListener('touchstart', this._touchStartEventListener); |
1222 | 1261 | this.canvas.addEventListener('touchmove', this._touchMoveEventListener); |
1223 | 1262 | this.canvas.addEventListener('touchend', this._touchEndEventListener); |
| 1263 | + this.canvas.addEventListener('touchmove', this._previewTouchMoveEventListener); |
1224 | 1264 | } |
1225 | 1265 | exports._addDOMEvents = _addDOMEvents; |
1226 | 1266 | function _removeDOMEvents() { |
|
1231 | 1271 | this.canvas.removeEventListener('touchstart', this._touchStartEventListener); |
1232 | 1272 | this.canvas.removeEventListener('touchmove', this._touchMoveEventListener); |
1233 | 1273 | this.canvas.removeEventListener('touchend', this._touchEndEventListener); |
| 1274 | + this.canvas.removeEventListener('touchmove', this._previewTouchMoveEventListener); |
1234 | 1275 | } |
1235 | 1276 | exports._removeDOMEvents = _removeDOMEvents; |
1236 | 1277 | }); |
|
1369 | 1410 | }; |
1370 | 1411 | _this._previewMouseMoveEventListener = function (e) { |
1371 | 1412 | var coords = _this._getMouseCoords(e); |
1372 | | - _this._display(_this._toolPreview(coords)); |
| 1413 | + _this._display(_this._toolPreview(coords, 'mouse')); |
1373 | 1414 | }; |
1374 | 1415 | // --- Mouse Events --- |
1375 | 1416 | // --- Touch Events --- |
|
1386 | 1427 | } |
1387 | 1428 | }; |
1388 | 1429 | _this._touchMoveEventListener = function (e) { |
| 1430 | + e.preventDefault(); |
| 1431 | + for (var i = 0; i < e.touches.length; i++) { |
| 1432 | + _this._display(_this._toolPreview(_this._getTouchCoords(e.touches.item(i)), e.touches.item(i).identifier.toString())); |
| 1433 | + } |
| 1434 | + _this._display(_this.graphPixels); |
| 1435 | + }; |
| 1436 | + _this._previewTouchMoveEventListener = function (e) { |
1389 | 1437 | e.preventDefault(); |
1390 | 1438 | for (var i = 0; i < e.touches.length; i++) { |
1391 | 1439 | _this._doStroke(_this._getTouchCoords(e.touches.item(i)), e.touches.item(i).identifier.toString()); |
|
0 commit comments