From f5d73910cef412e11f6bc7f1e0ef4a21d8907c59 Mon Sep 17 00:00:00 2001 From: George Satellite Date: Wed, 15 Nov 2023 00:06:50 +0200 Subject: [PATCH 1/4] Inversion --- .../Generator/CanvasSection/CanvasSection.tsx | 27 ++++++++++++++++++- .../CanvasSection/utils/drawInvert.ts | 19 +++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/components/pages/Generator/CanvasSection/utils/drawInvert.ts diff --git a/src/components/pages/Generator/CanvasSection/CanvasSection.tsx b/src/components/pages/Generator/CanvasSection/CanvasSection.tsx index 043153a..82ed5b6 100644 --- a/src/components/pages/Generator/CanvasSection/CanvasSection.tsx +++ b/src/components/pages/Generator/CanvasSection/CanvasSection.tsx @@ -7,9 +7,10 @@ import {SectionTitle} from '../SectionTitle'; import {saveImage} from './utils/saveImage'; import {draw} from './utils/draw'; import {Switch} from '@/components/ui/Switch'; +import {getCanvasDimensions} from './utils/getCanvasDimensions'; import {clearCanvas} from './utils/clearCanvas'; import {drawNormal} from './utils/drawNormal'; -import {getCanvasDimensions} from './utils/getCanvasDimensions'; +import {drawInvert} from './utils/drawInvert'; export function CanvasSection() { const [is8k, setIs8k] = useState(false); @@ -129,6 +130,24 @@ export function CanvasSection() { setIs8k(is8k); }; + const invert = () => { + const renderTimeStartMs: number = performance.now(); + setIsRendering(true); + setIsNormalPreview(false); + + const updateCanvas = () => { + const ctx2d = getCtx2d(canvasRef); + drawInvert(ctx2d); + }; + + // Put a small timeout to allow the UI to update before canvas takes the main thread over + setTimeout(() => { + updateCanvas(); + setIsRendering(false); + setRenderTimeMs(performance.now() - renderTimeStartMs); + }, 20); + }; + const toggleNormalPreview = () => { const isNormalPreviewNew = !isNormalPreview; const renderTimeStartMs: number = performance.now(); @@ -197,6 +216,12 @@ export function CanvasSection() {
+