/// <summary> /// StylusInputBegin /// </summary> /// <param name="stylusPoints">stylusPoints</param> /// <param name="userInitiated">true if the source eventArgs.UserInitiated flag was set to true</param> protected override void StylusInputBegin(StylusPointCollection stylusPoints, bool userInitiated) { _userInitiated = false; //we only initialize to true if the first stylusPoints were user initiated if (userInitiated) { _userInitiated = true; } _stylusPoints = new StylusPointCollection(stylusPoints.Description, 100); _stylusPoints.Add(stylusPoints); _strokeDrawingAttributes = this.InkCanvas.DefaultDrawingAttributes.Clone(); // Reset the dynamic renderer if it's been flagged. if (_resetDynamicRenderer) { InputDevice inputDevice = EditingCoordinator.GetInputDeviceForReset(); if (InkCanvas.InternalDynamicRenderer != null && inputDevice != null) { StylusDevice stylusDevice = inputDevice as StylusDevice; // If the input device is MouseDevice, null will be passed in Reset Method. InkCanvas.InternalDynamicRenderer.Reset(stylusDevice, stylusPoints); } _resetDynamicRenderer = false; } // Call InvalidateBehaviorCursor at the end of the routine. The method will cause an external event fired. // So it should be invoked after we set up our states. EditingCoordinator.InvalidateBehaviorCursor(this); }
public void ToggleSelect() { StylusDevice currentStylus = Stylus.CurrentStylusDevice; // Check if the stylus is down or the mouse is pressed. if (Mouse.LeftButton != MouseButtonState.Pressed && (currentStylus == null || currentStylus.InAir)) { return; } selectionMode = !selectionMode; // If the control is in selection mode, change the color of // the current stroke dark gray. if (selectionMode) { dynamicRenderer1.DrawingAttributes.Color = Colors.DarkGray; } else { dynamicRenderer1.DrawingAttributes.Color = Colors.Purple; } dynamicRenderer1.Reset(currentStylus, stylusPoints); }
public static void AddStylusListener(StylusDevice stylus, UIElement target, Action <object, StylusEventArgs> callback) { Dictionary <UIElement, StylusListenerData> map; StylusListenerData data; if (!listenmap.ContainsKey(stylus.Id)) { listenmap[stylus.Id] = map = new Dictionary <UIElement, StylusListenerData>(); } else { map = listenmap[stylus.Id]; } if (!map.ContainsKey(target)) { if (StylusListenerData.InListener) { throw new InvalidOperationException("Listeners cannot be added in response to another listener."); } map[target] = data = new StylusListenerData(target); } else { data = map[target]; } data.Callback += callback; }
// Token: 0x06006D4A RID: 27978 RVA: 0x001F6088 File Offset: 0x001F4288 internal void OnInkCanvasDeviceUp(object sender, InputEventArgs args) { MouseButtonEventArgs mouseButtonEventArgs = args as MouseButtonEventArgs; StylusDevice stylusDevice = null; if (mouseButtonEventArgs != null) { stylusDevice = mouseButtonEventArgs.StylusDevice; } if (this.IsInputDeviceCaptured(args.Device) || (stylusDevice != null && this.IsInputDeviceCaptured(stylusDevice))) { if (this._capturedMouse != null && mouseButtonEventArgs != null && mouseButtonEventArgs.ChangedButton != MouseButton.Left) { return; } try { if (this.ActiveEditingBehavior != null) { this.ActiveEditingBehavior.Commit(true); } } finally { this.ReleaseCapture(true); } } }
public HexMouseEventArgs( MouseDevice mouse, int timestamp, MouseButton button, StylusDevice stylusDevice ) : base(mouse, timestamp, stylusDevice) { }
public override void Reset(StylusDevice stylusDevice, StylusPointCollection stylusPoints) { try { base.Reset(stylusDevice, stylusPoints); } catch (Exception e) { } }
//</Snippet25> //<Snippet26> void SynchronizeCurrentStylus() { StylusDevice currentStylus = Stylus.CurrentStylusDevice; currentStylus.Synchronize(); UIElement element = (UIElement)currentStylus.DirectlyOver; output.Text += "The stylus is over " + element.ToString() + "\r\n"; }
// Token: 0x06006D59 RID: 27993 RVA: 0x001F65E0 File Offset: 0x001F47E0 private bool UpdateInvertedState(StylusDevice stylusDevice, bool stylusIsInverted) { if ((!this.IsInMidStroke || (this.IsInMidStroke && this.IsInputDeviceCaptured(stylusDevice))) && stylusIsInverted != this._stylusIsInverted) { this._stylusIsInverted = stylusIsInverted; this.UpdateActiveEditingState(); return(true); } return(false); }
internal GeneralTransform GetTabletToElementTransform(IInputElement relativeTo) { GeneralTransformGroup group = new GeneralTransformGroup(); Matrix toDevice = _inputSource.Value.CompositionTarget.TransformToDevice; toDevice.Invert(); group.Children.Add(new MatrixTransform(PointerTabletDevice.TabletToScreen * toDevice)); group.Children.Add(StylusDevice.GetElementTransform(relativeTo)); return(group); }
//</SnippetMouseEventArgsMouseButton> private void GetDevices(object sender, MouseEventArgs e) { //<SnippetMouseEventArgsMouseDevice> MouseDevice mouseDevice = e.MouseDevice; //</SnippetMouseEventArgsMouseDevice> //<SnippetMouseEventArgsStylusDevice> StylusDevice stylusDevice = e.StylusDevice; //</SnippetMouseEventArgsStylusDevice> }
public StylusHandler(int pressureCap, IInputElement el) { mStylusDevice = Stylus.CurrentStylusDevice; mPressureCap = pressureCap; rel = el; if (mStylusDevice == null) { throw new Exception("No stylus device"); } }
//</Snippet1> //<Snippet8> void TextBoxStylusUp(object sender, StylusEventArgs e) { StylusDevice currentStylus = Stylus.CurrentStylusDevice; if (currentStylus.Inverted) { string selectedText = textbox1.SelectedText; textbox1.SelectedText = ""; } }
static public StylusButtonState SwitchState(this StylusDevice dev, string which) { foreach (StylusButton sb in dev.StylusButtons) { if (sb.Name == which) { return(sb.StylusButtonState); } } return(StylusButtonState.Up); }
/// <summary> /// Returns a StylusPointCollection object for processing the data in the packet. /// This method creates a new StylusPointCollection and copies the data. /// </summary> internal override StylusPointCollection GetStylusPoints(IInputElement relativeTo) { VerifyAccess(); // Fake up an empty one if we have to. if (_currentStylusPoints == null) { return(new StylusPointCollection(_tabletDevice.StylusPointDescription)); } return(_currentStylusPoints.Clone(StylusDevice.GetElementTransform(relativeTo), _currentStylusPoints.Description)); }
public static void SafeCaptureStylus(StylusDevice stylus, IInputElement target) { if (target != null) { capturemap[stylus.Id] = target; } else { capturemap.Remove(stylus.Id); } }
public void StartDrawing(StylusDevice stylus) { if (stylus != null && stylus.InAir) { return; } _dynamicRenderer.Reset(stylus, _stylusPoints); _dynamicRenderer.Enabled = true; _dynamicRenderer.DrawingAttributes.Color = Colors.Black; // Capture the stylus so all stylus input is routed to this control. Stylus.Capture(this); _stylusPoints = new StylusPointCollection(); }
public static void RemoveStylusListener(StylusDevice stylus, UIElement target, Action <object, StylusEventArgs> callback) { Action next = _stylusremove; Action act = delegate() { Dictionary <UIElement, StylusListenerData> map; StylusListenerData data; if (!listenmap.ContainsKey(stylus.Id)) { return; } map = listenmap[stylus.Id]; if (!map.ContainsKey(target)) { return; } data = map[target]; data.Callback -= callback; if (data.Callback == null) { data.Dispose(); map.Remove(target); } if (next != null) { next(); } else { _stylusremove = null; } }; if (StylusListenerData.InListener) { _stylusremove = act; } else { act(); } }
/// <summary> /// Returns a StylusPointCollection object for processing the data in the packet. /// This method creates a new StylusPointCollection and copies the data. /// </summary> internal override StylusPointCollection GetStylusPoints(IInputElement relativeTo, StylusPointDescription subsetToReformatTo) { if (null == subsetToReformatTo) { throw new ArgumentNullException("subsetToReformatTo"); } // Fake up an empty one if we have to. if (_currentStylusPoints == null) { return(new StylusPointCollection(subsetToReformatTo)); } return(_currentStylusPoints.Reformat(subsetToReformatTo, StylusDevice.GetElementTransform(relativeTo))); }
// </Snippet10> // This isn't hooked up to anything. // <Snippet12> private void OnStylusMove(object sender, StylusEventArgs e) { StylusDevice myStylusDevice = e.StylusDevice; if (myStylusDevice != null) { if (myStylusDevice.Inverted) { textbox1.Text = "stylus moves with eraser down"; } else { textbox1.Text = "stylus moves with pen down"; } } }
// This isn't hooked up to anything. // <Snippet10> private void OnMouseMove(object sender, MouseEventArgs e) { StylusDevice myStylusDevice = e.StylusDevice; if (myStylusDevice != null) { if (myStylusDevice.InAir) { textbox1.Text = "stylus moves in air"; } else { textbox1.Text = "stylus moves with pen down"; } } }
internal GettingFocusEventArgs(KeyboardFocusChangedEventArgs args) { _args = args; InputDevice = InputManager.Current.MostRecentInputDevice switch { MouseDevice _ => FocusInputDeviceKind.Mouse, TouchDevice _ => FocusInputDeviceKind.Touch, StylusDevice _ => FocusInputDeviceKind.Pen, TabletDevice _ => FocusInputDeviceKind.Pen, KeyboardDevice _ => FocusInputDeviceKind.Keyboard, _ => FocusInputDeviceKind.Mouse }; OldFocusedElement = args.OldFocus as DependencyObject; NewFocusedElement = args.NewFocus as DependencyObject; }
protected override void OnStylusInRange(StylusEventArgs e) { //Application.Current.Windows[0].Title = "StylusInRange " + DateTime.Now.ToLongTimeString(); if (!e.Inverted) { stylus1 = e.StylusDevice; } else { stylus2 = e.StylusDevice; } //if ((stylus1 != null) && (stylus2 != null)) //{ // bool result = stylus1 == stylus2; // Application.Current.Windows[0].Title = "styluses equal: " + result.ToString(); //} }
public static string ToText(this StylusDevice d) { if (d != null) { return(" Id: " + d.Id.ToString() + " Position: " + d.GetPosition(d.Target).ToText() + " InAir: " + d.InAir.ToString() + " InRange: " + d.InRange.ToString() + " Inverted: " + d.Inverted.ToString() + " Name: " + d.Name + " Buttons: " + d.StylusButtons.ToText() + " StylusDeviceCount: " + d.TabletDevice.StylusDevices.Count + " " + d.TabletDevice.StylusDevices.ToText()); } else { return(" StylusDevice: null "); } }
protected override void StylusInputBegin(StylusPointCollection stylusPoints, bool userInitiated) { this._userInitiated = false; if (userInitiated) { this._userInitiated = true; } this._stylusPoints = new StylusPointCollection(stylusPoints.Description, 100); this._stylusPoints.Add(stylusPoints); this._strokeDrawingAttributes = base.InkCanvas.DefaultDrawingAttributes.Clone(); if (this._resetDynamicRenderer) { InputDevice inputDeviceForReset = base.EditingCoordinator.GetInputDeviceForReset(); if (base.InkCanvas.InternalDynamicRenderer != null && inputDeviceForReset != null) { StylusDevice stylusDevice = inputDeviceForReset as StylusDevice; base.InkCanvas.InternalDynamicRenderer.Reset(stylusDevice, stylusPoints); } this._resetDynamicRenderer = false; } base.EditingCoordinator.InvalidateBehaviorCursor(this); }
void GetDescriptionFromStylusDevice() { //<Snippet26> StylusDevice currentStylus = Stylus.CurrentStylusDevice; StylusPointDescription description1 = new StylusPointDescription(new StylusPointPropertyInfo[] { new StylusPointPropertyInfo(StylusPointProperties.X), new StylusPointPropertyInfo(StylusPointProperties.Y), new StylusPointPropertyInfo(StylusPointProperties.NormalPressure), new StylusPointPropertyInfo(StylusPointProperties.XTiltOrientation), new StylusPointPropertyInfo(StylusPointProperties.YTiltOrientation), new StylusPointPropertyInfo(StylusPointProperties.BarrelButton) }); StylusPointDescription description2 = currentStylus.GetStylusPoints(inkCanvas1).Description; StylusPointDescription description3 = StylusPointDescription.GetCommonDescription(description1, description2); StylusPointCollection points = currentStylus.GetStylusPoints(inkCanvas1, description3); //</Snippet26> }
internal IntPtr FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, ref bool handled) { IntPtr result = IntPtr.Zero; // It is possible to be re-entered during disposal. Just return. if (null == _source || null == _source.Value) { return(result); } switch (msg) { case WindowMessage.WM_ENABLE: _stylusLogic.Value.OnWindowEnableChanged(hwnd, (int)NativeMethods.IntPtrToInt32(wParam) == 0); break; case WindowMessage.WM_TABLET_QUERYSYSTEMGESTURESTATUS: handled = true; NativeMethods.POINT pt1 = new NativeMethods.POINT( NativeMethods.SignedLOWORD(lParam), NativeMethods.SignedHIWORD(lParam)); SafeNativeMethods.ScreenToClient(new HandleRef(this, hwnd), pt1); Point ptClient1 = new Point(pt1.x, pt1.y); IInputElement inputElement = StylusDevice.LocalHitTest(_source.Value, ptClient1); if (inputElement != null) { // walk up the parent chain DependencyObject elementCur = (DependencyObject)inputElement; bool isPressAndHoldEnabled = Stylus.GetIsPressAndHoldEnabled(elementCur); bool isFlicksEnabled = Stylus.GetIsFlicksEnabled(elementCur); bool isTapFeedbackEnabled = Stylus.GetIsTapFeedbackEnabled(elementCur); bool isTouchFeedbackEnabled = Stylus.GetIsTouchFeedbackEnabled(elementCur); uint flags = 0; if (!isPressAndHoldEnabled) { flags |= TABLET_PRESSANDHOLD_DISABLED; } if (!isTapFeedbackEnabled) { flags |= TABLET_TAPFEEDBACK_DISABLED; } if (isTouchFeedbackEnabled) { flags |= TABLET_TOUCHUI_FORCEON; } else { flags |= TABLET_TOUCHUI_FORCEOFF; } if (!isFlicksEnabled) { flags |= TABLET_FLICKS_DISABLED; } result = new IntPtr(flags); } break; case WindowMessage.WM_TABLET_FLICK: handled = true; int flickData = NativeMethods.IntPtrToInt32(wParam); // We always handle any scroll actions if we are enabled. We do this when we see the SystemGesture Flick come through. // Note: Scrolling happens on window flicked on even if it is not the active window. if (_stylusLogic != null && _stylusLogic.Value.Enabled && (StylusLogic.GetFlickAction(flickData) == 1)) { result = new IntPtr(0x0001); // tell UIHub the flick has already been handled. } break; } if (handled && EventTrace.IsEnabled(EventTrace.Keyword.KeywordInput | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Info)) { EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientInputMessage, EventTrace.Keyword.KeywordInput | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Info, (_source.Value.CompositionTarget != null ? _source.Value.CompositionTarget.Dispatcher.GetHashCode() : 0), hwnd.ToInt64(), msg, (int)wParam, (int)lParam); } return(result); }
// Summary: // Initializes a new instance of the System.Windows.Input.StylusEventArgs class. // // Parameters: // stylus: // The stylus to associate with the event. // // timestamp: // The time when the event occurs. public StylusEventArgs(StylusDevice stylus, int timestamp) : base(stylus, timestamp) { throw new NotImplementedException(); }
public override void Reset(StylusDevice stylusDevice, StylusPointCollection stylusPoints) { //base.Reset(stylusDevice, stylusPoints); }
internal IInputElement FindTarget(PresentationSource inputSource, Point position) { IInputElement stylusOver = null; switch (_captureMode) { case CaptureMode.None: { stylusOver = StylusDevice.GlobalHitTest(inputSource, position); // We understand UIElements and ContentElements. // If we are over something else (like a raw visual) // find the containing element. if (!InputElement.IsValid(stylusOver)) { stylusOver = InputElement.GetContainingInputElement(stylusOver as DependencyObject); } } break; case CaptureMode.Element: stylusOver = _stylusCapture; break; case CaptureMode.SubTree: { IInputElement stylusCapture = InputElement.GetContainingInputElement(_stylusCapture as DependencyObject); if (stylusCapture != null && inputSource != null) { // We need to re-hit-test to get the "real" UIElement we are over. // This allows us to have our capture-to-subtree span multiple windows. // GlobalHitTest always returns an IInputElement, so we are sure to have one. stylusOver = StylusDevice.GlobalHitTest(inputSource, position); } if (stylusOver != null && !InputElement.IsValid(stylusOver)) { stylusOver = InputElement.GetContainingInputElement(stylusOver as DependencyObject); } // Make sure that the element we hit is acutally underneath // our captured element. Because we did a global hit test, we // could have hit an element in a completely different window. // // Note that we support the child being in a completely different window. // So we use the GetUIParent method instead of just looking at // visual/content parents. if (stylusOver != null) { IInputElement ieTest = stylusOver; UIElement eTest = null; ContentElement ceTest = null; while (ieTest != null && ieTest != stylusCapture) { eTest = ieTest as UIElement; if (eTest != null) { ieTest = InputElement.GetContainingInputElement(eTest.GetUIParent(true)); } else { ceTest = ieTest as ContentElement; // Should never fail. ieTest = InputElement.GetContainingInputElement(ceTest.GetUIParent(true)); } } // If we missed the capture point, we didn't hit anything. if (ieTest != stylusCapture) { stylusOver = _stylusCapture; } } else { // We didn't hit anything. Consider the stylus over the capture point. stylusOver = _stylusCapture; } } break; } return(stylusOver); }
// When user clicks button, // Display capabilities to panel private void Button1Click(object sender, RoutedEventArgs e) { // Clear the textbox if they clicked once before textbox1.Clear(); // <Snippet1> // Get the current stylus device StylusDevice myStylusDevice = Stylus.CurrentStylusDevice; // </Snippet1> // Check whether we got the current stylus if (null == myStylusDevice) { textbox1.AppendText("No current stylus device\n"); // Try to get it through the default tablet TabletDevice defaultTabletDevice = Tablet.TabletDevices[0]; // Quit if we did not get the default tablet if (null == defaultTabletDevice) { textbox1.AppendText("No default tablet device. Goodby!\n"); return; } // Now try to get the default stylus device through the default tablet device StylusDeviceCollection myStylusDeviceCollection = defaultTabletDevice.StylusDevices; int numStylusDevices = myStylusDeviceCollection.Count; // If none returned, we are toast, so quit if (numStylusDevices < 1) { textbox1.AppendText("No stylus devices attached.\n"); return; } else { // We have at least one stylus device, so just grab the first one textbox1.AppendText("Got " + numStylusDevices + " stylus device through default tablet\n"); myStylusDevice = myStylusDeviceCollection[0]; } } // See what properties the default stylus device has // <Snippet2> PresentationSource myPresentationSource = myStylusDevice.ActiveSource; if (null == myPresentationSource) { textbox1.AppendText("ActiveSource : null\n"); } else { textbox1.AppendText("ActiveSource :" + myPresentationSource.ToString() + "\n"); } // </Snippet2> // <Snippet15> TabletDevice myTabletDevice = myStylusDevice.TabletDevice; // </Snippet15> // <Snippet3> // Bind stylus to tablet's input element myStylusDevice.Capture(myStylusDevice.Target); // </Snippet3> // <Snippet4> // See to what Captured property is set // First see if it's null if (null == myStylusDevice.Captured) { textbox1.AppendText("Captured: null\n"); } else { // Otherwise display the underlying type textbox1.AppendText("Captured: " + myStylusDevice.Captured.GetType().Name + "\n"); } // </Snippet4> // <Snippet5> // Bind stylus to tablet's input element // through entire subtree myStylusDevice.Capture(myStylusDevice.Target, CaptureMode.SubTree); // </Snippet5> // <Snippet6> // See to what DirectlyOver property is set // First see if it's null if (null == myStylusDevice.DirectlyOver) { textbox1.AppendText("DirectlyOver: null\n"); } else { // Otherwise display the underlying type textbox1.AppendText("DirectlyOver: " + myStylusDevice.DirectlyOver.GetType().Name + "\n"); } // </Snippet6> //StylusPointDescription // <Snippet7> StylusPointCollection myStylusPoints = myStylusDevice.GetStylusPoints(myStylusDevice.Target); textbox1.AppendText("Got " + myStylusPoints.Count.ToString() + " packets\n"); // </Snippet7> // <Snippet8> Point myPoint = myStylusDevice.GetPosition(myStylusDevice.Target); textbox1.AppendText("The relative position is: (" + myPoint.X.ToString() + "," + myPoint.Y.ToString() + ")\n"); // </Snippet8> // <Snippet9> textbox1.AppendText("Id: " + myStylusDevice.Id.ToString() + "\n"); // </Snippet9> // <Snippet11> textbox1.AppendText("InRange: " + myStylusDevice.InRange.ToString() + "\n"); // </Snippet11> // <Snippet13> textbox1.AppendText("Name: " + myStylusDevice.Name + "\n"); // </Snippet13> // <Snippet14> StylusButtonCollection myStylusButtonCollection = myStylusDevice.StylusButtons; if (null == myStylusButtonCollection) { textbox1.AppendText("StylusButtons: null\n"); } else { textbox1.AppendText("# of StylusButtons == " + myStylusButtonCollection.Count.ToString() + "\n"); } // </Snippet14> // Snippet 15 (TabletDevice property) is between snippet 2 and snippet 3 // <Snippet16> // See to what Target property is set // First see if it's null if (null == myStylusDevice.Target) { textbox1.AppendText("Target: null\n"); } else { // Otherwise display the underlying type textbox1.AppendText("Target: " + myStylusDevice.Target.GetType().Name + "\n"); } // </Snippet16> // <Snippet17> textbox1.AppendText("\n" + "StylusDevice: " + myStylusDevice.ToString() + "\n"); // </Snippet17> // StylusButton members // Dummy array to hold result of CopyTo method StylusButton[] myStylusButtonArray = new StylusButton[100]; int index = 0; // <Snippet19> myStylusButtonCollection.CopyTo(myStylusButtonArray, index); // </Snippet19> // <Snippet20> // Get the names of the buttons for (int i = 0; i < myStylusButtonCollection.Count; i++) { textbox1.AppendText("Button[" + i + "]: " + myStylusButtonCollection[i].Name); } // </Snippet20> // <Snippet21> // Ensure collection access is synchronized //if (!myStylusButtonCollection.IsSynchronized) //{ // lock (myStylusButtonCollection.SyncRoot) // { // // work with collection // } //} // </Snippet21> // <Snippet22> // Get the names of all of the of StylusButton objects // and store them in an ArrayList ArrayList myStylusButtonNamesArrayList = new ArrayList(); foreach (StylusButton sb in myStylusButtonCollection) { myStylusButtonNamesArrayList.Add(sb.Name); } // </Snippet22> // <Snippet23> // Get the first StylusButton, if it exists if (myStylusButtonCollection.Count > 0) { StylusButton mySB = myStylusButtonCollection[0]; } // </Snippet23> StylusButton myStylusButton = myStylusButtonCollection[0]; // <Snippet25> // Get the name of the StylusButton textbox1.AppendText("StylusButton.Name: " + myStylusButton.Name + "\n"); // </Snippet25> // <Snippet26> // Get the state of the StylusButton switch (myStylusButton.StylusButtonState) { case StylusButtonState.Down: textbox1.AppendText("StylusButton.State: Down\n"); break; default: // StylusButtonState.Up textbox1.AppendText("StylusButton.State: Up\n"); break; } // </Snippet26> // <Snippet27> // Get the name of the StylusDevice to which the StylusButton is attached textbox1.AppendText("StylusButton.StylusDevice: " + myStylusButton.StylusDevice.Name + "\n"); // </Snippet27> // <Snippet28> // Get string representation of the StylusButton textbox1.AppendText("\n" + myStylusButton.ToString() + "\n"); // </Snippet28> }