Skip to content

Commit 9d4d0ba

Browse files
author
HarshKhandeparkar
committed
feat: maxUndos capacity
1 parent 2fa7755 commit 9d4d0ba

File tree

6 files changed

+16
-2
lines changed

6 files changed

+16
-2
lines changed

dist/gpujs-real-renderer-browser.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,7 @@
10111011
brushSize: 1,
10121012
eraserSize: 2,
10131013
brushColor: [1, 1, 1],
1014+
maxUndos: 15,
10141015
mode: 'paint'
10151016
};
10161017
});
@@ -1164,6 +1165,10 @@
11641165
this._plot.apply(this, endCoords);
11651166
this._lastCoords.delete(identifier);
11661167
this._snapshots[++this._currentSnapshotIndex] = this.getData();
1168+
if (this._snapshots.length > this._maxSnapshots) {
1169+
this._snapshots.shift();
1170+
this._currentSnapshotIndex--;
1171+
}
11671172
}
11681173
exports._endStroke = _endStroke;
11691174
function _doStroke(coords, identifier) {
@@ -1334,6 +1339,7 @@
13341339
_this.brushSize = options.brushSize;
13351340
_this.brushColor = options.brushColor;
13361341
_this.eraserSize = options.eraserSize;
1342+
_this._maxSnapshots = Math.max(options.maxUndos, 1);
13371343
_this.mode = options.mode;
13381344
// *****DEFAULTS*****
13391345
_this._initializeKernels();

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/constants/defaults/RealDrawBoardDefaults.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ export const RealDrawBoardDefaults: RealDrawBoardOptions = {
44
brushSize: 1,
55
eraserSize: 2,
66
brushColor: [1, 1, 1],
7+
maxUndos: 15,
78
mode: 'paint'
89
}

src/renderers/RealDrawBoard/RealDrawBoard.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Color } from '../../types/RealRendererTypes';
44
import { RealDrawBoardOptions, DrawMode } from '../../types/RealDrawBoardTypes';
55
import { RealDrawBoardDefaults } from '../../constants/defaults/RealDrawBoardDefaults';
66

7-
import { IKernelRunShortcut, Texture } from 'gpu.js';
7+
import { IKernelRunShortcut } from 'gpu.js';
88

99
export * as RealRendererTypes from '../../types/RealRendererTypes';
1010
export * as RealDrawBoardTypes from '../../types/RealDrawBoardTypes';
@@ -44,6 +44,7 @@ export class RealDrawBoard extends RealRenderer {
4444
_isDrawing: boolean = false;
4545
_snapshots: number[][] = []; // Undo snapshots
4646
_currentSnapshotIndex = 0; // Current snapshot
47+
_maxSnapshots: number;
4748
_plotKernel: IKernelRunShortcut;
4849
_previewPlot: IKernelRunShortcut;
4950
_strokeKernel: IKernelRunShortcut;
@@ -87,6 +88,7 @@ export class RealDrawBoard extends RealRenderer {
8788
this.brushColor = options.brushColor;
8889

8990
this.eraserSize = options.eraserSize;
91+
this._maxSnapshots = Math.max(options.maxUndos, 1);
9092

9193
this.mode = options.mode;
9294
// *****DEFAULTS*****

src/renderers/RealDrawBoard/stroke.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export function _endStroke(
2121
this._lastCoords.delete(identifier);
2222

2323
this._snapshots[++this._currentSnapshotIndex] = this.getData();
24+
if (this._snapshots.length > this._maxSnapshots) {
25+
this._snapshots.shift();
26+
this._currentSnapshotIndex--;
27+
}
2428
}
2529

2630
export function _doStroke(

src/types/RealDrawBoardTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ export interface RealDrawBoardOptions extends RealRendererOptions {
66
brushSize?: number,
77
brushColor?: Color,
88
eraserSize?: number,
9+
maxUndos?: number,
910
mode?: 'paint' | 'erase'
1011
}

0 commit comments

Comments
 (0)