예제 #1
0
        private bool IsInGlass(PokeEventArgs args)
        {
            Bounds bds = this.OffsetBounds;
            int    dx  = args.X - (bds.X + bds.Width / 2 - 4);
            int    dy  = args.Y - (bds.Y + bds.Height / 2 - 4);

            return(dx * dx + dy * dy < 16 * 16);
        }
예제 #2
0
        public void ProcessPokeEvent(PokeEventArgs args)
        {
            switch (args.Type)
            {
            case PokeEventType.PokeStart:
                args.StateUpdate = PokeUpdate(args, true, false);
                break;

            case PokeEventType.PokeEnd:
                args.StateUpdate = PokeUpdate(args, false, true);
                break;

            case PokeEventType.PokeCancel:
                args.StateUpdate = PokeUpdate(args, false, false);
                break;
            }
        }
예제 #3
0
 private Action <IInstanceState> PokeUpdate(PokeEventArgs args, bool pending, bool flip)
 {
     return((IInstanceState state) => {
         SwitchInstance myState = state.Instance as SwitchInstance;
         bool repaint = false;
         if (flip)
         {
             myState.currentValue = myState.currentValue.Not;
             myState.pendingPress = pending;
             args.Repropagate();
             repaint = true;
         }
         if (myState.pendingPress != pending)
         {
             myState.pendingPress = pending;
             repaint = true;
         }
         if (repaint)
         {
             args.Repaint();
         }
     });
 }
예제 #4
0
        public void ProcessPokeEvent(PokeEventArgs args)
        {
            switch (args.Type)
            {
            case PokeEventType.PokeStart:
                args.StateUpdate = (IInstanceState state) => {
                    ModuleInstance instance = state.Instance as ModuleInstance;
                    int            oldState = instance.PokeState;
                    int            newState = oldState;
                    if (IsInGlass(args))
                    {
                        if (oldState == ModuleInstance.Untouched)
                        {
                            newState = ModuleInstance.FirstDepress;
                        }
                        else if (oldState == ModuleInstance.Touched)
                        {
                            newState = ModuleInstance.SecondDepress;
                        }
                    }
                    else
                    {
                        newState = ModuleInstance.Untouched;
                        args.RejectPoke();
                    }
                    if (newState != oldState)
                    {
                        instance.PokeState = newState;
                        args.Repaint();
                    }
                };
                break;

            case PokeEventType.PokeEnd:
                args.StateUpdate = (IInstanceState state) => {
                    ModuleInstance instance = state.Instance as ModuleInstance;
                    int            oldState = instance.PokeState;
                    int            newState = oldState;
                    if (IsInGlass(args))
                    {
                        if (oldState == ModuleInstance.FirstDepress)
                        {
                            newState = ModuleInstance.Touched;
                        }
                        else if (oldState == ModuleInstance.SecondDepress)
                        {
                            newState = ModuleInstance.Untouched;
                            args.RequestView(module, instance.SimulationState);
                        }
                    }
                    else
                    {
                        if (oldState == ModuleInstance.FirstDepress)
                        {
                            newState = ModuleInstance.Untouched;
                        }
                        else if (oldState == ModuleInstance.SecondDepress)
                        {
                            newState = ModuleInstance.Touched;
                        }
                    }
                    if (newState != oldState)
                    {
                        instance.PokeState = newState;
                        args.Repaint();
                    }
                };
                break;

            case PokeEventType.PokeCancel:
                args.StateUpdate = (IInstanceState state) => {
                    ModuleInstance instance = state.Instance as ModuleInstance;
                    int            oldState = instance.PokeState;
                    int            newState = oldState;
                    if (oldState == ModuleInstance.FirstDepress)
                    {
                        newState = ModuleInstance.Untouched;
                    }
                    else if (oldState == ModuleInstance.SecondDepress)
                    {
                        newState = ModuleInstance.Touched;
                    }
                    if (newState != oldState)
                    {
                        instance.PokeState = newState;
                        args.Repaint();
                    }
                };
                break;
            }
        }
예제 #5
0
        private void PokeClient_Poked(object sender, PokeEventArgs e)
        {
            totalPokes = e.Pokes;

            UpdateText2();
        }