Skip to content

Commit

Permalink
Add DragAndScaleState for external proxy (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei authored Nov 16, 2024
1 parent b29a32c commit 8345b98
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/DragAndScale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@ import type { CanvasMouseEvent } from "./types/events"
import { LiteGraph } from "./litegraph"
import { isInRect } from "./measure"

export interface DragAndScaleState {
offset: Point
scale: number
}

export class DragAndScale {
/**
* The state of this DragAndScale instance.
*
* Implemented as a POCO that can be proxied without side-effects.
*/
state: DragAndScaleState

/** Maximum scale (zoom in) */
max_scale: number
/** Minimum scale (zoom out) */
min_scale: number
offset: Point
scale: number
enabled: boolean
last_mouse: Point
element?: HTMLCanvasElement
Expand All @@ -22,9 +32,25 @@ export class DragAndScale {
/** @deprecated */
onmouse?(e: unknown): boolean

get offset(): Point {
return this.state.offset
}
set offset(value: Point) {
this.state.offset = value
}

get scale(): number {
return this.state.scale
}
set scale(value: number) {
this.state.scale = value
}

constructor(element?: HTMLCanvasElement, skip_events?: boolean) {
this.offset = new Float32Array([0, 0])
this.scale = 1
this.state = {
offset: new Float32Array([0, 0]),
scale: 1
}
this.max_scale = 10
this.min_scale = 0.1
this.onredraw = null
Expand Down

0 comments on commit 8345b98

Please sign in to comment.