From 881069fd5d932a10b02197be18e5ae9a4a92f623 Mon Sep 17 00:00:00 2001 From: Benedikt Schroeder Date: Thu, 19 Jul 2018 07:05:21 +0200 Subject: [PATCH] Introduce RenderOptions --- .gitignore | 3 +- Avalonia.sln | 42 -------------------------- src/Avalonia.Controls/Image.cs | 17 ++--------- src/Avalonia.Controls/RenderOptions.cs | 36 ++++++++++++++++++++++ 4 files changed, 40 insertions(+), 58 deletions(-) create mode 100644 src/Avalonia.Controls/RenderOptions.cs diff --git a/.gitignore b/.gitignore index f0cbd79cbc..dd814ba26f 100644 --- a/.gitignore +++ b/.gitignore @@ -181,5 +181,4 @@ project.lock.json ################## ## BenchmarkDotNet ################## -BenchmarkDotNet.Artifacts/ -/src/ImageInterpRepro +BenchmarkDotNet.Artifacts/ \ No newline at end of file diff --git a/Avalonia.sln b/Avalonia.sln index 7938b95ac5..d1c5026e58 100644 --- a/Avalonia.sln +++ b/Avalonia.sln @@ -187,8 +187,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.Designer.HostApp.N EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Skia.UnitTests", "tests\Avalonia.Skia.UnitTests\Avalonia.Skia.UnitTests.csproj", "{E1240B49-7B4B-4371-A00E-068778C5CF0B}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageInterpRepro", "src\ImageInterpRepro\ImageInterpRepro.csproj", "{54A1062E-126E-4813-98A7-8DB9D949CD93}" -EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution src\Shared\RenderHelpers\RenderHelpers.projitems*{3c4c0cb4-0c0f-4450-a37b-148c84ff905f}*SharedItemsImports = 13 @@ -2516,46 +2514,6 @@ Global {E1240B49-7B4B-4371-A00E-068778C5CF0B}.Release|NetCoreOnly.Build.0 = Release|Any CPU {E1240B49-7B4B-4371-A00E-068778C5CF0B}.Release|x86.ActiveCfg = Release|Any CPU {E1240B49-7B4B-4371-A00E-068778C5CF0B}.Release|x86.Build.0 = Release|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Ad-Hoc|NetCoreOnly.ActiveCfg = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Ad-Hoc|NetCoreOnly.Build.0 = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Ad-Hoc|x86.Build.0 = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.AppStore|Any CPU.Build.0 = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.AppStore|iPhone.ActiveCfg = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.AppStore|iPhone.Build.0 = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.AppStore|NetCoreOnly.ActiveCfg = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.AppStore|NetCoreOnly.Build.0 = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.AppStore|x86.ActiveCfg = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.AppStore|x86.Build.0 = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Debug|Any CPU.Build.0 = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Debug|iPhone.Build.0 = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Debug|NetCoreOnly.ActiveCfg = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Debug|NetCoreOnly.Build.0 = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Debug|x86.ActiveCfg = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Debug|x86.Build.0 = Debug|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Release|Any CPU.ActiveCfg = Release|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Release|Any CPU.Build.0 = Release|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Release|iPhone.ActiveCfg = Release|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Release|iPhone.Build.0 = Release|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Release|NetCoreOnly.ActiveCfg = Release|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Release|NetCoreOnly.Build.0 = Release|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Release|x86.ActiveCfg = Release|Any CPU - {54A1062E-126E-4813-98A7-8DB9D949CD93}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Avalonia.Controls/Image.cs b/src/Avalonia.Controls/Image.cs index a9f24f5ce4..beddc75917 100644 --- a/src/Avalonia.Controls/Image.cs +++ b/src/Avalonia.Controls/Image.cs @@ -26,17 +26,10 @@ namespace Avalonia.Controls public static readonly StyledProperty StretchProperty = AvaloniaProperty.Register(nameof(Stretch), Stretch.Uniform); - /// - /// Defines the property. - /// - public static readonly StyledProperty ScalingModeProperty = - AvaloniaProperty.Register(nameof(BitmapScalingMode)); - static Image() { AffectsRender(SourceProperty); AffectsRender(StretchProperty); - AffectsRender(ScalingModeProperty); } /// @@ -57,12 +50,6 @@ namespace Avalonia.Controls set { SetValue(StretchProperty, value); } } - public BitmapScalingMode ScalingMode - { - get { return (BitmapScalingMode)GetValue(ScalingModeProperty); } - set { SetValue(ScalingModeProperty, value); } - } - /// /// Renders the control. /// @@ -83,7 +70,9 @@ namespace Avalonia.Controls Rect sourceRect = new Rect(sourceSize) .CenterRect(new Rect(destRect.Size / scale)); - context.DrawImage(source, 1, sourceRect, destRect, ScalingMode); + var scalingMode = RenderOptions.GetBitmapScalingMode(this); + + context.DrawImage(source, 1, sourceRect, destRect, scalingMode); } } diff --git a/src/Avalonia.Controls/RenderOptions.cs b/src/Avalonia.Controls/RenderOptions.cs new file mode 100644 index 0000000000..dff1d940d0 --- /dev/null +++ b/src/Avalonia.Controls/RenderOptions.cs @@ -0,0 +1,36 @@ +namespace Avalonia.Controls +{ + using Avalonia.Visuals.Media.Imaging; + + public class RenderOptions + { + /// + /// Defines the property. + /// + public static readonly StyledProperty BitmapScalingModeProperty = + AvaloniaProperty.RegisterAttached( + "BitmapScalingMode", + BitmapScalingMode.LowQuality, + inherits: true); + + /// + /// Gets the value of the BitmapScalingMode attached property for a control. + /// + /// The control. + /// The control's left coordinate. + public static BitmapScalingMode GetBitmapScalingMode(AvaloniaObject element) + { + return element.GetValue(BitmapScalingModeProperty); + } + + /// + /// Sets the value of the BitmapScalingMode attached property for a control. + /// + /// The control. + /// The left value. + public static void SetBitmapScalingMode(AvaloniaObject element, double value) + { + element.SetValue(BitmapScalingModeProperty, value); + } + } +}