public Form1() { InitializeSurfaceInput(); Affine2DManipulations supportedManipulations = Affine2DManipulations.TranslateX | Affine2DManipulations.TranslateY | Affine2DManipulations.Scale; manipulationProcessor = new Affine2DManipulationProcessor(supportedManipulations); manipulationProcessor.Affine2DManipulationStarted += OnAffine2DManipulationStarted; manipulationProcessor.Affine2DManipulationDelta += OnAffine2DDelta; manipulationProcessor.Affine2DManipulationCompleted += OnAffine2DManipulationCompleted; inertiaProcessor = new Affine2DInertiaProcessor(); inertiaProcessor.Affine2DInertiaCompleted += OnAffine2DInertiaCompleted; inertiaProcessor.Affine2DInertiaDelta += OnAffine2DDelta; Visible = true; InteractiveSurface interactiveSurface = InteractiveSurface.DefaultInteractiveSurface; if (interactiveSurface != null) { FormBorderStyle = FormBorderStyle.None; } UpdateWindowPosition(); // Set the application's orientation based on the current launcher orientation //currentOrientation = ApplicationLauncher.Orientation; // Subscribe to surface application activation events ApplicationLauncher.ApplicationActivated += OnApplicationActivated; ApplicationLauncher.ApplicationPreviewed += OnApplicationPreviewed; ApplicationLauncher.ApplicationDeactivated += OnApplicationDeactivated; }
public SurfaceVEMap() : base() { lastExpansionDelta = 0; downContacts = new List <Contact>(); this.manipulationProcessor = new Affine2DManipulationProcessor( Affine2DManipulations.TranslateX | Affine2DManipulations.TranslateY | Affine2DManipulations.Scale | Affine2DManipulations.Rotate, this, false); this.manipulationProcessor.Affine2DManipulationCompleted += new EventHandler <Affine2DOperationCompletedEventArgs>(manipulationProcessor_Affine2DManipulationCompleted); this.manipulationProcessor.Affine2DManipulationDelta += new EventHandler <Affine2DOperationDeltaEventArgs>(manipulationProcessor_Affine2DManipulationDelta); this.manipulationProcessor.Affine2DManipulationStarted += new EventHandler <Affine2DOperationStartedEventArgs>(manipulationProcessor_Affine2DManipulationStarted); this.inertiaProcessor = new Affine2DInertiaProcessor(); this.inertiaProcessor.Affine2DInertiaDelta += new EventHandler <Affine2DOperationDeltaEventArgs>(inertiaProcessor_Affine2DInertiaDelta); this.inertiaProcessor.Affine2DInertiaCompleted += new EventHandler <Affine2DOperationCompletedEventArgs>(inertiaProcessor_Affine2DInertiaCompleted); }
private void InitializeManipulationProcessor() { _manipulationProcessor = new Affine2DManipulationProcessor(Affine2DManipulations.Rotate, logo, _centerPoint); _manipulationProcessor.Affine2DManipulationDelta += OnManipulationDelta; }
/// <summary> /// Each Contact gets its own ManipulationProcessor assigned /// This way we can use the Manipulator data even if there are multiple Contacts /// </summary> /// <param name="c">Contact to add the Manipulator to</param> public void addManipulationProcessor(Contact c) { Affine2DManipulations supportedManipulations = Affine2DManipulations.TranslateX | Affine2DManipulations.TranslateY | Affine2DManipulations.Rotate | Affine2DManipulations.Scale; // Create and initialize a manipulation processor with the supported manipulations. Affine2DManipulationProcessor mp = new Affine2DManipulationProcessor(supportedManipulations); // Add event handlers for manipulation events. mp.Affine2DManipulationStarted += new EventHandler<Affine2DOperationStartedEventArgs>(OnAffine2DManipulationStarted); mp.Affine2DManipulationCompleted += new EventHandler<Affine2DOperationCompletedEventArgs>(OnAffine2DManipulationCompleted); mp.Affine2DManipulationDelta += new EventHandler<Affine2DOperationDeltaEventArgs>(OnAffine2DDelta); _contactProcessors.Add(c.Id, mp); }
/// <summary> /// Set the flick to completed so that it stops moving. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void OnAffine2DInertiaCompleted(object sender, Affine2DOperationCompletedEventArgs e) { processInertia = false; manipulationProcessor = null; if (inertiaProcessor != null) { inertiaProcessor.Affine2DInertiaDelta -= new EventHandler<Affine2DOperationDeltaEventArgs>(OnAffine2DInertiaDelta); inertiaProcessor.Affine2DInertiaCompleted -= new EventHandler<Affine2DOperationCompletedEventArgs>(OnAffine2DInertiaCompleted); inertiaProcessor = null; } }
/// <summary> /// Returns the average of the captured contacts in the ThumbList. /// </summary> /// <returns></returns> private float AverageCapturedContactsInThumbList() { float average = 0; int count = 0; if (manipulationProcessor == null) { manipulationProcessor = new Affine2DManipulationProcessor(Affine2DManipulations.TranslateX); // The coordinate doesn't matter we always deal in 1 dimension. manipulationProcessor.Affine2DManipulationCompleted += new EventHandler<Affine2DOperationCompletedEventArgs>(OnAffine2DManipulationCompleted); } List<Manipulator> currentManipulators = new List<Manipulator>(); List<Manipulator> removedManipulators = new List<Manipulator>(); // Go through the contacts which are captured on the thumb and average them. for (int i = 0; i < thumbCapturedContactsList.Count; i++) { int id = thumbCapturedContactsList[i]; // Make sure the contact is captured. if (ContactsCaptured.Contains(id)) { // Make sure we have hit test details for this contact. if (captureContactsHitTestDetails.ContainsKey(id)) { Debug.Assert(distanceOffset.ContainsKey(id), "Offset wasn't calculated for this contact."); float offset = distanceOffset[id]; ScrollBarHitTestDetails details = captureContactsHitTestDetails[id]; // The Manipulations should all run in screen space. Manipulator manipulator = new Manipulator(id, ToScreenSpace(details.Position - offset), 0); // Make sure the value of each contact accounts for offset. average += captureContactsHitTestDetails[id].Position - offset; count++; currentManipulators.Add(manipulator); } else { Debug.Fail("The contact was captured, but wasn't in the hit test details dictionary."); } } else { float offset = distanceOffset[id]; ScrollBarHitTestDetails details = captureContactsHitTestDetails[id]; // The Manipulations should all run in screen space. Manipulator manipulator = new Manipulator(id, ToScreenSpace(details.Position - offset), 0); removedManipulators.Add(manipulator); // The contact was released so we need to remove it. thumbCapturedContactsList.Remove(id); i--; } } manipulationProcessor.ProcessManipulators(stopwatch.ElapsedTicks, currentManipulators, removedManipulators); // Don't divide by zero. if (count != 0) average = average / count; return average; }
/// <summary> /// Initializes the surface input system. This should be called after any window /// initialization is done, and should only be called once. /// </summary> public override void Initialize() { surfaceComp = Game.Components.OfType<SurfaceComponent>().First(); System.Diagnostics.Debug.Assert(Game.Window.Handle != System.IntPtr.Zero, "Window initialization must be complete before InitializeSurfaceInput is called"); if (Game.Window.Handle == System.IntPtr.Zero) return; System.Diagnostics.Debug.Assert(contactTarget == null, "Surface input already initialized"); if (contactTarget != null) return; // Create a target for surface input. contactTarget = new ContactTarget(Game.Window.Handle, EventThreadChoice.OnBackgroundThread); contactTarget.EnableInput(); contactTarget.EnableImage(ImageType.Normalized); contactTarget.FrameReceived += new EventHandler<FrameReceivedEventArgs>(contactTarget_FrameReceived); CurrentContacts = contactTarget.GetState(); manipulationProcessor = new Affine2DManipulationProcessor(Affine2DManipulations.TranslateX | Affine2DManipulations.TranslateY | Affine2DManipulations.Rotate | Affine2DManipulations.Scale); manipulationProcessor.Affine2DManipulationDelta += new EventHandler<Affine2DOperationDeltaEventArgs>(manipulationDelta); manipulationProcessor.Affine2DManipulationStarted += (s, e) => IsManipulating = true; manipulationProcessor.Affine2DManipulationCompleted += (s, e) => IsManipulating = false; base.Initialize(); }
/// <summary> /// Fired when ScatterViewItem is changed. /// </summary> /// <param name="oldValue">The old value.</param> private void UpdateScatterViewItem(ScatterViewItem oldValue) { if (oldValue != null) { // Clean up the old SVI. ScatterViewItem.PreviewContactDown -= ScatterViewItem_PreviewContactDown; ScatterViewItem.PreviewContactUp -= ScatterViewItem_PreviewContactUp; ScatterViewItem.ScatterManipulationDelta -= ScatterViewItem_ScatterManipulationDelta; _scatterManipulationProcessor.Affine2DManipulationDelta -= ScatterManipulationProcessor_Affine2DManipulationDelta; _scatterManipulationProcessor = null; } if (ScatterViewItem != null) { // Set up the new SVI. ScatterViewItem.PreviewContactDown += ScatterViewItem_PreviewContactDown; ScatterViewItem.PreviewContactUp += ScatterViewItem_PreviewContactUp; ScatterViewItem.ScatterManipulationDelta += ScatterViewItem_ScatterManipulationDelta; _scatterManipulationProcessor = new Affine2DManipulationProcessor(Affine2DManipulations.Scale, ScatterViewItem); _scatterManipulationProcessor.Affine2DManipulationDelta += ScatterManipulationProcessor_Affine2DManipulationDelta; } }
public override void OnApplyTemplate() { // Set up the ContentPresenter. _content = GetTemplateChild("PART_Content") as ContentPresenter; _translate = new TranslateTransform(); _scale = new ScaleTransform(); _content.RenderTransform = new TransformGroup { Children = new TransformCollection { _scale, _translate } }; _content.RenderTransformOrigin = new Point(.5, .5); // Set up the spring animation. _spring = new Storyboard { Duration = TimeSpan.FromMilliseconds(200), FillBehavior = FillBehavior.Stop, DecelerationRatio = .6 }; _spring.Completed += Spring_Completed; _springScaleX = new DoubleAnimation { Duration = _spring.Duration, To = 1, DecelerationRatio = _spring.DecelerationRatio }; Storyboard.SetTarget(_springScaleX, _content); Storyboard.SetTargetProperty(_springScaleX, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)")); _spring.Children.Add(_springScaleX); _springScaleY = new DoubleAnimation { Duration = _spring.Duration, To = 1, DecelerationRatio = _spring.DecelerationRatio }; Storyboard.SetTarget(_springScaleY, _content); Storyboard.SetTargetProperty(_springScaleY, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)")); _spring.Children.Add(_springScaleY); _springTranslateX = new DoubleAnimation { Duration = _spring.Duration, To = 0, DecelerationRatio = _spring.DecelerationRatio }; Storyboard.SetTarget(_springTranslateX, _content); Storyboard.SetTargetProperty(_springTranslateX, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.X)")); _spring.Children.Add(_springTranslateX); _springTranslateY = new DoubleAnimation { Duration = _spring.Duration, To = 0, DecelerationRatio = _spring.DecelerationRatio }; Storyboard.SetTarget(_springTranslateY, _content); Storyboard.SetTargetProperty(_springTranslateY, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.Y)")); _spring.Children.Add(_springTranslateY); _spring.Begin(this, true); ClipToBounds = true; // Set up the ManipulationProcessor. _contentManipulationProcessor = new Affine2DManipulationProcessor(Affine2DManipulations.Scale | Affine2DManipulations.TranslateX | Affine2DManipulations.TranslateY, this); _contentManipulationProcessor.Affine2DManipulationStarted += ContentManipulationProcessor_Affine2DManipulationStarted; _contentManipulationProcessor.Affine2DManipulationDelta += ContentManipulationProcessor_Affine2DManipulationDelta; _contentManipulationProcessor.Affine2DManipulationCompleted += ContentManipulationProcessor_Affine2DManipulationCompleted; // Set up the InertiaProcessor. _inertiaProcessor = new Affine2DInertiaProcessor(); _inertiaProcessor.Affine2DInertiaDelta += ContentManipulationProcessor_Affine2DManipulationDelta; _inertiaProcessor.DesiredDeceleration = 96 * 1.5 * .001 * .001; _inertiaProcessor.ElasticMargin = new Thickness(25); base.OnApplyTemplate(); }
/// <summary> /// Creates a new ScrollViewerStateMachine. /// </summary> /// <param name="controller">The UIController which dispatches hit testing.</param> /// <param name="elementToScroll">The element which is scrolling.</param> public ScrollAdapter(UIController controller, UIElementStateMachine elementToScroll) { // By default scrolling should be allowed in both directions. Orientation = Orientation.Both; this.elementToScroll = elementToScroll; // Handle the ScrollBars for this ScrollViewer. horizontalScrollBarStateMachine = new ScrollBarStateMachine(controller, elementToScroll.NumberOfPixelsInHorizontalAxis, 0); horizontalScrollBarStateMachine.Orientation = Orientation.Horizontal; verticalScrollBarStateMachine = new ScrollBarStateMachine(controller, 0, elementToScroll.NumberOfPixelsInVerticalAxis); verticalScrollBarStateMachine.Orientation = Orientation.Vertical; // Default to 1 (full size). HorizontalViewportSize = 1; VerticalViewportSize = 1; horizontalScrollBarStateMachine.ValueChanged += OnHorizontalScrollBarStateMachineValueChanged; horizontalScrollBarStateMachine.ThumbChanged += OnHorizontalScrollBarStateMachineThumbChanged; horizontalScrollBarStateMachine.NumberOfPixelsInHorizontalAxisChanged += HorizontalScrollBarStateMachineNumberOfPixelsInHorizontalAxisChanged; verticalScrollBarStateMachine.ValueChanged += OnVerticalScrollBarStateMachineValueChanged; verticalScrollBarStateMachine.ThumbChanged += OnVerticalScrollBarStateMachineThumbChanged; verticalScrollBarStateMachine.NumberOfPixelsInVerticalAxisChanged += VerticalScrollBarStateMachineNumberOfPixelsInVerticalAxisChanged; // Manipulations should only cause translations, not rotations or scaling. manipulationProcessor = new Affine2DManipulationProcessor(Affine2DManipulations.TranslateX | Affine2DManipulations.TranslateY); manipulationProcessor.Affine2DManipulationCompleted += OnAffine2DManipulationCompleted; stopwatch = Stopwatch.StartNew(); }