Esempio n. 1
0
        private GazePointer(Window window, GazeClickParameters clickParameters, GetGazeClickParameters getGazeClickParameters,
                            Settings settings, bool forceMouseCursor)
        {
            // TODO: Addition of loggingSettings with default as parameter WILL have introduced logging configuration bug.

            _settings         = settings;
            _sensorSettings   = settings.Sensor;
            _filterSettings   = settings.Filter;
            _loggingSettings  = settings.Logging;
            _forceMouseCursor = forceMouseCursor;

            if (_sensorSettings.Sensor == Sensors.Sensors.Mouse)
            {
                _filterSettings.ActiveFilter = FilterType.NullFilter;
            }

            _settings.PropertyChanged       += (o, args) => _window.Dispatcher.BeginInvoke(new GazePointerDelegate(UpdateCursorStyle));
            _filterSettings.PropertyChanged += (o, args) => _logFilter.Settings = _filterSettings;

            _window       = window;
            _windowClosed = false;

            _defaultClickParams = clickParameters;
            _getGazeClickParams = getGazeClickParameters;

            FindMainWindow();

            window.LocationChanged += OnWindowLocationOrSizeChanged;
            window.SizeChanged     += OnWindowLocationOrSizeChanged;
            window.Closed          += OnWindowClosed;

            UpdateCursorStyle();

            var source = PresentationSource.FromVisual(window);

            _transform        = source.CompositionTarget.TransformFromDevice;
            _reverseTransform = source.CompositionTarget.TransformToDevice;

            //
            // By the time we get here, the window may already be positioned correctly and
            // may receive no further location/size changed events. If that doesn't happen
            // _topLeft and _bottomRight don't get initialized correctly.
            // So force a call here
            //
            OnWindowLocationOrSizeChanged(window, null);

            if (source == null)
            {
                throw new NullReferenceException("Window does not contain a PresentationSource, may not be properly initialized");
            }
            if (source.CompositionTarget == null)
            {
                throw new NullReferenceException("Window Source does not contain a CompositionTarget, may not be properly initialized");
            }

            OriginalSignal = new GazeStats();
            FilteredSignal = new GazeStats();

            _xyFilter = InitializeFilter();

            _gazeHistory    = new List <GazeHistoryItem>();
            _hitTargetTimes = new Dictionary <FrameworkElement, int>();
            _hitTarget      = _offScreenElement;

            _gazeDataProvider.GazeEvent += OnGazeData;

            _idleDetector.GoneIdle += OnEyeGazeGoneIdle;
        }
Esempio n. 2
0
        /// <summary>
        /// Attach GazePointer behavior to this window
        /// </summary>
        public static GazePointer Attach(Window window, GazeClickParameters clickParams = null, GetGazeClickParameters getGazeClickParams = null,
                                         Settings settings = null, bool forceMouseCursor = false)
        {
            if (settings == null)
            {
                settings = new Settings();
            }

            if (_gazeDataProvider == null)
            {
                _gazeDataProvider = GazeDataProvider.InitializeGazeDataProvider(settings.Sensor);
            }

            return(new GazePointer(
                       window,
                       clickParams ?? new GazeClickParameters
            {
                MouseDownDelay = 1 * DefaultMouseDownDelay,
                MouseUpDelay = 2 * DefaultMouseDownDelay,
                RepeatMouseDownDelay = 3 * DefaultMouseDownDelay
            },
                       getGazeClickParams,
                       settings,
                       forceMouseCursor
                       ));
        }