示例#1
0
        public void MultipleContactsCaptureSameObject()
        {
            Run(() =>
            {
                window             = new TestWindow();
                window.NewContact += HandleEvent;
                window.Show();

                HwndSource source = (HwndSource)PresentationSource.FromVisual(window);

                Assert.AreEqual(0, MultitouchScreen.GetContactsCaptured(window.testElement2).Count());
                Assert.AreEqual(0, MultitouchScreen.GetContactsCaptured(window.testElement).Count());
                window.ExecuteOnNextContact(c => c.Capture(window.testElement));

                RawMultitouchReport report = new RawMultitouchReport(CreateContact(GetContactData(0, ContactState.New, new Point(100, 100)), 0, source));
                InputManager.Current.ProcessInput(report);

                Assert.AreEqual(1, MultitouchScreen.GetContactsCaptured(window.testElement).Count());
                window.ExecuteOnNextContact(c => c.Capture(window.testElement));

                report = new RawMultitouchReport(CreateContact(GetContactData(1, ContactState.New, new Point(100, 100)), 1, source));
                InputManager.Current.ProcessInput(report);

                Assert.AreEqual(2, MultitouchScreen.GetContactsCaptured(window.testElement).Count());
                Assert.AreEqual(0, MultitouchScreen.GetContactsCaptured(window.testElement2).Count());

                Dispatcher.ExitAllFrames();
                resetEvent.Set();
            });
            resetEvent.WaitOne();
        }
示例#2
0
 void OnNewContact(object sender, NewContactEventArgs e)
 {
     if (ClickMode != ClickMode.Hover)
     {
         e.Handled = true;
         if (e.Contact.Capture(this))
         {
             IsPressed = true;
             if (ClickMode == ClickMode.Press && MultitouchScreen.GetContactsCaptured(this).Count() == 1)
             {
                 bool failed = true;
                 try
                 {
                     OnClick();
                     failed = false;
                 }
                 finally
                 {
                     if (failed)
                     {
                         IsPressed = false;
                         e.Contact.ReleaseCapture();
                     }
                 }
             }
         }
     }
 }
 public MultitouchButton()
 {
     MultitouchScreen.AddContactClickHandler(this, OnContactClick);
     MultitouchScreen.AddContactDownHandler(this, OnContactDown);
     MultitouchScreen.AddContactUpHandler(this, OnContactUp);
     MultitouchScreen.AddContactLeaveHandler(this, OnContactLeave);
 }
 void SubscribeEventsToChild(DependencyObject frameworkElement)
 {
     MultitouchScreen.AddGotContactCaptureHandler(frameworkElement, OnGotContactCapture);
     MultitouchScreen.AddLostContactCaptureHandler(frameworkElement, OnLostContactCapture);
     MultitouchScreen.AddNewContactHandler(frameworkElement, OnNewContact);
     MultitouchScreen.AddContactMovedHandler(frameworkElement, OnContactMoved);
     MultitouchScreen.AddContactRemovedHandler(frameworkElement, OnContactRemoved);
 }
 void UnsubscribeEventsFromChild(DependencyObject frameworkElement)
 {
     MultitouchScreen.RemoveGotContactCaptureHandler(frameworkElement, OnGotContactCapture);
     MultitouchScreen.RemoveLostContactCaptureHandler(frameworkElement, OnLostContactCapture);
     MultitouchScreen.RemoveNewContactHandler(frameworkElement, OnNewContact);
     MultitouchScreen.RemoveContactMovedHandler(frameworkElement, OnContactMoved);
     MultitouchScreen.RemoveContactRemovedHandler(frameworkElement, OnContactRemoved);
 }
示例#6
0
        public MouseHandler(MultitouchScreen screen)
        {
            this.screen = screen;
            Application.Current.Activated   += Current_Activated;
            Application.Current.Deactivated += Current_Deactivated;

            if (Application.Current.MainWindow != null)
            {
                Current_Activated(null, EventArgs.Empty);
            }
        }
示例#7
0
 void OnContactRemoved(object sender, ContactEventArgs e)
 {
     if (ClickMode != ClickMode.Hover)
     {
         e.Handled = true;
         if (e.Contact.Captured == this)
         {
             e.Contact.ReleaseCapture();
             if (MultitouchScreen.GetContactsCaptured(this).Count() == 0)
             {
                 StopTimer();
                 IsPressed = false;
             }
         }
     }
 }
示例#8
0
 void OnContactRemoved(object sender, ContactEventArgs e)
 {
     if (ClickMode != ClickMode.Hover)
     {
         e.Handled = true;
         if (e.Contact.Captured == this)
         {
             bool shouldMakeClick = IsPressed && ClickMode == ClickMode.Release;
             e.Contact.ReleaseCapture();
             if (MultitouchScreen.GetContactsCaptured(this).Count() == 0)
             {
                 if (shouldMakeClick)
                 {
                     OnClick();
                 }
                 IsPressed = false;
             }
         }
     }
 }
示例#9
0
        /// <summary>
        ///
        /// </summary>
        public InkCanvas()
        {
            MultitouchScreen.AddNewContactHandler(this, OnNewContact);
            MultitouchScreen.AddContactLeaveHandler(this, OnContactLeave);
            MultitouchScreen.AddContactMovedHandler(this, OnContactMove);

            inkCanvas = new System.Windows.Controls.InkCanvas();
            key       = new object();
            DefaultDrawingAttributes = new DrawingAttributes();
            Strokes = new StrokeCollection();

            BindToInkCanvas(BackgroundProperty);
            BindToInkCanvas(DefaultDrawingAttributesProperty);
            BindToInkCanvas(EditingModeProperty);
            BindToInkCanvas(StrokesProperty);

            inkCanvas.DefaultDrawingAttributesReplaced += OnDefaultDrawingAttributesReplaced;
            inkCanvas.StrokeErasing   += OnStrokeErasing;
            inkCanvas.StrokesReplaced += OnStrokesReplaced;
            inkCanvas.StrokeCollected += OnCollected;
        }
示例#10
0
        public void TouchablePanelCapture()
        {
            Run(() =>
            {
                window = new TestWindow();
                window.Show();

                HwndSource source = (HwndSource)PresentationSource.FromVisual(window);

                Point rectPosition    = GetPosition(window.panel, window.rect, true);
                Point contactPosition = rectPosition;
                contactPosition.Offset(-20, 0);
                MultitouchScreen.AddContactEnterHandler(window.rect, (sender, e) => e.Contact.Capture((IInputElement)e.Source));

                RawMultitouchReport report = new RawMultitouchReport(CreateContact(GetContactData(0, ContactState.New, contactPosition), 1, source));
                InputManager.Current.ProcessInput(report);
                Assert.AreEqual(rectPosition, GetPosition(window.panel, window.rect, true));

                contactPosition.Offset(20, 0);
                report = new RawMultitouchReport(CreateContact(GetContactData(0, ContactState.Moved, contactPosition), 2, source));
                InputManager.Current.ProcessInput(report);
                Assert.AreEqual(rectPosition, GetPosition(window.panel, window.rect, true));

                contactPosition.Offset(20, 0);
                report = new RawMultitouchReport(CreateContact(GetContactData(0, ContactState.Moved, contactPosition), 3, source));
                InputManager.Current.ProcessInput(report);

                Point newPosition = rectPosition;
                newPosition.Offset(20, 0);

                Point position = GetPosition(window.panel, window.rect, true);
                Assert.AreNotEqual(rectPosition, position);
                Assert.AreEqual(newPosition, position);

                Dispatcher.ExitAllFrames();
                resetEvent.Set();
            });
            resetEvent.WaitOne();
        }
        public void EnterLeaveEvents()
        {
            Run(() =>
            {
                window = new TestWindow();

                window.PreviewNewContact += HandleEvent;
                window.NewContact        += HandleEvent;

                window.PreviewContactMoved += HandleEvent;
                window.ContactMoved        += HandleEvent;

                window.PreviewContactRemoved += HandleEvent;
                window.ContactRemoved        += HandleEvent;

                window.ContactEnter += HandleEvent;
                window.ContactLeave += HandleEvent;

                MultitouchScreen.AddContactEnterHandler(window.canvas, HandleEvent);
                MultitouchScreen.AddContactLeaveHandler(window.canvas, HandleEvent);

                window.testElement.ContactEnter += HandleEvent;
                window.testElement.ContactLeave += HandleEvent;

                window.Show();

                HwndSource source = (HwndSource)PresentationSource.FromVisual(window);

                RawMultitouchReport report = new RawMultitouchReport(CreateContact(GetContactData(0, ContactState.New, new Point(30, 100)), 0, source));
                InputManager.Current.ProcessInput(report);

                report = new RawMultitouchReport(CreateContact(GetContactData(0, ContactState.Moved, new Point(49, 100)), 1, source));
                InputManager.Current.ProcessInput(report);

                report = new RawMultitouchReport(CreateContact(GetContactData(0, ContactState.Moved, new Point(100, 100)), 2, source));
                InputManager.Current.ProcessInput(report);

                report = new RawMultitouchReport(CreateContact(GetContactData(0, ContactState.Moved, new Point(150, 100)), 3, source));
                InputManager.Current.ProcessInput(report);

                report = new RawMultitouchReport(CreateContact(GetContactData(0, ContactState.Moved, new Point(200, 100)), 4, source));
                InputManager.Current.ProcessInput(report);

                report = new RawMultitouchReport(CreateContact(GetContactData(0, ContactState.Removed, new Point(200, 100)), 5, source));
                InputManager.Current.ProcessInput(report);

                Dispatcher.ExitAllFrames();

                resetEvent.Set();
            });

            resetEvent.WaitOne();

            Assert.AreEqual(18, events.Count);

            RoutedEventArgsInfo dequeue = events.Dequeue();

            CheckContactEventArgs(dequeue, MultitouchScreen.ContactEnterEvent, window);             // 30,100
            dequeue = events.Dequeue();
            CheckContactEventArgs(dequeue, MultitouchScreen.PreviewNewContactEvent, window);
            dequeue = events.Dequeue();
            CheckContactEventArgs(dequeue, MultitouchScreen.NewContactEvent, window);
            dequeue = events.Dequeue();
            CheckContactEventArgs(dequeue, MultitouchScreen.PreviewContactMovedEvent, window);             // 49,100
            dequeue = events.Dequeue();
            CheckContactEventArgs(dequeue, MultitouchScreen.ContactMovedEvent, window);
            dequeue = events.Dequeue();
            CheckContactEventArgs(dequeue, MultitouchScreen.ContactEnterEvent, window.testElement);             //100,100
            dequeue = events.Dequeue();
            CheckContactEventArgs(dequeue, MultitouchScreen.ContactEnterEvent, window.canvas);
            dequeue = events.Dequeue();
            CheckContactEventArgs(dequeue, MultitouchScreen.PreviewContactMovedEvent, window.testElement);
            dequeue = events.Dequeue();
            CheckContactEventArgs(dequeue, MultitouchScreen.ContactMovedEvent, window.testElement);
            dequeue = events.Dequeue();
            CheckContactEventArgs(dequeue, MultitouchScreen.PreviewContactMovedEvent, window.testElement);             //150,100
            dequeue = events.Dequeue();
            CheckContactEventArgs(dequeue, MultitouchScreen.ContactMovedEvent, window.testElement);
            dequeue = events.Dequeue();
            CheckContactEventArgs(dequeue, MultitouchScreen.ContactLeaveEvent, window.testElement);             //200,100
            dequeue = events.Dequeue();
            CheckContactEventArgs(dequeue, MultitouchScreen.ContactLeaveEvent, window.canvas);
            dequeue = events.Dequeue();
            CheckContactEventArgs(dequeue, MultitouchScreen.PreviewContactMovedEvent, window);
            dequeue = events.Dequeue();
            CheckContactEventArgs(dequeue, MultitouchScreen.ContactMovedEvent, window);
            dequeue = events.Dequeue();
            CheckContactEventArgs(dequeue, MultitouchScreen.PreviewContactRemovedEvent, window);             //200,100
            dequeue = events.Dequeue();
            CheckContactEventArgs(dequeue, MultitouchScreen.ContactRemovedEvent, window);
            dequeue = events.Dequeue();
            CheckContactEventArgs(dequeue, MultitouchScreen.ContactLeaveEvent, window);
        }
        void OnContactMoved(object sender, ContactEventArgs e)
        {
            Point position = e.GetPosition(this);

            FixedHingeJoint joint;

            if (contactJoints.TryGetValue(e.Contact.Id, out joint))
            {
                joint.Anchor = position.ToVector2D();

                //scale
                Body             body             = joint.Bodies.First();
                FrameworkElement frameworkElement = body.Tag as FrameworkElement;
                if (frameworkElement != null && GetIsScalable(frameworkElement))
                {
                    ScaleState state;
                    if (elementToScale.TryGetValue(frameworkElement, out state))
                    {
                        IEnumerable <Contact> contacts = MultitouchScreen.GetContactsCaptured((IInputElement)e.Source);
                        double    previousDistance     = 0;
                        double    currentDistance      = 0;
                        int       divisor       = 0;
                        Contact[] contactsArray = contacts.ToArray();

                        Point center = new Point(frameworkElement.ActualWidth / 2, frameworkElement.ActualHeight / 2);

                        for (int i = 0; i < contactsArray.Length; i++)
                        {
                            for (int j = i + 1; j < contactsArray.Length; j++)
                            {
                                Point  currFirst  = contactsArray[j].GetPosition(this);
                                Point  currSecond = contactsArray[i].GetPosition(this);
                                Vector vector     = frameworkElement.PointFromScreen(currFirst) - frameworkElement.PointFromScreen(currSecond);
                                currentDistance += vector.Length;

                                Point prevFirst = contactsArray[j].GetPoints(this).FirstOrDefault();
                                if (default(Point) == prevFirst)
                                {
                                    prevFirst = currFirst;
                                }
                                Point prevSecond = contactsArray[i].GetPoints(this).FirstOrDefault();
                                if (default(Point) == prevSecond)
                                {
                                    prevSecond = currSecond;
                                }
                                Vector previousVector = frameworkElement.PointFromScreen(prevFirst) - frameworkElement.PointFromScreen(prevSecond);
                                previousDistance += previousVector.Length;
                                divisor++;
                            }
                        }
                        if (divisor == 0)
                        {
                            divisor = 1;
                        }

                        previousDistance /= divisor;
                        currentDistance  /= divisor;

                        double delta = currentDistance / previousDistance;
                        if (double.IsNaN(delta))
                        {
                            delta = 1;
                        }

                        var newScale = state.Scale * delta;
                        if (newScale > MaxScale)
                        {
                            delta = MaxScale / state.Scale;
                        }
                        else if (newScale < MinScale)
                        {
                            delta = MinScale / state.Scale;
                        }

                        state.Scale         *= delta;
                        state.Center         = center;
                        body.Transformation *= Matrix2x3.FromScale(new Vector2D(delta, delta));
                    }
                }
            }
        }
示例#13
0
 protected override void OnStartup(StartupEventArgs e)
 {
     screen = MultitouchScreen.Instace;
     base.OnStartup(e);
 }