|
1013 | 1013 | brushColor: [1, 1, 1], |
1014 | 1014 | allowUndo: false, |
1015 | 1015 | maxUndos: 10, |
1016 | | - mode: 'paint' |
| 1016 | + tool: 'brush' |
1017 | 1017 | }; |
1018 | 1018 | }); |
1019 | 1019 |
|
|
1037 | 1037 | var _draw = createCommonjsModule(function (module, exports) { |
1038 | 1038 | Object.defineProperty(exports, "__esModule", { value: true }); |
1039 | 1039 | exports._stroke = exports._plot = void 0; |
1040 | | - function _plot(x, y) { |
1041 | | - this.graphPixels = this._plotKernel(this._cloneTexture(this.graphPixels), x, y, this.mode === 'paint' ? this.brushSize : this.eraserSize, this.mode === 'paint' ? this.brushColor : this.bgColor); |
| 1040 | + function _plot(x, y, size, color) { |
| 1041 | + this.graphPixels = this._plotKernel(this._cloneTexture(this.graphPixels), x, y, size, color); |
1042 | 1042 | return this; |
1043 | 1043 | } |
1044 | 1044 | exports._plot = _plot; |
1045 | | - function _stroke(x, y, identifier) { |
| 1045 | + function _stroke(x, y, size, color, identifier) { |
1046 | 1046 | if (!this._lastCoords.has(identifier)) |
1047 | 1047 | this._lastCoords.set(identifier, [x, y]); |
1048 | | - 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); |
| 1048 | + this.graphPixels = this._strokeKernel(this._cloneTexture(this.graphPixels), this._lastCoords.get(identifier), [x, y], size, color); |
1049 | 1049 | } |
1050 | 1050 | exports._stroke = _stroke; |
1051 | 1051 | }); |
|
1076 | 1076 | exports.redo = redo; |
1077 | 1077 | }); |
1078 | 1078 |
|
| 1079 | + var brush = createCommonjsModule(function (module, exports) { |
| 1080 | + Object.defineProperty(exports, "__esModule", { value: true }); |
| 1081 | + exports._toolPreview = exports._doStroke = exports._endStroke = exports._startStroke = exports.name = void 0; |
| 1082 | + exports.name = 'brush'; |
| 1083 | + function _startStroke(coords, identifier) { |
| 1084 | + if (this._currentSnapshotIndex < this._snapshots.length - 1 && this._maxSnapshots > 0) |
| 1085 | + this._snapshots.splice(this._currentSnapshotIndex + 1); // Delete all redo snapshots |
| 1086 | + this._plot(coords[0], coords[1], this.brushSize, this.brushColor); |
| 1087 | + this._lastCoords.set(identifier, coords); |
| 1088 | + } |
| 1089 | + exports._startStroke = _startStroke; |
| 1090 | + function _endStroke(endCoords, identifier) { |
| 1091 | + this._plot(endCoords[0], endCoords[1], this.brushSize, this.brushColor); |
| 1092 | + this._lastCoords.delete(identifier); |
| 1093 | + if (this._maxSnapshots > 0) |
| 1094 | + this._snapshots[++this._currentSnapshotIndex] = this.getData(); |
| 1095 | + if (this._snapshots.length > this._maxSnapshots) { |
| 1096 | + this._snapshots.shift(); |
| 1097 | + this._currentSnapshotIndex--; |
| 1098 | + } |
| 1099 | + } |
| 1100 | + exports._endStroke = _endStroke; |
| 1101 | + function _doStroke(coords, identifier) { |
| 1102 | + this._plot(coords[0], coords[1], this.brushSize, this.brushColor); |
| 1103 | + this._stroke(coords[0], coords[1], this.brushSize, this.brushColor, identifier); |
| 1104 | + this._lastCoords.set(identifier, coords); |
| 1105 | + } |
| 1106 | + exports._doStroke = _doStroke; |
| 1107 | + function _toolPreview(coords) { |
| 1108 | + return this._previewPlot(this.graphPixels, coords[0], coords[1], this.brushSize, this.brushColor); |
| 1109 | + } |
| 1110 | + exports._toolPreview = _toolPreview; |
| 1111 | + }); |
| 1112 | + |
| 1113 | + var eraser = createCommonjsModule(function (module, exports) { |
| 1114 | + Object.defineProperty(exports, "__esModule", { value: true }); |
| 1115 | + exports._toolPreview = exports._doStroke = exports._endStroke = exports._startStroke = exports.name = void 0; |
| 1116 | + exports.name = 'eraser'; |
| 1117 | + function _startStroke(coords, identifier) { |
| 1118 | + if (this._currentSnapshotIndex < this._snapshots.length - 1 && this._maxSnapshots > 0) |
| 1119 | + this._snapshots.splice(this._currentSnapshotIndex + 1); // Delete all redo snapshots |
| 1120 | + this._plot(coords[0], coords[1], this.eraserSize, this.bgColor); |
| 1121 | + this._lastCoords.set(identifier, coords); |
| 1122 | + } |
| 1123 | + exports._startStroke = _startStroke; |
| 1124 | + function _endStroke(endCoords, identifier) { |
| 1125 | + this._plot(endCoords[0], endCoords[1], this.eraserSize, this.bgColor); |
| 1126 | + this._lastCoords.delete(identifier); |
| 1127 | + if (this._maxSnapshots > 0) |
| 1128 | + this._snapshots[++this._currentSnapshotIndex] = this.getData(); |
| 1129 | + if (this._snapshots.length > this._maxSnapshots) { |
| 1130 | + this._snapshots.shift(); |
| 1131 | + this._currentSnapshotIndex--; |
| 1132 | + } |
| 1133 | + } |
| 1134 | + exports._endStroke = _endStroke; |
| 1135 | + function _doStroke(coords, identifier) { |
| 1136 | + this._plot(coords[0], coords[1], this.eraserSize, this.bgColor); |
| 1137 | + this._stroke(coords[0], coords[1], this.eraserSize, this.bgColor, identifier); |
| 1138 | + this._lastCoords.set(identifier, coords); |
| 1139 | + } |
| 1140 | + exports._doStroke = _doStroke; |
| 1141 | + function _toolPreview(coords) { |
| 1142 | + return this._previewPlot(this.graphPixels, coords[0], coords[1], this.eraserSize, this.bgColor); |
| 1143 | + } |
| 1144 | + exports._toolPreview = _toolPreview; |
| 1145 | + }); |
| 1146 | + |
| 1147 | + var tools = createCommonjsModule(function (module, exports) { |
| 1148 | + Object.defineProperty(exports, "__esModule", { value: true }); |
| 1149 | + exports.tools = void 0; |
| 1150 | + |
| 1151 | + |
| 1152 | + exports.tools = { |
| 1153 | + brush: brush, |
| 1154 | + eraser: eraser |
| 1155 | + }; |
| 1156 | + }); |
| 1157 | + |
1079 | 1158 | var boardManip = createCommonjsModule(function (module, exports) { |
1080 | 1159 | Object.defineProperty(exports, "__esModule", { value: true }); |
1081 | | - exports._resetBoard = exports.clear = exports.changeMode = exports.changeEraserSize = exports.changeBrushSize = exports.changeBrushColor = void 0; |
| 1160 | + exports._resetBoard = exports.clear = exports.changeTool = exports.changeEraserSize = exports.changeBrushSize = exports.changeBrushColor = void 0; |
| 1161 | + |
1082 | 1162 | function changeBrushColor(color) { |
1083 | 1163 | this.brushColor = color; |
1084 | 1164 | return this; |
|
1094 | 1174 | return this; |
1095 | 1175 | } |
1096 | 1176 | exports.changeEraserSize = changeEraserSize; |
1097 | | - function changeMode(newMode) { |
1098 | | - this.mode = newMode; |
| 1177 | + function changeTool(newTool) { |
| 1178 | + this.tool = newTool; |
| 1179 | + this._startStroke = tools.tools[this.tool]._startStroke; |
| 1180 | + this._doStroke = tools.tools[this.tool]._doStroke; |
| 1181 | + this._endStroke = tools.tools[this.tool]._endStroke; |
| 1182 | + this._toolPreview = tools.tools[this.tool]._toolPreview; |
1099 | 1183 | return this; |
1100 | 1184 | } |
1101 | | - exports.changeMode = changeMode; |
| 1185 | + exports.changeTool = changeTool; |
1102 | 1186 | function clear() { |
1103 | 1187 | this._snapshots = []; |
1104 | 1188 | this._currentSnapshotIndex = 0; |
|
1116 | 1200 | this.brushSize = this.options.brushSize; |
1117 | 1201 | this.bgColor = this.options.bgColor; |
1118 | 1202 | this.eraserSize = this.options.eraserSize; |
1119 | | - this.mode = this.options.mode; |
| 1203 | + this.tool = this.options.tool; |
1120 | 1204 | this._isDrawing = false; |
1121 | 1205 | this._currentSnapshotIndex = 0; |
1122 | 1206 | this._snapshots = [this.getData()]; |
|
1151 | 1235 | exports._removeDOMEvents = _removeDOMEvents; |
1152 | 1236 | }); |
1153 | 1237 |
|
1154 | | - var stroke = createCommonjsModule(function (module, exports) { |
1155 | | - Object.defineProperty(exports, "__esModule", { value: true }); |
1156 | | - exports._doStroke = exports._endStroke = exports._startStroke = void 0; |
1157 | | - function _startStroke(coords, identifier) { |
1158 | | - if (this._currentSnapshotIndex < this._snapshots.length - 1 && this._maxSnapshots > 0) |
1159 | | - this._snapshots.splice(this._currentSnapshotIndex + 1); // Delete all redo snapshots |
1160 | | - this._plot.apply(// Delete all redo snapshots |
1161 | | - this, coords); |
1162 | | - this._lastCoords.set(identifier, coords); |
1163 | | - } |
1164 | | - exports._startStroke = _startStroke; |
1165 | | - function _endStroke(endCoords, identifier) { |
1166 | | - this._plot.apply(this, endCoords); |
1167 | | - this._lastCoords.delete(identifier); |
1168 | | - if (this._maxSnapshots > 0) |
1169 | | - this._snapshots[++this._currentSnapshotIndex] = this.getData(); |
1170 | | - if (this._snapshots.length > this._maxSnapshots) { |
1171 | | - this._snapshots.shift(); |
1172 | | - this._currentSnapshotIndex--; |
1173 | | - } |
1174 | | - } |
1175 | | - exports._endStroke = _endStroke; |
1176 | | - function _doStroke(coords, identifier) { |
1177 | | - this._plot.apply(this, coords); |
1178 | | - this._stroke(coords[0], coords[1], identifier); |
1179 | | - this._lastCoords.set(identifier, coords); |
1180 | | - } |
1181 | | - exports._doStroke = _doStroke; |
1182 | | - }); |
1183 | | - |
1184 | 1238 | var _coords = createCommonjsModule(function (module, exports) { |
1185 | 1239 | Object.defineProperty(exports, "__esModule", { value: true }); |
1186 | 1240 | exports._getTouchCoords = exports._getMouseCoords = void 0; |
|
1261 | 1315 | var _this = |
1262 | 1316 | // *****DEFAULTS***** |
1263 | 1317 | _super.call(this, options) || this; |
| 1318 | + _this.tool = RealDrawBoardDefaults.RealDrawBoardDefaults.tool; |
1264 | 1319 | _this._isDrawing = false; |
1265 | 1320 | _this._snapshots = []; // Undo snapshots |
1266 | 1321 | _this._currentSnapshotIndex = 0; // Current snapshot |
|
1274 | 1329 | _this._resetBoard = boardManip._resetBoard; |
1275 | 1330 | _this._addDOMEvents = _DOMEvents._addDOMEvents; |
1276 | 1331 | _this._removeDOMEvents = _DOMEvents._removeDOMEvents; |
1277 | | - _this._startStroke = stroke._startStroke; |
1278 | | - _this._endStroke = stroke._endStroke; |
1279 | | - _this._doStroke = stroke._doStroke; |
| 1332 | + _this._startStroke = tools.tools[RealDrawBoardDefaults.RealDrawBoardDefaults.tool]._startStroke; |
| 1333 | + _this._endStroke = tools.tools[RealDrawBoardDefaults.RealDrawBoardDefaults.tool]._endStroke; |
| 1334 | + _this._doStroke = tools.tools[RealDrawBoardDefaults.RealDrawBoardDefaults.tool]._doStroke; |
| 1335 | + _this._toolPreview = tools.tools[RealDrawBoardDefaults.RealDrawBoardDefaults.tool]._toolPreview; |
1280 | 1336 | _this._getMouseCoords = _coords._getMouseCoords; |
1281 | 1337 | _this._getTouchCoords = _coords._getTouchCoords; |
1282 | 1338 | _this.undo = undo_1.undo; |
1283 | 1339 | _this.redo = undo_1.redo; |
1284 | 1340 | _this.changeBrushColor = boardManip.changeBrushColor; |
1285 | 1341 | _this.changeBrushSize = boardManip.changeBrushSize; |
1286 | 1342 | _this.changeEraserSize = boardManip.changeEraserSize; |
1287 | | - _this.changeMode = boardManip.changeMode; |
| 1343 | + _this.changeTool = boardManip.changeTool; |
1288 | 1344 | _this.clear = boardManip.clear; |
1289 | 1345 | // --- DOM Event Listeners --- |
1290 | 1346 | // --- Mouse Events --- |
|
1313 | 1369 | }; |
1314 | 1370 | _this._previewMouseMoveEventListener = function (e) { |
1315 | 1371 | var coords = _this._getMouseCoords(e); |
1316 | | - _this._display(_this._previewPlot(_this.graphPixels, coords[0], coords[1], _this.mode === 'paint' ? _this.brushSize : _this.eraserSize, _this.mode === 'erase' ? _this.bgColor : _this.brushColor)); |
| 1372 | + _this._display(_this._toolPreview(coords)); |
1317 | 1373 | }; |
1318 | 1374 | // --- Mouse Events --- |
1319 | 1375 | // --- Touch Events --- |
|
1342 | 1398 | _this.brushColor = options.brushColor; |
1343 | 1399 | _this.eraserSize = options.eraserSize; |
1344 | 1400 | _this._maxSnapshots = options.allowUndo ? Math.max(options.maxUndos + 1, 0) : 0; |
1345 | | - _this.mode = options.mode; |
| 1401 | + _this.changeTool(options.tool); |
1346 | 1402 | // *****DEFAULTS***** |
1347 | 1403 | _this._initializeKernels(); |
1348 | 1404 | _this._snapshots[0] = _this.getData(); |
|
0 commit comments