diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte index e08d422..dd784bb 100644 --- a/frontend/src/App.svelte +++ b/frontend/src/App.svelte @@ -9,7 +9,7 @@ import { LoadedFile, PixelsPlaceUndoable, SelectionClearUndoable, SelectionSetUndoable } from './types/file' import "carbon-components-svelte/css/all.css" - import { Tabs, Tab, TabContent, Theme, Button, Modal, Truncate, ButtonSet, NumberInput } from "carbon-components-svelte" + import { Tabs, Tab, TabContent, Theme, Button, Modal, Truncate, ButtonSet, NumberInput, Dropdown } from "carbon-components-svelte" import { ComposedModal } from "carbon-components-svelte" import { OverflowMenu, OverflowMenuItem } from "carbon-components-svelte" @@ -44,6 +44,23 @@ let alpha: number = 0 let refreshPalette = {} + let fakePalette: Uint32Array | undefined = undefined + let selectedPaletteID: number = 0 + $: { + if (selectedPaletteID === 0) { + fakePalette = undefined + } else if (selectedPaletteID === 1) { + fakePalette = new Uint32Array([ + 0xFFE0F8D0, 0xFF88C070, 0xFF346856, 0xFF081820, + 0xFFF8F8F8, 0xFFC0C0C0, 0xFF606060, 0xFF202020, + 0xFFF8D8F8, 0xFFA800A8, 0xFF503050, 0xFF200020, + 0xFFF8B8F8, 0xFFA800A8, 0xFF503050, 0xFF200020, + ]) + } + focusedFile?.canvas.setFakePalette(fakePalette) + focusedFile?.canvas.refreshImageData() + focusedFile?.canvas.refreshCanvas() + } // Oh no, what are you doing, step palette~ function stepPalette(step: number, primary: boolean) { @@ -189,7 +206,15 @@
- + "}, + { id: 1, text: "test palette"}, + ]} + /> +
refreshPalette={}} /> @@ -302,7 +327,7 @@ } .left { display: grid; - grid-template-rows: minmax(0, 1fr) auto; + grid-template-rows: auto minmax(0, 1fr) auto; } .toolbar { display: flex; diff --git a/frontend/src/sections/Palette.svelte b/frontend/src/sections/Palette.svelte index bbc7a97..2ec39ef 100644 --- a/frontend/src/sections/Palette.svelte +++ b/frontend/src/sections/Palette.svelte @@ -35,6 +35,16 @@ lastFile = file } } + + export let fakePalette: Uint32Array | undefined + let palette: Uint32Array | undefined[] + $: { + if (fakePalette) { + palette = fakePalette + } else { + palette = file ? file.canvas.palette : [] + } + } function paletteClick(event: MouseEvent) { const target = event.target as HTMLSpanElement @@ -48,16 +58,15 @@ } } function handleWheel(event: WheelEvent) { - if (!file) return if (event.deltaX < 0) { - secondaryColorIndex = (secondaryColorIndex - 1 + file.canvas.palette.length) % file.canvas.palette.length + secondaryColorIndex = (secondaryColorIndex - 1 + palette.length) % palette.length } else if (event.deltaX > 0) { - secondaryColorIndex = (secondaryColorIndex + 1) % file.canvas.palette.length + secondaryColorIndex = (secondaryColorIndex + 1) % palette.length } if (event.deltaY < 0) { - primaryColorIndex = (primaryColorIndex - 1 + file.canvas.palette.length) % file.canvas.palette.length + primaryColorIndex = (primaryColorIndex - 1 + palette.length) % palette.length } else if (event.deltaY > 0) { - primaryColorIndex = (primaryColorIndex + 1) % file.canvas.palette.length + primaryColorIndex = (primaryColorIndex + 1) % palette.length } } @@ -118,24 +127,22 @@
- {#if file} - {#each file.canvas.palette as palette, paletteIndex} - {#if draggingIndex !== -1 && (paletteIndex === hoveringIndex || (paletteIndex === hoveringIndex-1 && paletteIndex === file.canvas.palette.length-2))} - - - - {draggingIndex} - - {/if} - {#if paletteIndex !== draggingIndex} - - - - {paletteIndex} - - {/if} - {/each} - {/if} + {#each palette as swatch, swatchIndex} + {#if draggingIndex !== -1 && (swatchIndex === hoveringIndex || (swatchIndex === hoveringIndex-1 && swatchIndex === palette.length-1))} + + + + {draggingIndex} + + {/if} + {#if swatchIndex !== draggingIndex} + + + + {swatchIndex} + + {/if} + {/each}