Skip to content

Commit b638a17

Browse files
author
HarshKhandeparkar
committed
refactor<RealDrawBoard>: split more methods
into separate files
1 parent 7e6175d commit b638a17

File tree

4 files changed

+134
-88
lines changed

4 files changed

+134
-88
lines changed

dist/gpujs-real-renderer-browser.js

Lines changed: 60 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,56 @@
11371137
exports._removeMouseEvents = _removeMouseEvents;
11381138
});
11391139

1140+
var stroke = createCommonjsModule(function (module, exports) {
1141+
var __spreadArrays = (commonjsGlobal && commonjsGlobal.__spreadArrays) || function () {
1142+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
1143+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
1144+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
1145+
r[k] = a[j];
1146+
return r;
1147+
};
1148+
Object.defineProperty(exports, "__esModule", { value: true });
1149+
exports._doStroke = exports._endStroke = exports._startStroke = void 0;
1150+
function _startStroke(coords) {
1151+
this._strokeHappening = true;
1152+
this._drawnPaths[this._pathIndex + 1] = {
1153+
pathCoords: [],
1154+
color: this.brushColor.map(function (x) { return x; }),
1155+
mode: this.mode,
1156+
brushSize: this.brushSize,
1157+
eraserSize: this.eraserSize
1158+
};
1159+
this._lastCoords = coords;
1160+
}
1161+
exports._startStroke = _startStroke;
1162+
function _endStroke(endCoords) {
1163+
if (this._lastCoords[0] === endCoords[0] &&
1164+
this._lastCoords[1] === endCoords[1]) {
1165+
this._plot.apply(this, endCoords);
1166+
this._drawnPaths[this._pathIndex + 1].pathCoords.push(__spreadArrays(endCoords, [true]));
1167+
}
1168+
if (this._strokeHappening) {
1169+
this.canvas.removeEventListener('mousemove', this._strokeEventListener);
1170+
this._lastCoords = null;
1171+
if (this._drawnPaths[this._pathIndex + 1].pathCoords.length === 0)
1172+
this._drawnPaths.splice(-1, 1);
1173+
else {
1174+
this._drawnPaths = this._drawnPaths.slice(0, this._pathIndex + 2); // Overwrite further paths to prevent wrong redos
1175+
this._pathIndex++;
1176+
}
1177+
this._strokeHappening = false;
1178+
}
1179+
}
1180+
exports._endStroke = _endStroke;
1181+
function _doStroke(coords) {
1182+
this._strokeHappening = true;
1183+
this._drawnPaths[this._pathIndex + 1].pathCoords.push(__spreadArrays(coords, [false]));
1184+
this._stroke.apply(this, coords);
1185+
this._lastCoords = coords;
1186+
}
1187+
exports._doStroke = _doStroke;
1188+
});
1189+
11401190
var RealDrawBoard_1 = createCommonjsModule(function (module, exports) {
11411191
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
11421192
var extendStatics = function (d, b) {
@@ -1172,13 +1222,6 @@
11721222
var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
11731223
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11741224
};
1175-
var __spreadArrays = (commonjsGlobal && commonjsGlobal.__spreadArrays) || function () {
1176-
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
1177-
for (var r = Array(s), k = 0, i = 0; i < il; i++)
1178-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
1179-
r[k] = a[j];
1180-
return r;
1181-
};
11821225
Object.defineProperty(exports, "__esModule", { value: true });
11831226
exports.RealDrawBoard = exports.RealDrawBoardTypes = exports.RealRendererTypes = void 0;
11841227

@@ -1192,6 +1235,7 @@
11921235

11931236

11941237

1238+
11951239
var RealDrawBoard = /** @class */ (function (_super) {
11961240
__extends(RealDrawBoard, _super);
11971241
function RealDrawBoard(options) {
@@ -1209,6 +1253,9 @@
12091253
_this._resetBoard = boardManip._resetBoard;
12101254
_this._addMouseEvents = _DOMEvents._addMouseEvents;
12111255
_this._removeMouseEvents = _DOMEvents._removeMouseEvents;
1256+
_this._startStroke = stroke._startStroke;
1257+
_this._endStroke = stroke._endStroke;
1258+
_this._doStroke = stroke._doStroke;
12121259
_this.undo = undo_1.undo;
12131260
_this.redo = undo_1.redo;
12141261
_this.changeBrushColor = boardManip.changeBrushColor;
@@ -1226,53 +1273,24 @@
12261273
_this._mouseDownEventListener = function (e) {
12271274
if (e.button === 0 /* Left Click */) {
12281275
_this.canvas.addEventListener('mousemove', _this._strokeEventListener);
1229-
_this._strokeHappening = true;
1230-
_this._drawnPaths[_this._pathIndex + 1] = {
1231-
pathCoords: [],
1232-
color: _this.brushColor.map(function (x) { return x; }),
1233-
mode: _this.mode,
1234-
brushSize: _this.brushSize,
1235-
eraserSize: _this.eraserSize
1236-
};
1237-
_this._lastCoords = _this._getCoords(e);
1276+
_this._startStroke(_this._getCoords(e));
12381277
}
12391278
};
12401279
_this._mouseUpEventListener = function (e) {
1241-
if (e.button === 0) {
1242-
var currentCoords = _this._getCoords(e);
1243-
if (_this._lastCoords[0] === currentCoords[0] &&
1244-
_this._lastCoords[1] === currentCoords[1]) {
1245-
_this._plot.apply(_this, currentCoords);
1246-
_this._drawnPaths[_this._pathIndex + 1].pathCoords.push(__spreadArrays(currentCoords, [true]));
1247-
}
1248-
_this._strokeEnd();
1280+
if (e.button === 0 /* Left Click */) {
1281+
var endCoords = _this._getCoords(e);
1282+
_this._endStroke(endCoords);
12491283
}
12501284
};
12511285
_this._mouseEnterEventListener = function (e) {
12521286
_this._lastCoords = _this._getCoords(e);
12531287
};
12541288
_this._mouseLeaveEventListener = function (e) {
1255-
_this._strokeEnd();
1289+
_this._endStroke(_this._getCoords(e));
12561290
};
12571291
_this._strokeEventListener = function (e) {
12581292
var coords = _this._getCoords(e);
1259-
_this._strokeHappening = true;
1260-
_this._drawnPaths[_this._pathIndex + 1].pathCoords.push(__spreadArrays(coords, [false]));
1261-
_this._stroke.apply(_this, coords);
1262-
_this._lastCoords = coords;
1263-
};
1264-
_this._strokeEnd = function () {
1265-
if (_this._strokeHappening) {
1266-
_this.canvas.removeEventListener('mousemove', _this._strokeEventListener);
1267-
_this._lastCoords = null;
1268-
if (_this._drawnPaths[_this._pathIndex + 1].pathCoords.length === 0)
1269-
_this._drawnPaths.splice(-1, 1);
1270-
else {
1271-
_this._drawnPaths = _this._drawnPaths.slice(0, _this._pathIndex + 2); // Overwrite further paths to prevent wrong redos
1272-
_this._pathIndex++;
1273-
}
1274-
_this._strokeHappening = false;
1275-
}
1293+
_this._doStroke(coords);
12761294
};
12771295
options = __assign(__assign({}, RealDrawBoardDefaults.RealDrawBoardDefaults), options);
12781296
_this.options = options;

0 commit comments

Comments
 (0)