コード例 #1
0
ファイル: InkText.cs プロジェクト: henuliulei/gobangGa
        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);
        }
コード例 #2
0
 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);
 }
コード例 #3
0
ファイル: InkObject.cs プロジェクト: henuliulei/gobangGa
 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;
 }
コード例 #4
0
ファイル: InkObject.cs プロジェクト: henuliulei/gobangGa
 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);
 }
コード例 #5
0
ファイル: InkObject.cs プロジェクト: henuliulei/gobangGa
 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;
 }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
ファイル: MyInkData.cs プロジェクト: henuliulei/gobangGa
 public MyInkData Clone()
 {
     MyInkData data = new MyInkData()
     {
         inkRadius = this.inkRadius,
         inkColor = this.inkColor,
         inkBrushType = this.inkBrushType,
         inkStylusType = this.inkStylusType,
         inkDrawOption = this.inkDrawOption
     };
     return data;
 }
コード例 #9
0
ファイル: MyInkCanvas.cs プロジェクト: henuliulei/gobangGa
        /// <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);
            }
        }
コード例 #10
0
ファイル: MyInkCanvas.cs プロジェクト: henuliulei/gobangGa
 /// <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());
 }
コード例 #11
0
ファイル: InkObject.cs プロジェクト: henuliulei/gobangGa
        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);
        }
コード例 #12
0
ファイル: InkImageCurve.cs プロジェクト: henuliulei/gobangGa
 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);
 }
コード例 #13
0
ファイル: InkObject.cs プロジェクト: henuliulei/gobangGa
        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);
        }
コード例 #14
0
ファイル: MyInkCanvas.cs プロジェクト: henuliulei/gobangGa
        /// <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);
        }
コード例 #15
0
ファイル: InkEllipse.cs プロジェクト: henuliulei/gobangGa
        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);
        }
コード例 #16
0
ファイル: InkRectangle.cs プロジェクト: henuliulei/gobangGa
        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);
        }
コード例 #17
0
ファイル: InkCurve.cs プロジェクト: henuliulei/gobangGa
 public override Point Draw(Point first, MyInkData tool, DrawingContext dc, StylusPointCollection points)
 {
     return(first);
 }
コード例 #18
0
ファイル: InkObject.cs プロジェクト: henuliulei/gobangGa
 public abstract Point Draw(Point first, MyInkData tool, DrawingContext dc, StylusPointCollection points);