/// <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 )); }
static GazePointer() { _mouseListener = new MouseInputListener(); _logFilter = new LogFilter(); _logFilter.Initialize(); CreateCursorWindow(); _offScreenElement = new FrameworkElement(); _offScreenElementClickParams = new GazeClickParameters { MouseDownDelay = 1 * DefaultMouseDownDelay, MouseUpDelay = 2 * DefaultMouseDownDelay, RepeatMouseDownDelay = uint.MaxValue }; _hwndMouseListner = _mouseListener.Hwnd; }
void AdjustHistorySampleTime(GazeClickParameters clickParams) { // Update the max total time we are maintaining if we ever see a click param higher than what we have. const int PAD_HISTORY = 500;// add a padding of time (in milliseconds) so that the history is slightly larger and includes the largest click param value if ((clickParams.RepeatMouseDownDelay + PAD_HISTORY > _maxHistoryTime) && (clickParams.RepeatMouseDownDelay != uint.MaxValue)) { _maxHistoryTime = clickParams.RepeatMouseDownDelay + PAD_HISTORY; } if ((clickParams.MouseUpDelay + PAD_HISTORY > _maxHistoryTime) && (clickParams.MouseUpDelay != uint.MaxValue)) { _maxHistoryTime = clickParams.MouseUpDelay + PAD_HISTORY; } if ((clickParams.MouseDownDelay + PAD_HISTORY > _maxHistoryTime) && (clickParams.MouseDownDelay != uint.MaxValue)) { _maxHistoryTime = clickParams.MouseDownDelay + PAD_HISTORY; } }
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; }