Skip to content

Commit bf87832

Browse files
committed
Marching ants testing.
1 parent 8d227b2 commit bf87832

4 files changed

Lines changed: 70 additions & 1 deletion

File tree

src/pg/inputPixelEditor/inputPixelEditor.css

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
}
44

55
[part="wrapper"] {
6-
display: flex;
6+
display: grid;
7+
grid-template-columns: auto;
8+
grid-template-rows: auto;
79
position: relative;
810
outline: 0;
911
}
@@ -21,7 +23,32 @@
2123
}
2224

2325
canvas {
26+
grid-column: 1;
27+
grid-row: 1;
2428
touch-action: none;
2529
user-select: none;
2630
outline: 0;
31+
}
32+
33+
svg {
34+
pointer-events: none;
35+
grid-column: 1;
36+
grid-row: 1;
37+
}
38+
39+
path {
40+
fill: none;
41+
stroke: #000;
42+
stroke-width: 1px;
43+
vector-effect: non-scaling-stroke;
44+
stroke-dasharray: 5px;
45+
animation: stroke 0.4s linear infinite;
46+
shape-rendering: geometricPrecision;
47+
stroke-dashoffset: 10px;
48+
}
49+
50+
@keyframes stroke {
51+
to {
52+
stroke-dashoffset: 0;
53+
}
2754
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
11
<div part="wrapper" tabindex="0">
22
<canvas part="canvas" draggable="false"></canvas>
3+
<svg part="selection" viewBox="0 0 10 10">
4+
<defs>
5+
<filter id="whiteOutline" x="-50%" y="-50%" width="200%" height="200%">
6+
<!-- Thicken the source graphic (the original stroke path) -->
7+
<feMorphology in="SourceGraphic" operator="dilate" radius="1" result="dilated" />
8+
9+
<!-- Flood the dilated shape with white color -->
10+
<feFlood flood-color="white" result="flood" />
11+
12+
<!-- Composite the white color with the dilated shape to create the white outline shape -->
13+
<feComposite in="flood" in2="dilated" operator="in" result="whiteOutlineShape" />
14+
15+
<!-- Merge the white outline shape with the original source graphic -->
16+
<feMerge>
17+
<feMergeNode in="whiteOutlineShape" />
18+
<feMergeNode in="SourceGraphic" />
19+
</feMerge>
20+
</filter>
21+
</defs>
22+
<path part="selectionPath" d="M9,7H1V1H9Z" filter="url(#whiteOutline)" />
23+
</svg>
324
</div>

src/pg/inputPixelEditor/inputPixelEditor.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ export default class PgInputPixelEditor extends HTMLElement {
9898

9999
@Part() $wrapper: HTMLDivElement;
100100
@Part() $canvas: HTMLCanvasElement;
101+
@Part() $selection: SVGSVGElement;
102+
@Part() $selectionPath: SVGPathElement;
101103

102104
// Internal State
103105
#inputStamp: number[][] = [];
@@ -111,6 +113,7 @@ export default class PgInputPixelEditor extends HTMLElement {
111113
#y: number = -1;
112114
#layer: number = 0;
113115
#layers: Layer[] = [];
116+
#selection = new Set<string>(); // 'x,y'
114117
#isCtrl: boolean = false;
115118
#isShift: boolean = false;
116119
#isAlt: boolean = false;
@@ -255,6 +258,9 @@ export default class PgInputPixelEditor extends HTMLElement {
255258
this.dispatchEvent(new CustomEvent('change', {
256259
detail: { export: this.#export }
257260
}));
261+
// temporary test
262+
this.$selection.setAttribute('viewBox', `0 0 ${this.width * this.size} ${this.height * this.size}`)
263+
this.$selectionPath.setAttribute('d', bitmaskToPath(this.#data[0], { scale: this.size }));
258264
};
259265

260266
#delayTimerId: number = 0;
@@ -946,6 +952,18 @@ export default class PgInputPixelEditor extends HTMLElement {
946952
this.#clearStampPreview();
947953
}
948954

955+
inputModeSelectRectangle() {
956+
this.#inputMode = InputMode.SelectRectangle;
957+
}
958+
959+
inputModeSelectEllipse() {
960+
this.#inputMode = InputMode.SelectEllipse;
961+
}
962+
963+
inputModeSelectLasso() {
964+
this.#inputMode = InputMode.SelectLasso;
965+
}
966+
949967
inputModePixel() {
950968
this.#inputMode = InputMode.Pixel;
951969
}

src/pg/inputPixelEditor/utils/inputMode.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
export const enum InputMode {
2+
SelectRectangle,
3+
SelectEllipse,
4+
SelectLasso,
25
Stamp,
36
Pixel,
47
Line,

0 commit comments

Comments
 (0)