Beispiel #1
0
        public override Result Input(Def.Event.IEvent evnt, Point point)
        {
            // Special side effect 3, 4
            if (MustBeIgnored(evnt))
            {
                return(Result.EventIsConsumed(nextState: this));
            }

            if (evnt is Def.Event.IDoubleActionRelease)
            {
                var ev = evnt as Def.Event.IDoubleActionRelease;
                if (ev == secondaryEvent.GetPair())
                {
                    Debug.Print("[Transition 3_0]");
                    ExecuteUserDoFuncInBackground(ctx, T1);
                    ExecuteUserAfterFuncInBackground(ctx, T1);
                    return(Result.EventIsConsumed(nextState: S2));
                }
                else if (ev == primaryEvent.GetPair())
                {
                    Debug.Print("[Transition 3_1]");
                    IgnoreNext(secondaryEvent.GetPair());
                    ExecuteUserAfterFuncInBackground(ctx, T1);
                    ExecuteUserAfterFuncInBackground(ctx, T0);
                    return(Result.EventIsConsumed(nextState: S0));
                }
            }
            return(base.Input(evnt, point));
        }
Beispiel #2
0
        public bool Input(Def.Event.IEvent evnt, Point point)
        {
            lock (lockObject)
            {
                var res = State.Input(evnt, point);
                if (State.GetType() != res.NextState.GetType())
                {
                    Debug.Print("The state of GestureMachine was changed: {0} -> {1}", State.GetType().Name, res.NextState.GetType().Name);

                    // Special side effect 1
                    if (res.NextState is State1 || res.NextState is State2)
                    {
                        Global.ResetStrokeWatcher();
                    }

                    // Reset timer for gesture timeout
                    if (State is State0 && res.NextState is State1)
                    {
                        timer.Stop();
                        // Reflect current config value
                        timer.Interval = Global.Config.Gesture.Timeout;
                        timer.Start();
                    }
                }
                State = res.NextState;
                return(res.Event.IsConsumed);
            }
        }
Beispiel #3
0
        public override Result Input(Def.Event.IEvent evnt, Point point)
        {
            // Special side effect 3, 4
            if (MustBeIgnored(evnt))
            {
                return(Result.EventIsConsumed(nextState: this));
            }
            // Special side effect 2
            Global.StrokeWatcher.Queue(point);

            if (evnt is Def.Event.ISingleAction)
            {
                var ev = evnt as Def.Event.ISingleAction;
                if (T0.Keys.Contains(ev))
                {
                    Debug.Print("[Transition 2_0]");
                    ExecuteUserDoFuncInBackground(ctx, T0[ev]);
                    return(Result.EventIsConsumed(nextState: this));
                }
            }
            else if (evnt is Def.Event.IDoubleActionSet)
            {
                var ev = evnt as Def.Event.IDoubleActionSet;
                if (T1.Keys.Contains(ev))
                {
                    Debug.Print("[Transition 2_1]");
                    ExecuteUserBeforeFuncInBackground(ctx, T1[ev]);
                    return(Result.EventIsConsumed(nextState: new State3(Global, S0, this, ctx, primaryEvent, ev, T3, T1[ev])));
                }
            }
            else if (evnt is Def.Event.IDoubleActionRelease)
            {
                var ev = evnt as Def.Event.IDoubleActionRelease;
                if (ev == primaryEvent.GetPair())
                {
                    var stroke = Global.StrokeWatcher.GetStorke();
                    if (stroke.Count() > 0)
                    {
                        Debug.Print("Stroke: {0}", stroke.ToString());
                        if (T2.Keys.Contains(stroke))
                        {
                            Debug.Print("[Transition 2_2]");
                            ExecuteUserDoFuncInBackground(ctx, T2[stroke]);
                            ExecuteUserAfterFuncInBackground(ctx, T3);
                        }
                    }
                    else
                    {
                        Debug.Print("[Transition 2_3]");
                        ExecuteUserAfterFuncInBackground(ctx, T3);
                    }
                    return(Result.EventIsConsumed(nextState: S0));
                }
            }
            return(base.Input(evnt, point));
        }
Beispiel #4
0
        public override Result Input(Def.Event.IEvent evnt, Point point)
        {
            // Special side effect 3, 4
            if (MustBeIgnored(evnt))
            {
                return(Result.EventIsConsumed(nextState: this));
            }

            if (evnt is Def.Event.ISingleAction)
            {
                var ev = evnt as Def.Event.ISingleAction;
                if (T0.Keys.Contains(ev))
                {
                    var ctx = new UserActionExecutionContext(point);
                    var _T0 = FilterByWhenClause(ctx, T0[ev]);
                    if (_T0.Count() > 0)
                    {
                        Debug.Print("[Transition 0_0]");
                        ExecuteUserDoFuncInBackground(ctx, _T0);
                        return(Result.EventIsConsumed(nextState: this));
                    }
                }
            }
            else if (evnt is Def.Event.IDoubleActionSet)
            {
                var ev = evnt as Def.Event.IDoubleActionSet;
                if (T1.Keys.Contains(ev) || T2.Keys.Contains(ev))
                {
                    var ctx   = new UserActionExecutionContext(point);
                    var cache = new Dictionary <DSL.Def.WhenFunc, bool>();
                    var _T1   = T1.Keys.Contains(ev) ? FilterByWhenClause(ctx, T1[ev], cache) : new List <OnButtonGestureDefinition>();
                    var _T2   = T2.Keys.Contains(ev) ? FilterByWhenClause(ctx, T2[ev], cache) : new List <IfButtonGestureDefinition>();
                    if (_T1.Count() > 0 || _T2.Count() > 0)
                    {
                        Debug.Print("[Transition 0_1]");
                        ExecuteUserBeforeFuncInBackground(ctx, _T2);
                        return(Result.EventIsConsumed(nextState: new State1(Global, this, ctx, ev, _T1, _T2)));
                    }
                }
            }
            return(base.Input(evnt, point));
        }
Beispiel #5
0
 // Check whether given event must be ignored or not.
 // Return true if given event is in the ignore list, and remove it from the list.
 // Return false if the pair of given event is in the ignore list, and remove it from the list.
 // Otherwise return false.
 protected internal bool MustBeIgnored(Def.Event.IEvent evnt)
 {
     if (evnt is Def.Event.IDoubleActionRelease)
     {
         var ev = evnt as Def.Event.IDoubleActionRelease;
         if (Global.IgnoreNext.Contains(ev))
         {
             Global.IgnoreNext.Remove(ev);
             return(true);
         }
     }
     else if (evnt is Def.Event.IDoubleActionSet)
     {
         var ev = evnt as Def.Event.IDoubleActionSet;
         var p  = ev.GetPair();
         if (Global.IgnoreNext.Contains(p))
         {
             Global.IgnoreNext.Remove(p);
             return(false);
         }
     }
     return(false);
 }
Beispiel #6
0
 public virtual Result Input(Def.Event.IEvent evnt, Point point)
 {
     return(Result.EventIsRemained(nextState: this));
 }