Ejemplo n.º 1
0
        private void AssertDrawTextWithCorrectColor(ColorF expected, ColorF colorValue, AnimationFlags flags)
        {
            const float Divisor  = 255f / 128f;
            var         sequence = new Sequence
            {
                AnimationGroups = new List <Sequence.AnimationGroup>
                {
                    new Sequence.AnimationGroup
                    {
                        Animations = new List <Sequence.Animation>
                        {
                            new Sequence.Animation
                            {
                                FrameEnd   = 100,
                                Flags      = Sequence.CanHostChildFlag,
                                ColorStart = (colorValue / Divisor).ToRgba(),
                                ColorEnd   = (colorValue / Divisor).ToRgba(),
                            }
                        }
                    }
                },
                SpriteGroups = new List <List <Sequence.SpritePart> >
                {
                    new List <Sequence.SpritePart>()
                },
                Sprites = new List <Sequence.Sprite>()
            };

            var drawing         = Extensions.MockDrawing();
            var messageProvider = Substitute.For <IMessageProvider>();
            var messageRenderer = new MockMessageRenderer();
            var messageEncode   = Substitute.For <IMessageEncode>();
            var spriteTexture   = Substitute.For <ISpriteTexture>();
            var factory         = new AnimatedSequenceFactory(
                drawing,
                messageProvider,
                messageRenderer,
                messageEncode,
                sequence,
                spriteTexture);

            messageEncode.Encode(Arg.Is <List <MessageCommandModel> >(x => true))
            .Returns(new byte[] { 0x21 });

            var animation = factory.Create(new AnimatedSequenceDesc
            {
                Flags       = flags,
                MessageText = "test"
            });

            animation.Draw(0, 0);

            expected = ColorF.FromRgba(expected.ToRgba());
            Assert.True(messageRenderer.HasBeenCalled);
            Assert.Equal(expected.R, messageRenderer.LastColor.R, 2);
            Assert.Equal(expected.G, messageRenderer.LastColor.G, 2);
            Assert.Equal(expected.B, messageRenderer.LastColor.B, 2);
            Assert.Equal(expected.A, messageRenderer.LastColor.A, 2);
        }
Ejemplo n.º 2
0
        public void AnchorTextCorrectly(TextAnchor anchor, int expectedX, int expectedY)
        {
            var sequence = new Sequence
            {
                AnimationGroups = new List <Sequence.AnimationGroup>
                {
                    new Sequence.AnimationGroup
                    {
                        Animations = new List <Sequence.Animation>()
                    }
                },
                SpriteGroups = new List <List <Sequence.SpritePart> >(),
                Sprites      = new List <Sequence.Sprite>()
            };

            var drawing         = Extensions.MockDrawing();
            var messageProvider = Substitute.For <IMessageProvider>();
            var messageRenderer = new MockMessageRenderer();
            var messageEncode   = Substitute.For <IMessageEncode>();
            var spriteTexture   = Substitute.For <ISpriteTexture>();
            var factory         = new AnimatedSequenceFactory(
                drawing,
                messageProvider,
                messageRenderer,
                messageEncode,
                sequence,
                spriteTexture);

            messageEncode.Encode(Arg.Is <List <MessageCommandModel> >(x => true))
            .Returns(new byte[] { 0x21 });

            var animation = factory.Create(new AnimatedSequenceDesc
            {
                TextAnchor  = anchor,
                MessageText = "test"
            });

            animation.Draw(0, 0);

            Assert.True(messageRenderer.HasBeenCalled);
            Assert.Equal(expectedX, messageRenderer.LastPosX);
            Assert.Equal(expectedY, messageRenderer.LastPosY);
        }
Ejemplo n.º 3
0
        public void StackItemsFromChildSize(AnimationFlags flags, int uiPadding,
                                            int elementCount, int expectedLastPosX, int expectedLastPosY)
        {
            var sequence = new Sequence
            {
                AnimationGroups = new List <Sequence.AnimationGroup>
                {
                    new Sequence.AnimationGroup
                    {
                        UiPadding  = 0,
                        Animations = new List <Sequence.Animation>()
                    },
                    new Sequence.AnimationGroup
                    {
                        UiPadding  = uiPadding,
                        Animations = new List <Sequence.Animation>
                        {
                            new Sequence.Animation
                            {
                                FrameEnd = 100,
                                Flags    = Sequence.CanHostChildFlag,
                            }
                        }
                    },
                },
                SpriteGroups = new List <List <Sequence.SpritePart> >
                {
                    new List <Sequence.SpritePart>
                    {
                        new Sequence.SpritePart
                        {
                            Right  = 50,
                            Bottom = 30,
                        }
                    }
                },
                Sprites = new List <Sequence.Sprite>()
                {
                    new Sequence.Sprite()
                }
            };

            var drawing         = Extensions.MockDrawing();
            var messageProvider = Substitute.For <IMessageProvider>();
            var messageRenderer = new MockMessageRenderer();
            var messageEncode   = Substitute.For <IMessageEncode>();
            var spriteTexture   = Substitute.For <ISpriteTexture>();
            var factory         = new AnimatedSequenceFactory(
                drawing,
                messageProvider,
                messageRenderer,
                messageEncode,
                sequence,
                spriteTexture);

            var animation = factory.Create(new AnimatedSequenceDesc
            {
                SequenceIndexLoop = 0,
                Flags             = flags,
                Children          = Enumerable.Range(0, elementCount)
                                    .Select(x => new AnimatedSequenceDesc
                {
                    SequenceIndexLoop = 1,
                })
                                    .ToList()
            });

            animation.Begin();
            animation.Draw(0, 0);

            drawing.AssertCallCount(4);
            drawing.AssertDraw(3, x =>
            {
                Assert.Equal(expectedLastPosX, x.Vec0.X);
                Assert.Equal(expectedLastPosY, x.Vec0.Y);
            });
        }
Ejemplo n.º 4
0
        public void StackChildrenHorizontally()
        {
            var sequence = new Sequence
            {
                AnimationGroups = new List <Sequence.AnimationGroup>
                {
                    new Sequence.AnimationGroup
                    {
                        LightPositionX = 100,
                        Animations     = new List <Sequence.Animation>
                        {
                            new Sequence.Animation
                            {
                                FrameEnd = 100,
                                Flags    = Sequence.CanHostChildFlag,
                            }
                        }
                    }
                },
                SpriteGroups = new List <List <Sequence.SpritePart> >
                {
                    new List <Sequence.SpritePart>
                    {
                        new Sequence.SpritePart
                        {
                            Right  = 50,
                            Bottom = 30,
                        }
                    }
                },
                Sprites = new List <Sequence.Sprite>()
                {
                    new Sequence.Sprite()
                }
            };

            var drawing         = Extensions.MockDrawing();
            var messageProvider = Substitute.For <IMessageProvider>();
            var messageRenderer = new MockMessageRenderer();
            var messageEncode   = Substitute.For <IMessageEncode>();
            var spriteTexture   = Substitute.For <ISpriteTexture>();
            var factory         = new AnimatedSequenceFactory(
                drawing,
                messageProvider,
                messageRenderer,
                messageEncode,
                sequence,
                spriteTexture);

            var animation = factory.Create(new AnimatedSequenceDesc
            {
                Flags    = AnimationFlags.ChildStackHorizontally,
                Children = Enumerable.Range(0, 3)
                           .Select(x => new AnimatedSequenceDesc())
                           .ToList()
            });

            animation.Draw(0, 0);

            drawing.AssertAtLeastOneCall();
            drawing.AssertCallCount(4);
            drawing.AssertDraw(3, x =>
            {
                Assert.Equal(200, x.Vec0.X);
                Assert.Equal(0, x.Vec0.Y);
            });
        }