Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #7400 - Issue with mouseX and mouseY when using a CSS border #7463

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions test/manual-test-examples/learningprocessing/chp3/example_3_2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@

// Example 3-2: mouseX and mouseY

let offsetX, offsetY; // Declare variables globally

function setup() {
createCanvas(200, 200);
const rect = canvas.elt.getBoundingClientRect(); // Get canvas position
offsetX = rect.left + window.scrollX;
offsetY = rect.top + window.scrollY;
}

function draw() {
Expand All @@ -19,7 +24,9 @@ function draw() {
fill(175);
rectMode(CENTER);

// mouseX is a keyword that the sketch replaces with the horizontal position of the mouse.
// mouseY is a keyword that the sketch replaces with the vertical position of the mouse.
rect(mouseX, mouseY, 50, 50);
// Corrected mouseX and mouseY for canvas offset
const correctedMouseX = mouseX - offsetX;
const correctedMouseY = mouseY - offsetY;

rect(correctedMouseX, correctedMouseY, 50, 50); // Adjust size as needed
}