2using System.Collections.Generic;
3using System.Threading.Tasks;
17 private readonly LinkedList<CanvasOperation> operations =
new LinkedList<CanvasOperation>();
18 private SKColor? defaultColor;
19 private SKColor? bgColor;
39 : base(
Variables, DefaultWidth, DefaultHeight)
57 this.bgColor = BackgroundColor;
72 this.width = this.Settings.
Width;
73 this.height = this.Settings.
Height;
74 this.bgColor = BackgroundColor;
110 this.defaultColor =
Color;
126 Result.operations.AddLast(Op);
129 Result.operations.AddLast(Op);
149 Result.operations.AddLast(Op);
152 Result.operations.AddLast(Op);
164 this.width != G.width ||
165 this.height != G.height ||
166 this.bgColor != G.bgColor ||
167 this.defaultColor != G.defaultColor)
172 LinkedList<CanvasOperation>.Enumerator e1 = this.operations.GetEnumerator();
173 LinkedList<CanvasOperation>.Enumerator e2 = G.operations.GetEnumerator();
187 if (!e1.Current.Equals(e2.Current))
195 int Result = this.width.GetHashCode();
196 Result ^= Result << 5 ^ this.height.GetHashCode();
197 Result ^= Result << 5 ^ this.bgColor.GetHashCode();
198 Result ^= Result << 5 ^ this.defaultColor.GetHashCode();
215 using (SKSurface Surface = SKSurface.Create(
new SKImageInfo(this.width, this.height, SKImageInfo.PlatformColorType, SKAlphaType.Premul)))
217 SKCanvas Canvas = Surface.Canvas;
221 BgColor = this.bgColor ?? Settings.BackgroundColor
227 Op.
Draw(Canvas, State);
229 using (SKImage Result = Surface.Snapshot())
231 States =
new object[0];
243 Output.WriteStartElement(
"CanvasGraph");
244 Output.WriteAttributeString(
"width", this.width.ToString());
245 Output.WriteAttributeString(
"height", this.height.ToString());
247 if (this.bgColor.HasValue)
250 if (this.defaultColor.HasValue)
251 Output.WriteAttributeString(
"defaultColor",
Expression.
ToString(
this.defaultColor.Value));
255 Output.WriteStartElement(Op.GetType().Name);
257 Output.WriteEndElement();
260 Output.WriteEndElement();
271 foreach (XmlAttribute Attr
in Xml.Attributes)
276 this.width =
int.Parse(Attr.Value);
280 this.height =
int.Parse(Attr.Value);
295 foreach (XmlNode N
in Xml.ChildNodes)
297 if (N is XmlElement E)
299 Type T =
Types.
GetType(OperationNamespace + E.LocalName);
308 this.operations.AddLast(Op);
330 this.operations.AddLast(
new LineTo((
float)x, (
float)y));
338 this.operations.AddLast(
new MoveTo((
float)x, (
float)y));
348 public void Line(
double x1,
double y1,
double x2,
double y2)
350 this.operations.AddLast(
new Line((
float)x1, (
float)y1, (
float)x2, (
float)y2));
387 public void Rectangle(
double x1,
double y1,
double x2,
double y2)
389 this.operations.AddLast(
new Rectangle((
float)x1, (
float)y1, (
float)x2, (
float)y2));
401 this.operations.AddLast(
new FillRectangle((
float)x1, (
float)y1, (
float)x2, (
float)y2));
409 public void Plot(
double x,
double y)
411 this.operations.AddLast(
new Plot((
float)x, (
float)y));
421 public void Ellipse(
double x1,
double y1,
double x2,
double y2)
423 this.operations.AddLast(
new Ellipse((
float)x1, (
float)y1, (
float)x2, (
float)y2));
433 public void FillEllipse(
double x1,
double y1,
double x2,
double y2)
435 this.operations.AddLast(
new FillEllipse((
float)x1, (
float)y1, (
float)x2, (
float)y2));
443 this.operations.AddLast(
new Clear());
Static class that dynamically manages types and interfaces available in the runtime environment.
static Type GetType(string FullName)
Gets a type, given its full name.
Base class for all types of elements.
Class managing a script expression.
static string ToString(double Value)
Converts a value to a string, that can be parsed as part of an expression.
Canvas graph. Permits custom drawing from scrupt.
void Rectangle(double x1, double y1, double x2, double y2)
Draws a rectangle defined by two opposing corner points.
void PenWidth(double Width)
Sets the current pen width.
override bool UsesDefaultColor
If graph uses default color
CanvasGraph(Variables Variables, int? DefaultWidth, int? DefaultHeight)
Canvas graph. Permits custom drawing from scrupt.
void FillRectangle(double x1, double y1, double x2, double y2)
Fills a rectangle defined by two opposing corner points.
void Color(SKColor Color)
Sets the current pen color.
int Width
Width, in puxels.
CanvasGraph(Variables Variables, int Width, int Height, SKColor? DefaultColor, SKColor? BackgroundColor)
Canvas graph. Permits custom drawing from scrupt.
void Color(object Color)
Sets the current pen color.
override string GetBitmapClickScript(double X, double Y, object[] States)
Gets script corresponding to a point in a generated bitmap representation of the graph.
SKColor? BgColor
Background color.
override ISemiGroupElement AddRight(ISemiGroupElement Element)
Tries to add an element to the current element, from the right.
CanvasGraph(GraphSettings Settings, int Width, int Height, SKColor? DefaultColor, SKColor? BackgroundColor)
Canvas graph. Permits custom drawing from scrupt.
override void ExportGraph(XmlWriter Output)
Exports graph specifics to XML.
void LineTo(double x, double y)
Draws a line to a specific coordinate
void Clear()
Clears the canvas with the current brush.
int Height
Height, in puxels.
override bool TrySetDefaultColor(SKColor Color)
Tries to set the default color.
void FillEllipse(double x1, double y1, double x2, double y2)
Fills a ellipse defined by two opposing corner points.
override int GetHashCode()
Calculates a hash code of the element. Hash code.
override bool Equals(object obj)
Compares the element to another. If elements are equal.
override ISemiGroupElement AddLeft(ISemiGroupElement Element)
Tries to add an element to the current element, from the left.
CanvasGraph(Variables Variables)
Canvas graph. Permits custom drawing from scrupt.
void Ellipse(double x1, double y1, double x2, double y2)
Draws a ellipse defined by two opposing corner points.
void Line(double x1, double y1, double x2, double y2)
Draws a line between two points.
void MoveTo(double x, double y)
Draws a line to a specific coordinate
override PixelInformation CreatePixels(GraphSettings Settings, out object[] States)
Creates a bitmap of the graph.
new? SKColor DefaultColor
Default color.
override async Task ImportGraphAsync(XmlElement Xml)
Imports graph specifics from XML.
void Plot(double x, double y)
Plots a pixel at a given coordinate.
Abstract base class for canvas operations.
abstract void ExportGraph(XmlWriter Output)
Exports graph specifics to XML.
abstract override int GetHashCode()
abstract void Draw(SKCanvas Canvas, CanvasState State)
Performs a drawing operation.
Current drawing state in a canvas graph.
SKColor BgColor
Background color
Draws a line to a specific coordinate
Moves to a new coordinate.
Sets the current pen color.
Sets the current pen width.
Plots a pixel at a given coordinate.
static readonly SKColor DefaultColor
Default color: Red
GraphSettings Settings
Graph settings available during creation.
static SKColor ToColor(object Object)
Converts an object to a color.
static async Task< IElement > ParseAsync(string s, Variables Variables)
Parses an element expression string.
SKColor BackgroundColor
Background color.
int Width
Width of graph, in pixels. (Default=640 pixels.)
int Height
Height of graph, in pixels. (Default=480 pixels.)
Basic interface for all types of semigroup elements.