@@ -637,22 +638,23 @@
}
function setupTouchEvents() {
- let touchStartX = 0;
- let touchStartY = 0;
-
canvas.addEventListener('touchstart', async (e) => {
if (!canvasInitialized) return;
e.preventDefault();
- const touch = e.touches[0];
- const rect = canvas.getBoundingClientRect();
- touchStartX = touch.clientX - rect.left;
- touchStartY = touch.clientY - rect.top;
-
- try {
- await connection.invoke("HandleTouchDown", touch.identifier, touchStartX, touchStartY);
- } catch (err) {
- console.error("觸摸開始處理失敗:", err);
+ // 處理所有觸控點,支援多點觸控
+ for (let i = 0; i < e.changedTouches.length; i++) {
+ const touch = e.changedTouches[i];
+ const rect = canvas.getBoundingClientRect();
+ const x = touch.clientX - rect.left;
+ const y = touch.clientY - rect.top;
+
+ try {
+ await connection.invoke("HandleTouchDown", touch.identifier, x, y);
+ console.log(`觸控開始 [${touch.identifier}]: (${x}, ${y})`);
+ } catch (err) {
+ console.error("觸摸開始處理失敗:", err);
+ }
}
});
@@ -660,15 +662,23 @@
if (!canvasInitialized) return;
e.preventDefault();
- const touch = e.touches[0];
- const rect = canvas.getBoundingClientRect();
- const x = touch.clientX - rect.left;
- const y = touch.clientY - rect.top;
+ // 處理所有移動的觸控點,支援捏合縮放和旋轉手勢
+ for (let i = 0; i < e.changedTouches.length; i++) {
+ const touch = e.changedTouches[i];
+ const rect = canvas.getBoundingClientRect();
+ const x = touch.clientX - rect.left;
+ const y = touch.clientY - rect.top;
+
+ try {
+ await connection.invoke("HandleTouchMove", touch.identifier, x, y);
+ } catch (err) {
+ console.error("觸摸移動處理失敗:", err);
+ }
+ }
- try {
- await connection.invoke("HandleTouchMove", touch.identifier, x, y);
- } catch (err) {
- console.error("觸摸移動處理失敗:", err);
+ // 顯示當前觸控點數量(用於調試)
+ if (e.touches.length >= 2) {
+ console.log(`多點觸控中 - 觸控點數量: ${e.touches.length}`);
}
});
@@ -676,12 +686,34 @@
if (!canvasInitialized) return;
e.preventDefault();
- const touch = e.changedTouches[0];
+ // 處理所有結束的觸控點
+ for (let i = 0; i < e.changedTouches.length; i++) {
+ const touch = e.changedTouches[i];
+
+ try {
+ await connection.invoke("HandleTouchUp", touch.identifier);
+ console.log(`觸控結束 [${touch.identifier}]`);
+ } catch (err) {
+ console.error("觸摸結束處理失敗:", err);
+ }
+ }
+ });
+
+ // 添加觸控取消事件處理
+ canvas.addEventListener('touchcancel', async (e) => {
+ if (!canvasInitialized) return;
- try {
- await connection.invoke("HandleTouchUp", touch.identifier);
- } catch (err) {
- console.error("觸摸結束處理失敗:", err);
+ e.preventDefault();
+ // 處理所有取消的觸控點
+ for (let i = 0; i < e.changedTouches.length; i++) {
+ const touch = e.changedTouches[i];
+
+ try {
+ await connection.invoke("HandleTouchUp", touch.identifier);
+ console.log(`觸控取消 [${touch.identifier}]`);
+ } catch (err) {
+ console.error("觸摸取消處理失敗:", err);
+ }
}
});
}
diff --git a/wwwroot/demo-vue-inline.html b/wwwroot/demo-vue-inline.html
deleted file mode 100644
index cc484c7..0000000
--- a/wwwroot/demo-vue-inline.html
+++ /dev/null
@@ -1,325 +0,0 @@
-
-
-
-
-
-
Vue.js Inline Rendering Canvas Demo
-
-
-
-
-
-
-
-
Vue.js 內嵌式渲染畫布示範
-
-
- {{ isConnected ? '已連接' : '未連接' }}
- - Session: {{ sessionId }}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
提示:使用滑鼠拖曳旋轉視圖,滾輪縮放,鍵盤 F1-F4 切換視圖
-
-
-
-
-
-
\ No newline at end of file
diff --git a/wwwroot/demo-vue.html b/wwwroot/demo-vue.html
index e08fde9..8527f0a 100644
--- a/wwwroot/demo-vue.html
+++ b/wwwroot/demo-vue.html
@@ -42,6 +42,13 @@
>
+