|
1079 | 1079 | exports._toolPreview = exports._doStroke = exports._endStroke = exports._startStroke = exports.name = void 0; |
1080 | 1080 | exports.name = 'brush'; |
1081 | 1081 | function _startStroke(coords, identifier) { |
| 1082 | + this._doPreview = false; |
1082 | 1083 | if (this._currentSnapshotIndex < this._snapshots.length - 1 && this._maxSnapshots > 0) |
1083 | 1084 | this._snapshots.splice(this._currentSnapshotIndex + 1); // Delete all redo snapshots |
1084 | 1085 | this._plot(coords[0], coords[1], this.brushSize, this.brushColor); |
|
1094 | 1095 | this._snapshots.shift(); |
1095 | 1096 | this._currentSnapshotIndex--; |
1096 | 1097 | } |
| 1098 | + this._doPreview = true; |
1097 | 1099 | } |
1098 | 1100 | exports._endStroke = _endStroke; |
1099 | 1101 | function _doStroke(coords, identifier) { |
|
1113 | 1115 | exports._toolPreview = exports._doStroke = exports._endStroke = exports._startStroke = exports.name = void 0; |
1114 | 1116 | exports.name = 'eraser'; |
1115 | 1117 | function _startStroke(coords, identifier) { |
| 1118 | + this._doPreview = false; |
1116 | 1119 | if (this._currentSnapshotIndex < this._snapshots.length - 1 && this._maxSnapshots > 0) |
1117 | 1120 | this._snapshots.splice(this._currentSnapshotIndex + 1); // Delete all redo snapshots |
1118 | 1121 | this._plot(coords[0], coords[1], this.eraserSize, this.bgColor); |
1119 | 1122 | this._lastCoords.set(identifier, coords); |
1120 | 1123 | } |
1121 | 1124 | exports._startStroke = _startStroke; |
1122 | 1125 | function _endStroke(endCoords, identifier) { |
| 1126 | + this._doPreview = true; |
1123 | 1127 | this._plot(endCoords[0], endCoords[1], this.eraserSize, this.bgColor); |
1124 | 1128 | this._lastCoords.delete(identifier); |
1125 | 1129 | if (this._maxSnapshots > 0) |
|
1365 | 1369 | * For mouse, the key is 'mouse', for touches, stringified identifier -> https://developer.mozilla.org/en-US/docs/Web/API/Touch/identifier |
1366 | 1370 | */ |
1367 | 1371 | _this._lastCoords = new Map(); /* key -> identifier, value -> coordinate*/ |
| 1372 | + _this._doPreview = true; // If a preview should be drawn |
1368 | 1373 | _this._initializeKernels = _initializeKernels_1._initializeKernels; |
1369 | 1374 | _this._stroke = _draw._stroke; |
1370 | 1375 | _this._plot = _draw._plot; |
|
1399 | 1404 | if (_this._lastCoords.has('mouse')) |
1400 | 1405 | _this._endStroke(endCoords, 'mouse'); |
1401 | 1406 | _this._isStroking = false; |
| 1407 | + _this._display(_this.graphPixels); |
1402 | 1408 | _this.canvas.removeEventListener('mousemove', _this._mouseMoveEventListener); |
1403 | 1409 | } |
1404 | 1410 | }; |
1405 | 1411 | _this._mouseLeaveEventListener = function (e) { |
1406 | 1412 | _this.canvas.removeEventListener('mousemove', _this._mouseMoveEventListener); |
1407 | 1413 | _this._isStroking = false; |
| 1414 | + _this._display(_this.graphPixels); |
1408 | 1415 | if (_this._lastCoords.has('mouse')) |
1409 | 1416 | _this._endStroke(_this._getMouseCoords(e), 'mouse'); |
1410 | 1417 | }; |
|
1414 | 1421 | }; |
1415 | 1422 | _this._previewMouseMoveEventListener = function (e) { |
1416 | 1423 | var coords = _this._getMouseCoords(e); |
1417 | | - // if (!this._isStroking) { |
1418 | | - // this._display( |
1419 | | - // this._toolPreview(coords, 'mouse') |
1420 | | - // ) |
1421 | | - // } |
1422 | | - // else { |
1423 | | - // this._display(this.graphPixels); |
1424 | | - // console.log('not previewing') |
1425 | | - // } |
| 1424 | + if (_this._doPreview) { |
| 1425 | + _this._display(_this._toolPreview(coords, 'mouse')); |
| 1426 | + } |
| 1427 | + else |
| 1428 | + _this._display(_this.graphPixels); |
1426 | 1429 | }; |
1427 | 1430 | // --- Mouse Events --- |
1428 | 1431 | // --- Touch Events --- |
|
1434 | 1437 | } |
1435 | 1438 | }; |
1436 | 1439 | _this._touchEndEventListener = function (e) { |
1437 | | - e.preventDefault(); |
1438 | 1440 | for (var i = 0; i < e.changedTouches.length; i++) { |
1439 | 1441 | _this._endStroke(_this._getTouchCoords(e.changedTouches.item(i)), e.changedTouches.item(i).identifier.toString()); |
1440 | 1442 | _this._isStroking = false; |
1441 | 1443 | } |
1442 | 1444 | }; |
1443 | 1445 | _this._touchMoveEventListener = function (e) { |
1444 | | - e.preventDefault(); |
1445 | 1446 | for (var i = 0; i < e.touches.length; i++) { |
1446 | 1447 | _this._doStroke(_this._getTouchCoords(e.touches.item(i)), e.touches.item(i).identifier.toString()); |
1447 | 1448 | } |
1448 | 1449 | }; |
1449 | 1450 | _this._previewTouchMoveEventListener = function (e) { |
1450 | | - e.preventDefault(); |
1451 | 1451 | for (var i = 0; i < e.touches.length; i++) { |
1452 | | - // if (!this._isStroking) { |
1453 | | - // this._display( |
1454 | | - // this._toolPreview(this._getTouchCoords(e.touches.item(i)), e.touches.item(i).identifier.toString()) |
1455 | | - // ) |
1456 | | - // } |
1457 | | - // else this._display(this.graphPixels); |
| 1452 | + if (!_this._doPreview) { |
| 1453 | + _this._display(_this._toolPreview(_this._getTouchCoords(e.touches.item(i)), e.touches.item(i).identifier.toString())); |
| 1454 | + } |
| 1455 | + else |
| 1456 | + _this._display(_this.graphPixels); |
1458 | 1457 | } |
1459 | 1458 | }; |
1460 | 1459 | options = __assign(__assign({}, RealDrawBoardDefaults.RealDrawBoardDefaults), options); |
|
1468 | 1467 | _this._initializeKernels(); |
1469 | 1468 | if (_this._maxSnapshots > 0) |
1470 | 1469 | _this._snapshots[0] = _this.getData(); |
1471 | | - var frameHandler = function () { |
1472 | | - if (_this._isStroking) |
1473 | | - _this._display(_this.graphPixels); |
1474 | | - window.requestAnimationFrame(frameHandler); |
1475 | | - }; |
1476 | | - window.requestAnimationFrame(frameHandler); |
1477 | 1470 | return _this; |
1478 | 1471 | } |
1479 | 1472 | // --- Touch Events --- |
|
0 commit comments