Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SkewX.cs
1using System.Threading.Tasks;
2using System.Xml;
3using SkiaSharp;
5
7{
12 {
13 private FloatAttribute factor;
14
20 public SkewX(Layout2DDocument Document, ILayoutElement Parent)
21 : base(Document, Parent)
22 {
23 }
24
28 public override string LocalName => "SkewX";
29
34 {
35 get => this.factor;
36 set => this.factor = value;
37 }
38
43 public override Task FromXml(XmlElement Input)
44 {
45 this.factor = new FloatAttribute(Input, "factor", this.Document);
46 return base.FromXml(Input);
47 }
48
53 public override void ExportAttributes(XmlWriter Output)
54 {
55 base.ExportAttributes(Output);
56
57 this.factor?.Export(Output);
58 }
59
66 public override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
67 {
68 return new SkewX(Document, Parent);
69 }
70
75 public override void CopyContents(ILayoutElement Destination)
76 {
77 base.CopyContents(Destination);
78
79 if (Destination is SkewX Dest)
80 Dest.factor = this.factor?.CopyIfNotPreset(Destination.Document);
81 }
82
87 public override async Task AfterMeasureDimensions(DrawingState State)
88 {
89 await base.AfterMeasureDimensions(State);
90
91 EvaluationResult<float> Factor = await this.factor.TryEvaluate(State.Session);
92 if (Factor.Ok)
93 {
94 this.sx = Factor.Result;
95
96 SKMatrix M = SKMatrix.CreateTranslation(this.xCoordinate, this.yCoordinate);
97 M = M.PreConcat(SKMatrix.CreateSkew(this.sx, 0));
98 M = M.PreConcat(SKMatrix.CreateTranslation(-this.xCoordinate, -this.yCoordinate));
99
100 this.TransformBoundingBox(M);
101 }
102 else
103 this.sx = 0;
104 }
105
106 private float sx;
107
112 public override async Task Draw(DrawingState State)
113 {
114 SKMatrix M = State.Canvas.TotalMatrix;
115 State.Canvas.Translate(this.xCoordinate, this.yCoordinate);
116 State.Canvas.Skew(this.sx, 0);
117 State.Canvas.Translate(-this.xCoordinate, -this.yCoordinate);
118
119 await base.Draw(State);
120
121 State.Canvas.SetMatrix(M);
122 }
123
128 public override void ExportStateAttributes(XmlWriter Output)
129 {
130 base.ExportStateAttributes(Output);
131
132 this.factor?.ExportState(Output);
133 }
134
135 }
136}
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
FloatAttribute CopyIfNotPreset(Layout2DDocument ForDocument)
Copies the attribute object if undefined, or defined by an expression. Returns a reference to itself,...
SKCanvas Canvas
Current drawing canvas.
Variables Session
Current session.
Definition: DrawingState.cs:91
Layout2DDocument Document
Layout document.
void TransformBoundingBox(SKMatrix M)
Transforms the measured bounding box.
Base abstract class for transformations using an optional pivot point.
A skew transform along the X-axis.
Definition: SkewX.cs:12
override Task FromXml(XmlElement Input)
Populates the element (including children) with information from its XML definition.
Definition: SkewX.cs:43
override async Task AfterMeasureDimensions(DrawingState State)
Called when dimensions have been measured.
Definition: SkewX.cs:87
override void ExportAttributes(XmlWriter Output)
Exports attributes to XML.
Definition: SkewX.cs:53
FloatAttribute FactorAttribute
Factor
Definition: SkewX.cs:34
override void ExportStateAttributes(XmlWriter Output)
Exports the local attributes of the current element.
Definition: SkewX.cs:128
override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
Creates a new instance of the layout element.
Definition: SkewX.cs:66
override async Task Draw(DrawingState State)
Draws layout entities.
Definition: SkewX.cs:112
override void CopyContents(ILayoutElement Destination)
Copies contents (attributes and children) to the destination element.
Definition: SkewX.cs:75
SkewX(Layout2DDocument Document, ILayoutElement Parent)
A skew transform along the X-axis.
Definition: SkewX.cs:20
override string LocalName
Local name of type of element.
Definition: SkewX.cs:28
Base interface for all layout elements.
Layout2DDocument Document
Layout document.