Exemple #1
0
        private GLColor getColor(FourCorners <IGLColor> color, float fractionX, float fractionY)
        {
            GLColor colorBottomX = getColor(color.BottomLeft, color.BottomRight, fractionX);
            GLColor colorTopX    = getColor(color.TopLeft, color.TopRight, fractionX);

            return(getColor(colorBottomX, colorTopX, fractionY));
        }
 public AGSColoredBorder(IGLUtils glUtils, float lineWidth, FourCorners <Color> color, FourCorners <bool> hasRoundCorner)
 {
     _glUtils       = glUtils;
     LineWidth      = lineWidth;
     Color          = color;
     HasRoundCorner = hasRoundCorner;
     _roundCorner   = new GLVertex[ROUND_CORNER_SAMPLE_SIZE + 1];
 }
Exemple #3
0
        public void DrawQuad(int texture, Vector3 bottomLeft, Vector3 bottomRight,
                             Vector3 topLeft, Vector3 topRight, IGLColor color, FourCorners <Vector2> texturePos)
        {
            GLVertex[] vertices = new GLVertex[] { new GLVertex(bottomLeft.Xy, texturePos.BottomLeft, color),
                                                   new GLVertex(bottomRight.Xy, texturePos.BottomRight, color), new GLVertex(topRight.Xy, texturePos.TopRight, color),
                                                   new GLVertex(topLeft.Xy, texturePos.TopLeft, color) };

            DrawQuad(texture, vertices);
        }
Exemple #4
0
        public void DrawQuad(int texture, AGSBoundingBox box, IGLColor color, FourCorners <Vector2> texturePos)
        {
            _quad[0] = new GLVertex(box.BottomLeft.Xy, texturePos.BottomLeft, color);
            _quad[1] = new GLVertex(box.BottomRight.Xy, texturePos.BottomRight, color);
            _quad[2] = new GLVertex(box.TopRight.Xy, texturePos.TopRight, color);
            _quad[3] = new GLVertex(box.TopLeft.Xy, texturePos.TopLeft, color);

            DrawQuad(texture, _quad);
        }
        private void drawBorders(ISquare square)
        {
            FourCorners <IGLColor> colors = Color.Convert(c => c.ToGLColor());

            float farLeft   = square.TopLeft.X - LineWidth;
            float farRight  = square.TopRight.X + LineWidth;
            float farTop    = square.TopLeft.Y + LineWidth;
            float farBottom = square.BottomLeft.Y - LineWidth;

            AGSSquare border = new AGSSquare(new PointF(farLeft, farBottom), new PointF(farRight, farBottom),
                                             new PointF(farLeft, farTop), new PointF(farRight, farTop));

            float     topQuadBottomY = square.TopLeft.Y;
            float     topQuadLeftX   = HasRoundCorner.TopLeft ? square.TopLeft.X : farLeft;
            float     topQuadRightX  = HasRoundCorner.TopRight ? square.TopRight.X : farRight;
            AGSSquare topQuad        = new AGSSquare(new PointF(topQuadLeftX, topQuadBottomY), new PointF(topQuadRightX, topQuadBottomY),
                                                     new PointF(topQuadLeftX, farTop), new PointF(topQuadRightX, farTop));

            float     bottomQuadTopY   = square.BottomLeft.Y;
            float     bottomQuadLeftX  = HasRoundCorner.BottomLeft ? square.BottomLeft.X : farLeft;
            float     bottomQuadRightX = HasRoundCorner.BottomRight ? square.BottomRight.X : farRight;
            AGSSquare bottomQuad       = new AGSSquare(new PointF(bottomQuadLeftX, farBottom), new PointF(bottomQuadRightX, farBottom),
                                                       new PointF(bottomQuadLeftX, bottomQuadTopY), new PointF(bottomQuadRightX, bottomQuadTopY));

            float horizQuadTop    = square.TopLeft.Y;
            float horizQuadBottom = square.BottomLeft.Y;

            float     leftQuadRightX = square.BottomLeft.X;
            AGSSquare leftQuad       = new AGSSquare(new PointF(farLeft, horizQuadBottom), new PointF(leftQuadRightX, horizQuadBottom),
                                                     new PointF(farLeft, horizQuadTop), new PointF(leftQuadRightX, horizQuadTop));

            float     rightQuadLeftX = square.BottomRight.X;
            AGSSquare rightQuad      = new AGSSquare(new PointF(rightQuadLeftX, horizQuadBottom), new PointF(farRight, horizQuadBottom),
                                                     new PointF(rightQuadLeftX, horizQuadTop), new PointF(farRight, horizQuadTop));

            if (HasRoundCorner.TopLeft)
            {
                drawRoundCorner(square.TopLeft, LineWidth, 270f, border, colors);
            }
            if (HasRoundCorner.TopRight)
            {
                drawRoundCorner(square.TopRight, LineWidth, 0f, border, colors);
            }
            if (HasRoundCorner.BottomLeft)
            {
                drawRoundCorner(square.BottomLeft, LineWidth, 180f, border, colors);
            }
            if (HasRoundCorner.BottomRight)
            {
                drawRoundCorner(square.BottomRight, LineWidth, 90f, border, colors);
            }
            drawQuad(topQuad, border, colors);
            drawQuad(bottomQuad, border, colors);
            drawQuad(leftQuad, border, colors);
            drawQuad(rightQuad, border, colors);
        }
Exemple #6
0
        private void drawQuad(AGSBoundingBox quad, AGSBoundingBox border, FourCorners <IGLColor> colors)
        {
            GLColor bottomLeftColor  = getColor(colors, border, quad.BottomLeft);
            GLColor bottomRightColor = getColor(colors, border, quad.BottomRight);
            GLColor topRightColor    = getColor(colors, border, quad.TopRight);
            GLColor topLeftColor     = getColor(colors, border, quad.TopLeft);

            _glUtils.DrawQuad(0, quad.BottomLeft, quad.BottomRight,
                              quad.TopLeft, quad.TopRight, bottomLeftColor, bottomRightColor, topLeftColor, topRightColor);
        }
        private void drawQuad(ISquare quad, ISquare border, FourCorners <IGLColor> colors)
        {
            GLColor bottomLeftColor  = getColor(colors, border, quad.BottomLeft);
            GLColor bottomRightColor = getColor(colors, border, quad.BottomRight);
            GLColor topRightColor    = getColor(colors, border, quad.TopRight);
            GLColor topLeftColor     = getColor(colors, border, quad.TopLeft);

            _glUtils.DrawQuad(0, quad.BottomLeft.ToVector3(), quad.BottomRight.ToVector3(),
                              quad.TopLeft.ToVector3(), quad.TopRight.ToVector3(), bottomLeftColor, bottomRightColor, topLeftColor, topRightColor);
        }
Exemple #8
0
        public FourCorners <Vector2> GetCropArea(BeforeCropEventArgs eventArgs, float spriteWidth, float spriteHeight, out float width, out float height)
        {
            width  = spriteWidth;
            height = spriteHeight;
            OnBeforeCrop?.Invoke(eventArgs);
            if (!CropEnabled)
            {
                return(null);
            }
            float cropX = CropArea.X;
            float cropY = CropArea.Y;

            width = Math.Min(width, CropArea.Width);
            if (width <= 0f)
            {
                return(null);
            }
            if (cropX + width > spriteWidth)
            {
                width = spriteWidth - cropX;
            }
            height = Math.Min(height, CropArea.Height);
            if (height <= 0f)
            {
                return(null);
            }
            if (cropY + height > spriteHeight)
            {
                height = spriteHeight - cropY;
            }
            float left   = MathUtils.Lerp(0f, 0f, spriteWidth, 1f, cropX);
            float right  = MathUtils.Lerp(0f, 0f, spriteWidth, 1f, cropX + width);
            float top    = MathUtils.Lerp(0f, 1f, spriteHeight, 0f, cropY + height);
            float bottom = MathUtils.Lerp(0f, 1f, spriteHeight, 0f, cropY);

            var textureBox = new FourCorners <Vector2>(new Vector2(left, bottom), new Vector2(right, bottom),
                                                       new Vector2(left, top), new Vector2(right, top));

            return(textureBox);
        }
Exemple #9
0
 public IBorderStyle Gradient(FourCorners <Color> color, FourCorners <bool> hasRoundCorners, float lineWidth = 10)
 {
     return(new AGSColoredBorder(_gLUtils, lineWidth, color, hasRoundCorners));
 }
Exemple #10
0
 public IBorderStyle Gradient(FourCorners <Color> color, float lineWidth = 10, bool hasRoundCorners = false)
 {
     return(new AGSColoredBorder(_gLUtils, lineWidth, color, new FourCorners <bool>(hasRoundCorners)));
 }
Exemple #11
0
        private void drawBorders(AGSBoundingBox square)
        {
            FourCorners <IGLColor> colors = Color.Convert(c => c.ToGLColor());

            float farBottomLeftX  = square.BottomLeft.X - LineWidth;
            float farBottomLeftY  = square.BottomLeft.Y - LineWidth;
            float farBottomRightX = square.BottomRight.X + LineWidth;
            float farBottomRightY = square.BottomRight.Y - LineWidth;
            float farTopLeftX     = square.TopLeft.X - LineWidth;
            float farTopLeftY     = square.TopLeft.Y + LineWidth;
            float farTopRightX    = square.TopRight.X + LineWidth;
            float farTopRightY    = square.TopRight.Y + LineWidth;

            AGSBoundingBox colorBox = new AGSBoundingBox(new Vector2(farBottomLeftX, farBottomLeftY), new Vector2(farBottomRightX, farBottomRightY),
                                                         new Vector2(farTopLeftX, farTopLeftY), new Vector2(farTopRightX, farTopRightY));

            float          topQuadLeftX  = HasRoundCorner.TopLeft ? square.TopLeft.X : farTopLeftX;
            float          topQuadRightX = HasRoundCorner.TopRight ? square.TopRight.X : farTopRightX;
            AGSBoundingBox topQuad       = new AGSBoundingBox(
                new Vector2(topQuadLeftX, square.TopLeft.Y), new Vector2(topQuadRightX, square.TopRight.Y),
                new Vector2(topQuadLeftX, farTopLeftY), new Vector2(topQuadRightX, farTopRightY));

            float          bottomQuadLeftX  = HasRoundCorner.BottomLeft ? square.BottomLeft.X : farBottomLeftX;
            float          bottomQuadRightX = HasRoundCorner.BottomRight ? square.BottomRight.X : farBottomRightX;
            AGSBoundingBox bottomQuad       = new AGSBoundingBox(
                new Vector2(bottomQuadLeftX, farBottomLeftY), new Vector2(bottomQuadRightX, farBottomRightY),
                new Vector2(bottomQuadLeftX, square.BottomLeft.Y), new Vector2(bottomQuadRightX, square.BottomRight.Y));

            float          leftQuadBottomY = square.BottomLeft.Y;
            float          leftQuadTopY    = square.TopLeft.Y;
            AGSBoundingBox leftQuad        = new AGSBoundingBox(
                new Vector2(farBottomLeftX, leftQuadBottomY), new Vector2(square.BottomLeft.X, leftQuadBottomY),
                new Vector2(farTopLeftX, leftQuadTopY), new Vector2(square.TopLeft.X, leftQuadTopY));

            float          rightQuadBottomY = square.BottomRight.Y;
            float          rightQuadTopY    = square.TopRight.Y;
            AGSBoundingBox rightQuad        = new AGSBoundingBox(
                new Vector2(square.BottomRight.X, rightQuadBottomY), new Vector2(farBottomRightX, rightQuadBottomY),
                new Vector2(square.TopRight.X, rightQuadTopY), new Vector2(farTopRightX, rightQuadTopY));

            if (HasRoundCorner.TopLeft)
            {
                drawRoundCorner(square.TopLeft, LineWidth, 270f, colorBox, colors);
            }
            if (HasRoundCorner.TopRight)
            {
                drawRoundCorner(square.TopRight, LineWidth, 0f, colorBox, colors);
            }
            if (HasRoundCorner.BottomLeft)
            {
                drawRoundCorner(square.BottomLeft, LineWidth, 180f, colorBox, colors);
            }
            if (HasRoundCorner.BottomRight)
            {
                drawRoundCorner(square.BottomRight, LineWidth, 90f, colorBox, colors);
            }
            drawQuad(topQuad, colorBox, colors);
            drawQuad(bottomQuad, colorBox, colors);
            drawQuad(leftQuad, colorBox, colors);
            drawQuad(rightQuad, colorBox, colors);
        }
Exemple #12
0
 private GLColor getColor(FourCorners <IGLColor> colors, ISquare border, PointF point)
 {
     return(getColor(colors, MathUtils.Lerp(border.BottomLeft.X, 0f, border.BottomRight.X, 1f, point.X),
                     MathUtils.Lerp(border.BottomRight.Y, 0f, border.TopRight.Y, 1f, point.Y)));
 }
Exemple #13
0
 private GLColor getColor(FourCorners <IGLColor> colors, AGSBoundingBox border, Vector3 point)
 {
     return(getColor(colors, MathUtils.Lerp(border.BottomLeft.X, 0f, border.BottomRight.X, 1f, point.X),
                     MathUtils.Lerp(border.BottomRight.Y, 0f, border.TopRight.Y, 1f, point.Y)));
 }
Exemple #14
0
        private void drawRoundCorner(Vector3 center, float radius, float angle, AGSBoundingBox border, FourCorners <IGLColor> colors)
        {
            Vector2  tex          = new Vector2();
            GLVertex centerVertex = new GLVertex(center.Xy, tex, getColor(colors, border, center));

            _roundCorner[0] = centerVertex;
            float step = (90f / (_roundCorner.Length - 2));

            for (int i = 1; i < _roundCorner.Length; i++)
            {
                float anglerad = (float)Math.PI * angle / 180.0f;
                float x        = (float)Math.Sin(anglerad) * radius;
                float y        = (float)Math.Cos(anglerad) * radius;
                angle += step;
                Vector3 point = new Vector3(x + center.X, y + center.Y, 0f);
                _roundCorner[i] = new GLVertex(point.Xy, tex, getColor(colors, border, point));
            }

            _glUtils.DrawTriangleFan(0, _roundCorner);
        }
 private void drawQuad(AGSBoundingBox quad, FourCorners <Vector2> texturePos)
 {
     _glUtils.DrawQuad(_texture, quad, _white, texturePos);
 }
Exemple #16
0
 public static AGSColoredBorder Gradient(IGLUtils glUtils, FourCorners <Color> color, float lineWidth = 10f, bool hasRoundCorners = false)
 {
     return(new AGSColoredBorder(glUtils, lineWidth, color, new FourCorners <bool>(hasRoundCorners)));
 }
Exemple #17
0
 public static AGSColoredBorder Gradient(FourCorners <Color> color, float lineWidth = 10f, bool hasRoundCorners = false)
 {
     return(Gradient(AGSGame.GLUtils, color, lineWidth, hasRoundCorners));
 }
Exemple #18
0
 private void drawQuad(ISquare quad, FourCorners <Vector2> texturePos)
 {
     _glUtils.DrawQuad(_texture, quad.BottomLeft.ToVector3(), quad.BottomRight.ToVector3(),
                       quad.TopLeft.ToVector3(), quad.TopRight.ToVector3(), _white, texturePos);
 }