Skip to content

Commit dbce8ee

Browse files
committed
refactor: use the same control between image preview view and image diff view
1 parent 45b93a1 commit dbce8ee

File tree

3 files changed

+14
-93
lines changed

3 files changed

+14
-93
lines changed

src/Views/ImageDiffView.axaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
<TextBlock Classes="monospace" Text="{DynamicResource Text.Diff.Binary.Old}" Margin="8,0" FontSize="10"/>
2929
</Border>
3030

31-
<TextBlock Grid.Column="1" Classes="monospace" Text="{Binding OldImageSize}" Margin="8,0,0,0"/>
32-
<TextBlock Grid.Column="2" Classes="monospace" Text="{Binding OldFileSize}" Foreground="{DynamicResource Brush.FG2}" Margin="16,0,0,0" HorizontalAlignment="Right"/>
33-
<TextBlock Grid.Column="3" Classes="monospace" Text="{DynamicResource Text.Bytes}" Foreground="{DynamicResource Brush.FG2}" Margin="2,0,0,0"/>
31+
<TextBlock Classes="monospace" Text="{Binding OldImageSize}" Margin="8,0,0,0"/>
32+
<TextBlock Classes="monospace" Text="{Binding OldFileSize}" Foreground="{DynamicResource Brush.FG2}" Margin="16,0,0,0" HorizontalAlignment="Right"/>
33+
<TextBlock Classes="monospace" Text="{DynamicResource Text.Bytes}" Foreground="{DynamicResource Brush.FG2}" Margin="2,0,0,0"/>
3434
</StackPanel>
3535

3636
<Border Grid.Row="1" Margin="0,12,0,0" Effect="drop-shadow(0 0 8 #A0000000)">
@@ -51,9 +51,9 @@
5151
<TextBlock Classes="monospace" Text="{DynamicResource Text.Diff.Binary.New}" Margin="8,0" FontSize="10"/>
5252
</Border>
5353

54-
<TextBlock Grid.Column="1" Classes="monospace" Text="{Binding NewImageSize}" Margin="8,0,0,0"/>
55-
<TextBlock Grid.Column="2" Classes="monospace" Text="{Binding NewFileSize}" Foreground="{DynamicResource Brush.FG2}" Margin="16,0,0,0" HorizontalAlignment="Right"/>
56-
<TextBlock Grid.Column="3" Classes="monospace" Text="{DynamicResource Text.Bytes}" Foreground="{DynamicResource Brush.FG2}" Margin="2,0,0,0"/>
54+
<TextBlock Classes="monospace" Text="{Binding NewImageSize}" Margin="8,0,0,0"/>
55+
<TextBlock Classes="monospace" Text="{Binding NewFileSize}" Foreground="{DynamicResource Brush.FG2}" Margin="16,0,0,0" HorizontalAlignment="Right"/>
56+
<TextBlock Classes="monospace" Text="{DynamicResource Text.Bytes}" Foreground="{DynamicResource Brush.FG2}" Margin="2,0,0,0"/>
5757
</StackPanel>
5858

5959
<Border Grid.Row="1" Margin="0,12,0,0" Effect="drop-shadow(0 0 8 #A0000000)">

src/Views/RevisionFiles.axaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,14 @@
5858
</DataTemplate>
5959

6060
<DataTemplate DataType="m:RevisionImageFile">
61-
<Border Background="{DynamicResource Brush.Window}" Effect="drop-shadow(0 0 8 #A0000000)" Margin="0,8" VerticalAlignment="Center" HorizontalAlignment="Center">
62-
<Border BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}" Margin="8">
63-
<v:RevisionImageFileView Source="{Binding Image}" RenderOptions.BitmapInterpolationMode="HighQuality"/>
61+
<Border Margin="0,8" VerticalAlignment="Center" HorizontalAlignment="Center" Effect="drop-shadow(0 0 8 #A0000000)">
62+
<Border Background="{DynamicResource Brush.Window}">
63+
<Border BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}" Margin="8">
64+
<Grid>
65+
<v:ImageContainer/>
66+
<Image Source="{Binding Image}" Stretch="Uniform" VerticalAlignment="Center" RenderOptions.BitmapInterpolationMode="HighQuality"/>
67+
</Grid>
68+
</Border>
6469
</Border>
6570
</Border>
6671
</DataTemplate>

src/Views/RevisionFiles.axaml.cs

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -164,90 +164,6 @@ private List<RevisionFileTreeNode> GetChildrenOfTreeNode(RevisionFileTreeNode no
164164
}
165165
}
166166

167-
public class RevisionImageFileView : Control
168-
{
169-
public static readonly StyledProperty<Bitmap> SourceProperty =
170-
AvaloniaProperty.Register<RevisionImageFileView, Bitmap>(nameof(Source), null);
171-
172-
public Bitmap Source
173-
{
174-
get => GetValue(SourceProperty);
175-
set => SetValue(SourceProperty, value);
176-
}
177-
178-
static RevisionImageFileView()
179-
{
180-
AffectsMeasure<RevisionImageFileView>(SourceProperty);
181-
}
182-
183-
public override void Render(DrawingContext context)
184-
{
185-
if (_bgBrush == null)
186-
{
187-
var maskBrush = new SolidColorBrush(ActualThemeVariant == ThemeVariant.Dark ? 0xFF404040 : 0xFFBBBBBB);
188-
var bg = new DrawingGroup()
189-
{
190-
Children =
191-
{
192-
new GeometryDrawing() { Brush = maskBrush, Geometry = new RectangleGeometry(new Rect(0, 0, 12, 12)) },
193-
new GeometryDrawing() { Brush = maskBrush, Geometry = new RectangleGeometry(new Rect(12, 12, 12, 12)) },
194-
}
195-
};
196-
197-
_bgBrush = new DrawingBrush(bg)
198-
{
199-
AlignmentX = AlignmentX.Left,
200-
AlignmentY = AlignmentY.Top,
201-
DestinationRect = new RelativeRect(new Size(24, 24), RelativeUnit.Absolute),
202-
Stretch = Stretch.None,
203-
TileMode = TileMode.Tile,
204-
};
205-
}
206-
207-
context.FillRectangle(_bgBrush, new Rect(Bounds.Size));
208-
209-
var source = Source;
210-
if (source != null)
211-
context.DrawImage(source, new Rect(source.Size), new Rect(8, 8, Bounds.Width - 16, Bounds.Height - 16));
212-
}
213-
214-
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
215-
{
216-
base.OnPropertyChanged(change);
217-
218-
if (change.Property.Name == "ActualThemeVariant")
219-
{
220-
_bgBrush = null;
221-
InvalidateVisual();
222-
}
223-
}
224-
225-
protected override Size MeasureOverride(Size availableSize)
226-
{
227-
var source = Source;
228-
if (source == null)
229-
return availableSize;
230-
231-
var w = availableSize.Width - 16;
232-
var h = availableSize.Height - 16;
233-
var size = source.Size;
234-
if (size.Width <= w)
235-
{
236-
if (size.Height <= h)
237-
return new Size(size.Width + 16, size.Height + 16);
238-
else
239-
return new Size(h * size.Width / size.Height + 16, availableSize.Height);
240-
}
241-
else
242-
{
243-
var scale = Math.Max(size.Width / w, size.Height / h);
244-
return new Size(size.Width / scale + 16, size.Height / scale + 16);
245-
}
246-
}
247-
248-
private DrawingBrush _bgBrush = null;
249-
}
250-
251167
public class RevisionTextFileView : TextEditor
252168
{
253169
protected override Type StyleKeyOverride => typeof(TextEditor);

0 commit comments

Comments
 (0)