From 77b5e25e641bb1d8f5756a98c2ce80791fb51590 Mon Sep 17 00:00:00 2001 From: Daniel Ledda Date: Sun, 3 Apr 2022 15:50:01 +0200 Subject: [PATCH] fix: fixed track unit event handling and initialisation --- src/ui/Beat/BeatView.ts | 12 ++++++------ src/ui/BeatSettings/BeatSettingsView.ts | 4 ++-- src/ui/Root/RootView.ts | 4 ++-- src/ui/Track/TrackView.ts | 9 ++++----- src/ui/TrackUnit/TrackUnitView.ts | 23 ++++++++++++++++++----- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/ui/Beat/BeatView.ts b/src/ui/Beat/BeatView.ts index e6a2894..3f27e24 100644 --- a/src/ui/Beat/BeatView.ts +++ b/src/ui/Beat/BeatView.ts @@ -29,17 +29,17 @@ export default class BeatView extends UINode implements ISubscriber this.notify(null, eventType)); @@ -78,7 +78,7 @@ export default class BeatSettingsView extends UINode implements ISubscriber this.onBeatViewHover(view)); - view.onMouseUp((event: MouseEvent) => this.onTrackUnitClick(event.button, i)); + view.onHover(() => this.onTrackUnitViewHover(view)); + view.onMouseDown((event: MouseEvent) => this.onTrackUnitClick(event.button, i)); } } } @@ -84,15 +84,14 @@ export default class TrackView extends UINode implements ISubscriber = new Publisher(this); private rotationTimeout: ReturnType | null = null; - private mouseUpListeners: ((ev: MouseEvent) => void)[] = []; + private mouseDownListeners: ((ev: MouseEvent) => void)[] = []; private hoverListeners: ((ev: MouseEvent) => void)[] = []; private blockNextMouseUp = false; constructor(options: TrackUnitUINodeOptions) { super(options); this.trackUnit = options.trackUnit; - this.setupBindings(); + this.setUnit(this.trackUnit); } setUnit(trackUnit: TrackUnit | null): void { @@ -45,8 +45,12 @@ export default class TrackUnitView extends UINode implements ISubscriber this.getNode().removeEventListener("mouseover", listener)); + this.mouseDownListeners.forEach(listener => this.getNode().removeEventListener("mousedown", listener)); this.redraw(); + this.hoverListeners.forEach(listener => this.getNode().addEventListener("mouseover", listener)); + this.mouseDownListeners.forEach(listener => this.getNode().addEventListener("mousedown", listener)); this.getNode().addEventListener("mousedown", (ev) => this.handleMouseDown(ev)); + this.getNode().addEventListener("mouseout", (ev) => this.handleMouseOut(ev)); this.getNode().addEventListener("mouseup", (ev) => this.handleMouseUp(ev)); this.getNode().addEventListener("touchstart", (ev) => this.handleTouchStart(ev)); this.getNode().addEventListener("touchend", (ev) => this.handleTouchEnd(ev)); @@ -56,6 +60,7 @@ export default class TrackUnitView extends UINode implements ISubscriber { this.trackUnit.rotateType(); this.blockNextMouseUp = true; @@ -64,13 +69,20 @@ export default class TrackUnitView extends UINode implements ISubscriber listener(ev)); + this.mouseDownListeners.forEach(listener => listener(ev)); } this.blockNextMouseUp = false; } @@ -148,7 +160,8 @@ export default class TrackUnitView extends UINode implements ISubscriber void): void { - this.mouseUpListeners.push(cb); + onMouseDown(cb: (ev: MouseEvent) => void): void { + this.mouseDownListeners.push(cb); + this.getNode().addEventListener("mousedown", cb); } }