diff --git a/src/Models/Preference.cs b/src/Models/Preference.cs index 21ec082f..9b3e4bff 100644 --- a/src/Models/Preference.cs +++ b/src/Models/Preference.cs @@ -105,6 +105,11 @@ namespace SourceGit.Models { /// public double Height { get; set; } = 600; + /// + /// 在提交列表视图中是否使用折线代替曲线 + /// + public bool UsePolylineInGraph { get; set; } = false; + /// /// 将提交信息面板与提交记录左右排布 /// diff --git a/src/Resources/Icons.xaml b/src/Resources/Icons.xaml index 1f907272..c74b5ecc 100644 --- a/src/Resources/Icons.xaml +++ b/src/Resources/Icons.xaml @@ -23,6 +23,9 @@ M1024 610v-224H640v48H256V224h128V0H0v224h128v752h512v48h384V800H640v48H256V562h384v48z M30 271l241 0 0-241-241 0 0 241zM392 271l241 0 0-241-241 0 0 241zM753 30l0 241 241 0 0-241-241 0zM30 632l241 0 0-241-241 0 0 241zM392 632l241 0 0-241-241 0 0 241zM753 632l241 0 0-241-241 0 0 241zM30 994l241 0 0-241-241 0 0 241zM392 994l241 0 0-241-241 0 0 241zM753 994l241 0 0-241-241 0 0 241z + M1017 598c0-25-25-50-50-50c-30 0-50 25-50 50c0 35-10 136-55 186c-25 25-55 35-95 35c-70 0-121-191-161-326c-50-196-100-377-231-377c-186 0-271 286-326 472c-10 40-20 75-30 95c-10 25 5 55 30 65c25 10 55-5 65-30c10-25 20-60 35-105c35-136 116-397 226-397c55 0 105 181 141 301c55 196 110 402 256 402c65 0 121-20 161-65c90-95 85-251 85-256z + M341 475 147 675 65 593l271-284 281 265 254-295 89 77-336 387z + M509 546l271-271 91 91-348 349-1-1-13 13-363-361 91-91z M256 224l0 115L512 544l256-205 0-115-256 205L256 224zM512 685l-256-205L256 595 512 800 768 595l0-115L512 685z M170 831l343-342L855 831l105-105-448-448L64 726 170 831z diff --git a/src/Resources/Locales/en_US.xaml b/src/Resources/Locales/en_US.xaml index dc154499..90d4c4ac 100644 --- a/src/Resources/Locales/en_US.xaml +++ b/src/Resources/Locales/en_US.xaml @@ -254,7 +254,8 @@ Histories SEARCH SHA/SUBJECT/AUTHOR. PRESS ENTER TO SEARCH, ESC TO QUIT CLEAR - Toggle Horizontal/Vertical Layout + Switch Curve/Polyline Graph Mode + Switch Horizontal/Vertical Layout SELECTED {0} COMMITS HISTORIES GUIDE 1. Select single commit to view detail diff --git a/src/Resources/Locales/zh_CN.xaml b/src/Resources/Locales/zh_CN.xaml index f2453658..64126169 100644 --- a/src/Resources/Locales/zh_CN.xaml +++ b/src/Resources/Locales/zh_CN.xaml @@ -254,6 +254,7 @@ 历史记录 查询提交指纹、信息、作者。回车键开始,ESC键取消 清空 + 切换曲线/折线显示 切换横向/纵向显示 已选中{0}项提交 操作说明 diff --git a/src/Resources/Styles/ToggleButton.xaml b/src/Resources/Styles/ToggleButton.xaml index 7319b305..f9c43e97 100644 --- a/src/Resources/Styles/ToggleButton.xaml +++ b/src/Resources/Styles/ToggleButton.xaml @@ -90,8 +90,8 @@ @@ -114,4 +114,32 @@ + + \ No newline at end of file diff --git a/src/Views/Controls/CommitGraph.cs b/src/Views/Controls/CommitGraph.cs index 6c9bdafd..ab7ba9be 100644 --- a/src/Views/Controls/CommitGraph.cs +++ b/src/Views/Controls/CommitGraph.cs @@ -235,12 +235,30 @@ namespace SourceGit.Views.Controls { protected override void OnRender(DrawingContext dc) { if (data == null) return; + dc.PushTransform(new TranslateTransform(0, -startY)); + + // 计算边界 var top = startY; var bottom = startY + ActualHeight; - dc.PushTransform(new TranslateTransform(0, -startY)); + // 绘制线 + if (Models.Preference.Instance.Window.UsePolylineInGraph) { + DrawPolyLine(dc, top, bottom); + } else { + DrawCurveLine(dc, top, bottom); + } - // 绘制曲线 + // 绘制点 + 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(dotFill, PENS[dot.Color], dot.Center, 3, 3); + } + } + + private void DrawCurveLine(DrawingContext dc, double top, double bottom) { foreach (var line in data.Lines) { var last = line.Points[0]; var size = line.Points.Count; @@ -265,8 +283,6 @@ namespace SourceGit.Views.Controls { ctx.QuadraticBezierTo(new Point(cur.X, last.Y), cur, true, false); } else if (cur.X < last.X) { if (i < size - 1) { - cur.Y += HALF_HEIGHT; - var midY = (last.Y + cur.Y) / 2; var midX = (last.X + cur.X) / 2; ctx.PolyQuadraticBezierTo(new Point[] { @@ -290,7 +306,6 @@ namespace SourceGit.Views.Controls { dc.DrawGeometry(null, pen, geo); } - // 绘制合并线 foreach (var link in data.Links) { if (link.End.Y < top) continue; if (link.Start.Y > bottom) break; @@ -304,14 +319,43 @@ namespace SourceGit.Views.Controls { geo.Freeze(); 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; + private void DrawPolyLine(DrawingContext dc, double top, double bottom) { + foreach (var line in data.Lines) { + var last = line.Points[0]; + var size = line.Points.Count; - dc.DrawEllipse(dotFill, PENS[dot.Color], dot.Center, 3, 3); + if (line.Points[size - 1].Y < top) continue; + if (last.Y > bottom) continue; + + var geo = new StreamGeometry(); + var pen = PENS[line.Color]; + using (var ctx = geo.Open()) { + ctx.BeginFigure(last, false, false); + + var ended = false; + for (int i = 1; i < size; i++) { + var cur = line.Points[i]; + if (cur.Y > bottom) { + cur.Y = bottom; + ended = true; + } + + ctx.LineTo(cur, true, false); + if (ended) break; + last = cur; + } + } + + geo.Freeze(); + dc.DrawGeometry(null, pen, geo); + } + + foreach (var link in data.Links) { + if (link.End.Y < top) continue; + if (link.Start.Y > bottom) break; + dc.DrawLine(PENS[link.Color], link.Start, link.End); } } } diff --git a/src/Views/Widgets/Histories.xaml b/src/Views/Widgets/Histories.xaml index 00059a97..2660f9e7 100644 --- a/src/Views/Widgets/Histories.xaml +++ b/src/Views/Widgets/Histories.xaml @@ -180,10 +180,19 @@ + + diff --git a/src/Views/Widgets/Histories.xaml.cs b/src/Views/Widgets/Histories.xaml.cs index b8b68999..a34ff0ed 100644 --- a/src/Views/Widgets/Histories.xaml.cs +++ b/src/Views/Widgets/Histories.xaml.cs @@ -143,6 +143,11 @@ namespace SourceGit.Views.Widgets { layout.InvalidateArrange(); } + + public void ChangeGraphMode(object sender, RoutedEventArgs e) { + graph.InvalidateVisual(); + e.Handled = true; + } #endregion #region SEARCH_BAR diff --git a/src/Views/Widgets/RevisionCompare.xaml b/src/Views/Widgets/RevisionCompare.xaml index be24121f..ceea3d8a 100644 --- a/src/Views/Widgets/RevisionCompare.xaml +++ b/src/Views/Widgets/RevisionCompare.xaml @@ -15,11 +15,11 @@ - + - +