public void ExecuteDrawingInstruction_PassNull()
    {
        var stroke      = new SerializableStroke(_attributes, _points);
        var instruction = new DrawInstruction(stroke);

        Assert.Throws <ArgumentNullException>(() => instruction.ExecuteDrawingInstruction(null));
    }
    public void CtorSerializableStroke_ValidData()
    {
        var stroke      = new SerializableStroke(_attributes, _points);
        var instruction = new DrawInstruction(stroke);

        Assert.Equal(stroke, instruction.DrawingStroke);
    }
 //else this.tweenObject(this.animations.get(0).frames.get(0).getObjectFor(this.nonTransformedTempObjects[i]), nextFrame.getObjectFor(this.nonTransformedTempObjects[i]), i, currentFrame.getTime(), nextFrame.getTime());
 protected internal virtual void setInstructionRef(DrawInstruction
                                                   dI, SpriterObject obj1, SpriterObject
                                                   obj2)
 {
     dI.@ref   = obj1.getRef();
     dI.loader = obj1.getLoader();
     dI.obj    = obj1;
 }
    public void ExecuteDrawingInstruction()
    {
        var repositoryMock = new Mock <IDrawingInstructionRepository>();
        var stroke         = new SerializableStroke(_attributes, _points);
        var instruction    = new DrawInstruction(stroke);

        instruction.ExecuteDrawingInstruction(repositoryMock.Object);

        repositoryMock.Verify(instructionRepository => instructionRepository.Draw(instruction), Times.Once);
    }
    public void CtorStroke_ValidData()
    {
        var instruction = new DrawInstruction(_nonSerializableStroke);

        Assert.True(instruction.DrawingStroke.Points.SequenceEqual(_points));
        Assert.Equal(instruction.DrawingStroke.Attributes.Color, _attributes.Color);
        Assert.Equal(instruction.DrawingStroke.Attributes.Height, _attributes.Height);
        Assert.Equal(instruction.DrawingStroke.Attributes.Width, _attributes.Width);
        Assert.Equal(instruction.DrawingStroke.Attributes.IgnorePressure, _attributes.IgnorePressure);
        Assert.Equal(instruction.DrawingStroke.Attributes.IsHighlighter, _attributes.IsHighlighter);
        Assert.Equal(instruction.DrawingStroke.Attributes.StylusTip, _attributes.StylusTip);
    }
Exemple #6
0
        protected virtual void PrepareText(bool draw = false)
        {
            int dx     = 0;
            int dy     = 0;
            int height = 0;
            int width  = 0;

            if (Font?.Invoke(this) is Font current)
            {
                string text = (Text?.Invoke(this) ?? "");

                text = TextLimit == -1 || text.Length <= TextLimit ? text : text.Substring(0, TextLimit - 2) + "...";

                foreach (char c in text)
                {
                    FontChar fc;
                    if (current.CharacterMap.TryGetValue(c, out fc))
                    {
                        var sourceRectangle = new Rectangle(fc.X, fc.Y, fc.Width, fc.Height);
                        height = Math.Max(height, (int)(sourceRectangle.Height * Scale));

                        if (draw)
                        {
                            var             position    = new Vector2(dx + fc.XOffset, dy + fc.YOffset);
                            Rectangle       destination = new Rectangle((int)position.X, (int)position.Y, (int)(sourceRectangle.Width * Scale), (int)(sourceRectangle.Height * Scale));
                            DrawInstruction textDraw    = new DrawInstruction(Id + " text", current.FontPages[fc.Page], destination, sourceRectangle, Color, 0f, Vector2.Zero, Microsoft.Xna.Framework.Graphics.SpriteEffects.None, 1f);
                            AddDrawInstructions(textDraw);
                        }

                        width = (dx) + (int)(sourceRectangle.Width * Scale);
                        dx   += (int)(fc.XAdvance * Scale);
                    }
                }
            }

            if (!draw)
            {
                DefaultBounds = new Rectangle(0, 0, width, height);
                Bounds        = DefaultBounds;
            }
        }
        public override void Apply(IComponent component)
        {
            if (BackgroundColor.A != 0)
            {
                component.RemoveDrawInstructions(d => d.Tag == "bgColor");

                var bgColorInstruction = new DrawInstruction(
                    "bgColor",
                    Helper.Content.Textures.WhitePixel,
                    new Rectangle(0, 0, component.Bounds.Width, component.Bounds.Height),
                    null, BackgroundColor, 0f, Vector2.Zero, SpriteEffects.None, 1f);

                component.AddDrawInstructions(bgColorInstruction);
            }

            if (BackgroundImage?.Invoke(component) is Texture2D bgImage)
            {
                component.RemoveDrawInstructions(d => d.Tag == "bgImage");

                BackgroundBounds = new Rectangle(0, 0, bgImage.Width, bgImage.Height);

                Rectangle drawBounds = BackgroundBounds.Value;

                float fitToHeight = (float)component.Bounds.Height / (float)BackgroundBounds.Value.Height;
                float fitToWidth  = (float)component.Bounds.Width / (float)BackgroundBounds.Value.Width;
                int   tileWidth   = (int)Math.Ceiling(component.Bounds.Width / (float)drawBounds.Width);
                int   tileHeight  = (int)Math.Ceiling(component.Bounds.Height / (float)drawBounds.Height);

                switch (FillStyle)
                {
                case BackgroundFill.Stretch:
                {
                    drawBounds = new Rectangle(0, 0, component.Bounds.Width, component.Bounds.Height);
                    break;
                }

                case BackgroundFill.Contain:
                {
                    float scale = Math.Min(Math.Min(fitToHeight, fitToWidth), BackgroundMaxScale);
                    int   w     = (int)(BackgroundBounds.Value.Width * scale);
                    int   h     = (int)(BackgroundBounds.Value.Height * scale);
                    drawBounds = new Rectangle((component.Bounds.Width - w) / 2, (component.Bounds.Height - h) / 2, w, h);
                    break;
                }

                case BackgroundFill.Cover:
                {
                    float scale = Math.Max(fitToHeight, fitToWidth);
                    drawBounds = new Rectangle(0, 0, (int)(BackgroundBounds.Value.Width * scale), (int)(BackgroundBounds.Value.Height * scale));
                    break;
                }

                case BackgroundFill.TileMap:
                {
                    drawBounds = new Rectangle(0, 0, drawBounds.Width / 3, drawBounds.Height / 3);
                    break;
                }

                case BackgroundFill.Original:
                case BackgroundFill.Pattern:
                default:
                    break;
                }

                switch (FillStyle)
                {
                case BackgroundFill.Stretch:
                case BackgroundFill.Cover:
                case BackgroundFill.Contain:
                case BackgroundFill.Original:
                {
                    var bgImageInstruction = new DrawInstruction(
                        "bgImage",
                        bgImage,
                        drawBounds,
                        BackgroundSourceRectangle, Color.White * BackgroundOpacity, 0f, Vector2.Zero, SpriteEffects.None, 1f);
                    component.AddDrawInstructions(bgImageInstruction);
                    break;
                }

                case BackgroundFill.TileMap:
                {
                    if (!BackgroundSourceRectangle.HasValue)
                    {
                        BackgroundSourceRectangle = BackgroundBounds;
                    }

                    for (int x = 0; x < tileWidth; x++)
                    {
                        for (int y = 0; y < tileHeight; y++)
                        {
                            int dx                 = x == 0 ? 0 : x == tileWidth - 1 ? 2 : 1;
                            int dy                 = y == 0 ? 0 : y == tileHeight - 1 ? 2 : 1;
                            var sWidth             = BackgroundSourceRectangle.Value.Width / 3;
                            var sHeight            = BackgroundSourceRectangle.Value.Height / 3;
                            var sX                 = BackgroundSourceRectangle.Value.X;
                            var sY                 = BackgroundSourceRectangle.Value.Y;
                            var sRect              = new Rectangle(sX + (sWidth * dx), sY + (sHeight * dy), sWidth, sHeight);
                            var bgImageInstruction = new DrawInstruction(
                                "bgImage",
                                bgImage,
                                new Rectangle(x * BackgroundBounds.Value.Width, y * BackgroundBounds.Value.Height, BackgroundBounds.Value.Width, BackgroundBounds.Value.Height),
                                sRect,
                                Color.White * BackgroundOpacity, 0f, Vector2.Zero, SpriteEffects.None, 1f);
                            component.AddDrawInstructions(bgImageInstruction);
                        }
                    }
                    break;
                }

                case BackgroundFill.Pattern:
                {
                    for (int x = 0; x < tileWidth; x++)
                    {
                        for (int y = 0; y < tileHeight; y++)
                        {
                            var bgImageInstruction = new DrawInstruction(
                                "bgImage",
                                bgImage,
                                new Rectangle(drawBounds.Width * x, drawBounds.Height * y, drawBounds.Width, drawBounds.Height),
                                BackgroundSourceRectangle,
                                Color.White * BackgroundOpacity, 0f, Vector2.Zero, SpriteEffects.None, 1f);
                            component.AddDrawInstructions(bgImageInstruction);
                        }
                    }
                    break;
                }
                }
            }

            if (Image?.Invoke(component) is Texture2D image)
            {
                var imageInstruction = new DrawInstruction(
                    "image",
                    image,
                    new Rectangle(0, 0, component.Bounds.Width, component.Bounds.Height),
                    new Rectangle(0, 0, image.Width, image.Height),
                    Color.White, 0f, Vector2.Zero, SpriteEffects.None, 1f);
                component.AddDrawInstructions(imageInstruction);
            }

            base.Apply(component);
        }
        //else this.tweenBone(this.nonTransformedTempBones[i], this.animations.get(0).frames.get(0).getBoneFor(this.nonTransformedTempBones[i]), i, currentFrame.getTime(), nextFrame.getTime());
        private void tweenObject(SpriterObject currentObject
                                 , SpriterObject nextObject, int i, long startTime
                                 , long endTime)
        {
            DrawInstruction dI = this.instructions[i];

            currentObject.copyValuesTo(this.tempObjects[i]);
            SpriterAbstractObject parent = null;

            if (!currentObject.isTransientObject())
            {
                this.tempObjects[i].setTimeline((nextObject != null) ? currentObject.getTimeline(
                                                    ) : -1);
                parent = (currentObject.hasParent()) ? this.tempBones[currentObject.getParentId()
                         ] : this.tempParent;
                if (nextObject != null)
                {
                    if (parent != this.tempParent)
                    {
                        if (!currentObject.getParent().equals(nextObject.getParent()))
                        {
                            nextObject = (SpriterObject)this.getTimelineObject
                                             (currentObject, this.tempObjects2);
                            SpriterCalculator.reTranslateRelative(parent, nextObject);
                            nextObject.setAngle(nextObject.getAngle() * this.flippedX * this.flippedY);
                        }
                    }
                    else
                    {
                        if (nextObject.hasParent())
                        {
                            nextObject = (SpriterObject)this.getTimelineObject
                                             (currentObject, this.tempObjects2);
                            SpriterCalculator.reTranslateRelative(parent, nextObject);
                            nextObject.setAngle(nextObject.getAngle() * this.flippedX * this.flippedY);
                        }
                    }
                    if (this.tempObjects[i].active)
                    {
                        this.interpolateSpriterObject(this.tempObjects[i], currentObject, nextObject, startTime
                                                      , endTime);
                    }
                }
                this.moddedObjects[currentObject.getId()].modSpriterObject(this.tempObjects[i]);
                if (this.transitionFixed)
                {
                    this.tempObjects[i].copyValuesTo(this.lastFrame.getObjects()[i]);
                }
                else
                {
                    this.tempObjects[i].copyValuesTo(this.lastTempFrame.getObjects()[i]);
                }
            }
            else
            {
                parent = this.tempParent;
            }
            if (!this.tempObjects[i].hasParent())
            {
                this.tempObjects[i].setX(this.tempObjects[i].getX() + this.pivotX);
                this.tempObjects[i].setY(this.tempObjects[i].getY() + this.pivotY);
            }
            this.translateRelative(this.tempObjects[i], parent);
            if (this.moddedObjects[currentObject.getId()].getRef() != null)
            {
                this.tempObjects[i].setRef(this.moddedObjects[currentObject.getId()].getRef());
            }
            if (this.moddedObjects[currentObject.getId()].getLoader() != null)
            {
                this.tempObjects[i].setLoader(this.moddedObjects[currentObject.getId()].getLoader
                                                  ());
            }
            this.tempObjects[i].copyValuesTo(dI);
            this.setInstructionRef(dI, this.tempObjects[i], nextObject);
        }
Exemple #9
0
 public override void draw(DrawInstruction instruction)
 {
     draw(instruction.getRef(), instruction.getX(), instruction.getY(), instruction.getPivotX(),
          instruction.getPivotY(), instruction.getScaleX(), instruction.getScaleY(), instruction.getAngle(),
          instruction.getAlpha());
 }