port from perforce
This commit is contained in:
77
intromat/Intromat/Views/Preview2DView.xaml.cs
Normal file
77
intromat/Intromat/Views/Preview2DView.xaml.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using Intromat.Graphics;
|
||||
using Intromat.Pipelines;
|
||||
using Intromat.ViewModels.Previews;
|
||||
using ReactiveUI;
|
||||
using SharpDX.Direct3D11;
|
||||
using Splat;
|
||||
|
||||
namespace Intromat.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for Preview2DView.xaml
|
||||
/// </summary>
|
||||
public partial class Preview2DView : IViewFor<DxTexturePreviewViewModel>
|
||||
{
|
||||
private DisplayTexturePipeline? _pipeline;
|
||||
|
||||
public static readonly DependencyProperty ViewModelProperty = DependencyProperty.Register(nameof(ViewModel),
|
||||
typeof(DxTexturePreviewViewModel), typeof(Preview2DView), new PropertyMetadata(null));
|
||||
|
||||
public Preview2DView()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
_pipeline = Locator.Current.GetService<DisplayTexturePipeline>()!;
|
||||
this.WhenAnyObservable(v => v.ViewModel!.TextureValue).Subscribe(textureValue =>
|
||||
{
|
||||
var srv = textureValue?.ShaderResourceView;
|
||||
if (srv != null)
|
||||
{
|
||||
_pipeline.ShaderResourceView = srv;
|
||||
_dxView.Render();
|
||||
}
|
||||
}).DisposeWith(d);
|
||||
_dxView.SetUpdateHandler(UpdateFrameAction);
|
||||
});
|
||||
}
|
||||
|
||||
private void UpdateFrameAction(Device device, DeviceContext context)
|
||||
{
|
||||
var graphicsAnalysis = Locator.Current.GetService<DxHost>()?._graphicsAnalysis;
|
||||
graphicsAnalysis?.BeginCapture();
|
||||
_pipeline?.Apply();
|
||||
graphicsAnalysis?.EndCapture();
|
||||
}
|
||||
|
||||
private void OnDxViewMouseWheel(object sender, MouseWheelEventArgs e)
|
||||
{
|
||||
var element = (UIElement)sender;
|
||||
var position = e.GetPosition(element);
|
||||
var transform = (MatrixTransform)element.RenderTransform;
|
||||
var matrix = transform.Matrix;
|
||||
var scale = e.Delta >= 0 ? 1.1 : (1.0 / 1.1); // choose appropriate scaling factor
|
||||
|
||||
matrix.ScaleAtPrepend(scale, scale, position.X, position.Y);
|
||||
transform.Matrix = matrix;
|
||||
}
|
||||
|
||||
object? IViewFor.ViewModel
|
||||
{
|
||||
get => ViewModel;
|
||||
set => ViewModel = (DxTexturePreviewViewModel?)value;
|
||||
}
|
||||
|
||||
public DxTexturePreviewViewModel? ViewModel
|
||||
{
|
||||
get => (DxTexturePreviewViewModel?)GetValue(ViewModelProperty);
|
||||
set => SetValue(ViewModelProperty, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user