public void ContactRemovedEvent()
		{
			ContactData contactData = GetContactData(0, ContactState.New);

			Run(() =>
				{
					window = new TestWindow();
					window.ContactRemoved += HandleEvent;
					window.PreviewContactRemoved += HandleEvent;
					window.Show();

					HwndSource source = (HwndSource)PresentationSource.FromVisual(window);
					contactData.Hwnd = source.Handle;

					RawMultitouchReport report = new RawMultitouchReport(CreateContact(contactData, 0, source));
					InputManager.Current.ProcessInput(report);

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

					Dispatcher.ExitAllFrames();

					resetEvent.Set();
				});

			resetEvent.WaitOne();

			Assert.AreEqual(2, events.Count);

			RoutedEventArgsInfo dequeue = events.Dequeue();
			Assert.AreEqual<RoutedEvent>(MultitouchScreen.PreviewContactRemovedEvent, dequeue.RoutedEvent);
			dequeue = events.Dequeue();
			Assert.AreEqual<RoutedEvent>(MultitouchScreen.ContactRemovedEvent, dequeue.RoutedEvent);
		}
示例#2
0
        UIElement GetTargetElement(Point position, UIElement root, RawMultitouchReport report)
        {
            DependencyObject captured;

            if (report.CaptureState == CaptureMode.Element)
            {
                captured = report.Captured;
            }
            else
            {
                captured = HitTest(root, position);
                if (captured != null && report.Captured != null && report.CaptureState == CaptureMode.SubTree)
                {
                    if (!IsPartOfSubTree(captured, report.Captured))
                    {
                        captured = report.Captured;
                    }
                }
            }
            if (captured != null)
            {
                DependencyObject currentObject = captured;
                UIElement        target        = currentObject as UIElement;
                while (target == null)
                {
                    currentObject = LogicalTreeHelper.GetParent(currentObject);
                    target        = currentObject as UIElement;
                }
                return(target);
            }
            return(null);
        }
示例#3
0
		public void UpdateFromPrevious(RawMultitouchReport previousReport)
		{
			Context.OverElement = previousReport.Context.OverElement;
			Context.ElementsList = previousReport.Context.ElementsList;
			CaptureState = previousReport.CaptureState;
			Captured = previousReport.Captured;
			Context.History = previousReport.Context.History;
			Context.History.Insert(0, previousReport.Context.Contact);
		}
 public void UpdateFromPrevious(RawMultitouchReport previousReport)
 {
     Context.OverElement  = previousReport.Context.OverElement;
     Context.ElementsList = previousReport.Context.ElementsList;
     CaptureState         = previousReport.CaptureState;
     Captured             = previousReport.Captured;
     Context.History      = previousReport.Context.History;
     Context.History.Insert(0, previousReport.Context.Contact);
 }
		void HandleContact(object sender, Framework.Input.ContactEventArgs e)
		{
			ContactContext context = new ContactContext(e.Contact, source.RootVisual as UIElement);
			RawMultitouchReport rawReport = new RawMultitouchReport(context);
			lock (lockContactsQueue)
			{
				contactsQueue.Enqueue(rawReport);
			}
			Dispatcher.BeginInvoke(DispatcherPriority.Input, inputManagerProcessInput, null);
		}
示例#6
0
        void HandleContact(object sender, Framework.Input.ContactEventArgs e)
        {
            ContactContext      context   = new ContactContext(e.Contact, source.RootVisual as UIElement);
            RawMultitouchReport rawReport = new RawMultitouchReport(context);

            lock (lockContactsQueue)
            {
                contactsQueue.Enqueue(rawReport);
            }
            Dispatcher.BeginInvoke(DispatcherPriority.Input, inputManagerProcessInput, null);
        }
示例#7
0
        void inputManager_PreNotifyInput(object sender, NotifyInputEventArgs e)
        {
            if (e.StagingItem.Input.RoutedEvent == PreviewRawInputEvent)
            {
                RawMultitouchReport report = e.StagingItem.Input as RawMultitouchReport;
                if (report != null && !report.Handled)
                {
                    report.Context.OverElement = GetTargetElement(report.Context.Contact.Position, report.Context.Root, report);

                    Contact contact;
                    if (!report.CleanUp)
                    {
                        if (ContactsManager.ExistingContacts.TryGetValue(report.Context.Contact.Id, out contact))
                        {
                            contact.InputArgs = report;
                        }
                        else
                        {
                            contact = new Contact(report);
                            ContactsManager.ExistingContacts[report.Context.Contact.Id] = contact;
                        }
                    }
                    else
                    {
                        contact           = ContactsManager.ExistingContacts[report.Context.Contact.Id];
                        contact.InputArgs = report;
                        report.Handled    = true;
                    }

                    UIElementsList mergedList;

                    report.Context.ElementsList = BuildElementsList(report, report.Context.OverElement, report.Context.ElementsList, out mergedList);
                    if (mergedList != null)
                    {
                        RaiseEnterLeave(contact, mergedList);
                    }

                    if (report.CleanUp)
                    {
                        if (report.Captured != null)
                        {
                            contact.Capture(null);
                        }
                        ContactsManager.ExistingContacts.Remove(contact.Id);
                    }
                }
            }
            Debug.Assert(e.StagingItem.Input.RoutedEvent != null, "routed event null");
        }
示例#8
0
        static UIElementsList BuildElementsList(RawMultitouchReport report, DependencyObject newOver, UIElementsList oldList, out UIElementsList mergedList)
        {
            UIElementsList newList = null;

            if (newOver != null)
            {
                newList = new UIElementsList(newOver);
                if (!report.CleanUp)
                {
                    BuildElementsList(newList, newOver);
                }
            }
            mergedList = UIElementsList.BuildDifference(newList, oldList);
            return(newList);
        }
示例#9
0
        object InputManagerProcessInput(object arg)
        {
            RawMultitouchReport report = null;

            lock (lockContactsQueue)
            {
                if (contactsQueue.Count > 0)
                {
                    report = contactsQueue.Dequeue();
                }
            }
            if (report != null)
            {
                inputManager.ProcessInput(report);
            }
            return(null);
        }
示例#10
0
		public void CaptureElement()
		{
			Run(() =>
				{
					window = new TestWindow();
					window.NewContact += HandleEvent;
					window.ContactMoved += HandleEvent;
					window.ContactRemoved += HandleEvent;
					window.Show();

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

					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);

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

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

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

					Dispatcher.ExitAllFrames();

					resetEvent.Set();

				});
			resetEvent.WaitOne();

			Assert.AreEqual(4, events.Count);

			RoutedEventArgsInfo dequeue = events.Dequeue();
			CheckContactEventArgs(dequeue, MultitouchScreen.NewContactEvent, window.testElement); // 100,100
			dequeue = events.Dequeue();
			CheckContactEventArgs(dequeue, MultitouchScreen.ContactMovedEvent, window.testElement); //130,100
			dequeue = events.Dequeue();
			CheckContactEventArgs(dequeue, MultitouchScreen.ContactMovedEvent, window.testElement); //200,100
			dequeue = events.Dequeue();
			CheckContactEventArgs(dequeue, MultitouchScreen.ContactRemovedEvent, window.testElement); //250,100
		}
示例#11
0
        void inputManager_PreProcessInput(object sender, PreProcessInputEventArgs e)
        {
            RoutedEvent routedEvent = e.StagingItem.Input.RoutedEvent;

            if (routedEvent == PreviewRawInputEvent)
            {
                RawMultitouchReport report = e.StagingItem.Input as RawMultitouchReport;
                if (report != null && !report.Handled)
                {
                    switch (report.Context.Contact.State)
                    {
                    case ContactState.New:
                        return;

                    case ContactState.Removed:
                    case ContactState.Moved:
                    {
                        Contact contact;
                        if (!ContactsManager.ExistingContacts.TryGetValue(report.Context.Contact.Id, out contact))
                        {
                            break;
                        }
                        report.UpdateFromPrevious(contact.InputArgs);
                        return;
                    }

                    default:
                        return;
                    }
                    report.Handled = true;
                }
            }
            else if (!MultitouchScreen.AllowNonContactEvents)
            {
                if (!IsContactEvent(routedEvent))
                {
                    e.StagingItem.Input.Handled = true;
                    e.Cancel();
                }
            }
            Debug.Assert(routedEvent != null, "routed event null");
        }
示例#12
0
        void PromoteRawToPreview(ProcessInputEventArgs e, RawMultitouchReport report)
        {
            ContactContext context     = report.Context;
            RoutedEvent    routedEvent = GetPreviewEventFromRawMultitouchState(context.Contact.State);

            if (report.Context.OverElement != null && routedEvent != null)
            {
                Contact          contact = ContactsManager.ExistingContacts[report.Context.Contact.Id];
                ContactEventArgs args;
                if (routedEvent == MultitouchScreen.PreviewNewContactEvent)
                {
                    args = new NewContactEventArgs(contact, report.Timestamp);
                }
                else
                {
                    args = new ContactEventArgs(contact, report.Timestamp);
                }
                args.RoutedEvent = routedEvent;
                args.Source      = report.Context.OverElement;
                e.PushInput(args, e.StagingItem);
            }
        }
示例#13
0
        void inputManager_PostProcessInput(object sender, ProcessInputEventArgs e)
        {
            InputEventArgs input = e.StagingItem.Input;

            if (input.RoutedEvent == PreviewRawInputEvent && !input.Handled)
            {
                PromoteRawToPreview(e, (RawMultitouchReport)input);
            }
            else if (input.Device != null && input.Device.GetType() == contactType)
            {
                if (!input.Handled)
                {
                    PromotePreviewToMain(e, input);
                }

                if (input.RoutedEvent == MultitouchScreen.ContactRemovedEvent)
                {
                    ContactEventArgs    args   = (ContactEventArgs)input;
                    RawMultitouchReport report = args.Contact.InputArgs.Clone();
                    report.CleanUp = true;
                    e.PushInput(report, e.StagingItem);
                }
            }
        }
示例#14
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();
		}
示例#15
0
		static UIElementsList BuildElementsList(RawMultitouchReport report, DependencyObject newOver, UIElementsList oldList, out UIElementsList mergedList)
		{
			UIElementsList newList = null;
			if (newOver != null)
			{
				newList = new UIElementsList(newOver);
				if (!report.CleanUp)
					BuildElementsList(newList, newOver);
			}
			mergedList = UIElementsList.BuildDifference(newList, oldList);
			return newList;
		}
示例#16
0
 internal Contact(RawMultitouchReport report)
 {
     InputArgs = report;
 }
示例#17
0
		internal Contact(RawMultitouchReport report)
		{
			InputArgs = report;
		}
示例#18
0
		UIElement GetTargetElement(Point position, UIElement root, RawMultitouchReport report)
		{
			DependencyObject captured;
			if (report.CaptureState == CaptureMode.Element)
				captured = report.Captured;
			else
			{
				captured = HitTest(root, position);
				if (captured != null && report.Captured != null && report.CaptureState == CaptureMode.SubTree)
				{
					if (!IsPartOfSubTree(captured, report.Captured))
						captured = report.Captured;
				}
			}
			if (captured != null)
			{
				DependencyObject currentObject = captured;
				UIElement target = currentObject as UIElement;
				while (target == null)
				{
					currentObject = LogicalTreeHelper.GetParent(currentObject);
					target = currentObject as UIElement;
				}
				return target;
			}
			return null;
		}
示例#19
0
		public void ContactHistory()
		{
			Run(() =>
				{
					window = new TestWindow();
					window.Show();

					ContactsManager manager = MultitouchLogic.Current.ContactsManager;

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

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

					Assert.AreEqual(1, manager.ExistingContacts.Count);
					Contact contact = manager.ExistingContacts.First().Value;
					Assert.AreEqual(0, contact.GetPoints(null).Count());

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

					Assert.AreEqual(1, manager.ExistingContacts.Count);
					contact = manager.ExistingContacts.First().Value;
					Assert.AreEqual(1, contact.GetPoints(null).Count());
                    
					report = new RawMultitouchReport(CreateContact(GetContactData(0, ContactState.Moved, new Point(130, 120)), 2, source));
					InputManager.Current.ProcessInput(report);

					Assert.AreEqual(1, manager.ExistingContacts.Count);
					contact = manager.ExistingContacts.First().Value;
					Assert.AreEqual(2, contact.GetPoints(null).Count());

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

					Assert.AreEqual(2, manager.ExistingContacts.Count);
					contact = manager.ExistingContacts.First().Value;
					Assert.AreEqual(2, contact.GetPoints(null).Count());
					contact = manager.ExistingContacts.ElementAt(1).Value;
					Assert.AreEqual(0, contact.GetPoints(null).Count());
                    
					report = new RawMultitouchReport(CreateContact(GetContactData(0, ContactState.Removed, new Point(130, 120)), 3, source));
					InputManager.Current.ProcessInput(report);

					Assert.AreEqual(1, manager.ExistingContacts.Count);
					contact = manager.ExistingContacts.First().Value;
					Assert.AreEqual(0, contact.GetPoints(null).Count());

					report = new RawMultitouchReport(CreateContact(GetContactData(1, ContactState.Moved, new Point(140, 120)), 3, source));
					InputManager.Current.ProcessInput(report);

					Assert.AreEqual(1, manager.ExistingContacts.Count);
					contact = manager.ExistingContacts.First().Value;
					Assert.AreEqual(1, contact.GetPoints(null).Count());

					report = new RawMultitouchReport(CreateContact(GetContactData(1, ContactState.Removed, new Point(140, 120)), 4, source));
					InputManager.Current.ProcessInput(report);

					Assert.AreEqual(0, manager.ExistingContacts.Count);

					Dispatcher.ExitAllFrames();
					resetEvent.Set();
				});
			resetEvent.WaitOne();
		}
示例#20
0
		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);
		}
示例#21
0
		void PromoteRawToPreview(ProcessInputEventArgs e, RawMultitouchReport report)
		{
			ContactContext context = report.Context;
			RoutedEvent routedEvent = GetPreviewEventFromRawMultitouchState(context.Contact.State);
			if (report.Context.OverElement != null && routedEvent != null)
			{
				Contact contact = ContactsManager.ExistingContacts[report.Context.Contact.Id];
				ContactEventArgs args;
				if (routedEvent == MultitouchScreen.PreviewNewContactEvent)
					args = new NewContactEventArgs(contact, report.Timestamp);
				else
					args = new ContactEventArgs(contact, report.Timestamp);
				args.RoutedEvent = routedEvent;
				args.Source = report.Context.OverElement;
				e.PushInput(args, e.StagingItem);
			}
		}
示例#22
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();
		}