44using Avalonia.Controls;
55using Avalonia.Media;
66using Avalonia.Media.Imaging;
7+ using Avalonia.Styling;
78
89namespace SourceGit.Views
910{
@@ -45,27 +46,54 @@ static ImageDiffView()
4546 public override void Render(DrawingContext context)
4647 {
4748 var alpha = Alpha;
48- var x = Bounds.Width * Alpha;
49+ var bgMaskBrush = new SolidColorBrush(ActualThemeVariant == ThemeVariant.Dark ? 0xFF404040 : 0xFFBBBBBB);
50+
51+ var bg = new DrawingGroup()
52+ {
53+ Children =
54+ {
55+ new GeometryDrawing() { Brush = bgMaskBrush, Geometry = new RectangleGeometry(new Rect(0, 0, 12, 12)) },
56+ new GeometryDrawing() { Brush = bgMaskBrush, Geometry = new RectangleGeometry(new Rect(12, 12, 12, 12)) },
57+ }
58+ };
59+
60+ var brushBG = new DrawingBrush(bg)
61+ {
62+ AlignmentX = AlignmentX.Left,
63+ AlignmentY = AlignmentY.Top,
64+ DestinationRect = new RelativeRect(new Size(24, 24), RelativeUnit.Absolute),
65+ Stretch = Stretch.None,
66+ TileMode = TileMode.Tile,
67+ };
68+
69+ context.FillRectangle(brushBG, new Rect(Bounds.Size));
4970
5071 var left = OldImage;
5172 if (left != null && alpha > 0)
5273 {
5374 var src = new Rect(0, 0, left.Size.Width * Alpha, left.Size.Height);
54- var dst = new Rect(0, 0, x , Bounds.Height);
75+ var dst = new Rect(8, 8, (Bounds.Width - 16) * Alpha , Bounds.Height - 16 );
5576 context.DrawImage(left, src, dst);
5677 }
5778
5879 var right = NewImage;
5980 if (right != null)
6081 {
6182 var src = new Rect(right.Size.Width * Alpha, 0, right.Size.Width - right.Size.Width * Alpha, right.Size.Height);
62- var dst = new Rect(x, 0, Bounds.Width - x , Bounds.Height);
83+ var dst = new Rect((Bounds.Width - 16) * Alpha + 8, 8, ( Bounds.Width - 16) * (1 - Alpha) , Bounds.Height - 16 );
6384 context.DrawImage(right, src, dst);
6485 }
65-
86+
87+ var x = (Bounds.Width - 16) * Alpha + 8;
6688 context.DrawLine(new Pen(Brushes.DarkGreen, 2), new Point(x, 0), new Point(x, Bounds.Height));
6789 }
6890
91+ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
92+ {
93+ base.OnPropertyChanged(change);
94+ if (change.Property.Name == "ActualThemeVariant") InvalidateVisual();
95+ }
96+
6997 protected override Size MeasureOverride(Size availableSize)
7098 {
7199 var left = OldImage;
@@ -87,21 +115,24 @@ protected override Size MeasureOverride(Size availableSize)
87115
88116 private Size GetDesiredSize(Size img, Size available)
89117 {
90- if (img.Width <= available.Width)
118+ var w = available.Width - 16;
119+ var h = available.Height - 16;
120+
121+ if (img.Width <= w)
91122 {
92- if (img.Height <= available.Height )
123+ if (img.Height <= h )
93124 {
94- return img;
125+ return new Size( img.Width + 16, img.Height + 16) ;
95126 }
96127 else
97128 {
98- return new Size(available.Height * img.Width / img.Height, available.Height);
129+ return new Size(h * img.Width / img.Height + 16 , available.Height);
99130 }
100131 }
101132 else
102133 {
103- var s = Math.Max(img.Width / available.Width , img.Height / available.Height );
104- return new Size(img.Width / s, img.Height / s);
134+ var s = Math.Max(img.Width / w , img.Height / h );
135+ return new Size(img.Width / s + 16 , img.Height / s + 16 );
105136 }
106137 }
107138 }
0 commit comments