Tldraw/packages/tldraw/src/state/tools/EllipseTool/EllipseTool.ts

43 wiersze
1.0 KiB
TypeScript
Czysty Zwykły widok Historia

import Vec from '@tldraw/vec'
2021-10-22 13:49:29 +00:00
import { Utils, TLPointerEventHandler, TLBoundsCorner } from '@tldraw/core'
import { Ellipse } from '~state/shapes'
import { SessionType, TLDrawShapeType } from '~types'
import { BaseTool, Status } from '../BaseTool'
export class EllipseTool extends BaseTool {
type = TLDrawShapeType.Ellipse
/* ----------------- Event Handlers ----------------- */
onPointerDown: TLPointerEventHandler = (info) => {
const pagePoint = Vec.round(this.state.getPagePoint(info.point))
const {
appState: { currentPageId, currentStyle },
} = this.state
const childIndex = this.getNextChildIndex()
const id = Utils.uniqueId()
const newShape = Ellipse.create({
id,
parentId: currentPageId,
childIndex,
point: pagePoint,
style: { ...currentStyle },
})
2021-10-22 13:49:29 +00:00
this.state.patchCreate([newShape])
this.state.startSession(
SessionType.TransformSingle,
pagePoint,
TLBoundsCorner.BottomRight,
true
)
this.setStatus(Status.Creating)
}
}