Пример #1
0
 public override void DrawRectangle(Rectangle area, Brush brush, Thickness thickness, double radius,
     Rectangle bounds)
 {
     SetClipArea(bounds);
     if (area != Rectangle.Empty)
     {
         if (radius > 0)
         {
             FillRectangle(area, brush, radius, bounds);
         }
         else
         {
             var areaXNA = area.ToXNA();
             FillRect(new RectangleXNA(areaXNA.X,
                 areaXNA.Top, areaXNA.Width, thickness.Top), brush);
             FillRect(new RectangleXNA(areaXNA.X,
                 areaXNA.Top + thickness.Top, thickness.Left, areaXNA.Height - thickness.Top - thickness.Bottom),
                 brush);
             FillRect(new RectangleXNA(areaXNA.Right - thickness.Right,
                 areaXNA.Top + thickness.Top, thickness.Right, areaXNA.Height - thickness.Top - thickness.Bottom),
                 brush);
             FillRect(new RectangleXNA(areaXNA.X,
                 areaXNA.Bottom - thickness.Bottom, areaXNA.Width, thickness.Bottom), brush);
         }
     }
     ResetClipArea();
 }
Пример #2
0
 private void SetClipArea(Rectangle bounds)
 {
     manager.SpriteBatch.GraphicsDevice.ScissorRectangle = bounds.ToXNA();
 }
Пример #3
0
        public override void StretchRectangle(Rectangle area, Color color, Rectangle bounds)
        {
            var shadow =
                (Texture2D) manager.Skin.Textures["shadow"];
            var a = area.ToXNA();
            var b = bounds.ToXNA();
            var half = shadow.Width / 2;
            var col = color.ToXNA();

            FillRectangle(area, color, area);
            manager.SpriteBatch.Draw(shadow, new RectangleXNA(b.X, b.Y, a.X - b.X, a.Y - b.Y),
                new RectangleXNA(0, 0, half, half), col);
            manager.SpriteBatch.Draw(shadow, new RectangleXNA(b.X, a.Y + a.Height, a.X - b.X, a.Y - b.Y),
                new RectangleXNA(0, half, half, half), col);

            manager.SpriteBatch.Draw(shadow, new RectangleXNA(a.X + a.Width, b.Y, a.X - b.X, a.Y - b.Y),
                new RectangleXNA(half, 0, half, half), col);
            manager.SpriteBatch.Draw(shadow, new RectangleXNA(a.X + a.Width, a.Y + a.Height, a.X - b.X, a.Y - b.Y),
                new RectangleXNA(half, half, half, half), col);

            manager.SpriteBatch.Draw(shadow, new RectangleXNA(a.X, b.Y, a.Width, a.Y - b.Y),
                new RectangleXNA(half, 0, 1, half), col);
            manager.SpriteBatch.Draw(shadow, new RectangleXNA(a.X, a.Y + a.Height, a.Width, a.Y - b.Y),
                new RectangleXNA(half, half, 1, half), col);

            manager.SpriteBatch.Draw(shadow, new RectangleXNA(b.X, a.Y, a.X - b.X, a.Height),
                new RectangleXNA(0, half, half, 1), col);
            manager.SpriteBatch.Draw(shadow, new RectangleXNA(a.X + a.Width, a.Y, a.X - b.X, a.Height),
                new RectangleXNA(half, half, half, 1), col);
        }
Пример #4
0
 /// <summary>
 /// Draw a gradient over the specified area. To draw in a custom area (such as rounded rectangles), use a mask.
 /// </summary>
 private void DrawGradient(Rectangle area, GradientBrush gradientBrush)
 {
     Texture2D gradientTexture;
     // Create new gradient texture if it is not cached.
     if (!gradientCache.TryGetValue(gradientBrush, out gradientTexture))
     {
         var total = 15;
         gradientTexture = new Texture2D(manager.SpriteBatch.GraphicsDevice, 1, total);
         var start = gradientBrush.Start.ToXNA();
         var end = gradientBrush.End.ToXNA();
         var colors = new ColorXNA[total];
         // Add the start and end colors to the start and end, then add colors in betweeen.
         // The default way XNA/Monogame handles just two colors will only make 1/3rd of the result
         // a gradient, so we need to add some colors in between for better interpolation.
         colors[0] = start;
         for (var i = 1; i < total - 1; i++)
         {
             colors[i] = ColorXNA.Lerp(start, end, (float) i / (total - 2));
         }
         colors[total - 1] = end;
         gradientTexture.SetData(colors);
         gradientCache.Add(gradientBrush, gradientTexture);
     }
     manager.SpriteBatch.Draw(gradientTexture, area.ToXNA(), null, ColorXNA.White, 0, Vector2.Zero,
         SpriteEffects.None, 0);
 }
Пример #5
0
        public override void FillRectangle(Rectangle area, Brush brush, double radius, Rectangle bounds)
        {
            SetClipArea(bounds);
            if (area != Rectangle.Empty)
            {
                if (radius > 0)
                {
                    var corner = (int) Math.Round(radius);
                    var corner2 = corner * 2;
                    var areaXNA = area.ToXNA();

                    var gradientBrush = brush as GradientBrush;
                    if (gradientBrush != null)
                    {
                        UseMaskStencil(area);
                    }

                    // Draw 5 rectangles (top, bottom, left, right, center)
                    FillRect(new RectangleXNA(areaXNA.X + corner,
                        areaXNA.Top, areaXNA.Width - corner2, corner), brush);
                    FillRect(new RectangleXNA(areaXNA.X + corner,
                        areaXNA.Bottom - corner, areaXNA.Width - corner2, corner), brush);
                    FillRect(new RectangleXNA(areaXNA.X,
                        areaXNA.Top + corner, corner, areaXNA.Height - corner2), brush);
                    FillRect(new RectangleXNA(areaXNA.Right - corner,
                        areaXNA.Y + corner, corner, areaXNA.Height - corner2), brush);
                    FillRect(new RectangleXNA(areaXNA.X + corner,
                        areaXNA.Y + corner, areaXNA.Width - corner2, areaXNA.Height - corner2), brush);

                    // Draw edge corners.
                    var circle = GetCircleTexture(radius);
                    FillCorner(new RectangleXNA(areaXNA.X, areaXNA.Y, corner, corner), circle, Corner.TopLeft,
                        brush);
                    FillCorner(new RectangleXNA(areaXNA.Right - corner, areaXNA.Y, corner, corner), circle,
                        Corner.TopRight, brush);
                    FillCorner(new RectangleXNA(areaXNA.X, areaXNA.Bottom - corner, corner, corner), circle,
                        Corner.BottomLeft, brush);
                    FillCorner(new RectangleXNA(areaXNA.Right - corner, areaXNA.Bottom - corner, corner, corner),
                        circle,
                        Corner.BottomRight, brush);

                    // If using a gradient brush, draw a gradient over the mask.
                    if (gradientBrush != null)
                    {
                        UseRenderStencil();
                        DrawGradient(area, gradientBrush);
                        EndStencil();
                    }
                }
                else
                {
                    var colorBrush = brush as ColorBrush;
                    var gradientBrush = brush as GradientBrush;
                    if (colorBrush != null)
                    {
                        manager.SpriteBatch.Draw(pixel, area.ToXNA(), null, colorBrush.ToXNA(), 0, Vector2.Zero,
                            SpriteEffects.None, 0);
                    }
                    if (gradientBrush != null)
                    {
                        DrawGradient(area, gradientBrush);
                    }
                }
            }
            ResetClipArea();
        }