Skip to content

Commit

Permalink
refactor: use better mapping logic in _setupBlocksContainerEvents (#4039
Browse files Browse the repository at this point in the history
)

* reduce duplication

* revert a rookie error
  • Loading branch information
retrogtx authored Oct 27, 2024
1 parent 4b29d1f commit b5be318
Showing 1 changed file with 21 additions and 38 deletions.
59 changes: 21 additions & 38 deletions js/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -1756,25 +1756,17 @@ class Activity {
*/
this._setupBlocksContainerEvents = () => {
const moving = false;
let lastCoords = {
x: 0,
y: 0,
delta: 0
};

const that = this;
let lastCoords = { x: 0, y: 0, delta: 0 };

/**
* Closes any open menus and labels.
*/
const closeAnyOpenMenusAndLabels = () => {
if (docById("wheelDiv") !== null) docById("wheelDiv").style.display = "none";
if (docById("contextWheelDiv") !== null)
docById("contextWheelDiv").style.display = "none";
if (docById("helpfulWheelDiv") !== null)
docById("helpfulWheelDiv").style.display = "none";
if (docById("textLabel") !== null) docById("textLabel").style.display = "none";
if (docById("numberLabel") !== null) docById("numberLabel").style.display = "none";
['wheelDiv', 'contextWheelDiv', 'helpfulWheelDiv', 'textLabel', 'numberLabel'].forEach(id => {
const elem = docById(id);
if (elem) elem.style.display = 'none';
});
};

/**
Expand Down Expand Up @@ -1898,30 +1890,23 @@ class Activity {
* @param {WheelEvent} event - The wheel event object.
*/
const __wheelHandler = (event) => {
const data = normalizeWheel(event); // normalize over different browsers
const data = normalizeWheel(event);
const delY = data.pixelY;
const delX = data.pixelX;

//Ctrl+MouseWheel Zoom functionality

if (event.ctrlKey) {
event.preventDefault(); // Prevent default scrolling behavior

if (delY < 0 && doLargerBlocks(this));//Zoom IN
if (delY >= 0 && doSmallerBlocks(this));//Zoom Out
}
if (delY !== 0 && event.axis === event.VERTICAL_AXIS) {
closeAnyOpenMenusAndLabels(); // closes all wheelnavs when scrolling .
event.preventDefault();
delY < 0 ? doLargerBlocks(that) : doSmallerBlocks(that);
} else if (delY !== 0 && event.axis === event.VERTICAL_AXIS) {
closeAnyOpenMenusAndLabels();
that.blocksContainer.y -= delY;
}
// horizontal scroll
if (that.scrollBlockContainer) {
if (delX !== 0 && event.axis === event.HORIZONTAL_AXIS) {
closeAnyOpenMenusAndLabels();
that.blocksContainer.x -= delX;
}
} else if (that.scrollBlockContainer && delX !== 0 && event.axis === event.HORIZONTAL_AXIS) {
closeAnyOpenMenusAndLabels();
that.blocksContainer.x -= delX;
} else {
event.preventDefault();
}

that.refreshCanvas();
};

Expand Down Expand Up @@ -1973,12 +1958,10 @@ class Activity {

that.stage.removeAllEventListeners("stagemousemove");
that.stage.on("stagemousemove", (event) => {
that.stageX = event.stageX;
that.stageY = event.stageY;

if (!moving) {
return;
}
that.stageX = moveEvent.stageX;
that.stageY = moveEvent.stageY;

if (!that.moving) return;

// if we are moving the block container, deselect the active block.
// Deselect active block if moving the block container
Expand Down Expand Up @@ -4182,7 +4165,7 @@ class Activity {
let st = sched[j].start;
let ed= sched[j].end;
let dur = ed - st;
var temp = this.getClosestStandardNoteValue(dur * 3 / 8);
let temp = this.getClosestStandardNoteValue(dur * 3 / 8);
shortestNoteDenominator=Math.max(shortestNoteDenominator,temp[1]);
}

Expand Down Expand Up @@ -4224,7 +4207,7 @@ class Activity {
}
return ar;
};
var obj = this.getClosestStandardNoteValue(duration * 3 / 8);
let obj = this.getClosestStandardNoteValue(duration * 3 / 8);
// let scalingFactor=1;
// if(shortestNoteDenominator>32)
// scalingFactor=shortestNoteDenominator/32;
Expand Down

0 comments on commit b5be318

Please sign in to comment.