Only show shape preview if using a brush

main
kts of kettek 2024-02-15 11:19:40 -08:00
parent b20caab1d7
commit e0572c82a1
1 changed files with 17 additions and 16 deletions

View File

@ -25,6 +25,7 @@
let mousePixelX: number = 0 let mousePixelX: number = 0
let mousePixelY: number = 0 let mousePixelY: number = 0
export let currentTool: Tool
export let primaryColorIndex: number export let primaryColorIndex: number
export let secondaryColorIndex: number export let secondaryColorIndex: number
export let brushSize: number export let brushSize: number
@ -164,21 +165,23 @@
ctx.lineWidth = 1 ctx.lineWidth = 1
// Draw brush preview. // Draw brush preview.
let shape: PixelPosition[] if (currentTool instanceof BrushTool) {
if (brushType === 'square' || brushSize <= 2) { let shape: PixelPosition[]
// FIXME: This is daft to adjust +1,+1 for size 2 -- without this, the rect preview draws one pixel offset to the top-left, which is not the same as when the filled rect is placed. if (brushType === 'square' || brushSize <= 2) {
if (brushSize === 2) { // FIXME: This is daft to adjust +1,+1 for size 2 -- without this, the rect preview draws one pixel offset to the top-left, which is not the same as when the filled rect is placed.
shape = FilledSquare(1, 1, brushSize, 1) if (brushSize === 2) {
} else { shape = FilledSquare(1, 1, brushSize, 1)
shape = FilledSquare(0, 0, brushSize, 1) } else {
shape = FilledSquare(0, 0, brushSize, 1)
}
} else if (brushType === 'circle') {
shape = FilledCircle(0, 0, brushSize-2, 1)
}
let {r, g, b, a }= file.canvas.getPaletteAsRGBA(primaryColorIndex)
ctx.fillStyle = `rgba(${r},${g},${b},${a})`
for (let i = 0; i < shape.length; i++) {
ctx.fillRect(offsetX*zoom+(mousePixelX+shape[i].x)*zoom, offsetY*zoom+(mousePixelY+shape[i].y)*zoom, zoom, zoom)
} }
} else if (brushType === 'circle') {
shape = FilledCircle(0, 0, brushSize-2, 1)
}
let {r, g, b, a }= file.canvas.getPaletteAsRGBA(primaryColorIndex)
ctx.fillStyle = `rgba(${r},${g},${b},${a})`
for (let i = 0; i < shape.length; i++) {
ctx.fillRect(offsetX*zoom+(mousePixelX+shape[i].x)*zoom, offsetY*zoom+(mousePixelY+shape[i].y)*zoom, zoom, zoom)
} }
// Draw zoomed pixel-sized square where mouse is. // Draw zoomed pixel-sized square where mouse is.
if (zoom > 1) { if (zoom > 1) {
@ -206,8 +209,6 @@
} }
} }
export let currentTool: Tool
function canvasMousedown(node) { function canvasMousedown(node) {
let buttons: Set<number> = new Set() let buttons: Set<number> = new Set()
let x: number = 0 let x: number = 0