public void TouchMove(object sdr, Type t, TouchDevice touchDevice, TouchPoint touchPoint) { My_Point point = Point_List.UpdatePoint(sdr, t, touchDevice.Id, touchPoint); if (point != null && (t == typeof(Card_Layer))) { ///Show gesture indicator //if (point.Life > STATICS.MIN_GESTURE_LIFE) //{ // FrameworkElement sender = point.Sender as FrameworkElement; // lock (Point_List.TouchPointList) // { // if (!mainWindow.GestureIndicatorLayer.Contain(touchDevice.Id)) // { // mainWindow.GestureIndicatorLayer.Add(touchDevice.Id, touchPoint.Position); // } // else // { // mainWindow.GestureIndicatorLayer.Move(touchDevice.Id, touchPoint.Position); // } // } //} } }
/// <summary> /// Rotate the arrow to demonstrate orientation. /// </summary> /// <param name="touchDevice">the touch device to diagram</param> private void UpdateOrientationArrow(TouchDevice touchDevice) { bool isTag = touchDevice.GetIsTagRecognized(); UIElement relativeTo = this; double? touchDeviceOrientation = touchDevice.GetOrientation(relativeTo); // Only show orientation arrow if this touchDevice is recognized as a tag // and there is orientation data available. if (isTag && touchDeviceOrientation != null) { // Show the arrow. OrientationArrow.Visibility = Visibility.Visible; // Set the arrow orientation. ArrowRotateTransform.Angle = (double)touchDeviceOrientation; // Set the arrow position. Point position = touchDevice.GetPosition(relativeTo); ArrowTranslateTransform.X = position.X; ArrowTranslateTransform.Y = position.Y; } else { // Hide the arrow. OrientationArrow.Visibility = Visibility.Hidden; } }
private void CaptureCurrentDevice(TouchEventArgs e) { var gotTouch = CaptureTouch(e.TouchDevice); if (gotTouch) { _currentDevice = e.TouchDevice; } }
private void CaptureCurrentDevice(TouchEventArgs e) { bool gotTouch = this.CaptureTouch(e.TouchDevice); if (gotTouch) { this.currentDevice = e.TouchDevice; } }
/// <summary> /// Creates and setups event listeners for a new gesture engine. /// </summary> /// <param name="device">The touch device that caused started the potential gesture</param> /// <returns>The newly created engine</returns> protected IGestureEngine CreateAndSetupGestureEngine(TouchDevice device) { var engine = _engineCreator(); engine.TouchDevice = device; engine.GestureAborted += engine_GestureAborted; engine.GestureCompleted += engine_GestureCompleted; engine.GestureStarted += engine_GestureStarted; return engine; }
//point is relative to scene //public bool IsPressed(Point pt) //{ // if (pt.X < Canvas.GetLeft(outerEllipse)) // return false; // if (pt.X > Canvas.GetRight(outerEllipse)) // return false; // if (pt.Y < Canvas.GetTop(outerEllipse)) // return false; // if (pt.Y > Canvas.GetBottom(outerEllipse)) // return false; // return true; //} public void StartManip(Point p, TouchDevice td) { currPoint = p; isManipulated = true; this.CaptureMouse(); if (td!=null) this.CaptureTouch(td); }
private void ReleaseCurrentDevice() { if (this.currentDevice != null) { // Set the reference to null so that we don't re-capture in the OnLostTouchCapture() method var temp = this.currentDevice; this.currentDevice = null; this.ReleaseTouchCapture(temp); } }
/// <summary> /// Update this diagram with the most recent touch device data. /// </summary> /// <param name="parentGrid">the container for this diagram- /// description text will not go outside of this container's bounds</param> /// <param name="touchDevice">the touch device to diagram</param> public void Update(Grid parentGrid, TouchDevice touchDevice, bool showBoundingRect, bool showDescription) { // Update the two-tone Ellipse. UpdateEllipse(touchDevice); // Update the bounding rect on the touchDevice UpdateRectangle(touchDevice, showBoundingRect); // Update the arrow that demonstrates orientation. UpdateOrientationArrow(touchDevice); // Update the text description of the touchDevice properties. UpdateDescription(parentGrid, touchDevice, showDescription); }
public static Contact GetContact(TouchDevice device) { try { SurfaceTouchDevice surfaceDevice = device as SurfaceTouchDevice; if (surfaceDevice == null) return null; return surfaceDevice.Contact; } //Ignore InvalidOperationException due to race condition on Surface hardware catch (InvalidOperationException) { } return null; }
protected override void OnTouchDown(TouchEventArgs e) { _touchTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); _touchTimer.Interval = 30; _touchTimer.AutoReset = false; _touchTimer.Enabled = true; if (_touchPoints == 0) { _primaryDevice = e.TouchDevice; _isPressed = true; } _touchPoints++; if (_touchPoints == 2) _twoFingersDown = true; _touchOrigin = e.TouchDevice.GetTouchPoint(this).Position; //_isDragging = true; //Pass the Message Up base.OnTouchDown(e); }
/// <summary> /// logs an interaction /// </summary> /// <param name="parent"> Parent of the container</param> /// <param name="Td"></param> /// <param name="touched">button that was touched with</param> /// <param name="Container">container of the button touched</param> public static void Interaction(Object parent,TouchDevice Td,Object touched,Object Container) { string Device="Interacted with : "; if (Td.GetIsFingerRecognized()) { Device+= "TypeOfDevice: Finger"; } else if (Td.GetIsTagRecognized()) { Device+="TypeOfDevice: Tag"; } else { Device+="TypeOfDevice: Blob"; } WriteLog(Device + " X=" + Td.GetPosition((SurfaceWindow1)parent).X + ", Y=" + Td.GetPosition((SurfaceWindow1)parent).Y + " Angle=" + Td.GetOrientation((SurfaceWindow1)parent) + " ; " + Container.ToString() + "; " + touched.ToString()); }
protected override void OnTouchUp(TouchEventArgs e) { if (_touchPoints > 0) _touchPoints--; _twoFingersDown = false; _touchTimer.Enabled = false; if (e.TouchDevice == _primaryDevice) { _primaryDevice = null; } if (_touchPoints == 0) { _isDragging = false; _isPressed = false; _currentPosition = _translate.Y; } //Pass the message up base.OnTouchUp(e); }
private void Rectangle_TouchDown(object sender, TouchEventArgs e) { // Capture to the rectangle. //e.TouchDevice.Capture(this.blueRect); norrbotten.CaptureTouch(e.TouchDevice); // Remember this contact if a contact has not been remembered already. // This contact is then used to move the rectangle around. if (rectangleControlTouchDevice == null) { rectangleControlTouchDevice = e.TouchDevice; } firstPoint = rectangleControlTouchDevice.GetTouchPoint(this.MainGrid).Position; touchdownCount ++; // Mark this event as handled. e.Handled = true; }
/// <summary> /// Releases capture from the specified touch device. /// </summary> /// <param name="touchDevice">The device that is captured to this element.</param> /// <returns>true if capture was released, false otherwise.</returns> public bool ReleaseTouchCapture(TouchDevice touchDevice) { if (touchDevice == null) { throw new ArgumentNullException("touchDevice"); } if (touchDevice.Captured == this) { touchDevice.Capture(null); return true; } else { return false; } }
/// <summary> /// Captures the specified device to this element. /// </summary> /// <param name="touchDevice">The touch device to capture.</param> /// <returns>True if capture was taken.</returns> public bool CaptureTouch(TouchDevice touchDevice) { if (touchDevice == null) { throw new ArgumentNullException("touchDevice"); } return touchDevice.Capture(this); }
public TouchEventArgs(Vector2 location, TouchDevice touchDevice) { Location = location; TouchDevice = touchDevice; }
private KeyAssignment get_key(double x, double y, TouchDevice td) { y = y - margin_h - 5; if (y < 0) y = 0; int row = (int)(y / (button_height));// + margin_h)); if (row > rows.Count() - 1) row = rows.Count() - 1; int sum = rows[row][0]; int col = 0; while (x > sum) { col++; if (col == rows[row].Count()) col--; sum = sum + rows[row][col] + margin_w; } Rectangle r = new Rectangle(); r.Stroke = new SolidColorBrush(Colors.Black); r.StrokeThickness = 4; r.Height = button_height; r.Width = rows[row][col]; Canvas.SetLeft(r, sum - r.Width); Canvas.SetTop(r, row * (button_height + margin_h)); this.keyboard_canvas.Children.Add(r); if (!this.rectangles.ContainsKey(td)) this.rectangles.Add(td, r); else { this.keyboard_canvas.Children.Remove(this.rectangles[td]); this.rectangles.Remove(td); } return keys[row][col]; }
public GestureCompletedEventArgs(UIElement source, TouchDevice touchDevice) { Source = source; TouchDevice = touchDevice; }
private void avatar_drag(ListBoxItem element, TouchDevice touch_device) { if (element == null) return; item_generic i; try { i = (item_generic)element.DataContext;} catch(Exception) {return; } if (i.Tag == null) return; if (list_users) { string username_id = "user;" + ((int)i.Tag).ToString() + ";" + i.avatar.Source.ToString() + ";" + (string)i.username.Text; start_drag(element, username_id, touch_device, i.avatar.Source.Clone()); } if (list_design_ideas) { string idea = "design idea;" + ((int)i.Tag).ToString() + ";" + i.avatar.Source.ToString() + ";" + (string)i.username.Text + ";" + i.user_desc.Content + ";" + i.desc.Content + ";" + i.content.Text; start_drag(element, idea, touch_device, i.avatar.Source.Clone()); } if (list_comments) { string comment = "comment;" + ((int)i.Tag).ToString() + ";" + i.avatar.Source.ToString() + ";" + (string)i.username.Text + ";" + i.user_desc.Content + ";" + i.desc.Content + ";" + i.content.Text; start_drag(element, comment, touch_device, i.avatar.Source.Clone()); } if (list_activities) { string avatar = ""; if (i.avatar.Source != null) avatar = i.avatar.Source.ToString(); string activity = "activity;" + ((int)i.Tag).ToString() + ";" + avatar + ";" + (string)i.username.Text + ";" + i.user_desc.Content + ";" + i.desc.Content + ";" + i.content.Text; ImageSource img = null; if (i.avatar.Source != null) img = i.avatar.Source.Clone(); start_drag(element, activity, touch_device, img); } }
/// <summary> /// Gets a string that describes the type of touch device on the surface /// </summary> /// <param name="touchDevice">the touch device to be examined</param> /// <returns>a string that describes the type of touch device</returns> private static string GetTouchDeviceTypeString(TouchDevice touchDevice) { if (touchDevice.GetTagData() != TagData.None) { return "Tag"; } if (touchDevice.GetIsFingerRecognized()) { return "Finger"; } return "Blob"; }
/// <summary> /// Update ellipse with the most recent touch device data. If an ellipse has not /// been created yet, create one. /// </summary> /// <param name="touchDevice">the touch device to diagram</param> private void UpdateEllipse(TouchDevice touchDevice) { UIElement relativeTo = this; // Create an ellipse if one does not exist already. if (twoToneEllipse == null) { // Request an ellipse with the proper dimensions and RenderTransform. twoToneEllipse = touchDevice.GetEllipse(relativeTo); // Give the ellipse a two color fill. LinearGradientBrush twoToneBrush = new LinearGradientBrush(); twoToneBrush.StartPoint = new Point(1.0, 0.5); twoToneBrush.EndPoint = new Point(0.0, 0.5); GradientStopCollection gradientStops = new GradientStopCollection(); gradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF1, 0x57, 0x27), 0.49)); gradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF3, 0x7A, 0x53), 0.51)); twoToneBrush.GradientStops = gradientStops; twoToneEllipse.Fill = twoToneBrush; // Add the ellipse to the MainCanvas. MainCanvas.Children.Add(twoToneEllipse); // Give the Ellipse a lower ZIndex than the ConnectingLine and Description // so it is not drawn on top of them. Canvas.SetZIndex(twoToneEllipse, -1); } else { // This diagram already has an ellipse. Update the existing ellipse // dimensions and RenderTransform so the shape will match the touchDevice. touchDevice.UpdateEllipse(twoToneEllipse, relativeTo); } }
public TouchEventArgs(TouchDevice touchDevice, int timestamp) : base(touchDevice, timestamp) { }
private bool start_drag(ListBoxItem item, string username_id, TouchDevice touch_device, ImageSource i) { Image i2 = new Image(); i2.Source = i; i2.Stretch = Stretch.Uniform; item_generic i3 = (item_generic)item.Content; ContentControl cursorVisual = new ContentControl() { //Content = i2, Content = i3.get_clone(), Style = FindResource("CursorStyle") as Style }; //SurfaceDragDrop.AddTargetChangedHandler(cursorVisual, OnTargetChanged); List<InputDevice> devices = new List<InputDevice>(); devices.Add(touch_device); foreach (TouchDevice touch in item.TouchesCapturedWithin) { if (touch != touch_device) { devices.Add(touch); } } FrameworkElement element = item; if (configurations.use_avatar_drag) element = ((item_generic)(item.DataContext)).avatar; SurfaceDragCursor startDragOkay = SurfaceDragDrop.BeginDragDrop( this._list, // The SurfaceListBox object that the cursor is dragged out from. element, // The SurfaceListBoxItem object that is dragged from the drag source. cursorVisual, // The visual element of the cursor. username_id, // The data associated with the cursor. devices, // The input devices that start dragging the cursor. DragDropEffects.Copy); // The allowed drag-and-drop effects of the operation. return (startDragOkay != null); }
public TouchEventArgs(TouchDevice touchDevice, int timestamp) : base(default(InputDevice), default(int)) { }
private void RaiseGestureCompleted(UIElement element, TouchDevice device) { if (GestureCompleted != null) { GestureCompleted(this, new GestureCompletedEventArgs(element, device)); } }
public bool CaptureTouch(TouchDevice touchDevice);
private void Rectangle_TouchUp(object sender, TouchEventArgs e) { // If this contact is the one that was remembered if (e.TouchDevice == rectangleControlTouchDevice) { // Forget about this contact. rectangleControlTouchDevice = null; } if(touchdownCount <= 1) { box.Width = 100; box.Height = 50; box.Content = "lorem ipsum"; box.Background = new SolidColorBrush(Colors.Blue); box.Foreground = new SolidColorBrush(Colors.Orange); Canvas.SetLeft(box, lastPoint.X); Canvas.SetTop(box, lastPoint.Y); box.IsManipulationEnabled = true; box.TouchDown += Box_TouchDown; box.TouchMove += Box_TouchMove; box.TouchUp += Box_TouchUp; MainGrid.Children.Add(box); } // Mark this event as handled. e.Handled = true; }
/// <summary> /// Update the bounding rectangle with the most recent touch device info. If a /// rectangle has not been created yet, create one. /// </summary> /// <param name="touchDevice">the touch device to diagram</param> /// <param name="showBoundingRectangle">Whether or not the rectangle should be shown</param> private void UpdateRectangle(TouchDevice touchDevice, bool showBoundingRectangle) { // Create an rectangle if one does not exist already. if(boundingRectangle == null) { // Make a new Rectangle boundingRectangle = new Rectangle(); // Give the rectangle a fill. boundingRectangle.Fill = new SolidColorBrush(Color.FromArgb(0xFF, 0xE6, 0xE6, 0xE6)); // Add the rectangle to the MainCanvas. MainCanvas.Children.Add(boundingRectangle); // Give the rectangle a lower ZIndex than everything else on the main canvas // so it is not drawn on top of anything else Canvas.SetZIndex(boundingRectangle, int.MinValue ); } // Get the bounding rect for the touchDevice Rect touchDeviceRect = touchDevice.GetBounds(this); Rect bounds = new Rect(touchDeviceRect.X, touchDeviceRect.Y, touchDeviceRect.Width, touchDeviceRect.Height); // Update the properties of boundingRectangle boundingRectangle.Height = bounds.Height; boundingRectangle.Width = bounds.Width; Canvas.SetLeft(boundingRectangle, bounds.Left); Canvas.SetTop(boundingRectangle, bounds.Top); // Hide the rectangle if the user does not want to view bounding rectangles boundingRectangle.Visibility = showBoundingRectangle ? Visibility.Visible : Visibility.Hidden; }
public bool ReleaseTouchCapture(TouchDevice touchDevice);
/// <summary> /// Update the text description with the most recent property values. Position /// the textbox so that it does not go offscreen (outside parentGrid). Also /// position the connecting line between the touch device and the textbox. /// </summary> /// <param name="parentGrid">the container for this diagram- /// description text will not go outside of this container's bounds</param> /// <param name="touchDevice">the touch device to diagram</param> /// <param name="showTouchDeviceInfo">Whether or not the touch device info will be visible</param> private void UpdateDescription(Grid parentGrid, TouchDevice touchDevice, bool showTouchDeviceInfo) { // Show or hide the touchDevice info based on showTouchDeviceInfo Description.Visibility = showTouchDeviceInfo ? Visibility.Visible : Visibility.Hidden; ConnectingLine.Visibility = showTouchDeviceInfo ? Visibility.Visible : Visibility.Hidden; if (!showTouchDeviceInfo) { // Don't need to do the calculations if info isn't going to be shown return; } Point position = touchDevice.GetPosition(parentGrid); Rect bounds = new Rect(0, 0, parentGrid.ActualWidth, parentGrid.ActualHeight); // Determine where around the touchDevice the description should be displayed. // The default position is above and to the left. bool isAbove = true; bool isLeft = true; // Description text for tags is different than non-tags double descriptionXDistance; bool isTag = touchDevice.GetIsTagRecognized(); if (isTag) { descriptionXDistance = tagDescriptionXDistance; } else { descriptionXDistance = nonTagDescriptionXDistance; } // Put description below touchDevice if default location is out of bounds. Rect upperLeftBounds = GetDescriptionBounds(position, isAbove, isLeft, descriptionXDistance, descriptionYDistance); if (upperLeftBounds.Top < bounds.Top) { isAbove = false; } // Put description to the right of the touchDevice if default location is out of bounds. if (upperLeftBounds.Left < bounds.Left) { isLeft = false; } // Calculate the final bounds that will be used for the textbox position // based on the updated isAbove and isLeft values. Rect finalBounds = GetDescriptionBounds(position, isAbove, isLeft, descriptionXDistance, descriptionYDistance); Canvas.SetLeft(Description, finalBounds.Left); Canvas.SetTop(Description, finalBounds.Top); // Set the justification of the type in the textbox based // on which side of the touchDevice the textbox is on. if(isLeft) { Description.TextAlignment = TextAlignment.Right; } else { Description.TextAlignment = TextAlignment.Left; } // Create the description string. StringBuilder descriptionText = new StringBuilder(); descriptionText.AppendLine(String.Format(CultureInfo.InvariantCulture, "RecognizedTypes: {0}", GetTouchDeviceTypeString(touchDevice))); descriptionText.AppendLine(String.Format(CultureInfo.InvariantCulture, "Id: {0}", touchDevice.Id)); // Use the "f1" format specifier to limit the amount of decimal positions shown. descriptionText.AppendLine(String.Format(CultureInfo.InvariantCulture, "X: {0}", position.X.ToString("f1", CultureInfo.InvariantCulture))); descriptionText.AppendLine(String.Format(CultureInfo.InvariantCulture, "Y: {0}", position.Y.ToString("f1", CultureInfo.InvariantCulture))); // Display "null" for Orientation if the touchDevice does not have an orientation value. string orientationString; double? touchDeviceOrientation = touchDevice.GetOrientation(parentGrid); if (touchDeviceOrientation == null) { orientationString = "null"; } else { orientationString = ((double)touchDeviceOrientation).ToString("f1", CultureInfo.InvariantCulture); } descriptionText.AppendLine(String.Format(CultureInfo.InvariantCulture, "Orientation: {0}", orientationString)); if (touchDevice.GetTagData() != TagData.None) { descriptionText.AppendLine("Schema: 0x" + touchDevice.GetTagData().Schema.ToString("x8", CultureInfo.InvariantCulture)); descriptionText.AppendLine("Series: 0x" + touchDevice.GetTagData().Series.ToString("x16", CultureInfo.InvariantCulture)); descriptionText.AppendLine("ExtendedValue: 0x" + touchDevice.GetTagData().ExtendedValue.ToString("x16", CultureInfo.InvariantCulture)); descriptionText.AppendLine("Value: 0x" + touchDevice.GetTagData().Value.ToString("x16", CultureInfo.InvariantCulture)); } // Update the description textbox. Description.Text = descriptionText.ToString(); // Update the line that connects the touchDevice to the description textbox. double x2; if(isLeft) { x2 = finalBounds.Right; } else { x2 = finalBounds.Left; } // Position (X1,Y1) is the center of the touchDevice. // Position (X2,Y2) is the edge of the description text box. ConnectingLine.X1 = position.X; ConnectingLine.Y1 = position.Y; ConnectingLine.X2 = x2; ConnectingLine.Y2 = finalBounds.Top + finalBounds.Height * 0.5; }
public TouchDeviceWrapper(TouchDevice device) { _device = device; }
/// <summary> /// Retrieves the current touch point for ever touch device that is currently active. /// </summary> /// <param name="relativeTo">Defines the coordinate space of the touch point.</param> /// <returns>A collection of touch points.</returns> public TouchPointCollection GetTouchPoints(IInputElement relativeTo) { return(TouchDevice.GetTouchPoints(relativeTo)); }
/// <summary> /// Retrieves the current touch point of the primary touch device, if one exists. /// </summary> /// <param name="relativeTo">Defines the coordinate space of the touch point.</param> /// <returns>The touch point of the primary device or null if no device is a primary device.</returns> public TouchPoint GetPrimaryTouchPoint(IInputElement relativeTo) { return(TouchDevice.GetPrimaryTouchPoint(relativeTo)); }
public My_Point TouchUp(TouchDevice touchDevice, TouchPoint touchPoint) { if (mainWindow.GestureIndicatorLayer.Contain(touchDevice.Id)) { mainWindow.GestureIndicatorLayer.Remove(touchDevice.Id); } My_Point point = Point_List.ReleasePoint(touchDevice.Id); if (!isTouched()) { mainWindow.GestureIndicatorLayer.Clear(); } return point; }
public RightTappedEventArgs(TouchDevice touchDevice, int timestamp) : base(touchDevice, timestamp) { }