Example #1
0
        private void tmInput_Tick(object sender, EventArgs e)
        {
            List <Touch> touches = pm.Touches.Values.ToList();

            if (touches.Count == 2)
            {
                FingerTransform ft = new FingerTransform(touches[0].X, touches[0].Y,
                                                         touches[1].X, touches[1].Y);

                if (oldFt != null)
                {
                    float dScale = 1 + (ft.Distance - oldFt.Distance) / oldFt.Distance;
                    Console.WriteLine(dScale);
                    scale *= dScale;
                    refreshImg();
                }
                oldFt = ft;
            }
            else
            {
                oldFt = null;
            }
        }
Example #2
0
        public virtual bool Think(List <Touch> allTouches, ref Touch stylus, ref Touch mouse, int screenWidth, int screenHeight)
        {
            bool         changes = false;
            List <Touch> fingers = new List <Touch>();

            for (int i = 0; i < allTouches.Count; i++)
            {
                if (allTouches[i].TouchDevice == TouchDevice.Finger &&
                    Collides(allTouches[i].X, allTouches[i].Y, screenWidth, screenHeight))
                {
                    fingers.Add(allTouches[i]);
                    allTouches.RemoveAt(i--);
                }
            }

            if (fingers.Count == 1 && lastTouch.X < 0)
            {
                // 1 Finger Down
                lastTouch = new Point(fingers[0].X, fingers[0].Y);
            }
            else if (fingers.Count == 1)
            {
                // 1 Finger Moved
                if (transformMove)
                {
                    int diffX = fingers[0].X - lastTouch.X;
                    int diffY = fingers[0].Y - lastTouch.Y;
                    lastTouch = new Point(fingers[0].X, fingers[0].Y);

                    Matrix3x3 translation = Matrix3x3.Translation(diffX, diffY);
                    intTransformation *= translation;
                    changes            = true;
                }
            }
            else if (fingers.Count != 1 && lastTouch.X >= 0)
            {
                // 1 Finger Up
                lastTouch = new Point(-1, -1);
            }

            if (fingers.Count == 2 && lastDblTouch == null)
            {
                // 2 Fingers Down
                lastDblTouch = new FingerTransform(fingers[0].X, fingers[0].Y,
                                                   fingers[1].X, fingers[1].Y);
            }
            else if (fingers.Count == 2)
            {
                // 2 Fingers Move
                FingerTransform ft = new FingerTransform(fingers[0].X, fingers[0].Y,
                                                         fingers[1].X, fingers[1].Y);
                int   pDiffX = ft.Position.X - lastDblTouch.Position.X;
                int   pDiffY = ft.Position.Y - lastDblTouch.Position.Y;
                float rDiff  = ft.Rotation - lastDblTouch.Rotation;
                float sDiff  = 1 + (ft.Distance - lastDblTouch.Distance) / lastDblTouch.Distance;
                lastDblTouch = ft;

                Matrix3x3 mat = new Matrix3x3();
                if (transformMove)
                {
                    mat.TransformTranslate(pDiffX, pDiffY);
                }
                if (transformRotate)
                {
                    mat.TransformRotateAt(-rDiff, ft.Position.X, ft.Position.Y);
                }
                if (transformScale)
                {
                    mat.TransformScaleAt(sDiff, sDiff, ft.Position.X, ft.Position.Y);
                }
                intTransformation *= mat;
                changes            = true;
            }
            else if (fingers.Count != 2 && lastDblTouch != null)
            {
                // 2 Finger Up
                lastDblTouch = null;
            }

            if (changes)
            {
                Transformation = new Matrix3x3(intTransformation);
            }

            return(changes);
        }