Beispiel #1
0
 public static void DrawFocusedItemMark(LJD.Graphics g, float x, float y, bool drawOuterFrame = false)
 {
     if (drawOuterFrame)
     {
         g.FillPolygon(white, MakeFocusedItemMarkPoints(x - 1f, y, new SizeF(
                                                            FocusedItemMarkFrame.Size.Width + 2.3f, FocusedItemMarkFrame.Size.Height + 4.4f)));
     }
     g.FillPolygon(blue, MakeFocusedItemMarkPoints(x, y, FocusedItemMarkFrame.Size));
 }
Beispiel #2
0
        public void DrawArrowsView(LJD.Graphics g, Size viewSize, Action <Rectangle> drawFocusRect)
        {
            foreach (var message in eventsHandler.ArrowsDrawInfo)
            {
                if (!message.IsFullyVisible)
                {
                    continue;
                }
                if (message.SelectionState != ArrowSelectionState.NotSelected)
                {
                    int y = message.Y;
                    int h = message.Height;
                    var r = new Rectangle(
                        0, y - h + 2,
                        viewSize.Width, h - 2
                        );
                    g.FillRectangle(resources.SelectedLineBrush, r);
                    if (message.SelectionState == ArrowSelectionState.FocusedSelectedArrow)
                    {
                        drawFocusRect(r);
                    }
                }
            }

            foreach (var role in eventsHandler.RolesDrawInfo)
            {
                var x = role.X;
                g.DrawLine(resources.RolePen, x, 0, x, viewSize.Height);
                foreach (var eo in role.ExecutionOccurrences)
                {
                    LJD.Brush fillBrush;
                    if (eo.DrawMode == ExecutionOccurrenceDrawMode.Normal)
                    {
                        fillBrush = eo.IsHighlighted ? resources.NormalHighlightedExecutionOccurrenceBrush : resources.NormalExecutionOccurrenceBrush;
                    }
                    else if (eo.DrawMode == ExecutionOccurrenceDrawMode.Activity)
                    {
                        fillBrush = eo.IsHighlighted ? resources.ActivityHighlightedExecutionOccurrenceBrush : resources.ActivityExecutionOccurrenceBrush;
                    }
                    else
                    {
                        continue;
                    }
                    g.FillRectangle(fillBrush, eo.Bounds);
                    g.DrawRectangle(eo.IsHighlighted ? resources.HighlightedExecutionOccurrencePen : resources.ExecutionOccurrencePen, eo.Bounds);
                }
            }

            Action <string, LJD.Brush, LJD.Brush, RectangleF> drawTextHelper = (str, back, fore, textRect) =>
            {
                if (back != null)
                {
                    var fillSz   = g.MeasureString(str, resources.Font, resources.ArrowTextFormat, textRect.Size);
                    var fillRect = new RectangleF(textRect.X, textRect.Y + 4, fillSz.Width, textRect.Height - 5);
                    g.FillRectangle(back, fillRect);
                }
                g.DrawString(str, resources.Font, fore, textRect, resources.ArrowTextFormat);
            };

            Action <PointF, bool> drawArrow = (pt, leftToRight) => {
                var pts = new List <PointF>(4);
                pts.Add(pt);
                foreach (var p in resources.ArrowEndShapePoints)
                {
                    pts.Add(new PointF(pt.X + (leftToRight ? 1f : -1f) * p.X, pt.Y + p.Y));
                }
                g.FillPolygon(resources.NormalArrowTextBrush, pts.ToArray());
            };

            foreach (var message in eventsHandler.ArrowsDrawInfo)
            {
                int y         = message.Y;
                int x1        = message.FromX;
                int x2        = message.ToX;
                int h         = message.Height;
                int w         = message.Width;
                int padding   = message.TextPadding;
                var backBrush = message.SelectionState != ArrowSelectionState.NotSelected ? resources.SelectedLineBrush : resources.ControlBackgroundBrush;
                var textBrush = message.Color == ArrowColor.Error ? resources.ErrorArrowTextBrush : resources.NormalArrowTextBrush;

                if (message.Mode == ArrowDrawMode.Arrow ||
                    message.Mode == ArrowDrawMode.DottedArrow)
                {
                    var pen = !message.IsHighlighted ?
                              (message.Mode == ArrowDrawMode.Arrow ? resources.RequestPen : resources.ResponsePen) :
                              (message.Mode == ArrowDrawMode.Arrow ? resources.HighlightedRequestPen : resources.HighlightedResponsePen);
                    if (x1 != x2)
                    {
                        if (message.IsFullyVisible)
                        {
                            drawTextHelper(
                                message.DisplayName,
                                backBrush,
                                textBrush,
                                new RectangleF(
                                    Math.Min(x1, x2) + padding, y - h,
                                    Math.Abs(x1 - x2) - padding * 2, h
                                    )
                                );
                        }

                        var nonHorizontal = message.NonHorizontalDrawingData;
                        if (nonHorizontal != null)
                        {
                            g.DrawLines(
                                pen,
                                new[]
                            {
                                new Point(x1, y),
                                new Point(nonHorizontal.VerticalLineX, y),
                                new Point(nonHorizontal.VerticalLineX, nonHorizontal.Y),
                                new Point(nonHorizontal.ToX, nonHorizontal.Y)
                            }
                                );
                            drawArrow(new PointF(nonHorizontal.ToX, nonHorizontal.Y), x2 > x1);
                        }
                        else
                        {
                            if (message.IsFullyVisible)
                            {
                                g.DrawLine(
                                    pen,
                                    x1, y,
                                    x2, y
                                    );
                                drawArrow(new PointF(x2, y), x2 > x1);
                            }
                        }
                    }
                    else
                    {
                        var midY  = y - h / 2;
                        var loopW = 10;
                        var loopH = 10;

                        drawTextHelper(
                            message.DisplayName,
                            backBrush,
                            textBrush,
                            new RectangleF(
                                x1 + loopW + padding, y - h,
                                message.Width - (loopW + padding * 2), h
                                )
                            );

                        g.DrawLines(
                            pen,
                            new[]
                        {
                            new Point(x1, midY - loopH / 2),
                            new Point(x1 + loopW, midY - loopH / 2),
                            new Point(x1 + loopW, midY + loopH / 2),
                            new Point(x1, midY + loopH / 2),
                        }
                            );
                        drawArrow(new PointF(x1, midY + loopH / 2), false);
                    }
                }
                else if (message.Mode == ArrowDrawMode.Bookmark)
                {
                    if (!message.IsFullyVisible)
                    {
                        continue;
                    }
                    float radius   = h / 4f;
                    var   textRect = new RectangleF(
                        message.MinX - w / 2 + padding, y - h,
                        (message.MaxX - message.MinX + w) - padding * 2, h
                        );
                    var sz = g.MeasureString("ABC", resources.Font, resources.ArrowTextFormat, textRect.Size).ToSize();
                    var r  = new RectangleF(textRect.X, y - sz.Height - 1, textRect.Width, sz.Height);
                    r.Inflate(radius, 0);

                    g.PushState();
                    g.EnableAntialiasing(true);
                    g.FillRoundRectangle(resources.BookmarkArrowBackgroundBrush, r, radius);
                    g.DrawRoundRectangle(resources.BookmarkArrowPen, r, radius);
                    g.PopState();

                    SizeF q = new SizeF(3, 3).Scale(resources.DpiScale);
                    if (x1 - q.Width > r.Left && x1 + q.Width < r.Right)
                    {
                        PointF[] pts;

                        pts = new []
                        {
                            new PointF(x1 - q.Width, r.Top + r.Height / 2),
                            new PointF(x1 - q.Width, r.Top),
                            new PointF(x1, r.Top - q.Height),
                            new PointF(x1 + q.Width, r.Top),
                            new PointF(x1 + q.Width, r.Top + r.Height / 2),
                        };
                        g.FillPolygon(resources.BookmarkArrowBackgroundBrush, pts);
                        g.DrawLines(resources.BookmarkArrowPen, pts.Skip(1).Take(3).ToArray());

                        pts = new []
                        {
                            new PointF(x1 + q.Width, r.Bottom - r.Height / 2),
                            new PointF(x1 + q.Width, r.Bottom),
                            new PointF(x1, r.Bottom + q.Height),
                            new PointF(x1 - q.Width, r.Bottom),
                            new PointF(x1 - q.Width, r.Bottom - r.Height / 2),
                        };
                        g.FillPolygon(resources.BookmarkArrowBackgroundBrush, pts);
                        g.DrawLines(resources.BookmarkArrowPen, pts.Skip(1).Take(3).ToArray());
                    }

                    drawTextHelper(
                        message.DisplayName,
                        null,
                        textBrush,
                        textRect
                        );
                }
                else if (message.Mode == ArrowDrawMode.UserAction ||
                         message.Mode == ArrowDrawMode.StateChange ||
                         message.Mode == ArrowDrawMode.APICall ||
                         message.Mode == ArrowDrawMode.ActivityLabel)
                {
                    if (!message.IsFullyVisible)
                    {
                        continue;
                    }
                    var   icon   = message.Mode == ArrowDrawMode.UserAction ? resources.UserActionImage : null;
                    float radius = h / 4f;
                    var   r      = new RectangleF(
                        x1 - (w - radius), y - h,
                        (w - radius) * 2, h
                        );
                    var sz      = g.MeasureString(message.DisplayName, resources.Font, resources.UserActionTextFormat, r.Size);
                    var szh     = sz.Height;
                    var boxRect = new RectangleF(
                        x1 - sz.Width / 2, y - szh - 1,
                        sz.Width, szh
                        );
                    boxRect.Inflate(radius, 0);
                    g.PushState();
                    g.EnableAntialiasing(true);
                    LJD.Brush backgroundBrush = null;
                    LJD.Pen   strokePen       = resources.UserActionFramePen;
                    if (message.Mode == ArrowDrawMode.UserAction || message.Mode == ArrowDrawMode.APICall)
                    {
                        backgroundBrush = resources.UserActionBrush;
                    }
                    else if (message.Mode == ArrowDrawMode.StateChange)
                    {
                        backgroundBrush = resources.StateChangeBrush;
                    }
                    else if (message.Mode == ArrowDrawMode.ActivityLabel)
                    {
                        backgroundBrush = resources.ActivityExecutionOccurrenceBrush;
                        if (message.IsHighlighted)
                        {
                            strokePen = resources.HighlightedExecutionOccurrencePen;
                        }
                    }
                    g.FillRoundRectangle(
                        backgroundBrush,
                        boxRect,
                        radius
                        );
                    g.DrawRoundRectangle(
                        strokePen,
                        boxRect,
                        radius
                        );
                    g.PopState();
                    g.DrawString(message.DisplayName, resources.Font,
                                 textBrush, boxRect, resources.UserActionTextFormat);
                    if (icon != null)
                    {
                        var iconsz = icon.GetSize(width: 10f).Scale(resources.DpiScale);
                        g.DrawImage(
                            icon,
                            new RectangleF(
                                (int)(boxRect.Left - iconsz.Width * 1.3f),
                                (int)(boxRect.Y + (boxRect.Height - iconsz.Height) / 2),
                                iconsz.Width,
                                iconsz.Height
                                )
                            );
                    }
                }
            }
        }