From 5bfbfb97d3689acd353136b05136f8d825010ef6 Mon Sep 17 00:00:00 2001 From: Rustam Sayfutdinov Date: Sun, 14 Feb 2021 11:36:06 +0300 Subject: [PATCH 01/72] Use ControlCatalog.NetCore as an artifact instead of ControlCatalog.Desktop --- nukebuild/Build.cs | 17 +++++++++++------ nukebuild/BuildParameters.cs | 7 ++----- .../ControlCatalog.NetCore.csproj | 6 +++++- samples/ControlCatalog/ControlCatalog.csproj | 2 +- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/nukebuild/Build.cs b/nukebuild/Build.cs index 8e331edab4..2c6ec70bd6 100644 --- a/nukebuild/Build.cs +++ b/nukebuild/Build.cs @@ -305,14 +305,19 @@ partial class Build : NukeBuild .Executes(() => { var data = Parameters; + var pathToProjectSource = RootDirectory / "samples" / "ControlCatalog.NetCore"; + var pathToPublish = pathToProjectSource / "bin" / data.Configuration / "publish"; + + DotNetPublish(c => c + .SetProject(pathToProjectSource / "ControlCatalog.NetCore.csproj") + .EnableNoBuild() + .SetConfiguration(data.Configuration) + .AddProperty("PackageVersion", data.Version) + .AddProperty("PublishDir", pathToPublish)); + Zip(data.ZipCoreArtifacts, data.BinRoot); Zip(data.ZipNuGetArtifacts, data.NugetRoot); - Zip(data.ZipTargetControlCatalogDesktopDir, - GlobFiles(data.ZipSourceControlCatalogDesktopDir, "*.dll").Concat( - GlobFiles(data.ZipSourceControlCatalogDesktopDir, "*.config")).Concat( - GlobFiles(data.ZipSourceControlCatalogDesktopDir, "*.so")).Concat( - GlobFiles(data.ZipSourceControlCatalogDesktopDir, "*.dylib")).Concat( - GlobFiles(data.ZipSourceControlCatalogDesktopDir, "*.exe"))); + Zip(data.ZipTargetControlCatalogNetCoreDir, pathToPublish); }); Target CreateIntermediateNugetPackages => _ => _ diff --git a/nukebuild/BuildParameters.cs b/nukebuild/BuildParameters.cs index c76019d9eb..a92c988fbd 100644 --- a/nukebuild/BuildParameters.cs +++ b/nukebuild/BuildParameters.cs @@ -58,8 +58,7 @@ public partial class Build public string FileZipSuffix { get; } public AbsolutePath ZipCoreArtifacts { get; } public AbsolutePath ZipNuGetArtifacts { get; } - public AbsolutePath ZipSourceControlCatalogDesktopDir { get; } - public AbsolutePath ZipTargetControlCatalogDesktopDir { get; } + public AbsolutePath ZipTargetControlCatalogNetCoreDir { get; } public BuildParameters(Build b) @@ -129,9 +128,7 @@ public partial class Build FileZipSuffix = Version + ".zip"; ZipCoreArtifacts = ZipRoot / ("Avalonia-" + FileZipSuffix); ZipNuGetArtifacts = ZipRoot / ("Avalonia-NuGet-" + FileZipSuffix); - ZipSourceControlCatalogDesktopDir = - RootDirectory / ("samples/ControlCatalog.Desktop/bin/" + DirSuffix + "/net461"); - ZipTargetControlCatalogDesktopDir = ZipRoot / ("ControlCatalog.Desktop-" + FileZipSuffix); + ZipTargetControlCatalogNetCoreDir = ZipRoot / ("ControlCatalog.NetCore-" + FileZipSuffix); } string GetVersion() diff --git a/samples/ControlCatalog.NetCore/ControlCatalog.NetCore.csproj b/samples/ControlCatalog.NetCore/ControlCatalog.NetCore.csproj index d5aedf7783..3c2d2ee359 100644 --- a/samples/ControlCatalog.NetCore/ControlCatalog.NetCore.csproj +++ b/samples/ControlCatalog.NetCore/ControlCatalog.NetCore.csproj @@ -1,7 +1,7 @@  - Exe + WinExe netcoreapp3.1 true @@ -15,6 +15,10 @@ + + + en + diff --git a/samples/ControlCatalog/ControlCatalog.csproj b/samples/ControlCatalog/ControlCatalog.csproj index 1aa926a2a6..53ad213d92 100644 --- a/samples/ControlCatalog/ControlCatalog.csproj +++ b/samples/ControlCatalog/ControlCatalog.csproj @@ -27,6 +27,6 @@ - + From d7f3c24365a9cb73649363892ea0296e89b1a9c1 Mon Sep 17 00:00:00 2001 From: Dariusz Komosinski Date: Thu, 25 Feb 2021 13:24:20 +0100 Subject: [PATCH 02/72] Allow for controlling behavior of CaptionButtons. --- .../Chrome/CaptionButtons.cs | 73 ++++++++++++------- 1 file changed, 45 insertions(+), 28 deletions(-) diff --git a/src/Avalonia.Controls/Chrome/CaptionButtons.cs b/src/Avalonia.Controls/Chrome/CaptionButtons.cs index cd60130c5b..d41a95b5a0 100644 --- a/src/Avalonia.Controls/Chrome/CaptionButtons.cs +++ b/src/Avalonia.Controls/Chrome/CaptionButtons.cs @@ -14,17 +14,21 @@ namespace Avalonia.Controls.Chrome public class CaptionButtons : TemplatedControl { private CompositeDisposable? _disposables; - private Window? _hostWindow; - public void Attach(Window hostWindow) + /// + /// Currently attached window. + /// + protected Window? HostWindow { get; private set; } + + public virtual void Attach(Window hostWindow) { if (_disposables == null) { - _hostWindow = hostWindow; + HostWindow = hostWindow; _disposables = new CompositeDisposable { - _hostWindow.GetObservable(Window.WindowStateProperty) + HostWindow.GetObservable(Window.WindowStateProperty) .Subscribe(x => { PseudoClasses.Set(":minimized", x == WindowState.Minimized); @@ -36,14 +40,45 @@ namespace Avalonia.Controls.Chrome } } - public void Detach() + public virtual void Detach() { if (_disposables != null) { _disposables.Dispose(); _disposables = null; - _hostWindow = null; + HostWindow = null; + } + } + + protected virtual void OnClose() + { + HostWindow?.Close(); + } + + protected virtual void OnRestore() + { + if (HostWindow != null) + { + HostWindow.WindowState = HostWindow.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized; + } + } + + protected virtual void OnMinimize() + { + if (HostWindow != null) + { + HostWindow.WindowState = WindowState.Minimized; + } + } + + private void OnToggleFullScreen() + { + if (HostWindow != null) + { + HostWindow.WindowState = HostWindow.WindowState == WindowState.FullScreen + ? WindowState.Normal + : WindowState.FullScreen; } } @@ -56,31 +91,13 @@ namespace Avalonia.Controls.Chrome var minimiseButton = e.NameScope.Get("PART_MinimiseButton"); var fullScreenButton = e.NameScope.Get("PART_FullScreenButton"); - closeButton.PointerReleased += (sender, e) => _hostWindow?.Close(); + closeButton.PointerReleased += (sender, e) => OnClose(); - restoreButton.PointerReleased += (sender, e) => - { - if (_hostWindow != null) - { - _hostWindow.WindowState = _hostWindow.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized; - } - }; + restoreButton.PointerReleased += (sender, e) => OnRestore(); - minimiseButton.PointerReleased += (sender, e) => - { - if (_hostWindow != null) - { - _hostWindow.WindowState = WindowState.Minimized; - } - }; + minimiseButton.PointerReleased += (sender, e) => OnMinimize(); - fullScreenButton.PointerReleased += (sender, e) => - { - if (_hostWindow != null) - { - _hostWindow.WindowState = _hostWindow.WindowState == WindowState.FullScreen ? WindowState.Normal : WindowState.FullScreen; - } - }; + fullScreenButton.PointerReleased += (sender, e) => OnToggleFullScreen(); } } } From 8a79141c24647376e392790607170ba3b4a31aa5 Mon Sep 17 00:00:00 2001 From: Dariusz Komosinski Date: Thu, 25 Feb 2021 14:56:51 +0100 Subject: [PATCH 03/72] Fix access modifer. --- src/Avalonia.Controls/Chrome/CaptionButtons.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Chrome/CaptionButtons.cs b/src/Avalonia.Controls/Chrome/CaptionButtons.cs index d41a95b5a0..be15d3d444 100644 --- a/src/Avalonia.Controls/Chrome/CaptionButtons.cs +++ b/src/Avalonia.Controls/Chrome/CaptionButtons.cs @@ -72,7 +72,7 @@ namespace Avalonia.Controls.Chrome } } - private void OnToggleFullScreen() + protected virtual void OnToggleFullScreen() { if (HostWindow != null) { From cf8117d9ecfe53687879ee4c6af1223f78d8319d Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 5 Mar 2021 17:58:08 +0000 Subject: [PATCH 04/72] change default extend chrome hint --- src/Avalonia.Controls/ApiCompatBaseline.txt | 3 ++- src/Avalonia.Controls/Platform/ExtendClientAreaChromeHints.cs | 2 +- src/Avalonia.Native/avn.idl | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.Controls/ApiCompatBaseline.txt b/src/Avalonia.Controls/ApiCompatBaseline.txt index e5adc8c6ed..f55f440db9 100644 --- a/src/Avalonia.Controls/ApiCompatBaseline.txt +++ b/src/Avalonia.Controls/ApiCompatBaseline.txt @@ -1,6 +1,7 @@ Compat issues with assembly Avalonia.Controls: MembersMustExist : Member 'public void Avalonia.Controls.Embedding.Offscreen.OffscreenTopLevelImplBase.SetCursor(Avalonia.Platform.IPlatformHandle)' does not exist in the implementation but it does exist in the contract. +EnumValuesMustMatch : Enum value 'Avalonia.Platform.ExtendClientAreaChromeHints Avalonia.Platform.ExtendClientAreaChromeHints.Default' is (System.Int32)2 in the implementation but (System.Int32)1 in the contract. InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Platform.ITopLevelImpl.SetCursor(Avalonia.Platform.ICursorImpl)' is present in the implementation but not in the contract. InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Platform.ITopLevelImpl.SetCursor(Avalonia.Platform.IPlatformHandle)' is present in the contract but not in the implementation. MembersMustExist : Member 'public void Avalonia.Platform.ITopLevelImpl.SetCursor(Avalonia.Platform.IPlatformHandle)' does not exist in the implementation but it does exist in the contract. -Total Issues: 4 +Total Issues: 5 diff --git a/src/Avalonia.Controls/Platform/ExtendClientAreaChromeHints.cs b/src/Avalonia.Controls/Platform/ExtendClientAreaChromeHints.cs index de3f58886b..bb3c0288eb 100644 --- a/src/Avalonia.Controls/Platform/ExtendClientAreaChromeHints.cs +++ b/src/Avalonia.Controls/Platform/ExtendClientAreaChromeHints.cs @@ -16,7 +16,7 @@ namespace Avalonia.Platform /// /// The default for the platform. /// - Default = SystemChrome, + Default = PreferSystemChrome, /// /// Use SystemChrome diff --git a/src/Avalonia.Native/avn.idl b/src/Avalonia.Native/avn.idl index 57a0c32067..476e64bd2d 100644 --- a/src/Avalonia.Native/avn.idl +++ b/src/Avalonia.Native/avn.idl @@ -397,7 +397,7 @@ enum AvnExtendClientAreaChromeHints AvnSystemChrome = 0x01, AvnPreferSystemChrome = 0x02, AvnOSXThickTitleBar = 0x08, - AvnDefaultChrome = AvnSystemChrome, + AvnDefaultChrome = AvnPreferSystemChrome, } [uuid(809c652e-7396-11d2-9771-00a0c9b4d50c)] From d1f44dcdf4d89abf20bba753494a3ac23728fd5e Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 16 Mar 2021 11:57:59 +0100 Subject: [PATCH 05/72] Added DevToolsOptions. With options to: - Set the key gesture - Show as child window - Set the initial size Co-Authored-By: workgroupengineering --- .../DevToolsExtensions.cs | 12 ++++++++- .../Diagnostics/DevTools.cs | 24 ++++++++++++----- .../Diagnostics/DevToolsOptions.cs | 26 +++++++++++++++++++ 3 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 src/Avalonia.Diagnostics/Diagnostics/DevToolsOptions.cs diff --git a/src/Avalonia.Diagnostics/DevToolsExtensions.cs b/src/Avalonia.Diagnostics/DevToolsExtensions.cs index 4bc2ca313f..a432c94a5d 100644 --- a/src/Avalonia.Diagnostics/DevToolsExtensions.cs +++ b/src/Avalonia.Diagnostics/DevToolsExtensions.cs @@ -15,7 +15,7 @@ namespace Avalonia /// The window to attach DevTools to. public static void AttachDevTools(this TopLevel root) { - DevTools.Attach(root, new KeyGesture(Key.F12)); + DevTools.Attach(root, new DevToolsOptions()); } /// @@ -27,5 +27,15 @@ namespace Avalonia { DevTools.Attach(root, gesture); } + + /// + /// Attaches DevTools to a window, to be opened with the specified options. + /// + /// The window to attach DevTools to. + /// additional settint of DevTools + public static void AttachDevTools(this TopLevel root, DevToolsOptions options) + { + DevTools.Attach(root, options); + } } } diff --git a/src/Avalonia.Diagnostics/Diagnostics/DevTools.cs b/src/Avalonia.Diagnostics/Diagnostics/DevTools.cs index 4899be2955..7942d22962 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/DevTools.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/DevTools.cs @@ -6,6 +6,8 @@ using Avalonia.Diagnostics.Views; using Avalonia.Input; using Avalonia.Interactivity; +#nullable enable + namespace Avalonia.Diagnostics { public static class DevTools @@ -13,12 +15,20 @@ namespace Avalonia.Diagnostics private static readonly Dictionary s_open = new Dictionary(); public static IDisposable Attach(TopLevel root, KeyGesture gesture) + { + return Attach(root, new DevToolsOptions() + { + Gesture = gesture, + }); + } + + public static IDisposable Attach(TopLevel root, DevToolsOptions options) { void PreviewKeyDown(object sender, KeyEventArgs e) { - if (gesture.Matches(e)) + if (options.Gesture.Matches(e)) { - Open(root); + Open(root, options); } } @@ -28,7 +38,9 @@ namespace Avalonia.Diagnostics RoutingStrategies.Tunnel); } - public static IDisposable Open(TopLevel root) + public static IDisposable Open(TopLevel root) => Open(root, new DevToolsOptions()); + + public static IDisposable Open(TopLevel root, DevToolsOptions options) { if (s_open.TryGetValue(root, out var window)) { @@ -38,15 +50,15 @@ namespace Avalonia.Diagnostics { window = new MainWindow { - Width = 1024, - Height = 512, Root = root, + Width = options.Size.Width, + Height = options.Size.Height, }; window.Closed += DevToolsClosed; s_open.Add(root, window); - if (root is Window inspectedWindow) + if (options.ShowAsChildWindow && root is Window inspectedWindow) { window.Show(inspectedWindow); } diff --git a/src/Avalonia.Diagnostics/Diagnostics/DevToolsOptions.cs b/src/Avalonia.Diagnostics/Diagnostics/DevToolsOptions.cs new file mode 100644 index 0000000000..ee46192207 --- /dev/null +++ b/src/Avalonia.Diagnostics/Diagnostics/DevToolsOptions.cs @@ -0,0 +1,26 @@ +using Avalonia.Input; + +namespace Avalonia.Diagnostics +{ + /// + /// Describes options used to customize DevTools. + /// + public class DevToolsOptions + { + /// + /// Gets or sets the key gesture used to open DevTools. + /// + public KeyGesture Gesture { get; set; } = new KeyGesture(Key.F12); + + /// + /// Gets or sets a value indicating whether DevTools should be displayed as a child window + /// of the window being inspected. The default value is true. + /// + public bool ShowAsChildWindow { get; set; } = true; + + /// + /// Gets or sets the initial size of the DevTools window. The default value is 1024x512. + /// + public Size Size { get; set; } = new Size(1024, 512); + } +} From f71d6b64c1085a6b0d1aaaf221e1c56248eaf1dc Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Thu, 18 Mar 2021 10:30:46 +0800 Subject: [PATCH 06/72] add new Path measurement API on IGeometryImpl.cs --- .../Platform/IGeometryImpl.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/Avalonia.Visuals/Platform/IGeometryImpl.cs b/src/Avalonia.Visuals/Platform/IGeometryImpl.cs index 7490ad912a..5c39afa846 100644 --- a/src/Avalonia.Visuals/Platform/IGeometryImpl.cs +++ b/src/Avalonia.Visuals/Platform/IGeometryImpl.cs @@ -11,6 +11,12 @@ namespace Avalonia.Platform /// Gets the geometry's bounding rectangle. /// Rect Bounds { get; } + + /// + /// Gets the geometry's total length as if all its contours are placed + /// in a straight line. + /// + double ContourLength { get; } /// /// Gets the geometry's bounding rectangle with the specified pen. @@ -47,5 +53,25 @@ namespace Avalonia.Platform /// The transform. /// The cloned geometry. ITransformedGeometryImpl WithTransform(Matrix transform); + + /// + /// Attempts to get the corresponding point from the + /// specified distance + /// + /// The contour distance to get from. + /// The point in the specified distance. + /// If there's valid point at the specified distance. + bool TryGetPointAtDistance(double distance, out Point point); + + /// + /// Attempts to get the corresponding point and + /// tangent from the specified distance along the + /// contour of the geometry. + /// + /// The contour distance to get from. + /// The point in the specified distance. + /// The tangent in the specified distance. + /// If there's valid point and tangent at the specified distance. + bool TryGetPositionAndTangentAtDistance (double distance, out Point position, out Point tangent); } } From ceb170e472cebb4ec1f60243deb9a91b1ee39722 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Thu, 18 Mar 2021 11:01:02 +0800 Subject: [PATCH 07/72] add apicompat for the new api --- src/Avalonia.Controls.DataGrid/ApiCompatBaseline.txt | 1 + src/Avalonia.DesignerSupport/ApiCompatBaseline.txt | 1 + src/Avalonia.Desktop/ApiCompatBaseline.txt | 1 + src/Avalonia.DesktopRuntime/ApiCompatBaseline.txt | 1 + src/Avalonia.Diagnostics/ApiCompatBaseline.txt | 1 + src/Avalonia.Dialogs/ApiCompatBaseline.txt | 1 + src/Avalonia.Interactivity/ApiCompatBaseline.txt | 1 + src/Avalonia.Layout/ApiCompatBaseline.txt | 1 + src/Avalonia.Themes.Default/ApiCompatBaseline.txt | 1 + src/Avalonia.Themes.Fluent/ApiCompatBaseline.txt | 1 + src/Avalonia.Visuals/ApiCompatBaseline.txt | 6 ++++++ src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt | 1 + src/Markup/Avalonia.Markup/ApiCompatBaseline.txt | 1 + 13 files changed, 18 insertions(+) create mode 100644 src/Avalonia.Controls.DataGrid/ApiCompatBaseline.txt create mode 100644 src/Avalonia.DesignerSupport/ApiCompatBaseline.txt create mode 100644 src/Avalonia.Desktop/ApiCompatBaseline.txt create mode 100644 src/Avalonia.DesktopRuntime/ApiCompatBaseline.txt create mode 100644 src/Avalonia.Diagnostics/ApiCompatBaseline.txt create mode 100644 src/Avalonia.Dialogs/ApiCompatBaseline.txt create mode 100644 src/Avalonia.Interactivity/ApiCompatBaseline.txt create mode 100644 src/Avalonia.Layout/ApiCompatBaseline.txt create mode 100644 src/Avalonia.Themes.Default/ApiCompatBaseline.txt create mode 100644 src/Avalonia.Themes.Fluent/ApiCompatBaseline.txt create mode 100644 src/Avalonia.Visuals/ApiCompatBaseline.txt create mode 100644 src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt create mode 100644 src/Markup/Avalonia.Markup/ApiCompatBaseline.txt diff --git a/src/Avalonia.Controls.DataGrid/ApiCompatBaseline.txt b/src/Avalonia.Controls.DataGrid/ApiCompatBaseline.txt new file mode 100644 index 0000000000..fcc74cf864 --- /dev/null +++ b/src/Avalonia.Controls.DataGrid/ApiCompatBaseline.txt @@ -0,0 +1 @@ +Total Issues: 0 diff --git a/src/Avalonia.DesignerSupport/ApiCompatBaseline.txt b/src/Avalonia.DesignerSupport/ApiCompatBaseline.txt new file mode 100644 index 0000000000..fcc74cf864 --- /dev/null +++ b/src/Avalonia.DesignerSupport/ApiCompatBaseline.txt @@ -0,0 +1 @@ +Total Issues: 0 diff --git a/src/Avalonia.Desktop/ApiCompatBaseline.txt b/src/Avalonia.Desktop/ApiCompatBaseline.txt new file mode 100644 index 0000000000..fcc74cf864 --- /dev/null +++ b/src/Avalonia.Desktop/ApiCompatBaseline.txt @@ -0,0 +1 @@ +Total Issues: 0 diff --git a/src/Avalonia.DesktopRuntime/ApiCompatBaseline.txt b/src/Avalonia.DesktopRuntime/ApiCompatBaseline.txt new file mode 100644 index 0000000000..fcc74cf864 --- /dev/null +++ b/src/Avalonia.DesktopRuntime/ApiCompatBaseline.txt @@ -0,0 +1 @@ +Total Issues: 0 diff --git a/src/Avalonia.Diagnostics/ApiCompatBaseline.txt b/src/Avalonia.Diagnostics/ApiCompatBaseline.txt new file mode 100644 index 0000000000..fcc74cf864 --- /dev/null +++ b/src/Avalonia.Diagnostics/ApiCompatBaseline.txt @@ -0,0 +1 @@ +Total Issues: 0 diff --git a/src/Avalonia.Dialogs/ApiCompatBaseline.txt b/src/Avalonia.Dialogs/ApiCompatBaseline.txt new file mode 100644 index 0000000000..fcc74cf864 --- /dev/null +++ b/src/Avalonia.Dialogs/ApiCompatBaseline.txt @@ -0,0 +1 @@ +Total Issues: 0 diff --git a/src/Avalonia.Interactivity/ApiCompatBaseline.txt b/src/Avalonia.Interactivity/ApiCompatBaseline.txt new file mode 100644 index 0000000000..fcc74cf864 --- /dev/null +++ b/src/Avalonia.Interactivity/ApiCompatBaseline.txt @@ -0,0 +1 @@ +Total Issues: 0 diff --git a/src/Avalonia.Layout/ApiCompatBaseline.txt b/src/Avalonia.Layout/ApiCompatBaseline.txt new file mode 100644 index 0000000000..fcc74cf864 --- /dev/null +++ b/src/Avalonia.Layout/ApiCompatBaseline.txt @@ -0,0 +1 @@ +Total Issues: 0 diff --git a/src/Avalonia.Themes.Default/ApiCompatBaseline.txt b/src/Avalonia.Themes.Default/ApiCompatBaseline.txt new file mode 100644 index 0000000000..fcc74cf864 --- /dev/null +++ b/src/Avalonia.Themes.Default/ApiCompatBaseline.txt @@ -0,0 +1 @@ +Total Issues: 0 diff --git a/src/Avalonia.Themes.Fluent/ApiCompatBaseline.txt b/src/Avalonia.Themes.Fluent/ApiCompatBaseline.txt new file mode 100644 index 0000000000..fcc74cf864 --- /dev/null +++ b/src/Avalonia.Themes.Fluent/ApiCompatBaseline.txt @@ -0,0 +1 @@ +Total Issues: 0 diff --git a/src/Avalonia.Visuals/ApiCompatBaseline.txt b/src/Avalonia.Visuals/ApiCompatBaseline.txt new file mode 100644 index 0000000000..f51f26974e --- /dev/null +++ b/src/Avalonia.Visuals/ApiCompatBaseline.txt @@ -0,0 +1,6 @@ +Compat issues with assembly Avalonia.Visuals: +InterfacesShouldHaveSameMembers : Interface member 'public System.Double Avalonia.Platform.IGeometryImpl.ContourLength' is present in the implementation but not in the contract. +InterfacesShouldHaveSameMembers : Interface member 'public System.Double Avalonia.Platform.IGeometryImpl.ContourLength.get()' is present in the implementation but not in the contract. +InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalonia.Platform.IGeometryImpl.TryGetPointAndTangentAtDistance(System.Double, Avalonia.Point, Avalonia.Point)' is present in the implementation but not in the contract. +InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalonia.Platform.IGeometryImpl.TryGetPointAtDistance(System.Double, Avalonia.Point)' is present in the implementation but not in the contract. +Total Issues: 4 diff --git a/src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt b/src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt new file mode 100644 index 0000000000..fcc74cf864 --- /dev/null +++ b/src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt @@ -0,0 +1 @@ +Total Issues: 0 diff --git a/src/Markup/Avalonia.Markup/ApiCompatBaseline.txt b/src/Markup/Avalonia.Markup/ApiCompatBaseline.txt new file mode 100644 index 0000000000..fcc74cf864 --- /dev/null +++ b/src/Markup/Avalonia.Markup/ApiCompatBaseline.txt @@ -0,0 +1 @@ +Total Issues: 0 From d7f149914d8ca307e4859fa4c4f3f5bad8173693 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Thu, 18 Mar 2021 11:17:57 +0800 Subject: [PATCH 08/72] change api again --- src/Avalonia.Visuals/Platform/IGeometryImpl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Visuals/Platform/IGeometryImpl.cs b/src/Avalonia.Visuals/Platform/IGeometryImpl.cs index 5c39afa846..c61e6c6112 100644 --- a/src/Avalonia.Visuals/Platform/IGeometryImpl.cs +++ b/src/Avalonia.Visuals/Platform/IGeometryImpl.cs @@ -72,6 +72,6 @@ namespace Avalonia.Platform /// The point in the specified distance. /// The tangent in the specified distance. /// If there's valid point and tangent at the specified distance. - bool TryGetPositionAndTangentAtDistance (double distance, out Point position, out Point tangent); + bool TryGetPointAndTangentAtDistance(double distance, out Point point, out Point tangent); } } From c6581cf02023c99b21e64cd973d2490576563136 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Thu, 18 Mar 2021 11:22:55 +0800 Subject: [PATCH 09/72] api compat update --- src/Avalonia.Animation/ApiCompatBaseline.txt | 1 + src/Avalonia.Base/ApiCompatBaseline.txt | 1 + src/Avalonia.Remote.Protocol/ApiCompatBaseline.txt | 1 + 3 files changed, 3 insertions(+) create mode 100644 src/Avalonia.Animation/ApiCompatBaseline.txt create mode 100644 src/Avalonia.Base/ApiCompatBaseline.txt create mode 100644 src/Avalonia.Remote.Protocol/ApiCompatBaseline.txt diff --git a/src/Avalonia.Animation/ApiCompatBaseline.txt b/src/Avalonia.Animation/ApiCompatBaseline.txt new file mode 100644 index 0000000000..fcc74cf864 --- /dev/null +++ b/src/Avalonia.Animation/ApiCompatBaseline.txt @@ -0,0 +1 @@ +Total Issues: 0 diff --git a/src/Avalonia.Base/ApiCompatBaseline.txt b/src/Avalonia.Base/ApiCompatBaseline.txt new file mode 100644 index 0000000000..fcc74cf864 --- /dev/null +++ b/src/Avalonia.Base/ApiCompatBaseline.txt @@ -0,0 +1 @@ +Total Issues: 0 diff --git a/src/Avalonia.Remote.Protocol/ApiCompatBaseline.txt b/src/Avalonia.Remote.Protocol/ApiCompatBaseline.txt new file mode 100644 index 0000000000..fcc74cf864 --- /dev/null +++ b/src/Avalonia.Remote.Protocol/ApiCompatBaseline.txt @@ -0,0 +1 @@ +Total Issues: 0 From 60d111b074fa51c61d0f83d284deadd5adf9a869 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Thu, 18 Mar 2021 11:24:12 +0800 Subject: [PATCH 10/72] add skia implementation --- src/Skia/Avalonia.Skia/GeometryImpl.cs | 43 +++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/Skia/Avalonia.Skia/GeometryImpl.cs b/src/Skia/Avalonia.Skia/GeometryImpl.cs index 879b18742e..e8b5795f60 100644 --- a/src/Skia/Avalonia.Skia/GeometryImpl.cs +++ b/src/Skia/Avalonia.Skia/GeometryImpl.cs @@ -11,9 +11,20 @@ namespace Avalonia.Skia internal abstract class GeometryImpl : IGeometryImpl { private PathCache _pathCache; - + /// public abstract Rect Bounds { get; } + + /// + public double ContourLength + { + get + { + if (EffectivePath is null) return 0; + return new SKPathMeasure(EffectivePath).Length; + } + } + public abstract SKPath EffectivePath { get; } /// @@ -103,6 +114,36 @@ namespace Avalonia.Skia { return new TransformedGeometryImpl(this, transform); } + + /// + public bool TryGetPointAtDistance(double distance, out Point point) + { + if (EffectivePath is null) + { + point = new Point(); + return false; + } + + var res = new SKPathMeasure(EffectivePath).GetPosition((float)distance, out var skPoint); + point = new Point(skPoint.X, skPoint.Y); + return res; + } + + /// + public bool TryGetPointAndTangentAtDistance(double distance, out Point point, out Point tangent) + { + if (EffectivePath is null) + { + point = new Point(); + tangent = new Point(); + return false; + } + + var res = new SKPathMeasure(EffectivePath).GetPositionAndTangent((float)distance, out var skPoint, out var skTangent); + point = new Point(skPoint.X, skPoint.Y); + tangent = new Point(skTangent.X, skTangent.Y); + return res; + } /// /// Invalidate all caches. Call after chaining path contents. From 38b322b02b5aa2b62d86038ba97bc2484a2e987c Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Thu, 18 Mar 2021 11:24:22 +0800 Subject: [PATCH 11/72] add partial d2d implementation --- .../Avalonia.Direct2D1/Media/GeometryImpl.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs b/src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs index d04e2b3110..81c21c8648 100644 --- a/src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs +++ b/src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs @@ -1,3 +1,4 @@ +using Avalonia.Logging; using Avalonia.Platform; using SharpDX.Direct2D1; @@ -8,6 +9,8 @@ namespace Avalonia.Direct2D1.Media /// public abstract class GeometryImpl : IGeometryImpl { + private const float ContourApproximation = 0.0001f; + public GeometryImpl(Geometry geometry) { Geometry = geometry; @@ -16,6 +19,9 @@ namespace Avalonia.Direct2D1.Media /// public Rect Bounds => Geometry.GetWidenedBounds(0).ToAvalonia(); + /// + public double ContourLength => Geometry.ComputeLength(null, ContourApproximation); + public Geometry Geometry { get; } /// @@ -57,6 +63,24 @@ namespace Avalonia.Direct2D1.Media transform.ToDirect2D()), this); } + + /// + public bool TryGetPointAtDistance(double distance, out Point point) + { + Geometry.ComputePointAtLength((float)distance, ContourApproximation, out var tangentVector); + point = new Point(tangentVector.X, tangentVector.Y); + return true; + } + + /// + public bool TryGetPointAndTangentAtDistance(double distance, out Point point, out Point tangent) + { + // Direct2D doesnt have this sadly. + Logger.TryGet(LogEventLevel.Warning, LogArea.Visual)?.Log(this, "TryGetPointAndTangentAtDistance is not available in Direct2D."); + point = new Point(); + tangent = new Point(); + return false; + } protected virtual Geometry GetSourceGeometry() => Geometry; } From 386a318abe2cdc4811832d6f68f56e232217b06b Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Thu, 18 Mar 2021 11:24:37 +0800 Subject: [PATCH 12/72] add stubs for headless/mock --- .../HeadlessPlatformRenderInterface.cs | 16 ++++++++++++++++ .../Avalonia.UnitTests/MockStreamGeometryImpl.cs | 15 +++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs b/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs index 6a78f4c6e7..ce5a8a2e86 100644 --- a/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs +++ b/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs @@ -104,6 +104,9 @@ namespace Avalonia.Headless } public Rect Bounds { get; set; } + + public double ContourLength { get; } = 0; + public virtual bool FillContains(Point point) => Bounds.Contains(point); public Rect GetRenderBounds(IPen pen) @@ -126,6 +129,19 @@ namespace Avalonia.Headless public ITransformedGeometryImpl WithTransform(Matrix transform) => new HeadlessTransformedGeometryStub(this, transform); + + public bool TryGetPointAtDistance(double distance, out Point point) + { + point = new Point(); + return false; + } + + public bool TryGetPointAndTangentAtDistance(double distance, out Point point, out Point tangent) + { + point = new Point(); + tangent = new Point(); + return false; + } } class HeadlessTransformedGeometryStub : HeadlessGeometryStub, ITransformedGeometryImpl diff --git a/tests/Avalonia.UnitTests/MockStreamGeometryImpl.cs b/tests/Avalonia.UnitTests/MockStreamGeometryImpl.cs index 4fa3fbf523..4e66eaeb24 100644 --- a/tests/Avalonia.UnitTests/MockStreamGeometryImpl.cs +++ b/tests/Avalonia.UnitTests/MockStreamGeometryImpl.cs @@ -30,6 +30,8 @@ namespace Avalonia.UnitTests public IGeometryImpl SourceGeometry { get; } public Rect Bounds => _context.CalculateBounds(); + + public double ContourLength { get; } public Matrix Transform { get; } @@ -69,6 +71,19 @@ namespace Avalonia.UnitTests return new MockStreamGeometryImpl(transform, _context); } + public bool TryGetPointAtDistance(double distance, out Point point) + { + point = new Point(); + return false; + } + + public bool TryGetPointAndTangentAtDistance(double distance, out Point point, out Point tangent) + { + point = new Point(); + tangent = new Point(); + return false; + } + class MockStreamGeometryContext : IStreamGeometryContextImpl { private List points = new List(); From ce655d715cb197ba3bb62bb0e56cc8ebf7eac7fe Mon Sep 17 00:00:00 2001 From: Jumar Macato <16554748+jmacato@users.noreply.github.com> Date: Thu, 18 Mar 2021 11:43:17 +0800 Subject: [PATCH 13/72] Apply suggestions from code review --- src/Avalonia.DesignerSupport/ApiCompatBaseline.txt | 2 +- src/Avalonia.Desktop/ApiCompatBaseline.txt | 2 +- src/Avalonia.DesktopRuntime/ApiCompatBaseline.txt | 2 +- src/Avalonia.Diagnostics/ApiCompatBaseline.txt | 2 +- src/Avalonia.Dialogs/ApiCompatBaseline.txt | 2 +- src/Avalonia.Interactivity/ApiCompatBaseline.txt | 2 +- src/Avalonia.Layout/ApiCompatBaseline.txt | 2 +- src/Avalonia.Remote.Protocol/ApiCompatBaseline.txt | 2 +- src/Avalonia.Themes.Default/ApiCompatBaseline.txt | 2 +- src/Avalonia.Themes.Fluent/ApiCompatBaseline.txt | 2 +- src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt | 2 +- src/Markup/Avalonia.Markup/ApiCompatBaseline.txt | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Avalonia.DesignerSupport/ApiCompatBaseline.txt b/src/Avalonia.DesignerSupport/ApiCompatBaseline.txt index fcc74cf864..8b13789179 100644 --- a/src/Avalonia.DesignerSupport/ApiCompatBaseline.txt +++ b/src/Avalonia.DesignerSupport/ApiCompatBaseline.txt @@ -1 +1 @@ -Total Issues: 0 + diff --git a/src/Avalonia.Desktop/ApiCompatBaseline.txt b/src/Avalonia.Desktop/ApiCompatBaseline.txt index fcc74cf864..8b13789179 100644 --- a/src/Avalonia.Desktop/ApiCompatBaseline.txt +++ b/src/Avalonia.Desktop/ApiCompatBaseline.txt @@ -1 +1 @@ -Total Issues: 0 + diff --git a/src/Avalonia.DesktopRuntime/ApiCompatBaseline.txt b/src/Avalonia.DesktopRuntime/ApiCompatBaseline.txt index fcc74cf864..8b13789179 100644 --- a/src/Avalonia.DesktopRuntime/ApiCompatBaseline.txt +++ b/src/Avalonia.DesktopRuntime/ApiCompatBaseline.txt @@ -1 +1 @@ -Total Issues: 0 + diff --git a/src/Avalonia.Diagnostics/ApiCompatBaseline.txt b/src/Avalonia.Diagnostics/ApiCompatBaseline.txt index fcc74cf864..8b13789179 100644 --- a/src/Avalonia.Diagnostics/ApiCompatBaseline.txt +++ b/src/Avalonia.Diagnostics/ApiCompatBaseline.txt @@ -1 +1 @@ -Total Issues: 0 + diff --git a/src/Avalonia.Dialogs/ApiCompatBaseline.txt b/src/Avalonia.Dialogs/ApiCompatBaseline.txt index fcc74cf864..8b13789179 100644 --- a/src/Avalonia.Dialogs/ApiCompatBaseline.txt +++ b/src/Avalonia.Dialogs/ApiCompatBaseline.txt @@ -1 +1 @@ -Total Issues: 0 + diff --git a/src/Avalonia.Interactivity/ApiCompatBaseline.txt b/src/Avalonia.Interactivity/ApiCompatBaseline.txt index fcc74cf864..8b13789179 100644 --- a/src/Avalonia.Interactivity/ApiCompatBaseline.txt +++ b/src/Avalonia.Interactivity/ApiCompatBaseline.txt @@ -1 +1 @@ -Total Issues: 0 + diff --git a/src/Avalonia.Layout/ApiCompatBaseline.txt b/src/Avalonia.Layout/ApiCompatBaseline.txt index fcc74cf864..8b13789179 100644 --- a/src/Avalonia.Layout/ApiCompatBaseline.txt +++ b/src/Avalonia.Layout/ApiCompatBaseline.txt @@ -1 +1 @@ -Total Issues: 0 + diff --git a/src/Avalonia.Remote.Protocol/ApiCompatBaseline.txt b/src/Avalonia.Remote.Protocol/ApiCompatBaseline.txt index fcc74cf864..8b13789179 100644 --- a/src/Avalonia.Remote.Protocol/ApiCompatBaseline.txt +++ b/src/Avalonia.Remote.Protocol/ApiCompatBaseline.txt @@ -1 +1 @@ -Total Issues: 0 + diff --git a/src/Avalonia.Themes.Default/ApiCompatBaseline.txt b/src/Avalonia.Themes.Default/ApiCompatBaseline.txt index fcc74cf864..8b13789179 100644 --- a/src/Avalonia.Themes.Default/ApiCompatBaseline.txt +++ b/src/Avalonia.Themes.Default/ApiCompatBaseline.txt @@ -1 +1 @@ -Total Issues: 0 + diff --git a/src/Avalonia.Themes.Fluent/ApiCompatBaseline.txt b/src/Avalonia.Themes.Fluent/ApiCompatBaseline.txt index fcc74cf864..8b13789179 100644 --- a/src/Avalonia.Themes.Fluent/ApiCompatBaseline.txt +++ b/src/Avalonia.Themes.Fluent/ApiCompatBaseline.txt @@ -1 +1 @@ -Total Issues: 0 + diff --git a/src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt b/src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt index fcc74cf864..8b13789179 100644 --- a/src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt +++ b/src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt @@ -1 +1 @@ -Total Issues: 0 + diff --git a/src/Markup/Avalonia.Markup/ApiCompatBaseline.txt b/src/Markup/Avalonia.Markup/ApiCompatBaseline.txt index fcc74cf864..8b13789179 100644 --- a/src/Markup/Avalonia.Markup/ApiCompatBaseline.txt +++ b/src/Markup/Avalonia.Markup/ApiCompatBaseline.txt @@ -1 +1 @@ -Total Issues: 0 + From 518d4022c85d33a8a12d08430c1b5cf2a6d6e80f Mon Sep 17 00:00:00 2001 From: Jumar Macato <16554748+jmacato@users.noreply.github.com> Date: Thu, 18 Mar 2021 11:44:01 +0800 Subject: [PATCH 14/72] Delete ApiCompatBaseline.txt --- src/Avalonia.Animation/ApiCompatBaseline.txt | 1 - src/Avalonia.Base/ApiCompatBaseline.txt | 1 - src/Avalonia.Controls.DataGrid/ApiCompatBaseline.txt | 1 - src/Avalonia.DesignerSupport/ApiCompatBaseline.txt | 1 - src/Avalonia.Desktop/ApiCompatBaseline.txt | 1 - src/Avalonia.DesktopRuntime/ApiCompatBaseline.txt | 1 - src/Avalonia.Diagnostics/ApiCompatBaseline.txt | 1 - src/Avalonia.Dialogs/ApiCompatBaseline.txt | 1 - src/Avalonia.Interactivity/ApiCompatBaseline.txt | 1 - src/Avalonia.Layout/ApiCompatBaseline.txt | 1 - src/Avalonia.Remote.Protocol/ApiCompatBaseline.txt | 1 - src/Avalonia.Themes.Default/ApiCompatBaseline.txt | 1 - src/Avalonia.Themes.Fluent/ApiCompatBaseline.txt | 1 - src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt | 1 - src/Markup/Avalonia.Markup/ApiCompatBaseline.txt | 1 - 15 files changed, 15 deletions(-) delete mode 100644 src/Avalonia.Animation/ApiCompatBaseline.txt delete mode 100644 src/Avalonia.Base/ApiCompatBaseline.txt delete mode 100644 src/Avalonia.Controls.DataGrid/ApiCompatBaseline.txt delete mode 100644 src/Avalonia.DesignerSupport/ApiCompatBaseline.txt delete mode 100644 src/Avalonia.Desktop/ApiCompatBaseline.txt delete mode 100644 src/Avalonia.DesktopRuntime/ApiCompatBaseline.txt delete mode 100644 src/Avalonia.Diagnostics/ApiCompatBaseline.txt delete mode 100644 src/Avalonia.Dialogs/ApiCompatBaseline.txt delete mode 100644 src/Avalonia.Interactivity/ApiCompatBaseline.txt delete mode 100644 src/Avalonia.Layout/ApiCompatBaseline.txt delete mode 100644 src/Avalonia.Remote.Protocol/ApiCompatBaseline.txt delete mode 100644 src/Avalonia.Themes.Default/ApiCompatBaseline.txt delete mode 100644 src/Avalonia.Themes.Fluent/ApiCompatBaseline.txt delete mode 100644 src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt delete mode 100644 src/Markup/Avalonia.Markup/ApiCompatBaseline.txt diff --git a/src/Avalonia.Animation/ApiCompatBaseline.txt b/src/Avalonia.Animation/ApiCompatBaseline.txt deleted file mode 100644 index fcc74cf864..0000000000 --- a/src/Avalonia.Animation/ApiCompatBaseline.txt +++ /dev/null @@ -1 +0,0 @@ -Total Issues: 0 diff --git a/src/Avalonia.Base/ApiCompatBaseline.txt b/src/Avalonia.Base/ApiCompatBaseline.txt deleted file mode 100644 index fcc74cf864..0000000000 --- a/src/Avalonia.Base/ApiCompatBaseline.txt +++ /dev/null @@ -1 +0,0 @@ -Total Issues: 0 diff --git a/src/Avalonia.Controls.DataGrid/ApiCompatBaseline.txt b/src/Avalonia.Controls.DataGrid/ApiCompatBaseline.txt deleted file mode 100644 index fcc74cf864..0000000000 --- a/src/Avalonia.Controls.DataGrid/ApiCompatBaseline.txt +++ /dev/null @@ -1 +0,0 @@ -Total Issues: 0 diff --git a/src/Avalonia.DesignerSupport/ApiCompatBaseline.txt b/src/Avalonia.DesignerSupport/ApiCompatBaseline.txt deleted file mode 100644 index 8b13789179..0000000000 --- a/src/Avalonia.DesignerSupport/ApiCompatBaseline.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/Avalonia.Desktop/ApiCompatBaseline.txt b/src/Avalonia.Desktop/ApiCompatBaseline.txt deleted file mode 100644 index 8b13789179..0000000000 --- a/src/Avalonia.Desktop/ApiCompatBaseline.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/Avalonia.DesktopRuntime/ApiCompatBaseline.txt b/src/Avalonia.DesktopRuntime/ApiCompatBaseline.txt deleted file mode 100644 index 8b13789179..0000000000 --- a/src/Avalonia.DesktopRuntime/ApiCompatBaseline.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/Avalonia.Diagnostics/ApiCompatBaseline.txt b/src/Avalonia.Diagnostics/ApiCompatBaseline.txt deleted file mode 100644 index 8b13789179..0000000000 --- a/src/Avalonia.Diagnostics/ApiCompatBaseline.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/Avalonia.Dialogs/ApiCompatBaseline.txt b/src/Avalonia.Dialogs/ApiCompatBaseline.txt deleted file mode 100644 index 8b13789179..0000000000 --- a/src/Avalonia.Dialogs/ApiCompatBaseline.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/Avalonia.Interactivity/ApiCompatBaseline.txt b/src/Avalonia.Interactivity/ApiCompatBaseline.txt deleted file mode 100644 index 8b13789179..0000000000 --- a/src/Avalonia.Interactivity/ApiCompatBaseline.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/Avalonia.Layout/ApiCompatBaseline.txt b/src/Avalonia.Layout/ApiCompatBaseline.txt deleted file mode 100644 index 8b13789179..0000000000 --- a/src/Avalonia.Layout/ApiCompatBaseline.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/Avalonia.Remote.Protocol/ApiCompatBaseline.txt b/src/Avalonia.Remote.Protocol/ApiCompatBaseline.txt deleted file mode 100644 index 8b13789179..0000000000 --- a/src/Avalonia.Remote.Protocol/ApiCompatBaseline.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/Avalonia.Themes.Default/ApiCompatBaseline.txt b/src/Avalonia.Themes.Default/ApiCompatBaseline.txt deleted file mode 100644 index 8b13789179..0000000000 --- a/src/Avalonia.Themes.Default/ApiCompatBaseline.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/Avalonia.Themes.Fluent/ApiCompatBaseline.txt b/src/Avalonia.Themes.Fluent/ApiCompatBaseline.txt deleted file mode 100644 index 8b13789179..0000000000 --- a/src/Avalonia.Themes.Fluent/ApiCompatBaseline.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt b/src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt deleted file mode 100644 index 8b13789179..0000000000 --- a/src/Markup/Avalonia.Markup.Xaml/ApiCompatBaseline.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/Markup/Avalonia.Markup/ApiCompatBaseline.txt b/src/Markup/Avalonia.Markup/ApiCompatBaseline.txt deleted file mode 100644 index 8b13789179..0000000000 --- a/src/Markup/Avalonia.Markup/ApiCompatBaseline.txt +++ /dev/null @@ -1 +0,0 @@ - From 88fef2fdd5f2ba6dc01d639de40bc65e571bc56b Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Thu, 18 Mar 2021 15:57:08 +0800 Subject: [PATCH 15/72] Add Bitmap Blending Mode API --- .../HeadlessPlatformRenderInterface.cs | 2 +- src/Avalonia.Visuals/ApiCompatBaseline.txt | 5 +- .../Media/Imaging/BitmapBlendingMode.cs | 57 +++++++++++++++++++ .../Platform/IDrawingContextImpl.cs | 3 +- .../SceneGraph/DeferredDrawingContextImpl.cs | 6 +- .../Rendering/SceneGraph/ImageNode.cs | 28 ++++++--- src/Skia/Avalonia.Skia/DrawingContextImpl.cs | 5 +- src/Skia/Avalonia.Skia/SkiaSharpExtensions.cs | 33 +++++++++++ .../Media/DrawingContextImpl.cs | 36 +++++++++++- 9 files changed, 156 insertions(+), 19 deletions(-) create mode 100644 src/Avalonia.Visuals/Media/Imaging/BitmapBlendingMode.cs diff --git a/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs b/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs index ce5a8a2e86..a00dc1f618 100644 --- a/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs +++ b/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs @@ -393,7 +393,7 @@ namespace Avalonia.Headless { } - public void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode = BitmapInterpolationMode.Default) + public void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode = BitmapInterpolationMode.Default, BitmapBlendingMode bitmapBlendingMode = BitmapBlendingMode.SourceOver) { } diff --git a/src/Avalonia.Visuals/ApiCompatBaseline.txt b/src/Avalonia.Visuals/ApiCompatBaseline.txt index f51f26974e..e781cb1d3e 100644 --- a/src/Avalonia.Visuals/ApiCompatBaseline.txt +++ b/src/Avalonia.Visuals/ApiCompatBaseline.txt @@ -1,6 +1,9 @@ Compat issues with assembly Avalonia.Visuals: +InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Platform.IDrawingContextImpl.DrawBitmap(Avalonia.Utilities.IRef, System.Double, Avalonia.Rect, Avalonia.Rect, Avalonia.Visuals.Media.Imaging.BitmapInterpolationMode)' is present in the contract but not in the implementation. +MembersMustExist : Member 'public void Avalonia.Platform.IDrawingContextImpl.DrawBitmap(Avalonia.Utilities.IRef, System.Double, Avalonia.Rect, Avalonia.Rect, Avalonia.Visuals.Media.Imaging.BitmapInterpolationMode)' does not exist in the implementation but it does exist in the contract. +InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Platform.IDrawingContextImpl.DrawBitmap(Avalonia.Utilities.IRef, System.Double, Avalonia.Rect, Avalonia.Rect, Avalonia.Visuals.Media.Imaging.BitmapInterpolationMode, Avalonia.Visuals.Media.Imaging.BitmapBlendingMode)' is present in the implementation but not in the contract. InterfacesShouldHaveSameMembers : Interface member 'public System.Double Avalonia.Platform.IGeometryImpl.ContourLength' is present in the implementation but not in the contract. InterfacesShouldHaveSameMembers : Interface member 'public System.Double Avalonia.Platform.IGeometryImpl.ContourLength.get()' is present in the implementation but not in the contract. InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalonia.Platform.IGeometryImpl.TryGetPointAndTangentAtDistance(System.Double, Avalonia.Point, Avalonia.Point)' is present in the implementation but not in the contract. InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalonia.Platform.IGeometryImpl.TryGetPointAtDistance(System.Double, Avalonia.Point)' is present in the implementation but not in the contract. -Total Issues: 4 +Total Issues: 7 diff --git a/src/Avalonia.Visuals/Media/Imaging/BitmapBlendingMode.cs b/src/Avalonia.Visuals/Media/Imaging/BitmapBlendingMode.cs new file mode 100644 index 0000000000..473b43dab3 --- /dev/null +++ b/src/Avalonia.Visuals/Media/Imaging/BitmapBlendingMode.cs @@ -0,0 +1,57 @@ +namespace Avalonia.Visuals.Media.Imaging +{ + /// + /// Controls the way the bitmaps are drawn together. + /// + public enum BitmapBlendingMode + { + /// + /// Source is placed over the destination. + /// + SourceOver, + /// + /// Only the source will be present. + /// + Source, + /// + /// Only the destination will be present. + /// + Destination, + /// + /// Destination is placed over the source. + /// + DestinationOver, + /// + /// The source that overlaps the destination, replaces the destination. + /// + SourceIn, + /// + /// Destination which overlaps the source, replaces the source. + /// + DestinationIn, + /// + /// Source is placed, where it falls outside of the destination. + /// + SourceOut, + /// + /// Destination is placed, where it falls outside of the source. + /// + DestinationOut, + /// + /// Source which overlaps the destination, replaces the destination. + /// + SourceAtop, + /// + /// Destination which overlaps the source replaces the source. + /// + DestinationAtop, + /// + /// The non-overlapping regions of source and destination are combined. + /// + Xor, + /// + /// Display the sum of the source image and destination image. + /// + Plus, + } +} diff --git a/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs b/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs index d6e88a7507..e9a1a2a6ae 100644 --- a/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs +++ b/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs @@ -30,7 +30,8 @@ namespace Avalonia.Platform /// The rect in the image to draw. /// The rect in the output to draw to. /// The bitmap interpolation mode. - void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode = BitmapInterpolationMode.Default); + /// The bitmap blending mode. + void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode = BitmapInterpolationMode.Default, BitmapBlendingMode bitmapBlendMode = BitmapBlendingMode.SourceOver); /// /// Draws a bitmap image. diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs index 28f426266d..1705bc6b1c 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs +++ b/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs @@ -112,13 +112,13 @@ namespace Avalonia.Rendering.SceneGraph } /// - public void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode) + public void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode, BitmapBlendingMode bitmapBlendingMode) { var next = NextDrawAs(); - if (next == null || !next.Item.Equals(Transform, source, opacity, sourceRect, destRect, bitmapInterpolationMode)) + if (next == null || !next.Item.Equals(Transform, source, opacity, sourceRect, destRect, bitmapInterpolationMode, bitmapBlendingMode)) { - Add(new ImageNode(Transform, source, opacity, sourceRect, destRect, bitmapInterpolationMode)); + Add(new ImageNode(Transform, source, opacity, sourceRect, destRect, bitmapInterpolationMode, bitmapBlendingMode)); } else { diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/ImageNode.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/ImageNode.cs index c9052c6ef2..c50601120f 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/ImageNode.cs +++ b/src/Avalonia.Visuals/Rendering/SceneGraph/ImageNode.cs @@ -18,7 +18,7 @@ namespace Avalonia.Rendering.SceneGraph /// The source rect. /// The destination rect. /// The bitmap interpolation mode. - public ImageNode(Matrix transform, IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode) + public ImageNode(Matrix transform, IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode, BitmapBlendingMode bitmapBlendingMode) : base(destRect, transform) { Transform = transform; @@ -27,6 +27,7 @@ namespace Avalonia.Rendering.SceneGraph SourceRect = sourceRect; DestRect = destRect; BitmapInterpolationMode = bitmapInterpolationMode; + BitmapBlendingMode = bitmapBlendingMode; SourceVersion = Source.Item.Version; } @@ -67,6 +68,14 @@ namespace Avalonia.Rendering.SceneGraph /// The scaling mode. /// public BitmapInterpolationMode BitmapInterpolationMode { get; } + + /// + /// The bitmap blending mode. + /// + /// + /// The blending mode. + /// + public BitmapBlendingMode BitmapBlendingMode { get; } /// /// Determines if this draw operation equals another. @@ -82,22 +91,23 @@ namespace Avalonia.Rendering.SceneGraph /// The properties of the other draw operation are passed in as arguments to prevent /// allocation of a not-yet-constructed draw operation object. /// - public bool Equals(Matrix transform, IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode) + public bool Equals(Matrix transform, IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode, BitmapBlendingMode bitmapBlendingMode) { return transform == Transform && - Equals(source.Item, Source.Item) && - source.Item.Version == SourceVersion && - opacity == Opacity && - sourceRect == SourceRect && - destRect == DestRect && - bitmapInterpolationMode == BitmapInterpolationMode; + Equals(source.Item, Source.Item) && + source.Item.Version == SourceVersion && + opacity == Opacity && + sourceRect == SourceRect && + destRect == DestRect && + bitmapInterpolationMode == BitmapInterpolationMode && + bitmapBlendingMode == BitmapBlendingMode; } /// public override void Render(IDrawingContextImpl context) { context.Transform = Transform; - context.DrawBitmap(Source, Opacity, SourceRect, DestRect, BitmapInterpolationMode); + context.DrawBitmap(Source, Opacity, SourceRect, DestRect, BitmapInterpolationMode, BitmapBlendingMode); } /// diff --git a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs index 2a79a4bb50..692d40a653 100644 --- a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs +++ b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs @@ -132,7 +132,7 @@ namespace Avalonia.Skia } /// - public void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode) + public void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode, BitmapBlendingMode bitmapBlendingMode) { var drawableImage = (IDrawableBitmapImpl)source.Item; var s = sourceRect.ToSKRect(); @@ -145,6 +145,7 @@ namespace Avalonia.Skia }) { paint.FilterQuality = bitmapInterpolationMode.ToSKFilterQuality(); + paint.BlendMode = bitmapBlendingMode.ToSKBlendMode(); drawableImage.Draw(this, s, d, paint); } @@ -154,7 +155,7 @@ namespace Avalonia.Skia public void DrawBitmap(IRef source, IBrush opacityMask, Rect opacityMaskRect, Rect destRect) { PushOpacityMask(opacityMask, opacityMaskRect); - DrawBitmap(source, 1, new Rect(0, 0, source.Item.PixelSize.Width, source.Item.PixelSize.Height), destRect, BitmapInterpolationMode.Default); + DrawBitmap(source, 1, new Rect(0, 0, source.Item.PixelSize.Width, source.Item.PixelSize.Height), destRect, BitmapInterpolationMode.Default, BitmapBlendingMode.SourceOver); PopOpacityMask(); } diff --git a/src/Skia/Avalonia.Skia/SkiaSharpExtensions.cs b/src/Skia/Avalonia.Skia/SkiaSharpExtensions.cs index bb3dbbfadc..75b4231640 100644 --- a/src/Skia/Avalonia.Skia/SkiaSharpExtensions.cs +++ b/src/Skia/Avalonia.Skia/SkiaSharpExtensions.cs @@ -25,6 +25,39 @@ namespace Avalonia.Skia } } + public static SKBlendMode ToSKBlendMode(this BitmapBlendingMode blendingMode) + { + switch (blendingMode) + { + case BitmapBlendingMode.SourceOver: + return SKBlendMode.SrcOver; + case BitmapBlendingMode.Source: + return SKBlendMode.Src; + case BitmapBlendingMode.SourceIn: + return SKBlendMode.SrcIn; + case BitmapBlendingMode.SourceOut: + return SKBlendMode.SrcOut; + case BitmapBlendingMode.SourceAtop: + return SKBlendMode.SrcATop; + case BitmapBlendingMode.Destination: + return SKBlendMode.Dst; + case BitmapBlendingMode.DestinationIn: + return SKBlendMode.DstIn; + case BitmapBlendingMode.DestinationOut: + return SKBlendMode.DstOut; + case BitmapBlendingMode.DestinationOver: + return SKBlendMode.DstOver; + case BitmapBlendingMode.DestinationAtop: + return SKBlendMode.DstATop; + case BitmapBlendingMode.Xor: + return SKBlendMode.Xor; + case BitmapBlendingMode.Plus: + return SKBlendMode.Plus; + default: + throw new ArgumentOutOfRangeException(nameof(blendingMode), blendingMode, null); + } + } + public static SKPoint ToSKPoint(this Point p) { return new SKPoint((float)p.X, (float)p.Y); diff --git a/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs b/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs index 47a19aad8c..0f5a932ef3 100644 --- a/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs +++ b/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs @@ -5,6 +5,7 @@ using Avalonia.Platform; using Avalonia.Rendering; using Avalonia.Rendering.SceneGraph; using Avalonia.Utilities; +using Avalonia.Visuals.Media.Imaging; using SharpDX; using SharpDX.Direct2D1; using SharpDX.Mathematics.Interop; @@ -116,12 +117,14 @@ namespace Avalonia.Direct2D1.Media /// The rect in the image to draw. /// The rect in the output to draw to. /// The bitmap interpolation mode. - public void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode) + public void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode, BitmapBlendingMode bitmapBlendingMode) { using (var d2d = ((BitmapImpl)source.Item).GetDirect2DBitmap(_deviceContext)) { var interpolationMode = GetInterpolationMode(bitmapInterpolationMode); - + + // TODO: How to implement CompositeMode here? + _deviceContext.DrawBitmap( d2d.Value, destRect.ToSharpDX(), @@ -149,6 +152,35 @@ namespace Avalonia.Direct2D1.Media } } + public static CompositeMode GetCompositeMode(BitmapBlendingMode blendingMode) + { + switch (blendingMode) + { + case BitmapBlendingMode.SourceIn: + return CompositeMode.SourceIn; + case BitmapBlendingMode.SourceOut: + return CompositeMode.SourceOut; + case BitmapBlendingMode.SourceOver: + return CompositeMode.SourceOver; + case BitmapBlendingMode.SourceAtop: + return CompositeMode.SourceAtop; + case BitmapBlendingMode.DestinationIn: + return CompositeMode.DestinationIn; + case BitmapBlendingMode.DestinationOut: + return CompositeMode.DestinationOut; + case BitmapBlendingMode.DestinationOver: + return CompositeMode.DestinationOver; + case BitmapBlendingMode.DestinationAtop: + return CompositeMode.DestinationAtop; + case BitmapBlendingMode.Xor: + return CompositeMode.Xor; + case BitmapBlendingMode.Plus: + return CompositeMode.Plus; + default: + throw new ArgumentOutOfRangeException(nameof(blendingMode), blendingMode, null); + } + } + /// /// Draws a bitmap image. /// From 4bffeaf3276a86c11d7b84e9a886713d6099620e Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Thu, 18 Mar 2021 21:24:38 +0800 Subject: [PATCH 16/72] use pop/push model for blendingmode instead. --- .../Platform/IDrawingContextImpl.cs | 13 +++++++++++- src/Skia/Avalonia.Skia/DrawingContextImpl.cs | 21 ++++++++++++++++--- .../Media/DrawingContextImpl.cs | 12 ++++++++++- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs b/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs index e9a1a2a6ae..e2fefffecc 100644 --- a/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs +++ b/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs @@ -31,7 +31,7 @@ namespace Avalonia.Platform /// The rect in the output to draw to. /// The bitmap interpolation mode. /// The bitmap blending mode. - void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode = BitmapInterpolationMode.Default, BitmapBlendingMode bitmapBlendMode = BitmapBlendingMode.SourceOver); + void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode = BitmapInterpolationMode.Default); /// /// Draws a bitmap image. @@ -149,6 +149,17 @@ namespace Avalonia.Platform /// Pops the latest pushed geometry clip. /// void PopGeometryClip(); + + /// + /// Pushes an bitmap blending value. + /// + /// The opacity. + void PushBitmapBlendMode(BitmapBlendingMode blendingMode); + + /// + /// Pops the latest pushed bitmap blending value. + /// + void PopBitmapBlendMode(); /// /// Adds a custom draw operation diff --git a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs index 692d40a653..b7d5d3ec59 100644 --- a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs +++ b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs @@ -23,9 +23,11 @@ namespace Avalonia.Skia private readonly Vector _dpi; private readonly Stack _maskStack = new Stack(); private readonly Stack _opacityStack = new Stack(); + private readonly Stack _blendingModeStack = new Stack(); private readonly Matrix? _postTransform; private readonly IVisualBrushRenderer _visualBrushRenderer; private double _currentOpacity = 1.0f; + private BitmapBlendingMode _currentBlendingMode = BitmapBlendingMode.SourceOver; private readonly bool _canTextUseLcdRendering; private Matrix _currentTransform; private bool _disposed; @@ -132,7 +134,7 @@ namespace Avalonia.Skia } /// - public void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode, BitmapBlendingMode bitmapBlendingMode) + public void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode) { var drawableImage = (IDrawableBitmapImpl)source.Item; var s = sourceRect.ToSKRect(); @@ -145,7 +147,7 @@ namespace Avalonia.Skia }) { paint.FilterQuality = bitmapInterpolationMode.ToSKFilterQuality(); - paint.BlendMode = bitmapBlendingMode.ToSKBlendMode(); + paint.BlendMode = _currentBlendingMode.ToSKBlendMode(); drawableImage.Draw(this, s, d, paint); } @@ -155,7 +157,7 @@ namespace Avalonia.Skia public void DrawBitmap(IRef source, IBrush opacityMask, Rect opacityMaskRect, Rect destRect) { PushOpacityMask(opacityMask, opacityMaskRect); - DrawBitmap(source, 1, new Rect(0, 0, source.Item.PixelSize.Width, source.Item.PixelSize.Height), destRect, BitmapInterpolationMode.Default, BitmapBlendingMode.SourceOver); + DrawBitmap(source, 1, new Rect(0, 0, source.Item.PixelSize.Width, source.Item.PixelSize.Height), destRect, BitmapInterpolationMode.Default); PopOpacityMask(); } @@ -509,6 +511,19 @@ namespace Avalonia.Skia Canvas.Restore(); } + /// + public void PushBitmapBlendMode(BitmapBlendingMode blendingMode) + { + _blendingModeStack.Push(_currentBlendingMode); + _currentBlendingMode = blendingMode; + } + + /// + public void PopBitmapBlendMode() + { + _currentBlendingMode = _blendingModeStack.Pop(); + } + public void Custom(ICustomDrawOperation custom) => custom.Render(this); /// diff --git a/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs b/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs index 0f5a932ef3..efe581ae0d 100644 --- a/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs +++ b/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs @@ -117,7 +117,7 @@ namespace Avalonia.Direct2D1.Media /// The rect in the image to draw. /// The rect in the output to draw to. /// The bitmap interpolation mode. - public void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode, BitmapBlendingMode bitmapBlendingMode) + public void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode) { using (var d2d = ((BitmapImpl)source.Item).GetDirect2DBitmap(_deviceContext)) { @@ -557,6 +557,16 @@ namespace Avalonia.Direct2D1.Media PopLayer(); } + public void PushBitmapBlendMode(BitmapBlendingMode blendingMode) + { + // Stubs for now + } + + public void PopBitmapBlendMode() + { + // Stubs for now + } + public void PushOpacityMask(IBrush mask, Rect bounds) { var parameters = new LayerParameters From c6491400fbbd4c5e5e96ad23b38d1365674573f7 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Thu, 18 Mar 2021 21:31:59 +0800 Subject: [PATCH 17/72] use path cache helpers and eliminate spurious instantiations of SKPathMeasure --- src/Skia/Avalonia.Skia/GeometryImpl.cs | 30 +++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Skia/Avalonia.Skia/GeometryImpl.cs b/src/Skia/Avalonia.Skia/GeometryImpl.cs index e8b5795f60..8b4ba66cf6 100644 --- a/src/Skia/Avalonia.Skia/GeometryImpl.cs +++ b/src/Skia/Avalonia.Skia/GeometryImpl.cs @@ -11,19 +11,12 @@ namespace Avalonia.Skia internal abstract class GeometryImpl : IGeometryImpl { private PathCache _pathCache; - + /// public abstract Rect Bounds { get; } /// - public double ContourLength - { - get - { - if (EffectivePath is null) return 0; - return new SKPathMeasure(EffectivePath).Length; - } - } + public double ContourLength => _pathCache.CachePathMeasure?.Length ?? 0; public abstract SKPath EffectivePath { get; } @@ -118,13 +111,13 @@ namespace Avalonia.Skia /// public bool TryGetPointAtDistance(double distance, out Point point) { - if (EffectivePath is null) + if (_pathCache.CachePathMeasure is null) { point = new Point(); return false; } - var res = new SKPathMeasure(EffectivePath).GetPosition((float)distance, out var skPoint); + var res = _pathCache.CachePathMeasure.GetPosition((float)distance, out var skPoint); point = new Point(skPoint.X, skPoint.Y); return res; } @@ -132,14 +125,14 @@ namespace Avalonia.Skia /// public bool TryGetPointAndTangentAtDistance(double distance, out Point point, out Point tangent) { - if (EffectivePath is null) + if (_pathCache.CachePathMeasure is null) { point = new Point(); tangent = new Point(); return false; } - var res = new SKPathMeasure(EffectivePath).GetPositionAndTangent((float)distance, out var skPoint, out var skTangent); + var res = _pathCache.CachePathMeasure.GetPositionAndTangent((float)distance, out var skPoint, out var skTangent); point = new Point(skPoint.X, skPoint.Y); tangent = new Point(skTangent.X, skTangent.Y); return res; @@ -156,7 +149,7 @@ namespace Avalonia.Skia private struct PathCache { private float _cachedStrokeWidth; - + /// /// Tolerance for two stroke widths to be deemed equal /// @@ -171,6 +164,11 @@ namespace Avalonia.Skia /// Cached geometry render bounds. /// public Rect CachedGeometryRenderBounds { get; private set; } + + /// + /// Cached path measurement helper. + /// + public SKPathMeasure CachePathMeasure { get; private set; } /// /// Is cached valid for given stroke width. @@ -196,7 +194,8 @@ namespace Avalonia.Skia } CachedStrokePath = path; - CachedGeometryRenderBounds = geometryRenderBounds; + CachedGeometryRenderBounds = geometryRenderBounds; + CachePathMeasure = new SKPathMeasure(path); _cachedStrokeWidth = strokeWidth; } @@ -206,6 +205,7 @@ namespace Avalonia.Skia public void Invalidate() { CachedStrokePath?.Dispose(); + CachePathMeasure?.Dispose(); CachedGeometryRenderBounds = Rect.Empty; _cachedStrokeWidth = default(float); } From cd35e2c35ea04b6f4b44d419c64e024eba4ddcbb Mon Sep 17 00:00:00 2001 From: Jumar Macato <16554748+jmacato@users.noreply.github.com> Date: Thu, 18 Mar 2021 21:34:50 +0800 Subject: [PATCH 18/72] Update src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs --- src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs b/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs index a00dc1f618..ce5a8a2e86 100644 --- a/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs +++ b/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs @@ -393,7 +393,7 @@ namespace Avalonia.Headless { } - public void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode = BitmapInterpolationMode.Default, BitmapBlendingMode bitmapBlendingMode = BitmapBlendingMode.SourceOver) + public void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode = BitmapInterpolationMode.Default) { } From f9a432ec9dbc43288ddbc69dcff4076fef26eec7 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Thu, 18 Mar 2021 21:40:39 +0800 Subject: [PATCH 19/72] fix HeadlessPlatformRenderInterface.cs --- .../HeadlessPlatformRenderInterface.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs b/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs index ce5a8a2e86..48c46f50a1 100644 --- a/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs +++ b/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs @@ -375,6 +375,16 @@ namespace Avalonia.Headless } + public void PushBitmapBlendMode(BitmapBlendingMode blendingMode) + { + + } + + public void PopBitmapBlendMode() + { + + } + public void Custom(ICustomDrawOperation custom) { From de3795514d0e1a345f1a65d82bb8b6d3a7841d10 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Thu, 18 Mar 2021 22:17:50 +0800 Subject: [PATCH 20/72] add DeferredDrawingContextImpl implementations for blendmode --- .../SceneGraph/BitmapBlendModeNode.cs | 68 +++++++++++++++++++ .../SceneGraph/DeferredDrawingContextImpl.cs | 37 +++++++++- .../Rendering/SceneGraph/ImageNode.cs | 10 ++- 3 files changed, 106 insertions(+), 9 deletions(-) create mode 100644 src/Avalonia.Visuals/Rendering/SceneGraph/BitmapBlendModeNode.cs diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/BitmapBlendModeNode.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/BitmapBlendModeNode.cs new file mode 100644 index 0000000000..b486b5060a --- /dev/null +++ b/src/Avalonia.Visuals/Rendering/SceneGraph/BitmapBlendModeNode.cs @@ -0,0 +1,68 @@ +using Avalonia.Platform; +using Avalonia.Visuals.Media.Imaging; + +namespace Avalonia.Rendering.SceneGraph +{ + /// + /// A node in the scene graph which represents an opacity push or pop. + /// + internal class BitmapBlendModeNode : IDrawOperation + { + /// + /// Initializes a new instance of the class that represents an + /// push. + /// + /// The to push. + public BitmapBlendModeNode(BitmapBlendingMode bitmapBlend) + { + BlendingMode = bitmapBlend; + } + + /// + /// Initializes a new instance of the class that represents an + /// pop. + /// + public BitmapBlendModeNode() + { + } + + /// + public Rect Bounds => Rect.Empty; + + /// + /// Gets the BitmapBlend to be pushed or null if the operation represents a pop. + /// + public BitmapBlendingMode? BlendingMode { get; } + + /// + public bool HitTest(Point p) => false; + + /// + /// Determines if this draw operation equals another. + /// + /// The opacity of the other draw operation. + /// True if the draw operations are the same, otherwise false. + /// + /// The properties of the other draw operation are passed in as arguments to prevent + /// allocation of a not-yet-constructed draw operation object. + /// + public bool Equals(BitmapBlendingMode? blendingMode) => BlendingMode == blendingMode; + + /// + public void Render(IDrawingContextImpl context) + { + if (BlendingMode.HasValue) + { + context.PushBitmapBlendMode(BlendingMode.Value); + } + else + { + context.PopBitmapBlendMode(); + } + } + + public void Dispose() + { + } + } +} diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs index 1705bc6b1c..d4564c9f29 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs +++ b/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs @@ -112,13 +112,13 @@ namespace Avalonia.Rendering.SceneGraph } /// - public void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode, BitmapBlendingMode bitmapBlendingMode) + public void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode) { var next = NextDrawAs(); - if (next == null || !next.Item.Equals(Transform, source, opacity, sourceRect, destRect, bitmapInterpolationMode, bitmapBlendingMode)) + if (next == null || !next.Item.Equals(Transform, source, opacity, sourceRect, destRect, bitmapInterpolationMode)) { - Add(new ImageNode(Transform, source, opacity, sourceRect, destRect, bitmapInterpolationMode, bitmapBlendingMode)); + Add(new ImageNode(Transform, source, opacity, sourceRect, destRect, bitmapInterpolationMode)); } else { @@ -179,6 +179,7 @@ namespace Avalonia.Rendering.SceneGraph } } + public void Custom(ICustomDrawOperation custom) { var next = NextDrawAs(); @@ -253,6 +254,21 @@ namespace Avalonia.Rendering.SceneGraph } } + /// + public void PopBitmapBlendMode() + { + var next = NextDrawAs(); + + if (next == null || !next.Item.Equals(null)) + { + Add(new BitmapBlendModeNode()); + } + else + { + ++_drawOperationindex; + } + } + /// public void PopOpacity() { @@ -358,6 +374,21 @@ namespace Avalonia.Rendering.SceneGraph } } + /// + public void PushBitmapBlendMode(BitmapBlendingMode blendingMode) + { + var next = NextDrawAs(); + + if (next == null || !next.Item.Equals(blendingMode)) + { + Add(new BitmapBlendModeNode(blendingMode)); + } + else + { + ++_drawOperationindex; + } + } + public readonly struct UpdateState : IDisposable { public UpdateState( diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/ImageNode.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/ImageNode.cs index c50601120f..d3da19d8c9 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/ImageNode.cs +++ b/src/Avalonia.Visuals/Rendering/SceneGraph/ImageNode.cs @@ -18,7 +18,7 @@ namespace Avalonia.Rendering.SceneGraph /// The source rect. /// The destination rect. /// The bitmap interpolation mode. - public ImageNode(Matrix transform, IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode, BitmapBlendingMode bitmapBlendingMode) + public ImageNode(Matrix transform, IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode) : base(destRect, transform) { Transform = transform; @@ -27,7 +27,6 @@ namespace Avalonia.Rendering.SceneGraph SourceRect = sourceRect; DestRect = destRect; BitmapInterpolationMode = bitmapInterpolationMode; - BitmapBlendingMode = bitmapBlendingMode; SourceVersion = Source.Item.Version; } @@ -91,7 +90,7 @@ namespace Avalonia.Rendering.SceneGraph /// The properties of the other draw operation are passed in as arguments to prevent /// allocation of a not-yet-constructed draw operation object. /// - public bool Equals(Matrix transform, IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode, BitmapBlendingMode bitmapBlendingMode) + public bool Equals(Matrix transform, IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode) { return transform == Transform && Equals(source.Item, Source.Item) && @@ -99,15 +98,14 @@ namespace Avalonia.Rendering.SceneGraph opacity == Opacity && sourceRect == SourceRect && destRect == DestRect && - bitmapInterpolationMode == BitmapInterpolationMode && - bitmapBlendingMode == BitmapBlendingMode; + bitmapInterpolationMode == BitmapInterpolationMode; } /// public override void Render(IDrawingContextImpl context) { context.Transform = Transform; - context.DrawBitmap(Source, Opacity, SourceRect, DestRect, BitmapInterpolationMode, BitmapBlendingMode); + context.DrawBitmap(Source, Opacity, SourceRect, DestRect, BitmapInterpolationMode); } /// From db70c9f94c4027e5919992f1666bbdb8e254f5a2 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Thu, 18 Mar 2021 22:26:45 +0800 Subject: [PATCH 21/72] apicompat stuff --- src/Avalonia.Visuals/ApiCompatBaseline.txt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Visuals/ApiCompatBaseline.txt b/src/Avalonia.Visuals/ApiCompatBaseline.txt index e781cb1d3e..0be3bedbd5 100644 --- a/src/Avalonia.Visuals/ApiCompatBaseline.txt +++ b/src/Avalonia.Visuals/ApiCompatBaseline.txt @@ -1,9 +1,8 @@ Compat issues with assembly Avalonia.Visuals: -InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Platform.IDrawingContextImpl.DrawBitmap(Avalonia.Utilities.IRef, System.Double, Avalonia.Rect, Avalonia.Rect, Avalonia.Visuals.Media.Imaging.BitmapInterpolationMode)' is present in the contract but not in the implementation. -MembersMustExist : Member 'public void Avalonia.Platform.IDrawingContextImpl.DrawBitmap(Avalonia.Utilities.IRef, System.Double, Avalonia.Rect, Avalonia.Rect, Avalonia.Visuals.Media.Imaging.BitmapInterpolationMode)' does not exist in the implementation but it does exist in the contract. -InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Platform.IDrawingContextImpl.DrawBitmap(Avalonia.Utilities.IRef, System.Double, Avalonia.Rect, Avalonia.Rect, Avalonia.Visuals.Media.Imaging.BitmapInterpolationMode, Avalonia.Visuals.Media.Imaging.BitmapBlendingMode)' is present in the implementation but not in the contract. +InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Platform.IDrawingContextImpl.PopBitmapBlendMode()' is present in the implementation but not in the contract. +InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Platform.IDrawingContextImpl.PushBitmapBlendMode(Avalonia.Visuals.Media.Imaging.BitmapBlendingMode)' is present in the implementation but not in the contract. InterfacesShouldHaveSameMembers : Interface member 'public System.Double Avalonia.Platform.IGeometryImpl.ContourLength' is present in the implementation but not in the contract. InterfacesShouldHaveSameMembers : Interface member 'public System.Double Avalonia.Platform.IGeometryImpl.ContourLength.get()' is present in the implementation but not in the contract. InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalonia.Platform.IGeometryImpl.TryGetPointAndTangentAtDistance(System.Double, Avalonia.Point, Avalonia.Point)' is present in the implementation but not in the contract. InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalonia.Platform.IGeometryImpl.TryGetPointAtDistance(System.Double, Avalonia.Point)' is present in the implementation but not in the contract. -Total Issues: 7 +Total Issues: 6 From f8596a60ea8965bb6c08e516c03b2c4f996a4c03 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Thu, 18 Mar 2021 22:49:01 +0800 Subject: [PATCH 22/72] add unimplemented stuff on MockRenderInterface.cs --- .../VisualTree/MockRenderInterface.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs b/tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs index 02236e4107..bb6301365a 100644 --- a/tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs +++ b/tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs @@ -112,6 +112,8 @@ namespace Avalonia.Visuals.UnitTests.VisualTree } } + public double ContourLength { get; } + public IStreamGeometryImpl Clone() { return this; @@ -151,6 +153,16 @@ namespace Avalonia.Visuals.UnitTests.VisualTree throw new NotImplementedException(); } + public bool TryGetPointAtDistance(double distance, out Point point) + { + throw new NotImplementedException(); + } + + public bool TryGetPointAndTangentAtDistance(double distance, out Point point, out Point tangent) + { + throw new NotImplementedException(); + } + class MockStreamGeometryContext : IStreamGeometryContextImpl { private List points = new List(); From 4ef47bfdb05d04e5f4be199da7c3e47893dfe5fa Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Fri, 19 Mar 2021 12:14:03 +0800 Subject: [PATCH 23/72] Add TryGetSegment --- .../HeadlessPlatformRenderInterface.cs | 6 +++++ .../Platform/IGeometryImpl.cs | 13 +++++++++++ src/Skia/Avalonia.Skia/GeometryImpl.cs | 22 +++++++++++++++++++ .../Avalonia.Direct2D1/Media/GeometryImpl.cs | 9 ++++++++ .../MockStreamGeometryImpl.cs | 6 +++++ .../VisualTree/MockRenderInterface.cs | 5 +++++ 6 files changed, 61 insertions(+) diff --git a/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs b/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs index 48c46f50a1..1563c66a96 100644 --- a/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs +++ b/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs @@ -142,6 +142,12 @@ namespace Avalonia.Headless tangent = new Point(); return false; } + + public bool TryGetSegment(float startDistance, float stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry) + { + segmentGeometry = null; + return false; + } } class HeadlessTransformedGeometryStub : HeadlessGeometryStub, ITransformedGeometryImpl diff --git a/src/Avalonia.Visuals/Platform/IGeometryImpl.cs b/src/Avalonia.Visuals/Platform/IGeometryImpl.cs index c61e6c6112..33092ca2b4 100644 --- a/src/Avalonia.Visuals/Platform/IGeometryImpl.cs +++ b/src/Avalonia.Visuals/Platform/IGeometryImpl.cs @@ -73,5 +73,18 @@ namespace Avalonia.Platform /// The tangent in the specified distance. /// If there's valid point and tangent at the specified distance. bool TryGetPointAndTangentAtDistance(double distance, out Point point, out Point tangent); + + /// + /// Attempts to get the corresponding path segment + /// given by the two distances specified. + /// Imagine it like snipping a part of the current + /// geometry. + /// + /// The contour distance to start snipping from. + /// The contour distance to stop snipping to. + /// If ture, the resulting snipped path will start with a BeginFigure call. + /// The resulting snipped path. + /// If the snipping operation is successful. + bool TryGetSegment (float startDistance, float stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry); } } diff --git a/src/Skia/Avalonia.Skia/GeometryImpl.cs b/src/Skia/Avalonia.Skia/GeometryImpl.cs index 8b4ba66cf6..0884399f4e 100644 --- a/src/Skia/Avalonia.Skia/GeometryImpl.cs +++ b/src/Skia/Avalonia.Skia/GeometryImpl.cs @@ -138,6 +138,28 @@ namespace Avalonia.Skia return res; } + public bool TryGetSegment(float startDistance, float stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry) + { + if (_pathCache.CachePathMeasure is null) + { + segmentGeometry = null; + return false; + } + + segmentGeometry = null; + + SKPath _skPathSegment = null; + + var res = _pathCache.CachePathMeasure.GetSegment(startDistance, stopDistance, _skPathSegment, startOnBeginFigure); + + if (res) + { + segmentGeometry = new StreamGeometryImpl(_skPathSegment); + } + + return res; + } + /// /// Invalidate all caches. Call after chaining path contents. /// diff --git a/src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs b/src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs index 81c21c8648..e03c049ec2 100644 --- a/src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs +++ b/src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs @@ -82,6 +82,15 @@ namespace Avalonia.Direct2D1.Media return false; } + public bool TryGetSegment(float startDistance, float stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry) + { + // Direct2D doesnt have this too sadly. + Logger.TryGet(LogEventLevel.Warning, LogArea.Visual)?.Log(this, "TryGetSegment is not available in Direct2D."); + + segmentGeometry = null; + return false; + } + protected virtual Geometry GetSourceGeometry() => Geometry; } } diff --git a/tests/Avalonia.UnitTests/MockStreamGeometryImpl.cs b/tests/Avalonia.UnitTests/MockStreamGeometryImpl.cs index 4e66eaeb24..dfe2021cc2 100644 --- a/tests/Avalonia.UnitTests/MockStreamGeometryImpl.cs +++ b/tests/Avalonia.UnitTests/MockStreamGeometryImpl.cs @@ -84,6 +84,12 @@ namespace Avalonia.UnitTests return false; } + public bool TryGetSegment(float startDistance, float stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry) + { + segmentGeometry = null; + return false; + } + class MockStreamGeometryContext : IStreamGeometryContextImpl { private List points = new List(); diff --git a/tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs b/tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs index bb6301365a..666ac75c4b 100644 --- a/tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs +++ b/tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs @@ -163,6 +163,11 @@ namespace Avalonia.Visuals.UnitTests.VisualTree throw new NotImplementedException(); } + public bool TryGetSegment(float startDistance, float stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry) + { + throw new NotImplementedException(); + } + class MockStreamGeometryContext : IStreamGeometryContextImpl { private List points = new List(); From edf18a44370cd93c6fded0778ae06ba0e7883608 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Fri, 19 Mar 2021 12:22:37 +0800 Subject: [PATCH 24/72] api compat --- src/Avalonia.Visuals/ApiCompatBaseline.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Visuals/ApiCompatBaseline.txt b/src/Avalonia.Visuals/ApiCompatBaseline.txt index 0be3bedbd5..6c7b3efaf8 100644 --- a/src/Avalonia.Visuals/ApiCompatBaseline.txt +++ b/src/Avalonia.Visuals/ApiCompatBaseline.txt @@ -5,4 +5,5 @@ InterfacesShouldHaveSameMembers : Interface member 'public System.Double Avaloni InterfacesShouldHaveSameMembers : Interface member 'public System.Double Avalonia.Platform.IGeometryImpl.ContourLength.get()' is present in the implementation but not in the contract. InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalonia.Platform.IGeometryImpl.TryGetPointAndTangentAtDistance(System.Double, Avalonia.Point, Avalonia.Point)' is present in the implementation but not in the contract. InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalonia.Platform.IGeometryImpl.TryGetPointAtDistance(System.Double, Avalonia.Point)' is present in the implementation but not in the contract. -Total Issues: 6 +InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalonia.Platform.IGeometryImpl.TryGetSegment(System.Single, System.Single, System.Boolean, Avalonia.Platform.IGeometryImpl)' is present in the implementation but not in the contract. +Total Issues: 7 From 58e71b6fa9c73eaf04441e01ee7aa58420c39c69 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Fri, 19 Mar 2021 14:46:07 +0800 Subject: [PATCH 25/72] fix init --- src/Skia/Avalonia.Skia/GeometryImpl.cs | 88 ++++++++++++++++---------- 1 file changed, 56 insertions(+), 32 deletions(-) diff --git a/src/Skia/Avalonia.Skia/GeometryImpl.cs b/src/Skia/Avalonia.Skia/GeometryImpl.cs index 0884399f4e..5042e6ebd2 100644 --- a/src/Skia/Avalonia.Skia/GeometryImpl.cs +++ b/src/Skia/Avalonia.Skia/GeometryImpl.cs @@ -11,12 +11,27 @@ namespace Avalonia.Skia internal abstract class GeometryImpl : IGeometryImpl { private PathCache _pathCache; - + private SKPathMeasure _pathMeasureCache; + /// public abstract Rect Bounds { get; } - + /// - public double ContourLength => _pathCache.CachePathMeasure?.Length ?? 0; + public double ContourLength + { + get + { + if (EffectivePath is null) + return 0; + + if (_pathMeasureCache is null) + { + _pathMeasureCache = new SKPathMeasure(EffectivePath); + } + + return (double)_pathMeasureCache?.Length; + } + } public abstract SKPath EffectivePath { get; } @@ -34,12 +49,12 @@ namespace Avalonia.Skia // Usually this function is being called with same stroke width per path, so this saves a lot of Skia traffic. var strokeWidth = (float)(pen?.Thickness ?? 0); - + if (!_pathCache.HasCacheFor(strokeWidth)) { UpdatePathCache(strokeWidth); } - + return PathContainsCore(_pathCache.CachedStrokePath, point); } @@ -62,7 +77,7 @@ namespace Avalonia.Skia { paint.IsStroke = true; paint.StrokeWidth = strokeWidth; - + paint.GetFillPath(EffectivePath, strokePath); _pathCache.Cache(strokePath, strokeWidth, strokePath.TightBounds.ToAvaloniaRect()); @@ -78,13 +93,13 @@ namespace Avalonia.Skia /// True, if point is contained in a path. private static bool PathContainsCore(SKPath path, Point point) { - return path.Contains((float)point.X, (float)point.Y); + return path.Contains((float)point.X, (float)point.Y); } /// public IGeometryImpl Intersect(IGeometryImpl geometry) { - var result = EffectivePath.Op(((GeometryImpl) geometry).EffectivePath, SKPathOp.Intersect); + var result = EffectivePath.Op(((GeometryImpl)geometry).EffectivePath, SKPathOp.Intersect); return result == null ? null : new StreamGeometryImpl(result); } @@ -93,70 +108,86 @@ namespace Avalonia.Skia public Rect GetRenderBounds(IPen pen) { var strokeWidth = (float)(pen?.Thickness ?? 0); - + if (!_pathCache.HasCacheFor(strokeWidth)) { UpdatePathCache(strokeWidth); } - + return _pathCache.CachedGeometryRenderBounds; } - + /// public ITransformedGeometryImpl WithTransform(Matrix transform) { return new TransformedGeometryImpl(this, transform); } - + /// public bool TryGetPointAtDistance(double distance, out Point point) { - if (_pathCache.CachePathMeasure is null) + if (EffectivePath is null) { point = new Point(); return false; } - - var res = _pathCache.CachePathMeasure.GetPosition((float)distance, out var skPoint); + + if (_pathMeasureCache is null) + { + _pathMeasureCache = new SKPathMeasure(EffectivePath); + } + + var res = _pathMeasureCache.GetPosition((float)distance, out var skPoint); point = new Point(skPoint.X, skPoint.Y); return res; } - + /// public bool TryGetPointAndTangentAtDistance(double distance, out Point point, out Point tangent) { - if (_pathCache.CachePathMeasure is null) + if (EffectivePath is null) { point = new Point(); tangent = new Point(); return false; } - - var res = _pathCache.CachePathMeasure.GetPositionAndTangent((float)distance, out var skPoint, out var skTangent); + + if (_pathMeasureCache is null) + { + _pathMeasureCache = new SKPathMeasure(EffectivePath); + } + + var res = _pathMeasureCache.GetPositionAndTangent((float)distance, out var skPoint, out var skTangent); point = new Point(skPoint.X, skPoint.Y); tangent = new Point(skTangent.X, skTangent.Y); return res; } - public bool TryGetSegment(float startDistance, float stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry) + public bool TryGetSegment(float startDistance, float stopDistance, bool startOnBeginFigure, + out IGeometryImpl segmentGeometry) { - if (_pathCache.CachePathMeasure is null) + if (EffectivePath is null) { segmentGeometry = null; return false; } + + if (_pathMeasureCache is null) + { + _pathMeasureCache = new SKPathMeasure(EffectivePath); + } segmentGeometry = null; SKPath _skPathSegment = null; - var res = _pathCache.CachePathMeasure.GetSegment(startDistance, stopDistance, _skPathSegment, startOnBeginFigure); + var res = _pathMeasureCache.GetSegment(startDistance, stopDistance, _skPathSegment, startOnBeginFigure); if (res) { segmentGeometry = new StreamGeometryImpl(_skPathSegment); } - + return res; } @@ -176,7 +207,7 @@ namespace Avalonia.Skia /// Tolerance for two stroke widths to be deemed equal /// public const float Tolerance = float.Epsilon; - + /// /// Cached contour path. /// @@ -186,11 +217,6 @@ namespace Avalonia.Skia /// Cached geometry render bounds. /// public Rect CachedGeometryRenderBounds { get; private set; } - - /// - /// Cached path measurement helper. - /// - public SKPathMeasure CachePathMeasure { get; private set; } /// /// Is cached valid for given stroke width. @@ -216,8 +242,7 @@ namespace Avalonia.Skia } CachedStrokePath = path; - CachedGeometryRenderBounds = geometryRenderBounds; - CachePathMeasure = new SKPathMeasure(path); + CachedGeometryRenderBounds = geometryRenderBounds; _cachedStrokeWidth = strokeWidth; } @@ -227,7 +252,6 @@ namespace Avalonia.Skia public void Invalidate() { CachedStrokePath?.Dispose(); - CachePathMeasure?.Dispose(); CachedGeometryRenderBounds = Rect.Empty; _cachedStrokeWidth = default(float); } From 74a74acf0ced08ea2380109e6fc1987900e8c1a1 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Fri, 19 Mar 2021 19:16:14 +0800 Subject: [PATCH 26/72] set from float to double --- src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs | 2 +- src/Avalonia.Visuals/Platform/IGeometryImpl.cs | 2 +- src/Skia/Avalonia.Skia/GeometryImpl.cs | 4 ++-- src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs | 2 +- tests/Avalonia.UnitTests/MockStreamGeometryImpl.cs | 2 +- .../VisualTree/MockRenderInterface.cs | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs b/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs index 1563c66a96..62cac378d7 100644 --- a/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs +++ b/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs @@ -143,7 +143,7 @@ namespace Avalonia.Headless return false; } - public bool TryGetSegment(float startDistance, float stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry) + public bool TryGetSegment(double startDistance, double stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry) { segmentGeometry = null; return false; diff --git a/src/Avalonia.Visuals/Platform/IGeometryImpl.cs b/src/Avalonia.Visuals/Platform/IGeometryImpl.cs index 33092ca2b4..9dfaab9575 100644 --- a/src/Avalonia.Visuals/Platform/IGeometryImpl.cs +++ b/src/Avalonia.Visuals/Platform/IGeometryImpl.cs @@ -85,6 +85,6 @@ namespace Avalonia.Platform /// If ture, the resulting snipped path will start with a BeginFigure call. /// The resulting snipped path. /// If the snipping operation is successful. - bool TryGetSegment (float startDistance, float stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry); + bool TryGetSegment (double startDistance, double stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry); } } diff --git a/src/Skia/Avalonia.Skia/GeometryImpl.cs b/src/Skia/Avalonia.Skia/GeometryImpl.cs index 5042e6ebd2..1511640c56 100644 --- a/src/Skia/Avalonia.Skia/GeometryImpl.cs +++ b/src/Skia/Avalonia.Skia/GeometryImpl.cs @@ -163,7 +163,7 @@ namespace Avalonia.Skia return res; } - public bool TryGetSegment(float startDistance, float stopDistance, bool startOnBeginFigure, + public bool TryGetSegment(double startDistance, double stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry) { if (EffectivePath is null) @@ -181,7 +181,7 @@ namespace Avalonia.Skia SKPath _skPathSegment = null; - var res = _pathMeasureCache.GetSegment(startDistance, stopDistance, _skPathSegment, startOnBeginFigure); + var res = _pathMeasureCache.GetSegment((float)startDistance, (float)stopDistance, _skPathSegment, startOnBeginFigure); if (res) { diff --git a/src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs b/src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs index e03c049ec2..ec88347a17 100644 --- a/src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs +++ b/src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs @@ -82,7 +82,7 @@ namespace Avalonia.Direct2D1.Media return false; } - public bool TryGetSegment(float startDistance, float stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry) + public bool TryGetSegment(double startDistance, double stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry) { // Direct2D doesnt have this too sadly. Logger.TryGet(LogEventLevel.Warning, LogArea.Visual)?.Log(this, "TryGetSegment is not available in Direct2D."); diff --git a/tests/Avalonia.UnitTests/MockStreamGeometryImpl.cs b/tests/Avalonia.UnitTests/MockStreamGeometryImpl.cs index dfe2021cc2..864e2efbaf 100644 --- a/tests/Avalonia.UnitTests/MockStreamGeometryImpl.cs +++ b/tests/Avalonia.UnitTests/MockStreamGeometryImpl.cs @@ -84,7 +84,7 @@ namespace Avalonia.UnitTests return false; } - public bool TryGetSegment(float startDistance, float stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry) + public bool TryGetSegment(double startDistance, double stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry) { segmentGeometry = null; return false; diff --git a/tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs b/tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs index 666ac75c4b..6d0683e699 100644 --- a/tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs +++ b/tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs @@ -163,7 +163,7 @@ namespace Avalonia.Visuals.UnitTests.VisualTree throw new NotImplementedException(); } - public bool TryGetSegment(float startDistance, float stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry) + public bool TryGetSegment(double startDistance, double stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry) { throw new NotImplementedException(); } From dd33693eb738bf1baa6acd58a07bca5ecec9a822 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Fri, 19 Mar 2021 19:32:30 +0800 Subject: [PATCH 27/72] fix getsegment --- src/Skia/Avalonia.Skia/GeometryImpl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Skia/Avalonia.Skia/GeometryImpl.cs b/src/Skia/Avalonia.Skia/GeometryImpl.cs index 1511640c56..e5794c1a64 100644 --- a/src/Skia/Avalonia.Skia/GeometryImpl.cs +++ b/src/Skia/Avalonia.Skia/GeometryImpl.cs @@ -179,7 +179,7 @@ namespace Avalonia.Skia segmentGeometry = null; - SKPath _skPathSegment = null; + var _skPathSegment = new SKPath(); var res = _pathMeasureCache.GetSegment((float)startDistance, (float)stopDistance, _skPathSegment, startOnBeginFigure); From 9291a8f74a79e2f651085bfdc241d8582954e971 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Fri, 19 Mar 2021 19:37:29 +0800 Subject: [PATCH 28/72] extend DrawingContext.cs to accept IGeometryImpl in DrawGeometry method --- src/Avalonia.Visuals/Media/DrawingContext.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Visuals/Media/DrawingContext.cs b/src/Avalonia.Visuals/Media/DrawingContext.cs index ae4c927ae2..4e3dc8699c 100644 --- a/src/Avalonia.Visuals/Media/DrawingContext.cs +++ b/src/Avalonia.Visuals/Media/DrawingContext.cs @@ -121,12 +121,23 @@ namespace Avalonia.Media /// The stroke pen. /// The geometry. public void DrawGeometry(IBrush brush, IPen pen, Geometry geometry) + { + DrawGeometry(brush, pen, geometry.PlatformImpl); + } + + /// + /// Draws a geometry. + /// + /// The fill brush. + /// The stroke pen. + /// The geometry. + public void DrawGeometry(IBrush brush, IPen pen, IGeometryImpl geometry) { Contract.Requires(geometry != null); if (brush != null || PenIsVisible(pen)) { - PlatformImpl.DrawGeometry(brush, pen, geometry.PlatformImpl); + PlatformImpl.DrawGeometry(brush, pen, geometry); } } From 9ebdef12a89d38f432acbb8898126786dac9fc77 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Fri, 19 Mar 2021 19:37:50 +0800 Subject: [PATCH 29/72] add path measure example --- .../RenderDemo/Pages/PathMeasurementPage.cs | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 samples/RenderDemo/Pages/PathMeasurementPage.cs diff --git a/samples/RenderDemo/Pages/PathMeasurementPage.cs b/samples/RenderDemo/Pages/PathMeasurementPage.cs new file mode 100644 index 0000000000..9f033e961f --- /dev/null +++ b/samples/RenderDemo/Pages/PathMeasurementPage.cs @@ -0,0 +1,119 @@ +using System.Diagnostics; +using System.Drawing.Drawing2D; +using Avalonia; +using Avalonia.Controls; +using Avalonia.LogicalTree; +using Avalonia.Media; +using Avalonia.Media.Imaging; +using Avalonia.Media.Immutable; +using Avalonia.Threading; +using Avalonia.Visuals.Media.Imaging; + +namespace RenderDemo.Pages +{ + public class PathMeasurementPage : Control + { + private RenderTargetBitmap _bitmap; + + protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e) + { + _bitmap = new RenderTargetBitmap(new PixelSize(500, 500), new Vector(96, 96)); + base.OnAttachedToLogicalTree(e); + } + + protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e) + { + _bitmap.Dispose(); + _bitmap = null; + base.OnDetachedFromLogicalTree(e); + } + + readonly Stopwatch _st = Stopwatch.StartNew(); + + + readonly IPen strokePen = new ImmutablePen(Brushes.DarkBlue, 10d, null, PenLineCap.Round, PenLineJoin.Round); + readonly IPen strokePen1 = new ImmutablePen(Brushes.Purple, 10d, null, PenLineCap.Round, PenLineJoin.Round); + readonly IPen strokePen2 = new ImmutablePen(Brushes.Green, 10d, null, PenLineCap.Round, PenLineJoin.Round); + readonly IPen strokePen3 = new ImmutablePen(Brushes.LightBlue, 10d, null, PenLineCap.Round, PenLineJoin.Round); + + public override void Render(DrawingContext context) + { + using (var ctxi = _bitmap.CreateDrawingContext(null)) + using (var ctx = new DrawingContext(ctxi, false)) + { + ctxi.Clear(default); + + var x = new PathGeometry(); + + using (var xsad = x.Open()) + { + xsad.BeginFigure(new Point(20, 20), false); + xsad.LineTo(new Point(400, 50)); + xsad.LineTo(new Point(80, 100)); + xsad.LineTo(new Point(300, 150)); + xsad.EndFigure(false); + } + + ctx.DrawGeometry(null, strokePen, x); + + + var length = x.PlatformImpl.ContourLength; + + + if (x.PlatformImpl.TryGetSegment(length * 0.05, length * 0.2, true, out var dst1)) + ctx.DrawGeometry(null, strokePen1, (Geometry)dst1); + + if (x.PlatformImpl.TryGetSegment(length * 0.2, length * 0.8, true, out var dst2)) + ctx.DrawGeometry(null, strokePen2, (Geometry)dst2); + + if (x.PlatformImpl.TryGetSegment(length * 0.8, length * 0.95, true, out var dst3)) + ctx.DrawGeometry(null, strokePen3, (Geometry)dst3); + + /* + * paint.Style = SKPaintStyle.Stroke;z + paint.StrokeWidth = 10;z + paint.IsAntialias = true;z + paint.StrokeCap = SKStrokeCap.Round;z + paint.StrokeJoin = SKStrokeJoin.Round;x + + path.MoveTo(20, 20); + path.LineTo(400, 50); + path.LineTo(80, 100); + path.LineTo(300, 150); + + paint.Color = SampleMedia.Colors.XamarinDarkBlue; + canvas.DrawPath(path, paint); + + using (var measure = new SKPathMeasure(path, false)) + using (var dst = new SKPath()) + { + var length = measure.Length; + + dst.Reset(); + measure.GetSegment(length * 0.05f, length * 0.2f, dst, true); + paint.Color = SampleMedia.Colors.XamarinPurple; + canvas.DrawPath(dst, paint); + + dst.Reset(); + measure.GetSegment( dst, true); + paint.Color = SampleMedia.Colors.XamarinGreen; + canvas.DrawPath(dst, paint); + + dst.Reset(); + measure.GetSegment(length * 0.8f, length * 0.95f, dst, true); + paint.Color = SampleMedia.Colors.XamarinLightBlue; + canvas.DrawPath(dst, paint); + } + */ + // + // ctx.FillRectangle(Brushes.Fuchsia, new Rect(50, 50, 100, 100)); + } + + context.DrawImage(_bitmap, + new Rect(0, 0, 500, 500), + new Rect(0, 0, 500, 500)); + Dispatcher.UIThread.Post(InvalidateVisual, DispatcherPriority.Background); + base.Render(context); + } + } +} From b01dc1932a80d38767b40996e173e7a25b925698 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Fri, 19 Mar 2021 20:01:56 +0800 Subject: [PATCH 30/72] add path measure example --- .../RenderDemo/Pages/PathMeasurementPage.cs | 84 ++++++------------- 1 file changed, 25 insertions(+), 59 deletions(-) diff --git a/samples/RenderDemo/Pages/PathMeasurementPage.cs b/samples/RenderDemo/Pages/PathMeasurementPage.cs index 9f033e961f..6373e39ac5 100644 --- a/samples/RenderDemo/Pages/PathMeasurementPage.cs +++ b/samples/RenderDemo/Pages/PathMeasurementPage.cs @@ -1,5 +1,7 @@ +using System; using System.Diagnostics; using System.Drawing.Drawing2D; +using System.Security.Cryptography; using Avalonia; using Avalonia.Controls; using Avalonia.LogicalTree; @@ -19,6 +21,7 @@ namespace RenderDemo.Pages { _bitmap = new RenderTargetBitmap(new PixelSize(500, 500), new Vector(96, 96)); base.OnAttachedToLogicalTree(e); + AffectsRender(BoundsProperty); } protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e) @@ -28,91 +31,54 @@ namespace RenderDemo.Pages base.OnDetachedFromLogicalTree(e); } - readonly Stopwatch _st = Stopwatch.StartNew(); - - readonly IPen strokePen = new ImmutablePen(Brushes.DarkBlue, 10d, null, PenLineCap.Round, PenLineJoin.Round); readonly IPen strokePen1 = new ImmutablePen(Brushes.Purple, 10d, null, PenLineCap.Round, PenLineJoin.Round); readonly IPen strokePen2 = new ImmutablePen(Brushes.Green, 10d, null, PenLineCap.Round, PenLineJoin.Round); readonly IPen strokePen3 = new ImmutablePen(Brushes.LightBlue, 10d, null, PenLineCap.Round, PenLineJoin.Round); + readonly IPen strokePen4 = new ImmutablePen(Brushes.Red, 1d, null, PenLineCap.Round, PenLineJoin.Round); public override void Render(DrawingContext context) { using (var ctxi = _bitmap.CreateDrawingContext(null)) - using (var ctx = new DrawingContext(ctxi, false)) + using (var bitmapCtx = new DrawingContext(ctxi, false)) { ctxi.Clear(default); - var x = new PathGeometry(); + var basePath = new PathGeometry(); - using (var xsad = x.Open()) + using (var basePathCtx = basePath.Open()) { - xsad.BeginFigure(new Point(20, 20), false); - xsad.LineTo(new Point(400, 50)); - xsad.LineTo(new Point(80, 100)); - xsad.LineTo(new Point(300, 150)); - xsad.EndFigure(false); + basePathCtx.BeginFigure(new Point(20, 20), false); + basePathCtx.LineTo(new Point(400, 50)); + basePathCtx.LineTo(new Point(80, 100)); + basePathCtx.LineTo(new Point(300, 150)); + basePathCtx.EndFigure(false); } - ctx.DrawGeometry(null, strokePen, x); + bitmapCtx.DrawGeometry(null, strokePen, basePath); - var length = x.PlatformImpl.ContourLength; + var length = basePath.PlatformImpl.ContourLength; + if (basePath.PlatformImpl.TryGetSegment(length * 0.05, length * 0.2, true, out var dst1)) + bitmapCtx.DrawGeometry(null, strokePen1, dst1); - if (x.PlatformImpl.TryGetSegment(length * 0.05, length * 0.2, true, out var dst1)) - ctx.DrawGeometry(null, strokePen1, (Geometry)dst1); + if (basePath.PlatformImpl.TryGetSegment(length * 0.2, length * 0.8, true, out var dst2)) + bitmapCtx.DrawGeometry(null, strokePen2, dst2); - if (x.PlatformImpl.TryGetSegment(length * 0.2, length * 0.8, true, out var dst2)) - ctx.DrawGeometry(null, strokePen2, (Geometry)dst2); + if (basePath.PlatformImpl.TryGetSegment(length * 0.8, length * 0.95, true, out var dst3)) + bitmapCtx.DrawGeometry(null, strokePen3, dst3); - if (x.PlatformImpl.TryGetSegment(length * 0.8, length * 0.95, true, out var dst3)) - ctx.DrawGeometry(null, strokePen3, (Geometry)dst3); - - /* - * paint.Style = SKPaintStyle.Stroke;z - paint.StrokeWidth = 10;z - paint.IsAntialias = true;z - paint.StrokeCap = SKStrokeCap.Round;z - paint.StrokeJoin = SKStrokeJoin.Round;x - - path.MoveTo(20, 20); - path.LineTo(400, 50); - path.LineTo(80, 100); - path.LineTo(300, 150); - - paint.Color = SampleMedia.Colors.XamarinDarkBlue; - canvas.DrawPath(path, paint); - - using (var measure = new SKPathMeasure(path, false)) - using (var dst = new SKPath()) - { - var length = measure.Length; - - dst.Reset(); - measure.GetSegment(length * 0.05f, length * 0.2f, dst, true); - paint.Color = SampleMedia.Colors.XamarinPurple; - canvas.DrawPath(dst, paint); - - dst.Reset(); - measure.GetSegment( dst, true); - paint.Color = SampleMedia.Colors.XamarinGreen; - canvas.DrawPath(dst, paint); - - dst.Reset(); - measure.GetSegment(length * 0.8f, length * 0.95f, dst, true); - paint.Color = SampleMedia.Colors.XamarinLightBlue; - canvas.DrawPath(dst, paint); - } - */ - // - // ctx.FillRectangle(Brushes.Fuchsia, new Rect(50, 50, 100, 100)); + var pathBounds = basePath.GetRenderBounds(strokePen); + + bitmapCtx.DrawRectangle(null, strokePen4, pathBounds); } + context.DrawImage(_bitmap, new Rect(0, 0, 500, 500), new Rect(0, 0, 500, 500)); - Dispatcher.UIThread.Post(InvalidateVisual, DispatcherPriority.Background); + base.Render(context); } } From 8b8f4c6669adf58b8037992d8ebeaa8f85ba9c15 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Fri, 19 Mar 2021 20:33:52 +0800 Subject: [PATCH 31/72] add path measure example --- samples/RenderDemo/MainWindow.xaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/samples/RenderDemo/MainWindow.xaml b/samples/RenderDemo/MainWindow.xaml index 93fbe5e412..aa165d13f7 100644 --- a/samples/RenderDemo/MainWindow.xaml +++ b/samples/RenderDemo/MainWindow.xaml @@ -57,6 +57,9 @@ + + + From 149f1a09587f41de335aa56cc6a05c84121568d3 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Fri, 19 Mar 2021 20:34:04 +0800 Subject: [PATCH 32/72] api compat again --- src/Avalonia.Visuals/ApiCompatBaseline.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Visuals/ApiCompatBaseline.txt b/src/Avalonia.Visuals/ApiCompatBaseline.txt index 6c7b3efaf8..805d1955ea 100644 --- a/src/Avalonia.Visuals/ApiCompatBaseline.txt +++ b/src/Avalonia.Visuals/ApiCompatBaseline.txt @@ -5,5 +5,5 @@ InterfacesShouldHaveSameMembers : Interface member 'public System.Double Avaloni InterfacesShouldHaveSameMembers : Interface member 'public System.Double Avalonia.Platform.IGeometryImpl.ContourLength.get()' is present in the implementation but not in the contract. InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalonia.Platform.IGeometryImpl.TryGetPointAndTangentAtDistance(System.Double, Avalonia.Point, Avalonia.Point)' is present in the implementation but not in the contract. InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalonia.Platform.IGeometryImpl.TryGetPointAtDistance(System.Double, Avalonia.Point)' is present in the implementation but not in the contract. -InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalonia.Platform.IGeometryImpl.TryGetSegment(System.Single, System.Single, System.Boolean, Avalonia.Platform.IGeometryImpl)' is present in the implementation but not in the contract. +InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalonia.Platform.IGeometryImpl.TryGetSegment(System.Double, System.Double, System.Boolean, Avalonia.Platform.IGeometryImpl)' is present in the implementation but not in the contract. Total Issues: 7 From 61792ce45faa422f328c6a545304a9b1c93d4982 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Wed, 24 Mar 2021 18:30:22 +0300 Subject: [PATCH 33/72] Allow binding to classes with Classes.ClassName --- src/Avalonia.Styling/ClassBindingManager.cs | 38 ++++++++ src/Avalonia.Styling/Controls/Classes.cs | 21 ++++ .../StyledElementExtensions.cs | 11 +++ .../AvaloniaXamlIlCompiler.cs | 5 +- .../AvaloniaXamlIlClassesPropertyResolver.cs | 97 +++++++++++++++++++ ...mlIlReorderClassesPropertiesTransformer.cs | 40 ++++++++ .../AvaloniaXamlIlWellKnownTypes.cs | 10 ++ .../Xaml/BindingTests.cs | 32 ++++++ 8 files changed, 253 insertions(+), 1 deletion(-) create mode 100644 src/Avalonia.Styling/ClassBindingManager.cs create mode 100644 src/Avalonia.Styling/StyledElementExtensions.cs create mode 100644 src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlClassesPropertyResolver.cs create mode 100644 src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlReorderClassesPropertiesTransformer.cs diff --git a/src/Avalonia.Styling/ClassBindingManager.cs b/src/Avalonia.Styling/ClassBindingManager.cs new file mode 100644 index 0000000000..6ddea934bb --- /dev/null +++ b/src/Avalonia.Styling/ClassBindingManager.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using Avalonia.Data; + +namespace Avalonia +{ + internal static class ClassBindingManager + { + private static readonly Dictionary s_RegisteredProperties = + new Dictionary(); + + public static IDisposable Bind(IStyledElement target, string className, IBinding source, object anchor) + { + if (!s_RegisteredProperties.TryGetValue(className, out var prop)) + s_RegisteredProperties[className] = prop = RegisterClassProxyProperty(className); + return target.Bind(prop, source, anchor); + } + + private static AvaloniaProperty RegisterClassProxyProperty(string className) + { + var prop = AvaloniaProperty.Register("__AvaloniaReserved::Classes::" + className); + prop.Changed.Subscribe(args => + { + var enable = args.NewValue.GetValueOrDefault(); + var classes = ((IStyledElement)args.Sender).Classes; + if (enable) + { + if (!classes.Contains(className)) + classes.Add(className); + } + else + classes.Remove(className); + }); + + return prop; + } + } +} diff --git a/src/Avalonia.Styling/Controls/Classes.cs b/src/Avalonia.Styling/Controls/Classes.cs index 51dca57928..4e2783d4ec 100644 --- a/src/Avalonia.Styling/Controls/Classes.cs +++ b/src/Avalonia.Styling/Controls/Classes.cs @@ -265,5 +265,26 @@ namespace Avalonia.Controls $"The pseudoclass '{name}' may only be {operation} by the control itself."); } } + + /// + /// Adds a or removes a style class to/from the collection. + /// + /// The class names. + /// If true adds the class, if false, removes it. + /// + /// Only standard classes may be added or removed via this method. To add pseudoclasses (classes + /// beginning with a ':' character) use the protected + /// property. + /// + public void Set(string name, bool value) + { + if (value) + { + if (!Contains(name)) + Add(name); + } + else + Remove(name); + } } } diff --git a/src/Avalonia.Styling/StyledElementExtensions.cs b/src/Avalonia.Styling/StyledElementExtensions.cs new file mode 100644 index 0000000000..0c5a5f7438 --- /dev/null +++ b/src/Avalonia.Styling/StyledElementExtensions.cs @@ -0,0 +1,11 @@ +using System; +using Avalonia.Data; + +namespace Avalonia +{ + public static class StyledElementExtensions + { + public static IDisposable BindClass(this IStyledElement target, string className, IBinding source, object anchor) => + ClassBindingManager.Bind(target, className, source, anchor); + } +} diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlCompiler.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlCompiler.cs index abff763bb1..a191dc59fb 100644 --- a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlCompiler.cs +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlCompiler.cs @@ -41,10 +41,13 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions // Targeted InsertBefore( + new AvaloniaXamlIlResolveClassesPropertiesTransformer(), new AvaloniaXamlIlTransformInstanceAttachedProperties(), new AvaloniaXamlIlTransformSyntheticCompiledBindingMembers()); InsertAfter( - new AvaloniaXamlIlAvaloniaPropertyResolver()); + new AvaloniaXamlIlAvaloniaPropertyResolver(), + new AvaloniaXamlIlReorderClassesPropertiesTransformer() + ); InsertBefore( new AvaloniaXamlIlBindingPathParser(), diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlClassesPropertyResolver.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlClassesPropertyResolver.cs new file mode 100644 index 0000000000..23232dbcf3 --- /dev/null +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlClassesPropertyResolver.cs @@ -0,0 +1,97 @@ +using System.Collections.Generic; +using XamlX.Ast; +using XamlX.Emit; +using XamlX.IL; +using XamlX.Transform; +using XamlX.TypeSystem; + +namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers +{ + class AvaloniaXamlIlResolveClassesPropertiesTransformer : IXamlAstTransformer + { + public IXamlAstNode Transform(AstTransformationContext context, IXamlAstNode node) + { + if (node is XamlAstNamePropertyReference prop + && prop.TargetType is XamlAstClrTypeReference targetRef + && prop.DeclaringType is XamlAstClrTypeReference declaringRef) + { + var types = context.GetAvaloniaTypes(); + if (types.StyledElement.IsAssignableFrom(targetRef.Type) + && types.Classes.Equals(declaringRef.Type)) + { + return new XamlAstClrProperty(node, "class:" + prop.Name, types.Classes, + null) + { + Setters = { new ClassValueSetter(types, prop.Name), new ClassBindingSetter(types, prop.Name) } + }; + } + } + return node; + } + + + class ClassValueSetter : IXamlEmitablePropertySetter + { + private readonly AvaloniaXamlIlWellKnownTypes _types; + private readonly string _className; + + public ClassValueSetter(AvaloniaXamlIlWellKnownTypes types, string className) + { + _types = types; + _className = className; + Parameters = new[] { types.XamlIlTypes.Boolean }; + } + + public void Emit(IXamlILEmitter emitter) + { + using (var value = emitter.LocalsPool.GetLocal(_types.XamlIlTypes.Boolean)) + { + emitter + .Stloc(value.Local) + .EmitCall(_types.StyledElementClassesProperty.Getter) + .Ldstr(_className) + .Ldloc(value.Local) + .EmitCall(_types.Classes.GetMethod(new FindMethodMethodSignature("Set", + _types.XamlIlTypes.Void, _types.XamlIlTypes.String, _types.XamlIlTypes.Boolean))); + } + } + + public IXamlType TargetType => _types.StyledElement; + + public PropertySetterBinderParameters BinderParameters { get; } = + new PropertySetterBinderParameters { AllowXNull = false }; + public IReadOnlyList Parameters { get; } + } + + class ClassBindingSetter : IXamlEmitablePropertySetter + { + private readonly AvaloniaXamlIlWellKnownTypes _types; + private readonly string _className; + + public ClassBindingSetter(AvaloniaXamlIlWellKnownTypes types, string className) + { + _types = types; + _className = className; + Parameters = new[] {types.IBinding}; + } + + public void Emit(IXamlILEmitter emitter) + { + using (var bloc = emitter.LocalsPool.GetLocal(_types.IBinding)) + emitter + .Stloc(bloc.Local) + .Ldstr(_className) + .Ldloc(bloc.Local) + // TODO: provide anchor? + .Ldnull(); + emitter.EmitCall(_types.ClassesBindMethod, true); + } + + public IXamlType TargetType => _types.StyledElement; + + public PropertySetterBinderParameters BinderParameters { get; } = + new PropertySetterBinderParameters { AllowXNull = false }; + public IReadOnlyList Parameters { get; } + } + } +} diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlReorderClassesPropertiesTransformer.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlReorderClassesPropertiesTransformer.cs new file mode 100644 index 0000000000..ae3515a6d6 --- /dev/null +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlReorderClassesPropertiesTransformer.cs @@ -0,0 +1,40 @@ +using XamlX.Ast; +using XamlX.Transform; + +namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers +{ + class AvaloniaXamlIlReorderClassesPropertiesTransformer : IXamlAstTransformer + { + public IXamlAstNode Transform(AstTransformationContext context, IXamlAstNode node) + { + if (node is XamlAstObjectNode obj) + { + IXamlAstNode classesNode = null; + IXamlAstNode firstSingleClassNode = null; + var types = context.GetAvaloniaTypes(); + foreach (var child in obj.Children) + { + if (child is XamlAstXamlPropertyValueNode propValue + && propValue.Property is XamlAstClrProperty prop) + { + if (prop.DeclaringType.Equals(types.Classes)) + { + if (firstSingleClassNode == null) + firstSingleClassNode = child; + } + else if (prop.Name == "Classes" && prop.DeclaringType.Equals(types.StyledElement)) + classesNode = child; + } + } + + if (classesNode != null && firstSingleClassNode != null) + { + obj.Children.Remove(classesNode); + obj.Children.Insert(obj.Children.IndexOf(firstSingleClassNode), classesNode); + } + } + + return node; + } + } +} diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlWellKnownTypes.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlWellKnownTypes.cs index 34aae2c5ed..c4995b2de3 100644 --- a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlWellKnownTypes.cs +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlWellKnownTypes.cs @@ -25,6 +25,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers public IXamlType AssignBindingAttribute { get; } public IXamlType UnsetValueType { get; } public IXamlType StyledElement { get; } + public IXamlType IStyledElement { get; } public IXamlType NameScope { get; } public IXamlMethod NameScopeSetNameScope { get; } public IXamlType INameScope { get; } @@ -78,6 +79,8 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers public IXamlType ColumnDefinition { get; } public IXamlType ColumnDefinitions { get; } public IXamlType Classes { get; } + public IXamlMethod ClassesBindMethod { get; } + public IXamlProperty StyledElementClassesProperty { get; set; } public AvaloniaXamlIlWellKnownTypes(TransformerConfiguration cfg) { @@ -97,6 +100,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers IBinding, cfg.WellKnownTypes.Object); UnsetValueType = cfg.TypeSystem.GetType("Avalonia.UnsetValueType"); StyledElement = cfg.TypeSystem.GetType("Avalonia.StyledElement"); + IStyledElement = cfg.TypeSystem.GetType("Avalonia.IStyledElement"); INameScope = cfg.TypeSystem.GetType("Avalonia.Controls.INameScope"); INameScopeRegister = INameScope.GetMethod( new FindMethodMethodSignature("Register", XamlIlTypes.Void, @@ -168,6 +172,12 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers RowDefinition = cfg.TypeSystem.GetType("Avalonia.Controls.RowDefinition"); RowDefinitions = cfg.TypeSystem.GetType("Avalonia.Controls.RowDefinitions"); Classes = cfg.TypeSystem.GetType("Avalonia.Controls.Classes"); + StyledElementClassesProperty = + StyledElement.Properties.First(x => x.Name == "Classes" && x.PropertyType.Equals(Classes)); + ClassesBindMethod = cfg.TypeSystem.GetType("Avalonia.StyledElementExtensions") + .FindMethod( "BindClass", IDisposable, false, IStyledElement, + cfg.WellKnownTypes.String, + IBinding, cfg.WellKnownTypes.Object); } } diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BindingTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BindingTests.cs index 4f2b580bce..8af638c5d7 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BindingTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BindingTests.cs @@ -377,5 +377,37 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml public string Greeting1 { get; set; } = "Hello"; public string Greeting2 { get; set; } = "World"; } + + [Fact] + public void Binding_Classes_Works() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + // Note, this test also checks `Classes` reordering, so it should be kept AFTER the last single class + var xaml = @" + + /// The window to attach DevTools to. - /// additional settint of DevTools + /// Additional settings of DevTools. public static void AttachDevTools(this TopLevel root, DevToolsOptions options) { DevTools.Attach(root, options); From 1a8f2f7f354084f130bcad5d7e393b4434e34fc4 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Fri, 18 Dec 2020 20:56:58 -0500 Subject: [PATCH 38/72] Add tapped event args --- src/Avalonia.Input/Gestures.cs | 20 +++++---- src/Avalonia.Input/InputElement.cs | 8 ++-- src/Avalonia.Input/TappedGestureEventArgs.cs | 44 ++++++++++++++++++++ 3 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 src/Avalonia.Input/TappedGestureEventArgs.cs diff --git a/src/Avalonia.Input/Gestures.cs b/src/Avalonia.Input/Gestures.cs index 1be2595ebe..8d7a02f12e 100644 --- a/src/Avalonia.Input/Gestures.cs +++ b/src/Avalonia.Input/Gestures.cs @@ -6,17 +6,17 @@ namespace Avalonia.Input { public static class Gestures { - public static readonly RoutedEvent TappedEvent = RoutedEvent.Register( + public static readonly RoutedEvent TappedEvent = RoutedEvent.Register( "Tapped", RoutingStrategies.Bubble, typeof(Gestures)); - public static readonly RoutedEvent DoubleTappedEvent = RoutedEvent.Register( + public static readonly RoutedEvent DoubleTappedEvent = RoutedEvent.Register( "DoubleTapped", RoutingStrategies.Bubble, typeof(Gestures)); - public static readonly RoutedEvent RightTappedEvent = RoutedEvent.Register( + public static readonly RoutedEvent RightTappedEvent = RoutedEvent.Register( "RightTapped", RoutingStrategies.Bubble, typeof(Gestures)); @@ -24,7 +24,7 @@ namespace Avalonia.Input public static readonly RoutedEvent ScrollGestureEvent = RoutedEvent.Register( "ScrollGesture", RoutingStrategies.Bubble, typeof(Gestures)); - + public static readonly RoutedEvent ScrollGestureEndedEvent = RoutedEvent.Register( "ScrollGestureEnded", RoutingStrategies.Bubble, typeof(Gestures)); @@ -89,7 +89,7 @@ namespace Avalonia.Input { if (s_lastPress.TryGetTarget(out var target) && target == e.Source) { - e.Source.RaiseEvent(new RoutedEventArgs(DoubleTappedEvent)); + e.Source.RaiseEvent(new DoubleTappedEventArgs(e)); } } } @@ -105,8 +105,14 @@ namespace Avalonia.Input { if (e.InitialPressMouseButton == MouseButton.Left || e.InitialPressMouseButton == MouseButton.Right) { - var et = e.InitialPressMouseButton != MouseButton.Right ? TappedEvent : RightTappedEvent; - e.Source.RaiseEvent(new RoutedEventArgs(et)); + if (e.InitialPressMouseButton != MouseButton.Right) + { + e.Source.RaiseEvent(new RightTappedEventArgs(e)); + } + else + { + e.Source.RaiseEvent(new TappedEventArgs(e)); + } } } } diff --git a/src/Avalonia.Input/InputElement.cs b/src/Avalonia.Input/InputElement.cs index f3996cea76..e0594b5ce6 100644 --- a/src/Avalonia.Input/InputElement.cs +++ b/src/Avalonia.Input/InputElement.cs @@ -176,12 +176,12 @@ namespace Avalonia.Input /// /// Defines the event. /// - public static readonly RoutedEvent TappedEvent = Gestures.TappedEvent; + public static readonly RoutedEvent TappedEvent = Gestures.TappedEvent; /// /// Defines the event. /// - public static readonly RoutedEvent DoubleTappedEvent = Gestures.DoubleTappedEvent; + public static readonly RoutedEvent DoubleTappedEvent = Gestures.DoubleTappedEvent; private bool _isEffectivelyEnabled = true; private bool _isFocused; @@ -346,7 +346,7 @@ namespace Avalonia.Input /// /// Occurs when a tap gesture occurs on the control. /// - public event EventHandler Tapped + public event EventHandler Tapped { add { AddHandler(TappedEvent, value); } remove { RemoveHandler(TappedEvent, value); } @@ -355,7 +355,7 @@ namespace Avalonia.Input /// /// Occurs when a double-tap gesture occurs on the control. /// - public event EventHandler DoubleTapped + public event EventHandler DoubleTapped { add { AddHandler(DoubleTappedEvent, value); } remove { RemoveHandler(DoubleTappedEvent, value); } diff --git a/src/Avalonia.Input/TappedGestureEventArgs.cs b/src/Avalonia.Input/TappedGestureEventArgs.cs new file mode 100644 index 0000000000..bed76f5abd --- /dev/null +++ b/src/Avalonia.Input/TappedGestureEventArgs.cs @@ -0,0 +1,44 @@ +using Avalonia.Interactivity; +using Avalonia.VisualTree; + +namespace Avalonia.Input +{ + public class DoubleTappedEventArgs : RoutedEventArgs + { + private readonly PointerEventArgs lastPointerEventArgs; + + public DoubleTappedEventArgs(PointerEventArgs lastPointerEventArgs) + : base(Gestures.DoubleTappedEvent) + { + this.lastPointerEventArgs = lastPointerEventArgs; + } + + public Point GetPosition(IVisual? relativeTo) => lastPointerEventArgs.GetPosition(relativeTo); + } + + public class TappedEventArgs : RoutedEventArgs + { + private readonly PointerEventArgs lastPointerEventArgs; + + public TappedEventArgs(PointerEventArgs lastPointerEventArgs) + : base(Gestures.DoubleTappedEvent) + { + this.lastPointerEventArgs = lastPointerEventArgs; + } + + public Point GetPosition(IVisual? relativeTo) => lastPointerEventArgs.GetPosition(relativeTo); + } + + public class RightTappedEventArgs : RoutedEventArgs + { + private readonly PointerEventArgs lastPointerEventArgs; + + public RightTappedEventArgs(PointerEventArgs lastPointerEventArgs) + : base(Gestures.DoubleTappedEvent) + { + this.lastPointerEventArgs = lastPointerEventArgs; + } + + public Point GetPosition(IVisual? relativeTo) => lastPointerEventArgs.GetPosition(relativeTo); + } +} From f7a41c079333afdbb37e24ad8572b23873751e04 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Sat, 23 Jan 2021 19:18:36 -0500 Subject: [PATCH 39/72] Use single TappedEventArgs for all tapped events --- src/Avalonia.Input/Gestures.cs | 10 ++--- src/Avalonia.Input/InputElement.cs | 4 +- src/Avalonia.Input/TappedEventArgs.cs | 18 ++++++++ src/Avalonia.Input/TappedGestureEventArgs.cs | 44 -------------------- 4 files changed, 25 insertions(+), 51 deletions(-) create mode 100644 src/Avalonia.Input/TappedEventArgs.cs delete mode 100644 src/Avalonia.Input/TappedGestureEventArgs.cs diff --git a/src/Avalonia.Input/Gestures.cs b/src/Avalonia.Input/Gestures.cs index 8d7a02f12e..f5499c12f3 100644 --- a/src/Avalonia.Input/Gestures.cs +++ b/src/Avalonia.Input/Gestures.cs @@ -11,12 +11,12 @@ namespace Avalonia.Input RoutingStrategies.Bubble, typeof(Gestures)); - public static readonly RoutedEvent DoubleTappedEvent = RoutedEvent.Register( + public static readonly RoutedEvent DoubleTappedEvent = RoutedEvent.Register( "DoubleTapped", RoutingStrategies.Bubble, typeof(Gestures)); - public static readonly RoutedEvent RightTappedEvent = RoutedEvent.Register( + public static readonly RoutedEvent RightTappedEvent = RoutedEvent.Register( "RightTapped", RoutingStrategies.Bubble, typeof(Gestures)); @@ -89,7 +89,7 @@ namespace Avalonia.Input { if (s_lastPress.TryGetTarget(out var target) && target == e.Source) { - e.Source.RaiseEvent(new DoubleTappedEventArgs(e)); + e.Source.RaiseEvent(new TappedEventArgs(DoubleTappedEvent, e)); } } } @@ -107,11 +107,11 @@ namespace Avalonia.Input { if (e.InitialPressMouseButton != MouseButton.Right) { - e.Source.RaiseEvent(new RightTappedEventArgs(e)); + e.Source.RaiseEvent(new TappedEventArgs(RightTappedEvent, e)); } else { - e.Source.RaiseEvent(new TappedEventArgs(e)); + e.Source.RaiseEvent(new TappedEventArgs(TappedEvent, e)); } } } diff --git a/src/Avalonia.Input/InputElement.cs b/src/Avalonia.Input/InputElement.cs index e0594b5ce6..8f99770b3b 100644 --- a/src/Avalonia.Input/InputElement.cs +++ b/src/Avalonia.Input/InputElement.cs @@ -181,7 +181,7 @@ namespace Avalonia.Input /// /// Defines the event. /// - public static readonly RoutedEvent DoubleTappedEvent = Gestures.DoubleTappedEvent; + public static readonly RoutedEvent DoubleTappedEvent = Gestures.DoubleTappedEvent; private bool _isEffectivelyEnabled = true; private bool _isFocused; @@ -355,7 +355,7 @@ namespace Avalonia.Input /// /// Occurs when a double-tap gesture occurs on the control. /// - public event EventHandler DoubleTapped + public event EventHandler DoubleTapped { add { AddHandler(DoubleTappedEvent, value); } remove { RemoveHandler(DoubleTappedEvent, value); } diff --git a/src/Avalonia.Input/TappedEventArgs.cs b/src/Avalonia.Input/TappedEventArgs.cs new file mode 100644 index 0000000000..02add509cd --- /dev/null +++ b/src/Avalonia.Input/TappedEventArgs.cs @@ -0,0 +1,18 @@ +using Avalonia.Interactivity; +using Avalonia.VisualTree; + +namespace Avalonia.Input +{ + public class TappedEventArgs : RoutedEventArgs + { + private readonly PointerEventArgs lastPointerEventArgs; + + public TappedEventArgs(RoutedEvent routedEvent, PointerEventArgs lastPointerEventArgs) + : base(routedEvent) + { + this.lastPointerEventArgs = lastPointerEventArgs; + } + + public Point GetPosition(IVisual? relativeTo) => lastPointerEventArgs.GetPosition(relativeTo); + } +} diff --git a/src/Avalonia.Input/TappedGestureEventArgs.cs b/src/Avalonia.Input/TappedGestureEventArgs.cs deleted file mode 100644 index bed76f5abd..0000000000 --- a/src/Avalonia.Input/TappedGestureEventArgs.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Avalonia.Interactivity; -using Avalonia.VisualTree; - -namespace Avalonia.Input -{ - public class DoubleTappedEventArgs : RoutedEventArgs - { - private readonly PointerEventArgs lastPointerEventArgs; - - public DoubleTappedEventArgs(PointerEventArgs lastPointerEventArgs) - : base(Gestures.DoubleTappedEvent) - { - this.lastPointerEventArgs = lastPointerEventArgs; - } - - public Point GetPosition(IVisual? relativeTo) => lastPointerEventArgs.GetPosition(relativeTo); - } - - public class TappedEventArgs : RoutedEventArgs - { - private readonly PointerEventArgs lastPointerEventArgs; - - public TappedEventArgs(PointerEventArgs lastPointerEventArgs) - : base(Gestures.DoubleTappedEvent) - { - this.lastPointerEventArgs = lastPointerEventArgs; - } - - public Point GetPosition(IVisual? relativeTo) => lastPointerEventArgs.GetPosition(relativeTo); - } - - public class RightTappedEventArgs : RoutedEventArgs - { - private readonly PointerEventArgs lastPointerEventArgs; - - public RightTappedEventArgs(PointerEventArgs lastPointerEventArgs) - : base(Gestures.DoubleTappedEvent) - { - this.lastPointerEventArgs = lastPointerEventArgs; - } - - public Point GetPosition(IVisual? relativeTo) => lastPointerEventArgs.GetPosition(relativeTo); - } -} From e0d7841b58483b9e43fc175ce9b39ce13a77135e Mon Sep 17 00:00:00 2001 From: Max Katz Date: Tue, 26 Jan 2021 00:36:22 -0500 Subject: [PATCH 40/72] Fix right/left tapped raise event --- src/Avalonia.Input/Gestures.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Input/Gestures.cs b/src/Avalonia.Input/Gestures.cs index f5499c12f3..f2cc9e9072 100644 --- a/src/Avalonia.Input/Gestures.cs +++ b/src/Avalonia.Input/Gestures.cs @@ -105,7 +105,7 @@ namespace Avalonia.Input { if (e.InitialPressMouseButton == MouseButton.Left || e.InitialPressMouseButton == MouseButton.Right) { - if (e.InitialPressMouseButton != MouseButton.Right) + if (e.InitialPressMouseButton == MouseButton.Right) { e.Source.RaiseEvent(new TappedEventArgs(RightTappedEvent, e)); } From e750512a4ba9dc07b5e020747dbd3fab163e6c3f Mon Sep 17 00:00:00 2001 From: Max Katz Date: Sun, 28 Mar 2021 19:21:02 -0400 Subject: [PATCH 41/72] Update API contract --- src/Avalonia.Input/ApiCompatBaseline.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Input/ApiCompatBaseline.txt b/src/Avalonia.Input/ApiCompatBaseline.txt index fff2fb2806..98eb8598d8 100644 --- a/src/Avalonia.Input/ApiCompatBaseline.txt +++ b/src/Avalonia.Input/ApiCompatBaseline.txt @@ -1,4 +1,13 @@ Compat issues with assembly Avalonia.Input: MembersMustExist : Member 'public Avalonia.Platform.IPlatformHandle Avalonia.Input.Cursor.PlatformCursor.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public Avalonia.Interactivity.RoutedEvent Avalonia.Interactivity.RoutedEvent Avalonia.Input.Gestures.DoubleTappedEvent' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public Avalonia.Interactivity.RoutedEvent Avalonia.Interactivity.RoutedEvent Avalonia.Input.Gestures.RightTappedEvent' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public Avalonia.Interactivity.RoutedEvent Avalonia.Interactivity.RoutedEvent Avalonia.Input.Gestures.TappedEvent' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public Avalonia.Interactivity.RoutedEvent Avalonia.Interactivity.RoutedEvent Avalonia.Input.InputElement.DoubleTappedEvent' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public Avalonia.Interactivity.RoutedEvent Avalonia.Interactivity.RoutedEvent Avalonia.Input.InputElement.TappedEvent' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public void Avalonia.Input.InputElement.add_DoubleTapped(System.EventHandler)' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public void Avalonia.Input.InputElement.add_Tapped(System.EventHandler)' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public void Avalonia.Input.InputElement.remove_DoubleTapped(System.EventHandler)' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public void Avalonia.Input.InputElement.remove_Tapped(System.EventHandler)' does not exist in the implementation but it does exist in the contract. TypesMustExist : Type 'Avalonia.Platform.IStandardCursorFactory' does not exist in the implementation but it does exist in the contract. -Total Issues: 2 +Total Issues: 11 From 6c608c6d0d67a8da67b030c7b2fe25992811e940 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Mon, 29 Mar 2021 22:33:56 -0400 Subject: [PATCH 42/72] Avoid breaking changes for next release --- src/Avalonia.Input/ApiCompatBaseline.txt | 11 +---------- src/Avalonia.Input/Gestures.cs | 6 +++--- src/Avalonia.Input/InputElement.cs | 8 ++++---- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/Avalonia.Input/ApiCompatBaseline.txt b/src/Avalonia.Input/ApiCompatBaseline.txt index 98eb8598d8..fff2fb2806 100644 --- a/src/Avalonia.Input/ApiCompatBaseline.txt +++ b/src/Avalonia.Input/ApiCompatBaseline.txt @@ -1,13 +1,4 @@ Compat issues with assembly Avalonia.Input: MembersMustExist : Member 'public Avalonia.Platform.IPlatformHandle Avalonia.Input.Cursor.PlatformCursor.get()' does not exist in the implementation but it does exist in the contract. -MembersMustExist : Member 'public Avalonia.Interactivity.RoutedEvent Avalonia.Interactivity.RoutedEvent Avalonia.Input.Gestures.DoubleTappedEvent' does not exist in the implementation but it does exist in the contract. -MembersMustExist : Member 'public Avalonia.Interactivity.RoutedEvent Avalonia.Interactivity.RoutedEvent Avalonia.Input.Gestures.RightTappedEvent' does not exist in the implementation but it does exist in the contract. -MembersMustExist : Member 'public Avalonia.Interactivity.RoutedEvent Avalonia.Interactivity.RoutedEvent Avalonia.Input.Gestures.TappedEvent' does not exist in the implementation but it does exist in the contract. -MembersMustExist : Member 'public Avalonia.Interactivity.RoutedEvent Avalonia.Interactivity.RoutedEvent Avalonia.Input.InputElement.DoubleTappedEvent' does not exist in the implementation but it does exist in the contract. -MembersMustExist : Member 'public Avalonia.Interactivity.RoutedEvent Avalonia.Interactivity.RoutedEvent Avalonia.Input.InputElement.TappedEvent' does not exist in the implementation but it does exist in the contract. -MembersMustExist : Member 'public void Avalonia.Input.InputElement.add_DoubleTapped(System.EventHandler)' does not exist in the implementation but it does exist in the contract. -MembersMustExist : Member 'public void Avalonia.Input.InputElement.add_Tapped(System.EventHandler)' does not exist in the implementation but it does exist in the contract. -MembersMustExist : Member 'public void Avalonia.Input.InputElement.remove_DoubleTapped(System.EventHandler)' does not exist in the implementation but it does exist in the contract. -MembersMustExist : Member 'public void Avalonia.Input.InputElement.remove_Tapped(System.EventHandler)' does not exist in the implementation but it does exist in the contract. TypesMustExist : Type 'Avalonia.Platform.IStandardCursorFactory' does not exist in the implementation but it does exist in the contract. -Total Issues: 11 +Total Issues: 2 diff --git a/src/Avalonia.Input/Gestures.cs b/src/Avalonia.Input/Gestures.cs index f2cc9e9072..60b6b9e947 100644 --- a/src/Avalonia.Input/Gestures.cs +++ b/src/Avalonia.Input/Gestures.cs @@ -6,17 +6,17 @@ namespace Avalonia.Input { public static class Gestures { - public static readonly RoutedEvent TappedEvent = RoutedEvent.Register( + public static readonly RoutedEvent TappedEvent = RoutedEvent.Register( "Tapped", RoutingStrategies.Bubble, typeof(Gestures)); - public static readonly RoutedEvent DoubleTappedEvent = RoutedEvent.Register( + public static readonly RoutedEvent DoubleTappedEvent = RoutedEvent.Register( "DoubleTapped", RoutingStrategies.Bubble, typeof(Gestures)); - public static readonly RoutedEvent RightTappedEvent = RoutedEvent.Register( + public static readonly RoutedEvent RightTappedEvent = RoutedEvent.Register( "RightTapped", RoutingStrategies.Bubble, typeof(Gestures)); diff --git a/src/Avalonia.Input/InputElement.cs b/src/Avalonia.Input/InputElement.cs index 8f99770b3b..f3996cea76 100644 --- a/src/Avalonia.Input/InputElement.cs +++ b/src/Avalonia.Input/InputElement.cs @@ -176,12 +176,12 @@ namespace Avalonia.Input /// /// Defines the event. /// - public static readonly RoutedEvent TappedEvent = Gestures.TappedEvent; + public static readonly RoutedEvent TappedEvent = Gestures.TappedEvent; /// /// Defines the event. /// - public static readonly RoutedEvent DoubleTappedEvent = Gestures.DoubleTappedEvent; + public static readonly RoutedEvent DoubleTappedEvent = Gestures.DoubleTappedEvent; private bool _isEffectivelyEnabled = true; private bool _isFocused; @@ -346,7 +346,7 @@ namespace Avalonia.Input /// /// Occurs when a tap gesture occurs on the control. /// - public event EventHandler Tapped + public event EventHandler Tapped { add { AddHandler(TappedEvent, value); } remove { RemoveHandler(TappedEvent, value); } @@ -355,7 +355,7 @@ namespace Avalonia.Input /// /// Occurs when a double-tap gesture occurs on the control. /// - public event EventHandler DoubleTapped + public event EventHandler DoubleTapped { add { AddHandler(DoubleTappedEvent, value); } remove { RemoveHandler(DoubleTappedEvent, value); } From 37e8890d2729d5e14912b3cc1a680d4672194c25 Mon Sep 17 00:00:00 2001 From: Yoh Deadfall Date: Tue, 30 Mar 2021 12:40:03 +0200 Subject: [PATCH 43/72] CanExecute reevaluation on attaching to logical tree --- src/Avalonia.Controls/Button.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Avalonia.Controls/Button.cs b/src/Avalonia.Controls/Button.cs index c779e4b0cb..6093cbd581 100644 --- a/src/Avalonia.Controls/Button.cs +++ b/src/Avalonia.Controls/Button.cs @@ -218,6 +218,7 @@ namespace Avalonia.Controls if (Command != null) { Command.CanExecuteChanged += CanExecuteChanged; + CanExecuteChanged(this, EventArgs.Empty); } } From 741f3458d4ec1e5bb32916e12f3d538b46c483a1 Mon Sep 17 00:00:00 2001 From: Yoh Deadfall Date: Thu, 1 Apr 2021 17:44:00 +0200 Subject: [PATCH 44/72] Allowed empty templates --- .../Templates/DataTemplate.cs | 2 +- .../Templates/ItemsPanelTemplate.cs | 3 +-- .../Templates/Template.cs | 2 +- .../Templates/TemplateContent.cs | 8 ++++-- .../Templates/TreeDataTemplate.cs | 8 ++++-- .../Xaml/DataTemplateTests.cs | 25 +++++++++++++++++++ 6 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/Markup/Avalonia.Markup.Xaml/Templates/DataTemplate.cs b/src/Markup/Avalonia.Markup.Xaml/Templates/DataTemplate.cs index 07c5451135..650534b347 100644 --- a/src/Markup/Avalonia.Markup.Xaml/Templates/DataTemplate.cs +++ b/src/Markup/Avalonia.Markup.Xaml/Templates/DataTemplate.cs @@ -30,7 +30,7 @@ namespace Avalonia.Markup.Xaml.Templates public IControl Build(object data, IControl existing) { - return existing ?? TemplateContent.Load(Content).Control; + return existing ?? TemplateContent.Load(Content)?.Control; } } } diff --git a/src/Markup/Avalonia.Markup.Xaml/Templates/ItemsPanelTemplate.cs b/src/Markup/Avalonia.Markup.Xaml/Templates/ItemsPanelTemplate.cs index c8843a3176..c096ed7ed7 100644 --- a/src/Markup/Avalonia.Markup.Xaml/Templates/ItemsPanelTemplate.cs +++ b/src/Markup/Avalonia.Markup.Xaml/Templates/ItemsPanelTemplate.cs @@ -10,8 +10,7 @@ namespace Avalonia.Markup.Xaml.Templates [TemplateContent] public object Content { get; set; } - public IPanel Build() - => (IPanel)TemplateContent.Load(Content).Control; + public IPanel Build() => (IPanel)TemplateContent.Load(Content)?.Control; object ITemplate.Build() => Build(); } diff --git a/src/Markup/Avalonia.Markup.Xaml/Templates/Template.cs b/src/Markup/Avalonia.Markup.Xaml/Templates/Template.cs index 65323ae665..45fae9cb28 100644 --- a/src/Markup/Avalonia.Markup.Xaml/Templates/Template.cs +++ b/src/Markup/Avalonia.Markup.Xaml/Templates/Template.cs @@ -10,7 +10,7 @@ namespace Avalonia.Markup.Xaml.Templates [TemplateContent] public object Content { get; set; } - public IControl Build() => TemplateContent.Load(Content).Control; + public IControl Build() => TemplateContent.Load(Content)?.Control; object ITemplate.Build() => Build(); } diff --git a/src/Markup/Avalonia.Markup.Xaml/Templates/TemplateContent.cs b/src/Markup/Avalonia.Markup.Xaml/Templates/TemplateContent.cs index 96f25668fb..483a1a5d06 100644 --- a/src/Markup/Avalonia.Markup.Xaml/Templates/TemplateContent.cs +++ b/src/Markup/Avalonia.Markup.Xaml/Templates/TemplateContent.cs @@ -1,6 +1,4 @@ using System; -using Avalonia.Controls; -using System.Collections.Generic; using Avalonia.Controls.Templates; namespace Avalonia.Markup.Xaml.Templates @@ -14,6 +12,12 @@ namespace Avalonia.Markup.Xaml.Templates { return (ControlTemplateResult)direct(null); } + + if (templateContent is null) + { + return null; + } + throw new ArgumentException(nameof(templateContent)); } } diff --git a/src/Markup/Avalonia.Markup.Xaml/Templates/TreeDataTemplate.cs b/src/Markup/Avalonia.Markup.Xaml/Templates/TreeDataTemplate.cs index d785ac4ac0..7b065c7f47 100644 --- a/src/Markup/Avalonia.Markup.Xaml/Templates/TreeDataTemplate.cs +++ b/src/Markup/Avalonia.Markup.Xaml/Templates/TreeDataTemplate.cs @@ -51,8 +51,12 @@ namespace Avalonia.Markup.Xaml.Templates public IControl Build(object data) { - var visualTreeForItem = TemplateContent.Load(Content).Control; - visualTreeForItem.DataContext = data; + var visualTreeForItem = TemplateContent.Load(Content)?.Control; + if (visualTreeForItem != null) + { + visualTreeForItem.DataContext = data; + } + return visualTreeForItem; } } diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/DataTemplateTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/DataTemplateTests.cs index 033b670bf4..53881467e7 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/DataTemplateTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/DataTemplateTests.cs @@ -7,6 +7,31 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml { public class DataTemplateTests : XamlTestBase { + [Fact] + public void DataTemplate_Can_Be_Empty() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var xaml = @" + + + + + +"; + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); + var target = window.FindControl("target"); + + window.ApplyTemplate(); + target.ApplyTemplate(); + ((ContentPresenter)target.Presenter).UpdateChild(); + + Assert.Null(target.Presenter.Child); + } + } + [Fact] public void DataTemplate_Can_Contain_Name() { From 65792cf4b037ec3f48d8e8c54de775608a519db8 Mon Sep 17 00:00:00 2001 From: artyom Date: Fri, 2 Apr 2021 02:21:08 +0300 Subject: [PATCH 45/72] feature: Disable ReactiveUI platform registrations --- build/ReactiveUI.props | 2 +- src/Avalonia.ReactiveUI/AppBuilderExtensions.cs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/build/ReactiveUI.props b/build/ReactiveUI.props index f74ab07e31..c3b136d41d 100644 --- a/build/ReactiveUI.props +++ b/build/ReactiveUI.props @@ -1,5 +1,5 @@ - + diff --git a/src/Avalonia.ReactiveUI/AppBuilderExtensions.cs b/src/Avalonia.ReactiveUI/AppBuilderExtensions.cs index 6771d3e179..fa666e2125 100644 --- a/src/Avalonia.ReactiveUI/AppBuilderExtensions.cs +++ b/src/Avalonia.ReactiveUI/AppBuilderExtensions.cs @@ -17,6 +17,8 @@ namespace Avalonia.ReactiveUI { return builder.AfterPlatformServicesSetup(_ => { + PlatformRegistrationManager.SetRegistrationNamespaces(RegistrationNamespace.Avalonia); + Locator.CurrentMutable.InitializeReactiveUI(); RxApp.MainThreadScheduler = AvaloniaScheduler.Instance; Locator.CurrentMutable.RegisterConstant(new AvaloniaActivationForViewFetcher(), typeof(IActivationForViewFetcher)); Locator.CurrentMutable.RegisterConstant(new AutoDataTemplateBindingHook(), typeof(IPropertyBindingHook)); From cc5568781cf046d8b81efe0fc56137b1fe920499 Mon Sep 17 00:00:00 2001 From: artyom Date: Fri, 2 Apr 2021 02:31:08 +0300 Subject: [PATCH 46/72] Don't initialize things twice --- src/Avalonia.ReactiveUI/AppBuilderExtensions.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Avalonia.ReactiveUI/AppBuilderExtensions.cs b/src/Avalonia.ReactiveUI/AppBuilderExtensions.cs index fa666e2125..e5250484e2 100644 --- a/src/Avalonia.ReactiveUI/AppBuilderExtensions.cs +++ b/src/Avalonia.ReactiveUI/AppBuilderExtensions.cs @@ -18,7 +18,6 @@ namespace Avalonia.ReactiveUI return builder.AfterPlatformServicesSetup(_ => { PlatformRegistrationManager.SetRegistrationNamespaces(RegistrationNamespace.Avalonia); - Locator.CurrentMutable.InitializeReactiveUI(); RxApp.MainThreadScheduler = AvaloniaScheduler.Instance; Locator.CurrentMutable.RegisterConstant(new AvaloniaActivationForViewFetcher(), typeof(IActivationForViewFetcher)); Locator.CurrentMutable.RegisterConstant(new AutoDataTemplateBindingHook(), typeof(IPropertyBindingHook)); From 2045097cc800b27df5c881c9970f617634f795ac Mon Sep 17 00:00:00 2001 From: artyom Date: Fri, 2 Apr 2021 11:45:58 +0300 Subject: [PATCH 47/72] Wrap UseReactiveUI in RegisterResolverCallbackChanged --- src/Avalonia.ReactiveUI/AppBuilderExtensions.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Avalonia.ReactiveUI/AppBuilderExtensions.cs b/src/Avalonia.ReactiveUI/AppBuilderExtensions.cs index e5250484e2..359da3d7c2 100644 --- a/src/Avalonia.ReactiveUI/AppBuilderExtensions.cs +++ b/src/Avalonia.ReactiveUI/AppBuilderExtensions.cs @@ -9,19 +9,22 @@ namespace Avalonia.ReactiveUI { /// /// Initializes ReactiveUI framework to use with Avalonia. Registers Avalonia - /// scheduler and Avalonia activation for view fetcher. Always remember to - /// call this method if you are using ReactiveUI in your application. + /// scheduler, an activation for view fetcher, a template binding hook. Remember + /// to call this method if you are using ReactiveUI in your application. /// public static TAppBuilder UseReactiveUI(this TAppBuilder builder) - where TAppBuilder : AppBuilderBase, new() - { - return builder.AfterPlatformServicesSetup(_ => + where TAppBuilder : AppBuilderBase, new() => + builder.AfterPlatformServicesSetup(_ => Locator.RegisterResolverCallbackChanged(() => { + if (Locator.CurrentMutable is null) + { + return; + } + PlatformRegistrationManager.SetRegistrationNamespaces(RegistrationNamespace.Avalonia); RxApp.MainThreadScheduler = AvaloniaScheduler.Instance; Locator.CurrentMutable.RegisterConstant(new AvaloniaActivationForViewFetcher(), typeof(IActivationForViewFetcher)); Locator.CurrentMutable.RegisterConstant(new AutoDataTemplateBindingHook(), typeof(IPropertyBindingHook)); - }); - } + })); } } From 38703b94232a562cfc20a7b50ca971e37a28bc43 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Fri, 2 Apr 2021 15:29:46 +0200 Subject: [PATCH 48/72] Fix pointer interaction with reversed direction slider. Previously dragging a slider with `IsDirectionRevered = true` resulted in the slider moving the wrong way. --- src/Avalonia.Controls/Slider.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Slider.cs b/src/Avalonia.Controls/Slider.cs index e02efc2bd2..6419981fb1 100644 --- a/src/Avalonia.Controls/Slider.cs +++ b/src/Avalonia.Controls/Slider.cs @@ -341,7 +341,9 @@ namespace Avalonia.Controls var pointNum = orient ? x.Position.X : x.Position.Y; var logicalPos = MathUtilities.Clamp(pointNum / pointDen, 0.0d, 1.0d); - var invert = orient ? 0 : 1; + var invert = orient ? + IsDirectionReversed ? 1 : 0 : + IsDirectionReversed ? 0 : 1; var calcVal = Math.Abs(invert - logicalPos); var range = Maximum - Minimum; var finalValue = calcVal * range + Minimum; From 2fcad40bce09115ab022a600e26de8a1de4f1903 Mon Sep 17 00:00:00 2001 From: Jumar Macato <16554748+jmacato@users.noreply.github.com> Date: Sat, 3 Apr 2021 16:27:00 +0800 Subject: [PATCH 49/72] Add Deterministic XamlX ID Generator (#5684) * Add Deterministic XamlX ID Generator * Apply suggestions from code review * simplify stuff and apply review * Update src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs * Update src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs * add the det id gen to runtine xamlx compiler * rerun tests * rerun tests * try this * use id gen instead of guid * a * Update src/Markup/Avalonia.Markup.Xaml.Loader/AvaloniaXamlIlRuntimeCompiler.cs * Update AvaloniaXamlIlCompilerConfiguration.cs revert * Update XamlIlClrPropertyInfoHelper.cs * Update AvaloniaXamlIlRuntimeCompiler.cs * fix * revert hack * make id gen optional --- src/Avalonia.Build.Tasks/DeterministicIdGenerator.cs | 12 ++++++++++++ src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs | 4 ++-- .../AvaloniaXamlIlCompilerConfiguration.cs | 5 +++-- 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 src/Avalonia.Build.Tasks/DeterministicIdGenerator.cs diff --git a/src/Avalonia.Build.Tasks/DeterministicIdGenerator.cs b/src/Avalonia.Build.Tasks/DeterministicIdGenerator.cs new file mode 100644 index 0000000000..f207b558a3 --- /dev/null +++ b/src/Avalonia.Build.Tasks/DeterministicIdGenerator.cs @@ -0,0 +1,12 @@ +using System; +using XamlX.Transform; + +namespace Avalonia.Build.Tasks +{ + public class DeterministicIdGenerator : IXamlIdentifierGenerator + { + private int _nextId = 1; + + public string GenerateIdentifierPart() => (_nextId++).ToString(); + } +} diff --git a/src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs b/src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs index 6ef8a98fae..508045dccb 100644 --- a/src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs +++ b/src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs @@ -22,7 +22,6 @@ using XamlX.IL; namespace Avalonia.Build.Tasks { - public static partial class XamlCompilerTaskExecutor { static bool CheckXamlName(IResource r) => r.Name.ToLowerInvariant().EndsWith(".xaml") @@ -99,7 +98,8 @@ namespace Avalonia.Build.Tasks XamlXmlnsMappings.Resolve(typeSystem, xamlLanguage), AvaloniaXamlIlLanguage.CustomValueConverter, new XamlIlClrPropertyInfoEmitter(typeSystem.CreateTypeBuilder(clrPropertiesDef)), - new XamlIlPropertyInfoAccessorFactoryEmitter(typeSystem.CreateTypeBuilder(indexerAccessorClosure))); + new XamlIlPropertyInfoAccessorFactoryEmitter(typeSystem.CreateTypeBuilder(indexerAccessorClosure)), + new DeterministicIdGenerator()); var contextDef = new TypeDefinition("CompiledAvaloniaXaml", "XamlIlContext", diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlCompilerConfiguration.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlCompilerConfiguration.cs index 0c0dcb1634..f6f47dce0d 100644 --- a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlCompilerConfiguration.cs +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlCompilerConfiguration.cs @@ -14,8 +14,9 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions XamlXmlnsMappings xmlnsMappings, XamlValueConverter customValueConverter, XamlIlClrPropertyInfoEmitter clrPropertyEmitter, - XamlIlPropertyInfoAccessorFactoryEmitter accessorFactoryEmitter) - : base(typeSystem, defaultAssembly, typeMappings, xmlnsMappings, customValueConverter) + XamlIlPropertyInfoAccessorFactoryEmitter accessorFactoryEmitter, + IXamlIdentifierGenerator identifierGenerator = null) + : base(typeSystem, defaultAssembly, typeMappings, xmlnsMappings, customValueConverter, identifierGenerator) { ClrPropertyEmitter = clrPropertyEmitter; AccessorFactoryEmitter = accessorFactoryEmitter; From 077b2cbfd15b93b10ae87e7be1f71de78f99a5b3 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sun, 4 Apr 2021 14:00:24 +0800 Subject: [PATCH 50/72] address review --- .../Rendering/SceneGraph/DeferredDrawingContextImpl.cs | 4 ++-- src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs index d4564c9f29..f4c350eead 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs +++ b/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs @@ -257,7 +257,7 @@ namespace Avalonia.Rendering.SceneGraph /// public void PopBitmapBlendMode() { - var next = NextDrawAs(); + var next = NextDrawAs(); if (next == null || !next.Item.Equals(null)) { @@ -377,7 +377,7 @@ namespace Avalonia.Rendering.SceneGraph /// public void PushBitmapBlendMode(BitmapBlendingMode blendingMode) { - var next = NextDrawAs(); + var next = NextDrawAs(); if (next == null || !next.Item.Equals(blendingMode)) { diff --git a/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs b/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs index efe581ae0d..af35934785 100644 --- a/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs +++ b/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs @@ -559,12 +559,12 @@ namespace Avalonia.Direct2D1.Media public void PushBitmapBlendMode(BitmapBlendingMode blendingMode) { - // Stubs for now + // TODO: Stubs for now } public void PopBitmapBlendMode() { - // Stubs for now + // TODO: Stubs for now } public void PushOpacityMask(IBrush mask, Rect bounds) From ae034cf212583b97fa89c4350f281096fa2de8b6 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sun, 4 Apr 2021 14:03:32 +0800 Subject: [PATCH 51/72] address review --- src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs | 3 +-- src/Avalonia.Visuals/Platform/IGeometryImpl.cs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs b/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs index e2fefffecc..8c9c17770e 100644 --- a/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs +++ b/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs @@ -30,7 +30,6 @@ namespace Avalonia.Platform /// The rect in the image to draw. /// The rect in the output to draw to. /// The bitmap interpolation mode. - /// The bitmap blending mode. void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode = BitmapInterpolationMode.Default); /// @@ -153,7 +152,7 @@ namespace Avalonia.Platform /// /// Pushes an bitmap blending value. /// - /// The opacity. + /// The bitmap blending mode. void PushBitmapBlendMode(BitmapBlendingMode blendingMode); /// diff --git a/src/Avalonia.Visuals/Platform/IGeometryImpl.cs b/src/Avalonia.Visuals/Platform/IGeometryImpl.cs index 9dfaab9575..2a79202e70 100644 --- a/src/Avalonia.Visuals/Platform/IGeometryImpl.cs +++ b/src/Avalonia.Visuals/Platform/IGeometryImpl.cs @@ -85,6 +85,6 @@ namespace Avalonia.Platform /// If ture, the resulting snipped path will start with a BeginFigure call. /// The resulting snipped path. /// If the snipping operation is successful. - bool TryGetSegment (double startDistance, double stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry); + bool TryGetSegment(double startDistance, double stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry); } } From 8652792563c8c0bd971f3e36c78ad43b66103d31 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sun, 4 Apr 2021 14:04:07 +0800 Subject: [PATCH 52/72] address review --- .../Rendering/SceneGraph/BitmapBlendModeNode.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/BitmapBlendModeNode.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/BitmapBlendModeNode.cs index b486b5060a..346a5941d5 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/BitmapBlendModeNode.cs +++ b/src/Avalonia.Visuals/Rendering/SceneGraph/BitmapBlendModeNode.cs @@ -12,7 +12,7 @@ namespace Avalonia.Rendering.SceneGraph /// Initializes a new instance of the class that represents an /// push. /// - /// The to push. + /// The to push. public BitmapBlendModeNode(BitmapBlendingMode bitmapBlend) { BlendingMode = bitmapBlend; From cdb16d31611e0899c82434281f4978c27c9a29e6 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sun, 4 Apr 2021 14:04:26 +0800 Subject: [PATCH 53/72] address review --- .../Rendering/SceneGraph/DeferredDrawingContextImpl.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs index f4c350eead..ec162e3e2a 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs +++ b/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs @@ -178,8 +178,7 @@ namespace Avalonia.Rendering.SceneGraph ++_drawOperationindex; } } - - + public void Custom(ICustomDrawOperation custom) { var next = NextDrawAs(); From 64b939bee84ae923d2d3baf3a01f8ab825a15a36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Neves?= Date: Mon, 5 Apr 2021 12:41:51 +0100 Subject: [PATCH 54/72] Show and hide native control if visibility of any of its ancestors changes --- src/Avalonia.Controls/NativeControlHost.cs | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/Avalonia.Controls/NativeControlHost.cs b/src/Avalonia.Controls/NativeControlHost.cs index 64414b1f47..c2fe1bb691 100644 --- a/src/Avalonia.Controls/NativeControlHost.cs +++ b/src/Avalonia.Controls/NativeControlHost.cs @@ -16,30 +16,16 @@ namespace Avalonia.Controls private bool _queuedForDestruction; private bool _queuedForMoveResize; private readonly List _propertyChangedSubscriptions = new List(); - private readonly EventHandler _propertyChangedHandler; - static NativeControlHost() - { - IsVisibleProperty.Changed.AddClassHandler(OnVisibleChanged); - } - - public NativeControlHost() - { - _propertyChangedHandler = PropertyChangedHandler; - } - - private static void OnVisibleChanged(NativeControlHost host, AvaloniaPropertyChangedEventArgs arg2) - => host.UpdateHost(); protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) { _currentRoot = e.Root as TopLevel; var visual = (IVisual)this; - while (visual != _currentRoot) + while (visual != null) { - if (visual is Visual v) { - v.PropertyChanged += _propertyChangedHandler; + v.PropertyChanged += PropertyChangedHandler; _propertyChangedSubscriptions.Add(v); } @@ -51,7 +37,7 @@ namespace Avalonia.Controls private void PropertyChangedHandler(object sender, AvaloniaPropertyChangedEventArgs e) { - if (e.IsEffectiveValueChange && e.Property == BoundsProperty) + if (e.IsEffectiveValueChange && (e.Property == BoundsProperty || e.Property == IsVisibleProperty)) EnqueueForMoveResize(); } @@ -61,7 +47,7 @@ namespace Avalonia.Controls if (_propertyChangedSubscriptions != null) { foreach (var v in _propertyChangedSubscriptions) - v.PropertyChanged -= _propertyChangedHandler; + v.PropertyChanged -= PropertyChangedHandler; _propertyChangedSubscriptions.Clear(); } UpdateHost(); From 79665bfc742a85a76c9ba3db6ff3242e3c67393b Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 5 Apr 2021 20:42:23 +0100 Subject: [PATCH 55/72] maintain the client size when switching between extended and non extended client areas. Previously the client area would grow to fill the window. --- src/Windows/Avalonia.Win32/WindowImpl.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index a42dd5fc07..feffa03d15 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.cs @@ -883,20 +883,19 @@ namespace Avalonia.Win32 _isClientAreaExtended = false; return; } - - GetWindowRect(_hwnd, out var rcClient); + GetClientRect(_hwnd, out var rcClient); + GetWindowRect(_hwnd, out var rcWindow); // Inform the application of the frame change. SetWindowPos(_hwnd, - IntPtr.Zero, - rcClient.left, rcClient.top, - rcClient.Width, rcClient.Height, - SetWindowPosFlags.SWP_FRAMECHANGED); - + IntPtr.Zero, + rcWindow.left, rcWindow.top, + rcClient.Width, rcClient.Height, + SetWindowPosFlags.SWP_FRAMECHANGED); + if (_isClientAreaExtended && WindowState != WindowState.FullScreen) { var margins = UpdateExtendMargins(); - DwmExtendFrameIntoClientArea(_hwnd, ref margins); } else @@ -906,6 +905,8 @@ namespace Avalonia.Win32 _offScreenMargin = new Thickness(); _extendedMargins = new Thickness(); + + Resize(new Size(rcWindow.Width, rcWindow.Height)); } if(!_isClientAreaExtended || (_extendChromeHints.HasFlagCustom(ExtendClientAreaChromeHints.SystemChrome) && From 9c192f0e3784c3d1262ea98a7622d4564292a56d Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 5 Apr 2021 20:46:37 +0100 Subject: [PATCH 56/72] whitespace. --- src/Windows/Avalonia.Win32/WindowImpl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index feffa03d15..48baf00177 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.cs @@ -892,7 +892,7 @@ namespace Avalonia.Win32 rcWindow.left, rcWindow.top, rcClient.Width, rcClient.Height, SetWindowPosFlags.SWP_FRAMECHANGED); - + if (_isClientAreaExtended && WindowState != WindowState.FullScreen) { var margins = UpdateExtendMargins(); From 2de40fafd2dc235a55c093a70fec46e0aa912940 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 5 Apr 2021 20:47:28 +0100 Subject: [PATCH 57/72] whitespace. --- src/Windows/Avalonia.Win32/WindowImpl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index 48baf00177..b87abdd5ed 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.cs @@ -892,7 +892,7 @@ namespace Avalonia.Win32 rcWindow.left, rcWindow.top, rcClient.Width, rcClient.Height, SetWindowPosFlags.SWP_FRAMECHANGED); - + if (_isClientAreaExtended && WindowState != WindowState.FullScreen) { var margins = UpdateExtendMargins(); From a1d653188120e22a461f1b0d6d4fb0dbe52418f5 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 6 Apr 2021 14:09:25 +0200 Subject: [PATCH 58/72] Use existing OffscreenParentWindow to hide taskbar icon. --- src/Windows/Avalonia.Win32/WindowImpl.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index 2f4183b8fc..40874abe33 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.cs @@ -85,7 +85,7 @@ namespace Avalonia.Win32 private ExtendClientAreaChromeHints _extendChromeHints = ExtendClientAreaChromeHints.Default; private bool _isCloseRequested; private bool _shown; - private WindowImpl _hiddenWindow; + private bool _hiddenWindowIsParent; public WindowImpl() { @@ -527,7 +527,6 @@ namespace Avalonia.Win32 } _framebuffer.Dispose(); - _hiddenWindow?.Dispose(); } public void Invalidate(Rect rect) @@ -757,11 +756,6 @@ namespace Avalonia.Win32 } } - private WindowImpl GetOrCreateHiddenWindow() - { - return _hiddenWindow ??= new WindowImpl(); - } - private void CreateDropTarget() { var odt = new OleDropTarget(this, _owner); @@ -1102,7 +1096,7 @@ namespace Avalonia.Win32 { exStyle |= WindowStyles.WS_EX_APPWINDOW; - if (_hiddenWindow is object && _parent == _hiddenWindow) + if (_hiddenWindowIsParent) { // Can't enable the taskbar icon by clearing the parent window unless the window // is hidden. Hide the window and show it again with the same activation state @@ -1118,13 +1112,15 @@ namespace Avalonia.Win32 if (shown) Show(activated); } - } else { // To hide a non-owned window's taskbar icon we need to parent it to a hidden window. if (_parent is null) - SetParent(GetOrCreateHiddenWindow()); + { + SetWindowLongPtr(_hwnd, (int)WindowLongParam.GWL_HWNDPARENT, OffscreenParentWindow.Handle); + _hiddenWindowIsParent = true; + } exStyle &= ~WindowStyles.WS_EX_APPWINDOW; } From 1b681688f78a9280378f4968671bedd56b7c09d5 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Tue, 6 Apr 2021 14:30:50 +0100 Subject: [PATCH 59/72] take into account render scaling. --- src/Windows/Avalonia.Win32/WindowImpl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index b87abdd5ed..3e1c8238b3 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.cs @@ -906,7 +906,7 @@ namespace Avalonia.Win32 _offScreenMargin = new Thickness(); _extendedMargins = new Thickness(); - Resize(new Size(rcWindow.Width, rcWindow.Height)); + Resize(new Size(rcWindow.Width/ RenderScaling, rcWindow.Height / RenderScaling)); } if(!_isClientAreaExtended || (_extendChromeHints.HasFlagCustom(ExtendClientAreaChromeHints.SystemChrome) && From 60a0ec9a3a3a7247e8ac1ad33cede8a5d2cda757 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Tue, 6 Apr 2021 15:17:22 +0100 Subject: [PATCH 60/72] take into account the extended mode when Resize is called. --- src/Windows/Avalonia.Win32/WindowImpl.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index 3e1c8238b3..b68203cb5a 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.cs @@ -483,8 +483,8 @@ namespace Avalonia.Win32 IntPtr.Zero, 0, 0, - requestedClientWidth + (windowRect.Width - clientRect.Width), - requestedClientHeight + (windowRect.Height - clientRect.Height), + requestedClientWidth + (_isClientAreaExtended ? 0 : windowRect.Width - clientRect.Width), + requestedClientHeight + (_isClientAreaExtended ? 0 : windowRect.Height - clientRect.Height), SetWindowPosFlags.SWP_RESIZE); } } From d1028cd3b862172331251175e5bdb17da338ab81 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Tue, 6 Apr 2021 16:20:14 +0100 Subject: [PATCH 61/72] get rid of dodgy logo... sorry --- readme.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/readme.md b/readme.md index f73bdffaeb..67b706f428 100644 --- a/readme.md +++ b/readme.md @@ -2,8 +2,6 @@
[![NuGet](https://img.shields.io/nuget/v/Avalonia.svg)](https://www.nuget.org/packages/Avalonia) [![downloads](https://img.shields.io/nuget/dt/avalonia)](https://www.nuget.org/packages/Avalonia) [![MyGet](https://img.shields.io/myget/avalonia-ci/vpre/Avalonia.svg?label=myget)](https://www.myget.org/gallery/avalonia-ci) ![Size](https://img.shields.io/github/repo-size/avaloniaui/avalonia.svg) -Avalonia - ## 📖 About AvaloniaUI Avalonia is a cross-platform XAML-based UI framework providing a flexible styling system and supporting a wide range of Operating Systems such as Windows via .NET Framework and .NET Core, Linux via Xorg, macOS. Avalonia is ready for **General-Purpose Desktop App Development**. However, there may be some bugs and breaking changes as we continue along into this project's development. From 81fc978d642884141f0f48a2d860d9f15769bea0 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 8 Apr 2021 12:36:32 +0200 Subject: [PATCH 62/72] Use hidden window when clearing parent... ...if `ShowInTaskbar == false`. --- src/Windows/Avalonia.Win32/WindowImpl.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index 0fbd58eeb9..d1dfb4a675 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.cs @@ -581,8 +581,15 @@ namespace Avalonia.Win32 public void SetParent(IWindowImpl parent) { - _parent = (WindowImpl)parent; - SetWindowLongPtr(_hwnd, (int)WindowLongParam.GWL_HWNDPARENT, _parent?._hwnd ?? IntPtr.Zero); + var parentHwnd = ((WindowImpl)parent)?._hwnd ?? IntPtr.Zero; + + if (parentHwnd == IntPtr.Zero && !_windowProperties.ShowInTaskbar) + { + parentHwnd = OffscreenParentWindow.Handle; + _hiddenWindowIsParent = true; + } + + SetWindowLongPtr(_hwnd, (int)WindowLongParam.GWL_HWNDPARENT, parentHwnd); } public void SetEnabled(bool enable) => EnableWindow(_hwnd, enable); @@ -1108,6 +1115,7 @@ namespace Avalonia.Win32 if (shown) Hide(); + _hiddenWindowIsParent = false; SetParent(null); if (shown) From c71b0e0f292113e841457044a50e1d2c430159e6 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 8 Apr 2021 12:43:53 +0200 Subject: [PATCH 63/72] Make showing the window use correct offscreen parent. --- src/Windows/Avalonia.Win32/WindowImpl.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index d1dfb4a675..f3f8618cc9 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.cs @@ -572,8 +572,7 @@ namespace Avalonia.Win32 public virtual void Show(bool activate) { - SetWindowLongPtr(_hwnd, (int)WindowLongParam.GWL_HWNDPARENT, _parent != null ? _parent._hwnd : IntPtr.Zero); - + SetParent(_parent); ShowWindow(_showWindowState, activate); } From 32e6ca7e2aafa76671725e3cf7c51158db7e99a9 Mon Sep 17 00:00:00 2001 From: SutandoTsukai181 <52977072+SutandoTsukai181@users.noreply.github.com> Date: Thu, 8 Apr 2021 17:11:23 +0300 Subject: [PATCH 64/72] Add missing XButtons 1 and 2 to MouseButton --- src/Avalonia.Input/PointerEventArgs.cs | 4 +++- src/Avalonia.Input/PointerPoint.cs | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Input/PointerEventArgs.cs b/src/Avalonia.Input/PointerEventArgs.cs index 451f80b1df..ba39f7ca8e 100644 --- a/src/Avalonia.Input/PointerEventArgs.cs +++ b/src/Avalonia.Input/PointerEventArgs.cs @@ -107,7 +107,9 @@ namespace Avalonia.Input None, Left, Right, - Middle + Middle, + XButton1, + XButton2 } public class PointerPressedEventArgs : PointerEventArgs diff --git a/src/Avalonia.Input/PointerPoint.cs b/src/Avalonia.Input/PointerPoint.cs index a316e0d964..ebc64fa2f9 100644 --- a/src/Avalonia.Input/PointerPoint.cs +++ b/src/Avalonia.Input/PointerPoint.cs @@ -90,6 +90,10 @@ namespace Avalonia.Input return MouseButton.Middle; if (kind == PointerUpdateKind.RightButtonPressed || kind == PointerUpdateKind.RightButtonReleased) return MouseButton.Right; + if (kind == PointerUpdateKind.XButton1Pressed || kind == PointerUpdateKind.XButton1Released) + return MouseButton.XButton1; + if (kind == PointerUpdateKind.XButton2Pressed || kind == PointerUpdateKind.XButton2Released) + return MouseButton.XButton2; return MouseButton.None; } } From 7485b3a8cfa7ac628625875639548322874b5f8c Mon Sep 17 00:00:00 2001 From: Jumar Macato <16554748+jmacato@users.noreply.github.com> Date: Fri, 9 Apr 2021 17:42:02 +0800 Subject: [PATCH 65/72] Update src/Avalonia.Visuals/Rendering/SceneGraph/BitmapBlendModeNode.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dariusz Komosiński --- .../Rendering/SceneGraph/BitmapBlendModeNode.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/BitmapBlendModeNode.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/BitmapBlendModeNode.cs index 346a5941d5..0a5c1f8db6 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/BitmapBlendModeNode.cs +++ b/src/Avalonia.Visuals/Rendering/SceneGraph/BitmapBlendModeNode.cs @@ -4,7 +4,7 @@ using Avalonia.Visuals.Media.Imaging; namespace Avalonia.Rendering.SceneGraph { /// - /// A node in the scene graph which represents an opacity push or pop. + /// A node in the scene graph which represents an bitmap blending mode push or pop. /// internal class BitmapBlendModeNode : IDrawOperation { From ef903d7ed2f0afd368a08ff38ab8557636ef2efb Mon Sep 17 00:00:00 2001 From: Jumar Macato <16554748+jmacato@users.noreply.github.com> Date: Fri, 9 Apr 2021 17:42:26 +0800 Subject: [PATCH 66/72] Update src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dariusz Komosiński --- src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs b/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs index 8c9c17770e..39d4066e55 100644 --- a/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs +++ b/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs @@ -150,7 +150,7 @@ namespace Avalonia.Platform void PopGeometryClip(); /// - /// Pushes an bitmap blending value. + /// Pushes a bitmap blending value. /// /// The bitmap blending mode. void PushBitmapBlendMode(BitmapBlendingMode blendingMode); From e191d22d96c9e1cd2aaf56499287e2bc755a840d Mon Sep 17 00:00:00 2001 From: Jumar Macato <16554748+jmacato@users.noreply.github.com> Date: Fri, 9 Apr 2021 18:18:49 +0800 Subject: [PATCH 67/72] Update src/Avalonia.Visuals/Platform/IGeometryImpl.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dariusz Komosiński --- src/Avalonia.Visuals/Platform/IGeometryImpl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Visuals/Platform/IGeometryImpl.cs b/src/Avalonia.Visuals/Platform/IGeometryImpl.cs index 2a79202e70..79e125c5cb 100644 --- a/src/Avalonia.Visuals/Platform/IGeometryImpl.cs +++ b/src/Avalonia.Visuals/Platform/IGeometryImpl.cs @@ -55,7 +55,7 @@ namespace Avalonia.Platform ITransformedGeometryImpl WithTransform(Matrix transform); /// - /// Attempts to get the corresponding point from the + /// Attempts to get the corresponding point at the /// specified distance /// /// The contour distance to get from. From 1ab777c96188a1df486ea96bcbee192374772fbc Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Fri, 9 Apr 2021 18:22:19 +0800 Subject: [PATCH 68/72] address review --- .../RenderDemo/Pages/PathMeasurementPage.cs | 6 ++- .../SceneGraph/DeferredDrawingContextImpl.cs | 2 +- src/Skia/Avalonia.Skia/GeometryImpl.cs | 43 ++++++++----------- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/samples/RenderDemo/Pages/PathMeasurementPage.cs b/samples/RenderDemo/Pages/PathMeasurementPage.cs index 6373e39ac5..212377deae 100644 --- a/samples/RenderDemo/Pages/PathMeasurementPage.cs +++ b/samples/RenderDemo/Pages/PathMeasurementPage.cs @@ -15,13 +15,17 @@ namespace RenderDemo.Pages { public class PathMeasurementPage : Control { + static PathMeasurementPage() + { + AffectsRender(BoundsProperty); + } + private RenderTargetBitmap _bitmap; protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e) { _bitmap = new RenderTargetBitmap(new PixelSize(500, 500), new Vector(96, 96)); base.OnAttachedToLogicalTree(e); - AffectsRender(BoundsProperty); } protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e) diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs index ec162e3e2a..e6092574c5 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs +++ b/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs @@ -178,7 +178,7 @@ namespace Avalonia.Rendering.SceneGraph ++_drawOperationindex; } } - + public void Custom(ICustomDrawOperation custom) { var next = NextDrawAs(); diff --git a/src/Skia/Avalonia.Skia/GeometryImpl.cs b/src/Skia/Avalonia.Skia/GeometryImpl.cs index e5794c1a64..23fc5be20a 100644 --- a/src/Skia/Avalonia.Skia/GeometryImpl.cs +++ b/src/Skia/Avalonia.Skia/GeometryImpl.cs @@ -11,7 +11,20 @@ namespace Avalonia.Skia internal abstract class GeometryImpl : IGeometryImpl { private PathCache _pathCache; - private SKPathMeasure _pathMeasureCache; + private SKPathMeasure _pathMeasureCachex; + + private SKPathMeasure CachedPathMeasure + { + get + { + if (_pathMeasureCachex is null) + { + _pathMeasureCachex = new SKPathMeasure(EffectivePath); + } + + return _pathMeasureCachex; + } + } /// public abstract Rect Bounds { get; } @@ -24,12 +37,7 @@ namespace Avalonia.Skia if (EffectivePath is null) return 0; - if (_pathMeasureCache is null) - { - _pathMeasureCache = new SKPathMeasure(EffectivePath); - } - - return (double)_pathMeasureCache?.Length; + return (double)CachedPathMeasure?.Length; } } @@ -132,12 +140,7 @@ namespace Avalonia.Skia return false; } - if (_pathMeasureCache is null) - { - _pathMeasureCache = new SKPathMeasure(EffectivePath); - } - - var res = _pathMeasureCache.GetPosition((float)distance, out var skPoint); + var res = CachedPathMeasure.GetPosition((float)distance, out var skPoint); point = new Point(skPoint.X, skPoint.Y); return res; } @@ -152,12 +155,7 @@ namespace Avalonia.Skia return false; } - if (_pathMeasureCache is null) - { - _pathMeasureCache = new SKPathMeasure(EffectivePath); - } - - var res = _pathMeasureCache.GetPositionAndTangent((float)distance, out var skPoint, out var skTangent); + var res = CachedPathMeasure.GetPositionAndTangent((float)distance, out var skPoint, out var skTangent); point = new Point(skPoint.X, skPoint.Y); tangent = new Point(skTangent.X, skTangent.Y); return res; @@ -172,16 +170,11 @@ namespace Avalonia.Skia return false; } - if (_pathMeasureCache is null) - { - _pathMeasureCache = new SKPathMeasure(EffectivePath); - } - segmentGeometry = null; var _skPathSegment = new SKPath(); - var res = _pathMeasureCache.GetSegment((float)startDistance, (float)stopDistance, _skPathSegment, startOnBeginFigure); + var res = CachedPathMeasure.GetSegment((float)startDistance, (float)stopDistance, _skPathSegment, startOnBeginFigure); if (res) { From 2da760005ca9c452464f7926712fd1bc2e70a5e9 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sat, 10 Apr 2021 14:44:12 +0800 Subject: [PATCH 69/72] address review --- src/Skia/Avalonia.Skia/GeometryImpl.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Skia/Avalonia.Skia/GeometryImpl.cs b/src/Skia/Avalonia.Skia/GeometryImpl.cs index 23fc5be20a..19dbcf9713 100644 --- a/src/Skia/Avalonia.Skia/GeometryImpl.cs +++ b/src/Skia/Avalonia.Skia/GeometryImpl.cs @@ -11,18 +11,18 @@ namespace Avalonia.Skia internal abstract class GeometryImpl : IGeometryImpl { private PathCache _pathCache; - private SKPathMeasure _pathMeasureCachex; + private SKPathMeasure _pathMeasureCache; private SKPathMeasure CachedPathMeasure { get { - if (_pathMeasureCachex is null) + if (_pathMeasureCache is null) { - _pathMeasureCachex = new SKPathMeasure(EffectivePath); + _pathMeasureCache = new SKPathMeasure(EffectivePath); } - return _pathMeasureCachex; + return _pathMeasureCache; } } From bcca8d86161b0fc50f6c808b4d7f07d831a1fa93 Mon Sep 17 00:00:00 2001 From: Andrey Ermilkin Date: Sun, 11 Apr 2021 16:29:37 -0400 Subject: [PATCH 70/72] Scaling Vector is not commutative --- tests/Avalonia.Visuals.UnitTests/VectorTests.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/Avalonia.Visuals.UnitTests/VectorTests.cs b/tests/Avalonia.Visuals.UnitTests/VectorTests.cs index 0e72cd7c7f..f9a9e59436 100644 --- a/tests/Avalonia.Visuals.UnitTests/VectorTests.cs +++ b/tests/Avalonia.Visuals.UnitTests/VectorTests.cs @@ -105,5 +105,15 @@ namespace Avalonia.Visuals.UnitTests Assert.Equal(expected, Vector.Multiply(vector, 2)); } + + [Fact] + public void Scale_Vector_Should_Be_Commutative() + { + var vector = new Vector(10, 2); + + var expected = vector * 2; + + Assert.Equal(expected, 2 * vector); + } } } From 323d975dad07a59fa286e75cc4d5cd05f5352d82 Mon Sep 17 00:00:00 2001 From: Andrey Ermilkin Date: Sun, 11 Apr 2021 16:34:12 -0400 Subject: [PATCH 71/72] Fixes Vector test for scale commutativeness. --- src/Avalonia.Visuals/Vector.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Avalonia.Visuals/Vector.cs b/src/Avalonia.Visuals/Vector.cs index 1b9f5c67d5..79c4202be4 100644 --- a/src/Avalonia.Visuals/Vector.cs +++ b/src/Avalonia.Visuals/Vector.cs @@ -82,6 +82,15 @@ namespace Avalonia public static Vector operator *(Vector vector, double scale) => Multiply(vector, scale); + /// + /// Scales a vector. + /// + /// The vector. + /// The scaling factor. + /// The scaled vector. + public static Vector operator *(double scale, Vector vector) + => Multiply(vector, scale); + /// /// Scales a vector. /// From 05496ccf349643b087586f34cf8d62bad035b137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Komosi=C5=84ski?= Date: Mon, 12 Apr 2021 18:46:09 +0200 Subject: [PATCH 72/72] Fix owned windows and dialogs not having a parent. --- src/Windows/Avalonia.Win32/WindowImpl.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index f3f8618cc9..22d6789242 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.cs @@ -580,7 +580,9 @@ namespace Avalonia.Win32 public void SetParent(IWindowImpl parent) { - var parentHwnd = ((WindowImpl)parent)?._hwnd ?? IntPtr.Zero; + _parent = (WindowImpl)parent; + + var parentHwnd = _parent?._hwnd ?? IntPtr.Zero; if (parentHwnd == IntPtr.Zero && !_windowProperties.ShowInTaskbar) {