Ejemplo n.º 1
0
        static void Display_TouchXYEvent(object sender, Driver.TouchEventXYArgs args)
        {
            //Debouncing
            if (NextTouchAllowed > DateTime.Now)
            {
                return;
            }
            NextTouchAllowed = DateTime.Now.AddSeconds(1);

            Debug.Print("New XY touch");

            if (State == GameState.Score)
            {
                Debug.Print("Start new game");
                StartGame.Set();
            }
        }
Ejemplo n.º 2
0
        static void Display_TouchXYEvent(object sender, Driver.TouchEventXYArgs args)
        {
            //Process on other thread otherwise you will create deadlock.
            //Thread pool would be usefull in this case
            var newThread = new Thread(new ThreadStart(() =>
            {
                lock (threadLock)
                {
                    LastTouchXY = args;
                    if (SleepMode)
                    {
                        if (SleepAllowWakeup < DateTime.Now)
                        {
                            Display.SetSleepMode(false);
                            SleepMode = false;
                        }
                    }
                    else if (CurrentPage == Page.Ready)
                    {
                        SemaphoreXY.Set();
                    }
                    else if (CurrentPage == Page.Draw5)
                    {
                        //Debuncer
                        if (Draw5AllowNextTouch > DateTime.Now)
                        {
                            return;
                        }

                        if (Draw5Count >= 5)
                        {
                            Display.TouchMode = Driver.TouchMode.Component;
                            Display.PageId    = DisplayConfiguration.Page2.Id;
                            CurrentPage       = Page.DateTime;
                        }
                        else
                        {
                            DisplayConfiguration.Page3.txtX.Text = LastTouchXY.X.ToString();
                            DisplayConfiguration.Page3.txtY.Text = LastTouchXY.Y.ToString();

                            var color   = CricleColorPalete[Rand.Next(CricleColorPalete.Length - 1)];
                            int shapeId = Rand.Next(3);
                            if (shapeId == 0)
                            {
                                Display.GUI.DrawCircle(LastTouchXY.X, LastTouchXY.Y, 5, (int)color);
                            }
                            else if (shapeId == 1)
                            {
                                Display.GUI.DrawRectangle(LastTouchXY.X - 5, LastTouchXY.Y - 5, LastTouchXY.X + 5, LastTouchXY.Y + 5, (int)color);
                            }
                            else
                            {
                                Display.GUI.DrawRectangleFilled(LastTouchXY.X - 5, LastTouchXY.Y - 5, LastTouchXY.X + 5, LastTouchXY.Y + 5, (int)color);
                            }

                            if (Draw5Count > 0)
                            {
                                Display.GUI.DrawLine(Draw5LastX, Draw5LastY, LastTouchXY.X, LastTouchXY.Y, (int)Driver.Color.Black);
                            }

                            Draw5LastX = LastTouchXY.X;
                            Draw5LastY = LastTouchXY.Y;

                            Draw5AllowNextTouch = DateTime.Now.AddMilliseconds(500);
                            Draw5Count++;
                        }
                    }
                }
            }));

            newThread.Start();
        }