From dbce8eebdee2b4f3d1147072a32b108da9f0cdb8 Mon Sep 17 00:00:00 2001 From: leo Date: Sat, 22 Jun 2024 18:56:49 +0800 Subject: [PATCH] refactor: use the same control between image preview view and image diff view --- src/Views/ImageDiffView.axaml | 12 ++--- src/Views/RevisionFiles.axaml | 11 +++-- src/Views/RevisionFiles.axaml.cs | 84 -------------------------------- 3 files changed, 14 insertions(+), 93 deletions(-) diff --git a/src/Views/ImageDiffView.axaml b/src/Views/ImageDiffView.axaml index a7132f3e..722e3a23 100644 --- a/src/Views/ImageDiffView.axaml +++ b/src/Views/ImageDiffView.axaml @@ -28,9 +28,9 @@ - - - + + + @@ -51,9 +51,9 @@ - - - + + + diff --git a/src/Views/RevisionFiles.axaml b/src/Views/RevisionFiles.axaml index da48651b..2d08e7d5 100644 --- a/src/Views/RevisionFiles.axaml +++ b/src/Views/RevisionFiles.axaml @@ -58,9 +58,14 @@ - - - + + + + + + + + diff --git a/src/Views/RevisionFiles.axaml.cs b/src/Views/RevisionFiles.axaml.cs index afa15bd1..4b4fc449 100644 --- a/src/Views/RevisionFiles.axaml.cs +++ b/src/Views/RevisionFiles.axaml.cs @@ -164,90 +164,6 @@ namespace SourceGit.Views } } - public class RevisionImageFileView : Control - { - public static readonly StyledProperty SourceProperty = - AvaloniaProperty.Register(nameof(Source), null); - - public Bitmap Source - { - get => GetValue(SourceProperty); - set => SetValue(SourceProperty, value); - } - - static RevisionImageFileView() - { - AffectsMeasure(SourceProperty); - } - - public override void Render(DrawingContext context) - { - if (_bgBrush == null) - { - var maskBrush = new SolidColorBrush(ActualThemeVariant == ThemeVariant.Dark ? 0xFF404040 : 0xFFBBBBBB); - var bg = new DrawingGroup() - { - Children = - { - new GeometryDrawing() { Brush = maskBrush, Geometry = new RectangleGeometry(new Rect(0, 0, 12, 12)) }, - new GeometryDrawing() { Brush = maskBrush, Geometry = new RectangleGeometry(new Rect(12, 12, 12, 12)) }, - } - }; - - _bgBrush = new DrawingBrush(bg) - { - AlignmentX = AlignmentX.Left, - AlignmentY = AlignmentY.Top, - DestinationRect = new RelativeRect(new Size(24, 24), RelativeUnit.Absolute), - Stretch = Stretch.None, - TileMode = TileMode.Tile, - }; - } - - context.FillRectangle(_bgBrush, new Rect(Bounds.Size)); - - var source = Source; - if (source != null) - context.DrawImage(source, new Rect(source.Size), new Rect(8, 8, Bounds.Width - 16, Bounds.Height - 16)); - } - - protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) - { - base.OnPropertyChanged(change); - - if (change.Property.Name == "ActualThemeVariant") - { - _bgBrush = null; - InvalidateVisual(); - } - } - - protected override Size MeasureOverride(Size availableSize) - { - var source = Source; - if (source == null) - return availableSize; - - var w = availableSize.Width - 16; - var h = availableSize.Height - 16; - var size = source.Size; - if (size.Width <= w) - { - if (size.Height <= h) - return new Size(size.Width + 16, size.Height + 16); - else - return new Size(h * size.Width / size.Height + 16, availableSize.Height); - } - else - { - var scale = Math.Max(size.Width / w, size.Height / h); - return new Size(size.Width / scale + 16, size.Height / scale + 16); - } - } - - private DrawingBrush _bgBrush = null; - } - public class RevisionTextFileView : TextEditor { protected override Type StyleKeyOverride => typeof(TextEditor);