YamlObject FromRoundedCorner(RoundedCorner content, YamlMap superclassContent)
        {
            var result = superclassContent;

            result.Add("Radius", FromAnimatable(content.Radius));
            return(result);
        }
示例#2
0
 /// <summary>
 /// Initialise un rectangle à partir du Rectangle <i>rect</i>, des arrondis
 /// aux coins <i>rc</i> et enfin les arrondis auront comme rayon <i>radius</i>
 /// </summary>
 /// <param name="rect">Rectangle de base</param>
 /// <param name="rc">Coins arrondis</param>
 /// <param name="radius">Rayon des arrondis</param>
 public RoundedRectangle(Rectangle rect, RoundedCorner rc, float radius)
 {
     this.x = rect.X;
     this.y = rect.Y;
     this.width = rect.Width;
     this.height = rect.Height;
     this.radius = radius;
     this.roundedCorners = rc;
 }
示例#3
0
 /// <summary>
 /// Initialise un rectangle avec les coins arrondis dont le point supérieur gauche
 /// aura pour coordonnées <i>location</i>, comme taille <i>size</i>, des arrondis
 /// aux coins <i>rc</i> et enfin les arrondis auront comme rayon <i>radius</i>
 /// </summary>
 /// <param name="location"></param>
 /// <param name="size"></param>
 /// <param name="rc">Coins arrondis</param>
 /// <param name="radius">Rayon des arrondis</param>
 public RoundedRectangle(Point location, Size size, RoundedCorner rc, float radius)
 {
     this.x = location.X;
     this.y = location.Y;
     this.width = size.Width;
     this.height = size.Height;
     this.radius = radius;
     this.roundedCorners = rc;
 }
示例#4
0
 /// <summary>
 /// Initialise un rectangle à partir du Rectangle <i>rect</i>, des arrondis
 /// aux coins <i>rc</i> et enfin les arrondis auront comme rayon <i>radius</i>
 /// </summary>
 /// <param name="rect">Rectangle de base</param>
 /// <param name="rc">Coins arrondis</param>
 /// <param name="radius">Rayon des arrondis</param>
 public RoundedRectangle(Rectangle rect, RoundedCorner rc, float radius)
 {
     this.x              = rect.X;
     this.y              = rect.Y;
     this.width          = rect.Width;
     this.height         = rect.Height;
     this.radius         = radius;
     this.roundedCorners = rc;
 }
示例#5
0
        #pragma warning restore 649

        #region Constructeurs

        /// <summary>
        /// Initialise un rectangle avec les coins arrondis dont le point supérieur gauche
        /// aura pour coordonnées (<i>x</i>,<i>y</i>), comme largeur/hauteur <i>width</i> et <i>height</i>, des arrondis
        /// aux coins <i>rc</i> et enfin les arrondis auront comme rayon <i>radius</i>
        /// </summary>
        /// <param name="x">Abscisse du point supérieur gauche</param>
        /// <param name="y">Ordonnée du point supérieur gauche</param>
        /// <param name="width">Largeur du rectangle</param>
        /// <param name="height">Hauteur du rectangle</param>
        /// <param name="rc">Coins arrondis</param>
        /// <param name="radius">Rayon des arrondis</param>
        public RoundedRectangle(int x, int y, int width, int height, RoundedCorner rc, float radius)
        {
            this.x = x;
            this.y = y;
            this.width = width;
            this.height = height;
            this.radius = radius;
            this.roundedCorners = rc;
        }
示例#6
0
 /// <summary>
 /// Initialise un rectangle avec les coins arrondis dont le point supérieur gauche
 /// aura pour coordonnées <i>location</i>, comme taille <i>size</i>, des arrondis
 /// aux coins <i>rc</i> et enfin les arrondis auront comme rayon <i>radius</i>
 /// </summary>
 /// <param name="location"></param>
 /// <param name="size"></param>
 /// <param name="rc">Coins arrondis</param>
 /// <param name="radius">Rayon des arrondis</param>
 public RoundedRectangle(Point location, Size size, RoundedCorner rc, float radius)
 {
     this.x              = location.X;
     this.y              = location.Y;
     this.width          = size.Width;
     this.height         = size.Height;
     this.radius         = radius;
     this.roundedCorners = rc;
 }
示例#7
0
#pragma warning restore 649

        #region Constructeurs

        /// <summary>
        /// Initialise un rectangle avec les coins arrondis dont le point supérieur gauche
        /// aura pour coordonnées (<i>x</i>,<i>y</i>), comme largeur/hauteur <i>width</i> et <i>height</i>, des arrondis
        /// aux coins <i>rc</i> et enfin les arrondis auront comme rayon <i>radius</i>
        /// </summary>
        /// <param name="x">Abscisse du point supérieur gauche</param>
        /// <param name="y">Ordonnée du point supérieur gauche</param>
        /// <param name="width">Largeur du rectangle</param>
        /// <param name="height">Hauteur du rectangle</param>
        /// <param name="rc">Coins arrondis</param>
        /// <param name="radius">Rayon des arrondis</param>
        public RoundedRectangle(int x, int y, int width, int height, RoundedCorner rc, float radius)
        {
            this.x              = x;
            this.y              = y;
            this.width          = width;
            this.height         = height;
            this.radius         = radius;
            this.roundedCorners = rc;
        }
示例#8
0
        private void EqualizeRoundedCornerBorders(Cell cell)
        {
            // If any of a corner relevant border is set, we want to copy its values to the second corner relevant border,
            // to ensure the innerWidth of the cell is the same, regardless of which border is used.
            // If set, we use the vertical borders as source for the values, otherwise we use the horizontal borders.
            RoundedCorner roundedCorner = cell.RoundedCorner;

            if (roundedCorner == RoundedCorner.None)
            {
                return;
            }

            BorderType primaryBorderType = BorderType.Top, secondaryBorderType = BorderType.Top;

            if (roundedCorner == RoundedCorner.TopLeft || roundedCorner == RoundedCorner.BottomLeft)
            {
                primaryBorderType = BorderType.Left;
            }
            if (roundedCorner == RoundedCorner.TopRight || roundedCorner == RoundedCorner.BottomRight)
            {
                primaryBorderType = BorderType.Right;
            }

            if (roundedCorner == RoundedCorner.TopLeft || roundedCorner == RoundedCorner.TopRight)
            {
                secondaryBorderType = BorderType.Top;
            }
            if (roundedCorner == RoundedCorner.BottomLeft || roundedCorner == RoundedCorner.BottomRight)
            {
                secondaryBorderType = BorderType.Bottom;
            }

            // If both borders don't exist, there's nothing to do and we should not create one by accessing it.
            if (!cell.Borders.HasBorder(primaryBorderType) && !cell.Borders.HasBorder(secondaryBorderType))
            {
                return;
            }

            // Get the borders. By using GV.ReadWrite we create the border, if not existing.
            Border primaryBorder   = (Border)cell.Borders.GetValue(primaryBorderType.ToString(), GV.ReadWrite);
            Border secondaryBorder = (Border)cell.Borders.GetValue(secondaryBorderType.ToString(), GV.ReadWrite);

            Border source = primaryBorder.Visible ? primaryBorder
                : secondaryBorder.Visible ? secondaryBorder : null;
            Border target = primaryBorder.Visible ? secondaryBorder
                : secondaryBorder.Visible ? primaryBorder : null;

            if (source == null || target == null)
            {
                return;
            }

            target.Visible = source.Visible;
            target.Width   = source.Width;
            target.Style   = source.Style;
            target.Color   = source.Color;
        }
        public static GraphicsPath Construct(Rectangle bounds, int radius, RoundedCorner corners,
                                             RoundedEdge edges = RoundedEdge.All)
        {
            var path = new GraphicsPath();

            if ((corners & RoundedCorner.TopLeft) != 0)
            {
                path.AddArc(bounds.Left, bounds.Top, radius, radius, 180, 90);
            }

            if ((edges & RoundedEdge.Top) != 0)
            {
                int left  = (corners & RoundedCorner.TopLeft) != 0 ? bounds.Left + radius : bounds.Left;
                int right = (corners & RoundedCorner.TopRight) != 0 ? bounds.Right - radius : bounds.Right;
                path.AddLine(left, bounds.Top, right, bounds.Top);
            }

            if ((corners & RoundedCorner.TopRight) != 0)
            {
                path.AddArc(bounds.Right - radius, bounds.Top, radius, radius, 270, 90);
            }

            if ((edges & RoundedEdge.Right) != 0)
            {
                int top    = (corners & RoundedCorner.TopRight) != 0 ? bounds.Top + radius : bounds.Top;
                int bottom = (corners & RoundedCorner.BottomRight) != 0 ? bounds.Bottom - radius : bounds.Bottom;
                path.AddLine(bounds.Right, top, bounds.Right, bottom);
            }

            if ((corners & RoundedCorner.BottomRight) != 0)
            {
                path.AddArc(bounds.Right - radius, bounds.Bottom - radius, radius, radius, 0, 90);
            }

            if ((edges & RoundedEdge.Bottom) != 0)
            {
                int left  = (corners & RoundedCorner.BottomLeft) != 0 ? bounds.Left + radius : bounds.Left;
                int right = (corners & RoundedCorner.BottomRight) != 0 ? bounds.Right - radius : bounds.Right;
                path.AddLine(right, bounds.Bottom, left, bounds.Bottom);
            }

            if ((corners & RoundedCorner.BottomLeft) != 0)
            {
                path.AddArc(bounds.Left, bounds.Bottom - radius, radius, radius, 90, 90);
            }

            if ((edges & RoundedEdge.Left) != 0)
            {
                int top    = (corners & RoundedCorner.TopLeft) != 0 ? bounds.Top + radius : bounds.Top;
                int bottom = (corners & RoundedCorner.BottomLeft) != 0 ? bounds.Bottom - radius : bounds.Bottom;
                path.AddLine(bounds.Left, bottom, bounds.Left, top);
            }

            path.CloseFigure();
            return(Round(path));
        }
示例#10
0
        /// <summary>
        /// Retourne un RoundedRectangle qui correspond à l'intersection des RoundedRectangle a et b et dont les
        /// coins <i>rc</i> sont arrondis d'un rayon de <i>radius</i>
        /// </summary>
        /// <param name="a">RoundedRectangle</param>
        /// <param name="b">RoundedRectangle</param>
        /// <param name="rc">Coins à arrondir</param>
        /// <param name="radius">Rayon de courbure des arrondis</param>
        /// <returns>RoundedRectangle de l'union</returns>
        public static RoundedRectangle Union(RoundedRectangle a, RoundedRectangle b, RoundedCorner rc, float radius)
        {
            int left   = Math.Min(a.Left, b.Left);
            int right  = Math.Max(a.Right, b.Right);
            int top    = Math.Min(a.Top, b.Top);
            int bottom = Math.Max(a.Bottom, b.Bottom);

            return(new RoundedRectangle(
                       left, right - left, top, bottom - top, rc, radius));
        }
        internal void RenderRounded(RoundedCorner roundedCorner, XUnit x, XUnit y, XUnit width, XUnit height)
        {
            if (roundedCorner == RoundedCorner.None)
            {
                return;
            }

            // As source we use the vertical borders.
            // If not set originally, they have been set to the horizontal border values in TableRenderer.EqualizeRoundedCornerBorders().
            BorderType borderType = BorderType.Top;

            if (roundedCorner == RoundedCorner.TopLeft || roundedCorner == RoundedCorner.BottomLeft)
            {
                borderType = BorderType.Left;
            }
            if (roundedCorner == RoundedCorner.TopRight || roundedCorner == RoundedCorner.BottomRight)
            {
                borderType = BorderType.Right;
            }

            XUnit borderWidth = GetWidth(borderType);
            XPen  borderPen   = GetPen(borderType);

            if (borderWidth == 0)
            {
                return;
            }


            x -= borderWidth / 2;
            y -= borderWidth / 2;
            XUnit ellipseWidth  = width * 2 + borderWidth;
            XUnit ellipseHeight = height * 2 + borderWidth;

            switch (roundedCorner)
            {
            case RoundedCorner.TopLeft:
                _gfx.DrawArc(borderPen, new XRect(x, y, ellipseWidth, ellipseHeight), 180, 90);
                break;

            case RoundedCorner.TopRight:
                _gfx.DrawArc(borderPen, new XRect(x - width, y, ellipseWidth, ellipseHeight), 270, 90);
                break;

            case RoundedCorner.BottomRight:
                _gfx.DrawArc(borderPen, new XRect(x - width, y - height, ellipseWidth, ellipseHeight), 0, 90);
                break;

            case RoundedCorner.BottomLeft:
                _gfx.DrawArc(borderPen, new XRect(x, y - height, ellipseWidth, ellipseHeight), 90, 90);
                break;
            }
        }
示例#12
0
        XElement FromRoundedCorner(RoundedCorner content)
        {
            return(new XElement("RoundedCorner", GetContents()));

            IEnumerable <XObject> GetContents()
            {
                foreach (var item in GetShapeLayerContentContents(content))
                {
                    yield return(item);
                }

                yield return(FromAnimatable(nameof(content.Radius), content.Radius));
            }
        }
示例#13
0
		static void addPath(CGContext context, CGRect rect, float radius, RoundedCorner cornerMask)
		{
			context.MoveTo(rect.X, rect.Y + radius);
			context.AddLineToPoint(rect.X, rect.Y + rect.Height - radius);
			if (((int)cornerMask & (int)RoundedCorner.BottomLeft) != 0) {
				context.AddArc(rect.X + radius, rect.Y + rect.Height - radius, 
					radius, (nfloat)Math.PI, (nfloat)Math.PI / 2, true);
			}
			else {
				context.AddLineToPoint(rect.X, rect.Y + rect.Height);
				context.AddLineToPoint(rect.X + radius, rect.Y + rect.Height);
			}

			context.AddLineToPoint(rect.X + rect.Width - radius, 
				rect.Y + rect.Height);

			if (((int)cornerMask & (int)RoundedCorner.BottomRight) != 0) {
				context.AddArc(rect.X + rect.Width - radius, 
					rect.Y + rect.Height - radius, radius, (nfloat)Math.PI / 2, 0.0f, true);
			}
			else {
				context.AddLineToPoint(rect.X + rect.Width, rect.Y + rect.Height);
				context.AddLineToPoint(rect.X + rect.Width, rect.Y + rect.Height - radius);
			}

			context.AddLineToPoint(rect.X + rect.Width, rect.Y + radius);

			if (((int)cornerMask & (int)RoundedCorner.TopRight) != 0) {
				context.AddArc(rect.X + rect.Width - radius, rect.Y + radius, 
					radius, 0, -(nfloat)Math.PI / 2, true);
			}
			else {
				context.AddLineToPoint(rect.X + rect.Width, rect.Y);
				context.AddLineToPoint(rect.X + rect.Width - radius, rect.Y);
			}

			context.AddLineToPoint(rect.X + radius, rect.Y);

			if (((int)cornerMask & (int)RoundedCorner.TopLeft) != 0) {
				context.AddArc(rect.X + radius, rect.Y + radius, radius, 
					-(nfloat)Math.PI / 2, (nfloat)Math.PI, true);
			}
			else {
				context.AddLineToPoint(rect.X, rect.Y);
				context.AddLineToPoint(rect.X, rect.Y + radius);
			}

			context.ClosePath();
		}
示例#14
0
        public void CheckPivotTangentTest(
            float2 pivotPoint, float2 linePoint1,
            float2 linePoint2, float cornerRadius,
            float2 center, float2 leftTangent, float2 rightTangent,
            bool shouldBeFound)
        {
            var isFound = RoundedCornerSolver.CheckPivotRadiusEdgeCase(pivotPoint, linePoint1, linePoint2, cornerRadius, out var circleResults);

            var expectedResults = new RoundedCorner
            {
                Center       = center,
                LeftTangent  = leftTangent,
                RightTangent = rightTangent
            };

            Assert.AreEqual(shouldBeFound, isFound);
            Assert.True(circleResults == expectedResults);
        }
示例#15
0
		public static GraphicsPath Construct(Rectangle bounds, int radius, RoundedCorner corners,
			RoundedEdge edges = RoundedEdge.All) {
			var path = new GraphicsPath();

			if ((corners & RoundedCorner.TopLeft) != 0)
				path.AddArc(bounds.Left, bounds.Top, radius, radius, 180, 90);

			if ((edges & RoundedEdge.Top) != 0) {
				int left = (corners & RoundedCorner.TopLeft) != 0 ? bounds.Left + radius : bounds.Left;
				int right = (corners & RoundedCorner.TopRight) != 0 ? bounds.Right - radius : bounds.Right;
				path.AddLine(left, bounds.Top, right, bounds.Top);
			}

			if ((corners & RoundedCorner.TopRight) != 0)
				path.AddArc(bounds.Right - radius, bounds.Top, radius, radius, 270, 90);

			if ((edges & RoundedEdge.Right) != 0) {
				int top = (corners & RoundedCorner.TopRight) != 0 ? bounds.Top + radius : bounds.Top;
				int bottom = (corners & RoundedCorner.BottomRight) != 0 ? bounds.Bottom - radius : bounds.Bottom;
				path.AddLine(bounds.Right, top, bounds.Right, bottom);
			}

			if ((corners & RoundedCorner.BottomRight) != 0)
				path.AddArc(bounds.Right - radius, bounds.Bottom - radius, radius, radius, 0, 90);

			if ((edges & RoundedEdge.Bottom) != 0) {
				int left = (corners & RoundedCorner.BottomLeft) != 0 ? bounds.Left + radius : bounds.Left;
				int right = (corners & RoundedCorner.BottomRight) != 0 ? bounds.Right - radius : bounds.Right;
				path.AddLine(right, bounds.Bottom, left, bounds.Bottom);
			}

			if ((corners & RoundedCorner.BottomLeft) != 0)
				path.AddArc(bounds.Left, bounds.Bottom - radius, radius, radius, 90, 90);

			if ((edges & RoundedEdge.Left) != 0) {
				int top = (corners & RoundedCorner.TopLeft) != 0 ? bounds.Top + radius : bounds.Top;
				int bottom = (corners & RoundedCorner.BottomLeft) != 0 ? bounds.Bottom - radius : bounds.Bottom;
				path.AddLine(bounds.Left, bottom, bounds.Left, top);
			}

			path.CloseFigure();
			return Round(path);
		}
示例#16
0
        internal void Render(XUnit x, XUnit y, XUnit width, XUnit height, RoundedCorner roundedCorner)
        {
            // If there is no rounded corner, we can use the usual Render method.
            if (roundedCorner == RoundedCorner.None)
            {
                Render(x, y, width, height);
                return;
            }

            if (_shading == null || _brush == null)
            {
                return;
            }

            XGraphicsPath path = new XGraphicsPath();

            switch (roundedCorner)
            {
            case RoundedCorner.TopLeft:
                path.AddArc(new XRect(x, y, width * 2, height * 2), 180, 90);     // Error in CORE: _corePath.AddArc().
                path.AddLine(new XPoint(x + width, y), new XPoint(x + width, y + height));
                break;

            case RoundedCorner.TopRight:
                path.AddArc(new XRect(x - width, y, width * 2, height * 2), 270, 90);     // Error in CORE: _corePath.AddArc().
                path.AddLine(new XPoint(x + width, y + height), new XPoint(x, y + height));
                break;

            case RoundedCorner.BottomRight:
                path.AddArc(new XRect(x - width, y - height, width * 2, height * 2), 0, 90);     // Error in CORE: _corePath.AddArc().
                path.AddLine(new XPoint(x, y + height), new XPoint(x, y));
                break;

            case RoundedCorner.BottomLeft:
                path.AddArc(new XRect(x, y - height, width * 2, height * 2), 90, 90);     // Error in CORE: _corePath.AddArc().
                path.AddLine(new XPoint(x, y), new XPoint(x + width, y));
                break;
            }

            path.CloseFigure();
            _gfx.DrawPath(_brush, path);
        }
示例#17
0
        internal void Render(XUnit x, XUnit y, XUnit width, XUnit height, RoundedCorner roundedCorner)
        {
            // If there is no rounded corner, we can use the usual Render method.
            if (roundedCorner == RoundedCorner.None)
            {
                Render(x, y, width, height);
                return;
            }

            if (_shading == null || _brush == null)
                return;

            XGraphicsPath path = new XGraphicsPath();

            switch (roundedCorner)
            {
                case RoundedCorner.TopLeft:
                    path.AddArc(new XRect(x, y, width * 2, height * 2), 180, 90); // Error in CORE: _corePath.AddArc().
                    path.AddLine(new XPoint(x + width, y), new XPoint(x + width, y + height));
                    break;
                case RoundedCorner.TopRight:
                    path.AddArc(new XRect(x - width, y, width * 2, height * 2), 270, 90); // Error in CORE: _corePath.AddArc().
                    path.AddLine(new XPoint(x + width, y + height), new XPoint(x, y + height));
                    break;
                case RoundedCorner.BottomRight:
                    path.AddArc(new XRect(x - width, y - height, width * 2, height * 2), 0, 90); // Error in CORE: _corePath.AddArc().
                    path.AddLine(new XPoint(x, y + height), new XPoint(x, y));
                    break;
                case RoundedCorner.BottomLeft:
                    path.AddArc(new XRect(x, y - height, width * 2, height * 2), 90, 90); // Error in CORE: _corePath.AddArc().
                    path.AddLine(new XPoint(x, y), new XPoint(x + width, y));
                    break;
            }

            path.CloseFigure();
            _gfx.DrawPath(_brush, path);
        }
示例#18
0
        internal void RenderRounded(RoundedCorner roundedCorner, XUnit x, XUnit y, XUnit width, XUnit height)
        {
            if (roundedCorner == RoundedCorner.None)
                return;

            // As source we use the vertical borders.
            // If not set originally, they have been set to the horizontal border values in TableRenderer.EqualizeRoundedCornerBorders().
            BorderType borderType = BorderType.Top;
            if (roundedCorner == RoundedCorner.TopLeft || roundedCorner == RoundedCorner.BottomLeft)
                borderType = BorderType.Left;
            if (roundedCorner == RoundedCorner.TopRight || roundedCorner == RoundedCorner.BottomRight)
                borderType = BorderType.Right;

            XUnit borderWidth = GetWidth(borderType);
            XPen borderPen = GetPen(borderType);

            if (borderWidth == 0)
                return;


            x -= borderWidth / 2;
            y -= borderWidth / 2;
            XUnit ellipseWidth = width * 2 + borderWidth;
            XUnit ellipseHeight = height * 2 + borderWidth;

            switch (roundedCorner)
            {
                case RoundedCorner.TopLeft:
                    _gfx.DrawArc(borderPen, new XRect(x, y, ellipseWidth, ellipseHeight), 180, 90);
                    break;
                case RoundedCorner.TopRight:
                    _gfx.DrawArc(borderPen, new XRect(x - width, y, ellipseWidth, ellipseHeight), 270, 90);
                    break;
                case RoundedCorner.BottomRight:
                    _gfx.DrawArc(borderPen, new XRect(x - width, y - height, ellipseWidth, ellipseHeight), 0, 90);
                    break;
                case RoundedCorner.BottomLeft:
                    _gfx.DrawArc(borderPen, new XRect(x, y - height, ellipseWidth, ellipseHeight), 90, 90);
                    break;
            }
        }
示例#19
0
        /// <summary>
        /// Retourne un RoundRectangle correspondant à l'intersection des RoundRectangles a et b
        /// </summary>
        /// <param name="a">RoundedRectangle</param>
        /// <param name="b">RoundedRectangle</param>
        /// <param name="rc">Coins à arrondir</param>
        /// <param name="radius">Rayon de coubure des arrondis</param>
        /// <returns></returns>
        /// <remarks>Si aucune intersection n'est trouvée entre les RoundRectangles, un RoundedRectangle est retourné</remarks>
        public static RoundedRectangle Intersect(RoundedRectangle a, RoundedRectangle b, RoundedCorner rc, float radius)
        {
            int left   = Math.Max(a.Left, b.Left);
            int right  = Math.Min(a.Right, b.Right);
            int top    = Math.Max(a.Top, b.Top);
            int bottom = Math.Min(a.Bottom, b.Bottom);

            if (left <= right && top <= bottom)
            {
                return(new RoundedRectangle(
                           left, right - left, top, bottom - top, rc, radius));
            }
            return(Empty);
        }
示例#20
0
        /// <summary>
        /// Retourne un RoundedRectangle qui correspond à l'intersection des RoundedRectangle a et b et dont les
        /// coins <i>rc</i> sont arrondis d'un rayon de <i>radius</i>
        /// </summary>
        /// <param name="a">RoundedRectangle</param>
        /// <param name="b">RoundedRectangle</param>
        /// <param name="rc">Coins à arrondir</param>
        /// <param name="radius">Rayon de courbure des arrondis</param>
        /// <returns>RoundedRectangle de l'union</returns>
        public static RoundedRectangle Union(RoundedRectangle a, RoundedRectangle b, RoundedCorner rc, float radius)
        {
            int left = Math.Min(a.Left, b.Left);
            int right = Math.Max(a.Right, b.Right);
            int top = Math.Min(a.Top, b.Top);
            int bottom = Math.Max(a.Bottom, b.Bottom);

            return new RoundedRectangle(
                left, right - left, top, bottom - top, rc, radius);
        }
示例#21
0
        public static void DrawRoundedBorder(this Graphics g, Color color, Rectangle rec, int radius, int borderWidth, RoundedCorner corners)
        {
            using (Bitmap b = new Bitmap(rec.Width, rec.Height))
                using (Graphics gb = Graphics.FromImage(b))
                {
                    var gfRec = new Rectangle(0, 0, rec.Width, rec.Height);
                    gb.Clear(Color.Green);

                    gb.DrawRoundedRectangle(color, gfRec, radius, corners);

                    gfRec.Height -= borderWidth << 1;
                    gfRec.Width  -= borderWidth << 1;
                    gfRec.X      += borderWidth;
                    gfRec.Y      += borderWidth;
                    gb.DrawRoundedRectangle(Color.Green, gfRec, radius - borderWidth, corners);

                    var maskAttr = new ImageAttributes();
                    maskAttr.SetColorKey(Color.Green, Color.Green);

                    g.DrawImage(b, rec, 0, 0, b.Width, b.Height, GraphicsUnit.Pixel, maskAttr);
                }
        }
示例#22
0
        public static void DrawRoundedRectangle(this Graphics g, Color color, Rectangle rec, int radius, RoundedCorner corners)
        {
            using (var b = new SolidBrush(color))
            {
                int x        = rec.X;
                int y        = rec.Y;
                int diameter = radius * 2;
                var horiz    = new Rectangle(x, y + radius, rec.Width, rec.Height - diameter);
                var vert     = new Rectangle(x + radius, y, rec.Width - diameter, rec.Height);

                g.FillRectangle(b, horiz);
                g.FillRectangle(b, vert);

                if ((corners & RoundedCorner.TopLeft) == RoundedCorner.TopLeft)
                {
                    g.FillEllipse(b, x, y, diameter, diameter);
                }
                else
                {
                    g.FillRectangle(b, x, y, diameter, diameter);
                }

                if ((corners & RoundedCorner.TopRight) == RoundedCorner.TopRight)
                {
                    g.FillEllipse(b, x + rec.Width - (diameter + 1), y, diameter, diameter);
                }
                else
                {
                    g.FillRectangle(b, x + rec.Width - (diameter + 1), y, diameter, diameter);
                }

                if ((corners & RoundedCorner.BottomLeft) == RoundedCorner.BottomLeft)
                {
                    g.FillEllipse(b, x, y + rec.Height - (diameter + 1), diameter, diameter);
                }
                else
                {
                    g.FillRectangle(b, x, y + rec.Height - (diameter + 1), diameter, diameter);
                }

                if ((corners & RoundedCorner.BottomRight) == RoundedCorner.BottomRight)
                {
                    g.FillEllipse(b, x + rec.Width - (diameter + 1), y + rec.Height - (diameter + 1), diameter, diameter);
                }
                else
                {
                    g.FillRectangle(b, x + rec.Width - (diameter + 1), y + rec.Height - (diameter + 1), diameter,
                                    diameter);
                }
                //return g;
            }
        }
示例#23
0
        /// <summary>
        /// Retourne un RoundRectangle correspondant à l'intersection des RoundRectangles a et b
        /// </summary>
        /// <param name="a">RoundedRectangle</param>
        /// <param name="b">RoundedRectangle</param>
        /// <param name="rc">Coins à arrondir</param>
        /// <param name="radius">Rayon de coubure des arrondis</param>
        /// <returns></returns>
        /// <remarks>Si aucune intersection n'est trouvée entre les RoundRectangles, un RoundedRectangle est retourné</remarks>
        public static RoundedRectangle Intersect(RoundedRectangle a, RoundedRectangle b, RoundedCorner rc, float radius)
        {
            int left = Math.Max(a.Left, b.Left);
            int right = Math.Min(a.Right, b.Right);
            int top = Math.Max(a.Top, b.Top);
            int bottom = Math.Min(a.Bottom, b.Bottom);

            if (left <= right && top <= bottom)
            {
                return new RoundedRectangle(
                    left, right - left, top, bottom - top, rc, radius);
            }
            return Empty;
        }