Пример #1
0
        protected override void ContextNodeCreated(object sender, ContextNodeCreatedEventArgs e)
        {
            Debug.WriteLine("Holy molly! {0}", e.NodeCreated);
            InkDrawingNode n = e.NodeCreated as InkDrawingNode;

            if (n != null)
            {
                Debug.WriteLine("Yeah!");
                foreach (Stroke x in n.Strokes)
                {
                    Debug.WriteLine("Uhhhhh {0}", x);
                    analyzer.RemoveStroke(x);
                    x.StylusPoints = InkUtils.xkcd(x.StylusPoints);
                }
            }
        }
Пример #2
0
        private static bool strokeIsHorizontalLine(Stroke stroke)
        {
            InkAnalyzer temp = new InkAnalyzer();

            temp.AddStroke(stroke);
            temp.Analyze();
            ContextNode node = temp.RootNode.SubNodes[0];

            if (node is InkDrawingNode)
            {
                InkDrawingNode  drawing     = node as InkDrawingNode;
                PointCollection boundingBox = drawing.GetRotatedBoundingBox();

                double d1 = distSquared(boundingBox[0], boundingBox[1]);
                double d2 = distSquared(boundingBox[1], boundingBox[2]);
                return((d2 > 0 && d1 / d2 > 10 * 10 && d1 > 100 && Math.Abs(slope(boundingBox[0], boundingBox[1])) < 0.5) ||
                       (d1 > 0 && d2 / d1 > 10 * 10 && d2 > 100 && Math.Abs(slope(boundingBox[1], boundingBox[2])) < 0.5));
            }
            return(false);
        }
Пример #3
0
        /// <summary>
        /// InkAnalysis results form a tree, this method is called recursively
        /// to render each node in the tree.
        /// </summary>
        private void DrawFeedback(DrawingContext drawingContext, ContextNode contextNode)
        {
            //see what type of ContextNode this is by casting it

            Rect        nodeBounds  = contextNode.Strokes.GetBounds();
            InkWordNode inkWordNode = contextNode as InkWordNode;

            if (inkWordNode != null)
            {
                drawingContext.DrawRoundedRectangle(null, new Pen(Brushes.Blue, 1.0d), nodeBounds, 1d, 1d);
                drawingContext.DrawText(new FormattedText(inkWordNode.GetRecognizedString(),
                                                          CultureInfo.CurrentCulture,
                                                          FlowDirection.LeftToRight,
                                                          new Typeface("Verdana"),
                                                          9.0d,
                                                          Brushes.Black),
                                        nodeBounds.BottomLeft);
                goto recurse;
            }

            InkDrawingNode inkDrawingNode = contextNode as InkDrawingNode;

            if (inkDrawingNode != null)
            {
                drawingContext.DrawRoundedRectangle(null, new Pen(Brushes.Purple, 1.0d), nodeBounds, 1d, 1d);
                drawingContext.DrawText(new FormattedText("Drawing: " + inkDrawingNode.GetShapeName(),
                                                          CultureInfo.CurrentCulture,
                                                          FlowDirection.LeftToRight,
                                                          new Typeface("Verdana"),
                                                          9.0d,
                                                          Brushes.Black),
                                        nodeBounds.BottomLeft);
                goto recurse;
            }

            InkBulletNode inkBulletNode = contextNode as InkBulletNode;

            if (inkBulletNode != null)
            {
                drawingContext.DrawRoundedRectangle(null, new Pen(Brushes.Green, 1.0d), nodeBounds, 1d, 1d);
                drawingContext.DrawText(new FormattedText(inkBulletNode.GetRecognizedString(),
                                                          CultureInfo.CurrentCulture,
                                                          FlowDirection.LeftToRight,
                                                          new Typeface("Verdana"),
                                                          9.0d,
                                                          Brushes.Black),
                                        nodeBounds.BottomLeft);
                goto recurse;
            }

            WritingRegionNode writingRegionNode = contextNode as WritingRegionNode;

            if (writingRegionNode != null)
            {
                nodeBounds.Inflate(3d, 3d);
                drawingContext.DrawRoundedRectangle(null, new Pen(Brushes.Black, 1.0d), nodeBounds, 1d, 1d);
                drawingContext.DrawText(new FormattedText("Writing Region",
                                                          CultureInfo.CurrentCulture,
                                                          FlowDirection.LeftToRight,
                                                          new Typeface("Verdana"),
                                                          9.0d,
                                                          Brushes.Black),
                                        nodeBounds.BottomLeft + new Vector(0, 3));
                goto recurse;
            }

            ParagraphNode paragraphNode = contextNode as ParagraphNode;

            if (paragraphNode != null)
            {
                nodeBounds.Inflate(2d, 2d); //inflate so this will be visible outside the line node
                drawingContext.DrawRoundedRectangle(null, new Pen(Brushes.Red, 1.0d), nodeBounds, 1d, 1d);
                goto recurse;
            }

            LineNode lineNode = contextNode as LineNode;

            if (lineNode != null)
            {
                nodeBounds.Inflate(1d, 1d); //inflate so this will be visible outside the word node
                drawingContext.DrawRoundedRectangle(null, new Pen(Brushes.Orange, 1.0d), nodeBounds, 1d, 1d);
                goto recurse;
            }

recurse:
            foreach (ContextNode subNode in contextNode.SubNodes)
            {
                DrawFeedback(drawingContext, subNode);
            }
        }