@@ -14,6 +14,7 @@ import iterateGrid from './utils/interateGrid';
1414import bitmaskToPath from './utils/bitmapToMask' ;
1515import createLayer from './utils/createLayer' ;
1616import diffGrid from './utils/diffGrid' ;
17+ import { getGuides } from './utils/getGuides' ;
1718
1819type Pixel = { x : number , y : number } ;
1920
@@ -152,25 +153,39 @@ export default class PgInputPixelEditor extends HTMLElement {
152153 }
153154 }
154155
156+ #reset = true ;
155157 #init( ) {
156158 const totalSize = this . size + this . gridSize ;
157159 const actualWidth = this . width * totalSize - this . gridSize ;
158160 const actualHeight = this . height * totalSize - this . gridSize ;
159161 this . $canvas . width = actualWidth ;
160162 this . $canvas . height = actualHeight ;
161- this . #layer = 0 ;
162- this . #layers = [ {
163- name : 'Layer 1' ,
164- export : true ,
165- locked : false ,
166- visible : true ,
167- opacity : 1
168- } ] ;
169- this . #data = [ fillGrid ( this . width , this . height ) ] ;
170163 [ this . #baseLayer, this . #baseLayerContext] = createLayer ( actualWidth , actualHeight ) ;
171164 [ this . #editLayer, this . #editLayerContext] = createLayer ( actualWidth , actualHeight ) ;
172165 [ this . #noEditLayer, this . #noEditLayerContext] = createLayer ( actualWidth , actualHeight ) ;
173166 [ this . #previewLayer, this . #previewLayerContext] = createLayer ( actualWidth , actualHeight ) ;
167+ if ( this . #reset) {
168+ this . #layer = 0 ;
169+ this . #layers = [ {
170+ name : 'Layer 1' ,
171+ export : true ,
172+ locked : false ,
173+ visible : true ,
174+ opacity : 1
175+ } ] ;
176+ this . #data = [ fillGrid ( this . width , this . height ) ] ;
177+ this . #reset = false ;
178+ }
179+ this . #redraw( ) ;
180+ }
181+
182+ #redraw( ) {
183+ // Render individual pixels
184+ this . #data[ this . #layer] . forEach ( ( row , y ) => {
185+ row . forEach ( ( cell , x ) => {
186+ this . #setPixel( x , y , cell ) ;
187+ } ) ;
188+ } ) ;
174189 }
175190
176191 #handleChange( ) {
@@ -579,6 +594,13 @@ export default class PgInputPixelEditor extends HTMLElement {
579594 cloned [ y ] [ x ] = cloned [ y ] [ x ] === 0 ? 1 : 0 ;
580595 } ) ;
581596 this . #data[ this . #layer] = cloned ;
597+ }
598+ applyGuides ( ) {
599+ const guides = getGuides ( this . width , this . height , this . size , this . gridSize ) ;
600+ this . #baseLayerContext. drawImage ( guides , 0 , 0 ) ;
601+ }
602+ clearGuides ( ) {
603+
582604 }
583605 undo ( ) {
584606 // ToDo: Rewrite to use new history api
0 commit comments