Exemplo n.º 1
0
    /// <summary>
    /// Creates a logarithmic function.
    /// </summary>
    /// <param name="originOfFuncXY">The origin point (on the simple function "log(x, b)" this would be (1, 0))</param>
    /// <param name="logBase">The logarithm base. Affects the slope of the function.</param>
    /// <param name="fartherPointXY">Any other arbitrary point on the function.</param>
    /// <returns>A logarithm function with the given properties.</returns>
    static public Func <float, float> GetLog(float[] originOfFuncXY, float[] fartherPointXY)
    {
        float top    = System.Math.Min(originOfFuncXY[1], fartherPointXY[1]);
        float bottom = System.Math.Max(originOfFuncXY[1], fartherPointXY[1]);
        float left   = System.Math.Min(originOfFuncXY[0], fartherPointXY[0]);
        float right  = System.Math.Max(originOfFuncXY[0], fartherPointXY[0]);

        RectCorners corner = RectCorners.TopLeft;

        if (originOfFuncXY[0] < fartherPointXY[0] && originOfFuncXY[1] > fartherPointXY[1])
        {
            corner = RectCorners.BottomLeft;
        }
        if (originOfFuncXY[0] > fartherPointXY[0] && originOfFuncXY[1] < fartherPointXY[1])
        {
            corner = RectCorners.TopRight;
        }
        if (originOfFuncXY[0] > fartherPointXY[0] && originOfFuncXY[1] > fartherPointXY[1])
        {
            corner = RectCorners.BottomRight;
        }

        return(GetLog(new float[2] {
            left, top
        }, new float[2] {
            right, bottom
        }, corner));
    }
Exemplo n.º 2
0
        public TextureWorker FillRoundedBorders(Color color, RectCorners corners, Color?background = null)
        {
            int w = Texture.width;
            int h = Texture.height;

            int r0 = corners.UpLeft;
            int r1 = corners.UpRight;
            int r2 = corners.BottomLeft;
            int r3 = corners.BottomRight;

            //new RectOffset(left, right, top, bottom)

            if (r0 > 0)
            {
                DrawnPixels += TextureUtils.DrawSector(Texture, r0, r0, r0, color, GetAngle(Corner.UpLeft), true, false);
            }

            if (r1 > 0)
            {
                DrawnPixels += TextureUtils.DrawSector(Texture, w - r1, r1, r1, color, GetAngle(Corner.UpRight), true, false);
            }

            if (r2 > 0)
            {
                DrawnPixels += TextureUtils.DrawSector(Texture, r2, h - r2, r2, color, GetAngle(Corner.BottomLeft), true, false);
            }

            if (r3 > 0)
            {
                DrawnPixels += TextureUtils.DrawSector(Texture, w - r3, h - r3, r3, color, GetAngle(Corner.BottomRight), true, false);
            }

            SmartFill(r0, w - r1, r2, h - r3, color);

            SmartFill(r0, w - r1, 0, Mathf.Max(r0, r1), color);
            SmartFill(0, Mathf.Max(r0, r2), r0, h - r2, color);
            SmartFill(w - Mathf.Max(r1, r3), w, r1 - 1, h - r3 + 1, color);
            SmartFill(r2, w - r3 + 1, h - Mathf.Max(r2, r3), h, color);

            Corners = corners;

            return(this);
        }
Exemplo n.º 3
0
        public TextureWorker CreateRoundedBorders(Color color, int borderRadius, Color?background = null)
        {
            int w = Texture.width;
            int h = Texture.height;
            int r = borderRadius;

            DrawnPixels += TextureUtils.DrawSector(Texture, r, r, r, color, GetAngle(Corner.UpLeft), true, false);
            DrawnPixels += TextureUtils.DrawSector(Texture, w - r, r, r, color, GetAngle(Corner.UpRight), true, false);
            DrawnPixels += TextureUtils.DrawSector(Texture, r, h - r, r, color, GetAngle(Corner.BottomLeft), true, false);
            DrawnPixels += TextureUtils.DrawSector(Texture, w - r, h - r, r, color, GetAngle(Corner.BottomRight), true, false);

            SmartFill(r, w - r, r, h - r, color);

            SmartFill(r, w - r, 0, r, color);
            SmartFill(0, r, r, h - r, color);
            SmartFill(w - r, w, r - 1, h - r + 1, color);
            SmartFill(r, w - r + 1, h - r, h, color);

            Corners = new RectCorners(borderRadius, borderRadius, borderRadius, borderRadius);

            return(this);
        }
Exemplo n.º 4
0
        protected static void AddRoundedRectangle(GraphicsPath path,
                                                  float x, float y, float w, float h,
                                                  float rad, RectCorners corners = RectCorners.All)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            path.StartFigure();
            if (corners == RectCorners.None)
            {
                path.AddRectangle(new RectangleF(x, y, w, h));
            }
            else if (corners == RectCorners.All)
            {
                float d = 2 * rad;
                path.AddArc(x, y, d, d, 180, 90);
                path.AddLine(x + rad, y, x + w - rad, y);
                path.AddArc(x + w - d, y, d, d, -90, 90);
                path.AddLine(x + w, y + rad, x + w, y + h - rad);
                path.AddArc(x + w - d, y + h - d, d, d, 0, 90);
                path.AddLine(x + w - rad, y + h, x + rad, y + h);
                path.AddArc(x, y + h - d, d, d, 90, 90);
                path.CloseFigure();
            }
            else
            {
                float d = 2 * rad;

                if ((corners & RectCorners.TL) == RectCorners.TL)
                {
                    path.AddArc(x, y, d, d, 180, 90);
                }

                if ((corners & RectCorners.Top) == RectCorners.Top)
                {
                    path.AddLine(x + rad, y, x + w - rad, y);
                    path.AddArc(x + w - d, y, d, d, -90, 90);
                }
                else if ((corners & RectCorners.TR) == RectCorners.TR)
                {
                    path.AddLine(x, y, x + w - rad, y);
                    path.AddArc(x + w - d, y, d, d, -90, 90);
                }
                else if ((corners & RectCorners.TL) == RectCorners.TL)
                {
                    path.AddLine(x + rad, y, x + w, y);
                }
                else
                {
                    path.AddLine(x, y, x + w, y);
                }

                if ((corners & RectCorners.Right) == RectCorners.Right)
                {
                    path.AddLine(x + w, y + rad, x + w, y + h - rad);
                    path.AddArc(x + w - d, y + h - d, d, d, 0, 90);
                }
                else if ((corners & RectCorners.BR) == RectCorners.BR)
                {
                    path.AddLine(x + w, y, x + w, y + h - rad);
                    path.AddArc(x + w - d, y + h - d, d, d, 0, 90);
                }
                else if ((corners & RectCorners.TR) == RectCorners.TR)
                {
                    path.AddLine(x + w, y + rad, x + w, y + h);
                }
                else
                {
                    path.AddLine(x + w, y, x + w, y + h);
                }

                if ((corners & RectCorners.Bottom) == RectCorners.Bottom)
                {
                    path.AddLine(x + w - rad, y + h, x + rad, y + h);
                    path.AddArc(x, y + h - d, d, d, 90, 90);
                }
                else if ((corners & RectCorners.BL) == RectCorners.BL)
                {
                    path.AddLine(x + w, y + h, x + rad, y + h);
                    path.AddArc(x, y + h - d, d, d, 90, 90);
                }
                else if ((corners & RectCorners.BR) == RectCorners.BR)
                {
                    path.AddLine(x + w - rad, y + h, x, y + h);
                }
                else
                {
                    path.AddLine(x + w, y + h, x, y + h);
                }

                path.CloseFigure();
            }
        }
Exemplo n.º 5
0
        private GraphicsPath RoundRect(RectangleF rect, float rad, RectCorners corners)
        {
            float        l = rect.Left, t = rect.Top, r = rect.Right - 1, b = rect.Bottom - 1;
            GraphicsPath rr = new GraphicsPath();

            rr.StartFigure();

            PointF ptTL1 = new PointF(l, t + rad);
            PointF ptTL2 = new PointF(l, t);
            PointF ptTL3 = new PointF(l + rad, t);

            PointF ptTR1 = new PointF(r - rad, t);
            PointF ptTR2 = new PointF(r, t);
            PointF ptTR3 = new PointF(r, t + rad);

            PointF ptBR1 = new PointF(r, b - rad);
            PointF ptBR2 = new PointF(r, b);
            PointF ptBR3 = new PointF(r - rad, b);

            PointF ptBL1 = new PointF(l + rad, b);
            PointF ptBL2 = new PointF(l, b);
            PointF ptBL3 = new PointF(l, b - rad);

            RectangleF rectTL = new RectangleF(l, t, rad * 2, rad * 2);
            RectangleF rectTR = rectTL;

            rectTR.X = r - rad * 2;
            RectangleF rectBR = rectTR;

            rectBR.Y = b - rad * 2;
            RectangleF rectBL = rectTL;

            rectBL.Y = b - rad * 2;

            // Top Left
            if ((corners & RectCorners.TopLeft) != 0)
            {
                rr.AddArc(rectTL, 180f, 90f);
            }
            else
            {
                rr.AddLines(new PointF[] { ptTL1, ptTL2, ptTL3 });
            }

            // Top
            rr.AddLine(ptTL3, ptTR1);

            // Top Right
            if ((corners & RectCorners.TopRight) != 0)
            {
                rr.AddArc(rectTR, 270f, 90f);
            }
            else
            {
                rr.AddLines(new PointF[] { ptTR1, ptTR2, ptTR3 });
            }

            // Right
            rr.AddLine(ptTR3, ptBR1);

            // Bottom Right
            if ((corners & RectCorners.BottomRight) != 0)
            {
                rr.AddArc(rectBR, 0f, 90f);
            }
            else
            {
                rr.AddLines(new PointF[] { ptBR1, ptBR2, ptBR3 });
            }

            // Bottom
            rr.AddLine(ptBR3, ptBL1);

            // Bottom Left
            if ((corners & RectCorners.BottomLeft) != 0)
            {
                rr.AddArc(rectBL, 90f, 90f);
            }
            else
            {
                rr.AddLines(new PointF[] { ptBL1, ptBL2, ptBL3 });
            }

            // Left
            rr.AddLine(ptBL3, ptTL1);

            rr.CloseFigure();
            return(rr);
        }
Exemplo n.º 6
0
    /// <summary>
    /// Creates a logarithmic function.
    /// </summary>
    /// <param name="values">A rectangle representing two points in the logarithm: one corner is the logarithmic origin point (on the simple function "log(x, b)" this would be (1, 0)), and the opposite corner is any arbitrary point on the function.</param>
    /// <param name="logBase">The logarithm base. Affects the slope of the function.</param>
    /// <param name="originPoint">Which corner of "values" is the logarithmic origin.</param>
    /// <returns>A logarithm function with the given properties.</returns>
    static public Func <float, float> GetLog(float[] valueBoundsTopLeft, float[] valueBoundsBottomRight, RectCorners originPoint)
    {
        float[] sign = new float[2] {
            1, 1
        };
        if (originPoint == RectCorners.TopLeft || originPoint == RectCorners.TopRight)
        {
            sign[1] = -1;
        }
        if (originPoint == RectCorners.TopRight || originPoint == RectCorners.BottomRight)
        {
            sign[0] = -1;
        }

        float[] origin = new float[2] {
            0, 0
        };
        switch (originPoint)
        {
        case RectCorners.BottomLeft:
            origin = new float[2] {
                valueBoundsTopLeft[0], valueBoundsBottomRight[1]
            };
            break;

        case RectCorners.BottomRight:
            origin = valueBoundsBottomRight;
            break;

        case RectCorners.TopLeft:
            origin = valueBoundsTopLeft;
            break;

        case RectCorners.TopRight:
            origin = new float[2] {
                valueBoundsBottomRight[0], valueBoundsTopLeft[1]
            };
            break;
        }

        float a = sign[1] * (valueBoundsTopLeft[1] - valueBoundsBottomRight[1]) / (float)System.Math.Log(valueBoundsBottomRight[0] - valueBoundsTopLeft[0], System.Math.E);

        return(f => origin[1] + (a * (float)System.Math.Log(sign[0] * (f - origin[0]))));
    }