task(CAD-14): phase 4c - legacy interaction engine DELETED (1173 lines), dispatcher is the single engine (native snap/ortho/pan/wheel/cursor), ToolState moved to ui.types
This commit is contained in:
@@ -17,6 +17,14 @@ import type { ZoomPanController } from '../canvas/ZoomPanController';
|
||||
|
||||
export interface DispatcherDeps {
|
||||
zoomPan: ZoomPanController;
|
||||
/** CAD-14 Phase 4c: Snap-Funktion (Weltkoordinaten) fuer Tool-Events. */
|
||||
snap?(x: number, y: number): { x: number; y: number };
|
||||
/** CAD-14 Phase 4c: Cursor-Meldung (auch ohne aktives Tool). */
|
||||
onCursorMoved?(worldX: number, worldY: number): void;
|
||||
/** CAD-14 Phase 4c: Render-Anstoess nach Pan/Wheel (CanvasArea ruft renderEngine.render). */
|
||||
requestRender?(): void;
|
||||
/** CAD-14 Phase 4c: Ortho-Anwendung gegen den letzten gesnappten Down-Punkt. */
|
||||
ortho?(x: number, y: number, last: { x: number; y: number } | null): { x: number; y: number };
|
||||
/** Liefert Optionsstände je ToolId (typisch: toolStore.optionValues). */
|
||||
getOptions?(toolId: string): Record<string, unknown>;
|
||||
/** Statuszeile (typisch: StatusBar-Bridge). */
|
||||
@@ -81,6 +89,9 @@ export class InteractionDispatcher {
|
||||
window.removeEventListener('pointermove', this.onMove);
|
||||
window.removeEventListener('pointerup', this.onUp);
|
||||
window.removeEventListener('keydown', this.onKey);
|
||||
this.canvas.removeEventListener('wheel', this.onWheelNative as EventListener);
|
||||
window.removeEventListener('pointermove', this.onPanMove);
|
||||
window.removeEventListener('pointerup', this.onPanEnd);
|
||||
this.bound = false;
|
||||
}
|
||||
|
||||
@@ -92,9 +103,46 @@ export class InteractionDispatcher {
|
||||
window.addEventListener('pointermove', this.onMove);
|
||||
window.addEventListener('pointerup', this.onUp);
|
||||
window.addEventListener('keydown', this.onKey);
|
||||
// CAD-14 Phase 4c: natives Pan + Wheel (ersetzt Legacy-Engine)
|
||||
this.canvas.addEventListener('wheel', this.onWheelNative as EventListener, { passive: false });
|
||||
window.addEventListener('pointermove', this.onPanMove);
|
||||
window.addEventListener('pointerup', this.onPanEnd);
|
||||
this.bound = true;
|
||||
}
|
||||
|
||||
// ── CAD-14 Phase 4c: natives Pan (Mittel-/Rechtsklick-Drag) ──
|
||||
private panActive = false;
|
||||
private lastPanScreen = { x: 0, y: 0 };
|
||||
/** CAD-14 Phase 4c: Letzter gesnappter Down-Punkt (Ortho-Referenz). */
|
||||
private lastSnappedDown: { x: number; y: number } | null = null;
|
||||
|
||||
private onPanMove = (e: PointerEvent): void => {
|
||||
if (!this.panActive) return;
|
||||
const dx = e.clientX - this.lastPanScreen.x;
|
||||
const dy = e.clientY - this.lastPanScreen.y;
|
||||
this.lastPanScreen = { x: e.clientX, y: e.clientY };
|
||||
this.deps.zoomPan.pan(dx, dy);
|
||||
this.requestRender();
|
||||
};
|
||||
|
||||
private onPanEnd = (): void => {
|
||||
this.panActive = false;
|
||||
};
|
||||
|
||||
private onWheelNative = (e: WheelEvent): void => {
|
||||
e.preventDefault();
|
||||
const factor = e.deltaY > 0 ? 0.9 : 1.1;
|
||||
const rect = this.canvas.getBoundingClientRect();
|
||||
const cx = e.clientX - rect.left;
|
||||
const cy = e.clientY - rect.top;
|
||||
this.deps.zoomPan.zoomAt(cx, cy, factor);
|
||||
this.requestRender();
|
||||
};
|
||||
|
||||
private requestRender(): void {
|
||||
this.deps.requestRender?.();
|
||||
}
|
||||
|
||||
private buildContext(): import('../plugins/types').FullToolContext {
|
||||
const toolId = this.active?.manifest.id ?? '';
|
||||
return {
|
||||
@@ -112,26 +160,31 @@ export class InteractionDispatcher {
|
||||
}
|
||||
|
||||
private onDown = (e: PointerEvent): void => {
|
||||
if (!this.active) return;
|
||||
// Rechtsklick = Abbruch wie ESC
|
||||
if (e.button === 2) {
|
||||
this.cancelActive();
|
||||
// CAD-14 Phase 4c: natives Pan bei Mittel-/Rechtsklick (auch ohne Tool)
|
||||
if (e.button === 1 || e.button === 2) {
|
||||
this.panActive = true;
|
||||
this.lastPanScreen = { x: e.clientX, y: e.clientY };
|
||||
return;
|
||||
}
|
||||
const tpe = toToolPointerEvent(e, this.canvas, this.deps.zoomPan);
|
||||
if (!this.active) return;
|
||||
const tpe = this.applySnapToEvent(toToolPointerEvent(e, this.canvas, this.deps.zoomPan));
|
||||
this.lastSnappedDown = { x: tpe.world.x, y: tpe.world.y };
|
||||
this.session.begin();
|
||||
this.active.handlers.down?.(tpe, this.buildContext());
|
||||
};
|
||||
|
||||
private onMove = (e: PointerEvent): void => {
|
||||
const tpeRaw = toToolPointerEvent(e, this.canvas, this.deps.zoomPan);
|
||||
// CAD-14 Phase 4c: Cursor-Meldung auch ohne aktives Tool (Statusleiste)
|
||||
this.deps.onCursorMoved?.(tpeRaw.world.x, tpeRaw.world.y);
|
||||
if (!this.active || !this.session.isActive) return;
|
||||
const tpe = toToolPointerEvent(e, this.canvas, this.deps.zoomPan);
|
||||
const tpe = this.applySnapToEvent(tpeRaw);
|
||||
this.active.handlers.move?.(tpe, this.buildContext());
|
||||
};
|
||||
|
||||
private onUp = (e: PointerEvent): void => {
|
||||
if (!this.active || !this.session.isActive) return;
|
||||
const tpe = toToolPointerEvent(e, this.canvas, this.deps.zoomPan);
|
||||
const tpe = this.applySnapToEvent(toToolPointerEvent(e, this.canvas, this.deps.zoomPan));
|
||||
try {
|
||||
this.active.handlers.up?.(tpe, this.buildContext());
|
||||
} finally {
|
||||
@@ -149,6 +202,20 @@ export class InteractionDispatcher {
|
||||
if (consumed) e.preventDefault();
|
||||
};
|
||||
|
||||
/** CAD-14 Phase 4c: wendet Snap aus Deps auf ein Tool-Pointer-Event an. */
|
||||
private applySnapToEvent(tpe: import('../plugins/types').ToolPointerEvent): import('../plugins/types').ToolPointerEvent {
|
||||
if (!this.deps.snap && !this.deps.ortho) return tpe;
|
||||
let p = { x: tpe.world.x, y: tpe.world.y };
|
||||
if (this.deps.snap) {
|
||||
const snapped = this.deps.snap(p.x, p.y);
|
||||
p = { x: snapped.x, y: snapped.y };
|
||||
}
|
||||
if (this.deps.ortho) {
|
||||
p = this.deps.ortho(p.x, p.y, this.lastSnappedDown);
|
||||
}
|
||||
return { ...tpe, world: p };
|
||||
}
|
||||
|
||||
private cancelActive(): void {
|
||||
if (!this.active) return;
|
||||
this.active.handlers.cancel?.(this.buildContext());
|
||||
|
||||
Reference in New Issue
Block a user