2024-03-17 18:37:06 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
|
|
|
|
using Avalonia;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
using Avalonia.Controls;
|
|
|
|
|
using Avalonia.Media;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.Views
|
|
|
|
|
{
|
|
|
|
|
public class ChangeStatusIcon : Control
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
private static readonly IBrush[] BACKGROUNDS = [
|
|
|
|
|
Brushes.Transparent,
|
2024-03-17 18:37:06 -07:00
|
|
|
|
new LinearGradientBrush
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
GradientStops = new GradientStops() { new GradientStop(Color.FromRgb(238, 160, 14), 0), new GradientStop(Color.FromRgb(228, 172, 67), 1) },
|
|
|
|
|
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
|
|
|
|
|
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
|
|
|
|
|
},
|
2024-03-17 18:37:06 -07:00
|
|
|
|
new LinearGradientBrush
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
GradientStops = new GradientStops() { new GradientStop(Color.FromRgb(47, 185, 47), 0), new GradientStop(Color.FromRgb(75, 189, 75), 1) },
|
|
|
|
|
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
|
|
|
|
|
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
|
|
|
|
|
},
|
2024-03-17 18:37:06 -07:00
|
|
|
|
new LinearGradientBrush
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
GradientStops = new GradientStops() { new GradientStop(Colors.Tomato, 0), new GradientStop(Color.FromRgb(252, 165, 150), 1) },
|
|
|
|
|
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
|
|
|
|
|
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
|
|
|
|
|
},
|
2024-03-17 18:37:06 -07:00
|
|
|
|
new LinearGradientBrush
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
GradientStops = new GradientStops() { new GradientStop(Colors.Orchid, 0), new GradientStop(Color.FromRgb(248, 161, 245), 1) },
|
|
|
|
|
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
|
|
|
|
|
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
|
|
|
|
|
},
|
2024-03-17 18:37:06 -07:00
|
|
|
|
new LinearGradientBrush
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
GradientStops = new GradientStops() { new GradientStop(Color.FromRgb(238, 160, 14), 0), new GradientStop(Color.FromRgb(228, 172, 67), 1) },
|
|
|
|
|
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
|
|
|
|
|
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
|
|
|
|
|
},
|
2024-03-17 18:37:06 -07:00
|
|
|
|
new LinearGradientBrush
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
GradientStops = new GradientStops() { new GradientStop(Color.FromRgb(238, 160, 14), 0), new GradientStop(Color.FromRgb(228, 172, 67), 1) },
|
|
|
|
|
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
|
|
|
|
|
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
|
|
|
|
|
},
|
2024-03-17 18:37:06 -07:00
|
|
|
|
new LinearGradientBrush
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
GradientStops = new GradientStops() { new GradientStop(Color.FromRgb(47, 185, 47), 0), new GradientStop(Color.FromRgb(75, 189, 75), 1) },
|
|
|
|
|
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
|
|
|
|
|
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
private static readonly string[] INDICATOR = ["?", "±", "+", "−", "➜", "❏", "U", "★"];
|
|
|
|
|
|
|
|
|
|
public static readonly StyledProperty<bool> IsWorkingCopyChangeProperty =
|
|
|
|
|
AvaloniaProperty.Register<Avatar, bool>(nameof(IsWorkingCopyChange));
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool IsWorkingCopyChange
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => GetValue(IsWorkingCopyChangeProperty);
|
|
|
|
|
set => SetValue(IsWorkingCopyChangeProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static readonly StyledProperty<Models.Change> ChangeProperty =
|
|
|
|
|
AvaloniaProperty.Register<Avatar, Models.Change>(nameof(Change));
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Models.Change Change
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => GetValue(ChangeProperty);
|
|
|
|
|
set => SetValue(ChangeProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
static ChangeStatusIcon()
|
|
|
|
|
{
|
2024-03-04 23:53:38 -08:00
|
|
|
|
AffectsRender<ChangeStatusIcon>(IsWorkingCopyChangeProperty, ChangeProperty);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public override void Render(DrawingContext context)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
if (Change == null || Bounds.Width <= 0) return;
|
|
|
|
|
|
2024-03-04 23:53:38 -08:00
|
|
|
|
var typeface = new Typeface("fonts:SourceGit#JetBrains Mono");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
|
|
IBrush background = null;
|
|
|
|
|
string indicator;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (IsWorkingCopyChange)
|
|
|
|
|
{
|
|
|
|
|
if (Change.IsConflit)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
background = Brushes.OrangeRed;
|
|
|
|
|
indicator = "!";
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
background = BACKGROUNDS[(int)Change.WorkTree];
|
|
|
|
|
indicator = INDICATOR[(int)Change.WorkTree];
|
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
background = BACKGROUNDS[(int)Change.Index];
|
|
|
|
|
indicator = INDICATOR[(int)Change.Index];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var txt = new FormattedText(
|
|
|
|
|
indicator,
|
|
|
|
|
CultureInfo.CurrentCulture,
|
|
|
|
|
FlowDirection.LeftToRight,
|
|
|
|
|
typeface,
|
|
|
|
|
Bounds.Width * 0.8,
|
|
|
|
|
Brushes.White);
|
|
|
|
|
|
|
|
|
|
float corner = (float)Math.Max(2, Bounds.Width / 16);
|
|
|
|
|
Point textOrigin = new Point((Bounds.Width - txt.Width) * 0.5, (Bounds.Height - txt.Height) * 0.5);
|
|
|
|
|
context.DrawRectangle(background, null, new Rect(0, 0, Bounds.Width, Bounds.Height), corner, corner);
|
|
|
|
|
context.DrawText(txt, textOrigin);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|