Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SolidPen.cs
1using System.Threading.Tasks;
2using System.Xml;
3using SkiaSharp;
5
7{
11 public class SolidPen : Pen
12 {
13 private ColorAttribute color;
14
20 public SolidPen(Layout2DDocument Document, ILayoutElement Parent)
21 : base(Document, Parent)
22 {
23 }
24
28 public override string LocalName => "SolidPen";
29
34 {
35 get => this.color;
36 set => this.color = value;
37 }
38
43 public override Task FromXml(XmlElement Input)
44 {
45 this.color = new ColorAttribute(Input, "color", this.Document);
46 return base.FromXml(Input);
47 }
48
53 public override void ExportAttributes(XmlWriter Output)
54 {
55 base.ExportAttributes(Output);
56
57 this.color?.Export(Output);
58 }
59
66 public override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
67 {
68 return new SolidPen(Document, Parent);
69 }
70
75 public override void CopyContents(ILayoutElement Destination)
76 {
77 base.CopyContents(Destination);
78
79 if (Destination is SolidPen Dest)
80 Dest.color = this.color?.CopyIfNotPreset(Destination.Document);
81 }
82
88 public override async Task DoMeasureDimensions(DrawingState State)
89 {
90 await base.DoMeasureDimensions(State);
91
92 if (this.paint is null)
93 {
94 EvaluationResult<SKColor> Color = await this.color.TryEvaluate(State.Session);
95 if (Color.Ok)
96 {
97 this.paint = new SKPaint()
98 {
99 FilterQuality = SKFilterQuality.High,
100 IsAntialias = true,
101 Style = SKPaintStyle.Stroke,
102 Color = Color.Result,
103 };
104
105 if (this.penWidth.HasValue)
106 this.paint.StrokeWidth = this.penWidth.Value;
107
108 if (this.penCap.HasValue)
109 this.paint.StrokeCap = this.penCap.Value;
110
111 if (this.penJoin.HasValue)
112 this.paint.StrokeJoin = this.penJoin.Value;
113
114 if (this.penMiter.HasValue)
115 this.paint.StrokeMiter = this.penMiter.Value;
116
117 this.defined = true;
118 }
119 }
120 }
121
126 public override void ExportStateAttributes(XmlWriter Output)
127 {
128 base.ExportStateAttributes(Output);
129
130 this.color?.ExportState(Output);
131 }
132
133 }
134}
Contains a 2D layout document.
void Export(XmlWriter Output)
Exports the attribute.
Definition: Attribute.cs:187
void ExportState(XmlWriter Output)
Exports the state of the attribute.
Definition: Attribute.cs:199
static async Task< EvaluationResult< T > > TryEvaluate(Attribute< T > Attribute, Variables Session)
Tries to evaluate the attribute value.
Definition: Attribute.cs:256
ColorAttribute CopyIfNotPreset(Layout2DDocument ForDocument)
Copies the attribute object if undefined, or defined by an expression. Returns a reference to itself,...
Variables Session
Current session.
Definition: DrawingState.cs:91
Layout2DDocument Document
Layout document.
Abstract base class for pens.
Definition: Pen.cs:13
SKStrokeCap? penCap
Measured pen stroke cap.
Definition: Pen.cs:182
SKStrokeJoin? penJoin
Measured pen stroke join.
Definition: Pen.cs:187
float? penWidth
Measured pen width.
Definition: Pen.cs:177
SKPaint paint
Current pen
Definition: Pen.cs:22
float? penMiter
Measured pen miter.
Definition: Pen.cs:192
override string LocalName
Local name of type of element.
Definition: SolidPen.cs:28
override void CopyContents(ILayoutElement Destination)
Copies contents (attributes and children) to the destination element.
Definition: SolidPen.cs:75
override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
Creates a new instance of the layout element.
Definition: SolidPen.cs:66
override void ExportStateAttributes(XmlWriter Output)
Exports the local attributes of the current element.
Definition: SolidPen.cs:126
override void ExportAttributes(XmlWriter Output)
Exports attributes to XML.
Definition: SolidPen.cs:53
override async Task DoMeasureDimensions(DrawingState State)
Measures layout entities and defines unassigned properties, related to dimensions.
Definition: SolidPen.cs:88
SolidPen(Layout2DDocument Document, ILayoutElement Parent)
A solid pen
Definition: SolidPen.cs:20
override Task FromXml(XmlElement Input)
Populates the element (including children) with information from its XML definition.
Definition: SolidPen.cs:43
Base interface for all layout elements.
Layout2DDocument Document
Layout document.