public void undo() { if (_myGraphic.ShapeType != "relativeGraphic") { MathTool.getInstance().MoveStrokes(_myGraphic.Strokes, -offset_x, -offset_y); MathTool.getInstance().MoveStrokes(_myGraphic.textStrokeCollection, -offset_x, -offset_y); MathTool.getInstance().MoveStrokes(_myGraphic.PentagramStrokes, -offset_x, -offset_y); _myGraphic.Shape.Margin = new Thickness(_myGraphic.Shape.Margin.Left - offset_x, _myGraphic.Shape.Margin.Top - offset_y, 0, 0); GraphicMathTool.getInstance().SearchRelationByPosition(_myGraphic, MyGraphics, _inkCollector); } }
/// <summary> /// 删除与笔迹strokes相交的图形 /// </summary> /// <param name="strokes"></param> public void removeHitMyGraphics(StrokeCollection strokes) { List <MyGraphic> myGraphics = new List <MyGraphic>(); foreach (MyGraphic myGraphic in Sketch.MyGraphics) { if (MathTool.getInstance().isHitRects(myGraphic.Strokes.GetBounds(), strokes.GetBounds())) { myGraphics.Add(myGraphic); } } foreach (MyGraphic myGraphic in myGraphics) { GraphicMathTool.getInstance().deleteMyGraphic(myGraphic, this); } }
/// <summary> /// 删除graphic /// </summary> /// <param name="image"></param> public void RemoveMyGraphic(MyGraphic myGraphic) { _inkCanvas.Children.Remove(myGraphic.Shape); foreach (Stroke s in myGraphic.Strokes) { if (_inkCanvas.Strokes.IndexOf(s) != -1) { _inkCanvas.Strokes.Remove(s); } } foreach (Stroke s in myGraphic.textStrokeCollection) { if (_inkCanvas.Strokes.IndexOf(s) != -1) { _inkCanvas.Strokes.Remove(s); } } if (myGraphic.PentagramStrokes != null) { _inkCanvas.Strokes.Remove(myGraphic.PentagramStrokes); } GraphicMathTool.getInstance().searchExistRelationAndRemove(myGraphic, Sketch.MyGraphics, this); Sketch.RemoveMyGraphic(myGraphic); }
public override void _presenter_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { _inkCollector.IsAutoMove = true; _inkCanvas.CaptureMouse(); _startPoint = e.GetPosition(_inkCanvas); _prepoint = _startPoint; //button foreach (MyButton myButton in _inkCollector.Sketch.MyButtons) { if (myButton.IsDeleted == false && myButton.Button.Visibility == Visibility.Visible) { if (MathTool.getInstance().isCloseMyButton(_startPoint, myButton, -2) == true) { _inkCollector.SelectButtons.Add(myButton); myButton.InkFrame._inkCanvas.CaptureMouse(); myButton.InkFrame._inkCanvas.Cursor = Cursors.ScrollAll; myButton.TextBoxTime.Background = Brushes.CornflowerBlue; MoveOrZoom = "Move"; break; } if (MathTool.getInstance().isEncircleMyButton(_startPoint, myButton, -2, 20) == true) { _inkCollector.SelectButtons.Add(myButton); _inkCanvas.Cursor = new Cursor(GlobalValues.FilesPath + "/WPFInk/WPFInk/src/cursor/Zoom.cur"); myButton.TextBoxTime.Background = Brushes.CornflowerBlue; MoveOrZoom = "Zoom"; break; } } } //image foreach (MyImage myImage in _inkCollector.Sketch.Images) { if (MathTool.getInstance().isCloseRectangle(_startPoint, myImage.Bound, -2)) { _inkCollector.SelectedImages.Add(myImage); _inkCanvas.Cursor = Cursors.ScrollAll; myImage.Bound.Visibility = Visibility.Visible; MoveOrZoom = "Move"; } if (MathTool.getInstance().isEncircleRectangle(_startPoint, myImage.Bound, -2, 20)) { _inkCollector.SelectedImages.Add(myImage); _inkCanvas.Cursor = new Cursor(GlobalValues.FilesPath + "/WPFInk/WPFInk/src/cursor/Zoom.cur"); myImage.Bound.Visibility = Visibility.Visible; MoveOrZoom = "Zoom"; } } //stroke StrokeCollection strokes = new StrokeCollection(); foreach (MyStroke myStroke in _inkCollector.Sketch.MyStrokes) { //myStroke.Stroke.DrawingAttributes.Color = Colors.Red; strokes.Add(myStroke.Stroke); } StrokeCollection hitStrokes = strokes.HitTest(_startPoint, 10); if (hitStrokes.Count > 0) { foreach (Stroke stroke in hitStrokes) { foreach (MyStroke myStroke in _inkCollector.Sketch.MyStrokes) { if (myStroke.Stroke == stroke) { _inkCollector.SelectedStrokes.Add(myStroke); } } } _inkCanvas.Cursor = Cursors.ScrollAll; MoveOrZoom = "Move"; } //myGraphic foreach (MyGraphic myGraphic in _inkCollector.Sketch.MyGraphics) { if (myGraphic.ShapeType != "loopArc" && MathTool.getInstance().isPointInRectangle(MathTool.getInstance().RectToRectangle(myGraphic.Strokes.GetBounds()), _startPoint)) { //myGraphic.Stroke.DrawingAttributes.Color = Colors.Red; SelectedMyGraphics = GraphicMathTool.getInstance().getDirectRelativeMyGraphicLineHasSelf(myGraphic, _inkCollector, new List <MyGraphic>()); //_inkCollector._mainPage.message.Text= SelectedMyGraphics.Count.ToString(); _inkCanvas.Cursor = Cursors.ScrollAll; MoveOrZoom = "Move"; } } //Text,移动text,要求鼠标的位置在text周围,而不是上面 foreach (MyRichTextBox myRichTextBox in _inkCollector.Sketch.MyRichTextBoxs) { TextRange textRange = new TextRange(myRichTextBox.RichTextBox.Document.ContentStart, myRichTextBox.RichTextBox.Document.ContentEnd); string textRangeStr1 = textRange.Text.Replace(" ", ""); string textRangeStr2 = textRangeStr1.Replace("\r\n", ""); if (textRangeStr2 != "" && MathTool.getInstance().isEncircleRectangle(_startPoint, MathTool.getInstance().RectToRectangle(new Rect(new Point(myRichTextBox.RichTextBox.Margin.Left, myRichTextBox.RichTextBox.Margin.Top), new Point(myRichTextBox.RichTextBox.Margin.Left + myRichTextBox.RichTextBox.Width, myRichTextBox.RichTextBox.Margin.Top + myRichTextBox.RichTextBox.Height))), 0, 20)) { _inkCollector.SelectedMyRichTextBoxs.Add(myRichTextBox); myRichTextBox.RichTextBox.BorderBrush = new SolidColorBrush(Colors.Blue); _inkCanvas.Cursor = Cursors.ScrollAll; MoveOrZoom = "Move"; } } pressedMouseLeftButtonDown = true; }
public override void _presenter_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e) { if (pressedMouseLeftButtonDown) { if (_startPoint != null) { current = e.GetPosition(_inkCanvas); switch (MoveOrZoom) { case "Move": double offsetx = current.X - _startPoint.X; double offsety = current.Y - _startPoint.Y; _inkCollector.IsAutoMove = true; foreach (MyButton myButton in _inkCollector.SelectButtons) { myButton.InkFrame._inkCanvas.ReleaseMouseCapture(); myButton.InkFrame._inkCanvas.Cursor = Cursors.Arrow; myButton.TextBoxTime.Background = null; ButtonMoveCommand bmc = new ButtonMoveCommand(myButton, offsetx, offsety, _inkCollector); _inkCollector.CommandStack.Push(bmc); } if (_inkCollector.SelectedImages.Count > 0) { foreach (MyImage image in _inkCollector.SelectedImages) { Command imc = new ImageMoveCommand(image, offsetx, offsety); _inkCollector.CommandStack.Push(imc); image.Bound.Visibility = Visibility.Collapsed; _inkCanvas.Cursor = Cursors.Arrow; image.Image.ReleaseMouseCapture(); foreach (ImageConnector connector in image.ConnectorCollection) { connector.adjustConnector(); } } } if (_inkCollector.SelectedStrokes.Count > 0) { foreach (MyStroke myStroke in _inkCollector.SelectedStrokes) { MoveCommand mc = new MoveCommand(myStroke, offsetx, offsety); _inkCollector.CommandStack.Push(mc); } } //移动图形 if (SelectedMyGraphics.Count > 0) { foreach (MyGraphic myGraphic in SelectedMyGraphics) { MyGraphicMoveCommand mgmc = new MyGraphicMoveCommand(myGraphic, offsetx, offsety, _inkCollector); _inkCollector.CommandStack.Push(mgmc); mgmc.searchRelation(); } //MyGraphicsMoveCommand mgsmc = new MyGraphicsMoveCommand(SelectedMyGraphics, offsetx, offsety, _inkCollector.Sketch.MyGraphics, _inkCollector); //_inkCollector.CommandStack.Push(mgsmc); List <int> ids = GraphicMathTool.getInstance().getGraphicStructure(_inkCollector.Sketch.MyGraphics[0], _inkCollector, new List <int>()); foreach (int id in ids) { _inkCollector._mainPage.message.Content += id.ToString() + ","; } } //移动文本 foreach (MyRichTextBox myRichTextBox in _inkCollector.SelectedMyRichTextBoxs) { Command tmc = new TextMoveCommand(myRichTextBox, offsetx, offsety); myRichTextBox.RichTextBox.BorderBrush = null; _inkCollector.CommandStack.Push(tmc); } MoveOrZoom = ""; break; case "Zoom": _inkCollector.IsAutoMove = false; StylusPoint curr = new StylusPoint(current.X, current.Y); StylusPoint sta = new StylusPoint(_startPoint.X, _startPoint.Y); foreach (MyButton myButton in _inkCollector.SelectButtons) { double dist1 = MathTool.getInstance().distanceP2P(MathTool.getInstance().getMyButtonCenter(myButton), curr); double dist2 = MathTool.getInstance().distanceP2P(MathTool.getInstance().getMyButtonCenter(myButton), sta); if (dist2 == 0) { dist2 = 1; } double scaling = dist1 / dist2; _inkCanvas.Cursor = Cursors.Arrow; myButton.TextBoxTime.Background = null; ButtonZoomCommand bmc = new ButtonZoomCommand(myButton, scaling, _inkCollector, myButton.Angle); _inkCollector.CommandStack.Push(bmc); } foreach (MyImage image in _inkCollector.SelectedImages) { double dist1 = MathTool.getInstance().distanceP2P(MathTool.getInstance().getImageCenter(image), curr); double dist2 = MathTool.getInstance().distanceP2P(MathTool.getInstance().getImageCenter(image), sta); if (dist2 == 0) { dist2 = 1; } double scaling = dist1 / dist2; _inkCanvas.Cursor = Cursors.Arrow; image.Bound.Visibility = Visibility.Collapsed; ImageZoomCommand izc = new ImageZoomCommand(image, scaling); _inkCollector.CommandStack.Push(izc); foreach (ImageConnector connector in image.ConnectorCollection) { connector.adjustConnector(); } } MoveOrZoom = ""; break; } _inkCollector.SelectButtons.Clear(); _inkCollector.SelectedImages.Clear(); _inkCollector.SelectedStrokes.Clear(); _inkCollector.SelectedMyRichTextBoxs.Clear(); SelectedMyGraphics.Clear(); } _inkCanvas.ReleaseMouseCapture(); _inkCollector.IsAutoMove = false; pressedMouseLeftButtonDown = false; } }
public void searchRelation() { GraphicMathTool.getInstance().SearchRelationByPosition(_myGraphic, MyGraphics, _inkCollector); }