diff --git a/Avalonia.sln b/Avalonia.sln
index 76d8a14524..f71a94888d 100644
--- a/Avalonia.sln
+++ b/Avalonia.sln
@@ -186,6 +186,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Designer.HostApp.N
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Skia.UnitTests", "tests\Avalonia.Skia.UnitTests\Avalonia.Skia.UnitTests.csproj", "{E1240B49-7B4B-4371-A00E-068778C5CF0B}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.OpenGL", "src\Avalonia.OpenGL\Avalonia.OpenGL.csproj", "{7CCAEFC4-135D-401D-BDDD-896B9B7D3569}"
+EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\Shared\RenderHelpers\RenderHelpers.projitems*{3c4c0cb4-0c0f-4450-a37b-148c84ff905f}*SharedItemsImports = 13
@@ -1663,6 +1665,30 @@ Global
{E1240B49-7B4B-4371-A00E-068778C5CF0B}.Release|iPhone.Build.0 = Release|Any CPU
{E1240B49-7B4B-4371-A00E-068778C5CF0B}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{E1240B49-7B4B-4371-A00E-068778C5CF0B}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.AppStore|Any CPU.Build.0 = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.AppStore|iPhone.Build.0 = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Debug|iPhone.ActiveCfg = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Debug|iPhone.Build.0 = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Release|Any CPU.Build.0 = Release|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Release|iPhone.ActiveCfg = Release|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Release|iPhone.Build.0 = Release|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/build.cake b/build.cake
index 24f529ee4a..56653109ae 100644
--- a/build.cake
+++ b/build.cake
@@ -170,6 +170,7 @@ Task("Run-Unit-Tests-Impl")
RunCoreTest("./tests/Avalonia.Styling.UnitTests", data.Parameters, false);
RunCoreTest("./tests/Avalonia.Visuals.UnitTests", data.Parameters, false);
RunCoreTest("./tests/Avalonia.Skia.UnitTests", data.Parameters, false);
+ RunCoreTest("./tests/Avalonia.ReactiveUI.UnitTests", data.Parameters, false);
if (data.Parameters.IsRunningOnWindows)
{
RunCoreTest("./tests/Avalonia.Direct2D1.UnitTests", data.Parameters, false);
diff --git a/build/ReactiveUI.props b/build/ReactiveUI.props
index acdfdd215a..1208be34b8 100644
--- a/build/ReactiveUI.props
+++ b/build/ReactiveUI.props
@@ -1,5 +1,5 @@
-
+
diff --git a/packages.cake b/packages.cake
index 9defa3004c..fea45153f1 100644
--- a/packages.cake
+++ b/packages.cake
@@ -167,6 +167,7 @@ public class Packages
new [] { "./src/", "Avalonia.Logging.Serilog"},
new [] { "./src/", "Avalonia.Visuals"},
new [] { "./src/", "Avalonia.Styling"},
+ new [] { "./src/", "Avalonia.OpenGL"},
new [] { "./src/", "Avalonia.Themes.Default"},
new [] { "./src/Markup/", "Avalonia.Markup"},
new [] { "./src/Markup/", "Avalonia.Markup.Xaml"},
diff --git a/samples/ControlCatalog/App.xaml b/samples/ControlCatalog/App.xaml
index 43971dec4f..95d515ec60 100644
--- a/samples/ControlCatalog/App.xaml
+++ b/samples/ControlCatalog/App.xaml
@@ -14,6 +14,11 @@
-
+
+
+
-
\ No newline at end of file
+
diff --git a/samples/ControlCatalog/Pages/MenuPage.xaml b/samples/ControlCatalog/Pages/MenuPage.xaml
index 296cfa8704..c5aa35312c 100644
--- a/samples/ControlCatalog/Pages/MenuPage.xaml
+++ b/samples/ControlCatalog/Pages/MenuPage.xaml
@@ -7,29 +7,46 @@
Margin="0,16,0,0"
HorizontalAlignment="Center"
Spacing="16">
-
+
+
+
+ Dyanamically generated
+
+
+
+
+
+
-
\ No newline at end of file
+
diff --git a/samples/ControlCatalog/Pages/MenuPage.xaml.cs b/samples/ControlCatalog/Pages/MenuPage.xaml.cs
index d637c172e1..ec7c000fe6 100644
--- a/samples/ControlCatalog/Pages/MenuPage.xaml.cs
+++ b/samples/ControlCatalog/Pages/MenuPage.xaml.cs
@@ -1,5 +1,10 @@
+using System.Collections.Generic;
+using System.Reactive;
+using System.Threading.Tasks;
+using System.Windows.Input;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
+using ReactiveUI;
namespace ControlCatalog.Pages
{
@@ -8,6 +13,51 @@ namespace ControlCatalog.Pages
public MenuPage()
{
this.InitializeComponent();
+ var vm = new MenuPageViewModel();
+
+ vm.MenuItems = new[]
+ {
+ new MenuItemViewModel
+ {
+ Header = "_File",
+ Items = new[]
+ {
+ new MenuItemViewModel { Header = "_Open...", Command = vm.OpenCommand },
+ new MenuItemViewModel { Header = "Save", Command = vm.SaveCommand },
+ new MenuItemViewModel { Header = "-" },
+ new MenuItemViewModel
+ {
+ Header = "Recent",
+ Items = new[]
+ {
+ new MenuItemViewModel
+ {
+ Header = "File1.txt",
+ Command = vm.OpenRecentCommand,
+ CommandParameter = @"c:\foo\File1.txt"
+ },
+ new MenuItemViewModel
+ {
+ Header = "File2.txt",
+ Command = vm.OpenRecentCommand,
+ CommandParameter = @"c:\foo\File2.txt"
+ },
+ }
+ },
+ }
+ },
+ new MenuItemViewModel
+ {
+ Header = "_Edit",
+ Items = new[]
+ {
+ new MenuItemViewModel { Header = "_Copy" },
+ new MenuItemViewModel { Header = "_Paste" },
+ }
+ }
+ };
+
+ DataContext = vm;
}
private void InitializeComponent()
@@ -15,4 +65,51 @@ namespace ControlCatalog.Pages
AvaloniaXamlLoader.Load(this);
}
}
+
+ public class MenuPageViewModel
+ {
+ public MenuPageViewModel()
+ {
+ OpenCommand = ReactiveCommand.CreateFromTask(Open);
+ SaveCommand = ReactiveCommand.Create(Save);
+ OpenRecentCommand = ReactiveCommand.Create(OpenRecent);
+ }
+
+ public IReadOnlyList MenuItems { get; set; }
+ public ReactiveCommand OpenCommand { get; }
+ public ReactiveCommand SaveCommand { get; }
+ public ReactiveCommand OpenRecentCommand { get; }
+
+ public async Task Open()
+ {
+ var dialog = new OpenFileDialog();
+ var result = await dialog.ShowAsync();
+
+ if (result != null)
+ {
+ foreach (var path in result)
+ {
+ System.Diagnostics.Debug.WriteLine($"Opened: {path}");
+ }
+ }
+ }
+
+ public void Save()
+ {
+ System.Diagnostics.Debug.WriteLine("Save");
+ }
+
+ public void OpenRecent(string path)
+ {
+ System.Diagnostics.Debug.WriteLine($"Open recent: {path}");
+ }
+ }
+
+ public class MenuItemViewModel
+ {
+ public string Header { get; set; }
+ public ICommand Command { get; set; }
+ public object CommandParameter { get; set; }
+ public IList Items { get; set; }
+ }
}
diff --git a/samples/RenderDemo/Pages/AnimationsPage.xaml b/samples/RenderDemo/Pages/AnimationsPage.xaml
index 5287e4e373..473807ac50 100644
--- a/samples/RenderDemo/Pages/AnimationsPage.xaml
+++ b/samples/RenderDemo/Pages/AnimationsPage.xaml
@@ -107,9 +107,12 @@
+
+
+
Hover to activate Transform Keyframe Animations.
-
+
@@ -120,4 +123,4 @@
-
\ No newline at end of file
+
diff --git a/samples/RenderDemo/Pages/AnimationsPage.xaml.cs b/samples/RenderDemo/Pages/AnimationsPage.xaml.cs
index 5b02fd9297..2195b3d494 100644
--- a/samples/RenderDemo/Pages/AnimationsPage.xaml.cs
+++ b/samples/RenderDemo/Pages/AnimationsPage.xaml.cs
@@ -5,6 +5,7 @@ using Avalonia.Controls;
using Avalonia.Controls.Shapes;
using Avalonia.Data;
using Avalonia.Input;
+using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using RenderDemo.ViewModels;
@@ -23,5 +24,20 @@ namespace RenderDemo.Pages
{
AvaloniaXamlLoader.Load(this);
}
+
+ private void ToggleClock(object sender, RoutedEventArgs args)
+ {
+ var button = sender as Button;
+ var clock = button.Clock;
+
+ if (clock.PlayState == PlayState.Run)
+ {
+ clock.PlayState = PlayState.Pause;
+ }
+ else if (clock.PlayState == PlayState.Pause)
+ {
+ clock.PlayState = PlayState.Run;
+ }
+ }
}
}
diff --git a/samples/RenderDemo/ViewModels/AnimationsPageViewModel.cs b/samples/RenderDemo/ViewModels/AnimationsPageViewModel.cs
index f724baf3c6..7b89b7944c 100644
--- a/samples/RenderDemo/ViewModels/AnimationsPageViewModel.cs
+++ b/samples/RenderDemo/ViewModels/AnimationsPageViewModel.cs
@@ -6,27 +6,15 @@ namespace RenderDemo.ViewModels
{
public class AnimationsPageViewModel : ReactiveObject
{
- private string _playStateText = "Pause all animations";
+ private bool _isPlaying = true;
- public AnimationsPageViewModel()
- {
- ToggleGlobalPlayState = ReactiveCommand.Create(() => TogglePlayState());
- }
+ private string _playStateText = "Pause animations on this page";
- void TogglePlayState()
+ public void TogglePlayState()
{
- switch (Animation.GlobalPlayState)
- {
- case PlayState.Run:
- PlayStateText = "Resume all animations";
- Animation.GlobalPlayState = PlayState.Pause;
- break;
-
- case PlayState.Pause:
- PlayStateText = "Pause all animations";
- Animation.GlobalPlayState = PlayState.Run;
- break;
- }
+ PlayStateText = _isPlaying
+ ? "Resume animations on this page" : "Pause animations on this page";
+ _isPlaying = !_isPlaying;
}
public string PlayStateText
@@ -34,7 +22,5 @@ namespace RenderDemo.ViewModels
get { return _playStateText; }
set { this.RaiseAndSetIfChanged(ref _playStateText, value); }
}
-
- public ReactiveCommand ToggleGlobalPlayState { get; }
}
}
diff --git a/samples/VirtualizationDemo/ViewModels/MainWindowViewModel.cs b/samples/VirtualizationDemo/ViewModels/MainWindowViewModel.cs
index eb08ef9656..eba17f92e4 100644
--- a/samples/VirtualizationDemo/ViewModels/MainWindowViewModel.cs
+++ b/samples/VirtualizationDemo/ViewModels/MainWindowViewModel.cs
@@ -7,6 +7,7 @@ using System.Linq;
using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
+using ReactiveUI.Legacy;
using ReactiveUI;
namespace VirtualizationDemo.ViewModels
diff --git a/samples/interop/Direct3DInteropSample/MainWindow.cs b/samples/interop/Direct3DInteropSample/MainWindow.cs
index 19c31a3af1..1ac4b44a74 100644
--- a/samples/interop/Direct3DInteropSample/MainWindow.cs
+++ b/samples/interop/Direct3DInteropSample/MainWindow.cs
@@ -1,81 +1,83 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+// Copyright (c) The Avalonia Project. All rights reserved.
+// Licensed under the MIT license. See licence.md file in the project root for full license information.
+
+using System;
+
using Avalonia;
using Avalonia.Controls;
+using Avalonia.Direct2D1;
using Avalonia.Direct2D1.Media;
using Avalonia.Markup.Xaml;
using Avalonia.Platform;
using Avalonia.Rendering;
+
using SharpDX;
using SharpDX.D3DCompiler;
using SharpDX.Direct2D1;
using SharpDX.Direct3D;
using SharpDX.Direct3D11;
using SharpDX.DXGI;
-using SharpDX.WIC;
-using SharpDX.Mathematics;
+
using AlphaMode = SharpDX.Direct2D1.AlphaMode;
using Buffer = SharpDX.Direct3D11.Buffer;
-using DeviceContext = SharpDX.Direct3D11.DeviceContext;
-using Factory1 = SharpDX.DXGI.Factory1;
+using DeviceContext = SharpDX.Direct2D1.DeviceContext;
+using Factory2 = SharpDX.DXGI.Factory2;
using InputElement = SharpDX.Direct3D11.InputElement;
using Matrix = SharpDX.Matrix;
using PixelFormat = SharpDX.Direct2D1.PixelFormat;
+using Resource = SharpDX.Direct3D11.Resource;
namespace Direct3DInteropSample
{
- class MainWindow : Window
+ public class MainWindow : Window
{
- private SharpDX.Direct3D11.Device _d3dDevice;
- private SharpDX.DXGI.Device _dxgiDevice;
- Texture2D backBuffer = null;
- RenderTargetView renderView = null;
- Texture2D depthBuffer = null;
- DepthStencilView depthView = null;
+ Texture2D _backBuffer;
+ RenderTargetView _renderView;
+ Texture2D _depthBuffer;
+ DepthStencilView _depthView;
private readonly SwapChain _swapChain;
- private SwapChainDescription _desc;
+ private SwapChainDescription1 _desc;
private Matrix _proj = Matrix.Identity;
- private Matrix _view;
+ private readonly Matrix _view;
private Buffer _contantBuffer;
- private SharpDX.Direct2D1.Device _d2dDevice;
- private SharpDX.Direct2D1.DeviceContext _d2dContext;
- private RenderTarget _d2dRenderTarget;
- private MainWindowViewModel _model;
+ private DeviceContext _deviceContext;
+ private readonly MainWindowViewModel _model;
public MainWindow()
{
- _dxgiDevice = AvaloniaLocator.Current.GetService();
- _d3dDevice = _dxgiDevice.QueryInterface();
- _d2dDevice = AvaloniaLocator.Current.GetService();
DataContext = _model = new MainWindowViewModel();
- _desc = new SwapChainDescription()
+
+ _desc = new SwapChainDescription1()
{
BufferCount = 1,
- ModeDescription =
- new ModeDescription((int)ClientSize.Width, (int)ClientSize.Height,
- new Rational(60, 1), Format.R8G8B8A8_UNorm),
- IsWindowed = true,
- OutputHandle = PlatformImpl?.Handle.Handle ?? IntPtr.Zero,
+ Width = (int)ClientSize.Width,
+ Height = (int)ClientSize.Height,
+ Format = Format.R8G8B8A8_UNorm,
SampleDescription = new SampleDescription(1, 0),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
};
- _swapChain = new SwapChain(new Factory1(), _d3dDevice, _desc);
+ using (var factory = Direct2D1Platform.DxgiDevice.Adapter.GetParent())
+ {
+ _swapChain = new SwapChain1(factory, Direct2D1Platform.DxgiDevice, PlatformImpl?.Handle.Handle ?? IntPtr.Zero, ref _desc);
+ }
- _d2dContext = new SharpDX.Direct2D1.DeviceContext(_d2dDevice, DeviceContextOptions.None)
+ _deviceContext = new DeviceContext(Direct2D1Platform.Direct2D1Device, DeviceContextOptions.None)
{
DotsPerInch = new Size2F(96, 96)
};
CreateMesh();
+
_view = Matrix.LookAtLH(new Vector3(0, 0, -5), new Vector3(0, 0, 0), Vector3.UnitY);
+
this.GetObservable(ClientSizeProperty).Subscribe(Resize);
+
Resize(ClientSize);
+
AvaloniaXamlLoader.Load(this);
+
Background = Avalonia.Media.Brushes.Transparent;
}
@@ -83,29 +85,32 @@ namespace Direct3DInteropSample
protected override void HandlePaint(Rect rect)
{
var viewProj = Matrix.Multiply(_view, _proj);
- var context = _d3dDevice.ImmediateContext;
+ var context = Direct2D1Platform.Direct3D11Device.ImmediateContext;
+
// Clear views
- context.ClearDepthStencilView(depthView, DepthStencilClearFlags.Depth, 1.0f, 0);
- context.ClearRenderTargetView(renderView, Color.White);
+ context.ClearDepthStencilView(_depthView, DepthStencilClearFlags.Depth, 1.0f, 0);
+ context.ClearRenderTargetView(_renderView, Color.White);
// Update WorldViewProj Matrix
- var worldViewProj = Matrix.RotationX((float) _model.RotationX) * Matrix.RotationY((float) _model.RotationY) *
- Matrix.RotationZ((float) _model.RotationZ)
- * Matrix.Scaling((float) _model.Zoom) * viewProj;
+ var worldViewProj = Matrix.RotationX((float)_model.RotationX) * Matrix.RotationY((float)_model.RotationY)
+ * Matrix.RotationZ((float)_model.RotationZ)
+ * Matrix.Scaling((float)_model.Zoom)
+ * viewProj;
worldViewProj.Transpose();
context.UpdateSubresource(ref worldViewProj, _contantBuffer);
// Draw the cube
context.Draw(36, 0);
base.HandlePaint(rect);
+
// Present!
_swapChain.Present(0, PresentFlags.None);
}
-
- void CreateMesh()
+ private void CreateMesh()
{
- var device = _d3dDevice;
+ var device = Direct2D1Platform.Direct3D11Device;
+
// Compile Vertex and Pixel shaders
var vertexShaderByteCode = ShaderBytecode.CompileFromFile("MiniCube.fx", "VS", "vs_4_0");
var vertexShader = new VertexShader(device, vertexShaderByteCode);
@@ -114,63 +119,72 @@ namespace Direct3DInteropSample
var pixelShader = new PixelShader(device, pixelShaderByteCode);
var signature = ShaderSignature.GetInputSignature(vertexShaderByteCode);
+
+ var inputElements = new[]
+ {
+ new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
+ new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0)
+ };
+
// Layout from VertexShader input signature
- var layout = new InputLayout(device, signature, new[]
- {
- new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
- new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0)
- });
-
- // Instantiate Vertex buiffer from vertex data
- var vertices = Buffer.Create(device, BindFlags.VertexBuffer, new[]
- {
- new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f), // Front
- new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
- new Vector4( 1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
- new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
- new Vector4( 1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
- new Vector4( 1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
-
- new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f), // BACK
- new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
- new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
- new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
- new Vector4( 1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
- new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
-
- new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f), // Top
- new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
- new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
- new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
- new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
- new Vector4( 1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
-
- new Vector4(-1.0f,-1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f), // Bottom
- new Vector4( 1.0f,-1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
- new Vector4(-1.0f,-1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
- new Vector4(-1.0f,-1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
- new Vector4( 1.0f,-1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
- new Vector4( 1.0f,-1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
-
- new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f), // Left
- new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
- new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
- new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
- new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
- new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
-
- new Vector4( 1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f), // Right
- new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
- new Vector4( 1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
- new Vector4( 1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
- new Vector4( 1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
- new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
- });
+ var layout = new InputLayout(
+ device,
+ signature,
+ inputElements);
+
+ // Instantiate Vertex buffer from vertex data
+ var vertices = Buffer.Create(
+ device,
+ BindFlags.VertexBuffer,
+ new[]
+ {
+ new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f), // Front
+ new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
+ new Vector4( 1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
+ new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
+ new Vector4( 1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
+ new Vector4( 1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
+
+ new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f), // BACK
+ new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
+ new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
+ new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
+ new Vector4( 1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
+ new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
+
+ new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f), // Top
+ new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
+ new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
+ new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
+ new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
+ new Vector4( 1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
+
+ new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f), // Bottom
+ new Vector4( 1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
+ new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
+ new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
+ new Vector4( 1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
+ new Vector4( 1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
+
+ new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f), // Left
+ new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
+ new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
+ new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
+ new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
+ new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
+
+ new Vector4( 1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f), // Right
+ new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
+ new Vector4( 1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
+ new Vector4( 1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
+ new Vector4( 1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
+ new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
+ });
// Create Constant Buffer
_contantBuffer = new Buffer(device, Utilities.SizeOf(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
- var context = _d3dDevice.ImmediateContext;
+ var context = Direct2D1Platform.Direct3D11Device.ImmediateContext;
// Prepare All the stages
context.InputAssembler.InputLayout = layout;
@@ -181,63 +195,73 @@ namespace Direct3DInteropSample
context.PixelShader.Set(pixelShader);
}
- void Resize(Size size)
+ private void Resize(Size size)
{
- Utilities.Dispose(ref _d2dRenderTarget);
- Utilities.Dispose(ref backBuffer);
- Utilities.Dispose(ref renderView);
- Utilities.Dispose(ref depthBuffer);
- Utilities.Dispose(ref depthView);
- var context = _d3dDevice.ImmediateContext;
+ Utilities.Dispose(ref _deviceContext);
+ Utilities.Dispose(ref _backBuffer);
+ Utilities.Dispose(ref _renderView);
+ Utilities.Dispose(ref _depthBuffer);
+ Utilities.Dispose(ref _depthView);
+ var context = Direct2D1Platform.Direct3D11Device.ImmediateContext;
+
// Resize the backbuffer
- _swapChain.ResizeBuffers(_desc.BufferCount, (int)size.Width, (int)size.Height, Format.Unknown, SwapChainFlags.None);
+ _swapChain.ResizeBuffers(0, 0, 0, Format.Unknown, SwapChainFlags.None);
// Get the backbuffer from the swapchain
- backBuffer = Texture2D.FromSwapChain(_swapChain, 0);
+ _backBuffer = Resource.FromSwapChain(_swapChain, 0);
// Renderview on the backbuffer
- renderView = new RenderTargetView(_d3dDevice, backBuffer);
+ _renderView = new RenderTargetView(Direct2D1Platform.Direct3D11Device, _backBuffer);
// Create the depth buffer
- depthBuffer = new Texture2D(_d3dDevice, new Texture2DDescription()
- {
- Format = Format.D32_Float_S8X24_UInt,
- ArraySize = 1,
- MipLevels = 1,
- Width = (int)size.Width,
- Height = (int)size.Height,
- SampleDescription = new SampleDescription(1, 0),
- Usage = ResourceUsage.Default,
- BindFlags = BindFlags.DepthStencil,
- CpuAccessFlags = CpuAccessFlags.None,
- OptionFlags = ResourceOptionFlags.None
- });
+ _depthBuffer = new Texture2D(
+ Direct2D1Platform.Direct3D11Device,
+ new Texture2DDescription()
+ {
+ Format = Format.D32_Float_S8X24_UInt,
+ ArraySize = 1,
+ MipLevels = 1,
+ Width = (int)size.Width,
+ Height = (int)size.Height,
+ SampleDescription = new SampleDescription(1, 0),
+ Usage = ResourceUsage.Default,
+ BindFlags = BindFlags.DepthStencil,
+ CpuAccessFlags = CpuAccessFlags.None,
+ OptionFlags = ResourceOptionFlags.None
+ });
// Create the depth buffer view
- depthView = new DepthStencilView(_d3dDevice, depthBuffer);
+ _depthView = new DepthStencilView(Direct2D1Platform.Direct3D11Device, _depthBuffer);
// Setup targets and viewport for rendering
context.Rasterizer.SetViewport(new Viewport(0, 0, (int)size.Width, (int)size.Height, 0.0f, 1.0f));
- context.OutputMerger.SetTargets(depthView, renderView);
+ context.OutputMerger.SetTargets(_depthView, _renderView);
// Setup new projection matrix with correct aspect ratio
_proj = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)(size.Width / size.Height), 0.1f, 100.0f);
using (var dxgiBackBuffer = _swapChain.GetBackBuffer(0))
{
- _d2dRenderTarget = new RenderTarget(AvaloniaLocator.Current.GetService()
- , dxgiBackBuffer, new RenderTargetProperties
+ var renderTarget = new SharpDX.Direct2D1.RenderTarget(
+ Direct2D1Platform.Direct2D1Factory,
+ dxgiBackBuffer,
+ new RenderTargetProperties
{
DpiX = 96,
DpiY = 96,
Type = RenderTargetType.Default,
- PixelFormat = new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)
+ PixelFormat = new PixelFormat(
+ Format.Unknown,
+ AlphaMode.Premultiplied)
});
- }
+ _deviceContext = renderTarget.QueryInterface();
+
+ renderTarget.Dispose();
+ }
}
- class D3DRenderTarget: IRenderTarget
+ private class D3DRenderTarget : IRenderTarget
{
private readonly MainWindow _window;
@@ -245,16 +269,14 @@ namespace Direct3DInteropSample
{
_window = window;
}
+
public void Dispose()
{
-
}
public IDrawingContextImpl CreateDrawingContext(IVisualBrushRenderer visualBrushRenderer)
{
- return new DrawingContextImpl(visualBrushRenderer, null, _window._d2dRenderTarget,
- AvaloniaLocator.Current.GetService(),
- AvaloniaLocator.Current.GetService());
+ return new DrawingContextImpl(visualBrushRenderer, null, _window._deviceContext);
}
}
diff --git a/src/Android/Avalonia.Android/AndroidPlatform.cs b/src/Android/Avalonia.Android/AndroidPlatform.cs
index 2b46bfa492..5f0edadf63 100644
--- a/src/Android/Avalonia.Android/AndroidPlatform.cs
+++ b/src/Android/Avalonia.Android/AndroidPlatform.cs
@@ -52,7 +52,8 @@ namespace Avalonia.Android
.Bind().ToTransient()
.Bind().ToConstant(Instance)
.Bind().ToSingleton()
- .Bind().ToConstant(new DefaultRenderLoop(60))
+ .Bind().ToConstant(new DefaultRenderTimer(60))
+ .Bind().ToConstant(new RenderLoop())
.Bind().ToConstant(new AssetLoader(app.GetType().Assembly));
SkiaPlatform.Initialize();
diff --git a/src/Avalonia.Animation/Animatable.cs b/src/Avalonia.Animation/Animatable.cs
index 8a1a17a6fc..516f383b92 100644
--- a/src/Avalonia.Animation/Animatable.cs
+++ b/src/Avalonia.Animation/Animatable.cs
@@ -14,26 +14,14 @@ namespace Avalonia.Animation
/// Base class for all animatable objects.
///
public class Animatable : AvaloniaObject
- {
- ///
- /// Defines the property.
- ///
- public static readonly DirectProperty PlayStateProperty =
- AvaloniaProperty.RegisterDirect(
- nameof(PlayState),
- o => o.PlayState,
- (o, v) => o.PlayState = v);
-
- private PlayState _playState = PlayState.Run;
+ {
+ public static readonly StyledProperty ClockProperty =
+ AvaloniaProperty.Register(nameof(Clock), inherits: true);
- ///
- /// Gets or sets the state of the animation for this
- /// control.
- ///
- public PlayState PlayState
+ public IClock Clock
{
- get { return _playState; }
- set { SetAndRaise(PlayStateProperty, ref _playState, value); }
+ get => GetValue(ClockProperty);
+ set => SetValue(ClockProperty, value);
}
///
@@ -69,9 +57,9 @@ namespace Avalonia.Animation
if (match != null)
{
- match.Apply(this, e.OldValue, e.NewValue);
+ match.Apply(this, Clock ?? Avalonia.Animation.Clock.GlobalClock, e.OldValue, e.NewValue);
}
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Avalonia.Animation/Animation.cs b/src/Avalonia.Animation/Animation.cs
index 2c359ecac3..d7efc69e10 100644
--- a/src/Avalonia.Animation/Animation.cs
+++ b/src/Avalonia.Animation/Animation.cs
@@ -17,11 +17,6 @@ namespace Avalonia.Animation
///
public class Animation : AvaloniaList, IAnimation
{
- ///
- /// Gets or sets the animation play state for all animations
- ///
- public static PlayState GlobalPlayState { get; set; } = PlayState.Run;
-
///
/// Gets or sets the active time of this animation.
///
@@ -149,12 +144,12 @@ namespace Avalonia.Animation
}
///
- public IDisposable Apply(Animatable control, IObservable match, Action onComplete)
+ public IDisposable Apply(Animatable control, IClock clock, IObservable match, Action onComplete)
{
var (animators, subscriptions) = InterpretKeyframes(control);
if (animators.Count == 1)
{
- subscriptions.Add(animators[0].Apply(this, control, match, onComplete));
+ subscriptions.Add(animators[0].Apply(this, control, clock, match, onComplete));
}
else
{
@@ -168,7 +163,7 @@ namespace Avalonia.Animation
animatorOnComplete = () => tcs.SetResult(null);
completionTasks.Add(tcs.Task);
}
- subscriptions.Add(animator.Apply(this, control, match, animatorOnComplete));
+ subscriptions.Add(animator.Apply(this, control, clock, match, animatorOnComplete));
}
if (onComplete != null)
@@ -180,7 +175,7 @@ namespace Avalonia.Animation
}
///
- public Task RunAsync(Animatable control)
+ public Task RunAsync(Animatable control, IClock clock = null)
{
var run = new TaskCompletionSource