From 5b50b443f3fab28cc6b6cd3f63eb07a7988ffb89 Mon Sep 17 00:00:00 2001 From: Zylan Date: Sat, 26 Apr 2025 13:41:48 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=9C=AA=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E8=A7=A6=E6=91=B8=E4=BA=8B=E4=BB=B6=E5=A4=84=E7=90=86?= =?UTF-8?q?=E5=87=BD=E6=95=B0=EF=BC=8C=E7=AE=80=E5=8C=96=E7=94=BB=E5=B8=83?= =?UTF-8?q?=E4=BA=A4=E4=BA=92=E9=80=BB=E8=BE=91=EF=BC=8C=E6=8F=90=E5=8D=87?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=8F=AF=E8=AF=BB=E6=80=A7=E3=80=82=E5=90=8C?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E4=BF=9D=E7=95=99=E4=BA=86=E4=B8=BB=E8=A6=81?= =?UTF-8?q?=E7=9A=84=E4=BA=A4=E4=BA=92=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E4=BB=A5=E7=A1=AE=E4=BF=9D=E5=8A=9F=E8=83=BD=E5=AE=8C=E6=95=B4?= =?UTF-8?q?=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 | 52 +++--------------------------------------------- 1 file changed, 3 insertions(+), 49 deletions(-) diff --git a/src/app/page.tsx b/src/app/page.tsx index cc5f23b..ac81e66 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,6 +1,6 @@ 'use client'; -import React, { useState, useRef, ChangeEvent, DragEvent, TouchEvent, useEffect, useMemo } from 'react'; +import React, { useState, useRef, ChangeEvent, DragEvent, useEffect, useMemo } from 'react'; import Script from 'next/script'; import Image from 'next/image'; // 添加导入Image组件 import ColorPalette from '../components/ColorPalette'; @@ -152,8 +152,8 @@ export default function Home() { const fileInputRef = useRef(null); const longPressTimerRef = useRef(null); // ++ Re-add touch refs needed for tooltip logic ++ - const touchStartPosRef = useRef<{ x: number; y: number; pageX: number; pageY: number } | null>(null); - const touchMovedRef = useRef(false); + //const touchStartPosRef = useRef<{ x: number; y: number; pageX: number; pageY: number } | null>(null); + //const touchMovedRef = useRef(false); // ++ Add a ref for the main element ++ const mainRef = useRef(null); @@ -787,52 +787,6 @@ export default function Home() { // --- Tooltip Logic --- - // Function to calculate cell and update tooltip - const updateTooltip = (clientX: number, clientY: number, pageX: number, pageY: number) => { - const canvas = pixelatedCanvasRef.current; - if (!canvas || !mappedPixelData || !gridDimensions) { - setTooltipData(null); - return false; // Indicate failure or no action - } - - const rect = canvas.getBoundingClientRect(); - const scaleX = canvas.width / rect.width; - const scaleY = canvas.height / rect.height; - const canvasX = (clientX - rect.left) * scaleX; - const canvasY = (clientY - rect.top) * scaleY; - - const { N, M } = gridDimensions; - const cellWidthOutput = canvas.width / N; - const cellHeightOutput = canvas.height / M; - - const i = Math.floor(canvasX / cellWidthOutput); - const j = Math.floor(canvasY / cellHeightOutput); - - if (i >= 0 && i < N && j >= 0 && j < M) { - const cellData = mappedPixelData[j][i]; - if (cellData && !cellData.isExternal && cellData.key) { - setTooltipData({ - x: pageX, // Use page coordinates for positioning - y: pageY, - key: cellData.key, - color: cellData.color, - }); - return true; // Indicate success - } - } - - setTooltipData(null); // Hide if outside bounds or on background - return false; - }; - - // Clear any active long press timer and hide tooltip - const clearLongPress = () => { - if (longPressTimerRef.current) { - clearTimeout(longPressTimerRef.current); - longPressTimerRef.current = null; - } - }; - // --- Canvas Interaction --- // ++ Re-introduce the combined interaction handler ++