Beispiel #1
0
 /// <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());
 }
        /// <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;
            }
        }
        /// <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;
        }
Beispiel #4
0
        private void TryAddManipulator(TouchDevice td)
        {
            if (_manipulators.ContainsKey(td.Id))
                return;

            var pos = td.GetPosition(_keyboardWnd);
            _manipulators.Add(td.Id, new Manipulator2D(td.Id, (float) pos.X, (float) pos.Y));

            var pivot = new ManipulationPivot2D();
            if (_manipulators.Count > 1)
            {
                pivot.X = (_manipulators.Values.First().X + _manipulators.Values.Last().X)/2;
                pivot.Y = (_manipulators.Values.First().Y + _manipulators.Values.Last().Y)/2;
            }
            else
            {
                pivot.X = (float) pos.X;
                pivot.Y = (float) pos.Y;
            }
            pivot.Radius = (float) 1.0;
            _zoomManipProc.Pivot = pivot;
        }