Esempio n. 1
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);
        }