Beispiel #1
0
        public static void DrawHandle(SpriteBatch sb, Rectangle rect, Color c = default(Color), BufferSet buffers = null)
        {
            if (buffers != null)
            {
                Rectangle screen = NineSlice.Screen;
                var       leftX  = rect.X + buffers.Left;
                var       rightX = rect.Right - buffers.Right;
                var       topY   = rect.Top + buffers.Top;
                var       botY   = rect.Bottom - buffers.Bot;

                sb.DrawLine(new Vector2(leftX, 0), new Vector2(leftX, screen.Bottom), c);
                sb.DrawLine(new Vector2(rightX, 0), new Vector2(rightX, screen.Bottom), c);
                sb.DrawLine(new Vector2(0, topY), new Vector2(screen.Right, topY), c);
                sb.DrawLine(new Vector2(0, botY), new Vector2(screen.Right, botY), c);
            }

            sb.DrawRectangle(rect, c);
        }
Beispiel #2
0
        private List <Rectangle> SliceRectangle(Rectangle rect, BufferSet buffers)
        {
            var result = new List <Rectangle>();

            int x      = rect.X;
            int y      = rect.Y;
            int bottom = rect.Bottom;
            int right  = rect.Right;

            int middleWidth = rect.Width - (buffers.Left + buffers.Right);
            var s0          = new Rectangle
            {
                X      = x,
                Y      = y,
                Width  = buffers.Left,
                Height = buffers.Top,
            };

            result.Add(s0);

            var s1 = new Rectangle
            {
                X      = x + buffers.Left,
                Y      = y,
                Width  = middleWidth,
                Height = buffers.Top,
            };

            result.Add(s1);

            var s2 = new Rectangle
            {
                X      = right - buffers.Right,
                Y      = y,
                Width  = buffers.Right,
                Height = buffers.Top
            };

            result.Add(s2);

            // MIDDLE ROW
            int middleHeight = rect.Height - (buffers.Top + buffers.Bot);
            var s3           = new Rectangle
            {
                X      = x,
                Y      = y + buffers.Top,
                Width  = buffers.Left,
                Height = middleHeight,
            };

            result.Add(s3);

            var s4 = new Rectangle
            {
                X      = x + buffers.Left,
                Y      = y + buffers.Top,
                Width  = middleWidth,
                Height = middleHeight,
            };

            result.Add(s4);

            var s5 = new Rectangle
            {
                X      = right - buffers.Right,
                Y      = y + buffers.Top,
                Width  = buffers.Right,
                Height = middleHeight
            };

            result.Add(s5);

            // BOTTOM ROW
            var s6 = new Rectangle
            {
                X      = x,
                Y      = bottom - buffers.Bot,
                Width  = buffers.Left,
                Height = buffers.Bot,
            };

            result.Add(s6);

            var s7 = new Rectangle
            {
                X      = x + buffers.Left,
                Y      = bottom - buffers.Bot,
                Width  = middleWidth,
                Height = buffers.Bot,
            };

            result.Add(s7);

            var s8 = new Rectangle
            {
                X      = right - buffers.Right,
                Y      = bottom - buffers.Bot,
                Width  = buffers.Right,
                Height = buffers.Bot
            };

            result.Add(s8);

            return(result);
        }