@@ -45,53 +45,62 @@ static ImageDiffView()
4545
4646 public override void Render ( DrawingContext context )
4747 {
48- var alpha = Alpha ;
49- var bgMaskBrush = new SolidColorBrush ( ActualThemeVariant == ThemeVariant . Dark ? 0xFF404040 : 0xFFBBBBBB ) ;
50-
51- var bg = new DrawingGroup ( )
48+ if ( _bgBrush == null )
5249 {
53- Children =
50+ var maskBrush = new SolidColorBrush ( ActualThemeVariant == ThemeVariant . Dark ? 0xFF404040 : 0xFFBBBBBB ) ;
51+ var bg = new DrawingGroup ( )
5452 {
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- } ;
53+ Children =
54+ {
55+ new GeometryDrawing ( ) { Brush = maskBrush , Geometry = new RectangleGeometry ( new Rect ( 0 , 0 , 12 , 12 ) ) } ,
56+ new GeometryDrawing ( ) { Brush = maskBrush , Geometry = new RectangleGeometry ( new Rect ( 12 , 12 , 12 , 12 ) ) } ,
57+ }
58+ } ;
59+
60+ _bgBrush = 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+ }
6869
69- context . FillRectangle ( brushBG , new Rect ( Bounds . Size ) ) ;
70+ context . FillRectangle ( _bgBrush , new Rect ( Bounds . Size ) ) ;
7071
72+ var alpha = Alpha ;
73+ var w = Bounds . Width - 16 ;
74+ var h = Bounds . Height - 16 ;
75+ var x = w * alpha ;
7176 var left = OldImage ;
7277 if ( left != null && alpha > 0 )
7378 {
74- var src = new Rect ( 0 , 0 , left . Size . Width * Alpha , left . Size . Height ) ;
75- var dst = new Rect ( 8 , 8 , ( Bounds . Width - 16 ) * Alpha , Bounds . Height - 16 ) ;
79+ var src = new Rect ( 0 , 0 , left . Size . Width * alpha , left . Size . Height ) ;
80+ var dst = new Rect ( 8 , 8 , x , h ) ;
7681 context . DrawImage ( left , src , dst ) ;
7782 }
7883
7984 var right = NewImage ;
80- if ( right != null )
85+ if ( right != null && alpha < 1 )
8186 {
82- var src = new Rect ( right . Size . Width * Alpha , 0 , right . Size . Width - right . Size . Width * Alpha , right . Size . Height ) ;
83- var dst = new Rect ( ( Bounds . Width - 16 ) * Alpha + 8 , 8 , ( Bounds . Width - 16 ) * ( 1 - Alpha ) , Bounds . Height - 16 ) ;
87+ var src = new Rect ( right . Size . Width * alpha , 0 , right . Size . Width * ( 1 - alpha ) , right . Size . Height ) ;
88+ var dst = new Rect ( x + 8 , 8 , w - x , h ) ;
8489 context . DrawImage ( right , src , dst ) ;
8590 }
8691
87- var x = ( Bounds . Width - 16 ) * Alpha + 8 ;
88- context . DrawLine ( new Pen ( Brushes . DarkGreen , 2 ) , new Point ( x , 0 ) , new Point ( x , Bounds . Height ) ) ;
92+ context . DrawLine ( new Pen ( Brushes . DarkGreen , 2 ) , new Point ( x + 8 , 0 ) , new Point ( x + 8 , Bounds . Height ) ) ;
8993 }
9094
9195 protected override void OnPropertyChanged ( AvaloniaPropertyChangedEventArgs change )
9296 {
9397 base . OnPropertyChanged ( change ) ;
94- if ( change . Property . Name == "ActualThemeVariant" ) InvalidateVisual ( ) ;
98+
99+ if ( change . Property . Name == "ActualThemeVariant" )
100+ {
101+ _bgBrush = null ;
102+ InvalidateVisual ( ) ;
103+ }
95104 }
96105
97106 protected override Size MeasureOverride ( Size availableSize )
@@ -135,6 +144,8 @@ private Size GetDesiredSize(Size img, Size available)
135144 return new Size ( img . Width / s + 16 , img . Height / s + 16 ) ;
136145 }
137146 }
147+
148+ private DrawingBrush _bgBrush = null ;
138149 }
139150
140151 public partial class DiffView : UserControl
0 commit comments