public override Point Draw(Point first, MyInkData tool, DrawingContext dc, StylusPointCollection points) { int len = s.Length; FormattedText[] ftArray = new FormattedText[len]; for (int i = 0; i < len; i++) { ftArray[i] = new FormattedText(s[i].ToString(), System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, tool.inkRadius * 3, tool.inkBrush); } for (int i = 0; i < points.Count; i++) { Point pt = (Point)points[i]; Vector v = Point.Subtract(pt, first); if (v.Length >= tool.inkRadius * 3) { Point pt1 = new Point(pt.X - tool.inkRadius * 1.5, pt.Y - tool.inkRadius * 1.5); dc.DrawText(ftArray[TextIndex % len], pt1); TextIndex++; first = pt; } } return(first); }
public override Point Draw(Point first, MyInkData tool, DrawingContext dc, StylusPointCollection points) { for (int i = 0; i < points.Count; i++) { Point pt = (Point)points[i]; Vector v = Point.Subtract(pt, first); Size size; double distance = GetStylusInkDistance(tool, out size); if (v.Length >= distance) { if (tool.inkDrawOption == InkDrawOption.仅填充) { dc.DrawEllipse(tool.inkBrush, null, pt, size.Width, size.Height); } else if (tool.inkDrawOption == InkDrawOption.仅轮廓) { dc.DrawEllipse(null, tool.inkPen, pt, size.Width, size.Height); } else { dc.DrawEllipse(tool.inkBrush, tool.inkPen, pt, size.Width, size.Height); } first = pt; } } return(first); }
public InkObjectStroke(InkObject ink, StylusPointCollection stylusPoints) : base(stylusPoints) { this.ink = ink; inkTool = ink.CreateFromInkData(ink.inkTool); this.DrawingAttributes = ink.inkDA.Clone(); this.DrawingAttributes.Color = ink.myInkCanvas.fillColor; }
protected override void OnStylusDown(RawStylusInput rawStylusInput) { myInkCanvas.isFromFileInk = false; inkTool = CreateFromInkData(myInkCanvas.myData); inkDA = myInkCanvas.inkDA.Clone(); this.DrawingAttributes = inkDA; previousPoint = new Point(double.NegativeInfinity, double.NegativeInfinity); base.OnStylusDown(rawStylusInput); }
public InkObject(MyInkCanvas myInkCanvas, bool isInkColorAtEnd) { this.myInkCanvas = myInkCanvas; this.isInkColorAtEnd = isInkColorAtEnd; brush.Opacity = 0.09; inkTool = CreateFromInkData(myInkCanvas.myData); inkDA = myInkCanvas.inkDA.Clone(); this.DrawingAttributes = inkDA; }
public override Point Draw(Point first, MyInkData tool, DrawingContext dc, StylusPointCollection points) { Point pt = (Point)points.Last(); Vector v = Point.Subtract(pt, first); if (v.Length > 4) { dc.DrawLine(tool.inkPen, first, pt); } return(first); }
public override Point Draw(Point first, MyInkData tool, DrawingContext dc, StylusPointCollection points) { Point pt = (Point)points.Last(); Vector v = Point.Subtract(pt, first); if (v.Length > 4) { Rect rect = new Rect(first, v); dc.DrawImage(bi, rect); } return(first); }
public MyInkData Clone() { MyInkData data = new MyInkData() { inkRadius = this.inkRadius, inkColor = this.inkColor, inkBrushType = this.inkBrushType, inkStylusType = this.inkStylusType, inkDrawOption = this.inkDrawOption }; return data; }
/// <summary>当从文件中加载墨迹时,会自动调用此方法</summary> protected override void OnStrokesReplaced(InkCanvasStrokesReplacedEventArgs e) { isFromFileInk = true; StrokeCollection strokes = e.NewStrokes.Clone(); this.Strokes.Remove(e.NewStrokes); base.OnStrokesReplaced(e); foreach (var v in strokes) { this.Strokes.Remove(v); Guid id = v.GetPropertyDataIds()[0]; string[] s = ((string)v.GetPropertyData(id)).Split('#'); MyInkData data = new MyInkData(); for (int i = 0; i < s.Length; i++) { string[] property = s[i].Split(':'); switch (property[0]) { case "inkName": this.SetInkAttributes(property[1]); break; case "inkRadius": data.inkRadius = double.Parse(property[1]); break; case "inkColor": string[] c = property[1].Split(','); data.inkColor = Color.FromArgb(byte.Parse(c[0]), byte.Parse(c[1]), byte.Parse(c[2]), byte.Parse(c[3])); break; case "inkBrushType": data.inkBrushType = (InkBrushType)Enum.Parse(typeof(InkBrushType), property[1]); break; case "inkStylusType": data.inkStylusType = (InkStylusType)Enum.Parse(typeof(InkStylusType), property[1]); break; case "inkDrawOption": data.inkDrawOption = (InkDrawOption)Enum.Parse(typeof(InkDrawOption), property[1]); break; } } ink.inkTool = ink.CreateFromInkData(data); InkCanvasStrokeCollectedEventArgs args = new InkCanvasStrokeCollectedEventArgs(v); this.OnStrokeCollected(args); } }
/// <summary> /// 初始化墨迹类型和笔尖信息,其初值必须与RibbonTab中的默认选项相同 /// </summary> public MyInkCanvas() { fillColor = Colors.Transparent; this.myData = new MyInkData() { inkRadius = 12.0, inkColor = Colors.Red, inkBrushType = InkBrushType.线性渐变, inkStylusType = InkStylusType.圆笔, inkDrawOption = InkDrawOption.全部 }; UpdateInkParams(); SetInkAttributes(InkType.球形.ToString()); }
public MyInkData CreateFromInkData(MyInkData data) { MyInkData tool = data.Clone(); tool.inkBrush = null; if (isInkColorAtEnd) { GradientStopCollection c = new GradientStopCollection() { new GradientStop(Colors.White, 0.05), new GradientStop(Colors.Gold, 0.15), new GradientStop(data.inkColor, 1.0), }; switch (data.inkBrushType) { case InkBrushType.仿射渐变: tool.inkBrush = new RadialGradientBrush(c); break; case InkBrushType.线性渐变: tool.inkBrush = new LinearGradientBrush(c); break; case InkBrushType.纯色: tool.inkBrush = new SolidColorBrush(data.inkColor); break; } Brush b = tool.inkBrush; tool.inkPen = new Pen(b, tool.inkRadius * 0.5); } else { switch (data.inkBrushType) { case InkBrushType.仿射渐变: tool.inkBrush = new RadialGradientBrush(data.inkColor, Colors.Gold); break; case InkBrushType.线性渐变: tool.inkBrush = new LinearGradientBrush(data.inkColor, Colors.Gold, 45.0); break; case InkBrushType.纯色: tool.inkBrush = new SolidColorBrush(data.inkColor); break; } tool.inkPen = new Pen(tool.inkBrush, tool.inkRadius * 0.5); } return(tool); }
public override Point Draw(Point first, MyInkData tool, DrawingContext dc, StylusPointCollection points) { for (int i = 0; i < points.Count; i++) { Point pt = (Point)points[i]; Vector v = Point.Subtract(pt, first); Size size; double distance = GetStylusInkDistance(tool, out size); if (v.Length >= distance) { double x = pt.X - size.Width; double y = pt.Y - size.Height; Rect rect = new Rect(x, y, 2 * size.Width, 2 * size.Height); dc.DrawImage(bi, rect); first = pt; } } return(first); }
protected double GetStylusInkDistance(MyInkData data, out Size size) { double width = data.inkRadius;; double height = data.inkRadius; switch (data.inkStylusType) { case InkStylusType.圆笔: break; case InkStylusType.竖笔: height *= 2; break; case InkStylusType.横笔: width *= 2; break; case InkStylusType.钢笔: width *= 0.5; height *= 0.5; break; } size = new Size(width, height); double distance = Math.Max(size.Width, size.Height) * 1.5 + 10; return(distance); }
/// <summary>当收集墨迹时,会自动调用此方法</summary> protected override void OnStrokeCollected(InkCanvasStrokeCollectedEventArgs e) { this.Strokes.Remove(e.Stroke); ink.CreateNewStroke(e); MyInkData data = ink.InkStroke.inkTool; StringBuilder sb = new StringBuilder(); sb.AppendFormat("inkName:{0}#", ink.inkType); sb.AppendFormat("inkRadius:{0}#", data.inkRadius); Color c = data.inkColor; sb.AppendFormat("inkColor:{0},{1},{2},{3}#", c.A, c.R, c.G, c.B); sb.AppendFormat("inkBrushType:{0}#", data.inkBrushType); sb.AppendFormat("inkStylusType:{0}#", data.inkStylusType); sb.AppendFormat("inkDrawOption:{0}", data.inkDrawOption); ink.InkStroke.AddPropertyData(Guid.NewGuid(), sb.ToString()); this.Strokes.Add(ink.InkStroke); InkCanvasStrokeCollectedEventArgs args = new InkCanvasStrokeCollectedEventArgs(ink.InkStroke); base.OnStrokeCollected(args); }
public override Point Draw(Point first, MyInkData tool, DrawingContext dc, StylusPointCollection points) { Point pt = (Point)points.Last(); Vector v = Point.Subtract(pt, first); double radiusX = (pt.X - first.X) / 2.0; double radiusY = (pt.Y - first.Y) / 2.0; Point center = new Point((pt.X + first.X) / 2.0, (pt.Y + first.Y) / 2.0); if (tool.inkDrawOption == InkDrawOption.仅填充) { dc.DrawEllipse(tool.inkBrush, null, center, radiusX, radiusY); } else if (tool.inkDrawOption == InkDrawOption.仅轮廓) { dc.DrawEllipse(null, tool.inkPen, center, radiusX, radiusY); } else { dc.DrawEllipse(tool.inkBrush, tool.inkPen, center, radiusX, radiusY); } return(first); }
public override Point Draw(Point first, MyInkData tool, DrawingContext dc, StylusPointCollection points) { Point pt = (Point)points.Last(); Vector v = Point.Subtract(pt, first); if (v.Length > 4) { Rect rect = new Rect(first, v); if (tool.inkDrawOption == InkDrawOption.仅填充) { dc.DrawRectangle(tool.inkBrush, null, rect); } else if (tool.inkDrawOption == InkDrawOption.仅轮廓) { dc.DrawRectangle(null, tool.inkPen, rect); } else { dc.DrawRectangle(tool.inkBrush, tool.inkPen, rect); } } return(first); }
public override Point Draw(Point first, MyInkData tool, DrawingContext dc, StylusPointCollection points) { return(first); }
public abstract Point Draw(Point first, MyInkData tool, DrawingContext dc, StylusPointCollection points);