@@ -20,31 +20,81 @@ enum VerticalAlignment { top, center, bottom }
2020
2121enum StrokeStyle { solid, dotted }
2222
23+ @freezed
24+ sealed class ElementPaint with _$ElementPaint {
25+ const ElementPaint ._();
26+
27+ const factory ElementPaint .solid ({
28+ @Default (SRGBColor .black) @ColorJsonConverter () SRGBColor color,
29+ }) = SolidElementPaint ;
30+
31+ const factory ElementPaint .texture ({
32+ required String source,
33+ @Default (SRGBColor .white) @ColorJsonConverter () SRGBColor tint,
34+ @Default (1 ) double scale,
35+ }) = TextureElementPaint ;
36+
37+ const factory ElementPaint .gradient ({
38+ @Default (SRGBColor .black) @ColorJsonConverter () SRGBColor start,
39+ @Default (SRGBColor .white) @ColorJsonConverter () SRGBColor end,
40+ @Default (0 ) double angle,
41+ }) = GradientElementPaint ;
42+
43+ factory ElementPaint .fromJson (Map <String , dynamic > json) =>
44+ _$ElementPaintFromJson (json);
45+
46+ SRGBColor get previewColor => switch (this ) {
47+ SolidElementPaint (: final color) => color,
48+ TextureElementPaint (: final tint) => tint,
49+ GradientElementPaint (: final start) => start,
50+ };
51+
52+ ElementPaint withAlpha (int alpha) => switch (this ) {
53+ SolidElementPaint (: final color) => ElementPaint .solid (
54+ color: color.withValues (a: alpha),
55+ ),
56+ TextureElementPaint (: final source, : final tint, : final scale) =>
57+ ElementPaint .texture (
58+ source: source,
59+ tint: tint.withValues (a: alpha),
60+ scale: scale,
61+ ),
62+ GradientElementPaint (: final start, : final end, : final angle) =>
63+ ElementPaint .gradient (
64+ start: start.withValues (a: alpha),
65+ end: end.withValues (a: alpha),
66+ angle: angle,
67+ ),
68+ };
69+ }
70+
2371@freezed
2472sealed class Property with _$Property {
2573 @Implements < PathProperty > ()
2674 const factory Property .pen ({
2775 @Default (5 ) double strokeWidth,
2876 @Default (0.4 ) double thinning,
29- @Default (SRGBColor .black) @ColorJsonConverter () SRGBColor color,
30- @Default (SRGBColor .transparent) @ColorJsonConverter () SRGBColor fill,
77+ @Default (ElementPaint .solid ()) ElementPaint paint,
78+ @Default (ElementPaint .solid (color: SRGBColor .transparent))
79+ ElementPaint fillPaint,
3180 @Default (0.5 ) double smoothing,
3281 @Default (0.3 ) double streamline,
3382 }) = PenProperty ;
3483
3584 const factory Property .shape ({
3685 @Default (5 ) double strokeWidth,
3786 required PathShape shape,
38- @Default (SRGBColor .black) @ColorJsonConverter () SRGBColor color ,
87+ @Default (ElementPaint . solid ()) ElementPaint paint ,
3988 @Default (StrokeStyle .solid) StrokeStyle strokeStyle,
4089 @Default (1.0 ) double dashMultiplier,
4190 @Default (1.0 ) double gapMultiplier,
4291 }) = ShapeProperty ;
4392
4493 const factory Property .polygon ({
4594 @Default (5 ) double strokeWidth,
46- @Default (SRGBColor .black) @ColorJsonConverter () SRGBColor color,
47- @Default (SRGBColor .transparent) @ColorJsonConverter () SRGBColor fill,
95+ @Default (ElementPaint .solid ()) ElementPaint paint,
96+ @Default (ElementPaint .solid (color: SRGBColor .transparent))
97+ ElementPaint fillPaint,
4898 }) = PolygonProperty ;
4999
50100 factory Property .fromJson (Map <String , dynamic > json) =>
@@ -55,18 +105,21 @@ sealed class Property with _$Property {
55105sealed class PathShape with _$PathShape {
56106 const PathShape ._();
57107 const factory PathShape .circle ({
58- @Default (SRGBColor .transparent) @ColorJsonConverter () SRGBColor fillColor,
108+ @Default (ElementPaint .solid (color: SRGBColor .transparent))
109+ ElementPaint fillPaint,
59110 }) = CircleShape ;
60111 const factory PathShape .rectangle ({
61- @Default (SRGBColor .transparent) @ColorJsonConverter () SRGBColor fillColor,
112+ @Default (ElementPaint .solid (color: SRGBColor .transparent))
113+ ElementPaint fillPaint,
62114 @Default (0 ) double topLeftCornerRadius,
63115 @Default (0 ) double topRightCornerRadius,
64116 @Default (0 ) double bottomLeftCornerRadius,
65117 @Default (0 ) double bottomRightCornerRadius,
66118 }) = RectangleShape ;
67119 const factory PathShape .line () = LineShape ;
68120 const factory PathShape .triangle ({
69- @Default (SRGBColor .transparent) @ColorJsonConverter () SRGBColor fillColor,
121+ @Default (ElementPaint .solid (color: SRGBColor .transparent))
122+ ElementPaint fillPaint,
70123 }) = TriangleShape ;
71124
72125 factory PathShape .fromJson (Map <String , dynamic > json) =>
0 commit comments