Skip to content

Commit b4fe947

Browse files
committed
Invert support.
1 parent 47d9ca2 commit b4fe947

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/pg/inputPixelEditor/__examples__/basic/basic.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<div>
2929
<button part="reset">Reset</button>
3030
<button part="clear">Clear</button>
31+
<button part="invert">Invert</button>
3132
<button part="modePixel">Pixel</button>
3233
<button part="modeLine">Line</button>
3334
<button part="modeRectangle">Rectangle</button>

src/pg/inputPixelEditor/__examples__/basic/basic.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default class XPgInputPixelEditorBasic extends HTMLElement {
2222

2323
@Part() $reset: HTMLButtonElement;
2424
@Part() $clear: HTMLButtonElement;
25+
@Part() $invert: HTMLButtonElement;
2526
@Part() $modePixel: HTMLButtonElement;
2627
@Part() $modeLine: HTMLButtonElement;
2728
@Part() $modeRectangle: HTMLButtonElement;
@@ -64,6 +65,9 @@ export default class XPgInputPixelEditorBasic extends HTMLElement {
6465
this.$clear.addEventListener('click', () => {
6566
this.$input.clear();
6667
});
68+
this.$invert.addEventListener('click', () => {
69+
this.$input.invert();
70+
});
6771
}
6872

6973
handleChange(e: CustomEvent) {

src/pg/inputPixelEditor/inputPixelEditor.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,14 @@ export default class PgInputPixelEditor extends HTMLElement {
301301
this.#delayedChange();
302302
}
303303

304+
#setPixelAll() {
305+
for (let y = 0; y < this.height; y++) {
306+
for (let x = 0; x < this.width; x++) {
307+
this.#setPixel(x, y, this.#data[this.#layer][y][x]);
308+
}
309+
}
310+
}
311+
304312
#setPreview(pixels: Pixel[], previousX: number, previousY: number) {
305313
const totalSize = this.size + this.gridSize;
306314
const actualWidth = this.width * totalSize - this.gridSize;
@@ -656,16 +664,17 @@ export default class PgInputPixelEditor extends HTMLElement {
656664
if (this.#colors.length > 2) {
657665
return;
658666
}
659-
const cloned = cloneGrid(this.#data[this.#layer]);
660-
iterateGrid(cloned, (x, y) => {
661-
cloned[y][x] = cloned[y][x] === 0 ? 1 : 0;
667+
iterateGrid(this.#data[this.#layer], (x, y) => {
668+
this.#data[this.#layer][y][x] = this.#data[this.#layer] [y][x] === 0 ? 1 : 0;
662669
});
663-
this.#data[this.#layer] = cloned;
670+
this.#setPixelAll();
664671
}
672+
665673
applyGuides() {
666674
const guides = getGuides(this.width, this.height, this.size, this.gridSize);
667675
this.#baseLayerContext.drawImage(guides, 0, 0);
668676
}
677+
669678
clearGuides() {
670679

671680
}

0 commit comments

Comments
 (0)