Пример #1
0
 public static void DrawRectangle(this ISpriteDrawing drawing, float x, float y, float width, float height, ColorF color, float thickness = 1.0f)
 {
     drawing.FillRectangle(x, y, width, thickness, color);
     drawing.FillRectangle(x, y + height - 1, width - 1, thickness, color);
     drawing.FillRectangle(x, y, thickness, height, color);
     drawing.FillRectangle(x + width - 1, y, thickness, height, color);
 }
Пример #2
0
        private void Draw(DrawContext context, MessageCommandModel command)
        {
            if (command.Command == MessageCommand.PrintText)
            {
                DrawText(context, command);
            }
            else if (command.Command == MessageCommand.PrintComplex)
            {
                DrawText(context, command);
            }
            else if (command.Command == MessageCommand.PrintIcon)
            {
                DrawIcon(context, command.Data[0]);
            }
            else if (command.Command == MessageCommand.Color)
            {
                SetColor(context, command.Data);
            }
            else if (command.Command == MessageCommand.Reset)
            {
                context.Reset();
            }
            else if (command.Command == MessageCommand.Clear)
            {
                context.NewLine(_msgContext.FontHeight);
                context.y += 4;
                _drawing.FillRectangle(
                    8,
                    (float)context.y,
                    Math.Max(1.0f, (float)(context.WindowWidth - 16)),
                    2,
                    ColorF.White);
                context.y += 4;
            }
            else if (command.Command == MessageCommand.Position)
            {
                context.x = command.PositionX;
                context.y = command.PositionY;
            }
            else if (command.Command == MessageCommand.TextWidth)
            {
                context.WidthMultiplier = command.TextWidth;
            }
            else if (command.Command == MessageCommand.TextScale)
            {
                context.Scale = command.TextScale;
            }
            else if (command.Command == MessageCommand.Tabulation)
            {
                context.x += 16; // TODO this is not the real tabulation size
            }
            else if (command.Command == MessageCommand.NewLine)
            {
                context.NewLine(_msgContext.FontHeight);
            }

            context.Width  = Math.Max(context.Width, context.x);
            context.Height = Math.Max(context.Height, context.y + _msgContext.FontHeight * context.Scale);
        }
Пример #3
0
        private void DrawCenter(ISpriteDrawing drawing, float alpha)
        {
            if (!_isPivotVisible)
            {
                return;
            }

            const float Infinite = 65535f;
            var         origin   = GetOrigin(SpriteGroupModel);
            var         backgroundColorInverse = new ColorF(
                1f - _settings.EditorBackground.R,
                1f - _settings.EditorBackground.G,
                1f - _settings.EditorBackground.B,
                alpha);

            drawing.FillRectangle(origin.X, 0, 1, Infinite, backgroundColorInverse);
            drawing.FillRectangle(0, origin.Y, Infinite, 1, backgroundColorInverse);
            drawing.Flush();
        }
Пример #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;
        }