2021-06-23 22:32:21 +00:00
|
|
|
import CodeShape from './index'
|
2021-07-01 14:03:02 +00:00
|
|
|
import { uniqueId } from 'utils/utils'
|
2021-06-24 22:09:36 +00:00
|
|
|
import { DrawShape, ShapeProps, ShapeType } from 'types'
|
2021-06-23 22:32:21 +00:00
|
|
|
import { defaultStyle } from 'state/shape-styles'
|
|
|
|
|
2021-06-25 10:28:52 +00:00
|
|
|
/* ----------------- Start Copy Here ---------------- */
|
|
|
|
|
2021-06-23 22:32:21 +00:00
|
|
|
export default class Draw extends CodeShape<DrawShape> {
|
2021-06-24 22:09:36 +00:00
|
|
|
constructor(props = {} as ShapeProps<DrawShape>) {
|
2021-06-23 22:32:21 +00:00
|
|
|
super({
|
|
|
|
id: uniqueId(),
|
|
|
|
type: ShapeType.Draw,
|
2021-06-25 10:28:52 +00:00
|
|
|
parentId: (window as any).currentPageId,
|
2021-06-23 22:32:21 +00:00
|
|
|
name: 'Draw',
|
|
|
|
childIndex: 0,
|
|
|
|
point: [0, 0],
|
|
|
|
points: [],
|
|
|
|
rotation: 0,
|
|
|
|
...props,
|
|
|
|
style: {
|
|
|
|
...defaultStyle,
|
|
|
|
...props.style,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2021-06-27 19:50:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a point to the draw shape's points.
|
|
|
|
*
|
|
|
|
* ```ts
|
|
|
|
* shape.addPoint([100,100])
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
addPoint(point: number[]): CodeShape<DrawShape> {
|
|
|
|
this.utils.setProperty(this.shape, 'points', [...this.points, point])
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The draw shape's points.
|
|
|
|
*
|
|
|
|
* ```ts
|
|
|
|
* const shapePoints = shape.points
|
|
|
|
*
|
|
|
|
* shape.points = [[0,0], [100,100], [100,200]]
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
get points(): number[][] {
|
|
|
|
return this.shape.points
|
|
|
|
}
|
|
|
|
|
|
|
|
set points(points: number[][]) {
|
|
|
|
this.utils.setProperty(this.shape, 'points', points)
|
|
|
|
}
|
2021-06-23 22:32:21 +00:00
|
|
|
}
|