2021-10-22 13:49:29 +00:00
|
|
|
import { Utils, TLPointerEventHandler, TLBoundsCorner } from '@tldraw/core'
|
2021-11-06 11:16:30 +00:00
|
|
|
import { Ellipse } from '~state/shapes'
|
2021-11-16 16:01:29 +00:00
|
|
|
import { SessionType, TDShapeType } from '~types'
|
2021-10-16 07:33:25 +00:00
|
|
|
import { BaseTool, Status } from '../BaseTool'
|
2021-10-13 13:55:31 +00:00
|
|
|
|
|
|
|
export class EllipseTool extends BaseTool {
|
2021-11-16 16:01:29 +00:00
|
|
|
type = TDShapeType.Ellipse as const
|
2021-10-13 13:55:31 +00:00
|
|
|
|
|
|
|
/* ----------------- Event Handlers ----------------- */
|
|
|
|
|
2021-11-16 16:01:29 +00:00
|
|
|
onPointerDown: TLPointerEventHandler = () => {
|
2021-11-24 18:07:31 +00:00
|
|
|
if (this.status !== Status.Idle) return
|
|
|
|
|
2021-10-13 13:55:31 +00:00
|
|
|
const {
|
2021-11-16 16:01:29 +00:00
|
|
|
currentPoint,
|
2021-10-13 13:55:31 +00:00
|
|
|
appState: { currentPageId, currentStyle },
|
2021-11-16 16:01:29 +00:00
|
|
|
} = this.app
|
2021-10-13 13:55:31 +00:00
|
|
|
|
|
|
|
const childIndex = this.getNextChildIndex()
|
|
|
|
|
|
|
|
const id = Utils.uniqueId()
|
|
|
|
|
|
|
|
const newShape = Ellipse.create({
|
|
|
|
id,
|
|
|
|
parentId: currentPageId,
|
|
|
|
childIndex,
|
2021-11-16 16:01:29 +00:00
|
|
|
point: currentPoint,
|
2021-10-13 13:55:31 +00:00
|
|
|
style: { ...currentStyle },
|
|
|
|
})
|
|
|
|
|
2021-11-16 16:01:29 +00:00
|
|
|
this.app.patchCreate([newShape])
|
2021-10-13 13:55:31 +00:00
|
|
|
|
2021-11-16 16:01:29 +00:00
|
|
|
this.app.startSession(
|
2021-10-15 09:33:48 +00:00
|
|
|
SessionType.TransformSingle,
|
2021-11-16 16:01:29 +00:00
|
|
|
newShape.id,
|
2021-10-15 09:33:48 +00:00
|
|
|
TLBoundsCorner.BottomRight,
|
|
|
|
true
|
|
|
|
)
|
2021-10-13 13:55:31 +00:00
|
|
|
|
|
|
|
this.setStatus(Status.Creating)
|
|
|
|
}
|
|
|
|
}
|