Skip to content

Commit 2ba2230

Browse files
author
HarshKhandeparkar
committed
v0.8.0
1 parent 03c28f5 commit 2ba2230

File tree

3 files changed

+130
-120
lines changed

3 files changed

+130
-120
lines changed

dist/gpujs-real-renderer-browser.js

Lines changed: 128 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -990,144 +990,83 @@
990990
exports.RealComplexSpace = RealComplexSpace;
991991
});
992992

993-
var RealDrawBoardDefaults = createCommonjsModule(function (module, exports) {
994-
Object.defineProperty(exports, "__esModule", { value: true });
995-
exports.RealDrawBoardDefaults = void 0;
996-
exports.RealDrawBoardDefaults = {
997-
brushSize: 1,
998-
eraserSize: 2,
999-
brushColor: [1, 1, 1],
1000-
allowUndo: false,
1001-
maxUndos: 10,
1002-
tool: 'brush'
1003-
};
1004-
});
1005-
1006-
var RealDrawBoardTypes = createCommonjsModule(function (module, exports) {
1007-
Object.defineProperty(exports, "__esModule", { value: true });
1008-
});
1009-
1010-
var _initializeKernels_1 = createCommonjsModule(function (module, exports) {
1011-
Object.defineProperty(exports, "__esModule", { value: true });
1012-
exports._initializeKernels = void 0;
1013-
1014-
1015-
function _initializeKernels() {
1016-
this._plotKernel = plot.getPlotKernel(this.gpu, this.dimensions, this.xScaleFactor, this.yScaleFactor, this.xOffset, this.yOffset);
1017-
this._previewPlot = plot.getPlotKernel(this.gpu, this.dimensions, this.xScaleFactor, this.yScaleFactor, this.xOffset, this.yOffset);
1018-
this._strokeKernel = interpolate.getInterpolateKernel(this.gpu, this.dimensions, this.xScaleFactor, this.yScaleFactor, this.xOffset, this.yOffset);
1019-
}
1020-
exports._initializeKernels = _initializeKernels;
1021-
});
1022-
1023-
var _draw = createCommonjsModule(function (module, exports) {
1024-
Object.defineProperty(exports, "__esModule", { value: true });
1025-
exports._stroke = exports._plot = void 0;
1026-
function _plot(x, y, size, color) {
1027-
this.graphPixels = this._plotKernel(this._cloneTexture(this.graphPixels), x, y, size, color);
1028-
return this;
1029-
}
1030-
exports._plot = _plot;
1031-
function _stroke(x, y, size, color, identifier) {
1032-
if (!this._lastCoords.has(identifier))
1033-
this._lastCoords.set(identifier, [x, y]);
1034-
this.graphPixels = this._strokeKernel(this._cloneTexture(this.graphPixels), this._lastCoords.get(identifier), [x, y], size, color);
1035-
}
1036-
exports._stroke = _stroke;
1037-
});
1038-
1039-
var undo_1 = createCommonjsModule(function (module, exports) {
1040-
Object.defineProperty(exports, "__esModule", { value: true });
1041-
exports.redo = exports.undo = void 0;
1042-
function undo(numUndo) {
1043-
if (numUndo === void 0) { numUndo = 1; }
1044-
if (this._currentSnapshotIndex - numUndo >= 0 &&
1045-
this._currentSnapshotIndex - numUndo < this._snapshots.length) {
1046-
var wasDrawing = this._isDrawing;
1047-
this.stopRender();
1048-
this.graphPixels = this._loadData(this._snapshots[this._currentSnapshotIndex - numUndo]);
1049-
this._currentSnapshotIndex -= numUndo;
1050-
this._display(this.graphPixels);
1051-
if (wasDrawing)
1052-
this.startRender();
1053-
}
1054-
return this;
1055-
}
1056-
exports.undo = undo;
1057-
function redo(numRedo) {
1058-
if (numRedo === void 0) { numRedo = 1; }
1059-
this.undo(-numRedo);
1060-
return this;
1061-
}
1062-
exports.redo = redo;
1063-
});
1064-
1065993
var brush = createCommonjsModule(function (module, exports) {
1066994
Object.defineProperty(exports, "__esModule", { value: true });
1067-
exports._toolPreview = exports._doStroke = exports._endStroke = exports._startStroke = exports.name = void 0;
995+
exports._toolPreview = exports._doStroke = exports._endStroke = exports._startStroke = exports.BrushDefaults = exports.name = void 0;
1068996
exports.name = 'brush';
997+
exports.BrushDefaults = {
998+
brushColor: [1, 1, 1],
999+
brushSize: 1
1000+
};
10691001
function _startStroke(coords, identifier) {
10701002
this._doPreview = false;
1071-
this._plot(coords[0], coords[1], this.brushSize, this.brushColor);
1003+
this._plot(coords[0], coords[1], this.toolSettings.brushSize, this.toolSettings.brushColor);
10721004
}
10731005
exports._startStroke = _startStroke;
10741006
function _endStroke(endCoords, identifier) {
1075-
this._plot(endCoords[0], endCoords[1], this.brushSize, this.brushColor);
1007+
this._plot(endCoords[0], endCoords[1], this.toolSettings.brushSize, this.toolSettings.brushColor);
10761008
this._doPreview = true;
10771009
}
10781010
exports._endStroke = _endStroke;
10791011
function _doStroke(coords, identifier) {
1080-
this._plot(coords[0], coords[1], this.brushSize, this.brushColor);
1081-
this._stroke(coords[0], coords[1], this.brushSize, this.brushColor, identifier);
1012+
this._plot(coords[0], coords[1], this.toolSettings.brushSize, this.toolSettings.brushColor);
1013+
this._stroke(coords[0], coords[1], this.toolSettings.brushSize, this.toolSettings.brushColor, identifier);
10821014
}
10831015
exports._doStroke = _doStroke;
10841016
function _toolPreview(coords, identifier) {
1085-
return this._previewPlot(this.graphPixels, coords[0], coords[1], this.brushSize, this.brushColor);
1017+
return this._previewPlot(this.graphPixels, coords[0], coords[1], this.toolSettings.brushSize, this.toolSettings.brushColor);
10861018
}
10871019
exports._toolPreview = _toolPreview;
10881020
});
10891021

10901022
var eraser = createCommonjsModule(function (module, exports) {
10911023
Object.defineProperty(exports, "__esModule", { value: true });
1092-
exports._toolPreview = exports._doStroke = exports._endStroke = exports._startStroke = exports.name = void 0;
1024+
exports._toolPreview = exports._doStroke = exports._endStroke = exports._startStroke = exports.EraserDefaults = exports.name = void 0;
10931025
exports.name = 'eraser';
1026+
exports.EraserDefaults = {
1027+
eraserSize: 2
1028+
};
10941029
function _startStroke(coords, identifier) {
10951030
this._doPreview = false;
1096-
this._plot(coords[0], coords[1], this.eraserSize, this.bgColor);
1031+
this._plot(coords[0], coords[1], this.toolSettings.eraserSize, this.bgColor);
10971032
}
10981033
exports._startStroke = _startStroke;
10991034
function _endStroke(endCoords, identifier) {
11001035
this._doPreview = true;
1101-
this._plot(endCoords[0], endCoords[1], this.eraserSize, this.bgColor);
1036+
this._plot(endCoords[0], endCoords[1], this.toolSettings.eraserSize, this.bgColor);
11021037
}
11031038
exports._endStroke = _endStroke;
11041039
function _doStroke(coords, identifier) {
1105-
this._plot(coords[0], coords[1], this.eraserSize, this.bgColor);
1106-
this._stroke(coords[0], coords[1], this.eraserSize, this.bgColor, identifier);
1040+
this._plot(coords[0], coords[1], this.toolSettings.eraserSize, this.bgColor);
1041+
this._stroke(coords[0], coords[1], this.toolSettings.eraserSize, this.bgColor, identifier);
11071042
}
11081043
exports._doStroke = _doStroke;
11091044
function _toolPreview(coords, identifier) {
1110-
return this._previewPlot(this.graphPixels, coords[0], coords[1], this.eraserSize, this.bgColor);
1045+
return this._previewPlot(this.graphPixels, coords[0], coords[1], this.toolSettings.eraserSize, this.bgColor);
11111046
}
11121047
exports._toolPreview = _toolPreview;
11131048
});
11141049

11151050
var line = createCommonjsModule(function (module, exports) {
11161051
Object.defineProperty(exports, "__esModule", { value: true });
1117-
exports._toolPreview = exports._doStroke = exports._endStroke = exports._startStroke = exports.name = void 0;
1052+
exports._toolPreview = exports._doStroke = exports._endStroke = exports._startStroke = exports.LineDefaults = exports.name = void 0;
11181053
exports.name = 'line';
1054+
exports.LineDefaults = {
1055+
lineThickness: 1,
1056+
lineColor: [1, 1, 1]
1057+
};
11191058
/** key -> identifier, value -> coordinate
11201059
* For mouse, the key is 'mouse', for touches, stringified identifier -> https://developer.mozilla.org/en-US/docs/Web/API/Touch/identifier
11211060
*/
11221061
var _startCoords = new Map(); /* key -> identifier, value -> coordinate*/
11231062
function _startStroke(coords, identifier) {
1124-
this._plot(coords[0], coords[1], this.brushSize, this.brushColor);
1063+
this._plot(coords[0], coords[1], this.toolSettings.lineThickness, this.toolSettings.lineColor);
11251064
_startCoords.set(identifier, coords);
11261065
}
11271066
exports._startStroke = _startStroke;
11281067
function _endStroke(endCoords, identifier) {
1129-
this.graphPixels = this._strokeKernel(this._cloneTexture(this.graphPixels), _startCoords.get(identifier), endCoords, this.brushSize, this.brushColor);
1130-
this._plot(endCoords[0], endCoords[1], this.brushSize, this.brushColor);
1068+
this.graphPixels = this._strokeKernel(this._cloneTexture(this.graphPixels), _startCoords.get(identifier), endCoords, this.toolSettings.lineThickness, this.toolSettings.lineColor);
1069+
this._plot(endCoords[0], endCoords[1], this.toolSettings.lineThickness, this.toolSettings.lineColor);
11311070
_startCoords.delete(identifier);
11321071
}
11331072
exports._endStroke = _endStroke;
@@ -1136,10 +1075,10 @@
11361075
exports._doStroke = _doStroke;
11371076
function _toolPreview(coords, identifier) {
11381077
if (_startCoords.has(identifier)) {
1139-
return this._previewPlot(this._strokeKernel(this._cloneTexture(this.graphPixels), _startCoords.get(identifier), coords, this.brushSize, this.brushColor), coords[0], coords[1], this.brushSize, this.brushColor);
1078+
return this._previewPlot(this._strokeKernel(this._cloneTexture(this.graphPixels), _startCoords.get(identifier), coords, this.toolSettings.lineThickness, this.toolSettings.lineColor), coords[0], coords[1], this.toolSettings.lineThickness, this.toolSettings.lineColor);
11401079
}
11411080
else
1142-
return this._previewPlot(this.graphPixels, coords[0], coords[1], this.brushSize, this.brushColor);
1081+
return this._previewPlot(this.graphPixels, coords[0], coords[1], this.toolSettings.lineThickness, this.toolSettings.lineColor);
11431082
}
11441083
exports._toolPreview = _toolPreview;
11451084
});
@@ -1203,39 +1142,54 @@
12031142

12041143
var rainbow_brush = createCommonjsModule(function (module, exports) {
12051144
Object.defineProperty(exports, "__esModule", { value: true });
1206-
exports._toolPreview = exports._doStroke = exports._endStroke = exports._startStroke = exports.name = void 0;
1145+
exports._toolPreview = exports._doStroke = exports._endStroke = exports._startStroke = exports.RainbowBrushDefaults = exports.name = void 0;
12071146

12081147
var hue = 0;
12091148
var gradientColors = [1, 1, 1];
12101149
exports.name = 'rainbow_brush';
1150+
exports.RainbowBrushDefaults = {
1151+
brushSize: 1,
1152+
changeRate: 1
1153+
};
12111154
function _startStroke(coords, identifier) {
12121155
gradientColors = convertHSLToRGB_1.convertHSLToRGB(hue, 90, 40);
12131156
this._doPreview = false;
1214-
this._plot(coords[0], coords[1], this.brushSize, gradientColors);
1157+
this._plot(coords[0], coords[1], this.toolSettings.brushSize, gradientColors);
12151158
}
12161159
exports._startStroke = _startStroke;
12171160
function _endStroke(endCoords, identifier) {
12181161
gradientColors = convertHSLToRGB_1.convertHSLToRGB(hue, 90, 40);
1219-
this._plot(endCoords[0], endCoords[1], this.brushSize, gradientColors);
1162+
this._plot(endCoords[0], endCoords[1], this.toolSettings.brushSize, gradientColors);
12201163
this._doPreview = true;
12211164
}
12221165
exports._endStroke = _endStroke;
12231166
function _doStroke(coords, identifier) {
1224-
hue = (hue + 1) % 360;
1167+
hue = (hue + this.toolSettings.changeRate) % 360;
12251168
gradientColors = convertHSLToRGB_1.convertHSLToRGB(hue, 90, 40);
1226-
this._plot(coords[0], coords[1], this.brushSize, gradientColors);
1227-
this._stroke(coords[0], coords[1], this.brushSize, gradientColors, identifier);
1169+
this._plot(coords[0], coords[1], this.toolSettings.brushSize, gradientColors);
1170+
this._stroke(coords[0], coords[1], this.toolSettings.brushSize, gradientColors, identifier);
12281171
}
12291172
exports._doStroke = _doStroke;
12301173
function _toolPreview(coords, identifier) {
1231-
return this._previewPlot(this.graphPixels, coords[0], coords[1], this.brushSize, gradientColors);
1174+
return this._previewPlot(this.graphPixels, coords[0], coords[1], this.toolSettings.brushSize, gradientColors);
12321175
}
12331176
exports._toolPreview = _toolPreview;
12341177
});
12351178

12361179
var tools = createCommonjsModule(function (module, exports) {
1180+
var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
1181+
__assign = Object.assign || function(t) {
1182+
for (var s, i = 1, n = arguments.length; i < n; i++) {
1183+
s = arguments[i];
1184+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
1185+
t[p] = s[p];
1186+
}
1187+
return t;
1188+
};
1189+
return __assign.apply(this, arguments);
1190+
};
12371191
Object.defineProperty(exports, "__esModule", { value: true });
1238-
exports.tools = void 0;
1192+
exports.ToolDefaults = exports.tools = void 0;
12391193

12401194

12411195

@@ -1246,27 +1200,84 @@
12461200
eraser: eraser,
12471201
line: line
12481202
};
1203+
exports.ToolDefaults = __assign(__assign(__assign(__assign({}, brush.BrushDefaults), line.LineDefaults), eraser.EraserDefaults), rainbow_brush.RainbowBrushDefaults);
12491204
});
12501205

1251-
var boardManip = createCommonjsModule(function (module, exports) {
1206+
var RealDrawBoardDefaults = createCommonjsModule(function (module, exports) {
1207+
Object.defineProperty(exports, "__esModule", { value: true });
1208+
exports.RealDrawBoardDefaults = void 0;
1209+
1210+
exports.RealDrawBoardDefaults = {
1211+
toolSettings: tools.ToolDefaults,
1212+
allowUndo: false,
1213+
maxUndos: 10,
1214+
tool: 'brush'
1215+
};
1216+
});
1217+
1218+
var RealDrawBoardTypes = createCommonjsModule(function (module, exports) {
1219+
Object.defineProperty(exports, "__esModule", { value: true });
1220+
});
1221+
1222+
var _initializeKernels_1 = createCommonjsModule(function (module, exports) {
12521223
Object.defineProperty(exports, "__esModule", { value: true });
1253-
exports._resetBoard = exports.clear = exports.changeTool = exports.changeEraserSize = exports.changeBrushSize = exports.changeBrushColor = void 0;
1224+
exports._initializeKernels = void 0;
1225+
1226+
1227+
function _initializeKernels() {
1228+
this._plotKernel = plot.getPlotKernel(this.gpu, this.dimensions, this.xScaleFactor, this.yScaleFactor, this.xOffset, this.yOffset);
1229+
this._previewPlot = plot.getPlotKernel(this.gpu, this.dimensions, this.xScaleFactor, this.yScaleFactor, this.xOffset, this.yOffset);
1230+
this._strokeKernel = interpolate.getInterpolateKernel(this.gpu, this.dimensions, this.xScaleFactor, this.yScaleFactor, this.xOffset, this.yOffset);
1231+
}
1232+
exports._initializeKernels = _initializeKernels;
1233+
});
12541234

1255-
function changeBrushColor(color) {
1256-
this.brushColor = color;
1235+
var _draw = createCommonjsModule(function (module, exports) {
1236+
Object.defineProperty(exports, "__esModule", { value: true });
1237+
exports._stroke = exports._plot = void 0;
1238+
function _plot(x, y, size, color) {
1239+
this.graphPixels = this._plotKernel(this._cloneTexture(this.graphPixels), x, y, size, color);
12571240
return this;
12581241
}
1259-
exports.changeBrushColor = changeBrushColor;
1260-
function changeBrushSize(newSize) {
1261-
this.brushSize = newSize;
1242+
exports._plot = _plot;
1243+
function _stroke(x, y, size, color, identifier) {
1244+
if (!this._lastCoords.has(identifier))
1245+
this._lastCoords.set(identifier, [x, y]);
1246+
this.graphPixels = this._strokeKernel(this._cloneTexture(this.graphPixels), this._lastCoords.get(identifier), [x, y], size, color);
1247+
}
1248+
exports._stroke = _stroke;
1249+
});
1250+
1251+
var undo_1 = createCommonjsModule(function (module, exports) {
1252+
Object.defineProperty(exports, "__esModule", { value: true });
1253+
exports.redo = exports.undo = void 0;
1254+
function undo(numUndo) {
1255+
if (numUndo === void 0) { numUndo = 1; }
1256+
if (this._currentSnapshotIndex - numUndo >= 0 &&
1257+
this._currentSnapshotIndex - numUndo < this._snapshots.length) {
1258+
var wasDrawing = this._isDrawing;
1259+
this.stopRender();
1260+
this.graphPixels = this._loadData(this._snapshots[this._currentSnapshotIndex - numUndo]);
1261+
this._currentSnapshotIndex -= numUndo;
1262+
this._display(this.graphPixels);
1263+
if (wasDrawing)
1264+
this.startRender();
1265+
}
12621266
return this;
12631267
}
1264-
exports.changeBrushSize = changeBrushSize;
1265-
function changeEraserSize(newSize) {
1266-
this.eraserSize = newSize;
1268+
exports.undo = undo;
1269+
function redo(numRedo) {
1270+
if (numRedo === void 0) { numRedo = 1; }
1271+
this.undo(-numRedo);
12671272
return this;
12681273
}
1269-
exports.changeEraserSize = changeEraserSize;
1274+
exports.redo = redo;
1275+
});
1276+
1277+
var boardManip = createCommonjsModule(function (module, exports) {
1278+
Object.defineProperty(exports, "__esModule", { value: true });
1279+
exports._resetBoard = exports.clear = exports.changeToolSetting = exports.changeTool = void 0;
1280+
12701281
function changeTool(newTool) {
12711282
this.tool = newTool;
12721283
this._startStroke = tools.tools[this.tool]._startStroke;
@@ -1276,6 +1287,11 @@
12761287
return this;
12771288
}
12781289
exports.changeTool = changeTool;
1290+
function changeToolSetting(settingName, value) {
1291+
this.toolSettings[settingName] = value;
1292+
return this;
1293+
}
1294+
exports.changeToolSetting = changeToolSetting;
12791295
function clear() {
12801296
this._snapshots = [];
12811297
this._currentSnapshotIndex = 0;
@@ -1290,11 +1306,9 @@
12901306
function _resetBoard() {
12911307
this.xScaleFactor = this.options.xScaleFactor;
12921308
this.yScaleFactor = this.options.yScaleFactor;
1293-
this.brushColor = this.options.brushColor;
1294-
this.brushSize = this.options.brushSize;
12951309
this.bgColor = this.options.bgColor;
1296-
this.eraserSize = this.options.eraserSize;
12971310
this.tool = this.options.tool;
1311+
this.toolSettings = this.options.toolSettings;
12981312
this._isDrawing = false;
12991313
this._currentSnapshotIndex = 0;
13001314
if (this._maxSnapshots > 0)
@@ -1435,9 +1449,7 @@
14351449
_this._getTouchCoords = _coords._getTouchCoords;
14361450
_this.undo = undo_1.undo;
14371451
_this.redo = undo_1.redo;
1438-
_this.changeBrushColor = boardManip.changeBrushColor;
1439-
_this.changeBrushSize = boardManip.changeBrushSize;
1440-
_this.changeEraserSize = boardManip.changeEraserSize;
1452+
_this.changeToolSetting = boardManip.changeToolSetting;
14411453
_this.changeTool = boardManip.changeTool;
14421454
_this.clear = boardManip.clear;
14431455
// --- DOM Event Listeners ---
@@ -1550,9 +1562,7 @@
15501562
};
15511563
options = __assign(__assign({}, RealDrawBoardDefaults.RealDrawBoardDefaults), options);
15521564
_this.options = options;
1553-
_this.brushSize = options.brushSize;
1554-
_this.brushColor = options.brushColor;
1555-
_this.eraserSize = options.eraserSize;
1565+
_this.toolSettings = options.toolSettings;
15561566
_this._maxSnapshots = options.allowUndo ? Math.max(options.maxUndos + 1, 0) : 0;
15571567
_this.changeTool(options.tool);
15581568
// *****DEFAULTS*****

0 commit comments

Comments
 (0)