예제 #1
0
        public static void CursorAdded(TouchCursor b)
        {
            if (mutex.WaitOne(TimeSpan.FromSeconds(0.0), false))
            {
                _window.Dispatcher.BeginInvoke(DispatcherPriority.Input, (Action)(() =>
                {
                    System.Diagnostics.Debug.WriteLine(b.ID + "down");
                    if (Contacts.ContainsKey(b.ID))
                    {
                        return;
                    }

                    var device = new TouchProvider(b.ID);
                    device.SetActiveSource(PresentationSource.FromVisual(_window));
                    device.Position = new Point(b.X, b.Y);
                    device.width = b.Width;
                    device.height = b.Height;
                    device.Activate();
                    device.ReportDown();

                    if (!Contacts.ContainsKey(b.ID))
                    {
                        Contacts.Add(b.ID, device);
                    }
                }));
            }
        }
예제 #2
0
        private void myCanvas_TouchDown(object sender, TouchEventArgs e)
        {
            if (mutex == null)
            {
                mutex = new Mutex(false, "test");
            }

            if (mutex.WaitOne(TimeSpan.FromSeconds(0.0), false))
            {
                System.Diagnostics.Debug.WriteLine(e.TouchDevice.Id + "wdown");
                TouchPoint tp = e.GetTouchPoint(this);

                Ellipse ep = new Ellipse();
                ep.Width  = 50;
                ep.Height = 50;
                ep.Fill   = new SolidColorBrush(Colors.White);

                if (ht.Contains(e.TouchDevice.Id))
                {
                    if (ht.Count > 5) // test for human or woodpecker
                    {
                        TouchProvider.StopSimulation();
                        MessageBox.Show("I can't receive touchpoint id:" + e.TouchDevice.Id.ToString() + " up message. Please refer to re.log");
                        this.Close();
                    }
                }
                else
                {
                    ht.Add(e.TouchDevice.Id, ep);

                    myCanvas.Children.Add(ep);
                    ep.SetValue(Canvas.LeftProperty, tp.Position.X - tp.Size.Width / 2);
                    ep.SetValue(Canvas.TopProperty, tp.Position.Y - tp.Size.Height / 2);
                }
            }
        }
예제 #3
0
 public MainWindow()
 {
     InitializeComponent();
     TouchProvider.BeginSimulation(this, 0.03);
 }
예제 #4
0
        static void timer_Tick(object sender, EventArgs e)
        {
            if (mutex == null)
            {
                mutex = new Mutex(false, "test");
            }

            if (mutex.WaitOne(TimeSpan.FromSeconds(0.0), false))
            {
                System.Diagnostics.Debug.WriteLine("------------------------------------");
                int num = r.Next(MaxDownPointsFrame + 1);


                for (int i = 0; i < num; i++)
                {
                    System.Diagnostics.Debug.WriteLine(i.ToString() + "down point");
                    CursorAdded(TouchCursor.GetRandomCursor(GetAvailableID(), _w, _h));
                }

                for (int i = 0; i < Contacts.Count; i++)
                {
                    double probability = r.NextDouble();
                    if (probability < UpRate)
                    {
                        TouchProvider tp = Contacts.ElementAt(i).Value as TouchProvider;
                        TouchCursor   tc = new TouchCursor(tp.Id, tp.Position.X, tp.Position.Y);
                        CursorRemoved(tc);
                    }
                    else
                    {
                        TouchProvider tp = Contacts.ElementAt(i).Value as TouchProvider;
                        double        nx = tp.Position.X;
                        double        ny = tp.Position.Y;
                        if (r.NextDouble() < 0.5)
                        {
                            nx += MaxUpdateDistance * r.NextDouble();
                            if (nx >= _w)
                            {
                                nx = _w - 1;
                            }
                        }
                        else
                        {
                            nx -= MaxUpdateDistance * r.NextDouble();
                            if (nx < 0)
                            {
                                nx = 0;
                            }
                        }

                        if (r.NextDouble() < 0.5)
                        {
                            ny += MaxUpdateDistance * r.NextDouble();
                            if (ny > _h - 1)
                            {
                                ny = _h - 1;
                            }
                        }
                        else
                        {
                            ny -= MaxUpdateDistance * r.NextDouble();
                            if (ny < 0)
                            {
                                ny = 0;
                            }
                        }
                    }
                }
            }
        }