예제 #1
0
        public static void FilledGradientRect(PrimitivBuffer target, Vector2 center, Vector2 size, Color maxColor, Color minColor, bool horizontal)
        {
            target.Clear();
            target.DrawType = PrimitiveType.Quads;
            if (horizontal)
            {
                target.Colors.Add(minColor);
                target.Vertex(center.X - size.X, center.Y + size.Y);
                target.Colors.Add(minColor);
                target.Vertex(center.X - size.X, center.Y - size.Y);

                target.Colors.Add(maxColor);
                target.Vertex(center.X + size.X, center.Y - size.Y);
                target.Colors.Add(maxColor);
                target.Vertex(center.X + size.X, center.Y + size.Y);
            }
            else
            {
                target.Colors.Add(minColor);
                target.Vertex(center.X - size.X, center.Y - size.Y);
                target.Colors.Add(minColor);
                target.Vertex(center.X + size.X, center.Y - size.Y);

                target.Colors.Add(maxColor);
                target.Vertex(center.X + size.X, center.Y + size.Y);
                target.Colors.Add(maxColor);
                target.Vertex(center.X - size.X, center.Y + size.Y);
            }
        }
예제 #2
0
        public static void FilledCenteredRect(PrimitivBuffer target, Vector2 center, Vector2 size)
        {
            target.Clear();
            target.DrawType = PrimitiveType.Quads;

            target.Vertex(center.X - size.X, center.Y - size.Y);
            target.Vertex(center.X + size.X, center.Y - size.Y);
            target.Vertex(center.X + size.X, center.Y + size.Y);
            target.Vertex(center.X - size.X, center.Y + size.Y);
        }
예제 #3
0
        public static void FilledRect(PrimitivBuffer target, float minimumX, float minimumY, float maxiumX, float maxiumY)
        {
            target.Clear();
            target.DrawType = PrimitiveType.Quads;

            target.Vertex(minimumX, minimumY);
            target.Vertex(maxiumX, minimumY);
            target.Vertex(maxiumX, maxiumY);
            target.Vertex(minimumX, maxiumY);
        }
예제 #4
0
        public static void OutlineRect(PrimitivBuffer target, float minimumX, float minimumY, float maxiumX, float maxiumY, float width)
        {
            target.Clear();
            target.OutlineWidth = width;
            target.DrawType     = PrimitiveType.LineLoop;

            target.Vertex(minimumX, minimumY);
            target.Vertex(minimumX, maxiumY);
            target.Vertex(maxiumX, maxiumY);
            target.Vertex(maxiumX, minimumY);
        }
예제 #5
0
        public static void OutlineCenteredRect(PrimitivBuffer target, Vector2 center, Vector2 size, float width)
        {
            target.Clear();
            target.OutlineWidth = width;
            target.DrawType     = PrimitiveType.LineLoop;

            target.Vertex(center.X - size.X, center.Y - size.Y);
            target.Vertex(center.X - size.X, center.Y + size.Y);
            target.Vertex(center.X + size.X, center.Y + size.Y);
            target.Vertex(center.X + size.X, center.Y - size.Y);
        }
예제 #6
0
        public static void TexturedRect(PrimitivBuffer target, float minimumX, float minimumY, float maxiumX, float maxiumY, Vector2 uvScale, bool reverseU = false, bool revserseV = false)
        {
            target.Clear();
            target.DrawType = PrimitiveType.Quads;

            target.Vertex(minimumX, minimumY);
            target.UVs.Add(new Vector2(reverseU ? uvScale.X : 0, revserseV ? 0 : uvScale.Y));

            target.Vertex(maxiumX, minimumY);
            target.UVs.Add(new Vector2(reverseU ? 0 : uvScale.X, revserseV ? 0 : uvScale.Y));

            target.Vertex(maxiumX, maxiumY);
            target.UVs.Add(new Vector2(reverseU ? 0 : uvScale.X, revserseV ? uvScale.Y : 0));

            target.Vertex(minimumX, maxiumY);
            target.UVs.Add(new Vector2(reverseU ? uvScale.X : 0, revserseV ? uvScale.Y : 0));
        }
        public static void FourSlice(PrimitivBuffer target, RelativeRect rect, Vector2 textureBounds)
        {
            var origin = rect.GetPixelOrigin();
            var size   = rect.GetPixelSize();

            float texWidth  = textureBounds.X;
            float texHeight = textureBounds.Y;

            if (size.X <= texWidth || size.Y <= texHeight) // it's too small to do pixel based quad sprite, let it do an axis stretch, it's the best we can hope for
            {
                StrechedBuffer.Stretched(target, rect);
                return;
            }

            float halfWidth  = texWidth * 0.5f;
            float halfHeight = texHeight * 0.5f;

            target.Clear();
            target.DrawType = PrimitiveType.Quads;


            // lower
            Vector2 minV = new Vector2(origin.X, origin.Y);
            Vector2 maxV = new Vector2(origin.X + halfWidth, origin.Y + halfHeight);

            Vector2 minT = new Vector2(0, 0.5f);
            Vector2 maxT = new Vector2(0.5f, 1);

            // left side
            AddQuad(target, minV, maxV, minT, maxT);


            // center
            minV = new Vector2(origin.X + halfWidth, origin.Y);
            maxV = new Vector2(origin.X + size.Y - halfWidth, origin.Y + halfHeight);

            minT = new Vector2(0.5f, 0.5f);
            maxT = new Vector2(0.5f, 1);
            AddQuad(target, minV, maxV, minT, maxT);

            // right
            minV = new Vector2(origin.X + size.Y - halfWidth, origin.Y);
            maxV = new Vector2(origin.X + size.Y, origin.Y + halfHeight);

            minT = new Vector2(0.5f, 0.5f);
            maxT = new Vector2(1, 1);
            AddQuad(target, minV, maxV, minT, maxT);


            // middle
            // left
            minV = new Vector2(origin.X, origin.Y + halfHeight);
            maxV = new Vector2(origin.X + halfWidth, origin.Y + size.Y - halfHeight);

            minT = new Vector2(0, 0.5f);
            maxT = new Vector2(0.5f, 0.5f);

            AddQuad(target, minV, maxV, minT, maxT);

            // center
            minV = new Vector2(origin.X + halfWidth, origin.Y + halfHeight);
            maxV = new Vector2(origin.X + size.Y - halfWidth, origin.Y + size.Y - halfHeight);

            minT = new Vector2(0.5f, 0.5f);
            maxT = new Vector2(0.5f, 0.5f);
            AddQuad(target, minV, maxV, minT, maxT);

            // right
            minV = new Vector2(origin.X + size.Y - halfWidth, origin.Y + halfHeight);
            maxV = new Vector2(origin.X + size.Y, origin.Y + size.Y - halfHeight);

            minT = new Vector2(0.5f, 0.5f);
            maxT = new Vector2(1, 0.5f);
            AddQuad(target, minV, maxV, minT, maxT);


            // upper
            // left
            minV = new Vector2(origin.X, origin.Y + size.Y - halfHeight);
            maxV = new Vector2(origin.X + halfWidth, origin.Y + size.Y);

            minT = new Vector2(0, 0);
            maxT = new Vector2(0.5f, 0.5f);

            AddQuad(target, minV, maxV, minT, maxT);

            // center
            minV = new Vector2(origin.X + halfWidth, origin.Y + size.Y - halfHeight);
            maxV = new Vector2(origin.X + size.Y - halfWidth, origin.Y + size.Y);

            minT = new Vector2(0.5f, 0);
            maxT = new Vector2(0.5f, 0.5f);
            AddQuad(target, minV, maxV, minT, maxT);

            // right
            minV = new Vector2(origin.X + size.Y - halfWidth, origin.Y + size.Y - halfHeight);
            maxV = new Vector2(origin.X + size.Y, origin.Y + size.Y);

            minT = new Vector2(0.5f, 0);
            maxT = new Vector2(1, 0.5f);
            AddQuad(target, minV, maxV, minT, maxT);
        }
예제 #8
0
        public static void StretchedH(PrimitivBuffer target, RelativeRect rect)
        {
            var origin = rect.GetPixelOrigin();
            var size   = rect.GetPixelSize();

            if (size.X <= size.Y)
            {
                ShapeBuffer.TexturedRect(target, rect);
                return;
            }

            float halfHeight = size.Y * 0.5f;

            target.Clear();
            target.DrawType = PrimitiveType.Quads;

            float minimumX = origin.X;
            float minimumY = origin.Y;
            float maxiumX  = origin.X + halfHeight;
            float maxiumY  = origin.Y + size.Y;

            float minU = 0;
            float maxU = 0.5f;
            float minV = 0;
            float maxV = 1;

            // left side
            target.Vertex(minimumX, minimumY);
            target.UVs.Add(new Vector2(minU, maxV));

            target.Vertex(maxiumX, minimumY);
            target.UVs.Add(new Vector2(maxU, maxV));

            target.Vertex(maxiumX, maxiumY);
            target.UVs.Add(new Vector2(maxU, minV));

            target.Vertex(minimumX, maxiumY);
            target.UVs.Add(new Vector2(minU, minV));

            // middle
            minimumX = origin.X + halfHeight;
            minimumY = origin.Y;
            maxiumX  = origin.X + size.X - halfHeight;
            maxiumY  = origin.Y + size.Y;

            minU = 0.5f;
            maxU = 0.5f;
            minV = 0;
            maxV = 1;

            target.Vertex(minimumX, minimumY);
            target.UVs.Add(new Vector2(minU, maxV));

            target.Vertex(maxiumX, minimumY);
            target.UVs.Add(new Vector2(maxU, maxV));

            target.Vertex(maxiumX, maxiumY);
            target.UVs.Add(new Vector2(maxU, minV));

            target.Vertex(minimumX, maxiumY);
            target.UVs.Add(new Vector2(minU, minV));


            // right
            minimumX = origin.X + size.X - halfHeight;
            minimumY = origin.Y;
            maxiumX  = origin.X + size.X;
            maxiumY  = origin.Y + size.Y;

            minU = 0.5f;
            maxU = 1f;
            minV = 0;
            maxV = 1;

            target.Vertex(minimumX, minimumY);
            target.UVs.Add(new Vector2(minU, maxV));

            target.Vertex(maxiumX, minimumY);
            target.UVs.Add(new Vector2(maxU, maxV));

            target.Vertex(maxiumX, maxiumY);
            target.UVs.Add(new Vector2(maxU, minV));

            target.Vertex(minimumX, maxiumY);
            target.UVs.Add(new Vector2(minU, minV));
        }