Skip to content

Commit

Permalink
Merge pull request #5 from shrutivarade/main
Browse files Browse the repository at this point in the history
add changes for canvas ratio
  • Loading branch information
haehn authored Nov 17, 2023
2 parents 15a9b52 + f29bb82 commit 1238aa6
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/frameworks/niivue.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class NiiVue extends Framework {
}

// replace nv canvas with new one
// console.log('aaa',originalcanvas.clientWidth+'px');
// originalcanvas.parentNode.replaceChild(newcanvas, originalcanvas);
newcanvas.style.width = originalcanvas.clientWidth+'px';
newcanvas.style.height = originalcanvas.clientHeight+'px';
originalcanvas.parentNode.replaceChild(newcanvas, originalcanvas);
Expand Down Expand Up @@ -186,13 +186,13 @@ export class NiiVue extends Framework {

let canvas = this.instance.canvas;


canvas.addEventListener('mousedown', function (e) {
this.isMouseDown = true;

var rect = e.currentTarget.getBoundingClientRect(),
offsetX = e.clientX - rect.left,
offsetY = e.clientY - rect.top;
offsetX = e.clientX * window.devicePixelRatio - rect.left * window.devicePixelRatio,
offsetY = e.clientY * window.devicePixelRatio - rect.top * window.devicePixelRatio;

this.x1 = offsetX;
this.y1 = offsetY;
Expand All @@ -202,8 +202,8 @@ export class NiiVue extends Framework {
if (this.isMouseDown) {

var rect = e.currentTarget.getBoundingClientRect(),
offsetX = e.clientX - rect.left,
offsetY = e.clientY - rect.top;
offsetX = e.clientX * window.devicePixelRatio - rect.left * window.devicePixelRatio,
offsetY = e.clientY * window.devicePixelRatio - rect.top * window.devicePixelRatio;

this.x2 = offsetX;
this.y2 = offsetY;
Expand All @@ -214,8 +214,8 @@ export class NiiVue extends Framework {

canvas.addEventListener('mouseup', function (e) {
var rect = e.currentTarget.getBoundingClientRect(),
offsetX = e.clientX - rect.left,
offsetY = e.clientY - rect.top;
offsetX = e.clientX * window.devicePixelRatio - rect.left * window.devicePixelRatio,
offsetY = e.clientY * window.devicePixelRatio - rect.top * window.devicePixelRatio;

this.x2 = offsetX;
this.y2 = offsetY;
Expand Down

0 comments on commit 1238aa6

Please sign in to comment.