/// <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); }
/// <summary> /// StylusInputEnd /// </summary> /// <param name="commit">commit</param> protected override void StylusInputEnd(bool commit) { // The follow code raises Gesture and/or StrokeCollected event // The out-side code could throw exception in the their handlers. We use try/finally block to protect our status. try { if (commit) { // // It's possible that the input may end up without any StylusPoint being collected since the behavior can be deactivated by // the user code in the any event handler. if (_stylusPoints != null) { Debug.Assert(_strokeDrawingAttributes != null, "_strokeDrawingAttributes can not be null, did we not see a down?"); Stroke stroke = new Stroke(_stylusPoints, _strokeDrawingAttributes); //we don't add the stroke to the InkCanvas stroke collection until RaiseStrokeCollected //since this might be a gesture and in some modes, gestures don't get added InkCanvasStrokeCollectedEventArgs argsStroke = new InkCanvasStrokeCollectedEventArgs(stroke); InkCanvas.RaiseGestureOrStrokeCollected(argsStroke, _userInitiated); } } } finally { _stylusPoints = null; _strokeDrawingAttributes = null; _userInitiated = false; EditingCoordinator.InvalidateBehaviorCursor(this); } }
//------------------------------------------------------------------------------- // // Protected Methods // //------------------------------------------------------------------------------- #region Protected Methods /// <summary> /// Attaching to the element, we get attached in StylusDown /// </summary> protected override void OnActivate() { _actionStarted = false; // Capture the mouse. InitializeCapture(); // Hittest for the grab handle MouseDevice mouse = Mouse.PrimaryDevice; _hitResult = InkCanvas.SelectionAdorner.SelectionHandleHitTest( mouse.GetPosition((IInputElement)(InkCanvas.SelectionAdorner))); Debug.Assert(_hitResult != InkCanvasSelectionHitResult.None); EditingCoordinator.InvalidateBehaviorCursor(this); // Get the current selection bounds. _selectionRect = InkCanvas.GetSelectionBounds( ); // Set the initial tracking position and rectangle _previousLocation = mouse.GetPosition(InkCanvas.SelectionAdorner); _previousRect = _selectionRect; // Start the feedback rubber band. InkCanvas.InkCanvasSelection.StartFeedbackAdorner(_selectionRect, _hitResult); // Add handlers to the mouse events. InkCanvas.SelectionAdorner.AddHandler(Mouse.MouseUpEvent, new MouseButtonEventHandler(OnMouseUp)); InkCanvas.SelectionAdorner.AddHandler(Mouse.MouseMoveEvent, new MouseEventHandler(OnMouseMove)); InkCanvas.SelectionAdorner.AddHandler(UIElement.LostMouseCaptureEvent, new MouseEventHandler(OnLostMouseCapture)); }
/// <summary> /// This method updates the cursor when the mouse is hovering ont the selection adorner. /// It is called from /// OnAdornerMouseLeaveEvent /// OnAdornerMouseEvent /// </summary> /// <param name="hitPoint">the handle is being hit</param> private void UpdateSelectionCursor(Point hitPoint) { InkCanvasSelectionHitResult hitResult = HitTestOnSelectionAdorner(hitPoint); if ( _hitResult != hitResult ) { // Keep the current handle _hitResult = hitResult; EditingCoordinator.InvalidateBehaviorCursor(this); } }
protected override void OnActivate() { base.OnActivate(); InkCanvasEditingMode newEraseMode = EditingCoordinator.ActiveEditingMode; Debug.Assert(newEraseMode == InkCanvasEditingMode.EraseByPoint || newEraseMode == InkCanvasEditingMode.EraseByStroke); // Check whether we have to update cursor. if (_cachedEraseMode != newEraseMode) { // EraseMode is changed _cachedEraseMode = newEraseMode; EditingCoordinator.InvalidateBehaviorCursor(this); } else if (newEraseMode == InkCanvasEditingMode.EraseByPoint) { // Invalidate the PointEraser if we don't have the cache yet. bool isPointEraserCursorValid = _cachedStylusShape != null; // NTRAID:WINDOWSOS#1673398-2006/05/23-WAYNEZEN, // If the cached EraserShape is different from the current EraserShape, we shoud just reset the cache. // The new cursor will be generated when it's needed later. if (isPointEraserCursorValid && (_cachedStylusShape.Width != InkCanvas.EraserShape.Width || _cachedStylusShape.Height != InkCanvas.EraserShape.Height || _cachedStylusShape.Rotation != InkCanvas.EraserShape.Rotation || _cachedStylusShape.GetType() != InkCanvas.EraserShape.GetType())) { Debug.Assert(_cachedPointEraserCursor != null, "_cachedPointEraserCursor shouldn't be null."); ResetCachedPointEraserCursor(); isPointEraserCursorValid = false; } if (!isPointEraserCursorValid) { // EraserShape is changed when the new mode is EraseByPoint EditingCoordinator.InvalidateBehaviorCursor(this); } } }
/// <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) { // // get a disposable dynamic hit-tester and add event handler // _incrementalStrokeHitTester = this.InkCanvas.Strokes.GetIncrementalStrokeHitTester(this.InkCanvas.EraserShape); if (InkCanvasEditingMode.EraseByPoint == _cachedEraseMode) { _incrementalStrokeHitTester.StrokeHit += new StrokeHitEventHandler(OnPointEraseResultChanged); } else { //we're in stroke hit test mode _incrementalStrokeHitTester.StrokeHit += new StrokeHitEventHandler(OnStrokeEraseResultChanged); } _stylusPoints = new StylusPointCollection(stylusPoints.Description, 100); _stylusPoints.Add(stylusPoints); // // start erasing // _incrementalStrokeHitTester.AddPoints(stylusPoints); // NTRAID:WINDOWSOS#1642274-2006/05/10-WAYNEZEN, // Since InkCanvas will ignore the animated tranforms when it receives the property changes. // So we should update our cursor when the stylus is down if there are animated transforms applied to InkCanvas. if (InkCanvasEditingMode.EraseByPoint == _cachedEraseMode) { // 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); } }
/// <summary> /// Adorner MouseLeave Handler /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnAdornerMouseLeaveEvent(object sender, MouseEventArgs args) { // We are leaving the adorner, update our cursor. EditingCoordinator.InvalidateBehaviorCursor(this); }