public void FadeColour(SRGBColour newColour, int duration, EasingTypes easing = EasingTypes.None)
        {
            UpdateTransformsOfType(typeof(TransformColour));
            Color4 startValue = (Transforms.FindLast(t => t is TransformColour) as TransformColour)?.EndValue ?? Colour.Linear;

            if (transformationDelay == 0)
            {
                Transforms.RemoveAll(t => t is TransformColour);
                if (startValue == newColour)
                {
                    return;
                }
            }

            double startTime = Clock != null ? (Time.Current + transformationDelay) : 0;

            TransformColour transform = new TransformColour
            {
                StartTime  = startTime,
                EndTime    = startTime + duration,
                StartValue = startValue,
                EndValue   = newColour.Linear,
                Easing     = easing
            };

            if (Clock == null)
            {
                transform.UpdateTime(new FrameTimeInfo {
                    Current = transform.EndTime
                });
                transform.Apply(this);
            }
            else if (duration == 0 && transformationDelay == 0)
            {
                transform.UpdateTime(Time);
                transform.Apply(this);
            }
            else
            {
                Transforms.Add(transform);
            }
        }
示例#2
0
        public void FlashColour(SRGBColour flashColour, int duration)
        {
            Debug.Assert(transformationDelay == 0, @"FlashColour doesn't support Delay() currently");

            Color4 startValue = (Transforms.FindLast(t => t is TransformColour) as TransformColour)?.EndValue ?? Colour.Linear;

            Transforms.RemoveAll(t => t is TransformColour);

            double startTime = Time.Current + transformationDelay;

            // We need to pass colours in linear space, since colour transformations work in linear colour space.
            Transforms.Add(new TransformColour
            {
                StartTime  = startTime,
                EndTime    = startTime + duration,
                StartValue = flashColour.Linear,
                EndValue   = startValue,
            });

            return;
        }
示例#3
0
        public void Test_SRGBColour_Construct()
        {
            var rgb = new SRGBColour();

            rgb.R.Should().Be(0);
            rgb.G.Should().Be(0);
            rgb.B.Should().Be(0);
            rgb.A.Should().Be(0); // Blegh!!

            rgb = new SRGBColour(11, 22, 33);
            rgb.R.Should().Be(11);
            rgb.G.Should().Be(22);
            rgb.B.Should().Be(33);
            rgb.A.Should().Be(255);

            rgb = new SRGBColour(11, 22, 33, 44);
            rgb.R.Should().Be(11);
            rgb.G.Should().Be(22);
            rgb.B.Should().Be(33);
            rgb.A.Should().Be(44);
        }
        public void FlashColour(SRGBColour flashColour, int duration, EasingTypes easing = EasingTypes.None)
        {
            Debug.Assert(transformationDelay == 0, @"FlashColour doesn't support Delay() currently");

            Color4 startValue = (Transforms.FindLast(t => t is TransformColour) as TransformColour)?.EndValue ?? Colour.Linear;

            Transforms.RemoveAll(t => t is TransformColour);

            double startTime = Clock != null ? (Time.Current + transformationDelay) : 0;

            TransformColour transform = new TransformColour
            {
                StartTime  = startTime,
                EndTime    = startTime + duration,
                StartValue = flashColour.Linear,
                EndValue   = startValue,
                Easing     = easing
            };

            if (Clock == null)
            {
                transform.UpdateTime(new FrameTimeInfo {
                    Current = transform.EndTime
                });
                transform.Apply(this);
            }
            else if (duration == 0 && transformationDelay == 0)
            {
                transform.UpdateTime(Time);
                transform.Apply(this);
            }
            else
            {
                Transforms.Add(transform);
            }
        }
示例#5
0
        public override void DrawTriangle(Triangle vertexTriangle, RectangleF?textureRect, ColourInfo drawColour, Action <TexturedVertex2D> vertexAction = null, Vector2?inflationPercentage = null)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(ToString(), "Can not draw a triangle with a disposed texture.");
            }

            RectangleF texRect         = GetTextureRect(textureRect);
            Vector2    inflationAmount = inflationPercentage.HasValue ? new Vector2(inflationPercentage.Value.X * texRect.Width, inflationPercentage.Value.Y * texRect.Height) : Vector2.Zero;
            RectangleF inflatedTexRect = texRect.Inflate(inflationAmount);

            if (vertexAction == null)
            {
                vertexAction = default_triangle_action;
            }

            // We split the triangle into two, such that we can obtain smooth edges with our
            // texture coordinate trick. We might want to revert this to drawing a single
            // triangle in case we ever need proper texturing, or if the additional vertices
            // end up becoming an overhead (unlikely).
            SRGBColour topColour    = (drawColour.TopLeft + drawColour.TopRight) / 2;
            SRGBColour bottomColour = (drawColour.BottomLeft + drawColour.BottomRight) / 2;

            // Left triangle half
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexTriangle.P0,
                TexturePosition = new Vector2(inflatedTexRect.Left, inflatedTexRect.Top),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = topColour.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexTriangle.P1,
                TexturePosition = new Vector2(inflatedTexRect.Left, inflatedTexRect.Bottom),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = drawColour.BottomLeft.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = (vertexTriangle.P1 + vertexTriangle.P2) / 2,
                TexturePosition = new Vector2((inflatedTexRect.Left + inflatedTexRect.Right) / 2, inflatedTexRect.Bottom),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = bottomColour.Linear,
            });

            // Right triangle half
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexTriangle.P0,
                TexturePosition = new Vector2(inflatedTexRect.Right, inflatedTexRect.Top),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = topColour.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = (vertexTriangle.P1 + vertexTriangle.P2) / 2,
                TexturePosition = new Vector2((inflatedTexRect.Left + inflatedTexRect.Right) / 2, inflatedTexRect.Bottom),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = bottomColour.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexTriangle.P2,
                TexturePosition = new Vector2(inflatedTexRect.Right, inflatedTexRect.Bottom),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = drawColour.BottomRight.Linear,
            });

            FrameStatistics.Add(StatisticsCounterType.Pixels, (long)vertexTriangle.ConservativeArea);
        }
示例#6
0
 public static SRGBColour ValueAt(double time, SRGBColour startColour, SRGBColour endColour, double startTime, double endTime, Easing easing = Easing.None) =>
 ValueAt(time, (Color4)startColour, (Color4)endColour, startTime, endTime, easing);
示例#7
0
 public static SRGBColour ValueAt(double time, SRGBColour startColour, SRGBColour endColour, double startTime, double endTime, Easing easing = Easing.None)
 => ValueAt(time, startColour, endColour, startTime, endTime, new DefaultEasingFunction(easing));
示例#8
0
        public override void DrawTriangle(Triangle vertexTriangle, RectangleF?textureRect, ColourInfo drawColour, Action <TexturedVertex2D> vertexAction = null, Vector2?inflationPercentage = null)
        {
            Debug.Assert(!IsDisposed);

            RectangleF texRect         = GetTextureRect(textureRect);
            Vector2    inflationAmount = inflationPercentage.HasValue ? new Vector2(inflationPercentage.Value.X * texRect.Width, inflationPercentage.Value.Y * texRect.Height) : Vector2.Zero;
            RectangleF inflatedTexRect = texRect.Inflate(inflationAmount);

            if (vertexAction == null)
            {
                if (triangleBatch == null)
                {
                    // We multiply the size param by 3 such that the amount of vertices is a multiple of the amount of vertices
                    // per primitive (triangles in this case). Otherwise overflowing the batch will result in wrong
                    // grouping of vertices into primitives.
                    triangleBatch = new LinearBatch <TexturedVertex2D>(512 * 3, 128, PrimitiveType.Triangles);
                }
                vertexAction = triangleBatch.Add;
            }

            // We split the triangle into two, such that we can obtain smooth edges with our
            // texture coordinate trick. We might want to revert this to drawing a single
            // triangle in case we ever need proper texturing, or if the additional vertices
            // end up becoming an overhead (unlikely).
            SRGBColour topColour    = (drawColour.TopLeft + drawColour.TopRight) / 2;
            SRGBColour bottomColour = (drawColour.BottomLeft + drawColour.BottomRight) / 2;

            // Left triangle half
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexTriangle.P0,
                TexturePosition = new Vector2(inflatedTexRect.Left, inflatedTexRect.Top),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = topColour.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexTriangle.P1,
                TexturePosition = new Vector2(inflatedTexRect.Left, inflatedTexRect.Bottom),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = drawColour.BottomLeft.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = (vertexTriangle.P1 + vertexTriangle.P2) / 2,
                TexturePosition = new Vector2((inflatedTexRect.Left + inflatedTexRect.Right) / 2, inflatedTexRect.Bottom),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = bottomColour.Linear,
            });

            // Right triangle half
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexTriangle.P0,
                TexturePosition = new Vector2(inflatedTexRect.Right, inflatedTexRect.Top),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = topColour.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = (vertexTriangle.P1 + vertexTriangle.P2) / 2,
                TexturePosition = new Vector2((inflatedTexRect.Left + inflatedTexRect.Right) / 2, inflatedTexRect.Bottom),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = bottomColour.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexTriangle.P2,
                TexturePosition = new Vector2(inflatedTexRect.Right, inflatedTexRect.Bottom),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = inflationAmount,
                Colour          = drawColour.BottomRight.Linear,
            });

            FrameStatistics.Increment(StatisticsCounterType.KiloPixels, (long)vertexTriangle.ConservativeArea);
        }
示例#9
0
 public void TransformBorderTo(SRGBColour colour)
 => this.TransformTo(nameof(BorderColour), colour, 250, Easing.OutQuint);
示例#10
0
 public static SRGBColourAssertions Should(this SRGBColour value)
 => new SRGBColourAssertions(value);
示例#11
0
 public SrgbProvider(SRGBColour color)
 {
     _color = color;
 }