public void initialize() { this.selectedBrick = null; this.previousTap = null; this.blockTangibleLastInContact = null; this.lastFineCameraInformation = null; this.rotateOrZoom = false; this.holdingTouchPointID = -1; this.activeTouchPoints = new Dictionary<int, TouchPoint>(); this.holdingTouchPointIds = new List<int>(); this.lastCorkScrewOrientation = -1; Manipulations2D enabledManipulations = Manipulations2D.Rotate | Manipulations2D.Scale | Manipulations2D.Translate; manipulationProcessor = new ManipulationProcessor2D(enabledManipulations); manipulationProcessor.Pivot = new ManipulationPivot2D(); manipulationProcessor.Pivot.Radius = 10; manipulationProcessor.Started += OnManipulationStarted; manipulationProcessor.Delta += OnManipulationDelta; manipulationProcessor.Completed += OnManipulationCompleted; }
protected override void OnAttached() { base.OnAttached(); CanRotate = true; CanTranslate = true; CanScale = true; CanManipulate = true; _manipulationProcessor = new ManipulationProcessor2D(Manipulations2D.All); _manipulationProcessor.Started += OnManipulationStarted; _manipulationProcessor.Delta += OnManipulationDelta; _manipulationProcessor.Completed += OnManipulationCompleted; TouchHelper.AddHandlers(AssociatedObject, new TouchHandlers { TouchDown = OnTouchDown, CapturedTouchReported = OnCapturedTouchReported }); TouchHelper.EnableInput(true); TouchHelper.SetRootElement(TouchHelper.GetRootElement(AssociatedObject)); _renderTransform = AssociatedObject.RenderTransform as CompositeTransform; if (_renderTransform == null) { _renderTransform = new CompositeTransform(); AssociatedObject.RenderTransform = _renderTransform; } }
protected override void OnAttached() { base.OnAttached(); // Initializes the manipulation processor. _manipulationProcessor = new ManipulationProcessor2D(Manipulations2D.All); _manipulationProcessor.Started += OnManipulationStarted; _manipulationProcessor.Delta += OnManipulationDelta; _manipulationProcessor.Completed += OnManipulationCompleted; // Initializes the touch helper. TouchHelper.AddHandlers(AssociatedObject, new TouchHandlers { TouchDown = OnTouchDown, CapturedTouchReported = OnCapturedTouchReported }); TouchHelper.EnableInput(true); TouchHelper.SetRootElement(TouchHelper.GetRootElement(AssociatedObject)); _renderTransform = AssociatedObject.RenderTransform as CompositeTransform; if (_renderTransform == null) { throw new InvalidCastException(); } _initialCenter = new Point(_renderTransform.CenterX, _renderTransform.CenterY); }
// </Snippet_GamePiece_PrivateMembers> /*******************************************/ // <Snippet_GamePiece_Constructor> #region Constructor public GamePiece(SpriteBatch spriteBatch, string fileName) { // For brevity, omitting checking of null parameters. this.spriteBatch = spriteBatch; // Get the texture from the specified file. texture = Texture2D.FromFile(spriteBatch.GraphicsDevice, fileName); // Initial position set to 0,0. position = new Vector2(0); // Set the origin to be the center of the texture. origin = new Vector2(texture.Width / 2.0f, texture.Height / 2.0f); // Set bounds. bounds.X and bounds.Y are set as the position or scale changes. bounds = new Rectangle(0, 0, texture.Width, texture.Height); // Create manipulation processor. Manipulations2D enabledManipulations = Manipulations2D.Translate | Manipulations2D.Rotate; manipulationProcessor = new ManipulationProcessor2D(enabledManipulations); manipulationProcessor.Pivot = new ManipulationPivot2D(); manipulationProcessor.Pivot.Radius = texture.Width / 2; manipulationProcessor.MinimumScaleRotateRadius = 10.0f; manipulationProcessor.Started += OnManipulationStarted; manipulationProcessor.Delta += OnManipulationDelta; manipulationProcessor.Completed += OnManipulationCompleted; // Create inertia processor. inertiaProcessor = new InertiaProcessor2D(); inertiaProcessor.Delta += OnInertiaDelta; inertiaProcessor.Completed += OnInertiaCompleted; inertiaProcessor.TranslationBehavior.DesiredDeceleration = 0.0001F; inertiaProcessor.RotationBehavior.DesiredDeceleration = 1e-6F; inertiaProcessor.ExpansionBehavior.DesiredDeceleration = 0.0001F; // Save the view port. Used to detect when the piece needs to bounce. viewport = spriteBatch.GraphicsDevice.Viewport; // Set the piece in a random location. Random random = new Random((int)Timestamp); X = random.Next(viewport.Width); Y = random.Next(viewport.Height); // Set a random orientation. rotation = (float)(random.NextDouble() * Math.PI * 2.0); dragPoint = new System.Windows.Point(double.NaN, double.NaN); pieceColor = Color.White; // Set scale to normal (100%) Scale = 1.0f; }
internal void ReportFrame(ICollection <IManipulator> manipulators) { Int64 timestamp = GetCurrentTimestamp(); LastTimestamp = (int)timestamp; // InputEventArgs timestamps are Int32 while the processors take Int64 int numManipulators = manipulators.Count; if (IsInertiaActive && (numManipulators > 0)) { // Inertia is active but now there are fingers, stop inertia _inertiaProcessor.Complete(timestamp); PushEventsToDevice(); } if (!IsManipulationActive && (numManipulators > 0)) { // Time to start a new manipulation ManipulationStartingEventArgs startingArgs = RaiseStarting(); if (!startingArgs.RequestedCancel && (startingArgs.Mode != ManipulationModes.None)) { // Determine if we allow single-finger manipulation if (startingArgs.IsSingleTouchEnabled || (numManipulators >= 2)) { SetContainer(startingArgs.ManipulationContainer); _mode = startingArgs.Mode; _pivot = startingArgs.Pivot; IList <ManipulationParameters2D> parameters = startingArgs.Parameters; _manipulationProcessor = new ManipulationProcessor2D(ConvertMode(_mode), ConvertPivot(_pivot)); if (parameters != null) { int count = parameters.Count; for (int i = 0; i < parameters.Count; i++) { _manipulationProcessor.SetParameters(parameters[i]); } } _manipulationProcessor.Started += OnManipulationStarted; _manipulationProcessor.Delta += OnManipulationDelta; _manipulationProcessor.Completed += OnManipulationCompleted; _currentManipulators.Clear(); } } } if (IsManipulationActive) { // A manipulation process is available to process this frame of manipulators UpdateManipulators(manipulators); _manipulationProcessor.ProcessManipulators(timestamp, CurrentManipulators); PushEventsToDevice(); } }
/// <summary> /// Called after the behavior is attached to an AssociatedObject. /// </summary> /// <remarks>Override this to hook up functionality to the AssociatedObject.</remarks> protected override void OnAttached() { _manipulationProcessor = new ManipulationProcessor2D(Manipulations2D.Rotate | Manipulations2D.Scale | Manipulations2D.TranslateX | Manipulations2D.TranslateY); _manipulationProcessor.Delta += ManipulationProcessor_Delta; AssociatedObject.PreviewTouchDown += ScrollViewerTouchHandler; AssociatedObject.PreviewTouchMove += ScrollViewerTouchHandler; AssociatedObject.PreviewTouchUp += ScrollViewerTouchHandler; }
public MainWindow() { InitializeComponent(); ManipulationProcessor2D = new ManipulationProcessor2D(Manipulations2D.All); ManipulationProcessor2D.Started += ManipulationProcessor2D_Started; ManipulationProcessor2D.Delta += ManipulationProcessor2D_Delta; ManipulationProcessor2D.Completed += ManipulationProcessor2D_Completed; StylusDown += MainWindow_StylusDown; StylusMove += MainWindow_StylusMove; StylusUp += MainWindow_StylusUp; }
/******************************************************************************/ #region Constructor public ManipulationItem() { InitializeComponent(); PivotButton.Click += OnPivotClick; // The DeadZone is a little red ring that shows the area inside which // no rotation or scaling will happen if you drag the mouse. We set // it to four times the size of the manipulation processor's MininumScaleRotateRadius. // Reason for the number: // - x2, because diameter = 2 * radius // - x2, because the number on the manipulation processor is radius from // the center of mass of the manipulators being used, which in the case // of this test app will be the midpoint between the mouse and the hub. //DeadZone.Width = 4 * minScaleRotateRadius; //DeadZone.Height = 4 * minScaleRotateRadius; manipulationProcessor = new ManipulationProcessor2D(Manipulations2D.None); manipulationProcessor.MinimumScaleRotateRadius = minScaleRotateRadius; manipulationProcessor.Started += OnManipulationStarted; manipulationProcessor.Started += OnManipulationStarted2; manipulationProcessor.Delta += OnManipulationDelta; manipulationProcessor.Completed += OnManipulationCompleted; inertiaProcessor = new InertiaProcessor2D(); inertiaProcessor.TranslationBehavior.DesiredDeceleration = 0.0001F; inertiaProcessor.RotationBehavior.DesiredDeceleration = 1e-6F; inertiaProcessor.ExpansionBehavior.DesiredDeceleration = 0.0001F; inertiaProcessor.Delta += OnManipulationDelta; inertiaProcessor.Completed += OnInertiaCompleted; inertiaTimer = new DispatcherTimer( DispatcherPriority.Input, Dispatcher.CurrentDispatcher); inertiaTimer.IsEnabled = false; inertiaTimer.Interval = TimeSpan.FromMilliseconds(25); inertiaTimer.Tick += OnTimerTick; pivot = new ManipulationPivot2D(); RenderTransformOrigin = new Point(0.5, 0.5); Radius = 75; Center = new Point(0, 0); IsPivotActive = true; Move(Radius, Radius, 0, 1); }
public DefaultProcessor(Game game, IViewManager viewManager, PhysicsManager physics ) { this.game = game; this.viewManager = viewManager; this.physics = physics; Manipulations2D enabledManipulations = Manipulations2D.Rotate | Manipulations2D.Scale | Manipulations2D.Translate; manipulationProcessor = new ManipulationProcessor2D(enabledManipulations); manipulationProcessor.Pivot = new ManipulationPivot2D(); manipulationProcessor.Pivot.Radius = 10; manipulationProcessor.Started += OnManipulationStarted; manipulationProcessor.Delta += OnManipulationDelta; manipulationProcessor.Completed += OnManipulationCompleted; }
/// <summary> /// Called when the behavior is being detached from its AssociatedObject, but before it has actually occurred. /// </summary> /// <remarks>Override this to unhook functionality from the AssociatedObject.</remarks> protected override void OnDetaching() { AssociatedObject.PreviewTouchDown -= ScrollViewerTouchHandler; AssociatedObject.PreviewTouchUp -= ScrollViewerTouchHandler; if (_scatterViewItem != null) { _scatterViewItem.PreviewTouchUp -= ScatterViewItem_PreviewContactUp; _scatterViewItem = null; } _manipulationProcessor.Delta -= ManipulationProcessor_Delta; _manipulationProcessor = null; base.OnDetaching(); }
/// <summary> /// Initialize the behavior /// </summary> protected override void OnAttached() { base.OnAttached(); //Initialise default values for public properties IsConstrainedToParentBounds = true; IsRotateEnabled = true; IsTranslateEnabled = true; IsScaleEnabled = true; IsPivotEnabled = true; AreFingersVisible = true; IsInertiaEnabled = true; AreManipulationsEnabled = true; MinimumScaleRadius = 60; MaximumScaleRadius = 240; IgnoredTypes = null; _manipulationProcessor = new ManipulationProcessor2D(SupportedManipulations); _manipulationProcessor.Started += OnManipulationStarted; _manipulationProcessor.Delta += OnManipulationDelta; _manipulationProcessor.Completed += OnManipulationCompleted; _inertiaProcessor = new InertiaProcessor2D { TranslationBehavior = { DesiredDeceleration = Deceleration }, RotationBehavior = { DesiredDeceleration = AngularDeceleration }, ExpansionBehavior = { DesiredDeceleration = ExpansionDeceleration } }; _inertiaProcessor.Delta += OnManipulationDelta; _inertiaProcessor.Completed += OnInertiaCompleted; _inertiaTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(30) }; _inertiaTimer.Tick += OnTimerTick; var centerX = (double)AssociatedObject.ActualWidth / 2 + (double)AssociatedObject.GetValue(Canvas.LeftProperty); var centerY = (double)AssociatedObject.ActualHeight / 2 + (double)AssociatedObject.GetValue(Canvas.TopProperty); AssociatedObject.RenderTransformOrigin = new Point(centerX, centerY); Move(new Point(centerX, centerY), 0, 100); InitializeAssociatedObject(AssociatedObject); }
/// <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(TouchPoint c) { Manipulations2D supportedManipulations = Manipulations2D.TranslateX | Manipulations2D.TranslateY | Manipulations2D.Rotate | Manipulations2D.Scale; // Create and initialize a manipulation processor with the supported manipulations. ManipulationProcessor2D mp = new ManipulationProcessor2D(supportedManipulations); // Add event handlers for manipulation events. mp.Started += new EventHandler <Manipulation2DStartedEventArgs>(OnAffine2DManipulationStarted); mp.Completed += new EventHandler <Manipulation2DCompletedEventArgs>(OnAffine2DManipulationCompleted); mp.Delta += new EventHandler <Manipulation2DDeltaEventArgs>(OnAffine2DDelta); _contactProcessors.Add(c.Id, mp); }
/// <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. oldValue.PreviewTouchDown -= ScatterViewItem_PreviewTouchDown; oldValue.PreviewTouchUp -= ScatterViewItem_PreviewTouchUp; oldValue.PreviewTouchMove -= ScatterViewItem_PreviewTouchMove; oldValue.ContainerManipulationDelta -= ScatterViewItem_ContainerManipulationDelta; _scatterManipulationProcessor.Delta -= ScatterManipulationProcessor_Delta; _scatterManipulationProcessor = null; } if (ScatterViewItem != null) { // Set up the new SVI. ScatterViewItem.PreviewTouchDown += ScatterViewItem_PreviewTouchDown; ScatterViewItem.PreviewTouchUp += ScatterViewItem_PreviewTouchUp; ScatterViewItem.PreviewTouchMove += ScatterViewItem_PreviewTouchMove; ScatterViewItem.ContainerManipulationDelta += ScatterViewItem_ContainerManipulationDelta; _scatterManipulationProcessor = new ManipulationProcessor2D(Manipulations2D.Scale); _scatterManipulationProcessor.Delta += ScatterManipulationProcessor_Delta; } }
public EditorWndCtx(Canvas canv, DistributedInkCanvas inkCanv, Palette palette, InkPalette inkPalette, PortableWindow keyboardWnd, int topicId, int discussionId, bool shapesVisibility) { _canv = canv; _inkCanv = inkCanv; _palette = palette; _keyboardWnd = keyboardWnd; _zoomManipProc = new ManipulationProcessor2D(Manipulations2D.All); mgr = new SceneManager(canv, inkCanv, palette, inkPalette, topicId, discussionId, shapesVisibility); SetListeners(true); //poinManipDeferrer = new DispatcherTimer(); //poinManipDeferrer.Interval = TimeSpan.FromMilliseconds(260); //poinManipDeferrer.Tick += manipDeferrerTick; }
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 ManipulationProcessor2D(Manipulations2D.Scale | Manipulations2D.TranslateX | Manipulations2D.TranslateY); _contentManipulationProcessor.Started += ContentManipulationProcessor_Affine2DManipulationStarted; _contentManipulationProcessor.Delta += ContentManipulationProcessor_Affine2DManipulationDelta; _contentManipulationProcessor.Completed += ContentManipulationProcessor_Affine2DManipulationCompleted; // Set up the InertiaProcessor. _inertiaTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(30) }; _inertiaTimer.Tick += (sender, e) => _inertiaProcessor.Process(DateTime.UtcNow.Ticks); _inertiaProcessor = new InertiaProcessor2D(); _inertiaProcessor.Delta += ContentManipulationProcessor_Affine2DManipulationDelta; _inertiaProcessor.Completed += (sender, e) => _inertiaTimer.Stop(); _inertiaProcessor.TranslationBehavior.DesiredDeceleration = (float)(96 * 1.5 * .001 * .001); #warning ElasticMargin has been deprecated. //// _inertiaProcessor.ElasticMargin = new Thickness(25); base.OnApplyTemplate(); }
/// <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(TouchPoint c) { Manipulations2D supportedManipulations = Manipulations2D.TranslateX | Manipulations2D.TranslateY | Manipulations2D.Rotate | Manipulations2D.Scale; // Create and initialize a manipulation processor with the supported manipulations. ManipulationProcessor2D mp = new ManipulationProcessor2D(supportedManipulations); // Add event handlers for manipulation events. mp.Started += new EventHandler<Manipulation2DStartedEventArgs>(OnAffine2DManipulationStarted); mp.Completed += new EventHandler<Manipulation2DCompletedEventArgs>(OnAffine2DManipulationCompleted); mp.Delta += new EventHandler<Manipulation2DDeltaEventArgs>(OnAffine2DDelta); _contactProcessors.Add(c.Id, mp); }
/// <summary> /// Called when this object is passed into the SetParameters /// method on a manipulation processor. /// </summary> /// <param name="processor"></param> internal abstract void Set(ManipulationProcessor2D processor);
/// <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 ManipulationProcessor2D(Manipulations2D.TranslateX | Manipulations2D.TranslateY); manipulationProcessor.Completed += OnAffine2DManipulationCompleted; stopwatch = Stopwatch.StartNew(); }
/// <summary> /// Set the flick to completed so that it stops moving. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void OnAffine2DInertiaCompleted(object sender, Manipulation2DCompletedEventArgs e) { processInertia = false; manipulationProcessor = null; if (inertiaProcessor != null) { inertiaProcessor.Delta -= OnAffine2DInertiaDelta; inertiaProcessor.Completed -= OnAffine2DInertiaCompleted; inertiaProcessor = null; } }
//==========================================================// /// <summary> /// Creates manipulation and inertis processors that support only this item's allowed manipulations. /// </summary> private void SetAllowedManipulations() { Manipulations2D supportedManipulations = ((canTranslate || canTranslateFlick) ? Manipulations2D.TranslateX | Manipulations2D.TranslateY : Manipulations2D.None) | ((canScale || canScaleFlick) ? Manipulations2D.Scale : Manipulations2D.None) | ((canRotate || canRotateFlick) ? Manipulations2D.Rotate : Manipulations2D.None); manipulationProcessor = new ManipulationProcessor2D(supportedManipulations); manipulationProcessor.Started += OnAffine2DManipulationStarted; manipulationProcessor.Delta += OnAffine2DDelta; manipulationProcessor.Completed += OnAffine2DManipulationCompleted; inertiaProcessor = new InertiaProcessor2D(); inertiaProcessor.Completed += OnAffine2DInertiaCompleted; inertiaProcessor.Delta += OnAffine2DDelta; }
internal void ReportFrame(ICollection<IManipulator> manipulators) { Int64 timestamp = GetCurrentTimestamp(); LastTimestamp = (int)timestamp; // InputEventArgs timestamps are Int32 while the processors take Int64 int numManipulators = manipulators.Count; if (IsInertiaActive && (numManipulators > 0)) { // Inertia is active but now there are fingers, stop inertia _inertiaProcessor.Complete(timestamp); PushEventsToDevice(); } if (!IsManipulationActive && (numManipulators > 0)) { // Time to start a new manipulation ManipulationStartingEventArgs startingArgs = RaiseStarting(); if (!startingArgs.RequestedCancel && (startingArgs.Mode != ManipulationModes.None)) { // Determine if we allow single-finger manipulation if (startingArgs.IsSingleTouchEnabled || (numManipulators >= 2)) { SetContainer(startingArgs.ManipulationContainer); _mode = startingArgs.Mode; _pivot = startingArgs.Pivot; IList<ManipulationParameters2D> parameters = startingArgs.Parameters; _manipulationProcessor = new ManipulationProcessor2D(ConvertMode(_mode), ConvertPivot(_pivot)); if (parameters != null) { int count = parameters.Count; for (int i = 0; i < parameters.Count; i++) { _manipulationProcessor.SetParameters(parameters[i]); } } _manipulationProcessor.Started += OnManipulationStarted; _manipulationProcessor.Delta += OnManipulationDelta; _manipulationProcessor.Completed += OnManipulationCompleted; _currentManipulators.Clear(); } } } if (IsManipulationActive) { // A manipulation process is available to process this frame of manipulators UpdateManipulators(manipulators); _manipulationProcessor.ProcessManipulators(timestamp, CurrentManipulators); PushEventsToDevice(); } }
//==========================================================// /// <summary> /// Constructor. Sets allowed manipulations and creates the manipulation processor. /// </summary> public XnaScatterView(UIController controller, string backgroundImage, int top, int bottom, int left, int right) : base(controller, right - left, bottom - top) { textureSourceFile = backgroundImage; transformedCenter = new Vector2(0, 0); topBoundary = top; bottomBoundary = bottom; leftBoundary = left; rightBoundary = right; Manipulations2D supportedManipulations = Manipulations2D.TranslateX | Manipulations2D.TranslateY | Manipulations2D.Scale; manipulationProcessor = new ManipulationProcessor2D(supportedManipulations); manipulationProcessor.Delta += OnAffine2DDelta; }
/// <summary> /// Returns the average of the captured touches in the ThumbList. /// </summary> /// <returns></returns> private float AverageCapturedTouchesInThumbList() { float average = 0; int count = 0; if (manipulationProcessor == null) { manipulationProcessor = new ManipulationProcessor2D(Manipulations2D.TranslateX); // The coordinate doesn't matter we always deal in 1 dimension. manipulationProcessor.Completed += OnAffine2DManipulationCompleted; } List<Manipulator2D> currentManipulators = new List<Manipulator2D>(); // Go through the touches which are captured on the thumb and average them. for (int i = 0; i < thumbCapturedTouchesList.Count; i++) { int id = thumbCapturedTouchesList[i]; // Make sure the touch is captured. if (TouchesCaptured.Contains(id)) { // Make sure we have hit test details for this touch. if (captureTouchesHitTestDetails.ContainsKey(id)) { Debug.Assert(distanceOffset.ContainsKey(id), "Offset wasn't calculated for this touch."); float offset = distanceOffset[id]; ScrollBarHitTestDetails details = captureTouchesHitTestDetails[id]; // The Manipulations should all run in screen space. Manipulator2D manipulator = new Manipulator2D(id, ToScreenSpace(details.Position - offset), 0); // Make sure the value of each touch accounts for offset. average += captureTouchesHitTestDetails[id].Position - offset; count++; currentManipulators.Add(manipulator); } else { Debug.Fail("The touch was captured, but wasn't in the hit test details dictionary."); } } else { // The touch was released so we need to remove it. thumbCapturedTouchesList.Remove(id); i--; } } manipulationProcessor.ProcessManipulators(stopwatch.Elapsed100Nanoseconds(), currentManipulators); // Don't divide by zero. if (count != 0) average = average / count; return average; }