|
@@ -5,6 +5,7 @@ using Avalonia.Data;
|
|
|
using Avalonia.Layout;
|
|
|
using Avalonia.Media;
|
|
|
using Avalonia.Media.Imaging;
|
|
|
+using Avalonia.Svg.Skia;
|
|
|
using PixiEditor.Extensions.CommonApi.FlyUI.Properties;
|
|
|
using PixiEditor.Extensions.Extensions;
|
|
|
using PixiEditor.Extensions.FlyUI.Converters;
|
|
@@ -19,8 +20,9 @@ public class Image : LayoutElement
|
|
|
private double _height = -1;
|
|
|
private FillMode _fillMode = FillMode.Uniform;
|
|
|
private FilterQuality _filterQuality = FilterQuality.None;
|
|
|
- private Avalonia.Controls.Image _image = null!;
|
|
|
-
|
|
|
+ private Avalonia.Controls.Image? _image = null;
|
|
|
+ private SvgImage? _svgImage = null;
|
|
|
+
|
|
|
public string Source { get => _source; set => SetField(ref _source, value); }
|
|
|
public double Width { get => _width; set => SetField(ref _width, value); }
|
|
|
public double Height { get => _height; set => SetField(ref _height, value); }
|
|
@@ -37,43 +39,43 @@ public class Image : LayoutElement
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
protected override Control CreateNativeControl()
|
|
|
{
|
|
|
_image = new();
|
|
|
-
|
|
|
+
|
|
|
Binding sourceBinding = new()
|
|
|
{
|
|
|
Source = this,
|
|
|
Path = nameof(Source),
|
|
|
- Converter = new PathToBitmapConverter(),
|
|
|
+ Converter = new PathToImgSourceConverter(),
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
Binding widthBinding = new()
|
|
|
{
|
|
|
Source = this,
|
|
|
Path = nameof(Width),
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
Binding heightBinding = new()
|
|
|
{
|
|
|
Source = this,
|
|
|
Path = nameof(Height),
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
Binding fillModeBinding = new()
|
|
|
{
|
|
|
Source = this,
|
|
|
Path = nameof(FillMode),
|
|
|
Converter = new EnumToEnumConverter<FillMode, Stretch>()
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
_image.Bind(Avalonia.Controls.Image.SourceProperty, sourceBinding);
|
|
|
_image.Bind(Layoutable.WidthProperty, widthBinding);
|
|
|
_image.Bind(Layoutable.HeightProperty, heightBinding);
|
|
|
_image.Bind(Avalonia.Controls.Image.StretchProperty, fillModeBinding);
|
|
|
RenderOptions.SetBitmapInterpolationMode(_image, (BitmapInterpolationMode)(byte)FilterQuality);
|
|
|
-
|
|
|
+
|
|
|
return _image;
|
|
|
}
|
|
|
|
|
@@ -81,10 +83,10 @@ public class Image : LayoutElement
|
|
|
protected override IEnumerable<object> GetControlProperties()
|
|
|
{
|
|
|
yield return Source;
|
|
|
-
|
|
|
+
|
|
|
yield return Width;
|
|
|
yield return Height;
|
|
|
-
|
|
|
+
|
|
|
yield return FillMode;
|
|
|
yield return FilterQuality;
|
|
|
}
|
|
@@ -93,13 +95,13 @@ public class Image : LayoutElement
|
|
|
{
|
|
|
var valuesList = values.ToList();
|
|
|
Source = (string)valuesList.ElementAtOrDefault(0);
|
|
|
-
|
|
|
+
|
|
|
Width = (double)valuesList.ElementAtOrDefault(1, double.NaN);
|
|
|
Height = (double)valuesList.ElementAtOrDefault(2, double.NaN);
|
|
|
-
|
|
|
+
|
|
|
Width = Width < 0 ? double.NaN : Width;
|
|
|
Height = Height < 0 ? double.NaN : Height;
|
|
|
-
|
|
|
+
|
|
|
FillMode = (FillMode)valuesList.ElementAtOrDefault(3, FillMode.Uniform);
|
|
|
FilterQuality = (FilterQuality)valuesList.ElementAtOrDefault(4, FilterQuality.Unspecified);
|
|
|
}
|