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/ControlCatalog.csproj b/samples/ControlCatalog/ControlCatalog.csproj
index dea9b35e24..61f2443eb7 100644
--- a/samples/ControlCatalog/ControlCatalog.csproj
+++ b/samples/ControlCatalog/ControlCatalog.csproj
@@ -35,4 +35,4 @@
-
\ No newline at end of file
+
diff --git a/samples/ControlCatalog/MainView.xaml b/samples/ControlCatalog/MainView.xaml
index 87cb5e9c5c..ec3bf799b4 100644
--- a/samples/ControlCatalog/MainView.xaml
+++ b/samples/ControlCatalog/MainView.xaml
@@ -20,8 +20,9 @@
+
-
+
diff --git a/samples/ControlCatalog/Pages/CanvasPage.xaml b/samples/ControlCatalog/Pages/CanvasPage.xaml
index 10a38895a2..d6c138a4f7 100644
--- a/samples/ControlCatalog/Pages/CanvasPage.xaml
+++ b/samples/ControlCatalog/Pages/CanvasPage.xaml
@@ -11,7 +11,8 @@
-
+
+
diff --git a/samples/ControlCatalog/Pages/ListBoxPage.xaml b/samples/ControlCatalog/Pages/ListBoxPage.xaml
new file mode 100644
index 0000000000..3dd8be91c2
--- /dev/null
+++ b/samples/ControlCatalog/Pages/ListBoxPage.xaml
@@ -0,0 +1,13 @@
+
+
+ ListBox
+ Hosts a collection of ListBoxItem.
+
+
+
+
+
+
diff --git a/samples/ControlCatalog/Pages/ListBoxPage.xaml.cs b/samples/ControlCatalog/Pages/ListBoxPage.xaml.cs
new file mode 100644
index 0000000000..dbe6c74800
--- /dev/null
+++ b/samples/ControlCatalog/Pages/ListBoxPage.xaml.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+
+namespace ControlCatalog.Pages
+{
+ public class ListBoxPage : UserControl
+ {
+ public ListBoxPage()
+ {
+ this.InitializeComponent();
+ DataContext = Enumerable.Range(1, 10).Select(i => $"Item {i}" )
+ .ToArray();
+ }
+
+ private void InitializeComponent()
+ {
+ AvaloniaXamlLoader.Load(this);
+ }
+
+ }
+}
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/ControlCatalog/Pages/NumericUpDownPage.xaml b/samples/ControlCatalog/Pages/NumericUpDownPage.xaml
index 305bcd177c..2bb6214b58 100644
--- a/samples/ControlCatalog/Pages/NumericUpDownPage.xaml
+++ b/samples/ControlCatalog/Pages/NumericUpDownPage.xaml
@@ -14,7 +14,7 @@
AllowSpin:
-
+
ClipValueToMinMax:
@@ -77,4 +77,4 @@
-
\ No newline at end of file
+
diff --git a/samples/ControlCatalog/Pages/ScreenPage.cs b/samples/ControlCatalog/Pages/ScreenPage.cs
index 34aa85b8aa..fd66185832 100644
--- a/samples/ControlCatalog/Pages/ScreenPage.cs
+++ b/samples/ControlCatalog/Pages/ScreenPage.cs
@@ -42,7 +42,11 @@ namespace ControlCatalog.Pages
context.DrawRectangle(p, boundsRect);
context.DrawRectangle(p, workingAreaRect);
- FormattedText text = new FormattedText();
+ FormattedText text = new FormattedText()
+ {
+ Typeface = Typeface.Default
+ };
+
text.Text = $"Bounds: {screen.Bounds.Width}:{screen.Bounds.Height}";
context.DrawText(Brushes.Black, boundsRect.Position.WithY(boundsRect.Size.Height), text);
@@ -59,4 +63,4 @@ namespace ControlCatalog.Pages
context.DrawRectangle(p, new Rect(w.Position.X / 10f + Math.Abs(_leftMost), w.Position.Y / 10, w.Bounds.Width / 10, w.Bounds.Height / 10));
}
}
-}
\ No newline at end of file
+}
diff --git a/samples/ControlCatalog/SideBar.xaml b/samples/ControlCatalog/SideBar.xaml
index 7d72d1821b..cc3c31d13a 100644
--- a/samples/ControlCatalog/SideBar.xaml
+++ b/samples/ControlCatalog/SideBar.xaml
@@ -36,7 +36,7 @@
-
+
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/SideBar.xaml b/samples/RenderDemo/SideBar.xaml
index b5f8ccaf01..26da2cc556 100644
--- a/samples/RenderDemo/SideBar.xaml
+++ b/samples/RenderDemo/SideBar.xaml
@@ -37,7 +37,7 @@
-
+
diff --git a/samples/RenderDemo/ViewModels/AnimationsPageViewModel.cs b/samples/RenderDemo/ViewModels/AnimationsPageViewModel.cs
index 626a3e7c77..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 (Timing.GetGlobalPlayState())
- {
- case PlayState.Run:
- PlayStateText = "Resume all animations";
- Timing.SetGlobalPlayState(PlayState.Pause);
- break;
-
- case PlayState.Pause:
- PlayStateText = "Pause all animations";
- Timing.SetGlobalPlayState(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/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 7134e7d1b4..5f0edadf63 100644
--- a/src/Android/Avalonia.Android/AndroidPlatform.cs
+++ b/src/Android/Avalonia.Android/AndroidPlatform.cs
@@ -1,8 +1,4 @@
using System;
-using System.IO;
-using System.Linq;
-using Android.Content;
-using Android.Views;
using Avalonia.Android.Platform;
using Avalonia.Android.Platform.Input;
using Avalonia.Android.Platform.SkiaPlatform;
@@ -56,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();
@@ -79,4 +76,4 @@ namespace Avalonia.Android
return new PopupImpl();
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Android/Avalonia.Android/AndroidThreadingInterface.cs b/src/Android/Avalonia.Android/AndroidThreadingInterface.cs
index 77dfc60b83..6fe77adca1 100644
--- a/src/Android/Avalonia.Android/AndroidThreadingInterface.cs
+++ b/src/Android/Avalonia.Android/AndroidThreadingInterface.cs
@@ -1,16 +1,7 @@
using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
using System.Reactive.Disposables;
-using System.Text;
using System.Threading;
-using Android.App;
-using Android.Content;
using Android.OS;
-using Android.Runtime;
-using Android.Views;
-using Android.Widget;
using Avalonia.Platform;
using Avalonia.Threading;
@@ -88,4 +79,3 @@ namespace Avalonia.Android
public event Action Signaled;
}
}
-
\ No newline at end of file
diff --git a/src/Android/Avalonia.Android/AppBuilder.cs b/src/Android/Avalonia.Android/AppBuilder.cs
index 6078e3bb98..805bb61655 100644
--- a/src/Android/Avalonia.Android/AppBuilder.cs
+++ b/src/Android/Avalonia.Android/AppBuilder.cs
@@ -1,16 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-using Android.App;
-using Android.Content;
-using Android.OS;
-using Android.Runtime;
-using Android.Views;
-using Android.Widget;
using Avalonia.Controls;
-using Avalonia.Platform;
using Avalonia.Shared.PlatformSupport;
namespace Avalonia
@@ -23,4 +11,4 @@ namespace Avalonia
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Android/Avalonia.Android/AvaloniaActivity.cs b/src/Android/Avalonia.Android/AvaloniaActivity.cs
index 21ce555086..d3696aa41d 100644
--- a/src/Android/Avalonia.Android/AvaloniaActivity.cs
+++ b/src/Android/Avalonia.Android/AvaloniaActivity.cs
@@ -1,14 +1,7 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using Android.App;
-using Android.Content;
using Android.OS;
-using Android.Runtime;
using Android.Views;
-using Android.Widget;
namespace Avalonia.Android
{
@@ -48,4 +41,4 @@ namespace Avalonia.Android
return View.DispatchKeyEvent(e);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Android/Avalonia.Android/AvaloniaView.cs b/src/Android/Avalonia.Android/AvaloniaView.cs
index 6c4274a6e4..fbe027db00 100644
--- a/src/Android/Avalonia.Android/AvaloniaView.cs
+++ b/src/Android/Avalonia.Android/AvaloniaView.cs
@@ -1,12 +1,5 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-using Android.App;
using Android.Content;
-using Android.OS;
-using Android.Runtime;
using Android.Views;
using Android.Widget;
using Avalonia.Android.Platform.SkiaPlatform;
@@ -66,4 +59,4 @@ namespace Avalonia.Android
public IDisposable ShowDialog() => null;
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Android/Avalonia.Android/CursorFactory.cs b/src/Android/Avalonia.Android/CursorFactory.cs
index e6b9433cca..9eb28c67f9 100644
--- a/src/Android/Avalonia.Android/CursorFactory.cs
+++ b/src/Android/Avalonia.Android/CursorFactory.cs
@@ -9,4 +9,4 @@ namespace Avalonia.Android
public IPlatformHandle GetCursor(StandardCursorType cursorType)
=> new PlatformHandle(IntPtr.Zero, "ZeroCursor");
}
-}
\ No newline at end of file
+}
diff --git a/src/Android/Avalonia.Android/Platform/ClipboardImpl.cs b/src/Android/Avalonia.Android/Platform/ClipboardImpl.cs
index 8c28b48019..51e0a1e799 100644
--- a/src/Android/Avalonia.Android/Platform/ClipboardImpl.cs
+++ b/src/Android/Avalonia.Android/Platform/ClipboardImpl.cs
@@ -1,9 +1,9 @@
+using System.Threading.Tasks;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Avalonia.Input.Platform;
using Avalonia.Platform;
-using System.Threading.Tasks;
namespace Avalonia.Android.Platform
{
@@ -44,4 +44,4 @@ namespace Avalonia.Android.Platform
return Task.FromResult