|
1069 | 1069 | function _startStroke(coords, identifier) { |
1070 | 1070 | this._doPreview = false; |
1071 | 1071 | this._plot(coords[0], coords[1], this.brushSize, this.brushColor); |
1072 | | - this._lastCoords.set(identifier, coords); |
1073 | 1072 | } |
1074 | 1073 | exports._startStroke = _startStroke; |
1075 | 1074 | function _endStroke(endCoords, identifier) { |
1076 | 1075 | this._plot(endCoords[0], endCoords[1], this.brushSize, this.brushColor); |
1077 | | - this._lastCoords.delete(identifier); |
1078 | 1076 | this._doPreview = true; |
1079 | 1077 | } |
1080 | 1078 | exports._endStroke = _endStroke; |
1081 | 1079 | function _doStroke(coords, identifier) { |
1082 | 1080 | this._plot(coords[0], coords[1], this.brushSize, this.brushColor); |
1083 | 1081 | this._stroke(coords[0], coords[1], this.brushSize, this.brushColor, identifier); |
1084 | | - this._lastCoords.set(identifier, coords); |
1085 | 1082 | } |
1086 | 1083 | exports._doStroke = _doStroke; |
1087 | 1084 | function _toolPreview(coords, identifier) { |
|
1097 | 1094 | function _startStroke(coords, identifier) { |
1098 | 1095 | this._doPreview = false; |
1099 | 1096 | this._plot(coords[0], coords[1], this.eraserSize, this.bgColor); |
1100 | | - this._lastCoords.set(identifier, coords); |
1101 | 1097 | } |
1102 | 1098 | exports._startStroke = _startStroke; |
1103 | 1099 | function _endStroke(endCoords, identifier) { |
1104 | 1100 | this._doPreview = true; |
1105 | 1101 | this._plot(endCoords[0], endCoords[1], this.eraserSize, this.bgColor); |
1106 | | - this._lastCoords.delete(identifier); |
1107 | 1102 | } |
1108 | 1103 | exports._endStroke = _endStroke; |
1109 | 1104 | function _doStroke(coords, identifier) { |
1110 | 1105 | this._plot(coords[0], coords[1], this.eraserSize, this.bgColor); |
1111 | 1106 | this._stroke(coords[0], coords[1], this.eraserSize, this.bgColor, identifier); |
1112 | | - this._lastCoords.set(identifier, coords); |
1113 | 1107 | } |
1114 | 1108 | exports._doStroke = _doStroke; |
1115 | 1109 | function _toolPreview(coords, identifier) { |
|
1128 | 1122 | var _startCoords = new Map(); /* key -> identifier, value -> coordinate*/ |
1129 | 1123 | function _startStroke(coords, identifier) { |
1130 | 1124 | this._plot(coords[0], coords[1], this.brushSize, this.brushColor); |
1131 | | - this._lastCoords.set(identifier, coords); |
1132 | 1125 | _startCoords.set(identifier, coords); |
1133 | 1126 | } |
1134 | 1127 | exports._startStroke = _startStroke; |
1135 | 1128 | function _endStroke(endCoords, identifier) { |
1136 | 1129 | this.graphPixels = this._strokeKernel(this._cloneTexture(this.graphPixels), _startCoords.get(identifier), endCoords, this.brushSize, this.brushColor); |
1137 | 1130 | this._plot(endCoords[0], endCoords[1], this.brushSize, this.brushColor); |
1138 | | - this._lastCoords.delete(identifier); |
1139 | 1131 | _startCoords.delete(identifier); |
1140 | 1132 | } |
1141 | 1133 | exports._endStroke = _endStroke; |
1142 | 1134 | function _doStroke(coords, identifier) { |
1143 | | - this._lastCoords.set(identifier, coords); |
1144 | 1135 | } |
1145 | 1136 | exports._doStroke = _doStroke; |
1146 | 1137 | function _toolPreview(coords, identifier) { |
|
1332 | 1323 | _super.call(this, options) || this; |
1333 | 1324 | _this.tool = RealDrawBoardDefaults.RealDrawBoardDefaults.tool; |
1334 | 1325 | _this._isDrawing = false; |
1335 | | - _this._ = false; // If a tool is drawing a strwoke |
1336 | 1326 | _this._snapshots = []; // Undo snapshots |
1337 | 1327 | _this._currentSnapshotIndex = 0; // Current snapshot |
1338 | 1328 | /** key -> identifier, value -> coordinate |
|
1366 | 1356 | _this.canvas.addEventListener('mousemove', _this._mouseMoveEventListener); |
1367 | 1357 | if (_this._currentSnapshotIndex < _this._snapshots.length - 1 && _this._maxSnapshots > 0) |
1368 | 1358 | _this._snapshots.splice(_this._currentSnapshotIndex + 1); // Delete all redo snapshots |
1369 | | - _this._startStroke(_this._getMouseCoords(e), 'mouse'); |
| 1359 | + var coords = _this._getMouseCoords(e); |
| 1360 | + _this._startStroke(coords, 'mouse'); |
| 1361 | + _this._lastCoords.set('mouse', coords); |
1370 | 1362 | } |
1371 | 1363 | }; |
1372 | 1364 | _this._mouseUpEventListener = function (e) { |
1373 | 1365 | if (e.button === 0 /* Left Click */) { |
1374 | 1366 | var endCoords = _this._getMouseCoords(e); |
1375 | 1367 | _this.canvas.removeEventListener('mousemove', _this._mouseMoveEventListener); |
1376 | 1368 | _this._removeDOMEvents(); |
1377 | | - if (_this._lastCoords.has('mouse')) |
| 1369 | + if (_this._lastCoords.has('mouse')) { |
1378 | 1370 | _this._endStroke(endCoords, 'mouse'); |
| 1371 | + _this._lastCoords.delete('mouse'); |
| 1372 | + } |
1379 | 1373 | _this._display(_this.graphPixels); |
1380 | 1374 | setTimeout(function () { |
1381 | 1375 | if (_this._maxSnapshots > 0) |
|
1393 | 1387 | if (_this._lastCoords.has('mouse')) { |
1394 | 1388 | _this._removeDOMEvents(); |
1395 | 1389 | _this._endStroke(_this._getMouseCoords(e), 'mouse'); |
| 1390 | + _this._lastCoords.delete('mouse'); |
1396 | 1391 | _this._display(_this.graphPixels); |
1397 | 1392 | setTimeout(function () { |
1398 | 1393 | if (_this._maxSnapshots > 0) |
|
1408 | 1403 | _this._mouseMoveEventListener = function (e) { |
1409 | 1404 | var coords = _this._getMouseCoords(e); |
1410 | 1405 | _this._doStroke(coords, 'mouse'); |
| 1406 | + _this._lastCoords.set('mouse', coords); |
1411 | 1407 | }; |
1412 | 1408 | _this._previewMouseMoveEventListener = function (e) { |
1413 | 1409 | var coords = _this._getMouseCoords(e); |
|
1424 | 1420 | for (var i = 0; i < e.touches.length; i++) { |
1425 | 1421 | if (_this._currentSnapshotIndex < _this._snapshots.length - 1 && _this._maxSnapshots > 0) |
1426 | 1422 | _this._snapshots.splice(_this._currentSnapshotIndex + 1); // Delete all redo snapshots |
1427 | | - _this._startStroke(_this._getTouchCoords(e.touches.item(i)), e.touches.item(i).identifier.toString()); |
| 1423 | + var coords = _this._getTouchCoords(e.touches.item(i)); |
| 1424 | + _this._startStroke(coords, e.touches.item(i).identifier.toString()); |
| 1425 | + _this._lastCoords.set(e.touches.item(i).identifier.toString(), coords); |
1428 | 1426 | } |
1429 | 1427 | }; |
1430 | 1428 | _this._touchEndEventListener = function (e) { |
1431 | 1429 | for (var i = 0; i < e.changedTouches.length; i++) { |
1432 | | - _this._endStroke(_this._getTouchCoords(e.changedTouches.item(i)), e.changedTouches.item(i).identifier.toString()); |
| 1430 | + var coords = _this._getTouchCoords(e.changedTouches.item(i)); |
| 1431 | + _this._endStroke(coords, e.changedTouches.item(i).identifier.toString()); |
| 1432 | + _this._lastCoords.delete(e.changedTouches.item(i).identifier.toString()); |
1433 | 1433 | } |
1434 | 1434 | setTimeout(function () { |
1435 | 1435 | if (_this._maxSnapshots > 0) |
|
1443 | 1443 | }; |
1444 | 1444 | _this._touchMoveEventListener = function (e) { |
1445 | 1445 | for (var i = 0; i < e.touches.length; i++) { |
1446 | | - _this._doStroke(_this._getTouchCoords(e.touches.item(i)), e.touches.item(i).identifier.toString()); |
| 1446 | + var coords = _this._getTouchCoords(e.touches.item(i)); |
| 1447 | + _this._doStroke(coords, e.touches.item(i).identifier.toString()); |
| 1448 | + _this._lastCoords.set(e.touches.item(i).identifier.toString(), coords); |
1447 | 1449 | } |
1448 | 1450 | }; |
1449 | 1451 | _this._previewTouchMoveEventListener = function (e) { |
|
0 commit comments