From 0159dae85f650944262d2a154e47aec9b3a4365e Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 18 May 2021 11:02:13 +0800 Subject: [PATCH] optimize: create pen as static resources; change style of dot point in CommitGraph --- src/Views/Controls/CommitGraph.cs | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/Views/Controls/CommitGraph.cs b/src/Views/Controls/CommitGraph.cs index 7146dc42..0915c880 100644 --- a/src/Views/Controls/CommitGraph.cs +++ b/src/Views/Controls/CommitGraph.cs @@ -10,15 +10,15 @@ namespace SourceGit.Views.Controls { /// 提交线路图 /// public class CommitGraph : FrameworkElement { - public static readonly Brush[] COLORS = new Brush[] { - Brushes.Orange, - Brushes.ForestGreen, - Brushes.Gold, - Brushes.Magenta, - Brushes.Red, - Brushes.Gray, - Brushes.Turquoise, - Brushes.Olive, + public static readonly Pen[] PENS = new Pen[] { + new Pen(Brushes.Orange, 2), + new Pen(Brushes.ForestGreen, 2), + new Pen(Brushes.Gold, 2), + new Pen(Brushes.Magenta, 2), + new Pen(Brushes.Red, 2), + new Pen(Brushes.Gray, 2), + new Pen(Brushes.Turquoise, 2), + new Pen(Brushes.Olive, 2), }; public static readonly double UNIT_WIDTH = 12; @@ -45,7 +45,7 @@ namespace SourceGit.Views.Controls { LastY = start.Y; Line = new Line(); - Line.Color = color % COLORS.Length; + Line.Color = color % PENS.Length; Line.Points.Add(start); } @@ -242,7 +242,7 @@ namespace SourceGit.Views.Controls { if (last.Y > bottom) continue; var geo = new StreamGeometry(); - var pen = new Pen(COLORS[line.Color], 2); + var pen = PENS[line.Color]; using (var ctx = geo.Open()) { ctx.BeginFigure(last, false, false); @@ -289,23 +289,22 @@ namespace SourceGit.Views.Controls { if (link.Start.Y > bottom) break; var geo = new StreamGeometry(); - var pen = new Pen(COLORS[link.Color], 2); - using (var ctx = geo.Open()) { ctx.BeginFigure(link.Start, false, false); ctx.QuadraticBezierTo(link.Control, link.End, true, false); } geo.Freeze(); - dc.DrawGeometry(null, pen, geo); + dc.DrawGeometry(null, PENS[link.Color], geo); } // 绘制点 + var dotFill = FindResource("Brush.Contents") as Brush; foreach (var dot in data.Dots) { if (dot.Center.Y < top) continue; if (dot.Center.Y > bottom) break; - dc.DrawEllipse(COLORS[dot.Color], null, dot.Center, 3, 3); + dc.DrawEllipse(dotFill, PENS[dot.Color], dot.Center, 3, 3); } } }