예제 #1
0
 public BasicMultiFingerEventArgs(string eventId, int groupId, float x, float y, int nFingers, IGestureListener validInitialZTarget)
     : base(eventId, groupId)
 {
     m_x = x;
     m_y = y;
     m_nFingers = nFingers;
     m_validInitialZTarget = validInitialZTarget;
 }
예제 #2
0
 public void RemoveListener(IGestureListener listener)
 {
     _listeners.Remove(listener);
 }
예제 #3
0
 public void AddListener(IGestureListener listener)
 {
     _listeners.Add(listener);
 }
예제 #4
0
 /// <summary>
 /// Unregisters all registered handlers for the given listener.
 /// </summary>
 /// <param name="listener">The listener</param>
 public static void UnregisterAllHandlersOf(IGestureListener listener)
 {
     lock (s_lock)
     {
         GestureEventRegistry.UnregisterAllHandlers(listener);
     }
 }
예제 #5
0
파일: Surface.cs 프로젝트: Geistyp/grafiti
 /// <summary>
 /// Takes a GUI control and point specified in Grafiti-coordinate-system and 
 /// returns the point relative to the GUI component in client's coordinates.
 /// </summary>
 /// <param name="target">The GUI component.</param>
 /// <param name="x">X coordinate of the point to convert.</param>
 /// <param name="y">Y coordinate of the point to convert.</param>
 /// <param name="cx">X coordinate of the converted point.</param>
 /// <param name="cy">Y coordinate of the converted point.</param>
 public void PointToClient(IGestureListener target, float x, float y, out float cx, out float cy)
 {
     m_clientGUIManager.PointToClient(target, x, y, out cx, out cy);
 }
예제 #6
0
 public MultiTraceFromToEventArgs(string eventId, int groupId, int nFingers, 
     IGestureListener fromTarget, IGestureListener toTarget,
     float initialCentroidX, float initialCentroidY, float finalCentroidX, float finalCentroidY)
     : base(eventId, groupId, nFingers, finalCentroidX, finalCentroidY)
 {
     m_fromTarget = fromTarget;
     m_toTarget = toTarget;
     m_initialCentroidX = initialCentroidX;
     m_initialCentroidY = initialCentroidY;
 }
예제 #7
0
        public override void Process(List<Trace> traces)
        {
            // If the group is added or reset, then reset m_initialZTarget
            if (m_allUp && traces.Exists(delegate(Trace trace)
            {
                return trace.State == Trace.States.ADDED || trace.State == Trace.States.RESET;
            }))
            {
                m_allUp = false;
                if (Group.OnZControl)
                {
                    // If the Z-control has changed then reset the down times
                    if (m_validInitialZTarget != Group.ClosestCurrentTarget)
                    {
                        //ResetDownTimes();
                        m_validInitialZTarget = Group.ClosestCurrentTarget;
                    }
                }
                else
                    m_validInitialZTarget = null;
            }

            // Check tap's spatial constraints for every updated, removed and reset trace
            if (m_tapSpatialConstraintsOk)
            {
                foreach (Trace trace in traces)
                {
                    if (trace.State != Trace.States.ADDED && trace.State != Trace.States.TERMINATED)
                    {
                        #region on Z-target
                        // This works good for buttons, but not for large controls where it's not desired
                        // to have a tap without any spatial threshold. It's probably better to deal taps
                        // at the client level by receiving only Down and Up events and by checking
                        // the ValidInitialZTarget property.
                        if (m_validInitialZTarget != null)
                        {
                            if (!(Group.OnZControl && m_validInitialZTarget == Group.ClosestCurrentTarget))
                            {
                                m_tapSpatialConstraintsOk = false;
                                m_validInitialZTarget = null;
                                break;
                            }
                        }
                        #endregion

                        #region outside of the Z-target
                        else
                        {
                            if (trace.Last.SquareDistance(m_traceLastDownCurDict[trace]) >
                                Settings.TRACE_SPACE_GAP * Settings.TRACE_SPACE_GAP)
                            {
                                m_tapSpatialConstraintsOk = false;
                                break;
                            }
                        }
                        #endregion
                    }
                }
            }

            // enter
            OnEnter();

            // track cursors and send cursor events
            foreach (Trace trace in traces)
            {
                /*** ADDED ***/
                if (trace.State == Trace.States.ADDED)
                {
                    m_traceLastDownCurDict[trace] = trace.Last;
                    m_numberOfCurrentFingers++;
                    m_tapNumberOfFingers++;// = Math.Max(m_tapNumberOfFingers, m_numberOfCurrentFingers);
                    OnDown(trace.Last);
                }

                /*** UPDATED ***/
                else if (trace.State == Trace.States.UPDATED)
                {
                    OnMove(trace.Last);
                }

                /*** RESET ***/
                else if (trace.State == Trace.States.RESET)
                {
                    m_traceLastDownCurDict[trace] = trace.Last;
                    m_numberOfCurrentFingers++;
                    m_tapNumberOfFingers++;// = Math.Max(m_tapNumberOfFingers, m_numberOfCurrentFingers);
                    OnDown(trace.Last);
                }

                /*** REMOVED ***/
                else if (trace.State == Trace.States.REMOVED)
                {
                    m_numberOfCurrentFingers--;
                    OnUp(trace.Last);
                }
            }

            // tap stuff
            if (m_numberOfCurrentFingers == 0)
            {
                if (m_tapSpatialConstraintsOk)
                {
                    if (!m_haveSingleTapped)
                    {
                        OnTap();
                        m_haveSingleTapped = true;
                    }
                    else
                    {
                        // TAP's temporal constraint
                        if (Group.CurrentTimeStamp - m_tapInitialTime <= TAP_TIME)
                        {
                            if (!m_haveDoubleTapped)
                            {
                                OnDoubleTap();
                                m_haveDoubleTapped = true;
                                if (!IS_TRIPLE_TAP_ENABLED)
                                    ResetTap();
                            }
                            else
                            {
                                OnTripleTap();
                                ResetTap();
                            }
                        }
                        else
                        {
                            OnTap();
                            ResetTap();
                        }
                    }
                }
                else
                {
                    ResetTap();
                }
                m_tapNumberOfFingers = 0;
                m_allUp = true;
                m_tapSpatialConstraintsOk = true;
            }

            // hover stuff
            if (!m_hoverHasBeenReset)
            {
                if(traces.Exists(delegate(Trace trace)
                {
                   return trace.State == Trace.States.ADDED ||
                        trace.State == Trace.States.REMOVED ||
                        trace.State == Trace.States.RESET;
                }))
                {
                    OnEndHover();
                    ResetHover();
                }
                // (TODO configurable...)
                // Same thing as for tap, where on Z-controls there's no threshold.
                else if (!Group.OnZControl && Group.ClosestCurrentTarget != null)
                {
                    // updated traces must comply with the spatial constraint
                    if (!traces.TrueForAll(delegate(Trace trace)
                    {
                        return trace.State != Trace.States.UPDATED ||
                            CheckHoverSpatialConstraints(trace);
                    }))
                    {
                        OnEndHover();
                        ResetHover();
                    }
                }
            }
            if (m_numberOfCurrentFingers == 0)
            {
                OnRemove();
                m_hoverEnabled = false;
            }

            // set for next refresh cycle
            m_hoverHasBeenReset = false;
            m_tapHasBeenReset = false;

            if (Recognizing)
                ValidateGesture();
        }
예제 #8
0
 private IEnumerable<GestureRecognizer> FindAllLGRsWithDifferentTarget(IGestureListener target)
 {
     foreach (int pn in m_pns)
         foreach (LocalGestureRecognizer lgr in m_unarmedLGRs[pn])
             if (lgr.Target != target)
                 yield return lgr;
 }
예제 #9
0
        private void InitializeLGRs(IGestureListener localTarget)
        {
            Type grType;
            object grConf;
            LocalGestureRecognizer lgr;
            Dictionary<object, LocalGestureRecognizer> lgrDict;

            foreach (GestureEventRegistry.RegistrationInfo lgrInfo in GestureEventRegistry.LGRRegistry)
            {
                if (lgrInfo.Handler.Target == localTarget)
                {
                    grType = lgrInfo.GRType;
                    grConf = lgrInfo.GRConfiguration;

                    if (!m_lgrInstanceTable.TryGetValue(grType, localTarget, out lgrDict))
                    {
                        lgrDict = new Dictionary<object, LocalGestureRecognizer>();
                        m_lgrInstanceTable[grType, localTarget] = lgrDict;
                    }

                    if (!lgrDict.TryGetValue(grConf, out lgr))
                    {
                        lgr = (LocalGestureRecognizer)grType.GetConstructor(new Type[] { typeof(GRConfiguration) }).Invoke(new Object[] { grConf });
                        lgr.Group = m_group;
                        lgr.PriorityNumber = lgrInfo.PriorityNumber;
                        lgr.Target = (IGestureListener)lgrInfo.Handler.Target;
                        lgrDict[grConf] = lgr;
                        m_targetLgrInstancesTable[localTarget].Add(lgr);
                        AddUnarmedGR(lgr);
                    }

                    lgr.AddHandler(lgrInfo.Event, lgrInfo.Handler);
                }
            }
        }
예제 #10
0
        internal void AddLocalTarget(IGestureListener localTarget)
        {
            if (!m_targetLgrInstancesTable.ContainsKey(localTarget))
                m_targetLgrInstancesTable[localTarget] = new List<GestureRecognizer>();

            InitializeLGRs(localTarget);
        }
예제 #11
0
        internal void RemoveLocalTarget(IGestureListener localTarget)
        {
            if (m_targetLgrInstancesTable.ContainsKey(localTarget))
            {
                foreach (GestureRecognizer lgr in m_targetLgrInstancesTable[localTarget])
                {
                    RemoveUnarmedGR(new ToRemoveGR(lgr, true));
                    RemoveArmedGR(lgr);

                    m_lgrInstanceTable.Remove(lgr.GetType(), localTarget);

                    // reset exclusive local target if this is removed
                    if (localTarget == m_group.ExclusiveLocalTarget)
                        ResetExclusiveLocalTarget();
                }
                m_targetLgrInstancesTable.Remove(localTarget);

                //Console.WriteLine("Removed local target {0}", localTarget);
            }
        }
 /// <summary>
 /// Removes given <see cref="IGestureListener"/> from list of listeners
 /// </summary>
 /// <param name="listener">Object which should no longer receive gesture notifications</param>
 public void UnregisterListener(IGestureListener listener)
 {
     _listeners.Remove(listener);
 }
 /// <summary>
 /// Registers given <see cref="IGestureListener"/> to receive gesture notifications
 /// </summary>
 /// <param name="listener">Object to be registered for listening</param>
 public void RegisterListener(IGestureListener listener)
 {
     _listeners.Add(listener);
 }
예제 #14
0
        public void GetTargetAt(float x, float y,
            out IGestureListener zGestureListener,
            out object zControl)
        {
            zGestureListener = null;
            zControl = null;

            // to center
            x = x - m_x;// +m_size / 2;
            y = y - m_y;// +m_size / 2;

            // rotate
            double radiants = Math.PI / 180 * m_theta;
            //Console.WriteLine(m_theta/180 + ", " + radiants/Math.PI);

            float tempX, tempY;

            tempX = (float)((double)x * Math.Cos(radiants) - (double)y * Math.Sin(radiants));
            tempY = (float)((double)x * Math.Sin(radiants) + (double)y * Math.Cos(radiants));

            x = tempX;
            y = tempY;

            // to top left
            x += m_size / 2;
            y += m_size / 2;

            if (x < 0 || x > m_size || y < 0 || y > m_size) // outside calculator
                return;

            zGestureListener = this;
            zControl = this;

            // to grid coordinates
            x = x * m_gridSize / m_size;
            y = y * m_gridSize / m_size;

            foreach (CalcButton button in m_buttons)
            {
                if (button.InsideTargetArea(x - button.X, y - button.Y))
                {
                    zGestureListener = button;
                    break;
                }
            }
        }
예제 #15
0
파일: Main.cs 프로젝트: nuigroup/grafiti
 public void PointToClient(IGestureListener target, float x, float y, out float cx, out float cy)
 {
     cx = x;
     cy = y;
 }
예제 #16
0
파일: Main.cs 프로젝트: nuigroup/grafiti
 public void GetVisualsAt(float x, float y,
     out IGestureListener zGestureListener,
     out object zControl,
     out List<ITangibleGestureListener> tangibleListeners)
 {
     if(m_displayCalculator)
         m_calculator.GetTargetAt(x, y, out zGestureListener, out zControl);
     else
     {
         zGestureListener = null;
         zControl = null;
     }
     tangibleListeners = s_demoObjectManager.HitTestTangibles(x, y);
 }