From fe6f3f11291e204661f1685325e4b666ac0fac8b Mon Sep 17 00:00:00 2001 From: zihanjian Date: Fri, 6 Jun 2025 14:41:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=94=BE=E5=A4=A7=E9=95=9C?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E5=8F=8A=E7=9B=B8=E5=85=B3=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E7=AE=A1=E7=90=86=EF=BC=8C=E4=BC=98=E5=8C=96=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E4=B8=8A=E8=89=B2=E6=A8=A1=E5=BC=8F=E4=B8=8B=E7=9A=84=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BA=A4=E4=BA=92=E4=BD=93=E9=AA=8C=EF=BC=8C=E6=8F=90?= =?UTF-8?q?=E5=8D=87=E7=95=8C=E9=9D=A2=E5=8F=8B=E5=A5=BD=E6=80=A7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/page.tsx | 96 +++++++ src/components/FloatingToolbar.tsx | 21 +- src/components/MagnifierSelectionOverlay.tsx | 264 +++++++++++++++++ src/components/MagnifierTool.tsx | 281 +++++++++++++++++++ 4 files changed, 661 insertions(+), 1 deletion(-) create mode 100644 src/components/MagnifierSelectionOverlay.tsx create mode 100644 src/components/MagnifierTool.tsx diff --git a/src/app/page.tsx b/src/app/page.tsx index f2af498..9b37dc3 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -87,6 +87,8 @@ import GridTooltip from '../components/GridTooltip'; import CustomPaletteEditor from '../components/CustomPaletteEditor'; import FloatingColorPalette from '../components/FloatingColorPalette'; import FloatingToolbar from '../components/FloatingToolbar'; +import MagnifierTool from '../components/MagnifierTool'; +import MagnifierSelectionOverlay from '../components/MagnifierSelectionOverlay'; import { loadPaletteSelections, savePaletteSelections, presetToSelections, PaletteSelections } from '../utils/localStorageUtils'; import { TRANSPARENT_KEY, transparentColorData } from '../utils/pixelEditingUtils'; @@ -161,6 +163,70 @@ export default function Home() { // 新增:悬浮调色盘状态 const [isFloatingPaletteOpen, setIsFloatingPaletteOpen] = useState(true); + // 新增:放大镜状态 + const [isMagnifierActive, setIsMagnifierActive] = useState(false); + const [magnifierSelectionArea, setMagnifierSelectionArea] = useState<{ + startRow: number; + startCol: number; + endRow: number; + endCol: number; + } | null>(null); + + // 放大镜切换处理函数 + const handleToggleMagnifier = () => { + setIsMagnifierActive(!isMagnifierActive); + }; + + // 放大镜像素编辑处理函数 + const handleMagnifierPixelEdit = (row: number, col: number, colorData: { key: string; color: string }) => { + if (!mappedPixelData) return; + + // 创建新的像素数据 + const newMappedPixelData = mappedPixelData.map((rowData, r) => + rowData.map((pixel, c) => { + if (r === row && c === col) { + return { + key: colorData.key, + color: colorData.color + } as MappedPixel; + } + return pixel; + }) + ); + + setMappedPixelData(newMappedPixelData); + + // 更新颜色统计 + if (colorCounts) { + const newColorCounts = { ...colorCounts }; + + // 减少原颜色的计数 + const oldPixel = mappedPixelData[row][col]; + if (newColorCounts[oldPixel.key]) { + newColorCounts[oldPixel.key].count--; + if (newColorCounts[oldPixel.key].count === 0) { + delete newColorCounts[oldPixel.key]; + } + } + + // 增加新颜色的计数 + if (newColorCounts[colorData.key]) { + newColorCounts[colorData.key].count++; + } else { + newColorCounts[colorData.key] = { + count: 1, + color: colorData.color + }; + } + + setColorCounts(newColorCounts); + + // 更新总计数 + const newTotal = Object.values(newColorCounts).reduce((sum, item) => sum + item.count, 0); + setTotalBeadCount(newTotal); + } + }; + const originalCanvasRef = useRef(null); const pixelatedCanvasRef = useRef(null); const fileInputRef = useRef(null); @@ -2074,7 +2140,10 @@ export default function Home() { step: 'select-source' }); setHighlightColorKey(null); + setIsMagnifierActive(false); }} + onToggleMagnifier={handleToggleMagnifier} + isMagnifierActive={isMagnifierActive} /> {/* 悬浮调色盘 */} @@ -2098,6 +2167,33 @@ export default function Home() { /> )} + {/* 放大镜工具 */} + {isManualColoringMode && ( + <> + setMagnifierSelectionArea(null)} + /> + + {/* 放大镜选择覆盖层 */} + + + )} + {/* Apply dark mode styles to the Footer */}