Skip to content

Commit

Permalink
mouse factor dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
ElyaConrad committed Apr 19, 2024
1 parent 86f0432 commit cc3e5f0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion zoompinch-vue/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "zoompinch",
"private": false,
"version": "0.0.29",
"version": "0.0.30",
"type": "module",
"files": [
"package.json",
Expand Down
20 changes: 16 additions & 4 deletions zoompinch-vue/src/controllers/wheel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ export function detectTrackpad(event: WheelEvent) {
}
return isTrackpad;
}
export function isMultipleOf(n: number, multiples: number[]) {
const factor = multiples.find((m) => n % m === 0);
if (factor) {
return n / factor;
} else {
return n;
}
}

export function useWheel({
scale,
Expand All @@ -36,11 +44,15 @@ export function useWheel({
}) {
function handleWheel(event: WheelEvent) {
let { deltaX, deltaY, ctrlKey } = event;
if (Math.abs(deltaX) === 100 || Math.abs(deltaY) === 200) {
deltaX = deltaX / 25;
const mouseMultiples = [120, 100];
const mouseFactor = 4;
if (Math.abs(deltaX)) {
}
if (isMultipleOf(deltaX, mouseMultiples)) {
deltaX = deltaX / ((100 / mouseFactor) * isMultipleOf(deltaX, mouseMultiples));
}
if (Math.abs(deltaY) === 100 || Math.abs(deltaY) === 200) {
deltaY = deltaY / 25;
if (isMultipleOf(deltaY, mouseMultiples)) {
deltaY = deltaY / ((100 / mouseFactor) * isMultipleOf(deltaY, mouseMultiples));
}
const currScale = scale.value;
if (ctrlKey) {
Expand Down

0 comments on commit cc3e5f0

Please sign in to comment.