Spaces:
Runtime error
Runtime error
fix key reception sequence
Browse files- static/poseEditor.js +18 -10
static/poseEditor.js
CHANGED
@@ -126,12 +126,19 @@ function repairPerson(personIndex) {
|
|
126 |
// ドラッグ中の各キーが押されているかどうかのフラグ
|
127 |
var keyDownFlags = {};
|
128 |
// マウスカーソル
|
129 |
-
var mouseCursor = [
|
130 |
|
131 |
function cross(lhs, rhs) {return lhs[0] * rhs[1] - lhs[1] * rhs[0];}
|
132 |
function dot(lhs, rhs) {return lhs[0] * rhs[0] + lhs[1] * rhs[1];}
|
133 |
function directedAngleTo(lhs, rhs) {return Math.atan2(cross(lhs, rhs), dot(lhs, rhs));}
|
134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
function clearCanvas() {
|
136 |
var w = canvas.width;
|
137 |
var h = canvas.height;
|
@@ -377,13 +384,6 @@ function getCanvasPosition(event) {
|
|
377 |
return [x, y];
|
378 |
}
|
379 |
|
380 |
-
function isMouseOnCanvas(event) {
|
381 |
-
const rect = canvas.getBoundingClientRect();
|
382 |
-
const x = event.clientX - rect.left;
|
383 |
-
const y = event.clientY - rect.top;
|
384 |
-
return 0 <= x && x <= canvas.width && 0 <= y && y <= canvas.height;
|
385 |
-
}
|
386 |
-
|
387 |
function forEachMarkedNodes(fn) {
|
388 |
for (let i = 0; i < dragMarks.length; i++) {
|
389 |
for (let j = 0; j < dragMarks[i].length; j++) {
|
@@ -477,7 +477,6 @@ function handleMouseMove(event) {
|
|
477 |
forEachMarkedNodes((i, j, node) => {
|
478 |
const lp = latestPoseData[i][j];
|
479 |
const np = rotateAndProject(rotateX, lp, center, angle);
|
480 |
-
console.log(np);
|
481 |
node[0] = np[0];
|
482 |
node[1] = np[1];
|
483 |
});
|
@@ -509,10 +508,14 @@ function handleMouseUp(event) {
|
|
509 |
Redraw();
|
510 |
}
|
511 |
|
|
|
|
|
|
|
|
|
512 |
function ModifyDragRange(delta) { dragRange = Math.max(dragRangeDelta, Math.min(512, dragRange + delta)); }
|
513 |
|
514 |
document.addEventListener('wheel', function(event) {
|
515 |
-
if (!isMouseOnCanvas(
|
516 |
if (!event.altKey) {return;}
|
517 |
|
518 |
event.preventDefault();
|
@@ -525,6 +528,8 @@ document.addEventListener('wheel', function(event) {
|
|
525 |
}, {passive: false});
|
526 |
|
527 |
document.addEventListener("keydown", (event) => {
|
|
|
|
|
528 |
if (event.code == "BracketLeft") { ModifyDragRange(-dragRangeDelta); }
|
529 |
if (event.code == "BracketRight") { ModifyDragRange(dragRangeDelta); }
|
530 |
keyDownFlags[event.code] = true;
|
@@ -532,6 +537,8 @@ document.addEventListener("keydown", (event) => {
|
|
532 |
event.preventDefault();
|
533 |
});
|
534 |
document.addEventListener("keyup", (event) => {
|
|
|
|
|
535 |
keyDownFlags[event.code] = false;
|
536 |
if (event.ctrlKey && event.code == "KeyE") {
|
537 |
addPerson();
|
@@ -555,6 +562,7 @@ function initializeEditor() {
|
|
555 |
canvas.addEventListener('mousedown', handleMouseDown);
|
556 |
canvas.addEventListener('mousemove', handleMouseMove);
|
557 |
canvas.addEventListener('mouseup', handleMouseUp);
|
|
|
558 |
poseData = [];
|
559 |
clearHistory();
|
560 |
}
|
|
|
126 |
// ドラッグ中の各キーが押されているかどうかのフラグ
|
127 |
var keyDownFlags = {};
|
128 |
// マウスカーソル
|
129 |
+
var mouseCursor = [-1, -1];
|
130 |
|
131 |
function cross(lhs, rhs) {return lhs[0] * rhs[1] - lhs[1] * rhs[0];}
|
132 |
function dot(lhs, rhs) {return lhs[0] * rhs[0] + lhs[1] * rhs[1];}
|
133 |
function directedAngleTo(lhs, rhs) {return Math.atan2(cross(lhs, rhs), dot(lhs, rhs));}
|
134 |
|
135 |
+
function isMouseOnCanvas() {
|
136 |
+
// mouseCursorがcanvasの範囲内にあるかどうかを判定
|
137 |
+
var rect = canvas.getBoundingClientRect();
|
138 |
+
var f = 0 <= mouseCursor[0] && mouseCursor[0] <= rect.width && 0 <= mouseCursor[1] && mouseCursor[1] <= rect.height;
|
139 |
+
return f;
|
140 |
+
}
|
141 |
+
|
142 |
function clearCanvas() {
|
143 |
var w = canvas.width;
|
144 |
var h = canvas.height;
|
|
|
384 |
return [x, y];
|
385 |
}
|
386 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
387 |
function forEachMarkedNodes(fn) {
|
388 |
for (let i = 0; i < dragMarks.length; i++) {
|
389 |
for (let j = 0; j < dragMarks[i].length; j++) {
|
|
|
477 |
forEachMarkedNodes((i, j, node) => {
|
478 |
const lp = latestPoseData[i][j];
|
479 |
const np = rotateAndProject(rotateX, lp, center, angle);
|
|
|
480 |
node[0] = np[0];
|
481 |
node[1] = np[1];
|
482 |
});
|
|
|
508 |
Redraw();
|
509 |
}
|
510 |
|
511 |
+
function handleMouseLeave(event) {
|
512 |
+
mouseCursor = [-1,-1];
|
513 |
+
}
|
514 |
+
|
515 |
function ModifyDragRange(delta) { dragRange = Math.max(dragRangeDelta, Math.min(512, dragRange + delta)); }
|
516 |
|
517 |
document.addEventListener('wheel', function(event) {
|
518 |
+
if (!isMouseOnCanvas()) {return;}
|
519 |
if (!event.altKey) {return;}
|
520 |
|
521 |
event.preventDefault();
|
|
|
528 |
}, {passive: false});
|
529 |
|
530 |
document.addEventListener("keydown", (event) => {
|
531 |
+
if (!isMouseOnCanvas()) {return;}
|
532 |
+
|
533 |
if (event.code == "BracketLeft") { ModifyDragRange(-dragRangeDelta); }
|
534 |
if (event.code == "BracketRight") { ModifyDragRange(dragRangeDelta); }
|
535 |
keyDownFlags[event.code] = true;
|
|
|
537 |
event.preventDefault();
|
538 |
});
|
539 |
document.addEventListener("keyup", (event) => {
|
540 |
+
if (!isMouseOnCanvas()) {return;}
|
541 |
+
|
542 |
keyDownFlags[event.code] = false;
|
543 |
if (event.ctrlKey && event.code == "KeyE") {
|
544 |
addPerson();
|
|
|
562 |
canvas.addEventListener('mousedown', handleMouseDown);
|
563 |
canvas.addEventListener('mousemove', handleMouseMove);
|
564 |
canvas.addEventListener('mouseup', handleMouseUp);
|
565 |
+
canvas.addEventListener('mouseleave', handleMouseLeave);
|
566 |
poseData = [];
|
567 |
clearHistory();
|
568 |
}
|