-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
52 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { IPointerData, PointerEventTypes } from "./base.ts"; | ||
import type { Point } from "../../toolkit.ts"; | ||
import type { ISingleNodeR } from "../../nodes.ts"; | ||
import type { IWorld } from "../../world.ts"; | ||
|
||
import { PointerProcessorBase, registerPointerProcessor } from "./base.ts"; | ||
import { DirtyStatus } from "../../board.ts"; | ||
|
||
class DragProcessor extends PointerProcessorBase<PointerEventTypes, IWorld> { | ||
private pointer: Point | null = null; | ||
private pointed: ISingleNodeR | null = null; | ||
|
||
exec(data: IPointerData<PointerEventTypes, IWorld>): Promise<void> { | ||
if (data.type === "onPointerDown") { | ||
const allPointed = this.getPointed(data); | ||
if (allPointed.length === 0) { | ||
this.reset(); | ||
} else { | ||
this.pointer = this.getPointer(data.e); | ||
this.pointed = allPointed.sort((a, b) => a.node.z - b.node.z)[0].node; | ||
} | ||
} else if (data.type === "onPointerMove") { | ||
if (this.pointer && this.pointed) { | ||
const newPointer = this.getPointer(data.e); | ||
this.pointed.position = this.pointed.lt.add(newPointer.subtract(this.pointer)); | ||
this.pointer = newPointer; | ||
data.world.renderer.board.get(this.pointed.alias).setDirtyStatus( | ||
DirtyStatus.TRANSFORM_DIRTY, | ||
); | ||
} | ||
} else if (data.type === "onPointerUp") { | ||
this.reset(); | ||
} | ||
return Promise.resolve(); | ||
} | ||
|
||
private reset(): void { | ||
this.pointed = null; | ||
this.pointer = null; | ||
} | ||
} | ||
|
||
const dragProcessor: DragProcessor = new DragProcessor(); | ||
export function registerDragPRocessor(): void { | ||
registerPointerProcessor("onPointerDown", dragProcessor); | ||
registerPointerProcessor("onPointerMove", dragProcessor); | ||
registerPointerProcessor("onPointerUp", dragProcessor); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,3 @@ | ||
import type { IPointerData, IPointerProcessor } from "@carefree0910/cfb-core"; | ||
import type { WebWorld } from "../world.ts"; | ||
import { registerDragPRocessor } from "@carefree0910/cfb-core"; | ||
|
||
import { Point, registerPointerProcessor } from "@carefree0910/cfb-core"; | ||
|
||
export class PointerDownProcessor | ||
implements IPointerProcessor<"onPointerDown", WebWorld> { | ||
exec({ e, world }: IPointerData<"onPointerDown", WebWorld>): Promise<void> { | ||
const graph = world.renderer.board.graph; | ||
const point = new Point(e.clientX, e.clientY); | ||
const pointed = graph.allSingleNodes.filter((gnode) => point.in(gnode.node.bbox)); | ||
console.log(pointed); | ||
return Promise.resolve(); | ||
} | ||
} | ||
|
||
registerPointerProcessor("onPointerDown", new PointerDownProcessor()); | ||
registerDragPRocessor(); |