diff --git a/src/Models/CommitGraph.cs b/src/Models/CommitGraph.cs index ea00d691..7c0d8433 100644 --- a/src/Models/CommitGraph.cs +++ b/src/Models/CommitGraph.cs @@ -2,55 +2,37 @@ using System.Collections.Generic; using Avalonia; +using Avalonia.Controls; using Avalonia.Media; namespace SourceGit.Models { public class CommitGraph { - static SolidColorBrush CreateBrushFromHex(string hex) + public static Pen GetPen(int penId) { - // Rimuove il carattere '#' se presente all'inizio del codice esadecimale - if (hex.StartsWith("#")) - { - hex = hex.Substring(1); - } - - // Converte il codice esadecimale in un valore ARGB - uint argb = uint.Parse(hex, System.Globalization.NumberStyles.HexNumber); - - // Estrae i componenti del colore - byte a = (byte)((argb >> 24) & 0xFF); - byte r = (byte)((argb >> 16) & 0xFF); - byte g = (byte)((argb >> 8) & 0xFF); - byte b = (byte)(argb & 0xFF); - - // Crea un oggetto Color - Color color = Color.FromArgb(a, r, g, b); - - // Crea e restituisce un SolidColorBrush usando il colore ottenuto - return new SolidColorBrush(color); + return Pens[penId]; } - public static readonly Pen[] Pens = [ - new Pen(CreateBrushFromHex("#ff15a0bf")), - new Pen(CreateBrushFromHex("#ff0669f7")), - new Pen(CreateBrushFromHex("#ff8e00c2")), - new Pen(CreateBrushFromHex("#ffc517b6")), - new Pen(CreateBrushFromHex("#ffd90171")), - new Pen(CreateBrushFromHex("#ffcd0101")), - new Pen(CreateBrushFromHex("#fff25d2e")), - new Pen(CreateBrushFromHex("#fff2ca33")), - new Pen(CreateBrushFromHex("#ff7bd938")), - new Pen(CreateBrushFromHex("#ff2ece9d")), - //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 void FillPen(int id, Pen pens) + { + if (id < Pens.Length) + { + Pens[id] = pens; + } + } + + static Pen[] Pens = [ + 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), + new Pen(Brushes.Khaki, 2), + new Pen(Brushes.Lime, 2), ]; public class Path diff --git a/src/Resources/Themes.axaml b/src/Resources/Themes.axaml index 3dc7943f..e63c9b65 100644 --- a/src/Resources/Themes.axaml +++ b/src/Resources/Themes.axaml @@ -32,6 +32,16 @@ #3CFF0000 #5A00FF00 #50FF0000 + #FFFFA500 + #FF228B22 + #FFFFD700 + #FFFF00FF + #FFFF0000 + #FF808080 + #FF40E0D0 + #FF808000 + #FFF0E68C + #FF00FF00 @@ -65,6 +75,16 @@ #3CFF0000 #5A00FF00 #50FF0000 + #FFFFA500 + #FF228B22 + #FFFFD700 + #FFFF00FF + #FFFF0000 + #FF808080 + #FF40E0D0 + #FF808000 + #FFF0E68C + #FF00FF00 diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index c35da951..f1b5673f 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -2,8 +2,9 @@ using System.Collections.Generic; using System.IO; using System.Text.Json; +using System.Threading; using System.Threading.Tasks; - +using Avalonia; using Avalonia.Collections; using Avalonia.Controls; using Avalonia.Media; @@ -709,8 +710,22 @@ namespace SourceGit.ViewModels } var commits = new Commands.QueryCommits(FullPath, limits).Result(); - var graph = Models.CommitGraph.Parse(commits, 10); + // hack: color commits + Dispatcher.UIThread.Invoke(() => { + object res; + for (int i = 1; i <= 10; i++) + { + if (Application.Current.TryFindResource($"Color.Graph.{i:00}", out res)) + { + var color = (Color)res; + var pen = new Pen(new SolidColorBrush(color)); + Models.CommitGraph.FillPen(i - 1, pen); + } + } + }); + + var graph = Models.CommitGraph.Parse(commits, 10); Dispatcher.UIThread.Invoke(() => { if (_histories != null) diff --git a/src/Views/Histories.axaml.cs b/src/Views/Histories.axaml.cs index 161bec31..40c29de9 100644 --- a/src/Views/Histories.axaml.cs +++ b/src/Views/Histories.axaml.cs @@ -140,7 +140,7 @@ namespace SourceGit.Views if (dot.Center.Y > bottom) break; - context.DrawEllipse(dotFill, Models.CommitGraph.Pens[dot.Color], dot.Center, 3, 3); + context.DrawEllipse(dotFill, Models.CommitGraph.GetPen(dot.Color), dot.Center, 3, 3); } } @@ -157,8 +157,10 @@ namespace SourceGit.Views continue; var geo = new StreamGeometry(); - var pen = Models.CommitGraph.Pens[line.Color]; + var pen = Models.CommitGraph.GetPen(line.Color); + pen.Thickness = 2.5; + using (var ctx = geo.Open()) { var started = false; @@ -228,7 +230,7 @@ namespace SourceGit.Views ctx.QuadraticBezierTo(link.Control, link.End); } - context.DrawGeometry(null, Models.CommitGraph.Pens[link.Color], geo); + context.DrawGeometry(null, Models.CommitGraph.GetPen(link.Color), geo); } } }