protected override void OnStrokeCollected(InkCanvasStrokeCollectedEventArgs E) { void AddCustomStroke(Stroke CustomStroke) { Strokes.Remove(E.Stroke); // Remove two history items if (DataContext is ImageEditorViewModel vm) { vm.RemoveLastHistory(); vm.RemoveLastHistory(); } Strokes.Add(CustomStroke); var args = new InkCanvasStrokeCollectedEventArgs(CustomStroke); base.OnStrokeCollected(args); } if (DynamicRenderer is IDynamicRenderer renderer) { AddCustomStroke(renderer.GetStroke(E.Stroke.StylusPoints, E.Stroke.DrawingAttributes)); } else { base.OnStrokeCollected(E); } }
public void Duplicate() { if (SelectedStrokesIds.Count > 0) { Clipboard = new StrokeList(SelectedStrokes); } if (Clipboard == null) { return; } SelectionChanged?.Invoke(new StrokeList()); var copiedStrokes = new StrokeList(); var translationMatrix = Constants.DuplicationTransform; var offset = 0; foreach (var s in Clipboard.OrderBy(x => (x as StrokeModel)?.CreatedDate)) { var strokeModel = new StrokeModel(s.Clone(), UserId); strokeModel.CreatedDate = strokeModel.CreatedDate.AddMilliseconds(offset++); strokeModel.Transform(translationMatrix, false); copiedStrokes.Add(strokeModel); } Strokes.Add(new StrokeCollection(copiedStrokes)); SelectionChanged?.Invoke(copiedStrokes); EditingMode = InkCanvasEditingMode.Select; }
/// <summary> /// Redo image edits that were undone /// </summary> internal void Redo() { int index = redoActions.Count - 1; if (index < 0) { return; } if (redoActions[index] == InkCanvasEditingMode.Ink) { Strokes.Add(redoStrokes[index]); } else if (redoActions[index] == InkCanvasEditingMode.EraseByStroke) { Strokes.RemoveAt(Strokes.Count - 1); } else if (redoActions[index] == InkCanvasEditingMode.None) { Strokes.Clear(); } undoActions.Add(redoActions[index]); undoStrokes.Add(redoStrokes[index]); redoActions.RemoveAt(index); redoStrokes.RemoveAt(index); }
private void StrokeHandle(Stroke stroke) { Application.Current.Dispatcher.Invoke(() => { Strokes.Add(stroke); }); }
public virtual void BeginStroke(Pen style) { activeStroke = new Stroke(style); Strokes.RemoveRange(Strokes.Count - undo, undo); undo = 0; Strokes.Add(activeStroke); }
// Busca el texto de las clases. Si la opcion es: // - 0=>Nombre de la clase // - 1=>Atributos // - 2=>Metodos public static String FindTextClass(Class c, Strokes strokes_text, int option) { Strokes reco_name = FormManager.ink_overlay.Ink.CreateStrokes(); String name = null; // Se obtienen los puntos necesarios de la clase int s1_X = c.GetS1().GetPoint(0).X; int s2_X = c.GetS2().GetPoint(0).X; int s3_Y = 0; int s4_Y = 0; switch (option) { case 0: s3_Y = c.GetS3().GetPoint(0).Y; s4_Y = c.GetS4().GetPoint(0).Y; break; case 1: s3_Y = c.GetS4().GetPoint(0).Y; s4_Y = c.GetS5().GetPoint(0).Y; break; case 2: s3_Y = c.GetS5().GetPoint(0).Y; s4_Y = c.GetS6().GetPoint(0).Y; break; default: break; } // Se recorren los strokes reconocidos como texto, y los que esten entre s3 y s4 de // la clase, forman el nombre, y es lo que se reconoce for (int i = 0; i < strokes_text.Count; i++) { Stroke s = strokes_text[i]; // Se obtienen los puntos de la esquina superior izquierda del stroke int s_X = s.GetBoundingBox().X; int s_Y = s.GetBoundingBox().Y; // Si el stroke esta entre los lados 1,2,3 y 4 de la clase, pertenece al // nombre de la clase if ((s1_X < s_X) && (s2_X > s_X) && (s3_Y < s_Y) && (s4_Y > s_Y)) { reco_name.Add(s); Facade.strokes_recognized.Add(s); } } name = reco_name.ToString(); return(name); }
private void RedoButton_Click(object sender, RoutedEventArgs e) { if (UndoneStrokes.Count == 0) { return; } Strokes.Add(UndoneStrokes.Last()); UndoneStrokes.Remove(UndoneStrokes.Last()); }
protected override void OnStrokeCollected(InkCanvasStrokeCollectedEventArgs e) { Strokes.Remove(e.Stroke); var customStroke = new SmoothableStroke(e.Stroke.GetBezierStylusPoints()); Strokes.Add(customStroke); InkCanvasStrokeCollectedEventArgs args = new InkCanvasStrokeCollectedEventArgs(customStroke); base.OnStrokeCollected(args); }
public void Divider(Stroke s) { if (TextShapeDivider.Divide(s) == 1) { strokes_text.Add(s); } else { strokes_shape.Add(s); } }
private void RemoveInk() { using (Synchronizer.Lock(this)) { // Collect all of the strokes we're supposed to delete. using (Synchronizer.Lock(this.m_Watcher.m_InkSheet.Ink.Strokes.SyncRoot)) { Strokes deleting = this.m_Watcher.m_InkSheet.Ink.CreateStrokes(); foreach (Stroke stroke in this.m_Watcher.m_InkSheet.Ink.Strokes) { if (stroke.ExtendedProperties.DoesPropertyExist(StrokeIdExtendedProperty)) { if (Array.IndexOf(this.m_StrokesToRemove, stroke.ExtendedProperties[StrokeIdExtendedProperty].Data) >= 0) { deleting.Add(stroke); } } } // It's possible that some of the strokes have been deleted elsewhere. // But this shouldn't happen because doing so should have caused an InkUndoer to be // pushed onto the Undo stack. So, for now, this check is "merely" a Debug.Assert. // TODO: Decide whether this should be an error, or at least whether it should // invalidate the rest of the undo stack. Debug.Assert(deleting.Count == this.m_StrokesToRemove.Length); // Get the stroke Ids so we can make a copy of the ink and fire the OnDeleting and OnDeleted events. int[] ids = new int[deleting.Count]; for (int i = 0; i < ids.Length; i++) // Is there a better way to get the array of Ids? { ids[i] = deleting[i].Id; } // Make a copy of the strokes, because if the original ink is later deleted // from the Ink object then it will become unusable. Ink ink = this.m_Watcher.m_InkSheet.Ink.ExtractStrokes(deleting, ExtractFlags.CopyFromOriginal); this.m_StrokesToAdd = ink.Strokes; this.m_StrokesToRemove = null; // Create the event arguments and add them to the ignore list so the // InkSheetUndoService won't create an InkUndoer for this change. StrokesEventArgs args = new StrokesEventArgs(ids); using (Synchronizer.Lock(this.m_Watcher.m_Ignore.SyncRoot)) { this.m_Watcher.m_Ignore.Add(args); } // Actually delete the ink, firing the appropriate events on the InkSheetModel. this.m_Watcher.m_InkSheet.OnInkDeleting(args); this.m_Watcher.m_InkSheet.Ink.DeleteStrokes(deleting); this.m_Watcher.m_InkSheet.OnInkDeleted(args); } } }
public void Redo() { if (UndoneStrokes.Count == 0) { return; } lock (StrokesLock) { var strokeToRedo = UndoneStrokes.Pop(); Strokes.Add(strokeToRedo); StrokeCollection.UpdateStroke(strokeToRedo.Id, strokeToRedo); } }
public override void TouchesEnded(NSSet touches, UIEvent evt) { base.TouchesEnded(touches, evt); var loc = (touches.AnyObject as UITouch).LocationInView(this); CurrentStroke.Points.Add(new Point(loc.X, loc.Y)); CurrentPathView.AddLineTo(loc); Strokes.Add(CurrentStroke); drawPath(); CurrentPathView.Clear(); SetNeedsDisplay(); }
private void MouseDownCommandExecuted(MouseEventArgs e) { if (EditingMode == InkCanvasEditingMode.None) { startPoint = new StylusPoint(e.GetPosition((InkCanvas)e.Source).X, e.GetPosition((InkCanvas)e.Source).Y); lastStroke = new Stroke(new StylusPointCollection() { startPoint }); lastStroke.DrawingAttributes.Color = DefaultDrawingAttributes.Color; Strokes.Add(lastStroke); } else if (EditingMode == InkCanvasEditingMode.Ink & DefaultDrawingAttributes.Color == Colors.White) { } }
private void UpdateStrokes() { App.Current.Dispatcher.Invoke(() => { // Do we need a lock here? IsRefreshingStrokes = true; var newStrokes = new StrokeCollection(StrokeCollection.GetMergedStrokeMaps()); Strokes.Clear(); Strokes.Add(newStrokes); if (EditingMode == InkCanvasEditingMode.Select) { SelectionChanged?.Invoke(SelectedStrokes); } IsRefreshingStrokes = false; }); }
protected override void OnStrokeCollected(InkCanvasStrokeCollectedEventArgs E) { void AddCustomStroke(Stroke CustomStroke) { Strokes.Remove(E.Stroke); // Remove two history items if (DataContext is ImageEditorViewModel vm) { vm.RemoveLastHistory(); vm.RemoveLastHistory(); } Strokes.Add(CustomStroke); var args = new InkCanvasStrokeCollectedEventArgs(CustomStroke); base.OnStrokeCollected(args); } switch (DynamicRenderer) { case LineDynamicRenderer _: AddCustomStroke(new Stroke(new StylusPointCollection(new [] { E.Stroke.StylusPoints.First(), E.Stroke.StylusPoints.Last() }), E.Stroke.DrawingAttributes)); break; case RectangleDynamicRenderer _: AddCustomStroke(new RectangleStroke(E.Stroke.StylusPoints, E.Stroke.DrawingAttributes)); break; case EllipseDynamicRenderer _: AddCustomStroke(new EllipseStroke(E.Stroke.StylusPoints, E.Stroke.DrawingAttributes)); break; default: base.OnStrokeCollected(E); break; } }
/// <summary> /// Undo edit actions performed /// </summary> internal void Undo() { int index = undoActions.Count - 1; if (index < 0) { return; } if (undoActions[index] == InkCanvasEditingMode.Ink) { Strokes.RemoveAt(Strokes.Count - 1); } else if (undoActions[index] == InkCanvasEditingMode.EraseByStroke) { Strokes.Add(undoStrokes[index]); } else if (undoActions[index] == InkCanvasEditingMode.None) { for (int i = 0; i < index; i++) { if (undoActions[i] == InkCanvasEditingMode.Ink) { Strokes.Add(undoStrokes[i]); } else if (undoActions[i] == InkCanvasEditingMode.EraseByStroke) { Strokes.Remove(undoStrokes[i]); } else if (undoActions[i] == InkCanvasEditingMode.None) { Strokes.Clear(); } } } redoActions.Add(undoActions[index]); redoStrokes.Add(undoStrokes[index]); undoActions.RemoveAt(index); undoStrokes.RemoveAt(index); }
protected override void OnStrokeCollected(InkCanvasStrokeCollectedEventArgs E) { void AddCustomStroke(Stroke CustomStroke) { Strokes.Remove(E.Stroke); Strokes.Add(CustomStroke); var args = new InkCanvasStrokeCollectedEventArgs(CustomStroke); base.OnStrokeCollected(args); } if (DynamicRenderer is IDynamicRenderer renderer) { AddCustomStroke(renderer.GetStroke(E.Stroke.StylusPoints, E.Stroke.DrawingAttributes)); } else { base.OnStrokeCollected(E); } }
void InkOverlay_Stroke(object sender, InkCollectorStrokeEventArgs e) { strokesToRecognize.Add(e.Stroke); recoContext.BackgroundRecognizeWithAlternates(); }
public void addStroke(Stroke stroke) { Strokes.Add(stroke); }
protected override void OnElementChanged(ElementChangedEventArgs <DrawingView> e) { base.OnElementChanged(e); if (Control == null && Element != null) { canvas = new InkCanvas { Background = Element.BackgroundColor.ToBrush(), DefaultDrawingAttributes = new() { Color = Element.DefaultLineColor.ToMediaColor(), Width = Element.DefaultLineWidth, Height = Element.DefaultLineWidth } }; Element.Lines.CollectionChanged += OnCollectionChanged; SetNativeControl(canvas); canvas.Strokes.StrokesChanged += OnStrokesChanged; Control !.PreviewMouseDown += OnPreviewMouseDown; } if (e.OldElement != null) { canvas !.Strokes.StrokesChanged -= OnStrokesChanged; Element !.Lines.CollectionChanged -= OnCollectionChanged; if (Control != null) { Control.PreviewMouseDown -= OnPreviewMouseDown; } } } void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs args) { canvas !.Strokes.StrokesChanged -= OnStrokesChanged; canvas.Strokes.Clear(); LoadLines(); canvas.Strokes.StrokesChanged += OnStrokesChanged; } void OnPreviewMouseDown(object sender, MouseButtonEventArgs e) => Clear(); void Clear(bool force = false) { if (!Element.MultiLineMode || force) { canvas !.Strokes.Clear(); Element.Lines.Clear(); } } void OnStrokesChanged(object sender, StrokeCollectionChangedEventArgs e) { Element.Lines.CollectionChanged -= OnCollectionChanged; if (e.Added.Count > 0) { if (!Element.MultiLineMode) { Element.Lines.Clear(); } var lines = Element.MultiLineMode ? e.Added : new StrokeCollection() { e.Added.First() }; foreach (var line in lines) { var points = line.StylusPoints.Select(point => new Point(point.X, point.Y)).ToList(); Element.Lines.Add(new Line() { Points = new ObservableCollection <Point>(points), LineColor = Color.FromRgba(line.DrawingAttributes.Color.R, line.DrawingAttributes.Color.G, line.DrawingAttributes.Color.B, line.DrawingAttributes.Color.A), LineWidth = (float)line.DrawingAttributes.Width }); } if (Element.Lines.Count > 0) { var lastLine = Element.Lines.Last(); if (Element.DrawingLineCompletedCommand?.CanExecute(lastLine) ?? false) { Element.DrawingLineCompletedCommand.Execute(lastLine); } } if (Element.ClearOnFinish) { Element.Lines.CollectionChanged -= OnCollectionChanged; Clear(true); canvas !.Strokes.StrokesChanged += OnStrokesChanged; } } Element.Lines.CollectionChanged += OnCollectionChanged; } void LoadLines() { var lines = Element.MultiLineMode ? Element.Lines : Element.Lines.Any() ? new ObservableCollection <Line> { Element.Lines.LastOrDefault() } : new ObservableCollection <Line>(); foreach (var line in lines) { var stylusPoints = line.Points.Select(point => new StylusPoint(point.X, point.Y)).ToList(); if (stylusPoints is { Count: > 0 }) { var stroke = new Stroke(new StylusPointCollection(stylusPoints)) { DrawingAttributes = new() { Color = line.LineColor.ToMediaColor(), Width = line.LineWidth, Height = line.LineWidth } }; canvas !.Strokes.Add(stroke); } } }
/// <summary> /// Adds a new stroke to be recognized. Call <see cref="Recognize"/> /// to convert the strokes to text. /// </summary> /// <param name="stroke">The stroke to add.</param> public void AddStroke(TouchStroke stroke) { EnsureNotDisposed(); _strokes.Add(_ink.CreateStroke(stroke.GetPoints())); }
public override bool OnTouchEvent(MotionEvent e) { if (!Enabled) { return(true); } float x = e.GetX(); float y = e.GetY(); float scale = GetDrawingScale(); if (backgroundBitmap != null) { float offsetX = (Width - backgroundBitmap.Width * scale) / 2.0f; float offsetY = (Height - backgroundBitmap.Height * scale) / 2.0f; x -= offsetX; y -= offsetY; if (x > backgroundBitmap.Width * scale) { x = backgroundBitmap.Width * scale; } if (y > backgroundBitmap.Height * scale) { y = backgroundBitmap.Height * scale; } } if (x < 0) { x = 0; } if (y < 0) { y = 0; } switch (e.Action) { case MotionEventActions.Down: currentStroke = new Abstractions.Stroke() { StrokeColor = StrokeColor.Clone(), Thickness = StrokeThickness }; currentStroke.Points.Add(new Abstractions.Point(x, y)); return(true); case MotionEventActions.Move: currentStroke.Points.Add(new Abstractions.Point(x, y)); drawingCanvas.DrawColor(Color.Transparent, PorterDuff.Mode.Clear); DrawCurrentStroke(drawingCanvas); Invalidate(); break; case MotionEventActions.Up: currentStroke.Points.Add(new Abstractions.Point(x, y)); drawingCanvas.DrawColor(Color.Transparent, PorterDuff.Mode.Clear); var smooth = CatmullRomSmoothing.SmoothPath(currentStroke.Points, 8); //Clamp the smooth strokes to the view foreach (var p in smooth) { if (p.X < 0) { p.X = 0; } if (p.Y < 0) { p.Y = 0; } if (backgroundBitmap != null) { if (p.X > backgroundBitmap.Width * scale) { p.X = backgroundBitmap.Width * scale; } if (p.Y > backgroundBitmap.Height * scale) { p.Y = backgroundBitmap.Height * scale; } } } currentStroke.Points = smooth; Strokes.Add(currentStroke); currentStroke = null; DrawStrokes(); Invalidate(); FinishedStrokeEvent?.Invoke(this, null); break; default: return(false); } return(true); }