Esempio n. 1
0
        private static Color4[] EllipseUniform(Ellipse ellipse, IColorResource color, int numVertex, int slices)
        {
            var solidColor = (SolidColor)color;

            Color4[] colors = new Color4[numVertex];
            for (int i = 0; i < numVertex; i++)
            {
                colors[i] = solidColor.Color;
            }
            return(colors);
        }
Esempio n. 2
0
        static Color4[] RectangleUniform(IColorResource color, int widthSegments, int heightSegments)
        {
            var solidColor = (SolidColor)color;

            Color4[] colors = new Color4[widthSegments * heightSegments];
            int      index  = colors.Length - 1;;

            for (int i = 0; i < heightSegments; i++)
            {
                for (int j = 0; j < widthSegments; j++)
                {
                    colors[index--] = solidColor.Color;
                }
            }
            return(colors);
        }
Esempio n. 3
0
        static Color4[] RectangleHorizontal(IColorResource color, int widthSegments, int heightSegments)
        {
            var gradient = (IGradient)color;

            Color4[] colors = new Color4[widthSegments * heightSegments];
            int      index  = colors.Length - 1;;

            for (int i = 0; i < heightSegments; i++)
            {
                for (int j = 0; j < widthSegments; j++)
                {
                    colors[index--] = gradient.GradientStops[j].Color;
                }
            }
            return(colors);
        }
Esempio n. 4
0
        static EllipseColorShader ChooseEllipseOutlineShader(float innerRadiusRatio, IColorResource color, out float[] ringOffsets)
        {
            EllipseColorShader shader;

            switch (color.Type)
            {
            case ColorType.SolidColor:
            case ColorType.RadialGradient:
                ringOffsets = ((IGradient)color).GradientStops.Select(g => (float)MathHelper.ConvertRange(0, 1, innerRadiusRatio, 1, g.Offset)).ToArray();
                shader      = EllipseOutlineRadial;
                break;

            default:
                throw new NotSupportedException(String.Format("Gradient `{0}' is not supported by EllipseOutline", color.Type));
            }
            return(shader);
        }
Esempio n. 5
0
        static EllipseColorShader ChooseEllipseShader(IColorResource color, out float[] ringOffsets)
        {
            EllipseColorShader shader;

            switch (color.Type)
            {
            case ColorType.SolidColor:
                ringOffsets = new[] { 0f, 1f };
                shader      = EllipseUniform;
                break;

            case ColorType.LinearGradient:
                var gLinear = (LinearGradient)color;

                if (gLinear.GradientStops.Count > 2)
                {
                    throw new NotSupportedException("Ellipse supports only two linear gradient stops");
                }

                ringOffsets = gLinear.GradientStops.Select(g => g.Offset).ToArray();
                Vector2 direction = gLinear.EndPoint - gLinear.StartPoint;
                if (direction == Vector2.UnitY)
                {
                    shader = EllipseVertical;
                }
                else if (direction == Vector2.UnitX)
                {
                    shader = EllipseHorizontal;
                }
                else
                {
                    throw new NotSupportedException("Non axis-aligned gradient are not supported");
                }
                break;

            case ColorType.RadialGradient:
                ringOffsets = ((IGradient)color).GradientStops.Select(g => g.Offset).ToArray();
                shader      = EllipseRadial;
                break;

            default:
                throw new NotSupportedException(String.Format("Gradient `{0}' is not supported by Ellipse", color.Type));
            }
            return(shader);
        }
Esempio n. 6
0
        private static Color4[] EllipseOutlineRadial(Ellipse ellipse, IColorResource color, int numVertex, int slices)
        {
            var gradient = (IGradient)color;

            Color4[] colors = new Color4[numVertex];
            int      k      = 0;

            for (int i = 0; i < colors.Length; i++)
            {
                if (i > 0 && i % slices == 0)
                {
                    k++;
                }
                colors[i] = gradient.GradientStops[k].Color;
            }

            return(colors);
        }
Esempio n. 7
0
        private static Color4[] EllipseHorizontal(Ellipse ellipse, IColorResource color, int numVertex, int slices)
        {
            var gradient = (IGradient)color;

            // Only one ellipse ring is supported
            Color4[] colors         = new Color4[numVertex];
            float    horizontalAxis = ellipse.HorizontalAxis;

            var vertices = ellipse.CalculateVertices(slices).ToArray();

            for (int i = 0; i < vertices.Length; i++)
            {
                float r = Math.Abs(vertices[i].X - ellipse.Center.X - ellipse.RadiusX) / horizontalAxis;
                colors[i + 1] = gradient.GradientStops.Evaluate(r);
            }

            // Color of the center vertex is equal to the color of the top or bottom vertex
            colors[0] = colors[slices / 4 + 1];

            return(colors);
        }
Esempio n. 8
0
        static RectangleColorShader ChooseShader(IColorResource color, out float[] widthSegments, out float[] heightSegments)
        {
            RectangleColorShader shader;

            switch (color.Type)
            {
            default:
            case ColorType.SolidColor:
                widthSegments  = new[] { 0f, 1f };
                heightSegments = new[] { 0f, 1f };
                shader         = RectangleUniform;
                break;

            case ColorType.LinearGradient:
                var     gLinear   = (LinearGradient)color;
                Vector2 direction = gLinear.EndPoint - gLinear.StartPoint;
                if (direction == Vector2.UnitY)
                {
                    widthSegments  = new[] { 0f, 1f };
                    heightSegments = gLinear.GradientStops.Select(gs => gs.Offset).ToArray();
                    shader         = RectangleVertical;
                }
                else if (direction == Vector2.UnitX)
                {
                    widthSegments  = gLinear.GradientStops.Select(gs => gs.Offset).ToArray();
                    heightSegments = new[] { 0f, 1f };
                    shader         = RectangleHorizontal;
                }
                else
                {
                    throw new NotSupportedException("Non axis-aligned gradient are not supported");
                }
                break;

            case ColorType.RadialGradient:
                throw new NotSupportedException("Rectangle does not support radial gradient");
            }
            return(shader);
        }
Esempio n. 9
0
 public SetColorInstruction(IColorResource color)
 {
     this.color = color;
 }