667 changed files with 6258 additions and 5636 deletions
@ -0,0 +1,5 @@ |
|||
<ProjectConfiguration> |
|||
<Settings> |
|||
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> |
|||
</Settings> |
|||
</ProjectConfiguration> |
|||
@ -0,0 +1,5 @@ |
|||
<ProjectConfiguration> |
|||
<Settings> |
|||
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> |
|||
</Settings> |
|||
</ProjectConfiguration> |
|||
@ -0,0 +1,5 @@ |
|||
<ProjectConfiguration> |
|||
<Settings> |
|||
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> |
|||
</Settings> |
|||
</ProjectConfiguration> |
|||
@ -1,3 +1,4 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<Import Project="$(MSBuildThisFileDirectory)\AvaloniaBuildTasks.targets"/> |
|||
<Import Project="$(MSBuildThisFileDirectory)\AvaloniaPrivateApis.targets" /> |
|||
</Project> |
|||
|
|||
@ -0,0 +1,26 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<Target Name="RemoveAvaloniaRefAssemblies" AfterTargets="ResolveTargetingPackAssets" Condition="'$(AvaloniaAccessUnstablePrivateApis.ToLowerInvariant())'=='true'"> |
|||
<ItemGroup> |
|||
<ReferencesToRemove Include="@(Reference)" Condition="'%(Reference.NuGetPackageId)' == 'Avalonia'" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Reference Remove="@(ReferencesToRemove)" /> |
|||
</ItemGroup> |
|||
</Target> |
|||
<Target Name="PreventPackingAvaloniaUnstableApis" BeforeTargets="Pack"> |
|||
<Error Condition="'$(IsPackable.ToLowerInvariant())' == 'true' and '$(AvaloniaAccessUnstablePrivateApis.ToLowerInvariant())' == 'true' and '$(Avalonia_I_Want_To_Use_Private_Apis_In_Nuget_Package_And_Promise_To_Pin_The_Exact_Avalonia_Version_In_Package_Dependency)' != 'true'" |
|||
Text="It seems that you are using private APIs in a nuget package, please follow this guide https://github.com/AvaloniaUI/Avalonia/wiki/Using-private-apis-in-nuget-packages" /> |
|||
</Target> |
|||
<Target Name="AddReferencePathsToRealAvaloniaAssemblies" BeforeTargets="CoreCompile" Condition="'$(AvaloniaAccessUnstablePrivateApis.ToLowerInvariant())'=='true'"> |
|||
<PropertyGroup> |
|||
<AvaloniaUnstableApiFrameworkToUse>net6.0</AvaloniaUnstableApiFrameworkToUse> |
|||
<AvaloniaUnstableApiFrameworkToUse Condition="$(TargetFramework.StartsWith('net4')) == 'true' or $(TargetFramework.StartsWith('net5')) == 'true' or $(TargetFramework.StartsWith('netsta')) == 'true' or $(TargetFramework.StartsWith('netcore')) == 'true'">netstandard2.0</AvaloniaUnstableApiFrameworkToUse> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<Reference Include="$(MSBuildThisFileDirectory)/../lib/$(AvaloniaUnstableApiFrameworkToUse)/*.dll"/> |
|||
<ReferencePath Include="$(MSBuildThisFileDirectory)/../lib/$(AvaloniaUnstableApiFrameworkToUse)/*.dll"/> |
|||
<ReferencePathWithRefAssemblies Include="$(MSBuildThisFileDirectory)/../lib/$(AvaloniaUnstableApiFrameworkToUse)/*.dll"/> |
|||
</ItemGroup> |
|||
<Warning Text="AvaloniaAccessUnstablePrivateApis is Enabled: This means you are using unstable internal APIs, and your code may be depending on APIs which may change or be removed in future versions of Avalonia. Set AvaloniaAccessUnstablePrivateApis to 'False' to disable this warning." /> |
|||
</Target> |
|||
</Project> |
|||
@ -1,35 +1,14 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel; |
|||
using System.Data; |
|||
using System.Drawing; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using System.Windows.Forms; |
|||
using Avalonia.Controls; |
|||
using Avalonia.Rendering; |
|||
using Avalonia.VisualTree; |
|||
using System.Windows.Forms; |
|||
using ControlCatalog; |
|||
|
|||
namespace WindowsInteropTest |
|||
{ |
|||
public partial class EmbedToWinFormsDemo : Form |
|||
{ |
|||
private readonly IRenderer _renderer; |
|||
|
|||
public EmbedToWinFormsDemo() |
|||
{ |
|||
InitializeComponent(); |
|||
avaloniaHost.Content = new MainView(); |
|||
_renderer = ((TopLevel)avaloniaHost.Content.GetVisualRoot()).Renderer; |
|||
_renderer.Start(); |
|||
} |
|||
|
|||
protected override void OnClosed(EventArgs e) |
|||
{ |
|||
_renderer.Stop(); |
|||
base.OnClosed(e); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,33 +0,0 @@ |
|||
<Window x:Class="WindowsInteropTest.EmbedToWpfDemo" |
|||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
xmlns:av="clr-namespace:Avalonia.Controls;assembly=Avalonia.Controls" |
|||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
|||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
|||
xmlns:local="clr-namespace:WindowsInteropTest" |
|||
xmlns:embedding="clr-namespace:Avalonia.Win32.Embedding;assembly=Avalonia.Win32" |
|||
xmlns:wpf="clr-namespace:Avalonia.Win32.Interop.Wpf;assembly=Avalonia.Win32.Interop" |
|||
mc:Ignorable="d" |
|||
d:DesignHeight="400" d:DesignWidth="400" MinWidth="500" MinHeight="400"> |
|||
<DockPanel> |
|||
<GroupBox DockPanel.Dock="Left" Header="WPF"> |
|||
<StackPanel> |
|||
<Slider/> |
|||
<Calendar/> |
|||
</StackPanel> |
|||
</GroupBox> |
|||
<GroupBox Header="Avalonia button" DockPanel.Dock="Bottom"> |
|||
<wpf:WpfAvaloniaHost > |
|||
<av:Button Content="Avalonia button"/> |
|||
</wpf:WpfAvaloniaHost> |
|||
</GroupBox> |
|||
<GroupBox Header="AvBtn" DockPanel.Dock="Right"> |
|||
<wpf:WpfAvaloniaHost x:Name="RightBtn"> |
|||
<av:Button Content="Avalonia button 2"/> |
|||
</wpf:WpfAvaloniaHost> |
|||
</GroupBox> |
|||
<GroupBox Header="Avalonia"> |
|||
<wpf:WpfAvaloniaHost x:Name="Host"/> |
|||
</GroupBox> |
|||
</DockPanel> |
|||
</Window> |
|||
@ -1,52 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using System.Windows.Controls; |
|||
using System.Windows.Data; |
|||
using System.Windows.Documents; |
|||
using System.Windows.Input; |
|||
using System.Windows.Media; |
|||
using System.Windows.Media.Imaging; |
|||
using System.Windows.Navigation; |
|||
using System.Windows.Shapes; |
|||
using Avalonia; |
|||
using Avalonia.Controls; |
|||
using Avalonia.Rendering; |
|||
using Avalonia.VisualTree; |
|||
using ControlCatalog; |
|||
using Window = System.Windows.Window; |
|||
|
|||
namespace WindowsInteropTest |
|||
{ |
|||
/// <summary>
|
|||
/// Interaction logic for EmbedToWpfDemo.xaml
|
|||
/// </summary>
|
|||
public partial class EmbedToWpfDemo : Window |
|||
{ |
|||
private IRenderer _renderer; |
|||
public EmbedToWpfDemo() |
|||
{ |
|||
InitializeComponent(); |
|||
var view = new MainView(); |
|||
Host.Content = view; |
|||
var tl = (TopLevel)view.GetVisualRoot(); |
|||
tl.AttachDevTools(); |
|||
_renderer = tl.Renderer; |
|||
_renderer.Start(); |
|||
var btn = (Avalonia.Controls.Button) RightBtn.Content; |
|||
btn.Click += delegate |
|||
{ |
|||
btn.Content += "!"; |
|||
}; |
|||
|
|||
} |
|||
|
|||
protected override void OnClosed(EventArgs e) |
|||
{ |
|||
_renderer.Stop(); |
|||
base.OnClosed(e); |
|||
} |
|||
} |
|||
} |
|||
@ -1,76 +0,0 @@ |
|||
namespace WindowsInteropTest |
|||
{ |
|||
partial class SelectorForm |
|||
{ |
|||
/// <summary>
|
|||
/// Required designer variable.
|
|||
/// </summary>
|
|||
private System.ComponentModel.IContainer components = null; |
|||
|
|||
/// <summary>
|
|||
/// Clean up any resources being used.
|
|||
/// </summary>
|
|||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|||
protected override void Dispose(bool disposing) |
|||
{ |
|||
if (disposing && (components != null)) |
|||
{ |
|||
components.Dispose(); |
|||
} |
|||
base.Dispose(disposing); |
|||
} |
|||
|
|||
#region Windows Form Designer generated code
|
|||
|
|||
/// <summary>
|
|||
/// Required method for Designer support - do not modify
|
|||
/// the contents of this method with the code editor.
|
|||
/// </summary>
|
|||
private void InitializeComponent() |
|||
{ |
|||
this.btnEmbedToWinForms = new System.Windows.Forms.Button(); |
|||
this.btnEmbedToWpf = new System.Windows.Forms.Button(); |
|||
this.SuspendLayout(); |
|||
//
|
|||
// btnEmbedToWinForms
|
|||
//
|
|||
this.btnEmbedToWinForms.Location = new System.Drawing.Point(12, 12); |
|||
this.btnEmbedToWinForms.Name = "btnEmbedToWinForms"; |
|||
this.btnEmbedToWinForms.Size = new System.Drawing.Size(201, 86); |
|||
this.btnEmbedToWinForms.TabIndex = 0; |
|||
this.btnEmbedToWinForms.Text = "Embed to WinForms"; |
|||
this.btnEmbedToWinForms.UseVisualStyleBackColor = true; |
|||
this.btnEmbedToWinForms.Click += new System.EventHandler(this.btnEmbedToWinForms_Click); |
|||
//
|
|||
// btnEmbedToWpf
|
|||
//
|
|||
this.btnEmbedToWpf.Location = new System.Drawing.Point(219, 12); |
|||
this.btnEmbedToWpf.Name = "btnEmbedToWpf"; |
|||
this.btnEmbedToWpf.Size = new System.Drawing.Size(201, 86); |
|||
this.btnEmbedToWpf.TabIndex = 1; |
|||
this.btnEmbedToWpf.Text = "Embed to WPF"; |
|||
this.btnEmbedToWpf.UseVisualStyleBackColor = true; |
|||
this.btnEmbedToWpf.Click += new System.EventHandler(this.btnEmbedToWpf_Click); |
|||
//
|
|||
// SelectorForm
|
|||
//
|
|||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); |
|||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; |
|||
this.ClientSize = new System.Drawing.Size(432, 284); |
|||
this.Controls.Add(this.btnEmbedToWpf); |
|||
this.Controls.Add(this.btnEmbedToWinForms); |
|||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; |
|||
this.MaximizeBox = false; |
|||
this.Name = "SelectorForm"; |
|||
this.Text = "Interop"; |
|||
this.ResumeLayout(false); |
|||
|
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
private System.Windows.Forms.Button btnEmbedToWinForms; |
|||
private System.Windows.Forms.Button btnEmbedToWpf; |
|||
} |
|||
} |
|||
|
|||
@ -1,30 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel; |
|||
using System.Data; |
|||
using System.Drawing; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using System.Windows.Forms; |
|||
|
|||
namespace WindowsInteropTest |
|||
{ |
|||
public partial class SelectorForm : Form |
|||
{ |
|||
public SelectorForm() |
|||
{ |
|||
InitializeComponent(); |
|||
} |
|||
|
|||
private void btnEmbedToWinForms_Click(object sender, EventArgs e) |
|||
{ |
|||
new EmbedToWinFormsDemo().ShowDialog(this); |
|||
} |
|||
|
|||
private void btnEmbedToWpf_Click(object sender, EventArgs e) |
|||
{ |
|||
new EmbedToWpfDemo().ShowDialog(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,120 +0,0 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<root> |
|||
<!-- |
|||
Microsoft ResX Schema |
|||
|
|||
Version 2.0 |
|||
|
|||
The primary goals of this format is to allow a simple XML format |
|||
that is mostly human readable. The generation and parsing of the |
|||
various data types are done through the TypeConverter classes |
|||
associated with the data types. |
|||
|
|||
Example: |
|||
|
|||
... ado.net/XML headers & schema ... |
|||
<resheader name="resmimetype">text/microsoft-resx</resheader> |
|||
<resheader name="version">2.0</resheader> |
|||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> |
|||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> |
|||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> |
|||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> |
|||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> |
|||
<value>[base64 mime encoded serialized .NET Framework object]</value> |
|||
</data> |
|||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> |
|||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> |
|||
<comment>This is a comment</comment> |
|||
</data> |
|||
|
|||
There are any number of "resheader" rows that contain simple |
|||
name/value pairs. |
|||
|
|||
Each data row contains a name, and value. The row also contains a |
|||
type or mimetype. Type corresponds to a .NET class that support |
|||
text/value conversion through the TypeConverter architecture. |
|||
Classes that don't support this are serialized and stored with the |
|||
mimetype set. |
|||
|
|||
The mimetype is used for serialized objects, and tells the |
|||
ResXResourceReader how to depersist the object. This is currently not |
|||
extensible. For a given mimetype the value must be set accordingly: |
|||
|
|||
Note - application/x-microsoft.net.object.binary.base64 is the format |
|||
that the ResXResourceWriter will generate, however the reader can |
|||
read any of the formats listed below. |
|||
|
|||
mimetype: application/x-microsoft.net.object.binary.base64 |
|||
value : The object must be serialized with |
|||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter |
|||
: and then encoded with base64 encoding. |
|||
|
|||
mimetype: application/x-microsoft.net.object.soap.base64 |
|||
value : The object must be serialized with |
|||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter |
|||
: and then encoded with base64 encoding. |
|||
|
|||
mimetype: application/x-microsoft.net.object.bytearray.base64 |
|||
value : The object must be serialized into a byte array |
|||
: using a System.ComponentModel.TypeConverter |
|||
: and then encoded with base64 encoding. |
|||
--> |
|||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> |
|||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> |
|||
<xsd:element name="root" msdata:IsDataSet="true"> |
|||
<xsd:complexType> |
|||
<xsd:choice maxOccurs="unbounded"> |
|||
<xsd:element name="metadata"> |
|||
<xsd:complexType> |
|||
<xsd:sequence> |
|||
<xsd:element name="value" type="xsd:string" minOccurs="0" /> |
|||
</xsd:sequence> |
|||
<xsd:attribute name="name" use="required" type="xsd:string" /> |
|||
<xsd:attribute name="type" type="xsd:string" /> |
|||
<xsd:attribute name="mimetype" type="xsd:string" /> |
|||
<xsd:attribute ref="xml:space" /> |
|||
</xsd:complexType> |
|||
</xsd:element> |
|||
<xsd:element name="assembly"> |
|||
<xsd:complexType> |
|||
<xsd:attribute name="alias" type="xsd:string" /> |
|||
<xsd:attribute name="name" type="xsd:string" /> |
|||
</xsd:complexType> |
|||
</xsd:element> |
|||
<xsd:element name="data"> |
|||
<xsd:complexType> |
|||
<xsd:sequence> |
|||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
|||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> |
|||
</xsd:sequence> |
|||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> |
|||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> |
|||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> |
|||
<xsd:attribute ref="xml:space" /> |
|||
</xsd:complexType> |
|||
</xsd:element> |
|||
<xsd:element name="resheader"> |
|||
<xsd:complexType> |
|||
<xsd:sequence> |
|||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
|||
</xsd:sequence> |
|||
<xsd:attribute name="name" type="xsd:string" use="required" /> |
|||
</xsd:complexType> |
|||
</xsd:element> |
|||
</xsd:choice> |
|||
</xsd:complexType> |
|||
</xsd:element> |
|||
</xsd:schema> |
|||
<resheader name="resmimetype"> |
|||
<value>text/microsoft-resx</value> |
|||
</resheader> |
|||
<resheader name="version"> |
|||
<value>2.0</value> |
|||
</resheader> |
|||
<resheader name="reader"> |
|||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
|||
</resheader> |
|||
<resheader name="writer"> |
|||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
|||
</resheader> |
|||
</root> |
|||
@ -1,15 +1,15 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
<PropertyGroup> |
|||
<OutputType>WinExe</OutputType> |
|||
<TargetFramework>net461</TargetFramework> |
|||
<PlatformTarget>x64</PlatformTarget> |
|||
<TargetFrameworks>net461;net6.0-windows</TargetFrameworks> |
|||
<UseWPF>true</UseWPF> |
|||
<UseWindowsForms>true</UseWindowsForms> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj" /> |
|||
<ProjectReference Include="..\..\..\src\Windows\Avalonia.Win32.Interop\Avalonia.Win32.Interop.csproj" /> |
|||
<ProjectReference Include="..\..\..\src\Skia\Avalonia.Skia\Avalonia.Skia.csproj" /> |
|||
<ProjectReference Include="..\..\..\src\Windows\Avalonia.Win32.Interoperability\Avalonia.Win32.Interoperability.csproj" /> |
|||
<ProjectReference Include="..\..\ControlCatalog\ControlCatalog.csproj" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
|
|||
@ -0,0 +1,94 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Avalonia.Animation.Animators; |
|||
using Avalonia.Media; |
|||
|
|||
namespace Avalonia.Animation; |
|||
|
|||
partial class Animation |
|||
{ |
|||
/// <summary>
|
|||
/// Sets the value of the Animator attached property for a setter.
|
|||
/// </summary>
|
|||
/// <param name="setter">The animation setter.</param>
|
|||
/// <param name="value">The property animator value.</param>
|
|||
[Obsolete("CustomAnimatorBase will be removed before 11.0, use InterpolatingAnimator<T>", true)] |
|||
public static void SetAnimator(IAnimationSetter setter, CustomAnimatorBase value) |
|||
{ |
|||
s_animators[setter] = (value.WrapperType, value.CreateWrapper); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Sets the value of the Animator attached property for a setter.
|
|||
/// </summary>
|
|||
/// <param name="setter">The animation setter.</param>
|
|||
/// <param name="value">The property animator value.</param>
|
|||
public static void SetAnimator(IAnimationSetter setter, ICustomAnimator value) |
|||
{ |
|||
s_animators[setter] = (value.WrapperType, value.CreateWrapper); |
|||
} |
|||
|
|||
private readonly static List<(Func<AvaloniaProperty, bool> Condition, Type Animator, Func<IAnimator> Factory)> |
|||
Animators = new() |
|||
{ |
|||
(prop =>(typeof(double).IsAssignableFrom(prop.PropertyType) && typeof(Transform).IsAssignableFrom(prop.OwnerType)), |
|||
typeof(TransformAnimator), () => new TransformAnimator()), |
|||
(prop => typeof(bool).IsAssignableFrom(prop.PropertyType), typeof(BoolAnimator), () => new BoolAnimator()), |
|||
(prop => typeof(byte).IsAssignableFrom(prop.PropertyType), typeof(ByteAnimator), () => new ByteAnimator()), |
|||
(prop => typeof(Int16).IsAssignableFrom(prop.PropertyType), typeof(Int16Animator), () => new Int16Animator()), |
|||
(prop => typeof(Int32).IsAssignableFrom(prop.PropertyType), typeof(Int32Animator), () => new Int32Animator()), |
|||
(prop => typeof(Int64).IsAssignableFrom(prop.PropertyType), typeof(Int64Animator), () => new Int64Animator()), |
|||
(prop => typeof(UInt16).IsAssignableFrom(prop.PropertyType), typeof(UInt16Animator), () => new UInt16Animator()), |
|||
(prop => typeof(UInt32).IsAssignableFrom(prop.PropertyType), typeof(UInt32Animator), () => new UInt32Animator()), |
|||
(prop => typeof(UInt64).IsAssignableFrom(prop.PropertyType), typeof(UInt64Animator), () => new UInt64Animator()), |
|||
(prop => typeof(float).IsAssignableFrom(prop.PropertyType), typeof(FloatAnimator), () => new FloatAnimator()), |
|||
(prop => typeof(double).IsAssignableFrom(prop.PropertyType), typeof(DoubleAnimator), () => new DoubleAnimator()), |
|||
(prop => typeof(decimal).IsAssignableFrom(prop.PropertyType), typeof(DecimalAnimator), () => new DecimalAnimator()), |
|||
}; |
|||
|
|||
static Animation() |
|||
{ |
|||
RegisterAnimator<IEffect?, EffectAnimator>(); |
|||
RegisterAnimator<BoxShadow, BoxShadowAnimator>(); |
|||
RegisterAnimator<BoxShadows, BoxShadowsAnimator>(); |
|||
RegisterAnimator<IBrush?, BaseBrushAnimator>(); |
|||
RegisterAnimator<CornerRadius, CornerRadiusAnimator>(); |
|||
RegisterAnimator<Color, ColorAnimator>(); |
|||
RegisterAnimator<Vector, VectorAnimator>(); |
|||
RegisterAnimator<Point, PointAnimator>(); |
|||
RegisterAnimator<Rect, RectAnimator>(); |
|||
RegisterAnimator<RelativePoint, RelativePointAnimator>(); |
|||
RegisterAnimator<Size, SizeAnimator>(); |
|||
RegisterAnimator<Thickness, ThicknessAnimator>(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Registers a <see cref="Animator{T}"/> that can handle
|
|||
/// a value type that matches the specified condition.
|
|||
/// </summary>
|
|||
static void RegisterAnimator<T, TAnimator>() |
|||
where TAnimator : Animator<T>, new() |
|||
{ |
|||
Animators.Insert(0, |
|||
(prop => typeof(T).IsAssignableFrom(prop.PropertyType), typeof(TAnimator), () => new TAnimator())); |
|||
} |
|||
|
|||
public static void RegisterCustomAnimator<T, TAnimator>() where TAnimator : InterpolatingAnimator<T>, new() |
|||
{ |
|||
Animators.Insert(0, (prop => typeof(T).IsAssignableFrom(prop.PropertyType), |
|||
typeof(InterpolatingAnimator<T>.AnimatorWrapper), () => new TAnimator().CreateWrapper())); |
|||
} |
|||
|
|||
private static (Type Type, Func<IAnimator> Factory)? GetAnimatorType(AvaloniaProperty property) |
|||
{ |
|||
foreach (var (condition, type, factory) in Animators) |
|||
{ |
|||
if (condition(property)) |
|||
{ |
|||
return (type, factory); |
|||
} |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
} |
|||
@ -0,0 +1,58 @@ |
|||
using System; |
|||
using Avalonia.Animation.Animators; |
|||
namespace Avalonia.Animation; |
|||
|
|||
[Obsolete("This class will be removed before 11.0, use InterpolatingAnimator<T>", true)] |
|||
public abstract class CustomAnimatorBase |
|||
{ |
|||
internal abstract IAnimator CreateWrapper(); |
|||
internal abstract Type WrapperType { get; } |
|||
} |
|||
|
|||
[Obsolete("This class will be removed before 11.0, use InterpolatingAnimator<T>", true)] |
|||
public abstract class CustomAnimatorBase<T> : CustomAnimatorBase |
|||
{ |
|||
public abstract T Interpolate(double progress, T oldValue, T newValue); |
|||
|
|||
internal override Type WrapperType => typeof(AnimatorWrapper); |
|||
internal override IAnimator CreateWrapper() => new AnimatorWrapper(this); |
|||
|
|||
internal class AnimatorWrapper : Animator<T> |
|||
{ |
|||
private readonly CustomAnimatorBase<T> _parent; |
|||
|
|||
public AnimatorWrapper(CustomAnimatorBase<T> parent) |
|||
{ |
|||
_parent = parent; |
|||
} |
|||
|
|||
public override T Interpolate(double progress, T oldValue, T newValue) => _parent.Interpolate(progress, oldValue, newValue); |
|||
} |
|||
} |
|||
|
|||
public interface ICustomAnimator |
|||
{ |
|||
internal IAnimator CreateWrapper(); |
|||
internal Type WrapperType { get; } |
|||
} |
|||
|
|||
public abstract class InterpolatingAnimator<T> : ICustomAnimator |
|||
{ |
|||
public abstract T Interpolate(double progress, T oldValue, T newValue); |
|||
|
|||
Type ICustomAnimator.WrapperType => typeof(AnimatorWrapper); |
|||
IAnimator ICustomAnimator.CreateWrapper() => new AnimatorWrapper(this); |
|||
internal IAnimator CreateWrapper() => new AnimatorWrapper(this); |
|||
|
|||
internal class AnimatorWrapper : Animator<T> |
|||
{ |
|||
private readonly InterpolatingAnimator<T> _parent; |
|||
|
|||
public AnimatorWrapper(InterpolatingAnimator<T> parent) |
|||
{ |
|||
_parent = parent; |
|||
} |
|||
|
|||
public override T Interpolate(double progress, T oldValue, T newValue) => _parent.Interpolate(progress, oldValue, newValue); |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
using System; |
|||
using Avalonia.Animation.Animators; |
|||
|
|||
namespace Avalonia.Animation; |
|||
|
|||
/// <summary>
|
|||
/// The base class for user-defined transition that are doing simple value interpolation
|
|||
/// </summary>
|
|||
public abstract class InterpolatingTransitionBase<T> : Transition<T> |
|||
{ |
|||
class Animator : Animator<T> |
|||
{ |
|||
private readonly InterpolatingTransitionBase<T> _parent; |
|||
|
|||
public Animator(InterpolatingTransitionBase<T> parent) |
|||
{ |
|||
_parent = parent; |
|||
} |
|||
|
|||
public override T Interpolate(double progress, T oldValue, T newValue) => |
|||
_parent.Interpolate(progress, oldValue, newValue); |
|||
} |
|||
|
|||
protected abstract T Interpolate(double progress, T from, T to); |
|||
|
|||
internal override IObservable<T> DoTransition(IObservable<double> progress, T oldValue, T newValue) => |
|||
new AnimatorTransitionObservable<T, Animator>(new Animator(this), progress, Easing, oldValue, newValue); |
|||
} |
|||
@ -1,26 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using Avalonia.Rendering; |
|||
|
|||
namespace Avalonia.Animation |
|||
{ |
|||
public class RenderLoopClock : ClockBase, IRenderLoopTask, IGlobalClock |
|||
{ |
|||
protected override void Stop() |
|||
{ |
|||
AvaloniaLocator.Current.GetRequiredService<IRenderLoop>().Remove(this); |
|||
} |
|||
|
|||
bool IRenderLoopTask.NeedsUpdate => HasSubscriptions; |
|||
|
|||
void IRenderLoopTask.Render() |
|||
{ |
|||
} |
|||
|
|||
void IRenderLoopTask.Update(TimeSpan time) |
|||
{ |
|||
Pulse(time); |
|||
} |
|||
} |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue