Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Scale.cs
1using System.Threading.Tasks;
2using System.Xml;
3using SkiaSharp;
5
7{
12 {
13 private FloatAttribute scaleX;
14 private FloatAttribute scaleY;
15
21 public Scale(Layout2DDocument Document, ILayoutElement Parent)
22 : base(Document, Parent)
23 {
24 }
25
29 public override string LocalName => "Scale";
30
35 {
36 get => this.scaleX;
37 set => this.scaleX = value;
38 }
39
44 {
45 get => this.scaleY;
46 set => this.scaleY = value;
47 }
48
53 public override Task FromXml(XmlElement Input)
54 {
55 this.scaleX = new FloatAttribute(Input, "scaleX", this.Document);
56 this.scaleY = new FloatAttribute(Input, "scaleY", 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.scaleX?.Export(Output);
70 this.scaleY?.Export(Output);
71 }
72
79 public override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
80 {
81 return new Scale(Document, Parent);
82 }
83
88 public override void CopyContents(ILayoutElement Destination)
89 {
90 base.CopyContents(Destination);
91
92 if (Destination is Scale Dest)
93 {
94 Dest.scaleX = this.scaleX?.CopyIfNotPreset(Destination.Document);
95 Dest.scaleY = this.scaleY?.CopyIfNotPreset(Destination.Document);
96 }
97 }
98
103 public override async Task AfterMeasureDimensions(DrawingState State)
104 {
105 await base.AfterMeasureDimensions(State);
106
107 this.sx = await this.scaleX.Evaluate(State.Session, 1);
108 this.sy = await this.scaleY.Evaluate(State.Session, 1);
109
110 SKMatrix M = SKMatrix.CreateScale(this.sx, this.sy, this.xCoordinate, this.yCoordinate);
111 this.TransformBoundingBox(M);
112 }
113
114 private float sx;
115 private float sy;
116
121 public override async Task Draw(DrawingState State)
122 {
123 SKMatrix M = State.Canvas.TotalMatrix;
124 State.Canvas.Scale(this.sx, this.sy, this.xCoordinate, this.yCoordinate);
125
126 await base.Draw(State);
127
128 State.Canvas.SetMatrix(M);
129 }
130
135 public override void ExportStateAttributes(XmlWriter Output)
136 {
137 base.ExportStateAttributes(Output);
138
139 this.scaleX?.ExportState(Output);
140 this.scaleY?.ExportState(Output);
141 }
142 }
143}
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
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.
override string LocalName
Local name of type of element.
Definition: Scale.cs:29
override async Task AfterMeasureDimensions(DrawingState State)
Called when dimensions have been measured.
Definition: Scale.cs:103
Scale(Layout2DDocument Document, ILayoutElement Parent)
A scale transform
Definition: Scale.cs:21
FloatAttribute ScaleYAttribute
Scale Y
Definition: Scale.cs:44
override void ExportStateAttributes(XmlWriter Output)
Exports the local attributes of the current element.
Definition: Scale.cs:135
override void CopyContents(ILayoutElement Destination)
Copies contents (attributes and children) to the destination element.
Definition: Scale.cs:88
override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
Creates a new instance of the layout element.
Definition: Scale.cs:79
override async Task Draw(DrawingState State)
Draws layout entities.
Definition: Scale.cs:121
override void ExportAttributes(XmlWriter Output)
Exports attributes to XML.
Definition: Scale.cs:65
override Task FromXml(XmlElement Input)
Populates the element (including children) with information from its XML definition.
Definition: Scale.cs:53
FloatAttribute ScaleXAttribute
Scale X
Definition: Scale.cs:35
Base interface for all layout elements.
Layout2DDocument Document
Layout document.