Ejemplo n.º 1
0
        private void UpdateRegion()
        {
            if (!IsHandleCreated)
            {
                return;
            }

            UpdateLocation();

            var balloonBounds = new Rectangle(Point.Empty, Size);

            switch (tailLocation)
            {
            case TailLocation.Left:
                balloonBounds.X     += TailLength;
                balloonBounds.Width -= TailLength;
                break;

            case TailLocation.Bottom:
                balloonBounds.Height -= TailLength;
                break;

            case TailLocation.Right:
                balloonBounds.Width -= TailLength;
                break;
            }


            var radius = Math.Min(CornerRadius, balloonBounds.Height / 2);

            var figure = new GeometryPathFigure(balloonBounds.Left + radius, balloonBounds.Top);

            figure.LineTo(balloonBounds.Right - radius, balloonBounds.Top);
            figure.AddArc(-radius, 0, radius, 270, 90);
            InsertBalloonTailRight(figure, balloonBounds);
            figure.LineTo(balloonBounds.Right, balloonBounds.Bottom - radius);
            figure.AddArc(-(radius * 2), -radius, radius, 0, 90);
            InsertBalloonTailBottom(figure, balloonBounds);
            figure.LineTo(balloonBounds.Left + radius, balloonBounds.Bottom);
            figure.AddArc(-radius, -(radius * 2), radius, 90, 90);
            InsertBalloonTailLeft(figure, balloonBounds);
            figure.LineTo(balloonBounds.Left, balloonBounds.Top + radius);
            figure.AddArc(0, -radius, radius, 180, 90);

            if (balloonPath != null)
            {
                balloonPath.Dispose();
                balloonPath = null;
            }

            balloonPath = figure.GetPath();

            Region = new Region(balloonPath);
        }
Ejemplo n.º 2
0
        private void InsertBalloonTailLeft(GeometryPathFigure figure, Rectangle bounds)
        {
            if (tailLocation != TailLocation.Left)
            {
                return;
            }

            var anchorMid  = anchorBounds.Top + (anchorBounds.Height / 2);
            var balloonTop = Math.Max(anchorMid - (bounds.Height / 2), anchorScreen.Bounds.Top);

            var tailStartAbsolute = Math.Min(Math.Max(anchorMid, balloonTop), balloonTop + bounds.Height - CornerRadius);
            var tailStart         = Math.Max(tailStartAbsolute - balloonTop, CornerRadius + (int)(TailLength / 1.5) + Fudge);

            var tailEnd = tailStart - (int)(TailLength / 1.5);

            figure.LineTo(bounds.Left, tailStart);
            figure.LineTo(bounds.Left - TailLength, tailStart);
            figure.LineTo(bounds.Left, tailEnd);
        }
Ejemplo n.º 3
0
        private void InsertBalloonTailBottom(GeometryPathFigure figure, Rectangle bounds)
        {
            if (tailLocation != TailLocation.Bottom)
            {
                return;
            }

            var anchorMid   = anchorBounds.Left + (anchorBounds.Width / 2);
            var balloonLeft = Math.Min(Math.Max(anchorMid - (bounds.Width / 2), anchorScreen.Bounds.Left), anchorScreen.Bounds.Right - bounds.Width);

            var tailStartAbsolute = Math.Min(Math.Max(anchorMid, balloonLeft),
                                             balloonLeft + bounds.Width - CornerRadius);
            var tailStart = Math.Max(tailStartAbsolute - balloonLeft, CornerRadius + (int)(TailLength / 1.5) + Fudge);

            var tailEnd = tailStart - (int)(TailLength / 1.5);

            figure.LineTo(tailStart, bounds.Bottom);
            figure.LineTo(tailStart, bounds.Bottom + TailLength);
            figure.LineTo(tailEnd, bounds.Bottom);
        }