Example #1
0
        private void DragEllipse_TouchMove(object sender, TouchEventArgs e)
        {
            if (e.TouchDevice == ellipseControlTouchDevice)
            {
                // Get the current position of the contact.
                Point currentTouchPoint = ellipseControlTouchDevice.GetCenterPosition(this.MainCanvas);

                // Get the change between the controlling contact point and
                // the changed contact point.
                double deltaX = currentTouchPoint.X - lastPoint.X;
                double deltaY = currentTouchPoint.Y - lastPoint.Y;

                // Get and then set a new top position and a new left position for the ellipse.
                double newTop  = Canvas.GetTop(sender as Ellipse) + deltaY;
                double newLeft = Canvas.GetLeft(sender as Ellipse) + deltaX;

                Canvas.SetTop(sender as Ellipse, newTop);
                Canvas.SetLeft(sender as Ellipse, newLeft);

                // Forget the old contact point, and remember the new contact point.
                lastPoint = currentTouchPoint;

                // Mark this event as handled.
                e.Handled = true;
            }
        }
Example #2
0
        void Ellipse_TouchMove(object sender, System.Windows.Input.TouchEventArgs e)
        {
            if (runHandler)
            {
                if (e.TouchDevice == this.ellipseControlTouchDevice)
                {
                    if (timerReset == 10)
                    {
                        timer.Stop();
                        timer.Start();
                        timerReset = 0;
                    }

                    Ellipse x = sender as Ellipse;

                    timerReset++;

                    // Get the current position of the contact.
                    Point currentTouchPoint = ellipseControlTouchDevice.GetCenterPosition(this.mainCanvas);

                    // Get the change between the controlling contact point and
                    // the changed contact point.
                    deltaX = currentTouchPoint.X - lastPoint.X;
                    deltaY = currentTouchPoint.Y - lastPoint.Y;

                    // Get and then set a new top position and a new left position for the ellipse.
                    this.Position = new Vector(this.Position.X + (int)deltaX, this.Position.Y + (int)deltaY);

                    // Forget the old contact point, and remember the new contact point.
                    lastPoint = currentTouchPoint;

                    // Mark this event as handled.
                    // e.Handled = true;
                    if (!this.affectedByGravity)
                    {
                        this.gravPosition = this.Position;
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// Event wird aufgerufen wenn TouchMove auf Skalieren-Schaltfläche.
        /// Berechnet Skalierungsfaktor und speichert neue Touchpunkte.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Eventparameter</param>
        private void ScaleButtonMoved(object sender, TouchEventArgs e)
        {
            bool TwoWayScalePossibleX = true;
            bool TwoWayScalePossibleY = true;

            if (e.TouchDevice == _scaleControlTouchDevice)
            {
                // Get the current position of the contact.
                Point currentTouchPoint = _scaleControlTouchDevice.GetCenterPosition(this.MainGrid);
                // Point currentTouchPoint = _scaleControlTouchDevice.GetTouchPoint(this.MainGrid).Position;

                // Get the change between the controlling contact point and
                // the changed contact point.
                double deltaX = currentTouchPoint.X - _lastPoint.X;
                double deltaY = currentTouchPoint.Y - _lastPoint.Y;

                Point backupLastValidScalePoint = _lastValidScalePoint;

                // Width...

                UpdateLayout();
                double widthAndDeltaX = this.Width + deltaX;

                if (widthAndDeltaX > 545)
                {
                    if (!(_lastPoint.X < _lastValidScalePoint.X))
                    {
                        // 1
                        this.Width = widthAndDeltaX;
                        MainGrid.ColumnDefinitions[1].Width = new GridLength(MainGrid.ColumnDefinitions[1].ActualWidth + deltaX);
                        AdaptMainGridCol2Width();
                        _parentSVI.Center = new Point(_parentSVI.Center.X + (deltaX / 2), _parentSVI.Center.Y);

                        _lastValidScalePoint.X = currentTouchPoint.X;
                        // Console.WriteLine("Width Fall #1");
                    }
                    else if (deltaX > (_lastValidScalePoint.X - _lastPoint.X))
                    {
                        // 2
                        double diffDeltaXLastPoints = deltaX - (_lastValidScalePoint.X - _lastPoint.X);

                        this.Width = this.Width + diffDeltaXLastPoints;
                        MainGrid.ColumnDefinitions[1].Width = new GridLength(MainGrid.ColumnDefinitions[1].ActualWidth + diffDeltaXLastPoints);
                        AdaptMainGridCol2Width();
                        _parentSVI.Center = new Point(_parentSVI.Center.X + (diffDeltaXLastPoints / 2), _parentSVI.Center.Y);

                        _lastValidScalePoint.X = currentTouchPoint.X;
                        // Console.WriteLine("Width Fall #2");
                    }
                    else
                    {
                        // 3
                        this.Width = 545;
                        MainGrid.ColumnDefinitions[1].Width = new GridLength(30);
                        AdaptMainGridCol2Width();
                        _parentSVI.Center = new Point(_parentSVI.Center.X, _parentSVI.Center.Y);

                        _lastValidScalePoint.X = _lastValidScalePoint.X;
                        TwoWayScalePossibleX   = false;
                        // Console.WriteLine("Width Fall #3");
                    }
                }
                else
                {
                    // 4
                    double diffDeltaXWidths = deltaX + (545 - widthAndDeltaX);

                    this.Width = 545;
                    MainGrid.ColumnDefinitions[1].Width = new GridLength(30);
                    AdaptMainGridCol2Width();
                    _parentSVI.Center = new Point(_parentSVI.Center.X + (diffDeltaXWidths / 2), _parentSVI.Center.Y);

                    _lastValidScalePoint.X = _lastValidScalePoint.X + diffDeltaXWidths;
                    TwoWayScalePossibleX   = false;
                    // Console.WriteLine("Width Fall #4");
                }

                // Height...

                double heightAndDeltaY = this.Height + deltaY;

                if (heightAndDeltaY > _currentHeightRestriction)
                {
                    if (!(_lastPoint.Y < _lastValidScalePoint.Y))
                    {
                        // 1
                        this.Height = heightAndDeltaY;
                        MainGrid.RowDefinitions[3].Height = new GridLength(MainGrid.RowDefinitions[3].ActualHeight + deltaY);
                        _parentSVI.Center = new Point(_parentSVI.Center.X, _parentSVI.Center.Y + (deltaY / 2));

                        _lastValidScalePoint.Y = currentTouchPoint.Y;
                        // Console.WriteLine("Height Fall #1");
                    }
                    else if (deltaY > (_lastValidScalePoint.Y - _lastPoint.Y))
                    {
                        // 2
                        double diffDeltaYLastPoints = deltaY - (_lastValidScalePoint.Y - _lastPoint.Y);

                        this.Height = this.Height + diffDeltaYLastPoints;
                        MainGrid.RowDefinitions[3].Height = new GridLength(MainGrid.RowDefinitions[3].ActualHeight + diffDeltaYLastPoints);
                        _parentSVI.Center = new Point(_parentSVI.Center.X, _parentSVI.Center.Y + (diffDeltaYLastPoints / 2));

                        _lastValidScalePoint.Y = currentTouchPoint.Y;
                        // Console.WriteLine("Height Fall #2");
                    }
                    else
                    {
                        // 3
                        this.Height = _currentHeightRestriction;
                        MainGrid.RowDefinitions[3].Height = new GridLength(200);
                        _parentSVI.Center = new Point(_parentSVI.Center.X, _parentSVI.Center.Y);

                        _lastValidScalePoint.Y = _lastValidScalePoint.Y;
                        TwoWayScalePossibleY   = false;
                        // Console.WriteLine("Height Fall #3");
                    }
                }
                else
                {
                    // 4
                    double diffDeltaYHeights = deltaY + (_currentHeightRestriction - heightAndDeltaY);

                    this.Height = _currentHeightRestriction;
                    MainGrid.RowDefinitions[3].Height = new GridLength(200);
                    _parentSVI.Center = new Point(_parentSVI.Center.X, _parentSVI.Center.Y + (diffDeltaYHeights / 2));

                    _lastValidScalePoint.Y = _lastValidScalePoint.Y + diffDeltaYHeights;
                    TwoWayScalePossibleY   = false;
                    // Console.WriteLine("Height Fall #4");
                }
                // UpdateLayout();
                MainGrid.Width = this.Width;
                MainGrid.ColumnDefinitions[0].Width = new GridLength(390);
                ScaleGrid.Height = MainGrid.RowDefinitions[3].Height.Value;
                ModelGrid.Height = MainGrid.RowDefinitions[3].Height.Value;

                ScaleGrid.Width = MainGrid.ColumnDefinitions[0].Width.Value + MainGrid.ColumnDefinitions[1].Width.Value;
                ModelGrid.Width = ScaleGrid.Width - 30;

                ModelGrid.RowDefinitions[1].Height = new GridLength(ModelGrid.Height - 60);
                Model_InfoGrid.Height = ModelGrid.Height - 60;

                Model_InfoGrid.Width = ModelGrid.Width; // -30;

                _parentSVI.Height = this.Height;
                _parentSVI.Width  = this.Width;

                if (Hierarchy0Model.Name != "Open windows in ...")
                {
                    if (Model_InfoGrid.Width > 570)
                    {
                        ModelImg.Source = new BitmapImage(new Uri(@"../Images/hierarchy2UpModelText.png", UriKind.Relative));
                    }
                    else
                    {
                        ModelImg.Source = new BitmapImage(new Uri(@"../Images/hierarchy2UpModelBlank.png", UriKind.Relative));
                    }
                }

                if (!TwoWayScalePossibleX && !TwoWayScalePossibleY)
                {
                    ScaleOneWayImg.Visibility = System.Windows.Visibility.Visible;
                    ScaleTwoWayImg.Visibility = System.Windows.Visibility.Hidden;
                }
                else
                {
                    ScaleOneWayImg.Visibility = System.Windows.Visibility.Hidden;
                    ScaleTwoWayImg.Visibility = System.Windows.Visibility.Visible;
                }

                _lastPoint.X = currentTouchPoint.X;
                _lastPoint.Y = currentTouchPoint.Y;

                // Mark this event as handled.
                e.Handled = true;
            }
        }
        //Used to update the length visualisation and displys the bounding circle (using length as the radius)
        private void updateViews(TouchDevice callee)
        {
            // just want to know how WPF handles multi touches and events simulatenously(Observation: This states it is executed by Main: that means other threads just add the event to Main thread's queue :) )
            //Console.WriteLine("Calling Thread: " + Thread.CurrentThread + " Is background Thread? : " + Thread.CurrentThread.IsBackground);
            //update the booleans if there are no blobs/tags
            if (noOfBlobs == 0)
            {
                blobDetected = false;
            }
            else
            {
                blobDetected = true;
            }
            if (noOfTags == 0)
            {
                tagDetected = false;
            }
            else
            {
                tagDetected = true;
            }

            Double distance = 0;

            //Drag the length displayer closer to the calling canvas's point
            lengthDisplayer.SetValue(Canvas.LeftProperty, (Double)callee.GetCenterPosition(this).X + 200);
            lengthDisplayer.SetValue(Canvas.TopProperty, (Double)callee.GetCenterPosition(this).Y + 10);

            //update length
            if (blobDetected)
            {
                TouchDevice blob = blobTouchDevices.FirstOrDefault();
                //Console.WriteLine( "Blob List SIze" + blobTouchDevices.Count + "  TAG List Size : " + tagTouchDevices.Count);
                if (noOfBlobs == 1 && noOfTags == 1)
                {
                    distance             = getDistance(blobTouchDevices[0].GetCenterPosition(this), tagTouchDevices[0].GetCenterPosition(this));
                    lengthDisplayer.Text = "Blob to Tag Distance: " + distance;
                    if (!blob.Equals(callee))
                    {
                        displayBoundingEllipse(distance, blob.GetCenterPosition(this));
                    }
                }
                else if (noOfBlobs == 2)
                {
                    distance             = getDistance(blobTouchDevices[0].GetCenterPosition(this), blobTouchDevices[1].GetCenterPosition(this));
                    lengthDisplayer.Text = "Blobs Distance: " + distance;
                    displayBoundingEllipse(distance, blobTouchDevices[0].GetCenterPosition(this));
                }
            }
            else if (tagDetected)
            {//no blobs detected
                if (noOfTags == 2)
                {
                    distance             = getDistance(tagTouchDevices[0].GetCenterPosition(this), tagTouchDevices[1].GetCenterPosition(this));
                    lengthDisplayer.Text = "Tags Distance: " + distance;

                    TouchDevice bigTag;
                    //We are not interested in the moving part's tag. As we use the bigger tag for updating center of the bounding circle
                    if (tagTouchDevices[0] != callee)
                    {
                        bigTag = tagTouchDevices[0];
                    }
                    else
                    {
                        bigTag = tagTouchDevices[1];
                    }
                    displayBoundingEllipse(distance, bigTag.GetCenterPosition(this));
                }
            }
            else
            {
                lengthDisplayer.Text = "Input not supported.\n OR \nToo few/many inputs. ";
            }
        }