3using System.Threading.Tasks;
19 private SKColor? defaultColor;
20 private SKColor? bgColor;
48 : base(
Variables, DefaultWidth, DefaultHeight)
66 this.bgColor = BackgroundColor;
81 this.width = this.Settings.
Width;
82 this.height = this.Settings.
Height;
83 this.bgColor = BackgroundColor;
119 this.defaultColor =
Color;
134 Result.operations.
AddRange(G.operations);
135 Result.operations.
AddRange(this.operations);
154 Result.operations.
AddRange(this.operations);
155 Result.operations.
AddRange(G.operations);
167 this.width != G.width ||
168 this.height != G.height ||
169 this.bgColor != G.bgColor ||
170 this.defaultColor != G.defaultColor)
175 IEnumerator<CanvasOperation> e1 = this.operations.GetEnumerator();
176 IEnumerator<CanvasOperation> e2 = G.operations.GetEnumerator();
192 if (!e1.Current.Equals(e2.Current))
206 int Result = this.width.GetHashCode();
207 Result ^= Result << 5 ^ this.height.GetHashCode();
208 Result ^= Result << 5 ^ this.bgColor.GetHashCode();
209 Result ^= Result << 5 ^ this.defaultColor.GetHashCode();
226 using (SKSurface Surface = SKSurface.Create(
new SKImageInfo(this.width, this.height, SKImageInfo.PlatformColorType, SKAlphaType.Premul)))
228 SKCanvas Canvas = Surface.Canvas;
232 BgColor = this.bgColor ?? Settings.BackgroundColor
238 Op.
Draw(Canvas, State);
240 using (SKImage Result = Surface.Snapshot())
242 States = Array.Empty<
object>();
254 Output.WriteStartElement(
"CanvasGraph");
255 Output.WriteAttributeString(
"width", this.width.ToString());
256 Output.WriteAttributeString(
"height", this.height.ToString());
258 if (this.bgColor.HasValue)
261 if (this.defaultColor.HasValue)
266 Output.WriteStartElement(Op.GetType().Name);
268 Output.WriteEndElement();
271 Output.WriteEndElement();
282 foreach (XmlAttribute Attr
in Xml.Attributes)
287 this.width =
int.Parse(Attr.Value);
291 this.height =
int.Parse(Attr.Value);
306 foreach (XmlNode N
in Xml.ChildNodes)
308 if (N is XmlElement E)
310 Type T =
Types.
GetType(OperationNamespace + E.LocalName);
319 this.operations.Add(Op);
341 this.operations.Add(
new LineTo((
float)x, (
float)y));
349 this.operations.Add(
new MoveTo((
float)x, (
float)y));
359 public void Line(
double x1,
double y1,
double x2,
double y2)
361 this.operations.Add(
new Line((
float)x1, (
float)y1, (
float)x2, (
float)y2));
398 public void Rectangle(
double x1,
double y1,
double x2,
double y2)
400 this.operations.Add(
new Rectangle((
float)x1, (
float)y1, (
float)x2, (
float)y2));
412 this.operations.Add(
new FillRectangle((
float)x1, (
float)y1, (
float)x2, (
float)y2));
420 public void Plot(
double x,
double y)
422 this.operations.Add(
new Plot((
float)x, (
float)y));
432 public void Ellipse(
double x1,
double y1,
double x2,
double y2)
434 this.operations.Add(
new Ellipse((
float)x1, (
float)y1, (
float)x2, (
float)y2));
444 public void FillEllipse(
double x1,
double y1,
double x2,
double y2)
446 this.operations.Add(
new FillEllipse((
float)x1, (
float)y1, (
float)x2, (
float)y2));
454 this.operations.Add(
new Clear());
A chunked list is a linked list of chunks of objects of type T .
void AddRange(IEnumerable< T > Collection)
Adds a range of elements (last) to the list.
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.
static object Instantiate(Type Type, params object[] Arguments)
Returns an instance of the type Type . If one needs to be created, it is. If the constructor requires...
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.
static string ToExpressionString(object Value)
Converts an object 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.
CanvasGraph()
Canvas graph. Permits custom drawing from scrupt.
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.