Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Pen.cs
1using System;
2using System.Threading.Tasks;
3using System.Xml;
4using SkiaSharp;
6
8{
12 public abstract class Pen : LayoutElement
13 {
14 private LengthAttribute width;
16 private EnumAttribute<SKStrokeJoin> join;
17 private LengthAttribute miter;
18
22 protected SKPaint paint;
23
29 public Pen(Layout2DDocument Document, ILayoutElement Parent)
30 : base(Document, Parent)
31 {
32 }
33
37 public override void Dispose()
38 {
39 base.Dispose();
40
41 this.paint?.Dispose();
42 this.paint = null;
43 }
44
48 public SKPaint Paint => this.paint;
49
54 {
55 get => this.width;
56 set => this.width = value;
57 }
58
63 {
64 get => this.cap;
65 set => this.cap = value;
66 }
67
72 {
73 get => this.join;
74 set => this.join = value;
75 }
76
81 {
82 get => this.miter;
83 set => this.miter = value;
84 }
85
90 public override Task FromXml(XmlElement Input)
91 {
92 this.width = new LengthAttribute(Input, "width", this.Document);
93 this.cap = new EnumAttribute<SKStrokeCap>(Input, "cap", this.Document);
94 this.join = new EnumAttribute<SKStrokeJoin>(Input, "join", this.Document);
95 this.miter = new LengthAttribute(Input, "miter", this.Document);
96
97 return base.FromXml(Input);
98 }
99
104 public override void ExportAttributes(XmlWriter Output)
105 {
106 base.ExportAttributes(Output);
107
108 this.width?.Export(Output);
109 this.cap?.Export(Output);
110 this.join?.Export(Output);
111 this.miter?.Export(Output);
112 }
113
118 public override void CopyContents(ILayoutElement Destination)
119 {
120 base.CopyContents(Destination);
121
122 if (Destination is Pen Dest)
123 {
124 Dest.width = this.width?.CopyIfNotPreset(Destination.Document);
125 Dest.cap = this.cap?.CopyIfNotPreset(Destination.Document);
126 Dest.join = this.join?.CopyIfNotPreset(Destination.Document);
127 Dest.miter = this.miter?.CopyIfNotPreset(Destination.Document);
128 }
129 }
130
136 public override async Task DoMeasureDimensions(DrawingState State)
137 {
138 await base.DoMeasureDimensions(State);
139 float a;
140
141 EvaluationResult<Length> Length = await this.width.TryEvaluate(State.Session);
142 if (Length.Ok)
143 {
144 a = this.penWidth ?? 0;
145 State.CalcDrawingSize(Length.Result, ref a, true, (ILayoutElement)this);
146 this.penWidth = a;
147 }
148 else
149 this.penWidth = null;
150
151 EvaluationResult<SKStrokeCap> Cap = await this.cap.TryEvaluate(State.Session);
152 if (Cap.Ok)
153 this.penCap = Cap.Result;
154 else
155 this.penCap = null;
156
157 EvaluationResult<SKStrokeJoin> Join = await this.join.TryEvaluate(State.Session);
158 if (Join.Ok)
159 this.penJoin = Join.Result;
160 else
161 this.penJoin = null;
162
163 Length = await this.miter.TryEvaluate(State.Session);
164 if (Length.Ok)
165 {
166 a = this.penMiter ?? 0;
167 State.CalcDrawingSize(Length.Result, ref a, true, (ILayoutElement)this);
168 this.penMiter = a;
169 }
170 else
171 this.penMiter = null;
172 }
173
177 protected float? penWidth;
178
182 protected SKStrokeCap? penCap;
183
187 protected SKStrokeJoin? penJoin;
188
192 protected float? penMiter;
193
198 public override void ExportStateAttributes(XmlWriter Output)
199 {
200 base.ExportStateAttributes(Output);
201
202 this.width?.ExportState(Output);
203 this.cap?.ExportState(Output);
204 this.join?.ExportState(Output);
205 this.miter?.ExportState(Output);
206 }
207
208 }
209}
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
EnumAttribute< TEnum > CopyIfNotPreset(Layout2DDocument ForDocument)
Copies the attribute object if undefined, or defined by an expression. Returns a reference to itself,...
LengthAttribute 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
void CalcDrawingSize(Length L, ref float Size, bool Horizontal, ILayoutElement Element)
Converts a defined length to drawing size.
Abstract base class for layout elements.
Layout2DDocument Document
Layout document.
Abstract base class for pens.
Definition: Pen.cs:13
override void ExportAttributes(XmlWriter Output)
Exports attributes to XML.
Definition: Pen.cs:104
override void CopyContents(ILayoutElement Destination)
Copies contents (attributes and children) to the destination element.
Definition: Pen.cs:118
EnumAttribute< SKStrokeJoin > JoinAttribute
Join
Definition: Pen.cs:72
SKStrokeCap? penCap
Measured pen stroke cap.
Definition: Pen.cs:182
SKStrokeJoin? penJoin
Measured pen stroke join.
Definition: Pen.cs:187
LengthAttribute WidthAttribute
Width
Definition: Pen.cs:54
float? penWidth
Measured pen width.
Definition: Pen.cs:177
Pen(Layout2DDocument Document, ILayoutElement Parent)
Abstract base class for pens.
Definition: Pen.cs:29
override async Task DoMeasureDimensions(DrawingState State)
Measures layout entities and defines unassigned properties, related to dimensions.
Definition: Pen.cs:136
override void ExportStateAttributes(XmlWriter Output)
Exports the local attributes of the current element.
Definition: Pen.cs:198
override void Dispose()
IDisposable.Dispose
Definition: Pen.cs:37
SKPaint paint
Current pen
Definition: Pen.cs:22
SKPaint Paint
Current pen
Definition: Pen.cs:48
EnumAttribute< SKStrokeCap > CapAttribute
Cap
Definition: Pen.cs:63
override Task FromXml(XmlElement Input)
Populates the element (including children) with information from its XML definition.
Definition: Pen.cs:90
LengthAttribute MiterAttribute
Miter
Definition: Pen.cs:81
float? penMiter
Measured pen miter.
Definition: Pen.cs:192
Base interface for all layout elements.
Layout2DDocument Document
Layout document.