using System;
using System.Collections.Generic;
using UnityEngine;
namespace ToolBuddy.ThirdParty.VectorGraphics
{
/// The gradient fill types.
public enum GradientFillType
{
/// A linear gradient.
Linear,
/// A radial gradient, centered at the radial focus of the gradient fill.
Radial
}
/// The path corner types, for joining path segments together.
public enum PathCorner
{
/// A tipped corner with a sharp edge.
Tipped,
/// A rounded corner.
Round,
/// A beveled corner.
Beveled
}
/// The path ending types.
public enum PathEnding
{
/// A square path ending.
Chop,
/// A square path ending with a small extrusion.
Square,
/// A rounded path ending.
Round
}
/// The fill mode types.
public enum FillMode
{
/// Determines the "insideness" of the shape by evaluating the direction of the edges crossed.
NonZero,
/// Determines the "insideness" of the shape by counting the number of edges crossed.
OddEven
}
/// The addressing mode, defining how textures or gradients behave when being addressed outside their unit range.
public enum AddressMode
{
/// Textures/gradients are wrapping around with a repeating pattern.
Wrap,
/// Textures/gradients are clamped on the borders.
Clamp,
/// Textures/gradients are repeated with a mirroring pattern.
Mirror
}
/// The gradient stops used for gradient fills.
public struct GradientStop
{
/// The color of the stop.
public Color Color { get; set; }
/// At which percentage this stop applies. Should be between 0 and 1, inclusively.
public float StopPercentage { get; set; }
}
/// A bezier segment.
///
/// Cubic Bezier segment starts from P0, flies in tangent to direction from P0 to P1,
/// then lands in direction from P2 to P3, to finally end exactly at P3.
///
public struct BezierSegment
{
/// Origin point of the segment.
public Vector2 P0;
/// First control point of the segment.
public Vector2 P1;
/// Second control point of the segment.
public Vector2 P2;
/// Ending point of the segment.
public Vector2 P3;
}
/// A bezier path segment.
///
/// Like BezierSegment but implies connectivity of segments, where segments[0].P3 is actually segments[1].P0
///
public struct BezierPathSegment
{
/// Origin point of the segment.
public Vector2 P0;
/// First control point of the segment.
public Vector2 P1;
/// Second control point of the segment.
public Vector2 P2;
}
/// A chain of bezier paths, optionnally closed.
public struct BezierContour
{
/// An array of every path segments on the contour.
/// Closed paths should not add a dedicated closing segment. It is implied by the 'closed' property.
public BezierPathSegment[] Segments { get; set; }
/// A boolean indicating if the contour should be closed.
///
/// When set to true, closed path will connect the last path segment to the first path segment, by using the
/// last path segment's P1 and P2 as control points.
///
public bool Closed { get; set; }
}
/// The IFill interface is implemented by filling techniques (solid, texture or gradient).
public interface IFill
{
/// The filling method (non-zero or even-odd) of the fill.
FillMode Mode { get; set; }
/// The opacity of the fill.
float Opacity { get; set; }
}
/// Fills a shape with a single color.
public class SolidFill : IFill
{
/// The color of the fill.
public Color Color { get; set; }
/// The opacity of the fill.
public float Opacity { get { return m_Opacity; } set { m_Opacity = value; } }
private float m_Opacity = 1.0f;
/// The filling method (non-zero or even-odd) of the fill.
public FillMode Mode { get; set; }
}
/// Fills a shape with a gradient.
///
/// Size of the fill is always assumed to cover the entire element's bounding box.
/// Radial fills are centered in the element's bounding box. Its radii are half the bounding box dimensions in each direction.
/// Linear fills start from the left edge to the right edge of the element's bounding box.
///
public class GradientFill : IFill
{
/// The fill type (linear or gradient).
public GradientFillType Type { get; set; }
/// An array of stops defining the gradient colors.
public GradientStop[] Stops { get; set; }
/// The filling method (non-zero or even-odd) of the fill.
public FillMode Mode { get; set; }
/// The opacity of the fill.
public float Opacity { get { return m_Opacity; } set { m_Opacity = value; } }
private float m_Opacity = 1.0f;
/// The adressing mode (wrap, clamp or mirror) of this fill.
public AddressMode Addressing { get; set; }
/// A position within the unit circle (-1,1) where 0 falls in the middle of the fill.
public Vector2 RadialFocus { get; set; }
}
/// Fills a shape with a texture.
public class TextureFill : IFill
{
/// The texture to fill the shape with.
public Texture2D Texture { get; set; }
/// The filling method (non-zero or even-odd) of the fill.
public FillMode Mode { get; set; }
/// The opacity of the fill.
public float Opacity { get { return m_Opacity; } set { m_Opacity = value; } }
private float m_Opacity = 1.0f;
/// The adressing mode (wrap, clamp or mirror) of this fill.
public AddressMode Addressing { get; set; }
}
/// Fills a shape with a pattern.
public class PatternFill : IFill
{
/// The filling method (non-zero or even-odd) of the fill.
public FillMode Mode { get; set; }
/// The opacity of the fill.
public float Opacity { get { return m_Opacity; } set { m_Opacity = value; } }
private float m_Opacity = 1.0f;
/// The root node of the pattern
public SceneNode Pattern { get; set; }
/// The rectangle that is repeated
public Rect Rect { get; set; }
}
/// Defines how strokes should be rendered.
public class Stroke
{
/// The stroke color.
public Color Color {
get {
var solidFill = Fill as SolidFill;
if (solidFill == null) return new Color();
return solidFill.Color;
}
set {
Fill = new SolidFill() { Color = value };
}
}
/// The stroke fill.
public IFill Fill { get; set; }
/// A transformation specific to the fill.
public Matrix2D FillTransform { get { return m_FillTransform; } set { m_FillTransform = value; } }
private Matrix2D m_FillTransform = Matrix2D.identity;
/// The stroke half-thickness.
public float HalfThickness { get; set; }
/// The stroke pattern (dashes).
/// Even entries mark a fill and odd entries mark void
public float[] Pattern { get; set; }
/// An offset to where the pattern should start.
public float PatternOffset { get; set; }
/// How far the tipped corners may extrude.
public float TippedCornerLimit { get; set; }
}
/// Defines properties of paths.
public struct PathProperties
{
/// The stroke used to render the path.
public Stroke Stroke { get; set; }
/// How the beginning of the path should be displayed.
public PathEnding Head { get; set; }
/// How the end of the path should be displayed.
public PathEnding Tail { get; set; }
/// How the corners of the path should be displayed.
public PathCorner Corners { get; set; }
}
/// A generic filled shape.
public class Shape
{
/// All the contours defining the shape.
///
/// Some of these coutours may be holes in the shape, depending on the fill mode used .
///
public BezierContour[] Contours { get; set; }
/// The fill used on the shape.
public IFill Fill { get; set; }
/// A transformation specific to the fill.
public Matrix2D FillTransform { get { return m_FillTransform; } set { m_FillTransform = value; } }
private Matrix2D m_FillTransform = Matrix2D.identity;
/// The path properties.
public PathProperties PathProps { get; set; }
/// Whether the specified contours are convex or not
///
/// Set this to true when you know the shape contours are convex.
/// This will allow for a faster tessellation process in some circumstances.
///
public bool IsConvex { get; set; }
}
/// A node inside a hierarchy.
public class SceneNode
{
/// The list of children nodes.
public List Children { get; set; }
/// The list of shapes inside this node.
public List Shapes { get; set; }
/// The transform of the node.
public Matrix2D Transform { get { return m_Transform; } set { m_Transform = value; } }
private Matrix2D m_Transform = Matrix2D.identity;
/// A clipper hierarchy that will clip this node.
public SceneNode Clipper { get; set; }
}
/// A scene contains the whole node hierarchy.
public class Scene
{
/// The root of the node hierarchy.
public SceneNode Root { get; set; }
}
} // namespace