Skip to content

Commit 6f1e461

Browse files
author
HarshKhandeparkar
committed
refactor<RealDrawBoard>: yes, refactor
1 parent 7111bfd commit 6f1e461

File tree

6 files changed

+26
-26
lines changed

6 files changed

+26
-26
lines changed

dist/gpujs-real-renderer-browser.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@
10251025
if (this._pathIndex >= numUndo - 1 && this._pathIndex - numUndo < this._drawnPaths.length) {
10261026
this.graphPixels = this._blankGraph(); // Start with a blank graph
10271027
var originalMode = this.mode, originalBrushColor = this.brushColor, originalBrushSize = this.brushSize, originalEraserSize = this.eraserSize;
1028-
this._removeMouseEvents();
1028+
this._removeDOMEvents();
10291029
this._drawnPaths.slice(0, this._pathIndex - numUndo + 1).forEach(function (path) {
10301030
_this.mode = path.mode;
10311031
_this.brushColor = path.color;
@@ -1115,21 +1115,21 @@
11151115

11161116
var _DOMEvents = createCommonjsModule(function (module, exports) {
11171117
Object.defineProperty(exports, "__esModule", { value: true });
1118-
exports._removeMouseEvents = exports._addMouseEvents = void 0;
1119-
function _addMouseEvents() {
1118+
exports._removeDOMEvents = exports._addDOMEvents = void 0;
1119+
function _addDOMEvents() {
11201120
this.canvas.addEventListener('mousedown', this._mouseDownEventListener);
11211121
this.canvas.addEventListener('mouseup', this._mouseUpEventListener);
11221122
this.canvas.addEventListener('mouseenter', this._mouseEnterEventListener);
11231123
this.canvas.addEventListener('mouseleave', this._mouseLeaveEventListener);
11241124
}
1125-
exports._addMouseEvents = _addMouseEvents;
1126-
function _removeMouseEvents() {
1125+
exports._addDOMEvents = _addDOMEvents;
1126+
function _removeDOMEvents() {
11271127
this.canvas.removeEventListener('mousedown', this._mouseDownEventListener);
11281128
this.canvas.removeEventListener('mouseup', this._mouseUpEventListener);
11291129
this.canvas.removeEventListener('mouseenter', this._mouseEnterEventListener);
11301130
this.canvas.removeEventListener('mouseexit', this._mouseLeaveEventListener);
11311131
}
1132-
exports._removeMouseEvents = _removeMouseEvents;
1132+
exports._removeDOMEvents = _removeDOMEvents;
11331133
});
11341134

11351135
var stroke = createCommonjsModule(function (module, exports) {
@@ -1161,7 +1161,7 @@
11611161
this._drawnPaths[this._pathIndex + 1].pathCoords.push(__spreadArrays(endCoords, [true]));
11621162
}
11631163
if (this._strokeHappening) {
1164-
this.canvas.removeEventListener('mousemove', this._strokeEventListener);
1164+
this.canvas.removeEventListener('mousemove', this._mouseMoveEventListener);
11651165
this._lastCoords = null;
11661166
if (this._drawnPaths[this._pathIndex + 1].pathCoords.length === 0)
11671167
this._drawnPaths.splice(-1, 1);
@@ -1245,8 +1245,8 @@
12451245
_this._stroke = _draw._stroke;
12461246
_this._plot = _draw._plot;
12471247
_this._resetBoard = boardManip._resetBoard;
1248-
_this._addMouseEvents = _DOMEvents._addMouseEvents;
1249-
_this._removeMouseEvents = _DOMEvents._removeMouseEvents;
1248+
_this._addDOMEvents = _DOMEvents._addDOMEvents;
1249+
_this._removeDOMEvents = _DOMEvents._removeDOMEvents;
12501250
_this._startStroke = stroke._startStroke;
12511251
_this._endStroke = stroke._endStroke;
12521252
_this._doStroke = stroke._doStroke;
@@ -1266,7 +1266,7 @@
12661266
};
12671267
_this._mouseDownEventListener = function (e) {
12681268
if (e.button === 0 /* Left Click */) {
1269-
_this.canvas.addEventListener('mousemove', _this._strokeEventListener);
1269+
_this.canvas.addEventListener('mousemove', _this._mouseMoveEventListener);
12701270
_this._startStroke(_this._getCoords(e));
12711271
}
12721272
};
@@ -1282,7 +1282,7 @@
12821282
_this._mouseLeaveEventListener = function (e) {
12831283
_this._endStroke(_this._getCoords(e));
12841284
};
1285-
_this._strokeEventListener = function (e) {
1285+
_this._mouseMoveEventListener = function (e) {
12861286
var coords = _this._getCoords(e);
12871287
_this._doStroke(coords);
12881288
};
@@ -1297,12 +1297,12 @@
12971297
return _this;
12981298
}
12991299
RealDrawBoard.prototype.startRender = function () {
1300-
this._addMouseEvents();
1300+
this._addDOMEvents();
13011301
this._isDrawing = true;
13021302
return this;
13031303
};
13041304
RealDrawBoard.prototype.stopRender = function () {
1305-
this._removeMouseEvents();
1305+
this._removeDOMEvents();
13061306
this._isDrawing = false;
13071307
return this;
13081308
};

dist/gpujs-real-renderer-browser.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/renderers/RealDrawBoard/RealDrawBoard.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import {
2222
_resetBoard
2323
} from './boardManip';
2424
import {
25-
_addMouseEvents,
26-
_removeMouseEvents
25+
_addDOMEvents,
26+
_removeDOMEvents
2727
} from './_DOMEvents';
2828
import {
2929
_startStroke,
@@ -55,8 +55,8 @@ export class RealDrawBoard extends RealRenderer {
5555
protected _stroke = _stroke;
5656
protected _plot = _plot;
5757
protected _resetBoard = _resetBoard;
58-
protected _addMouseEvents = _addMouseEvents;
59-
protected _removeMouseEvents = _removeMouseEvents;
58+
protected _addDOMEvents = _addDOMEvents;
59+
protected _removeDOMEvents = _removeDOMEvents;
6060
protected _startStroke = _startStroke;
6161
protected _endStroke = _endStroke;
6262
protected _doStroke = _doStroke;
@@ -103,7 +103,7 @@ export class RealDrawBoard extends RealRenderer {
103103

104104
_mouseDownEventListener = (e: MouseEvent) => {
105105
if (e.button === 0 /* Left Click */) {
106-
this.canvas.addEventListener('mousemove', this._strokeEventListener);
106+
this.canvas.addEventListener('mousemove', this._mouseMoveEventListener);
107107

108108
this._startStroke(this._getCoords(e));
109109
}
@@ -124,20 +124,20 @@ export class RealDrawBoard extends RealRenderer {
124124
this._endStroke(this._getCoords(e));
125125
}
126126

127-
_strokeEventListener = (e: MouseEvent) => {
127+
_mouseMoveEventListener = (e: MouseEvent) => {
128128
const coords = this._getCoords(e);
129129
this._doStroke(coords);
130130
}
131131

132132
startRender() {
133-
this._addMouseEvents();
133+
this._addDOMEvents();
134134
this._isDrawing = true;
135135

136136
return this;
137137
}
138138

139139
stopRender() {
140-
this._removeMouseEvents();
140+
this._removeDOMEvents();
141141
this._isDrawing = false;
142142

143143
return this;

src/renderers/RealDrawBoard/_DOMEvents.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { RealDrawBoard } from './RealDrawBoard';
22

3-
export function _addMouseEvents(this: RealDrawBoard) {
3+
export function _addDOMEvents(this: RealDrawBoard) {
44
this.canvas.addEventListener('mousedown', this._mouseDownEventListener);
55
this.canvas.addEventListener('mouseup', this._mouseUpEventListener);
66
this.canvas.addEventListener('mouseenter', this._mouseEnterEventListener);
77
this.canvas.addEventListener('mouseleave', this._mouseLeaveEventListener);
88
}
99

10-
export function _removeMouseEvents(this: RealDrawBoard) {
10+
export function _removeDOMEvents(this: RealDrawBoard) {
1111
this.canvas.removeEventListener('mousedown', this._mouseDownEventListener);
1212
this.canvas.removeEventListener('mouseup', this._mouseUpEventListener);
1313
this.canvas.removeEventListener('mouseenter', this._mouseEnterEventListener);

src/renderers/RealDrawBoard/stroke.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function _endStroke(
3131
}
3232

3333
if (this._strokeHappening) {
34-
this.canvas.removeEventListener('mousemove', this._strokeEventListener);
34+
this.canvas.removeEventListener('mousemove', this._mouseMoveEventListener);
3535
this._lastCoords = null;
3636

3737
if (this._drawnPaths[this._pathIndex + 1].pathCoords.length === 0) this._drawnPaths.splice(-1, 1);

src/renderers/RealDrawBoard/undo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function undo(this: RealDrawBoard, numUndo: number = 1) {
1010
originalBrushSize = this.brushSize,
1111
originalEraserSize = this.eraserSize;
1212

13-
this._removeMouseEvents();
13+
this._removeDOMEvents();
1414

1515
this._drawnPaths.slice(0, this._pathIndex - numUndo + 1).forEach(path => {
1616
this.mode = path.mode;

0 commit comments

Comments
 (0)