private void OnGameLoopStarting(ICanvasAnimatedControl sender, object args) { // // The GestureRecognizer needs to be created and accessed from the // same thread -- in this case the game loop thread, so we use the GameLoopStarting event // for this. // gestureRecognizer = new GestureRecognizer(); gestureRecognizer.GestureSettings = GestureSettings.ManipulationTranslateInertia | GestureSettings.ManipulationTranslateY; gestureRecognizer.ManipulationStarted += gestureRecognizer_ManipulationStarted; gestureRecognizer.ManipulationUpdated += gestureRecognizer_ManipulationUpdated; gestureRecognizer.ManipulationCompleted += gestureRecognizer_ManipulationCompleted; gestureRecognizer.InertiaTranslationDeceleration = -0.05f; // // When the GestureRecognizer goes into intertia mode (ie after the pointer is released) // we want it to generate ManipulationUpdated events in sync with the game loop's Update. // We do this by disabling AutoProcessIntertia and explicitly calling ProcessInertia() // from the Update. // gestureRecognizer.AutoProcessInertia = false; inputSource = animatedControl.CreateCoreIndependentInputSource(CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Pen | CoreInputDeviceTypes.Touch); inputSource.PointerPressed += Input_PointerPressed; inputSource.PointerMoved += Input_PointerMoved; inputSource.PointerReleased += Input_PointerReleased; }
public async Task Initialize(CanvasAnimatedControl canvasAnimatedControl, T scene) { if (canvasAnimatedControl == null) { throw new ArgumentNullException(nameof(canvasAnimatedControl)); } if (scene == null) { throw new ArgumentNullException(nameof(scene)); } _canvasAnimatedControl = canvasAnimatedControl; Scene = scene; await _canvasAnimatedControl.RunOnGameLoopThreadAsync(() => { _inputSource = canvasAnimatedControl.CreateCoreIndependentInputSource(CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Pen | CoreInputDeviceTypes.Touch); _inputSource.PointerPressed += OnPointerPressed; _inputSource.PointerMoved += OnPointerMoved; _inputSource.PointerReleased += OnPointerReleased; }); DoInitialize(); }
private void OnGameLoopStarting(ICanvasAnimatedControl sender, object args) { _gestureRecognizer = new GestureRecognizer(); _gestureRecognizer.GestureSettings = GestureSettings.ManipulationTranslateX | GestureSettings.ManipulationTranslateY | GestureSettings.ManipulationScale; _gestureRecognizer.ManipulationStarted += gestureRecognizer_ManipulationStarted; _gestureRecognizer.ManipulationUpdated += gestureRecognizer_ManipulationUpdated; _gestureRecognizer.ManipulationCompleted += gestureRecognizer_ManipulationCompleted; // // When the GestureRecognizer goes into intertia mode (ie after the pointer is released) // we want it to generate ManipulationUpdated events in sync with the game loop's Update. // We do this by disabling AutoProcessIntertia and explicitly calling ProcessInertia() // from the Update. // _gestureRecognizer.InertiaTranslationDeceleration = -5.0f; _gestureRecognizer.AutoProcessInertia = false; _inputDevice = Cvs.CreateCoreIndependentInputSource( CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Touch | CoreInputDeviceTypes.Pen); _inputDevice.PointerPressed += OnPointerPressed; _inputDevice.PointerReleased += OnPointerReleased; _inputDevice.PointerWheelChanged += OnPointerWheelChanged; _inputDevice.PointerMoved += OnPointerMoved; }
public async Task Clean() { DoClean(); if (_inputSource != null) { await _canvasAnimatedControl.RunOnGameLoopThreadAsync(() => { _inputSource.PointerPressed -= OnPointerPressed; _inputSource.PointerMoved -= OnPointerMoved; _inputSource.PointerReleased -= OnPointerReleased; _inputSource = null; }); } _canvasAnimatedControl = null; Scene = null; }
private async void CanvasCreateResources(object o, RoutedEventArgs routedEventArgs) { // initialize current displayinfo UpdateDisplayInfo(); DisplayInformation.DisplayContentsInvalidated += DisplayInformation_DisplayContentsInvalidated; // create swapchain var swapChain = new CanvasSwapChain(CanvasDevice.GetSharedDevice(), (float)CanvasWidth, (float)CanvasHeight, 96); _canvas.SwapChain = swapChain; // create back buffer _buffer = CanvasRenderTargetExtension.CreateEmpty(_canvas, new Size(CanvasWidth, CanvasHeight)); _tmpBuffer = CanvasRenderTargetExtension.CreateEmpty(_canvas, new Size(CanvasWidth, CanvasHeight)); // create default layer AddLayer(); _background = await CanvasBitmap.LoadAsync(_canvas.SwapChain, new Uri("ms-appx:///PaintCanvas/Assets/canvas.png")); //_canvas.Invalidate(); Invalidate(); Win2dInitialized?.Invoke(this, EventArgs.Empty); // initialize background input thread ThreadPool.RunAsync(_ => { // touch processor _inputSource = _canvas.CreateCoreIndependentInputSource( CoreInputDeviceTypes.Touch | CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Pen ); _inputSource.PointerPressed += CanvasPointerPressed; _inputSource.PointerMoved += CanvasPointerMoved; _inputSource.PointerReleased += CanvasPointerReleased; _inputSource.PointerCaptureLost += CanvasPointerReleased; _inputSource.PointerWheelChanged += CanvasWheelChanged; // setup gesture recognizer _recognizer = new GestureRecognizer { AutoProcessInertia = true }; _recognizer.GestureSettings = GestureSettings.ManipulationTranslateInertia | GestureSettings.ManipulationTranslateRailsX | GestureSettings.ManipulationTranslateRailsY | GestureSettings.ManipulationTranslateX | GestureSettings.ManipulationTranslateY | GestureSettings.ManipulationScale | GestureSettings.ManipulationScaleInertia; _recognizer.ManipulationUpdated += _recognizer_ManipulationUpdated; _inputSource.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessUntilQuit); }, WorkItemPriority.High, WorkItemOptions.TimeSliced); }
public StopVideoControl() { this.InitializeComponent(); StopNative.Class1 c = new StopNative.Class1(); // create c++ component this.d3dView = new StopNative.D3DView(); this.d3dView.Initialize(this.swapChainPanel); // create c++ component DisplayInformation displayInfo = DisplayInformation.GetForCurrentView(); CoreWindow window = Window.Current.CoreWindow; window.VisibilityChanged += window_VisibilityChanged; displayInfo.DpiChanged += displayInfo_DpiChanged; displayInfo.OrientationChanged += displayInfo_OrientationChanged; DisplayInformation.DisplayContentsInvalidated += DisplayInformation_DisplayContentsInvalidated; this.swapChainPanel.CompositionScaleChanged += swapChainPanel_CompositionScaleChanged; this.swapChainPanel.SizeChanged += swapChainPanel_SizeChanged; Application.Current.Suspending += Current_Suspending; Application.Current.Resuming += Current_Resuming; var inputItemHandler = new WorkItemHandler((IAsyncAction inputAction) => { this.coreInput = this.swapChainPanel.CreateCoreIndependentInputSource( CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Pen | CoreInputDeviceTypes.Touch); this.coreInput.PointerPressed += coreInput_PointerPressed; this.coreInput.PointerMoved += coreInput_PointerMoved; this.coreInput.PointerReleased += coreInput_PointerReleased; this.coreInput.PointerEntered += coreInput_PointerEntered; this.coreInput.PointerExited += coreInput_PointerExited; this.coreInput.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessUntilQuit); }); var inputTask = ThreadPool.RunAsync(inputItemHandler, WorkItemPriority.High, WorkItemOptions.TimeSliced); }
private void Page_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) { // CanvasSwapChain swapChain = new CanvasSwapChain(new CanvasDevice(), 800, 600, 96); // canvasControl.SwapChain = swapChain; // using (CanvasDrawingSession ds = swapChain.CreateDrawingSession(Colors.AliceBlue)) // { // } // swapChain.Present(); var a = ThreadPool.RunAsync((_) => { coreInput = canvasControl.CreateCoreIndependentInputSource(Windows.UI.Core.CoreInputDeviceTypes.Mouse); coreInput.PointerMoved += CoreInput_PointerMoved; coreInput.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessUntilQuit); }, WorkItemPriority.High); }
public InputEvents(CoreWindow window, UIElement inputElement, TouchQueue touchQueue) { _touchQueue = touchQueue; // The key events are always tied to the window as those will // only arrive here if some other control hasn't gotten it. window.KeyDown += CoreWindow_KeyDown; window.KeyUp += CoreWindow_KeyUp; window.CharacterReceived += Window_CharacterReceived; window.VisibilityChanged += CoreWindow_VisibilityChanged; window.Activated += CoreWindow_Activated; window.SizeChanged += CoreWindow_SizeChanged; DisplayInformation.GetForCurrentView().DpiChanged += InputEvents_DpiChanged; _currentDipFactor = DisplayInformation.GetForCurrentView().LogicalDpi / 96.0f; if (inputElement is SwapChainPanel || inputElement is SwapChainBackgroundPanel) { // Create a thread to precess input events. var workItemHandler = new WorkItemHandler((action) => { var inputDevices = CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Pen | CoreInputDeviceTypes.Touch; if (inputElement is SwapChainBackgroundPanel) { _coreIndependentInputSource = ((SwapChainBackgroundPanel)inputElement).CreateCoreIndependentInputSource(inputDevices); } else { _coreIndependentInputSource = ((SwapChainPanel)inputElement).CreateCoreIndependentInputSource(inputDevices); } _coreIndependentInputSource.PointerPressed += CoreWindow_PointerPressed; _coreIndependentInputSource.PointerMoved += CoreWindow_PointerMoved; _coreIndependentInputSource.PointerReleased += CoreWindow_PointerReleased; _coreIndependentInputSource.PointerWheelChanged += CoreWindow_PointerWheelChanged; _coreIndependentInputSource.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessUntilQuit); }); var inputWorker = ThreadPool.RunAsync(workItemHandler, WorkItemPriority.High, WorkItemOptions.TimeSliced); } if (inputElement != null) { // If we have an input UIElement then we bind input events // to it else we'll get events for overlapping XAML controls. inputElement.PointerPressed += UIElement_PointerPressed; inputElement.PointerReleased += UIElement_PointerReleased; inputElement.PointerCanceled += UIElement_PointerReleased; inputElement.PointerMoved += UIElement_PointerMoved; inputElement.PointerWheelChanged += UIElement_PointerWheelChanged; } else { // If we only have a CoreWindow then use it for input events. window.PointerPressed += CoreWindow_PointerPressed; window.PointerReleased += CoreWindow_PointerReleased; window.PointerMoved += CoreWindow_PointerMoved; window.PointerWheelChanged += CoreWindow_PointerWheelChanged; } }
private SwapChainPanelInterop CreateSCPContent(ElementCompositeMode compositeMode, DXContentType dxContentType, float[] color, Rect?rect, int height = 200) { double scpWidth = scrollViewer.Width; double scpHeight = height; SwapChainPanel scp = new SwapChainPanel() { Width = scpWidth, Height = scpHeight, CompositeMode = compositeMode }; SwapChainPanelInterop scpInterop = scp; IDXGISwapChain1 swapChain = DXInteropHelper.CreateSwapChainForComposition(d3d11Device, (int)scpWidth, (int)scpHeight, false); scpInterop.SetSwapChain(swapChain); DrawDXContent(dxContentType, scpInterop, color, rect); scpInterop.CopyBuffers(1, 0); float compositionScaleX = 1; float compositionScaleY = 1; scp.CompositionScaleChanged += (s, e) => { compositionScaleX = scp.CompositionScaleX; compositionScaleY = scp.CompositionScaleY; try { scpInterop.ResizeBuffers((int)scp.Width, (int)scp.Height); } catch (System.Runtime.InteropServices.COMException ex) { if (ex.HResult == unchecked ((int)0x887A0005)) /* DXGI_ERROR_DEVICE_REMOVED */ { swapChain = DXInteropHelper.CreateSwapChainForComposition(d3d11Device, (int)scp.Width, (int)scp.Height, false); scpInterop.SetSwapChain(swapChain); } else { throw ex; } } DrawDXContent(dxContentType, scpInterop, color, rect); scpInterop.CopyBuffers(1, 0); }; StackPanel scpStackPanel = new StackPanel() { Orientation = Orientation.Vertical }; StackPanel sp = new StackPanel() { Orientation = Orientation.Horizontal }; TextBox scpWidthTB = new TextBox() { Height = 60, Header = "SCPWidth" }; TextBox scpHeightTB = new TextBox() { Height = 60, Header = "SCPHeight" }; Binding binding = new Binding() { Source = scp, Path = new PropertyPath("Width"), Mode = BindingMode.TwoWay }; scpWidthTB.SetBinding(TextBox.TextProperty, binding); binding = new Binding() { Source = scp, Path = new PropertyPath("Height"), Mode = BindingMode.TwoWay }; scpHeightTB.SetBinding(TextBox.TextProperty, binding); sp.Children.Add(scpWidthTB); sp.Children.Add(scpHeightTB); scpStackPanel.Children.Add(sp); StackPanel sp1 = new StackPanel() { Orientation = Orientation.Horizontal }; sp1.Children.Add(new TextBlock() { Text = "CoreInput" }); CheckBox coreinputEnabledCB = new CheckBox() { IsChecked = true, IsThreeState = false }; sp1.Children.Add(coreinputEnabledCB); sp1.Children.Add(new TextBlock() { Text = "Touch" }); CheckBox coreinputTouchCB = new CheckBox() { IsChecked = true, IsThreeState = false }; sp1.Children.Add(coreinputTouchCB); sp1.Children.Add(new TextBlock() { Text = "Mouse" }); CheckBox coreinputMouseCB = new CheckBox() { IsChecked = true, IsThreeState = false }; sp1.Children.Add(coreinputMouseCB); scpStackPanel.Children.Add(sp1); scp.Children.Add(scpStackPanel); bool enableTouchCoreInput = true; bool enableMouseCoreInput = true; CoreDispatcher coreInputDispatcher = null; CoreDispatcher xamlDispatcher = Window.Current.Dispatcher; Action coreInputThreadAction = () => { CoreInputDeviceTypes deviceTypes = CoreInputDeviceTypes.Pen; if (enableTouchCoreInput) { deviceTypes |= CoreInputDeviceTypes.Touch; } if (enableMouseCoreInput) { deviceTypes |= CoreInputDeviceTypes.Mouse; } CoreIndependentInputSource coreInput = scp.CreateCoreIndependentInputSource(deviceTypes); coreInputDispatcher = coreInput.Dispatcher; xamlDispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { coreinputEnabledCB.Unchecked += (s4, e4) => { coreInputDispatcher.RunAsync(CoreDispatcherPriority.High, () => { coreInput.IsInputEnabled = false; }); }; coreinputEnabledCB.Checked += (s4, e4) => { coreInputDispatcher.RunAsync(CoreDispatcherPriority.High, () => { coreInput.IsInputEnabled = true; }); }; }); coreInput.PointerPressed += (s, e) => { scpInterop.UpdateSurfaceWithD2DEllipse(new Point(e.CurrentPoint.Position.X * compositionScaleX, e.CurrentPoint.Position.Y * compositionScaleY), 10.0f, new float[] { 1f, 0f, 1f, 1f }, true /*copyBuffers*/); }; coreInput.PointerMoved += (s1, e1) => { scpInterop.UpdateSurfaceWithD2DEllipse(new Point(e1.CurrentPoint.Position.X * compositionScaleX, e1.CurrentPoint.Position.Y * compositionScaleY), 10.0f, new float[] { 0f, 0f, 1f, 1f }, true /*copyBuffers*/); }; coreInput.PointerReleased += (s2, e2) => { scpInterop.UpdateSurfaceWithD2DEllipse(new Point(e2.CurrentPoint.Position.X * compositionScaleX, e2.CurrentPoint.Position.Y * compositionScaleY), 10.0f, new float[] { 0f, 0f, 1f, 1f }, true /*copyBuffers*/); // Marking this unhandled so that AppBar can be invoked by letting the right click go through CoreInput which then raises WM_ContextMenu // that calls handles in xaml framework which marshalles the call to the UIthread to toggle AppBar. e2.Handled = false; }; coreInputDispatcher.ProcessEvents(CoreProcessEventsOption.ProcessUntilQuit); }; Action startCoreInputThread = () => { Windows.System.Threading.ThreadPool.RunAsync((asyncAction) => { if (coreInputDispatcher != null) { coreInputDispatcher.StopProcessEvents(); coreInputDispatcher = null; } coreInputThreadAction(); }, WorkItemPriority.High); }; startCoreInputThread(); coreinputTouchCB.Checked += (x, y) => { enableTouchCoreInput = true; startCoreInputThread(); }; coreinputTouchCB.Unchecked += (x, y) => { enableTouchCoreInput = false; startCoreInputThread(); }; coreinputMouseCB.Checked += (x, y) => { enableMouseCoreInput = true; scp.CompositeMode = (ElementCompositeMode)(((int)scp.CompositeMode + 1) % 4); startCoreInputThread(); }; coreinputMouseCB.Unchecked += (x, y) => { enableMouseCoreInput = false; startCoreInputThread(); }; return(scpInterop); }
public CoreIndependentInputSourceEvents(CoreIndependentInputSource This) { this.This = This; }