/// <summary> /// Reads back custom data from a raw representation of the data message. /// </summary> /// <param name="reader">The binary reader used to read from the raw representation of the original data message.</param> protected override void ReadData(BinaryReader reader) { var dateTimeTicks = reader.ReadInt64(); var offsetTicks = reader.ReadInt64(); var offset = TimeSpan.FromTicks(offsetTicks); Timestamp = new DateTimeOffset(dateTimeTicks, offset); TouchPoint = new TouchPoint() { Id = reader.ReadInt32(), Location = new Vector2(reader.ReadSingle(), reader.ReadSingle()), State = (TouchPointState)reader.ReadInt32() }; }
/// <summary> /// Reads back custom data from a raw representation of the data message. /// </summary> /// <param name="reader">The binary reader used to read from the raw representation of the original data message.</param> protected override void ReadData(BinaryReader reader) { TouchPoints.Clear(); int count = reader.ReadInt32(); for (int i = 0; i < count; i++) { var point = new TouchPoint() { Id = reader.ReadInt32(), Location = new Vector2(reader.ReadSingle(), reader.ReadSingle()), State = (TouchPointState)reader.ReadInt32() }; TouchPoints.Add(point); } }
private void ProcessTouch() { var touchCollection = TouchPanel.GetState(); if (touchCollection.Count > 0) { // convert list List<TouchPoint> touchPoints = ConvertTouchPoints(touchCollection); // can be zero if points are outside of bounds if (touchPoints.Count > 0) { _logger.Trace("Processing raw touch/gesture input"); lock (_activeDataTypes) { // report touch? if (_activeDataTypes.Contains(DataType.Touch)) { var data = new TouchData(touchPoints); // pass on data to the outside world _dataAcquiredCallback(data); } // report drag? if (_activeDataTypes.Contains(DataType.CustomDrag)) { // use the first touch point var touchPoint = touchPoints[0]; // create the data var data = new CustomDragData(); data.TouchPoint = touchPoint; data.Delta = new Vector2(touchPoint.Location.X - _lastDragTouchPoint.Location.X, touchPoint.Location.Y - _lastDragTouchPoint.Location.Y); // new reference _lastDragTouchPoint = touchPoint; // send _dataAcquiredCallback(data); } } } } }
private List<TouchPoint> ConvertTouchPoints(TouchCollection touchCollection) { List<TouchPoint> result = new List<TouchPoint>(touchCollection.Count); foreach (var touch in touchCollection) { // convert to logical coordinates var location = new Vector2(); CoordinateSystemHelper.CalculateLogicalPosition(location, touch.Position); // check if this is valid if (!CoordinateSystemHelper.IsInActiveArea(location, InputMargin)) { continue; } // generate touch point var touchPoint = new TouchPoint(); touchPoint.Id = touch.Id; touchPoint.State = ConvertState(touch.State); // project CoordinateSystemHelper.ProjectToActiveArea(location, InputMargin); touchPoint.Location = location; result.Add(touchPoint); } return result; }