From 32beb3a221dcd72bb6a010a3f866376aca126373 Mon Sep 17 00:00:00 2001 From: kts of kettek Date: Fri, 16 Feb 2024 22:30:54 -0800 Subject: [PATCH] Add shift and control fields to ptr; use for selection add/remove --- frontend/src/sections/Editor2D.svelte | 12 ++++++------ frontend/src/types/tools.ts | 12 +++++++++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/frontend/src/sections/Editor2D.svelte b/frontend/src/sections/Editor2D.svelte index 6691f59..cdf2b5b 100644 --- a/frontend/src/sections/Editor2D.svelte +++ b/frontend/src/sections/Editor2D.svelte @@ -251,15 +251,15 @@ if (e.button === 0) { if (currentTool instanceof BrushTool) { - currentTool.pointerDown({file, brushSize, brushType, colorIndex: primaryColorIndex}, {x: mousePixelX, y: mousePixelY, id: e.button }) + currentTool.pointerDown({file, brushSize, brushType, colorIndex: primaryColorIndex}, {x: mousePixelX, y: mousePixelY, id: e.button, shift: e.shiftKey, control: e.ctrlKey }) } else if (currentTool instanceof EraserTool) { - currentTool.pointerDown({file, brushSize, brushType}, {x: mousePixelX, y: mousePixelY, id: e.button }) + currentTool.pointerDown({file, brushSize, brushType}, {x: mousePixelX, y: mousePixelY, id: e.button, shift: e.shiftKey, control: e.ctrlKey }) } else if (currentTool instanceof FillTool) { - currentTool.pointerDown({file, colorIndex: primaryColorIndex}, {x: mousePixelX, y: mousePixelY, id: e.button }) + currentTool.pointerDown({file, colorIndex: primaryColorIndex}, {x: mousePixelX, y: mousePixelY, id: e.button, shift: e.shiftKey, control: e.ctrlKey }) } else if (currentTool instanceof PickerTool) { - currentTool.pointerDown({file, setColorIndex: index=>primaryColorIndex=index}, {x: mousePixelX, y: mousePixelY, id: e.button }) + currentTool.pointerDown({file, setColorIndex: index=>primaryColorIndex=index}, {x: mousePixelX, y: mousePixelY, id: e.button, shift: e.shiftKey, control: e.ctrlKey }) } else { - currentTool.pointerDown({file}, {x: mousePixelX, y: mousePixelY, id: e.button }) + currentTool.pointerDown({file}, {x: mousePixelX, y: mousePixelY, id: e.button, shift: e.shiftKey, control: e.ctrlKey }) } } }) @@ -342,7 +342,7 @@ if (e.button === 0) { if (currentTool.isActive()) { - currentTool.pointerUp({file}, {x: mousePixelX, y: mousePixelY, id: 0 }) + currentTool.pointerUp({file}, {x: mousePixelX, y: mousePixelY, id: 0, shift: e.shiftKey, control: e.ctrlKey }) } } diff --git a/frontend/src/types/tools.ts b/frontend/src/types/tools.ts index b54c70a..4c3d062 100644 --- a/frontend/src/types/tools.ts +++ b/frontend/src/types/tools.ts @@ -9,6 +9,8 @@ interface Pointer { x: number y: number id: number + shift?: boolean + control?: boolean } export type BrushType = "circle" | "square" @@ -256,11 +258,19 @@ export class SelectionTool implements Tool { return } + let value = true + if (!ptr.shift && !ptr.control) { + ctx.file.selection.clear() + } + if (ptr.control) { + value = false + } + let {x: startX, y: startY, width, height} = this.getArea() for (let x = startX; x <= startX+width-1; x++) { for (let y = startY; y <= startY+height-1; y++) { - ctx.file.selection.setPixel(x, y, true) + ctx.file.selection.setPixel(x, y, value) } }