diff --git a/app/(app)/(published)/lish/[did]/[publication]/[rkey]/Blocks/StaticDrawingBlock.tsx b/app/(app)/(published)/lish/[did]/[publication]/[rkey]/Blocks/StaticDrawingBlock.tsx index 9a80f312..e642b45d 100644 --- a/app/(app)/(published)/lish/[did]/[publication]/[rkey]/Blocks/StaticDrawingBlock.tsx +++ b/app/(app)/(published)/lish/[did]/[publication]/[rkey]/Blocks/StaticDrawingBlock.tsx @@ -11,6 +11,7 @@ export const StaticDrawingBlock = ({ ({ id: String(i), stroke }))} + fills={block.fills?.map((fill, i) => ({ id: String(i), fill }))} /> ); diff --git a/components/Blocks/DrawingBlock/CanvasInkLayer.tsx b/components/Blocks/DrawingBlock/CanvasInkLayer.tsx index 7e38cd56..e8234728 100644 --- a/components/Blocks/DrawingBlock/CanvasInkLayer.tsx +++ b/components/Blocks/DrawingBlock/CanvasInkLayer.tsx @@ -23,6 +23,7 @@ import { DrawingState, commitStroke, eraseStrokes, + fillAt, readDrawing, stopInk, } from "./inkMutations"; @@ -39,6 +40,9 @@ const ERASER_CURSOR = `url("data:image/svg+xml,${encodeURIComponent( type Gesture = { pointerId: number; erase: boolean; + // Fills where the pointer went down once it lifts, so a pinch's first + // finger can still cancel it. + fill: boolean; // Canvas px, flattened x, y, pressure (0-1) triples. points: number[]; simulatePressure: boolean; @@ -124,6 +128,7 @@ export function CanvasInkLayer(props: { pageID: string }) { if (events.length === 0) events = [e.nativeEvent]; for (let ev of events) { let p = toCanvas(ev); + if (g.fill && g.points.length > 0) break; if (g.erase) { eraseAt(g, p); continue; @@ -138,7 +143,7 @@ export function CanvasInkLayer(props: { pageID: string }) { : g.points[g.points.length - 1] ?? 0.5; g.points.push(p.x, p.y, pressure); } - if (!g.erase) setLive(liveStroke(g)); + if (!g.erase && !g.fill) setLive(liveStroke(g)); }; let liveStroke = (g: Gesture): InkStroke => ({ @@ -168,6 +173,14 @@ export function CanvasInkLayer(props: { pageID: string }) { }).then(() => useInkSession.getState().setErasing([])); return; } + if (g.fill) { + fillAt(rep, undoManager, { + page: props.pageID, + point: { x: g.points[0], y: g.points[1] }, + color, + }); + return; + } let key = pendingKey.current++; setLive(null); setPending((p) => [...p, { key, stroke: liveStroke(g) }]); @@ -217,6 +230,7 @@ export function CanvasInkLayer(props: { pageID: string }) { gesture.current = { pointerId: e.pointerId, erase, + fill: tool === "fill" && !erase, points: [], simulatePressure: e.pointerType !== "pen", drawing: diff --git a/components/Blocks/DrawingBlock/InkSvg.tsx b/components/Blocks/DrawingBlock/InkSvg.tsx index 8dad1617..1068d70b 100644 --- a/components/Blocks/DrawingBlock/InkSvg.tsx +++ b/components/Blocks/DrawingBlock/InkSvg.tsx @@ -1,5 +1,12 @@ import { memo } from "react"; -import { InkStroke, ViewBox, inkColor, inkStrokePath } from "./ink"; +import { + InkFill, + InkStroke, + ViewBox, + inkColor, + inkFillPath, + inkStrokePath, +} from "./ink"; // Fills its container's width at the view box's aspect ratio. Strokes past // the view box still show: a collaborator's stroke can land before the view @@ -7,6 +14,8 @@ import { InkStroke, ViewBox, inkColor, inkStrokePath } from "./ink"; export function InkSvg(props: { viewBox: ViewBox; strokes: { id: string; stroke: InkStroke }[]; + // In paint order, beneath the strokes. + fills?: { id: string; fill: InkFill }[]; className?: string; }) { let { x, y, width, height } = props.viewBox; @@ -17,6 +26,13 @@ export function InkSvg(props: { className={`block w-full h-auto ${props.className || ""}`} style={{ aspectRatio: `${width} / ${height}` }} > + {props.fills?.map((f) => ( + + ))} {props.strokes.map((s) => ( ))} diff --git a/components/Blocks/DrawingBlock/InkToolbar.tsx b/components/Blocks/DrawingBlock/InkToolbar.tsx index 5c969825..716c858f 100644 --- a/components/Blocks/DrawingBlock/InkToolbar.tsx +++ b/components/Blocks/DrawingBlock/InkToolbar.tsx @@ -13,6 +13,7 @@ import { thumbStyle } from "components/ThemeManager/Pickers/ColorPicker"; import { Popover } from "components/Popover"; import { Separator } from "components/Layout"; import { EraserSmall } from "components/Icons/EraserSmall"; +import { PaintBucketSmall } from "components/Icons/PaintBucketSmall"; import { PaintSmall } from "components/Icons/PaintSmall"; import { CloseTiny } from "components/Icons/CloseTiny"; import { INK_COLORS, INK_SIZES, inkColor } from "./ink"; @@ -121,6 +122,15 @@ export function InkToolbar(props: { pageID: string }) { ); })} + +