 |
VectSharp
2.2.1
A light library for C# vector graphics
|
19 using System.Collections;
20 using System.Collections.Generic;
21 using System.Collections.Immutable;
129 this.
Offset = Math.Max(0, Math.Min(1, offset));
157 public int Count => gradientStops.Count;
159 private ImmutableList<GradientStop> gradientStops {
get;
set; }
164 return ((IEnumerable<GradientStop>)gradientStops).GetEnumerator();
167 IEnumerator IEnumerable.GetEnumerator()
169 return ((IEnumerable)gradientStops).GetEnumerator();
178 List<GradientStop> stops = (from el in gradientStops orderby el.Offset ascending select el).ToList();
180 if (stops.Count == 0)
185 if (stops[0].Offset > 0)
190 if (stops[stops.Count - 1].Offset < 1)
192 stops.Add(
new GradientStop(stops[stops.Count - 1].Colour, 1));
195 for (
int i = 1; i < stops.Count - 1; i++)
197 bool closeToPrevious = (stops[i].Offset - stops[i - 1].Offset <
StopTolerance);
198 bool closeToNext = (stops[i + 1].Offset - stops[i].Offset <
StopTolerance);
200 if (closeToPrevious && !closeToNext)
204 else if (!closeToPrevious && closeToNext)
208 else if (closeToPrevious && closeToNext)
215 this.gradientStops = ImmutableList.Create(stops.ToArray());
280 List<GradientStop> stops = (from el in gradientStops orderby el.Offset ascending select el).ToList();
282 if (stops.Count == 0)
287 if (stops[0].Offset > 0)
292 if (stops[stops.Count - 1].Offset < 1)
294 stops.Add(
new GradientStop(stops[stops.Count - 1].Colour, 1));
310 Stack<double[,]> transformMatrix =
new Stack<double[,]>();
311 double[,] currMatrix =
new double[3, 3] { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
313 for (
int i = 0; i < referenceGraphics.Actions.Count; i++)
315 if (referenceGraphics.Actions[i] is TransformAction)
317 TransformAction trf = referenceGraphics.Actions[i] as TransformAction;
319 if (trf.Delta !=
null)
321 currMatrix =
Graphics.Multiply(currMatrix,
Graphics.TranslationMatrix(trf.Delta.Value.X, trf.Delta.Value.Y));
323 else if (trf.Angle !=
null)
325 currMatrix =
Graphics.Multiply(currMatrix,
Graphics.RotationMatrix(trf.Angle.Value));
327 else if (trf.Scale !=
null)
329 currMatrix =
Graphics.Multiply(currMatrix,
Graphics.ScaleMatrix(trf.Scale.Value.Width, trf.Scale.Value.Height));
331 else if (trf.Matrix !=
null)
333 currMatrix =
Graphics.Multiply(currMatrix, trf.Matrix);
336 else if (referenceGraphics.Actions[i] is StateAction)
338 if (((StateAction)referenceGraphics.Actions[i]).StateActionType == StateAction.StateActionTypes.Save)
340 transformMatrix.Push(currMatrix);
344 currMatrix = transformMatrix.Pop();
349 currMatrix =
Graphics.Invert(currMatrix);
393 if (
new Point(focalPoint.
X - centre.
X, focalPoint.
Y - centre.
Y).
Modulus() > radius)
396 focalPoint =
new Point(centre.
X + norm.
X * radius, centre.
Y + norm.
Y * radius);
403 List<GradientStop> stops = (from el in gradientStops orderby el.Offset ascending select el).ToList();
405 if (stops.Count == 0)
410 if (stops[0].Offset > 0)
415 if (stops[stops.Count - 1].Offset < 1)
417 stops.Add(
new GradientStop(stops[stops.Count - 1].Colour, 1));
432 if (
new Point(focalPoint.
X - centre.
X, focalPoint.
Y - centre.
Y).
Modulus() > radius)
435 focalPoint =
new Point(centre.
X + norm.
X * radius, centre.
Y + norm.
Y * radius);
442 List<GradientStop> stops = (from el in gradientStops orderby el.Offset ascending select el).ToList();
444 if (stops.Count == 0)
449 if (stops[0].Offset > 0)
454 if (stops[stops.Count - 1].Offset < 1)
456 stops.Add(
new GradientStop(stops[stops.Count - 1].Colour, 1));
LinearGradientBrush(Point startPoint, Point endPoint, params GradientStop[] gradientStops)
Creates a new LinearGradientBrush with the specified start point, end point and gradient stops.
Represents a read-only list of GradientStops.
override Brush MultiplyOpacity(double opacity)
Returns a brush corresponding the current instance, with the specified opacity multiplication applie...
double R
Red component of the colour. Range: [0, 1].
Represents an RGB colour.
double Offset
The offset of the gradient stop. Range: [0, 1].
double R
Red component of the colour. Range: [0, 1].
double A
Alpha component of the colour. Range: [0, 1].
LinearGradientBrush RelativeTo(Graphics referenceGraphics)
Returns a LinearGradientBrush with the same gradient stops as the current instance,...
GradientStops(IEnumerable< GradientStop > gradientStops)
Creates a new GradientStops instance containing the specified gradient stops.
static readonly double StopTolerance
The minimum distance that is enforced between consecutive gradient stops.
Represents a brush used to fill or stroke graphics elements. This could be a solid colour,...
Represents a brush painting with a radial gradient.
GradientStops GradientStops
The colour stops in the gradient.
double A
Alpha component of the colour. Range: [0, 1].
RadialGradientBrush(Point focalPoint, Point centre, double radius, params GradientStop[] gradientStops)
Creates a new RadialGradientBrush with the specified focal point, centre, radius and gradient stops.
override Brush MultiplyOpacity(double opacity)
Returns a brush corresponding the current instance, with the specified opacity multiplication applie...
double Modulus()
Computes the modulus of the vector represented by the Point.
LinearGradientBrush(Point startPoint, Point endPoint, IEnumerable< GradientStop > gradientStops)
Creates a new LinearGradientBrush with the specified start point, end point and gradient stops.
Represents an abstract drawing surface.
static Colour WithAlpha(Colour original, double alpha)
Create a new Colour with the same RGB components as the original Colour, but with the specified alph...
double G
Green component of the colour. Range: [0, 1].
Point EndPoint
The end point of the gradient. Note that this is relative to the current coordinate system when the g...
Represents a colour stop in a gradient.
double Radius
The radius of the gradient.
Represents a brush painting with a gradient.
SolidColourBrush(Colour colour)
Creates a new SolidColourBrush with the specified colour .
IEnumerator< GradientStop > GetEnumerator()
Point StartPoint
The starting point of the gradient. Note that this is relative to the current coordinate system when ...
double B
Blue component of the colour. Range: [0, 1].
double X
Horizontal (x) coordinate, measured to the right of the origin.
GradientStop MultiplyOpacity(double opacity)
Returns a GradientStop corresponding to the current instance, whose colour's opacity has been multipl...
Represents a brush painting with a linear gradient.
GradientStops(params GradientStop[] gradientStops)
Creates a new GradientStops instance containing the specified gradient stops.
Point Centre
Represents the centre of the gradient.
Represents a brush painting with a single solid colour.
Point Normalize()
Normalises a Point.
Represents a point relative to an origin in the top-left corner.
Point FocalPoint
The focal point of the gradient (i.e. the point within the circle where the gradient starts).
double B
Blue component of the colour. Range: [0, 1].
override Brush MultiplyOpacity(double opacity)
Returns a brush corresponding the current instance, with the specified opacity multiplication applie...
double G
Green component of the colour. Range: [0, 1].
double Y
Vertical (y) coordinate, measured to the bottom of the origin.
GradientStop(Colour colour, double offset)
Creates a new GradientStop instance.
abstract Brush MultiplyOpacity(double opacity)
Returns a brush corresponding the current instance, with the specified opacity multiplication applie...
RadialGradientBrush(Point focalPoint, Point centre, double radius, IEnumerable< GradientStop > gradientStops)
Creates a new RadialGradientBrush with the specified focal point, centre, radius and gradient stops.
static Colour FromRgba(double r, double g, double b, double a)
Create a new colour from RGBA (red, green, blue and alpha) values.