Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
RoundedRectangle.cs
1using System.Threading.Tasks;
2using System.Xml;
3using SkiaSharp;
5
7{
12 {
13 private LengthAttribute radiusX;
14 private LengthAttribute radiusY;
15
22 : base(Document, Parent)
23 {
24 }
25
29 public override string LocalName => "RoundedRectangle";
30
35 {
36 get => this.radiusX;
37 set => this.radiusX = value;
38 }
39
44 {
45 get => this.radiusY;
46 set => this.radiusY = value;
47 }
48
53 public override Task FromXml(XmlElement Input)
54 {
55 this.radiusX = new LengthAttribute(Input, "radiusX", this.Document);
56 this.radiusY = new LengthAttribute(Input, "radiusY", 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.radiusX?.Export(Output);
70 this.radiusY?.Export(Output);
71 }
72
79 public override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
80 {
81 return new RoundedRectangle(Document, Parent);
82 }
83
88 public override void CopyContents(ILayoutElement Destination)
89 {
90 base.CopyContents(Destination);
91
92 if (Destination is RoundedRectangle Dest)
93 {
94 Dest.radiusX = this.radiusX?.CopyIfNotPreset(Destination.Document);
95 Dest.radiusY = this.radiusY?.CopyIfNotPreset(Destination.Document);
96 }
97 }
98
104 public override async Task DoMeasureDimensions(DrawingState State)
105 {
106 await base.DoMeasureDimensions(State);
107
108 EvaluationResult<Length> RadiusLength = await this.radiusX.TryEvaluate(State.Session);
109 if (RadiusLength.Ok)
110 State.CalcDrawingSize(RadiusLength.Result, ref this.rx, true, this);
111 else
112 this.rx = 0;
113
114 RadiusLength = await this.radiusY.TryEvaluate(State.Session);
115 if (RadiusLength.Ok)
116 State.CalcDrawingSize(RadiusLength.Result, ref this.ry, false, (ILayoutElement)this);
117 else
118 this.ry = 0;
119 }
120
124 protected float rx;
125
129 protected float ry;
130
135 public override async Task Draw(DrawingState State)
136 {
137 if (this.defined)
138 {
139 SKPaint Fill = await this.TryGetFill(State);
140 if (!(Fill is null))
141 {
142 State.Canvas.DrawRoundRect(this.xCoordinate, this.yCoordinate,
143 this.xCoordinate2 - this.xCoordinate,
144 this.yCoordinate2 - this.yCoordinate,
145 this.rx, this.ry, Fill);
146 }
147
148 SKPaint Pen = await this.TryGetPen(State);
149 if (!(Pen is null))
150 {
151 State.Canvas.DrawRoundRect(this.xCoordinate, this.yCoordinate,
152 this.xCoordinate2 - this.xCoordinate,
153 this.yCoordinate2 - this.yCoordinate,
154 this.rx, this.ry, Pen);
155 }
156
157 this.defined = false;
158 await base.Draw(State);
159 this.defined = true;
160 }
161 else
162 await base.Draw(State);
163 }
164
169 public override void ExportStateAttributes(XmlWriter Output)
170 {
171 base.ExportStateAttributes(Output);
172
173 this.radiusX?.ExportState(Output);
174 this.radiusY?.ExportState(Output);
175 }
176 }
177}
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.
async Task< SKPaint > TryGetPen(DrawingState State)
Tries to get the pen associated with the element, if one is defined.
Definition: Figure.cs:111
async Task< SKPaint > TryGetFill(DrawingState State)
Tries to get the filling of the figure, if one is defined.
Definition: Figure.cs:130
override void CopyContents(ILayoutElement Destination)
Copies contents (attributes and children) to the destination element.
override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
Creates a new instance of the layout element.
override void ExportStateAttributes(XmlWriter Output)
Exports the local attributes of the current element.
override string LocalName
Local name of type of element.
override void ExportAttributes(XmlWriter Output)
Exports attributes to XML.
override async Task DoMeasureDimensions(DrawingState State)
Measures layout entities and defines unassigned properties, related to dimensions.
RoundedRectangle(Layout2DDocument Document, ILayoutElement Parent)
A rounded rectangle
override Task FromXml(XmlElement Input)
Populates the element (including children) with information from its XML definition.
override async Task Draw(DrawingState State)
Draws layout entities.
Layout2DDocument Document
Layout document.
bool defined
If element is well-defined.
Base interface for all layout elements.
Layout2DDocument Document
Layout document.