Ejemplo n.º 1
0
        public void collectMousePositions()
        {
            void exitAnnotation(_TrackedAnnotation trackedAnnotation, int deviceId)
            {
                if (trackedAnnotation.annotation?.onExit != null &&
                    trackedAnnotation.activeDevices.Contains(deviceId))
                {
                    trackedAnnotation.annotation.onExit(PointerExitEvent.fromHoverEvent(this._lastMouseEvent[deviceId]));
                    trackedAnnotation.activeDevices.Remove(deviceId);
                }
            }

            void exitAllDevices(_TrackedAnnotation trackedAnnotation)
            {
                if (trackedAnnotation.activeDevices.isNotEmpty())
                {
                    HashSet <int> deviceIds = new HashSet <int>(trackedAnnotation.activeDevices);
                    foreach (int deviceId in deviceIds)
                    {
                        exitAnnotation(trackedAnnotation, deviceId);
                    }
                }
            }

            if (!this.mouseIsConnected)
            {
                foreach (var annotation in this._trackedAnnotations.Values)
                {
                    exitAllDevices(annotation);
                }

                return;
            }

            foreach (int deviceId in this._lastMouseEvent.Keys)
            {
                PointerEvent           lastEvent = this._lastMouseEvent[deviceId];
                MouseTrackerAnnotation hit       = this.annotationFinder(lastEvent.position);

                if (hit == null)
                {
                    foreach (_TrackedAnnotation trackedAnnotation in this._trackedAnnotations.Values)
                    {
                        exitAnnotation(trackedAnnotation, deviceId);
                    }

                    return;
                }

                _TrackedAnnotation hitAnnotation = this._findAnnotation(hit);
                //enter
                if (!hitAnnotation.activeDevices.Contains(deviceId))
                {
                    hitAnnotation.activeDevices.Add(deviceId);
                    if (hitAnnotation.annotation?.onEnter != null)
                    {
                        hitAnnotation.annotation.onEnter(PointerEnterEvent.fromHoverEvent(lastEvent));
                    }
                }

                //hover
                if (hitAnnotation.annotation?.onHover != null)
                {
                    hitAnnotation.annotation.onHover(PointerHoverEvent.fromHoverEvent(lastEvent));
                }

                //leave
                foreach (_TrackedAnnotation trackedAnnotation in this._trackedAnnotations.Values)
                {
                    if (hitAnnotation == trackedAnnotation)
                    {
                        continue;
                    }

                    if (trackedAnnotation.activeDevices.Contains(deviceId))
                    {
                        if (trackedAnnotation.annotation?.onExit != null)
                        {
                            trackedAnnotation.annotation.onExit(PointerExitEvent.fromHoverEvent((PointerHoverEvent)lastEvent));
                        }

                        trackedAnnotation.activeDevices.Remove(deviceId);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public static PointerExitEvent fromHoverEvent(PointerHoverEvent e)
 {
     return(fromMouseEvent(e));
 }