From 29f1f00e232e4f5cca7315782cf7e19cb8e14b86 Mon Sep 17 00:00:00 2001 From: strawberry42271 <2806566736@qq.com> Date: Tue, 24 Dec 2024 17:11:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20graphic=E7=9A=84patchProp=E5=86=99?= =?UTF-8?q?=E5=AE=8C=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/render/preset/graphics.ts | 105 +++++++++++++++++++++++++++++ src/core/render/renderer/props.ts | 44 ++++++++++-- 2 files changed, 143 insertions(+), 6 deletions(-) diff --git a/src/core/render/preset/graphics.ts b/src/core/render/preset/graphics.ts index 5ddf392..803d801 100644 --- a/src/core/render/preset/graphics.ts +++ b/src/core/render/preset/graphics.ts @@ -238,6 +238,18 @@ export class Circle extends GraphicItemBase { parentComponent?: ComponentInternalInstance | null ): void { switch (key) { + case 'radius': + if (!this.assertType(nextValue, 'number', key)) return; + this.setRadius(nextValue); + return; + case 'start': + if (!this.assertType(nextValue, 'number', key)) return; + this.setAngle(nextValue,this.end); + return; + case 'end': + if (!this.assertType(nextValue, 'number', key)) return; + this.setAngle(this.start,nextValue); + return; } super.patchProp(key, prevValue, nextValue, namespace, parentComponent); } @@ -307,6 +319,22 @@ export class Ellipse extends GraphicItemBase { parentComponent?: ComponentInternalInstance | null ): void { switch (key) { + case 'radiusX': + if (!this.assertType(nextValue, 'number', key)) return; + this.setRadius(nextValue,this.radiusY); + return; + case 'radiusY': + if (!this.assertType(nextValue, 'number', key)) return; + this.setRadius(this.radiusY,nextValue); + return; + case 'start': + if (!this.assertType(nextValue, 'number', key)) return; + this.setAngle(nextValue,this.end); + return; + case 'end': + if (!this.assertType(nextValue, 'number', key)) return; + this.setAngle(this.start,nextValue); + return; } super.patchProp(key, prevValue, nextValue, namespace, parentComponent); } @@ -357,6 +385,22 @@ export class Line extends GraphicItemBase { parentComponent?: ComponentInternalInstance | null ): void { switch (key) { + case 'x1': + if (!this.assertType(nextValue, 'number', key)) return; + this.setPoint1(nextValue,this.y1); + return; + case 'y1': + if (!this.assertType(nextValue, 'number', key)) return; + this.setPoint1(this.x1,nextValue); + return; + case 'x2': + if (!this.assertType(nextValue, 'number', key)) return; + this.setPoint2(nextValue,this.y2); + return; + case 'y2': + if (!this.assertType(nextValue, 'number', key)) return; + this.setPoint2(this.x2,nextValue); + return; } super.patchProp(key, prevValue, nextValue, namespace, parentComponent); } @@ -428,6 +472,38 @@ export class BezierCurve extends GraphicItemBase { parentComponent?: ComponentInternalInstance | null ): void { switch (key) { + case 'sx': + if (!this.assertType(nextValue, 'number', key)) return; + this.setStart(nextValue,this.sy); + return; + case 'sy': + if (!this.assertType(nextValue, 'number', key)) return; + this.setStart(this.sx,nextValue); + return; + case 'cp1x': + if (!this.assertType(nextValue, 'number', key)) return; + this.setControl1(nextValue,this.cp1y); + return; + case 'cp1y': + if (!this.assertType(nextValue, 'number', key)) return; + this.setControl1(this.cp1x,nextValue); + return; + case 'cp2x': + if (!this.assertType(nextValue, 'number', key)) return; + this.setControl2(nextValue,this.cp2y); + return; + case 'cp2y': + if (!this.assertType(nextValue, 'number', key)) return; + this.setControl2(this.cp2x,nextValue); + return; + case 'ex': + if (!this.assertType(nextValue, 'number', key)) return; + this.setEnd(nextValue,this.ey); + return; + case 'ey': + if (!this.assertType(nextValue, 'number', key)) return; + this.setEnd(this.ex,nextValue); + return; } super.patchProp(key, prevValue, nextValue, namespace, parentComponent); } @@ -488,6 +564,30 @@ export class QuadraticCurve extends GraphicItemBase { parentComponent?: ComponentInternalInstance | null ): void { switch (key) { + case 'sx': + if (!this.assertType(nextValue, 'number', key)) return; + this.setStart(nextValue,this.sy); + return; + case 'sy': + if (!this.assertType(nextValue, 'number', key)) return; + this.setStart(this.sx,nextValue); + return; + case 'cpx': + if (!this.assertType(nextValue, 'number', key)) return; + this.setControl(nextValue,this.cpy); + return; + case 'cpy': + if (!this.assertType(nextValue, 'number', key)) return; + this.setControl(this.cpx,nextValue); + return; + case 'ex': + if (!this.assertType(nextValue, 'number', key)) return; + this.setEnd(nextValue,this.ey); + return; + case 'ey': + if (!this.assertType(nextValue, 'number', key)) return; + this.setEnd(this.ex,nextValue); + return; } super.patchProp(key, prevValue, nextValue, namespace, parentComponent); } @@ -545,6 +645,11 @@ export class Path extends GraphicItemBase { parentComponent?: ComponentInternalInstance | null ): void { switch (key) { + case 'path': + if (!this.assertType(nextValue, Path2D, key)) return; + this.path = nextValue; + this.update(); + return; } super.patchProp(key, prevValue, nextValue, namespace, parentComponent); } diff --git a/src/core/render/renderer/props.ts b/src/core/render/renderer/props.ts index 61f688e..ddc9cfc 100644 --- a/src/core/render/renderer/props.ts +++ b/src/core/render/renderer/props.ts @@ -108,17 +108,49 @@ export interface GraphicPropsBase extends BaseProps, Partial { export interface RectProps extends GraphicPropsBase {} -export interface CirclesProps extends GraphicPropsBase {} +export interface CirclesProps extends GraphicPropsBase { + radius?: number; + start?: number; + end?: number; +} -export interface EllipseProps extends GraphicPropsBase {} +export interface EllipseProps extends GraphicPropsBase { + radiusX?: number; + radiusY?: number; + start?: number; + end?: number; +} -export interface LineProps extends GraphicPropsBase {} +export interface LineProps extends GraphicPropsBase { + x1?: number; + y1?: number; + x2?: number; + y2?: number; +} -export interface BezierProps extends GraphicPropsBase {} +export interface BezierProps extends GraphicPropsBase { + sx?: number; + sy?: number; + cp1x?: number; + cp1y?: number; + cp2x?: number; + cp2y?: number; + ex?: number; + ey?: number; +} -export interface QuadraticProps extends GraphicPropsBase {} +export interface QuadraticProps extends GraphicPropsBase { + sx?: number; + sy?: number; + cpx?: number; + cpy?: number; + ex?: number; + ey?: number; +} -export interface PathProps extends GraphicPropsBase {} +export interface PathProps extends GraphicPropsBase { + path?: Path2D; +} export interface IconProps extends BaseProps {}