public void UnregisterMouseInputProvider(IMouseInputProvider provider) { provider.ButtonPressEvent -= HandleProviderButtonPressEvent; provider.ButtonReleaseEvent -= HandleButtonReleaseEvent; provider.MotionNotifyEvent -= HandleMotionNotifyEvent; providers.Remove(provider); }
/// <summary> /// Constructor that lets you inject input-providers for testing purposes. /// </summary> public InputManager(IKeyInputProvider keyInputProvider, IMouseInputProvider mouseInputProvider, IPadInputProvider padInputProvider, ITouchInputProvider touchInputProvider) { Key = new Key(keyInputProvider); Mouse = new Mouse(mouseInputProvider); SetProviderForPads(padInputProvider); Touch = new Touch(touchInputProvider); }
public void RegistedMouseInputProvider(IMouseInputProvider provider) { provider.ButtonPressEvent += HandleProviderButtonPressEvent; provider.ButtonReleaseEvent += HandleButtonReleaseEvent; provider.MotionNotifyEvent += HandleMotionNotifyEvent; providers.Add(provider); }
public static int GetIntermediatePoints(IInputElement relativeTo, Point[] points) { // Security Mitigation: do not give out input state if the device is not active. if (Mouse.PrimaryDevice.IsActive) { if (relativeTo != null) { PresentationSource inputSource = PresentationSource.FromDependencyObject(InputElement.GetContainingVisual(relativeTo as DependencyObject)); if (inputSource != null) { IMouseInputProvider mouseInputProvider = inputSource.GetInputProvider(typeof(MouseDevice)) as IMouseInputProvider; if (null != mouseInputProvider) { return(mouseInputProvider.GetIntermediatePoints(relativeTo, points)); } } } } return(-1); }
public static void Initialize(GameWindow gw, Type mouseProviderType, Type keyboardProviderType) { if (!typeof(IMouseInputProvider).IsAssignableFrom(mouseProviderType)) { throw new ArgumentException("Mouse provider must implement IMouseInputProvider."); } if (!typeof(IKeyboardInputProvider).IsAssignableFrom(keyboardProviderType)) { throw new ArgumentException("Keyboard provider must implement IKeyboardInputProvider."); } gameWindow = gw; mouse = (IMouseInputProvider)Activator.CreateInstance(mouseProviderType); mouse.Initialize(gw); keyboard = (IKeyboardInputProvider)Activator.CreateInstance(keyboardProviderType); keyboard.Initialize(gw); }
private void ChangeMouseCapture(IInputElement mouseCapture, IMouseInputProvider providerCapture, CaptureMode captureMode, int timestamp) { DependencyObject o = null; if(mouseCapture != _mouseCapture) { // Console.WriteLine("ChangeMouseCapture(" + mouseCapture + ")"); // Update the critical pieces of data. IInputElement oldMouseCapture = _mouseCapture; _mouseCapture = mouseCapture; if (_mouseCapture != null) { _providerCapture = new SecurityCriticalDataClass<IMouseInputProvider>(providerCapture); } else { _providerCapture = null; } _captureMode = captureMode; using (Dispatcher.DisableProcessing()) // Disable reentrancy due to locks taken { // Adjust the handlers we use to track everything. if (oldMouseCapture != null) { o = oldMouseCapture as DependencyObject; if (InputElement.IsUIElement(o)) { ((UIElement)o).IsEnabledChanged -= _captureIsEnabledChangedEventHandler; ((UIElement)o).IsVisibleChanged -= _captureIsVisibleChangedEventHandler; ((UIElement)o).IsHitTestVisibleChanged -= _captureIsHitTestVisibleChangedEventHandler; } else if (InputElement.IsContentElement(o)) { ((ContentElement)o).IsEnabledChanged -= _captureIsEnabledChangedEventHandler; // NOTE: there are no IsVisible or IsHitTestVisible properties for ContentElements. // // ((ContentElement)o).IsVisibleChanged -= _captureIsVisibleChangedEventHandler; // ((ContentElement)o).IsHitTestVisibleChanged -= _captureIsHitTestVisibleChangedEventHandler; } else if (InputElement.IsUIElement3D(o)) { ((UIElement3D)o).IsEnabledChanged -= _captureIsEnabledChangedEventHandler; ((UIElement3D)o).IsVisibleChanged -= _captureIsVisibleChangedEventHandler; ((UIElement3D)o).IsHitTestVisibleChanged -= _captureIsHitTestVisibleChangedEventHandler; } } if (_mouseCapture != null) { o = _mouseCapture as DependencyObject; if (InputElement.IsUIElement(o)) { ((UIElement)o).IsEnabledChanged += _captureIsEnabledChangedEventHandler; ((UIElement)o).IsVisibleChanged += _captureIsVisibleChangedEventHandler; ((UIElement)o).IsHitTestVisibleChanged += _captureIsHitTestVisibleChangedEventHandler; } else if (InputElement.IsContentElement(o)) { ((ContentElement)o).IsEnabledChanged += _captureIsEnabledChangedEventHandler; // NOTE: there are no IsVisible or IsHitTestVisible properties for ContentElements. // // ((ContentElement)o).IsVisibleChanged += _captureIsVisibleChangedEventHandler; // ((ContentElement)o).IsHitTestVisibleChanged += _captureIsHitTestVisibleChangedEventHandler; } else if (InputElement.IsUIElement3D(o)) { ((UIElement3D)o).IsEnabledChanged += _captureIsEnabledChangedEventHandler; ((UIElement3D)o).IsVisibleChanged += _captureIsVisibleChangedEventHandler; ((UIElement3D)o).IsHitTestVisibleChanged += _captureIsHitTestVisibleChangedEventHandler; } } } // Oddly enough, update the IsMouseCaptureWithin property first. This is // so any callbacks will see the more-common IsMouseCaptureWithin property // set correctly. UIElement.MouseCaptureWithinProperty.OnOriginValueChanged(oldMouseCapture as DependencyObject, _mouseCapture as DependencyObject, ref _mouseCaptureWithinTreeState); // Invalidate the IsMouseCaptured properties. if (oldMouseCapture != null) { o = oldMouseCapture as DependencyObject; o.SetValue(UIElement.IsMouseCapturedPropertyKey, false); // Same property for ContentElements } if (_mouseCapture != null) { o = _mouseCapture as DependencyObject; o.SetValue(UIElement.IsMouseCapturedPropertyKey, true); // Same property for ContentElements } // Send the LostMouseCapture and GotMouseCapture events. if (oldMouseCapture != null) { MouseEventArgs lostCapture = new MouseEventArgs(this, timestamp, _stylusDevice); lostCapture.RoutedEvent=Mouse.LostMouseCaptureEvent; lostCapture.Source= oldMouseCapture; //ProcessInput has a linkdemand _inputManager.Value.ProcessInput(lostCapture); } if (_mouseCapture != null) { MouseEventArgs gotCapture = new MouseEventArgs(this, timestamp, _stylusDevice); gotCapture.RoutedEvent=Mouse.GotMouseCaptureEvent; gotCapture.Source= _mouseCapture; //ProcessInput has a linkdemand _inputManager.Value.ProcessInput(gotCapture); } // Force a mouse move so we can update the mouse over. Synchronize(); } }
internal Mouse(IMouseInputProvider provider) { this.provider = provider; Is = new IsSub(GetState, GetOldState); Was = new WasSub(GetOldState); }
public void UnregisterMouseInputProvider (IMouseInputProvider provider) { provider.ButtonPressEvent -= HandleProviderButtonPressEvent; provider.ButtonReleaseEvent -= HandleButtonReleaseEvent; provider.MotionNotifyEvent -= HandleMotionNotifyEvent; providers.Remove (provider); }
public void RegistedMouseInputProvider (IMouseInputProvider provider) { provider.ButtonPressEvent += HandleProviderButtonPressEvent; provider.ButtonReleaseEvent += HandleButtonReleaseEvent; provider.MotionNotifyEvent += HandleMotionNotifyEvent; providers.Add (provider); }