/// <summary> /// Creates a data message from raw message data, starting at a given offset in the raw data. /// </summary> /// <param name="rawMessage">The raw message data.</param> /// <param name="start">The index the recreation of the data message should be started at.</param> /// <returns>A data message of correct type, recreated from the raw data.</returns> public static DataMessage CreateFromRawMessage(byte[] rawMessage, int start) { // result DataMessage result = null; // inspect type var dataType = (DataType)BitConverter.ToInt32(rawMessage, start + 1); // simple switch here switch (dataType) { case DataType.ControllerInfo: result = new ControllerInfoData(); break; case DataType.Accelerometer: result = new AccelerometerData(); break; case DataType.Compass: result = new CompassData(); break; case DataType.Gyroscope: result = new GyroscopeData(); break; case DataType.Motion: result = new MotionData(); break; case DataType.Touch: result = new TouchData(); break; case DataType.Tap: result = new TapData(); break; case DataType.DoubleTap: result = new DoubleTapData(); break; case DataType.Hold: result = new HoldData(); break; case DataType.Flick: result = new FlickData(); break; case DataType.FreeDrag: result = new FreeDragData(); break; case DataType.HorizontalDrag: result = new HorizontalDragData(); break; case DataType.VerticalDrag: result = new VerticalDragData(); break; case DataType.DragComplete: result = new DragCompleteData(); break; case DataType.CustomDrag: result = new CustomDragData(); break; case DataType.CustomDragComplete: result = new CustomDragCompleteData(); break; case DataType.Pinch: result = new PinchData(); break; case DataType.PinchComplete: result = new PinchCompleteData(); break; case DataType.Text: result = new TextData(); break; } // fill from raw data if (result != null) { result.FromByteArray(rawMessage, start); } else { if (Debugger.IsAttached) { Debugger.Break(); } } return result; }
private void ProcessPinch(GestureSample gesture) { // convert first and second positions to logical coordinates var location = new Vector2(); CoordinateSystemHelper.CalculateLogicalPosition(location, gesture.Position); var location2 = new Vector2(); CoordinateSystemHelper.CalculateLogicalPosition(location2, gesture.Position2); // make sure the positions are valid if (!CoordinateSystemHelper.IsInActiveArea(location, InputMargin) || !CoordinateSystemHelper.IsInActiveArea(location2, InputMargin)) { return; } // project CoordinateSystemHelper.ProjectToActiveArea(location, InputMargin); CoordinateSystemHelper.ProjectToActiveArea(location2, InputMargin); _logger.Trace("Processing pinch gesture"); // set values var data = new PinchData(); data.TouchPoint = new TouchPoint { // Id and State are not really used here Id = 0, State = TouchPointState.Moved, Location = location }; data.TouchPoint2 = new TouchPoint { // Id and State are not really used here too Id = 0, State = TouchPointState.Moved, Location = location2 }; data.Delta = new Vector2(); CoordinateSystemHelper.AdjustLogicalAxis(data.Delta, gesture.Delta); data.Delta2 = new Vector2(); CoordinateSystemHelper.AdjustLogicalAxis(data.Delta2, gesture.Delta2); data.Timestamp = new DateTimeOffset(gesture.Timestamp.Ticks, TimeSpan.Zero); // notify _dataAcquiredCallback(data); }