public override void OnDrawing(IModel sender, PointerPoint args) { var f = args.Properties.Pressure; var s = size_prs ? Math.Max(size * size_min, size * f) : size; var d = density_prs ? Math.Max(density * density_min, density * f) : density; var b = blend_prs ? Math.Max(blend * blend_min, blend * (1 - f)) : blend; var layer = sender.CurrentLayer; var pr = new Rect((p.x - s), (p.y - s), (s * 2) + 2, (s * 2) + 2); if (!merge && orec != RectHelper.Union(orec, pr)) { merge = true; } p = new Point(-layer.X + args.Position.X, -layer.Y + args.Position.Y);// getPosition(e); rect = RectHelper.Intersect(RectHelper.Union(rect, pr), DrawRect); if (Vec2.testLen(p2, p, s * Graphics.Step)) { //gdi.DrawBerzier(p2, p1, p); gdi.DrawBerzier(p2, p1, p, s, hard, opacity, d, b, dilution); p2 = p1; p1 = p; } // View.DrawPanel.rec.setRect(rect); }
public override async void OnDrawCommit(IModel sender, PointerPoint args) { base.OnDrawCommit(sender, args); var area = sender.ElemArea as Border; if (area.Child == null) { return; } VModel.vm.Loading = true; var rb = await(area.Child as FrameworkElement).Render(); do { if (rb == null) { break; } sender.CurrentLayer.getRect(out Rect or, out WriteableBitmap ob); var layer = sender.CurrentLayer; var pos = (area.Child as FrameworkElement).RenderTransform as TranslateTransform; var rect = new Rect(pos.X, pos.Y, rb.PixelWidth, rb.PixelHeight); var nr = RectHelper.Intersect(or.IsEmpty ? rect : RectHelper.Union(rect, or), DrawRect); if (nr.IsEmpty) { break; } var i = sender.Layers.IndexOf(layer); var b = sender.CurrentLayer.Bitmap.Clone(); var nb = new WriteableBitmap((int)Math.Ceiling(nr.Width), (int)Math.Ceiling(nr.Height)); IGrap.addImg(b, nb, -(int)Math.Floor(nr.X - or.Left), -(int)Math.Floor(nr.Y - or.Top)); IGrap.addImg(rb, nb, -(int)Math.Floor(nr.X - rect.X), -(int)Math.Floor(nr.Y - rect.Y)); Exec.Do(new Exec() { exec = () => { sender.Layers[i].setRect(nr, nb); }, undo = () => { sender.Layers[i].setRect(or, ob); sender.CurrentLayer = sender.Layers[i]; } }); } while (false); VModel.vm.Loading = false; sender.ElemArea.Child = null; }
private void UnprocessedInput_PointerReleased(InkUnprocessedInput sender, PointerEventArgs args) { switch (this.toolbarMode) { case ToolbarMode.Erasing: if (this.isErasing) { args.Handled = true; } this.isErasing = false; break; case ToolbarMode.Lasso: if (this.isSelectionDragging) { this.isSelectionDragging = false; } else { if (this.isClickedOutsizeSelection) { if (this.InkSelectionToolbar.Visibility == Visibility.Collapsed) { this.ClearDrawnBoundingRect(); } } else { if (this.lasso != null) { Rect boundingRect = Rect.Empty; this.lasso.Points.Add(args.CurrentPoint.RawPosition); foreach (InkStrokeContainer item in this.strokes.ToArray()) { Rect rect = item.SelectWithPolyLine(this.lasso.Points); if (rect.Width > 0 && rect.Height > 0) { boundingRect = RectHelper.Union(boundingRect, rect); } } this.isBoundRect = false; this.DrawBoundingRect(boundingRect); } } } break; } }
private void OnExp(object sender, RoutedEventArgs e) { var i = Items.IndexOf(CurrentLayer); if (i + 1 >= Items.Count) { return; } var _u = Items[i]; var _d = Items[i + 1]; _u.getRect(out Rect ur, out WriteableBitmap ub); _d.getRect(out Rect dr, out WriteableBitmap db); var exm = RectHelper.Union(ur, dr); if (exm.IsEmpty) { return;//感谢反馈@microsoft } var ex = new WriteableBitmap((int)exm.Width, (int)exm.Height); IGrap.addImg(db, ex, (int)(_d.X - exm.X), (int)(_d.Y - exm.Y), _d.Opacity); IGrap.addImg(ub, ex, (int)(_u.X - exm.X), (int)(_u.Y - exm.Y), _u.Opacity); Exec.Do(new Exec() { exec = () => { Items.RemoveAt(i + 1); Items[i].setRect(exm, ex); }, undo = () => { Items[i].setRect(ur, ub); Items.Insert(i + 1, new LayerModel { Bitmap = db, X = dr.X, Y = dr.Y, }); }, }); }
public static void AddClonedNodes(InstructionGraph graph, IList <InstructionGraphNode.NodeData> nodes, Vector2 position) { var bounds = nodes[0].Bounds; foreach (var node in nodes) { bounds = RectHelper.Union(bounds, node.Bounds); } var offset = new Vector2(position.x - bounds.xMin, position.y - bounds.yMin); using (new UndoScope(graph, true)) { foreach (var node in nodes) { node.Position += offset; graph.Nodes.Add(node.Node); Undo.RegisterCreatedObjectUndo(node.Node, "Paste Node"); AssetDatabase.AddObjectToAsset(node.Node, graph); } AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(graph)); } }
private void UnprocessedInput_PointerMoved(InkUnprocessedInput sender, PointerEventArgs args) { switch (this.toolbarMode) { case ToolbarMode.Erasing: if (!this.isErasing) { return; } //bool invalidate = false; //draw rectange for eraser eraser = new Rect(args.CurrentPoint.Position, new Size(30, 30)); #region try 2 InkStroke newStroke1 = null; InkStroke newStroke2 = null; List <InkPoint> newpoints1 = new List <InkPoint>(); List <InkPoint> newpoints2 = new List <InkPoint>(); InkStrokeContainer newContainer1 = new InkStrokeContainer(); InkStrokeContainer newContainer2 = new InkStrokeContainer(); InkStrokeBuilder creator = new InkStrokeBuilder(); System.Numerics.Matrix3x2 matr = System.Numerics.Matrix3x2.Identity; foreach (InkStrokeContainer item in this.strokes.ToArray()) { Rect rect = item.SelectWithLine(this.lastPoint, args.CurrentPoint.Position); if (rect.Width == 0 && rect.Height == 0) { Debug.WriteLine("skipping InkStrokeContainer from strokes collection"); continue; } Debug.WriteLine("ciclyng strokes collection"); //Rect rect = item.SelectWithLine(this.lastPoint, args.CurrentPoint.Position); //if (rect.IsEmpty) continue; //if (rect.Width * rect.Height > 0) //{ var selectedStrokes = item.GetStrokes(); foreach (InkStroke stroke in selectedStrokes) { if (stroke.Selected == false) { continue; } //Debug.WriteLine("ciclyng selectedStrokes"); creator.SetDefaultDrawingAttributes(stroke.DrawingAttributes); bool switchToSecond = false; foreach (InkPoint point in stroke.GetInkPoints()) { //Debug.WriteLine("ciclyng GetInkPoints"); if (eraser.Contains(point.Position) == false) { if (switchToSecond == false) { newpoints1.Add(point); } else { newpoints2.Add(point); } } else { switchToSecond = true; } } if (newpoints1.Count > 0) { newStroke1 = creator.CreateStrokeFromInkPoints(newpoints1, matr); if (newStroke1 != null) { if (newContainer1 == null) { newContainer1 = new InkStrokeContainer(); } newContainer1.AddStroke(newStroke1); } } if (newpoints2.Count > 0) { newStroke2 = creator.CreateStrokeFromInkPoints(newpoints2, matr); if (newStroke2 != null) { if (newContainer2 == null) { newContainer2 = new InkStrokeContainer(); } newContainer2.AddStroke(newStroke2); } } } this.strokes.Remove(item); if (newContainer1 != null) { this.strokes.Add(newContainer1); } if (newContainer2 != null) { this.strokes.Add(newContainer2); } //canvas.Invalidate(); //invalidate = true; //} } newStroke1 = null; newStroke2 = null; newpoints1.Clear(); newpoints2.Clear(); newContainer1 = new InkStrokeContainer(); newContainer2 = new InkStrokeContainer(); #endregion this.lastPoint = args.CurrentPoint.Position; args.Handled = true; //if (invalidate) //{ // this.canvas.Invalidate(); //} //eraser = Rect.Empty; canvas.Invalidate(); break; case ToolbarMode.Lasso: if (this.isBoundRect) { if (args.CurrentPoint.RawPosition.X > 0 && args.CurrentPoint.RawPosition.Y > 0 && args.CurrentPoint.RawPosition.X < this.ActualWidth && args.CurrentPoint.RawPosition.Y < this.ActualHeight) { this.lasso.Points.Add(args.CurrentPoint.RawPosition); } } if (this.isSelectionDragging) { Rect boundingRect = Rect.Empty; Point upperLeft = new Point(args.CurrentPoint.RawPosition.X - this.selectionOffset.Width, args.CurrentPoint.RawPosition.Y - this.selectionOffset.Height); if (upperLeft.X > 0 && upperLeft.Y > 0 && upperLeft.X + this.selectionRectangle.Value.Width < this.ActualWidth && upperLeft.Y + this.selectionRectangle.Value.Height < this.ActualHeight) { Point point = new Point(args.CurrentPoint.RawPosition.X - this.selectionDragPoint.X, args.CurrentPoint.RawPosition.Y - this.selectionDragPoint.Y); foreach (InkStrokeContainer item in this.strokes.ToArray()) { Rect rect = item.MoveSelected(point); if (rect.Width > 0 && rect.Height > 0) { boundingRect = RectHelper.Union(boundingRect, rect); } } this.DrawBoundingRect(boundingRect); } this.canvas.Invalidate(); this.selectionDragPoint = args.CurrentPoint.RawPosition; } break; } }
public override async void OnDrawCommit(IModel sender, PointerPoint args) { if (rect.IsEmpty) { OnDrawRollback(sender, args); return; } var layer = sender.CurrentLayer; if (Clipper.IsCliping) { //sender.X.Source = bmp; VModel.vm.Loading = true; var bmp = await layer.Child.Render(); VModel.vm.Loading = false; var pos = (Point)layer.Child.Tag; IGrap.addImg(bmp, layer.Bitmap, (int)Math.Round(pos.X), (int)Math.Round(pos.Y)); layer.Child = null; } if (merge) { var or = orec; var ob = obmp; var nr = RectHelper.Intersect(RectHelper.Union(rect, orec), DrawRect); var i = sender.Layers.IndexOf(layer); var nb = IGrap.clipImg(layer.Bitmap, nr); Exec.Do(new Exec() { exec = () => { sender.Layers[i].setRect(nr, nb); }, undo = () => { sender.Layers[i].setRect(or, ob); sender.CurrentLayer = sender.Layers[i]; } }); } else { var or = orec; var nr = rect; var nb = IGrap.clipImg(layer.Bitmap, nr); layer.setRect(orec, obmp); nr.X -= or.X; nr.Y -= or.Y; var ob = IGrap.clipImg(obmp, nr); var i = sender.Layers.IndexOf(layer); Exec.Do(new Exec() { exec = () => { layer = sender.Layers[i]; IGrap.copyImg(nb, layer.Bitmap, (int)Math.Floor(nr.X), (int)Math.Floor(nr.Y)); layer.Bitmap.Invalidate(); }, undo = () => { layer = sender.Layers[i]; IGrap.copyImg(ob, layer.Bitmap, (int)Math.Floor(nr.X), (int)Math.Floor(nr.Y)); layer.Bitmap.Invalidate(); sender.CurrentLayer = sender.Layers[i]; } }); } }