Skip to content

Commit

Permalink
get rid of mouseOffsets
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuahhh committed Dec 23, 2024
1 parent 48db1ed commit 989236d
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,15 +407,14 @@ async function main() {

let mouseX = 0;
let mouseY = 0;
let mouseOffsets: Vec2 = [0, 0];
let pointerType: string;
let mouseDown = false;
const updateMouse = (e: PointerEvent) => {
// clientX/Y works better than offsetX/Y for Chrome/Safari compatibility.
const dragOffset =
ix.type === "confirmed" && pointerType === "touch" ? 50 : 0;
mouseX = e.clientX + mouseOffsets[0];
mouseY = e.clientY + mouseOffsets[1] - dragOffset;
mouseX = e.clientX;
mouseY = e.clientY - dragOffset;
pointerType = e.pointerType;
};

Expand Down Expand Up @@ -1391,16 +1390,15 @@ async function main() {

const [cursorName, cursorStyle] =
shiftHeld || (ix.type === "confirmed" && ix.isPan)
? ["glove1", "url('./glove1.png'), pointer"]
? ["glove1", "url('./glove1.png') 7 3, pointer"]
: tool.type === "pointer"
? mouseDown
? ["glove2", "url('./glove2.png'), pointer"]
: ["glove3", "url('./glove3.png'), pointer"]
? ["glove2", "url('./glove2.png') 7 3, pointer"]
: ["glove3", "url('./glove3.png') 7 3, pointer"]
: tool.type === "dev-action"
? ["help", "help"]
: ["none", "none"];
c.style.cursor = cursorStyle;
mouseOffsets = cursorName.startsWith("glove") ? [7, 3] : [0, 0];

// draw background
ctxReal.fillStyle = patternAsfault;
Expand Down Expand Up @@ -2355,6 +2353,16 @@ async function main() {
}
}

// ix state debug
if (false) {
lyrAbove.do(() => {
lyrAbove.strokeStyle = "rgba(255, 0, 255, 1)";
lyrAbove.lineWidth = 4;
lyrAbove.fillStyle = "rgba(255, 0, 255, 1)";
lyrAbove.fillText(JSON.stringify(ix), 20, 20);
});
}

const endTime = performance.now();
if (false) {
renderOutlinedText(
Expand Down

0 comments on commit 989236d

Please sign in to comment.