public MultitouchButton()
 {
     MultitouchScreen.AddContactClickHandler(this, OnContactClick);
     MultitouchScreen.AddContactDownHandler(this, OnContactDown);
     MultitouchScreen.AddContactUpHandler(this, OnContactUp);
     MultitouchScreen.AddContactLeaveHandler(this, OnContactLeave);
 }
Пример #2
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;
        }
        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);
        }