void OnContactMoved(object sender, ContactEventArgs e) { if(IsDragging) { Point currentPosition = e.GetPosition(this); if (currentPosition != lastThumbPosition) { e.Handled = true; RaiseEvent(new DragDeltaEventArgs(currentPosition.X - lastThumbPosition.X, currentPosition.Y - lastThumbPosition.Y)); lastThumbPosition = currentPosition; } } }
void OnGotContactCapture(object sender, ContactEventArgs e) { if (!IsDragging) { IsDragging = true; screenTotalDelta = new Vector(); originalThumbPosition = e.GetPosition(this); lastThumbPosition = originalThumbPosition; bool failed = true; try { RaiseEvent(new DragStartedEventArgs(originalThumbPosition.X, originalThumbPosition.Y)); failed = false; } finally { if (failed) CancelDrag(); } } }
void OnGotContactCapture(object sender, ContactEventArgs e) { FrameworkElement element = (FrameworkElement)e.Source; FrameworkElement container = ItemsControl.ContainerFromElement(null, element) as FrameworkElement; if (container != null) element = container; Body body; if (elementToBody.TryGetValue(element, out body)) { Point position = e.GetPosition(this); Vector2D contactPoint = position.ToVector2D(); if (body.Shape.CanGetIntersection) { Vector2D temp = body.Matrices.ToBody * contactPoint; IntersectionInfo intersectionInfo; if (body.Shape.TryGetIntersection(temp, out intersectionInfo)) { FixedHingeJoint joint = new FixedHingeJoint(body, contactPoint, new Lifespan()); joint.Softness = 0.3; engine.AddJoint(joint); contactJoints[e.Contact.Id] = joint; } } } SetZTop(element); }
void OnContactMoved(object sender, ContactEventArgs e) { Point position = e.GetPosition(this); FixedHingeJoint joint; if (contactJoints.TryGetValue(e.Contact.Id, out joint)) { joint.Anchor = position.ToVector2D(); //scale Body body = joint.Bodies.First(); FrameworkElement frameworkElement = body.Tag as FrameworkElement; if (frameworkElement != null && GetIsScalable(frameworkElement)) { ScaleState state; if (elementToScale.TryGetValue(frameworkElement, out state)) { IEnumerable<Contact> contacts = MultitouchScreen.GetContactsCaptured((IInputElement)e.Source); double previousDistance = 0; double currentDistance = 0; int divisor = 0; Contact[] contactsArray = contacts.ToArray(); Point center = new Point(frameworkElement.ActualWidth / 2, frameworkElement.ActualHeight / 2); for (int i = 0; i < contactsArray.Length; i++) { for (int j = i + 1; j < contactsArray.Length; j++) { Point currFirst = contactsArray[j].GetPosition(this); Point currSecond = contactsArray[i].GetPosition(this); Vector vector = frameworkElement.PointFromScreen(currFirst) - frameworkElement.PointFromScreen(currSecond); currentDistance += vector.Length; Point prevFirst = contactsArray[j].GetPoints(this).FirstOrDefault(); if (default(Point) == prevFirst) prevFirst = currFirst; Point prevSecond = contactsArray[i].GetPoints(this).FirstOrDefault(); if (default(Point) == prevSecond) prevSecond = currSecond; Vector previousVector = frameworkElement.PointFromScreen(prevFirst) - frameworkElement.PointFromScreen(prevSecond); previousDistance += previousVector.Length; divisor++; } } if (divisor == 0) divisor = 1; previousDistance /= divisor; currentDistance /= divisor; double delta = currentDistance / previousDistance; if (double.IsNaN(delta)) delta = 1; var newScale = state.Scale * delta; if (newScale > MaxScale) delta = MaxScale / state.Scale; else if (newScale < MinScale) delta = MinScale / state.Scale; state.Scale *= delta; state.Center = center; body.Transformation *= Matrix2x3.FromScale(new Vector2D(delta, delta)); } } } }
void OnContactLeave(object sender, ContactEventArgs e) { HitTestResult htr = VisualTreeHelper.HitTest(this, e.GetPosition(this)); if (htr != null) return; OnContactRemoved(sender, e); }
void OnContactMoved(object sender, ContactEventArgs e) { HitTestResult hitTestResult = VisualTreeHelper.HitTest(this, e.GetPosition(this)); if (hitTestResult != null) return; if (contactElements.ContainsKey(e.Contact.Id) && eltOffset.ContainsKey(contactElements[e.Contact.Id])) { var contactElement = contactElements[e.Contact.Id] as FrameworkElement; var offset = eltOffset[contactElements[e.Contact.Id]]; eltOffset.Remove(contactElements[e.Contact.Id]); RaiseElementDraggedEvent(contactElement, offset, e); e.Contact.ReleaseCapture(); } }
void OnContactMoved(object sender, ContactEventArgs e) { if (e.Contact.Id == firstContactId) { Point currentPoint = e.GetPosition(this); scrollJoint.Anchor = currentPoint.ToVector2D(); } }
/// <summary> /// when we drag a node we either want to delete it or move it. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void finger_Drag(object sender, ContactEventArgs e) { Point pos = e.GetPosition(drawingConfiguration.ellipse); Point currpos = new Point(drawingConfiguration.ellipse.Margin.Left, drawingConfiguration.ellipse.Margin.Top); bool nearLeft = currpos.X + pos.X - drawingConfiguration.ellipse.Width / 2 < 0; bool nearTop = currpos.Y + pos.Y - drawingConfiguration.ellipse.Height / 2 < 0; Int32 state = window.getAppState(); if (state == MainWindow.APPSTATE_DEFAULT) { moveThis(pos); } //if it's within the edge, then delete it }
/// <summary> /// When the ellipse is touched, we show that it's being selected /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void finger_Contact(object sender, ContactEventArgs e) { drawingConfiguration.selected = true; drawingConfiguration.ellipse.Fill = Brushes.Green; Int32 state = window.getAppState(); if (state == MainWindow.APPSTATE_CHOOSE_FIRST_NODE_TO_TOGGLE_CONNECTION || state == MainWindow.APPSTATE_CHOOSE_SECOND_NODE_TO_TOGGLE_CONNECTION) { window.makeConnection(data.number); } else if (state == MainWindow.APPSTATE_CHOOSE_NODE_TO_DELETE) { this.delete(); } else if (state == MainWindow.APPSTATE_CHOOSE_NODE_TO_EDIT) { window.editNode(this); } else if (state == MainWindow.APPSTATE_DEFAULT) { Point position = e.GetPosition(drawingConfiguration.ellipse); this.moveThis(position); } //Point pos = e.GetPosition(null); }
/// <summary> /// Called when contact is moved. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="Multitouch.Framework.WPF.Input.ContactEventArgs"/> instance containing the event data.</param> protected virtual void OnContactMoved(object sender, ContactEventArgs e) { Point position = e.GetPosition(this); if(points.ContainsKey(e.Contact.Id)) points[e.Contact.Id].Add(new StylusPoint(position.X, position.Y)); }
/// <summary> /// Called when is removed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="Multitouch.Framework.WPF.Input.ContactEventArgs"/> instance containing the event data.</param> protected virtual void OnContactRemoved(object sender, ContactEventArgs e) { Point position = e.GetPosition(this); StylusPointCollection pointCollection = points[e.Contact.Id]; pointCollection.Add(new StylusPoint(position.X, position.Y)); points.Remove(e.Contact.Id); Stroke stroke = new Stroke(pointCollection); raiseGestureOrStrokeCollectedMethod(this, new InkCanvasStrokeCollectedEventArgs(stroke), true); }