public virtual void Resize(int x, int y)
        {
            LastParentSize.X = x;
            LastParentSize.Y = y;

            Inited = true;

            Rect.Resize(x, y);
            var PixelSize = Rect.GetPixelSize();

            foreach (var child in Children)
            {
                child.Resize(PixelSize);
            }
        }
Beispiel #2
0
        public static void TexturedRect(PrimitivBuffer target, RelativeRect rect, Vector2 uvScale, bool reverseU = false, bool revserseV = false)
        {
            var origin = rect.GetPixelOrigin();
            var size   = rect.GetPixelSize();

            TexturedRect(target, origin.X, origin.Y, origin.X + size.X, origin.Y + size.Y, uvScale, reverseU, revserseV);
        }
Beispiel #3
0
        public static void OutlineRect(PrimitivBuffer target, RelativeRect rect, float width = 1)
        {
            var origin = rect.GetPixelOrigin();
            var size   = rect.GetPixelSize();

            OutlineRect(target, origin.X, origin.Y, origin.X + size.X, origin.Y + size.Y, width);
        }
Beispiel #4
0
        public static void FilledRect(PrimitivBuffer target, RelativeRect rect)
        {
            var origin = rect.GetPixelOrigin();
            var size   = rect.GetPixelSize();

            FilledRect(target, origin.X, origin.Y, origin.X + size.X, origin.Y + size.Y);
        }
Beispiel #5
0
        public static void TexturedRect(PrimitivBuffer target, RelativeRect rect, TextureInfo texture, bool reverseU = false, bool revserseV = false)
        {
            var origin = rect.GetPixelOrigin();
            var size   = rect.GetPixelSize();

            if (texture == null || texture.PixelSize.X == 0 || texture.PixelSize.Y == 0)
            {
                return;
            }

            Vector2 uvScale = new Vector2(size.X / texture.PixelSize.X, size.Y / texture.PixelSize.Y);

            TexturedRect(target, origin.X, origin.Y, origin.X + size.X, origin.Y + size.Y, uvScale, reverseU, revserseV);
        }
Beispiel #6
0
        public static void Stretched(PrimitivBuffer target, RelativeRect rect)
        {
            var origin = rect.GetPixelOrigin();
            var size   = rect.GetPixelSize();

            if (size.X >= size.Y)
            {
                StretchedH(target, rect);
            }
            else
            {
                StretchedV(target, rect);
            }
        }
        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);
        }
Beispiel #8
0
 public static void FilledGradientRect(PrimitivBuffer target, RelativeRect rect, Color maxColor, Color minColor, bool horizontal)
 {
     FilledGradientRect(target, rect.GetPixelOrigin(), rect.GetPixelSize(), maxColor, minColor, horizontal);
 }
Beispiel #9
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));
        }