|
3 | 3 | The `pg-input-pixel-editor` component is used to edit images. Tailored for pen or mouse input the editor can be used for various image editing tasks. |
4 | 4 |
|
5 | 5 | ```typescript |
6 | | -import '@pictogrammers/components/pgInputPixelEditor'; |
| 6 | +import '@pictogrammers/components/pg/inputPixelEditor'; |
7 | 7 | import PgInputPixelEditor, { |
8 | 8 | InputMode, |
9 | 9 | LayerType, |
10 | | -} from '@pictogrammers/components/pgInputPixelEditor'; |
| 10 | +} from '@pictogrammers/components/pg/inputPixelEditor'; |
11 | 11 | ``` |
12 | 12 |
|
13 | 13 | ```html |
@@ -50,8 +50,10 @@ See usage for each method below. |
50 | 50 | | `setData()` | - | Set layer data. | |
51 | 51 | | `setJson(json)` | - | Set JSON file. | |
52 | 52 | | `reset()` | - | Reset canvas and data. | |
53 | | -| `getExportCanvas()` | - | Get new canvas of export. | |
54 | | -| `await getExportPng(options, meta)` | - | Get image. | |
| 53 | +| `getExport()` | - | 2d array of pixel color indexes. Already calculated. | |
| 54 | +| `getExport(id)` | - | 2d array of pixel color indexes by export size. Minimal perf. | |
| 55 | +| `getExportCanvas()` | - | Get new prepopulated HTML canvas, ideal for advanced export screens. | |
| 56 | +| `await getExportPng(options, meta)` | - | Get png image with optional metadata. | |
55 | 57 | | `undo()` | - | Undo. | |
56 | 58 | | `hasUndo()` | - | Has undo | |
57 | 59 | | `hasRedo()` | - | Has redo | |
@@ -179,6 +181,11 @@ A complete JSON storage for a 10x10 image. |
179 | 181 | [{ "color": 2, "path": "M...Z" }] |
180 | 182 | ] |
181 | 183 | ], |
| 184 | + "grid": { |
| 185 | + "vertical": [], |
| 186 | + "horizontal": [] |
| 187 | + }, |
| 188 | + "exports": [], |
182 | 189 | "history": [] |
183 | 190 | } |
184 | 191 | ``` |
@@ -291,6 +298,85 @@ this.$input.addEventListener('reference', (e: any) => { |
291 | 298 | }); |
292 | 299 | ``` |
293 | 300 |
|
| 301 | +## Grid |
| 302 | + |
| 303 | +Grids seperate the frame into regions. The vertical and horizontal lines can be assigned a unique color often used in fonts. |
| 304 | + |
| 305 | +Grid lines on 0 or when equal or greater than to width/height are deleted. Applying a grid or resizing a frame will result in an error. Errors are handled by the consumer via the `error` event. `errorType: 'grid'`. |
| 306 | + |
| 307 | +```text |
| 308 | +0, 0 | 1, 0 | 2, 0 |
| 309 | +0, 1 | 1, 1 | 2, 1 |
| 310 | +0, 2 | 1, 2 | 2, 2 |
| 311 | +``` |
| 312 | + |
| 313 | +An example of a 9 segment grid for instance. Negative values offset from the right or bottom. |
| 314 | + |
| 315 | +> Note: When configuring exports all grid colors with `color: 0` will be visible. |
| 316 | +
|
| 317 | +```json |
| 318 | +{ |
| 319 | + "grid": [{ |
| 320 | + "vertical": [ |
| 321 | + { "start": 10, "color": 0 }, |
| 322 | + { "start": -10, "color": 0 } |
| 323 | + ], |
| 324 | + "horizontal": [ |
| 325 | + { "start": 10, "color": 0 }, |
| 326 | + { "start": -10, "color": 0 } |
| 327 | + ] |
| 328 | + }] |
| 329 | +} |
| 330 | +``` |
| 331 | + |
| 332 | +Specific grid colors are configured on the editor level and do not persist in this input component. In a font the first 5 colors are reserved for the below lines. |
| 333 | + |
| 334 | +- `1` - Ascender Line |
| 335 | +- `2` - Cap Line |
| 336 | +- `3` - Median / Mean line |
| 337 | +- `4` - Baseline |
| 338 | +- `5` - Decender Line |
| 339 | + |
| 340 | +### Repeating Grids |
| 341 | + |
| 342 | +A repeating grid is useful for tilesets and can be represented as. |
| 343 | +- `start` can be optional or null when `step` is defined. |
| 344 | +- `limit` can be optional or null. Null repeats for as many times as it can fit. |
| 345 | +- Similar to regular grids an error will throw if the first line is outside the `width` or `height`. |
| 346 | + |
| 347 | +```json |
| 348 | +{ "step": 10, "limit": null, "color": 0 }, |
| 349 | +{ "start": 5, "step": 10, "limit": 10, "color": 0 }, |
| 350 | +``` |
| 351 | + |
| 352 | +## Export |
| 353 | + |
| 354 | +Exports by default include the entire canvas, but can be resized to a specific pixel size or grid. The `x`, `y`, `width`, and `height` are optional. |
| 355 | + |
| 356 | +Use `getExport(id)` with a `id` value to get the data grid. This is ideal for export previews. |
| 357 | + |
| 358 | +```json |
| 359 | +{ |
| 360 | + "exports": [{ |
| 361 | + "id": "uuid", |
| 362 | + "unit": "pixel", |
| 363 | + "path": ["file.png"], |
| 364 | + "x": 0, |
| 365 | + "y": 0, |
| 366 | + "width": null, |
| 367 | + "height": null, |
| 368 | + }, { |
| 369 | + "id": "uuid", |
| 370 | + "unit": "grid", |
| 371 | + "path": ["folder", "bottomRight.png"], |
| 372 | + "x": 2, |
| 373 | + "y": 2, |
| 374 | + "width": 1, |
| 375 | + "height": 1, |
| 376 | + }] |
| 377 | +} |
| 378 | +``` |
| 379 | + |
294 | 380 | ## History |
295 | 381 |
|
296 | 382 | The history list contains every change made to the canvas. All feature insert an entry into history. Pens and pattern tools will group as to cut down history entries. |
|
0 commit comments