Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Translate.cs
1using System.Threading.Tasks;
2using System.Xml;
3using SkiaSharp;
5
7{
12 {
13 private LengthAttribute translateX;
14 private LengthAttribute translateY;
15
21 public Translate(Layout2DDocument Document, ILayoutElement Parent)
22 : base(Document, Parent)
23 {
24 }
25
29 public override string LocalName => "Translate";
30
35 {
36 get => this.translateX;
37 set => this.translateX = value;
38 }
39
44 {
45 get => this.translateY;
46 set => this.translateY = value;
47 }
48
53 public override Task FromXml(XmlElement Input)
54 {
55 this.translateX = new LengthAttribute(Input, "translateX", this.Document);
56 this.translateY = new LengthAttribute(Input, "translateY", this.Document);
57
58 return base.FromXml(Input);
59 }
60
65 public override void ExportAttributes(XmlWriter Output)
66 {
67 base.ExportAttributes(Output);
68
69 this.translateX?.Export(Output);
70 this.translateY?.Export(Output);
71 }
72
79 public override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
80 {
81 return new Translate(Document, Parent);
82 }
83
88 public override void CopyContents(ILayoutElement Destination)
89 {
90 base.CopyContents(Destination);
91
92 if (Destination is Translate Dest)
93 {
94 Dest.translateX = this.translateX?.CopyIfNotPreset(Destination.Document);
95 Dest.translateY = this.translateY?.CopyIfNotPreset(Destination.Document);
96 }
97 }
98
103 public override async Task AfterMeasureDimensions(DrawingState State)
104 {
105 await base.AfterMeasureDimensions(State);
106
107 EvaluationResult<Length> L = await this.translateX.TryEvaluate(State.Session);
108 if (L.Ok)
109 State.CalcDrawingSize(L.Result, ref this.dx, true, this.Parent);
110 else
111 this.dx = 0;
112
113 L = await this.translateY.TryEvaluate(State.Session);
114 if (L.Ok)
115 State.CalcDrawingSize(L.Result, ref this.dy, false, this.Parent);
116 else
117 this.dy = 0;
118
119 SKMatrix M = SKMatrix.CreateTranslation(this.dx, this.dy);
120 this.TransformBoundingBox(M);
121 }
122
123 private float dx;
124 private float dy;
125
130 public override async Task Draw(DrawingState State)
131 {
132 SKMatrix M = State.Canvas.TotalMatrix;
133 State.Canvas.Translate(this.dx, this.dy);
134
135 await base.Draw(State);
136
137 State.Canvas.SetMatrix(M);
138 }
139
144 public override void ExportStateAttributes(XmlWriter Output)
145 {
146 base.ExportStateAttributes(Output);
147
148 this.translateX?.ExportState(Output);
149 this.translateY?.ExportState(Output);
150 }
151 }
152}
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
LengthAttribute 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
void CalcDrawingSize(Length L, ref float Size, bool Horizontal, ILayoutElement Element)
Converts a defined length to drawing size.
Layout2DDocument Document
Layout document.
void TransformBoundingBox(SKMatrix M)
Transforms the measured bounding box.
LengthAttribute TranslateXAttribute
Translate X
Definition: Translate.cs:35
override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
Creates a new instance of the layout element.
Definition: Translate.cs:79
override void CopyContents(ILayoutElement Destination)
Copies contents (attributes and children) to the destination element.
Definition: Translate.cs:88
override async Task Draw(DrawingState State)
Draws layout entities.
Definition: Translate.cs:130
Translate(Layout2DDocument Document, ILayoutElement Parent)
A translation transform
Definition: Translate.cs:21
LengthAttribute TranslateYAttribute
Translate Y
Definition: Translate.cs:44
override void ExportStateAttributes(XmlWriter Output)
Exports the local attributes of the current element.
Definition: Translate.cs:144
override Task FromXml(XmlElement Input)
Populates the element (including children) with information from its XML definition.
Definition: Translate.cs:53
override string LocalName
Local name of type of element.
Definition: Translate.cs:29
override void ExportAttributes(XmlWriter Output)
Exports attributes to XML.
Definition: Translate.cs:65
override async Task AfterMeasureDimensions(DrawingState State)
Called when dimensions have been measured.
Definition: Translate.cs:103
Base interface for all layout elements.
Layout2DDocument Document
Layout document.