void _updateDevices( PointerEvent targetEvent = null, _UpdatedDeviceHandler handleUpdatedDevice = null) { D.assert(handleUpdatedDevice != null); D.assert(result: !_duringBuildPhase); D.assert(result: !_duringDeviceUpdate); var mouseWasConnected = mouseIsConnected; _MouseState targetState = null; if (targetEvent != null) { targetState = _mouseStates.getOrDefault(key: targetEvent.device); if (targetState == null) { targetState = new _MouseState(initialEvent: targetEvent); _mouseStates[key : targetState.device] = targetState; } else { D.assert(!(targetEvent is PointerAddedEvent)); targetState.latestEvent = targetEvent; if (targetEvent is PointerRemovedEvent) { _mouseStates.Remove(key: targetEvent.device); } } } D.assert(targetState == null == (targetEvent == null)); D.assert(() => { _duringDeviceUpdate = true; return(true); }); var dirtyStates = targetEvent == null ? (IEnumerable <_MouseState>)_mouseStates.Values : new List <_MouseState> { targetState }; foreach (var dirtyState in dirtyStates) { var nextAnnotations = _findAnnotations(state: dirtyState); var lastAnnotations = dirtyState.replaceAnnotations(value: nextAnnotations); handleUpdatedDevice(mouseState: dirtyState, previousAnnotations: lastAnnotations); } D.assert(() => { _duringDeviceUpdate = false; return(true); }); if (mouseWasConnected != mouseIsConnected) { notifyListeners(); } }
public void _handleEvent(PointerEvent Event) { if (Event.kind != PointerDeviceKind.mouse) { return; } if (Event is PointerSignalEvent) { return; } int device = Event.device; _MouseState existingState = _mouseStates.getOrDefault(device); if (!_shouldMarkStateDirty(existingState, Event)) { return; } PointerEvent previousEvent = existingState?.latestEvent; _updateDevices( targetEvent: Event, handleUpdatedDevice: (_MouseState mouseState, HashSet <MouseTrackerAnnotation> previousAnnotations) => { D.assert(mouseState.device == Event.device); _dispatchDeviceCallbacks( lastAnnotations: previousAnnotations, nextAnnotations: mouseState.annotations, previousEvent: previousEvent, unhandledEvent: Event ); } ); }
void _updateDevices( PointerEvent targetEvent = null, _UpdatedDeviceHandler handleUpdatedDevice = null) { D.assert(handleUpdatedDevice != null); D.assert(!_duringBuildPhase); D.assert(!_duringDeviceUpdate); bool mouseWasConnected = mouseIsConnected; _MouseState targetState = null; if (targetEvent != null) { targetState = _mouseStates.getOrDefault(targetEvent.device); if (targetState == null) { targetState = new _MouseState(initialEvent: targetEvent); _mouseStates[targetState.device] = targetState; } else { D.assert(!(targetEvent is PointerAddedEvent)); targetState.latestEvent = targetEvent; if (targetEvent is PointerRemovedEvent) { _mouseStates.Remove(targetEvent.device); } } } D.assert((targetState == null) == (targetEvent == null)); D.assert(() => { _duringDeviceUpdate = true; return(true); }); IEnumerable <_MouseState> dirtyStates = targetEvent == null ? (IEnumerable <_MouseState>)_mouseStates.Values : new List <_MouseState> { targetState }; foreach (_MouseState dirtyState in dirtyStates) { HashSet <MouseTrackerAnnotation> nextAnnotations = _findAnnotations(dirtyState); HashSet <MouseTrackerAnnotation> lastAnnotations = dirtyState.replaceAnnotations(nextAnnotations); handleUpdatedDevice(dirtyState, lastAnnotations); } D.assert(() => { _duringDeviceUpdate = false; return(true); }); if (mouseWasConnected != mouseIsConnected) { notifyListeners(); } }
public HashSet <MouseTrackerAnnotation> _findAnnotations(_MouseState state) { var globalPosition = state.latestEvent.position; var device = state.device; var result = new HashSet <MouseTrackerAnnotation>(); foreach (var values in annotationFinder(offset: globalPosition)) { result.Add(item: values); } return(_mouseStates.ContainsKey(key: device) ? result : new HashSet <MouseTrackerAnnotation>()); }
public HashSet <MouseTrackerAnnotation> _findAnnotations(_MouseState state) { Offset globalPosition = state.latestEvent.position; int device = state.device; HashSet <MouseTrackerAnnotation> result = new HashSet <MouseTrackerAnnotation>(); foreach (var values in annotationFinder(globalPosition)) { result.Add(values); } return((_mouseStates.ContainsKey(device)) ? result : new HashSet <MouseTrackerAnnotation> { } as HashSet <MouseTrackerAnnotation>); }
public static bool _shouldMarkStateDirty(_MouseState state, PointerEvent value) { if (state == null) { return(true); } D.assert(value != null); PointerEvent lastEvent = state.latestEvent; D.assert(value.device == lastEvent.device); D.assert((value is PointerAddedEvent) == (lastEvent is PointerRemovedEvent)); if (value is PointerSignalEvent) { return(false); } return(lastEvent is PointerAddedEvent || value is PointerRemovedEvent || lastEvent.position != value.position); }