public DeleteStrokeCommand(InkCollector inkcollector, Stroke stroke) { _inkcollector = inkcollector; _sketch = inkcollector.Sketch; _stroke = stroke; _mystroke = _sketch.GetStroke(stroke); }
public DeleteStrokeCommand(InkCollector inkcollector, MyStroke stroke) { _inkcollector = inkcollector; _sketch = _inkcollector.Sketch; _mystroke = stroke; _stroke = stroke.Stroke; }
public ZoomCommand(MyStroke myStroke, double scaling) { _myStroke = myStroke; Rect bounds = myStroke.Stroke.GetBounds(); center = new StylusPoint(bounds.Left + bounds.Width / 2, bounds.Top + bounds.Height / 2); this.scaling = scaling; }
//导入草图方法 public void LoadSketch(List <System.Drawing.Bitmap> BitmapList, List <Point> points, int width, int height) { List <BitmapImage> bmpList = new List <BitmapImage>(); int i = 0; foreach (System.Drawing.Bitmap bit in BitmapList) { bmpList.Add(WPFInk.tool.ConvertClass.getInstance().BitmapToBitmapImage(bit)); } int j; string pathName = GlobalValues.FilesPath + "//WPFink/0.bmp"; BitmapList[0].Save(pathName); MyImage preMyImage = new MyImage(pathName); MyImage MyImage0 = preMyImage; preMyImage.Width = width; preMyImage.Height = height; preMyImage.Left = points[0].X; preMyImage.Top = points[0].Y; preMyImage.PathName = pathName; preMyImage.setLocation((int)points[0].X, (int)points[0].Y); InkConstants.AddBound(preMyImage); AddImageCommand cmd = new AddImageCommand(InkCollector, preMyImage); cmd.execute(); ImageConnector connector = null; for (i = 0; i < bmpList.Count - 1; i++) { j = i + 1; pathName = GlobalValues.FilesPath + "//WPFink/" + j + ".bmp"; BitmapList[j].Save(pathName); MyImage newimage = new MyImage(pathName); newimage.Width = width; newimage.Height = height; newimage.setLocation((int)points[j].X, (int)points[j].Y); newimage.Left = points[j].X; newimage.Top = points[j].Y; newimage.PathName = pathName; InkConstants.AddBound(newimage); AddImageCommand cmd2 = new AddImageCommand(InkCollector, newimage); cmd2.execute(); connector = new ImageConnector(preMyImage, newimage); preMyImage = newimage; MyStroke myStroke = connector.MYSTROKE; myStroke.Stroke.DrawingAttributes.Width = 4; myStroke.Stroke.DrawingAttributes.Height = 4; myStroke.IsSketchConnector = true; Command sc = new AddStrokeCommand(InkCollector, myStroke); sc.execute(); } }
/// <summary> /// 笔迹回放 /// </summary> private void strokePlay() { if ((strokesForPlayback.Count == 0) || (_inkCollector.IsPlaying == false))//没有要播放的笔迹或者不在播放状态 { return; } MyStroke currentStroke = strokesForPlayback[playbackStrokeIndex]; if (playbackPointIndex == 0) { StylusPointCollection spc = new StylusPointCollection(); spc.Add(currentStroke.Stroke.StylusPoints[playbackPointIndex]); strokeToPlayback = new Stroke(spc); strokeToPlayback.DrawingAttributes = currentStroke.DrawingAttributes; _inkFrame._inkCanvas.Strokes.Add(strokeToPlayback); double progress = (double)(playbackStrokeIndex + 1) / (double)(strokesForPlayback.Count); this.timeBar.setProgress(progress); } strokeToPlayback.StylusPoints.Add(currentStroke.StylusPoints[playbackPointIndex]); playbackPointIndex++; if (playbackPointIndex < currentStroke.StylusPoints.Count) { strokeToPlayback.StylusPoints.Add(currentStroke.StylusPoints[playbackPointIndex]); playbackPointIndex++; } this.timeBar.StrokePlayButton = StrokePlayButton.StopPlay; if (playbackPointIndex == currentStroke.StylusPoints.Count) { playbackPointIndex = 0; playbackStrokeIndex++; if (playbackStrokeIndex >= strokesForPlayback.Count) { //结束播放 _inkCollector.Mode = InkMode.Ink; _inkFrame._inkCanvas.Strokes.Clear(); for (int i = 0; i < _inkCollector.Sketch.MyStrokes.Count; i++) { _inkFrame._inkCanvas.Strokes.Add(_inkCollector.Sketch.MyStrokes[i].Stroke); } this.timeBar.setProgress(0); _inkCollector.IsPlaying = false; _inkCollector.Mode = InkMode.Ink; MyTimer.getInstance().Resume(); this.timeBar.StrokePlayButton = StrokePlayButton.StartPlay; this._controlPanel.Visibility = Visibility.Visible; return; } } }
public override void _presenter_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e) { if (_startpoint != null) { if (_inkCanvas.Strokes.Count - 1 > _inkCollector._sketch.MyStrokes.Count) { _inkCollector._sketch.MyStrokes.Clear(); foreach (Stroke stroke in _inkCanvas.Strokes) { _mystroke = new MyStroke(stroke); _mystroke.StartTime = _starttime; _mystroke.EndTime = MyTimer.getInstance().getTime(); Command addStrokeCommand = new AddStrokeCommand(_inkCollector, _mystroke); _inkCollector.CommandStack.Push(addStrokeCommand); addStrokeCommand.execute(); } } else { //Point current = e.GetPosition(_inkCanvas); //Console.WriteLine("up:"+current.X + "," + current.Y); if (_inkCanvas.Strokes.Count > 0) { Stroke lastStroke = _inkCanvas.Strokes.Last(); _mystroke = new MyStroke(lastStroke); _mystroke.StartTime = _starttime; _mystroke.EndTime = MyTimer.getInstance().getTime(); Command addStrokeCommand = new AddStrokeCommand(_inkCollector, _mystroke); _inkCollector.CommandStack.Push(addStrokeCommand); addStrokeCommand.execute(); } } } }
/// <summary> /// 将stroke以点迹的模式擦除,拆分成两个stroke /// </summary> /// <param name="stroke">被擦除的stroke</param> /// <param name="pointErasePoints">擦除的点</param> void ProcessPointErase(Stroke stroke, Point pointErasePoint) { if (stroke.StylusPoints.Count > 1) { Stroke hitTestStroke; StylusPointCollection splitStrokePoints1 = new StylusPointCollection(); StylusPointCollection splitStrokePoints2 = new StylusPointCollection(); StylusPointCollection spc = new StylusPointCollection(); foreach (StylusPoint point in stroke.StylusPoints) { spc.Add(point); } hitTestStroke = new Stroke(spc); hitTestStroke.DrawingAttributes = stroke.DrawingAttributes; while (true) { if (hitTestStroke.StylusPoints.Count > 0) { if (hitTestStroke.StylusPoints.Count > 1) { StylusPoint sp = hitTestStroke.StylusPoints[hitTestStroke.StylusPoints.Count - 1]; hitTestStroke.StylusPoints.RemoveAt(hitTestStroke.StylusPoints.Count - 1); if (!hitTestStroke.HitTest(pointErasePoint, 3)) { break; } splitStrokePoints2.Add(sp); } else { break; } } } StylusPointCollection spc2 = new StylusPointCollection(); foreach (StylusPoint point in stroke.StylusPoints) { spc2.Add(point); } hitTestStroke = new Stroke(spc2); hitTestStroke.DrawingAttributes = stroke.DrawingAttributes; //从下标为0的位置开始遍历点迹,直到第一个被擦除的点 while (true) { if (hitTestStroke.StylusPoints.Count > 0) { if (hitTestStroke.StylusPoints.Count > 1) { StylusPoint sp = hitTestStroke.StylusPoints[0]; hitTestStroke.StylusPoints.RemoveAt(0); if (!hitTestStroke.HitTest(pointErasePoint, 3)) { break; } splitStrokePoints1.Add(sp); } else { break; } } } // 将原来的stroke删除掉,然后添加两个新的stroke if (splitStrokePoints1.Count > 1) { Stroke splitStroke1 = new Stroke(splitStrokePoints1); splitStroke1.DrawingAttributes = InkTool.getInstance().DrawingAttributesCopy(stroke.DrawingAttributes); MyStroke mystroke = new MyStroke(splitStroke1); AddStrokeCommand cmd = new AddStrokeCommand(_inkCollector, mystroke); _inkCollector.CommandStack.Push(cmd); cmd.execute(); } if (splitStrokePoints2.Count > 1) { Stroke splitStroke2 = new Stroke(splitStrokePoints2); splitStroke2.DrawingAttributes = InkTool.getInstance().DrawingAttributesCopy(stroke.DrawingAttributes); MyStroke mystroke = new MyStroke(splitStroke2); AddStrokeCommand cmd = new AddStrokeCommand(_inkCollector, mystroke); _inkCollector.CommandStack.Push(cmd); cmd.execute(); } } DeleteStrokeCommand dsc = new DeleteStrokeCommand(_inkCollector, stroke); _inkCollector.CommandStack.Push(dsc); dsc.execute(); }
public RotateCommand(MyStroke myStroke, double angle, StylusPoint center) { this._myStroke = myStroke; this.angle = angle / 180; this.center = center; }
/// <summary> /// 构造函数 /// 初始化要处理的strokecollection和移动的向量 /// </summary> /// <param name="strokeCollection"></param> /// <param name="offset_x"></param> /// <param name="offset_y"></param> public MoveCommand(MyStroke myStroke, double offset_x, double offset_y) { this._myStroke = myStroke; this.offset_x = offset_x; this.offset_y = offset_y; }
public AddStrokeCommand(InkCollector inkCollector, MyStroke stroke) { _inkCollector = inkCollector; _myStroke = stroke; }