diff --git a/ui/b/app.js b/ui/b/app.js index dc2320c9..3095a385 100644 --- a/ui/b/app.js +++ b/ui/b/app.js @@ -5,44 +5,15 @@ * Global application instance for Anklang. * *zmovehooks* * : An array of callbacks to be notified on pointer moves. - * *zmove (event)* - * : Trigger the callback list `zmovehooks`, passing `event` along. This is useful to get debounced + * *zmove()* + * : Trigger the callback list `zmovehooks`. This is useful to get debounced * notifications for pointer movements, including 0-distance moves after significant UI changes. */ import VueComponents from '../all-components.js'; import ShellClass from '../b/shell.js'; import * as Util from '../util.js'; - -// == zmove() == -class ZMove { - /** @type {Event} */ - static last_event; - static - zmove (ev) { - if (ev && ev.screenX && ev.screenY && - ev.timeStamp > (ZMove.last_event?.timeStamp || 0)) - ZMove.last_event = ev; - ZMove.trigger(); - } - static - trigger_hooks() { - if (ZMove.last_event) - for (const hook of ZMove.zmovehooks) - hook (ZMove.last_event); - } - static trigger = Util.debounce (ZMove.trigger_hooks); - static zmovehooks = []; - static zmoves_add (cb) { - ZMove.zmovehooks.push (cb); - return _ => { - Util.array_remove (ZMove.zmovehooks, cb); - }; - } -} -document.addEventListener ("pointerdown", ZMove.zmove, { capture: true, passive: true }); -document.addEventListener ("pointermove", ZMove.zmove, { capture: true, passive: true }); -document.addEventListener ("pointerup", ZMove.zmove, { capture: true, passive: true }); +import * as Mouse from '../mouse.js'; // == App == export class AppClass { @@ -191,9 +162,9 @@ export class AppClass { }; return this.shell.async_modal_dialog (dialog_setup); } - zmoves_add = ZMove.zmoves_add; - zmove = ZMove.zmove; - zmove_last = () => ZMove.last_event; + zmoves_add = Mouse.zmove_add; + zmove = Mouse.zmove_trigger; + zmove_last = Mouse.zmove_last; } // == addvc == diff --git a/ui/b/knob.js b/ui/b/knob.js index 0bd1b12e..3731a16f 100644 --- a/ui/b/knob.js +++ b/ui/b/knob.js @@ -34,6 +34,7 @@ import { LitComponent, html, JsExtract, docs } from '../little.js'; import * as Util from "../util.js"; +import * as Mouse from '../mouse.js'; // == STYLE == JsExtract.scss` @@ -64,7 +65,7 @@ b-knob { // == HTML == const HTML = (t,d) => html` -
@@ -172,9 +173,9 @@ class BKnob extends LitComponent { this.reposition(); } } - wheel (event) + wheel_event (event) { - const d = Util.wheel_delta (event); + const d = Mouse.wheel_delta (event); if (this[SPIN_DRAG]?.captureid === undefined && // not dragging ((!this.hscroll && d.x != 0) || (!this.vscroll && d.y != 0))) diff --git a/ui/b/pianoroll.js b/ui/b/pianoroll.js index 01f89d9c..97da25e2 100644 --- a/ui/b/pianoroll.js +++ b/ui/b/pianoroll.js @@ -12,6 +12,8 @@ import { LitComponent, ref, html, JsExtract, docs } from '../little.js'; import * as PianoCtrl from "./piano-ctrl.js"; import * as Util from '../util.js'; +import { clamp } from '../util.js'; +import * as Mouse from '../mouse.js'; const floor = Math.floor, round = Math.round; // == STYLE == @@ -77,7 +79,7 @@ const HTML = (t, d) => html` t.cgrid = h)} data-f1="#piano-roll" @pointerenter=${t.pointerenter} @pointerleave=${t.pointerleave} @focus=${t.focuschange} @blur=${t.focuschange} @keydown=${e => t.piano_ctrl.keydown (e)} - @wheel=${t.wheel} > + @wheel=${t.wheel_event} > t.menu_btn = h)} @click=${e => t.pianotoolmenu.popup (e)} @mousedown=${e => t.pianotoolmenu.popup (e)} > @@ -378,14 +380,21 @@ class BPianoRoll extends LitComponent { paint_timeline.call (this); paint_piano.call (this); } - wheel (event) + wheel_event (event) { - // TODO: use "scroll" for scrollbars, wheel delta is inappropriate - const delta = Util.wheel_delta (event); - if (Math.abs (delta.x) > Math.abs (delta.y)) - this.hscrollbar.scrollBy ({ left: delta.x }); - else - this.vscrollbar.scrollBy ({ top: delta.y }); + const delta = Mouse.wheel_delta (event, true); + if (event.ctrlKey) { + if (delta.deltaX) + this.hzoom = clamp (this.hzoom * (delta.deltaX > 0 ? 1.1 : 0.9), 0.25, 25); + if (delta.deltaY) + this.vzoom = clamp (this.vzoom * (delta.deltaY > 0 ? 1.1 : 0.9), 0.5, 25); + this.request_update_(); + } else { + if (delta.deltaX) + this.hscrollbar.scrollBy ({ left: delta.deltaX }); + if (delta.deltaY) + this.vscrollbar.scrollBy ({ top: delta.deltaY }); + } Util.prevent_event (event); } } diff --git a/ui/index.html b/ui/index.html index a7b902bb..05a74f0e 100644 --- a/ui/index.html +++ b/ui/index.html @@ -15,18 +15,19 @@ } } - - - - - - - - - - - - + @@ -61,6 +62,7 @@
+