Пример #1
0
        private void DrawFrame(Context context, Sequence.Sprite frame)
        {
            var drawContext = new SpriteDrawingContext()
                              .SpriteTexture(surface)
                              .SourceLTRB(frame.Left, frame.Top, frame.Right, frame.Bottom)
                              .Position(context.Left, context.Top)
                              .DestinationSize(context.Right - context.Left, context.Bottom - context.Top)
                              .Traslate(context.PivotX, context.PivotY)
                              .ScaleSize(context.ScaleX, context.ScaleY)
                              .RotateX(-context.RotationX)
                              .RotateY(-context.RotationY)
                              .RotateZ(-context.RotationZ)
                              .Traslate(context.PositionX, context.PositionY);

            drawContext.Color0 = ConvertColor(frame.ColorLeft);
            drawContext.Color1 = ConvertColor(frame.ColorTop);
            drawContext.Color2 = ConvertColor(frame.ColorRight);
            drawContext.Color3 = ConvertColor(frame.ColorBottom);
            drawContext.ColorMultiply(context.Color);
            drawContext.BlendMode = (BlendMode)context.ColorBlendMode;

            if (frame.UTranslation != 0) // HACK to increase performance
            {
                drawContext.TextureWrapHorizontal(TextureWrapMode.Repeat, Math.Min(frame.Left, frame.Right), Math.Max(frame.Left, frame.Right));
                drawContext.TextureHorizontalShift = frame.UTranslation * context.GlobalFrameIndex;
            }

            if (frame.VTranslation != 0) // HACK to increase performance
            {
                drawContext.TextureWrapVertical(TextureWrapMode.Repeat, Math.Min(frame.Top, frame.Bottom), Math.Max(frame.Top, frame.Bottom));
                drawContext.TextureVerticalShift = frame.VTranslation * context.GlobalFrameIndex;
            }

            drawing.AppendSprite(drawContext);
        }
Пример #2
0
 protected void DrawImage(ISpriteTexture texture, double x, double y, int sourceX, int sourceY, int width, int height, double scaleX, double scaleY, ColorF color) =>
 _drawing.AppendSprite(new SpriteDrawingContext()
                       .Source(sourceX, sourceY, width, height)
                       .MatchSourceSize()
                       .ScaleSize((float)scaleX, (float)scaleY)
                       .Traslate((float)x, (float)y)
                       .Color(color)
                       .SpriteTexture(texture));
Пример #3
0
 public static void FillRectangle(this ISpriteDrawing drawing, float x, float y, float width, float height, ColorF color)
 {
     drawing.AppendSprite(new SpriteDrawingContext()
                          .Source(0, 0, 1, 1)
                          .Position(x, y)
                          .DestinationSize(width, height)
                          .Color(color));
 }
Пример #4
0
        private void DrawCropAtlasTexture()
        {
            var sLeft     = SpriteModel.Sprite.Left;
            var sTop      = SpriteModel.Sprite.Top;
            var sRight    = SpriteModel.Sprite.Right;
            var sBottom   = SpriteModel.Sprite.Bottom;
            var cropColor = _settings.EditorBackground;

            cropColor.A = 0.75f;
            var invertedCropColor = new ColorF(
                1f - cropColor.R, 1f - cropColor.G,
                1f - cropColor.G, 1.0f);

            var context = new SpriteDrawingContext()
                          .SpriteTexture(_atlasTexture)
                          .ColorDefault()
                          .SourceLTRB(0, 0, _cropAtlasTexture.Width, _cropAtlasTexture.Height)
                          .Position(0, 0)
                          .DestinationSize(_cropAtlasTexture.Width, _cropAtlasTexture.Height);

            context.TextureWrapHorizontal(TextureWrapMode.Repeat, 0, _cropAtlasTexture.Width);
            context.TextureWrapVertical(TextureWrapMode.Repeat, 0, _cropAtlasTexture.Height);

            _spriteDrawing.DestinationTexture = _cropAtlasTexture;
            _spriteDrawing.SetViewport(0, _cropAtlasTexture.Width, 0, _cropAtlasTexture.Height);
            _spriteDrawing.Clear(_settings.EditorBackground);
            _spriteDrawing.AppendSprite(context);

            _spriteDrawing.FillRectangle(0, 0, _cropAtlasTexture.Width, sTop, cropColor);
            _spriteDrawing.FillRectangle(0, sTop, sLeft, sBottom - sTop, cropColor);
            _spriteDrawing.FillRectangle(sRight, sTop, _cropAtlasTexture.Width, sBottom - sTop, cropColor);
            _spriteDrawing.FillRectangle(0, sBottom, _cropAtlasTexture.Width, _cropAtlasTexture.Height, cropColor);
            _spriteDrawing.DrawRectangle(sLeft - 1, sTop - 1,
                                         sRight - sLeft + 2, sBottom - sTop + 2, invertedCropColor);

            _spriteDrawing.Flush();
            _spriteDrawing.DestinationTexture = null;
        }