Example #1
0
        void GetTriangle(StylusPointCollection pts, Action <StylusPointCollection> exec)
        {
            pts.Add(new StylusPoint(topLeft.X, topLeft.Y));
            pts.Add(new StylusPoint(bottomRight.X, bottomRight.Y));

            exec(pts);
        }
Example #2
0
        void _recognier_OnLineEnded(object sender, EventArgs e)
        {
            // 가상 선 등록
            //Line straightLine = new Line();
            //straightLine = new Line();
            //straightLine.StrokeThickness = this.DrawingCanvas.DefaultDrawingAttributes.Width;
            //straightLine.Stroke = this.DrawingCanvas.DefaultDrawingAttributes.Color;
            //straightLine.X1 = _floatingLine.X1;
            //straightLine.Y1 = _floatingLine.Y1;
            //straightLine.X2 = _floatingLine.X2;
            //straightLine.Y2 = _floatingLine.Y2;

            StylusPointCollection stcol = new StylusPointCollection();

            stcol.Add(new StylusPoint(_floatingLine.X1, _floatingLine.Y1));
            stcol.Add(new StylusPoint(_floatingLine.X2, _floatingLine.Y2));
            StrokeCollection col = new StrokeCollection();
            Stroke           st  = new Stroke(stcol);

            col.Add(st);

            this.DrawingCanvas.Strokes.Add(col);

            //gridMain.Children.Add(straightLine);
            //gridMain.RegisterName("ui_straightLine" + DateTime.Now.ToFileTime().ToString(), straightLine);

            _floatingLine.Visibility = System.Windows.Visibility.Collapsed;
        }
Example #3
0
        /// <summary>
        /// Cursor has been moved
        /// </summary>
        /// <param name="cursor">Position</param>
        /// <param name="mode">State</param>
        private void cursorMove(Point point)
        {
            var p = relativeTransform(point);

            // Check buttons
            helpButton.Over((helpButton.Intersects(this, point)));
            clearButton.Over((clearButton.Intersects(this, point)));
            cancelButton.Over((cancelButton.Intersects(this, point)));
            continueButton.Over((continueButton.Intersects(this, point)));

            // Stop if input capture isn't ready
            if (stylusPoints == null)
            {
                return;
            }

            // Add current point
            stylusPoints.Add(toStylusPoint(p));

            //Erase if need be
            if (cursor.Mode == CursorModes.Erase)
            {
                erase();
            }
        }
Example #4
0
        // Resampling all the strokes with the same distance intervals

        /*
         * public static void Resampling(Stroke myStroke, double scaleFactor, Rect myBounds)
         * {
         *  double diagonalLength = GeometryRelation.Distance(myBounds.BottomLeft, myBounds.TopRight);
         *  double S = diagonalLength / scaleFactor;
         *  //MessageBox.Show("S = "+S);
         *  //
         *  double D = 0;
         *  StylusPointCollection resampledStylusPointsCollection = new StylusPointCollection();
         *
         *
         *  // Add the first point to resampled stylus points
         *  resampledStylusPointsCollection.Add(myStroke.StylusPoints[0]);
         *  for (int i = 1; i < myStroke.StylusPoints.Count; i++)
         *  {
         *      StylusPoint p1, p2;
         *      p1 = myStroke.StylusPoints[i - 1];
         *      p2 = myStroke.StylusPoints[i];
         *      double d = GeometryRelation.Distance(p1, p2);
         *      if ((D + d) >= S)
         *      {
         *          StylusPoint newPoint = new StylusPoint(p1.X + ((S - D) / d) * (p2.X - p1.X), p1.Y + ((S - D) / d) * (p2.Y - p1.Y));
         *          resampledStylusPointsCollection.Add(newPoint);
         *          myStroke.StylusPoints[i] = newPoint;
         *          D = 0;
         *      }
         *      else
         *      {
         *          D = D + d;
         *      }
         *  }
         *  myStroke.StylusPoints = resampledStylusPointsCollection;
         * }
         */
        public static void Resampling(Stroke myStroke, int n)
        {
            double S = Length(myStroke) / (n - 1);
            double D = 0;
            StylusPointCollection resampledStylusPointsCollection = new StylusPointCollection();


            // Add the first point to resampled stylus points
            resampledStylusPointsCollection.Add(myStroke.StylusPoints[0]);
            for (int i = 1; i < myStroke.StylusPoints.Count; i++)
            {
                StylusPoint p1, p2;
                p1 = myStroke.StylusPoints[i - 1];
                p2 = myStroke.StylusPoints[i];
                double d = Distance(p1, p2);
                if ((D + d) >= S)
                {
                    StylusPoint newPoint = new StylusPoint(p1.X + ((S - D) / d) * (p2.X - p1.X), p1.Y + ((S - D) / d) * (p2.Y - p1.Y));
                    resampledStylusPointsCollection.Add(newPoint);
                    myStroke.StylusPoints.Insert(i, newPoint);
                    //myStroke.StylusPoints[i] = newPoint;
                    D = 0;
                }
                else
                {
                    D = D + d;
                }
            }
            myStroke.StylusPoints = resampledStylusPointsCollection;
            if (myStroke.StylusPoints.Count == n - 1)
            {
                myStroke.StylusPoints.Add(new StylusPoint(myStroke.StylusPoints[myStroke.StylusPoints.Count - 1].X, myStroke.StylusPoints[myStroke.StylusPoints.Count - 1].Y));
            }
        }
Example #5
0
            public override StylusPointCollection AddPoint(StylusPoint stylusPoint)
            {
                if (this._stylusPointQueue == null)
                {
                    this._stylusPointQueue = new StylusPointQueue(18);
                    this._stylusPointQueue.Enqueue(stylusPoint);
                    return(null);
                }
                StylusPointCollection stylusPointCollection2;
                int num = this._stylusPointQueue.Count;

                if (num != 16)
                {
                    this._stylusPointQueue.Enqueue(stylusPoint);
                }
                stylusPointCollection2 = new StylusPointCollection(stylusPoint.Description);
                int num2 = 0;

                if (num < 8)
                {
                    stylusPointCollection2.Add(this._stylusPointQueue.Dequeue());
                    num2++;
                    num = num2;
                }
                stylusPointCollection2.Add(this._stylusPointQueue[0]);
                return(stylusPointCollection2);
            }
        private void CreateSaveGroupStroke(InkCanvas _ink, string img_file, string str_file)
        {
            StrokeCollection InkGroup = new StrokeCollection();

            for (int j = 0; j < pointHist.Count; j++)
            {
                StylusPointCollection T = new StylusPointCollection();
                T.Add(new StylusPoint(_ink.ActualWidth / 2, _ink.ActualHeight / 2));
                for (int i = j; i < pointHist.Count; i++)
                {
                    T.Add(new StylusPoint(T[i - j].X - pointHist[i].X, T[i - j].Y - pointHist[i].Y));
                }
                Stroke So = new Stroke(T);
                InkGroup.Add(So);
            }

            FileStream file = File.Create(str_file);

            InkGroup.Save(file);
            file.Flush();
            file.Close();

            _ink.Strokes.Clear();
            _ink.Strokes.Add(InkGroup);
            CreateSaveBitmap(_ink, img_file);
        }
Example #7
0
        private void BtnStroke_Click(object sender, RoutedEventArgs e)
        {
            StylusPointCollection stylusPointCollection = new StylusPointCollection();

//            StylusPoint stylusPoint = new StylusPoint(100, 200, .2f);

            stylusPointCollection.Add(new StylusPoint(100, 200, .2f));
            stylusPointCollection.Add(new StylusPoint(100, 250, .5f));
            stylusPointCollection.Add(new StylusPoint(100, 300, .9f));
            Stroke stroke = new Stroke(stylusPointCollection);

            stroke.DrawingAttributes = new DrawingAttributes {
                Width = 25, Height = 25, Color = Color.FromRgb(0, 0, 0)
            };
            this.inkCanvas.Strokes.Add(stroke);


            stylusPointCollection = new StylusPointCollection();
            //            StylusPoint stylusPoint = new StylusPoint(100, 200, .2f);

            stylusPointCollection.Add(new StylusPoint(200, 200, .2f));
            stylusPointCollection.Add(new StylusPoint(200, 250, .5f));
            stylusPointCollection.Add(new StylusPoint(200, 300, .9f));
            stroke = new Stroke(stylusPointCollection);
            stroke.DrawingAttributes = new DrawingAttributes {
                Width = 25, Height = 25, Color = Color.FromRgb(0, 0, 0)
            };
            this.inkCanvas.Strokes.Add(stroke);
        }
Example #8
0
        protected void DrawLeapLine(Controller leap, Leap.Frame frame)
        {
            FingerList allFingers = frame.Fingers.Extended();

            if (allFingers.Count != 2 || leap.Frame(10).Fingers.Extended().Count != 2)
            {
                return;
            }

            Finger finger1 = allFingers.Leftmost;
            Finger finger2 = allFingers.Rightmost;

            InteractionBox interactionBox = frame.InteractionBox;

            Leap.Vector normalizedPosition1 = interactionBox.NormalizePoint(finger1.StabilizedTipPosition);
            Leap.Vector normalizedPosition2 = interactionBox.NormalizePoint(finger2.StabilizedTipPosition);

            double tx1 = normalizedPosition1.x * windowWidth;
            double ty1 = windowHeight - normalizedPosition1.y * windowHeight;
            double tx2 = normalizedPosition2.x * windowWidth;
            double ty2 = windowHeight - normalizedPosition2.y * windowHeight;

            StylusPointCollection tips = new StylusPointCollection();

            tips.Add(new StylusPoint(tx1, ty1));
            tips.Add(new StylusPoint(tx2, ty2));
            Stroke stroke = new Stroke(tips, lineIndicator);

            this.InkCanvas_LeapPaint.Strokes.Add(stroke);
        }
        public static Stroke StrokeToCircle(Stroke originalStroke)
        {
            //Fix the center.
            StylusPoint start   = originalStroke.StylusPoints[0];
            double      radiusX = originalStroke.GetGeometry().Bounds.Width * 0.5;
            double      radiusY = originalStroke.GetGeometry().Bounds.Height * 0.5;
            double      ycenter = originalStroke.GetGeometry().Bounds.Top + radiusY;
            double      xcenter = originalStroke.GetGeometry().Bounds.Left + radiusX;

            StylusPointCollection s = new StylusPointCollection();
            double angle            = 0.0f;

            for (int i = 0; i < 360; i++)
            {
                angle = Math.PI * i / 180.0;
                s.Add(new StylusPoint(xcenter + (radiusX * Math.Cos(angle)), ycenter + (radiusY * Math.Sin(angle))));
            }

            //make sure to close the loop
            s.Add(new StylusPoint(s[0].X, s[0].Y));

            Stroke st = new Stroke(s);

            return(st);
        }
        /// <summary>
        /// 每条注释笔迹完成以后的操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void InkCanvasAnnotation_StrokeCollected(object sender, System.Windows.Controls.InkCanvasStrokeCollectedEventArgs e)
        {
            if (null != _keyFramesAnnotation)
            {
                if (_keyFramesAnnotation.Strokes.Count == 0)
                {
                    if (_inkCollector.DefaultSummarizationNum == 0)
                    {
                        //关键帧索引
                        int index = _inkCollector.VideoSummarization.ShowKeyFrames.IndexOf(_inkCollector.SelectKeyFrames[0]);
                        ((SpiralSummarization)_inkCollector.VideoSummarization).AddPoints2ShowSpiral(index, Colors.Red, 0);
                    }
                    else if (_inkCollector.DefaultSummarizationNum == 1)
                    {
                        int         index   = _inkCollector.VideoSummarization.KeyFrames.IndexOf(_inkCollector.SelectKeyFrames[0]);
                        StylusPoint slPoint = _inkCollector.VideoSummarization.KeyPoints[index];

                        StylusPointCollection spc        = new StylusPointCollection();
                        StylusPoint           currPoint1 = new StylusPoint(slPoint.X - _inkCollector.VideoSummarization.ShowWidth / 2, slPoint.Y + _inkCollector.VideoSummarization.ShowHeight / 2 + 2);
                        StylusPoint           currPoint2 = new StylusPoint(slPoint.X + _inkCollector.VideoSummarization.ShowWidth / 2, slPoint.Y + _inkCollector.VideoSummarization.ShowHeight / 2 + 2);
                        spc.Add(currPoint1);
                        spc.Add(currPoint2);
                        Stroke s = new Stroke(spc);
                        s.DrawingAttributes.Color  = Colors.Red;
                        s.DrawingAttributes.Width  = 3;
                        s.DrawingAttributes.Height = 3;
                        ((InkCanvas)(_inkCollector._mainPage._inkCanvas.Children[1])).Strokes.Add(s);
                    }
                }
                Stroke lastStroke = InkCanvasAnnotation.Strokes[InkCanvasAnnotation.Strokes.Count - 1].Clone();
                _keyFramesAnnotation.Strokes.Add(lastStroke);
            }
        }
        //描く処理(マウスムーブ)
        private void inkCanvas1_MouseMove(object sender, MouseEventArgs e)
        {
            UIElement el = sender as UIElement;

            Console.WriteLine("dragging = " + dragging + " in mousemove");

            //かくモード
            if (dragging && isFreeLine)
            {
                points.Add(e.GetPosition(el));
                Console.WriteLine(e.GetPosition(el));
                counter++;
            }

            //直線モード
            else if (!isFreeLine && dragging)
            {
                inkCanvas1.Strokes.Clear();
                drawAll();

                //点の情報を集め、始点と現在の点をむすぶ
                StylusPointCollection spc = new StylusPointCollection();
                spc.Add(new StylusPoint(startP.X, startP.Y));
                spc.Add(new StylusPoint(e.GetPosition(el).X, e.GetPosition(el).Y));
                Stroke stroke = new Stroke(spc, inkDA);
                inkCanvas1.Strokes.Add(stroke);

                counter++;
            }
        }
Example #12
0
        /// <summary>
        /// We create a stroke with points close and then add the stroke to the canvas.
        /// If the points are far apart, we create a new stroke for those points.
        /// </summary>
        /// <param name="inkCanvas"></param>
        /// <param name="strokeInfo"></param>
        public static void AddStrokePreview(this InkCanvas inkCanvas, StrokeInfo strokeInfo)
        {
            StylusPoint           firstPoint = strokeInfo.PointCollection[0];
            StylusPointCollection tmpPoints  = new StylusPointCollection();

            tmpPoints.Add(firstPoint);

            for (int i = 0; i < strokeInfo.PointCollection.Count - 1; i++)
            {
                if (CalculateDistance(strokeInfo.PointCollection[i], strokeInfo.PointCollection[i + 1]) < 5)
                {
                    tmpPoints.Add(strokeInfo.PointCollection[i + 1]);
                }
                else
                {
                    inkCanvas.Strokes.Add(CreateStroke(strokeInfo, tmpPoints.Clone()));
                    tmpPoints.Clear();
                    tmpPoints.Add(strokeInfo.PointCollection[i + 1]);
                }
            }

            if (tmpPoints.Count > 0)
            {
                inkCanvas.Strokes.Add(CreateStroke(strokeInfo, tmpPoints));
            }
        }
Example #13
0
        void GetRectangle(StylusPointCollection pts, Action<StylusPointCollection> exec)
        {
            pts.Add(new StylusPoint(topLeft.X, topLeft.Y));
            pts.Add(new StylusPoint(bottomRight.X, bottomRight.Y));

            exec(pts);
        }
        public void Update()
        {
            double Mass1X = X0 + L1 * Math.Sin(Phi1);
            double Mass1Y = Y0 + L1 * Math.Cos(Phi1);
            double Mass2X = Mass1X + L2 * Math.Sin(Phi2);
            double Mass2Y = Mass1Y + L2 * Math.Cos(Phi2);

            SetSize(mass1, 2 * M1);
            SetSize(mass2, 2 * M2);
            SetPosition(mass1, Mass1X - M1, Mass1Y - M1);
            SetPosition(mass2, Mass2X - M2, Mass2Y - M2);
            SetPosition(Arm1, X0, Y0, Mass1X, Mass1Y);
            SetPosition(Arm2, Mass1X, Mass1Y, Mass2X, Mass2Y);

            var sp = new StylusPoint(Mass2X, Mass2Y);

            if (col == null || col.Count >= 1000)
            {
                var ncol = new StylusPointCollection();
                if (col != null)
                {
                    ncol.Add(col.Last());
                }
                ncol.Add(sp);
                stroke = new Stroke(ncol);
                stroke.DrawingAttributes.Color = Colors.Blue;
                _ink.Strokes.Add(stroke);
                col = ncol;
            }
            else
            {
                col.Add(sp);
            }
        }
Example #15
0
        public override StylusPointCollection GetShapePointCollection(Point anchor, Point cursor)
        {
            var    pointCollection = new StylusPointCollection();
            int    angleNum        = 5;                                                                          //The number of angles in the shape.
            double radius          = Math.Min(Math.Abs(anchor.X - cursor.X), Math.Abs(anchor.Y - cursor.Y)) / 2; //Getting radii of inscribed and circumscribed circles.
            double angle           = 20;                                                                         //Pitch angle.
            double x   = (anchor.X + cursor.X) / 2;                                                              //Center coords
            double y   = (anchor.Y + cursor.Y) / 2;
            double div = x / y;

            //Counting of star's apexes coords.
            for (int i = 1; i < angleNum * 2 + 2; i++)
            {
                var point = new StylusPoint();

                point.X = x + radius / 2 * Math.Cos(angle * Math.PI / 180) * div;
                point.Y = y - radius / 2 * Math.Sin(angle * Math.PI / 180) / div;

                angle = angle + 360 / angleNum;
                //Adding current apex to collection.
                pointCollection.Add(point);
            }

            //Adding first point to the collection's tail.
            pointCollection.Add(pointCollection[0]);

            //Drawing strokes between points.
            var pentagone = new Stroke(pointCollection);

            return(pointCollection);
        }
Example #16
0
        public Rectangle(Point TopPnt, Point LowerPnt, Color color)
        {
            if (TopPnt.X < LowerPnt.X)
            {
                TopLeft    = TopPnt;
                TopRight   = new Point(LowerPnt.X, TopPnt.Y);
                LowerLeft  = new Point(TopPnt.X, LowerPnt.Y);
                LowerRight = LowerPnt;
            }
            else
            {
                TopRight   = TopPnt;
                TopLeft    = new Point(LowerPnt.X, TopPnt.Y);
                LowerRight = new Point(TopRight.X, LowerPnt.Y);
                LowerLeft  = LowerPnt;
            }
            StylusPointCollection pts = new StylusPointCollection();

            pts.Add(new StylusPoint(TopLeft.X, TopLeft.Y));

            pts.Add(new StylusPoint(TopRight.X, TopRight.Y));

            pts.Add(new StylusPoint(LowerRight.X, LowerRight.Y));

            pts.Add(new StylusPoint(LowerLeft.X, LowerLeft.Y));

            pts.Add(new StylusPoint(TopLeft.X, TopLeft.Y));

            Outline = new Stroke(pts);

            Outline.DrawingAttributes.Color = color;
        }
        private void StrokeArrowConvert(System.Windows.Ink.Stroke stroke)
        {
            //Console.WriteLine("Stroke Completed");
            double toRadians = Math.PI / 180.0;
            StylusPointCollection ptsRect = new StylusPointCollection();
            StylusPointCollection pts     = stroke.StylusPoints;

            StylusPoint pt1 = pts[pts.Count - 1];
            StylusPoint pt2 = pts[0];

            ptsRect.Add(pt1);
            ptsRect.Add(pt2);
            //compute arrow head
            double arrowAngle = 30.0 * toRadians;
            double deltaX     = pt2.X - pt1.X;
            double deltaY     = pt2.Y - pt1.Y;
            double theta      = Math.Atan2(deltaY, deltaX); //radians
            double x1         = Math.Cos(theta + arrowAngle);
            double x2         = Math.Cos(theta - arrowAngle);
            double y1         = Math.Sin(theta + arrowAngle);
            double y2         = Math.Sin(theta - arrowAngle);
            double mag        = 10.0; //arrorhead line length

            ptsRect.Add(new StylusPoint(pt2.X - mag * x1, pt2.Y - mag * y1));
            ptsRect.Add(new StylusPoint(pt2.X, pt2.Y));
            ptsRect.Add(new StylusPoint(pt2.X - mag * x2, pt2.Y - mag * y2));
            stroke.StylusPoints = ptsRect;
            stroke.DrawingAttributes.FitToCurve = false;
        }
        public static Stroke PositionsToCircle(Point startPoint, Point endPoint)
        {
            StylusPointCollection stp = new StylusPointCollection();

            stp.Add(new StylusPoint(startPoint.X, startPoint.Y));
            stp.Add(new StylusPoint(endPoint.X, endPoint.Y));
            return(InkTransformerHelper.StrokeToCircle(new Stroke(stp)));
        }
 // Collect the points as the user draws the stroke.
 protected override void OnStylusMove(RawStylusInput rawStylusInput)
 {
     // Check whether the stylus that started the stroke is the same, and
     // that the element hasn't lost focus since the stroke began.
     if (points != null && currentStylus == rawStylusInput.StylusDeviceId)
     {
         points.Add(rawStylusInput.GetStylusPoints());
     }
 }
Example #20
0
        public override StylusPointCollection GetShapePointCollection(Point anchor, Point cursor)
        {
            var pointCollection = new StylusPointCollection();

            pointCollection.Add(new StylusPoint(anchor.X, anchor.Y));
            pointCollection.Add(new StylusPoint(cursor.X, cursor.Y));

            return(pointCollection);
        }
Example #21
0
        public override Stroke getShapeStroke(Point anchor, Point cursor)
        {                                                        /*
                                                                  * var pointCollection = new StylusPointCollection();
                                                                  * int angleNum = 5;                                                                                    //The number of angles in the shape.
                                                                  * double radius = Math.Min(Math.Abs(anchor.X - cursor.X), Math.Abs(anchor.Y - cursor.Y)) / 2;          //Getting radii of inscribed and circumscribed circles.
                                                                  * double angle = 20;                                                                                   //Pitch angle.
                                                                  * double x = (anchor.X + cursor.X) / 2;                                                                //Center coords
                                                                  * double y = (anchor.Y + cursor.Y) / 2;
                                                                  * double div = x / y;
                                                                  *
                                                                  * //Counting of star's apexes coords.
                                                                  * for (int i = 1; i < angleNum * 2 + 2; i++)
                                                                  * {
                                                                  *     var point = new StylusPoint();
                                                                  *
                                                                  *     point.X = x + radius / 2 * Math.Cos(angle * Math.PI / 180) * div;
                                                                  *     point.Y = y - radius / 2 * Math.Sin(angle * Math.PI / 180) / div;
                                                                  *
                                                                  *     angle = angle + 360 / angleNum;
                                                                  *     //Adding current apex to collection.
                                                                  *     pointCollection.Add(point);
                                                                  * }
                                                                  *
                                                                  * //Adding first point to the collection's tail.
                                                                  * pointCollection.Add(pointCollection[0]);
                                                                  *
                                                                  * //Drawing strokes between points.
                                                                  * var pentagone = new Stroke(pointCollection);
                                                                  * return pentagone;
                                                                  */
            var    pointCollection = new StylusPointCollection();
            double x        = Math.Abs(anchor.X - cursor.X) / 2; //Center coords
            double y        = Math.Abs(anchor.Y - cursor.Y) / 2;
            double angle    = 20;
            int    angleNum = 5;

            double div = x / y;

            for (int i = 0; i < 5; i++)
            {
                var    point = new StylusPoint();
                double fi    = 72;//Math.Atan((div) * Math.Tan(angle));
                point.X = (anchor.X + cursor.X) / 2 + (x / Math.Cos(fi));
                point.Y = (anchor.X + cursor.X) / 2 + (y / Math.Sin(fi));
                //angle = angle + 360 / angleNum;
                pointCollection.Add(point);
            }

            //Adding first point to the collection's tail.
            pointCollection.Add(pointCollection[0]);

            //Drawing strokes between points.
            var pentagone = new Stroke(pointCollection);

            return(pentagone);
        }
Example #22
0
        protected override void OnStylusMove(StylusEventArgs e)
        {
            // Allocate memory for the StylusPointsCollection, if necessary
            stylusPoints ??= new StylusPointCollection();

            // Add the StylusPoints that have come in since the last call to OnStylusMove
            StylusPointCollection newStylusPoints = e.GetStylusPoints(this, stylusPoints.Description);

            stylusPoints.Add(newStylusPoints);
        }
Example #23
0
        protected override void OnStylusMove(StylusEventArgs e)
        {
            if (stylusPoints == null)
            {
                stylusPoints = new StylusPointCollection();
            }
            StylusPointCollection newStylusPoints = e.GetStylusPoints(this, stylusPoints.Description);

            stylusPoints.Add(newStylusPoints);
        }
Example #24
0
        public override Stroke draw(Point anchor, Point cursor)
        {
            var pointCollection = new StylusPointCollection();

            pointCollection.Add(new StylusPoint(anchor.X, anchor.Y));
            pointCollection.Add(new StylusPoint(cursor.X, cursor.Y));

            var line = new Stroke(pointCollection);

            return(line);
        }
Example #25
0
        protected override void OnStylusMove(StylusEventArgs e)
        {
            base.OnStylusMove(e);

            if (stylusPoints == null)
            {
                stylusPoints = new StylusPointCollection();
            }

            stylusPoints.Add(e.GetStylusPoints(this, stylusPoints.Description));
        }
Example #26
0
 public void AddPoint(StylusPoint point)
 {
     if (Drawing)
     {
         activePoints.Add(point);
     }
     else
     {
         throw new NotSupportedException("Not drawing a stroke. Failed to add a point.");
     }
 }
Example #27
0
        public static StylusPointCollection box(Rect rect)
        {
            StylusPointCollection r = new StylusPointCollection();

            r.Add(sp(rect.TopLeft));
            r.Add(sp(rect.TopRight));
            r.Add(sp(rect.BottomRight));
            r.Add(sp(rect.BottomLeft));
            r.Add(sp(rect.TopLeft));
            return(r);
        }
Example #28
0
        public void Add_StylusPointCollection_Empty()
        {
            StylusPointCollection spc   = new StylusPointCollection();
            StylusPointCollection child = new StylusPointCollection();

            spc.Add(child);
            // twice
            spc.Add(child);
            // self
            spc.Add(spc);
            Assert.AreEqual(0, spc.Count, "Count-3");
        }
Example #29
0
    //</Snippet9>

    // Collect the stylus packets as the stylus moves.
    protected override void OnStylusMove(StylusEventArgs e)
    {
        if (stylusPoints == null)
        {
            return;
        }

        StylusPointCollection collectedPoints = e.GetStylusPoints(this, stylusPoints.Description);

        stylusPoints.Add(collectedPoints);
        AddPointsToHitTester(collectedPoints);
    }
Example #30
0
        static StylusPointCollection Points(StylusPointCollection StylusPointCollection)
        {
            var start = StylusPointCollection.First().ToPoint();
            var end   = StylusPointCollection.Last().ToPoint();

            RectangleDynamicRenderer.Prepare(ref start, ref end, out var w, out var h);

            var center = new Point(start.X + w / 2, start.Y + h / 2);

            var stylusPoints = new StylusPointCollection();

            const double step = 0.05;

            var arc1 = new List <StylusPoint>();
            var arc2 = new List <StylusPoint>();
            var arc3 = new List <StylusPoint>();
            var arc4 = new List <StylusPoint>();

            for (var dx = 0.0; dx < w / 2; dx += step)
            {
                var dy = (h / 2) * Math.Sqrt(1 - Math.Pow(2 * dx / w, 2));

                arc1.Add(new StylusPoint(center.X + dx, center.Y + dy));
                arc2.Add(new StylusPoint(center.X - dx, center.Y + dy));
                arc3.Add(new StylusPoint(center.X - dx, center.Y - dy));
                arc4.Add(new StylusPoint(center.X + dx, center.Y - dy));
            }

            foreach (var point in arc1.AsEnumerable().Reverse())
            {
                stylusPoints.Add(point);
            }

            foreach (var point in arc2)
            {
                stylusPoints.Add(point);
            }

            foreach (var point in arc3.AsEnumerable().Reverse())
            {
                stylusPoints.Add(point);
            }

            foreach (var point in arc4)
            {
                stylusPoints.Add(point);
            }

            stylusPoints.Add(arc1[arc1.Count - 1]);

            return(stylusPoints);
        }
Example #31
0
        //creates stroke and draws it on the canvas.
        public void generateStroke(PointCollection pointHist)
        {
            S = new StylusPointCollection();
            S.Add(new StylusPoint(_ink.ActualWidth / 2, _ink.ActualHeight / 2));
            for (int i = 0; i < pointHist.Count; i++)
            {
                S.Add(new StylusPoint(S[i].X - pointHist[i].X, S[i].Y - pointHist[i].Y));
            }
            Stroke So = new Stroke(S);

            _ink.Strokes.Clear();
            _ink.Strokes.Add(So);
        }
Example #32
0
        public static WindowsInk.Stroke ToWindowsStroke(NineInk.Stroke nineStroke)
        {
            var points = new StylusPointCollection();

            foreach (var point in nineStroke.Points)
                points.Add(new StylusPoint(point.X, point.Y, point.Pressure));

            var drwAttr = new WindowsInk.DrawingAttributes();
            var c = new Color();
            c.R = nineStroke.DrawingAttributes.Color.R;
            c.G = nineStroke.DrawingAttributes.Color.G;
            c.B = nineStroke.DrawingAttributes.Color.B;
            c.A = nineStroke.DrawingAttributes.Color.A;
            drwAttr.Color = c;

            switch (nineStroke.DrawingAttributes.Brush.Name)
            {
                case "Rectangle":
                    drwAttr.StylusTip = WindowsInk.StylusTip.Rectangle;
                    break;
                case "Ellipse":
                default:
                    drwAttr.StylusTip = WindowsInk.StylusTip.Ellipse;
                    break;
            }
            drwAttr.Height = nineStroke.DrawingAttributes.Height;
            drwAttr.Width = nineStroke.DrawingAttributes.Width;
            drwAttr.IsHighlighter = nineStroke.DrawingAttributes.IsHighlighter;

            return new WindowsInk.Stroke(points, drwAttr);
        }
        //A new stroke object named MyStroke is created. MyStroke is added to the StrokeCollection of the InkPresenter named MyIP
        private void MyIP_MouseLeftButtonDown(object sender, MouseEventArgs e)
        {
            MyIP.CaptureMouse();
            if (eraseflag == true)
            {

                StylusPointCollection MyStylusPointCollection = new StylusPointCollection();
                MyStylusPointCollection.Add(e.StylusDevice.GetStylusPoints(MyIP));
                NewStroke = new Stroke(MyStylusPointCollection);
                NewStroke.DrawingAttributes.Color = Colors.Red;
                MyIP.Strokes.Add(NewStroke); StylusPointCollection ErasePointCollection = new StylusPointCollection();


            }
            else
            {
                StylusPointCollection pointErasePoints = e.StylusDevice.GetStylusPoints(MyIP);
                StrokeCollection hitStrokes = MyIP.Strokes.HitTest(pointErasePoints);
                if (hitStrokes.Count > 0)
                {
                    foreach (Stroke hitStroke in hitStrokes)
                    {
                        MyIP.Strokes.Remove(hitStroke);
                        //undoStack.Push(hitStroke);
                        //undoStateBufferStack.Push(true);
                    }
                }
            }
        }
Example #34
0
 public Stroke Representation()
 {
     StylusPointCollection collection = new StylusPointCollection();
     foreach (var data in stylusPoints)
         collection.Add(data.Representation());
     return new Stroke(collection);
 }
Example #35
0
		public void Stroke_StylusPointCollection ()
		{
			StylusPointCollection spc = new StylusPointCollection ();
			spc.Add (new StylusPoint (1, 2));

			Stroke s = new Stroke (spc);
			Assert.AreEqual (1, s.StylusPoints.Count, "StylusPoints-1");

			spc.Add (new StylusPoint (3, 4));
			Assert.AreEqual (2, s.StylusPoints.Count, "StylusPoints-2");

			s.StylusPoints.Add (new StylusPoint (5, 6));
			Assert.AreEqual (3, s.StylusPoints.Count, "StylusPoints-3a");
			Assert.AreEqual (3, spc.Count, "StylusPoints-3b");

			Assert.Throws<ArgumentException> (delegate {
				s.HitTest (null);
			}, "HitTest-null");
			Assert.IsTrue (s.HitTest (s.StylusPoints), "HitTest-StylusPoints");
		}
Example #36
0
        private static void checkIfStrokeSelected(MouseButtonEventArgs e, InkPresenter inkCanvas, StylusPointCollection spc)
        {
            spc.Add(new StylusPoint(e.GetPosition(inkCanvas).X, e.GetPosition(inkCanvas).Y));

            if (inkCanvas.Strokes.HitTest(spc).Count > 0)
            {
                removeSelectedStroke(inkCanvas, spc);
            }

            return;
        }
 private void myInkPresenter_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     //捕获鼠标焦点
     myInkPresenter.CaptureMouse();
     myPointCollection = new StylusPointCollection();
     myPointCollection.Add(e.StylusDevice.GetStylusPoints(myInkPresenter));
     currentStroke = new Stroke(myPointCollection);
     //设置画笔属性
     currentStroke.DrawingAttributes.Color = currentColor;
     currentStroke.DrawingAttributes.Height = sliderThickness.Value;
     currentStroke.DrawingAttributes.Width = sliderThickness.Value;
     myInkPresenter.Strokes.Add(currentStroke);
 }
 public void Deserialize(XmlNode xmlNode, FlowDocument flowDocument)
 {
     var inkCanvas = new InkCanvasEx();
     foreach (XmlNode strokeNode in xmlNode.ChildNodes)
     {
         var points = new StylusPointCollection();
         foreach (XmlNode pointNode in strokeNode.ChildNodes)
         {
             points.Add(new StylusPoint(Double.Parse(pointNode.Attributes["X"].InnerText),
                 Double.Parse(pointNode.Attributes["Y"].InnerText)));
         }
         inkCanvas.Strokes.Add(new Stroke(points)); //TODO DrawingAttributes
     }
     flowDocument.Blocks.Add(new DrawerBlock { Child = new DrawerControl { Strokes = inkCanvas.Strokes }});
 }
Example #39
0
        public static void down(MouseButtonEventArgs e, InkPresenter inkCanvas, Grid LayoutRoot)
        {
            dragStarted = true;
            inkCanvas.CaptureMouse();

            clickedLayer = Common.hitTestLayer(e, inkCanvas);
            initialPos = e.GetPosition(inkCanvas);

            StylusPointCollection spc = new StylusPointCollection();
            spc.Add(new StylusPoint(e.GetPosition(inkCanvas).X, e.GetPosition(inkCanvas).Y));

            hitCount = inkCanvas.Strokes.HitTest(spc).Count;

            System.Diagnostics.Debug.WriteLine("layer " + clickedLayer);

            if (clickedLayer != -1)
            {

                //Calculate offset of left, right, top, bottom
                calculateOffset(e, inkCanvas);

                //System.Diagnostics.Debug.WriteLine("maxLeft " + MainPage.layerList[clickedLayer].imageToBorderDist[LEFT]);
                //System.Diagnostics.Debug.WriteLine("offSetLeft " + offSetLeft);
                //System.Diagnostics.Debug.WriteLine("positionY" + e.GetPosition(inkCanvas).Y);
                //System.Diagnostics.Debug.WriteLine("maxTop " + MainPage.layerList[clickedLayer].imageToBorderDist[TOP]);
                //System.Diagnostics.Debug.WriteLine("offSetTop " + offSetTop);

                //if the clickedLayer's image is out of bound
                if (clickedLayer != -1 && MainPage.layerList[clickedLayer].imgBackup != null)
                {
                    replaceMovingImgWithBackupImg(LayoutRoot);

                }
                else
                {
                    //temporarly save image in image backup
                    imageBackup = new WriteableBitmap((BitmapSource)MainPage.layerList[clickedLayer].img.Source);
                }

            }

            //Line clicked
            if (hitCount > 0)
            {
                moveInkToNewInkPresenter(inkCanvas, LayoutRoot, spc);
            }
        }
Example #40
0
        public TouchPoint2(TouchInfo info, UIElement source)
        {
            this.Source = source;

            #if SILVERLIGHT
            Stroke = new Stroke();
            #else
            var stylusPoints = new StylusPointCollection(1);
            stylusPoints.Add(new StylusPoint(info.Position.X, info.Position.Y));
            Stroke = new Stroke(stylusPoints);
            #endif

            TouchDeviceId = info.TouchDeviceId;
            StartTime = DateTime.Now;

            #if SILVERLIGHT
            UpdateTouchStroke(info);
            #endif
            UpdateTouchInfo(info);
        }
        private StrokeCollection GetStrokeCollectionFromPoints(dynamic strokePoints)
        {
            var strokeCollection = new StrokeCollection();

            foreach (var stroke in strokePoints.Strokes)
            {
                var points = new StylusPointCollection();

                foreach (var point in stroke.Points)
                {
                    var x = (float)point.X;
                    var y = (float)point.Y;

                    points.Add(new StylusPoint(x, y));
                }

                strokeCollection.Add(new Stroke(points));
            }

            return strokeCollection;
        }
Example #42
0
        public static StrokeCollection ConvertToStrokeCollection(SerializableStrokeCollection strokeCollection)
        {
            StrokeCollection resultCollection = new StrokeCollection();
            foreach (var stroke in strokeCollection)
            {
                DrawingAttributes drawingAttr = new DrawingAttributes
                {
                    Color = stroke.DrawingAttributes.Color,
                    FitToCurve = stroke.DrawingAttributes.FitToCurve,
                    Height = stroke.DrawingAttributes.Height,
                    Width = stroke.DrawingAttributes.Width,
                    IgnorePressure = stroke.DrawingAttributes.IgnorePressure,
                    IsHighlighter = stroke.DrawingAttributes.IsHighlighter,
                    StylusTipTransform = stroke.DrawingAttributes.StylusTipTransform
                };
                switch (stroke.DrawingAttributes.StylusTip)
                {
                    case SerializableDrawingAttributes.StylusTips.Ellipse:
                        drawingAttr.StylusTip = StylusTip.Ellipse;
                        break;
                    case SerializableDrawingAttributes.StylusTips.Rectangle:
                        drawingAttr.StylusTip = StylusTip.Rectangle;
                        break;
                    default:
                        break;
                }

                StylusPointCollection spc = new StylusPointCollection();
                foreach (var stylusPoint in stroke.StylusPoints)
                {
                    StylusPoint sp = new StylusPoint { X = stylusPoint.X, Y = stylusPoint.Y, PressureFactor = stylusPoint.PressureFactor };
                    spc.Add(sp);
                }
                Stroke newStroke = new Stroke(spc);
                newStroke.DrawingAttributes = drawingAttr;
                resultCollection.Add(newStroke);
            }
            return resultCollection;
        }
Example #43
0
        private void UIThreadDevice_StackingTouchEvent(object sender, StackingTouchEventArgs e)
        {
            if (e.Action == TouchAction.Down)
              {
            StylusPointCollection points = new StylusPointCollection();
            points.Add(new StylusPoint(e.Location.X, e.Location.Y));
            stackingSelectionStroke = new Stroke(points, inkCScribble.DefaultDrawingAttributes);
            inkCScribble.Strokes.Add(stackingSelectionStroke);
              }
              else if (e.Action == TouchAction.Move)
              {
            stackingSelectionStroke.StylusPoints.Add(new StylusPoint(e.Location.X, e.Location.Y));
            foreach (ScribbleCollection collection in ActualDocument[ActualPage].ScribblingCollections)
            {
              foreach (Stroke stroke in collection.Scribbles)
              {
            if (!stroke.HitTest(e.Location))
              continue;
            Synch.SendContent(ActualDocument.ID, ActualPage, stroke);
              }
            }

            var line = cHighlights.InputHitTest(e.Location);
            if (line == null || !(line is Line))
              return;
            Highlight highlight = (Highlight)ActualDocument[ActualPage].Highlights.SingleOrDefault(tmp => (tmp as Highlight).Line == line);
            if (highlight == null)
              return;
            Synch.SendContent(ActualDocument.ID, ActualPage, highlight);
              }
              else if (e.Action == TouchAction.Up)
              {
            if (inkCScribble.Strokes.Contains(stackingSelectionStroke))
              inkCScribble.Strokes.Remove(stackingSelectionStroke);
              }
        }
Example #44
0
        private void loadInk()
        {
            String inkFile = sceneName + ".ink";
            if(File.Exists(sceneDir + "\\" + inkFile))
            {
                StreamReader reader = new StreamReader(sceneDir + "\\" + inkFile);

                double x = -1;
                double y = -1;
                StylusPointCollection points = new StylusPointCollection();

                String s = reader.ReadLine();

                while (s != null)
                {
                    if (s != "")
                    {
                        x = Convert.ToDouble(s);
                    }

                    s = reader.ReadLine();

                    if (s != null && s != "")
                    {
                        y = Convert.ToDouble(s);
                    }

                    if (x != -1 && y != -1)
                    {
                        points.Add(new StylusPoint(x, y));
                    }

                    s = reader.ReadLine();

                    if (s == "---")
                    {
                        scene.Strokes.Add(new Stroke(points));
                        points = new StylusPointCollection();

                        s = reader.ReadLine();
                    }
                }

                reader.Close();

            }
        }
Example #45
0
		public void Add_StylusPointCollection_MultipleTimes ()
		{
			StylusPointCollection spc = new StylusPointCollection ();
			StylusPointCollection child = new StylusPointCollection ();
			child.Add (new StylusPoint (1, 2));
			spc.Add (child);
			Assert.AreEqual (1, spc.Count, "Count-1");
			// twice
			Assert.Throws<InvalidOperationException> (delegate {
				spc.Add (child);
			}, "child already added");
			Assert.AreEqual (1, spc.Count, "Count-2");
			Assert.Throws<InvalidOperationException> (delegate {
				spc.Add (spc);
			}, "child already added/2");
			Assert.AreEqual (1, spc.Count, "Count-3");
		}
Example #46
0
        /// <summary>
        ///     We just received (outsite event) and we want to draw and then delete the stroke.
        /// </summary>
        /// <param name="fullStroke">The full stroke.</param>
        public void DrawStroke(Stroke fullStroke)
        {
            var nbPts = HowManyPointPerTick(fullStroke.StylusPoints.Count);

            // Preparation of the pointer stroke
            var points = new StylusPointCollection();
            points.Add(fullStroke.StylusPoints[0]);
            fullStroke.StylusPoints.RemoveAt(0);
            var stroke = new Stroke(points);

            var uid = Guid.NewGuid().GetHashCode();
            toBeDrawed.Add(uid, new List<StylusPoint>());

            foreach (var pt in fullStroke.StylusPoints)
                toBeDrawed[uid].Add(pt);

            // Replicates the drawing attributes of that stroke
            stroke.DrawingAttributes = fullStroke.DrawingAttributes;

            // Adding our new Stroke to the ViewModel
            Application.Current.Dispatcher.BeginInvoke(
                new Action(
                    () => { LS.PointerStrokes.Add(stroke); }
                    ),
                DispatcherPriority.Render
                );

            // Creation of the Timer who will add the points
            var insertionTimer = new Timer(_quantum);
            var deletionTimer = new Timer(_quantum);


            // Preparation of the deletion timer, InsertionTimer will start it at the end
            deletionTimer.Elapsed += (src, args) => TimedDeletion(
                src,
                new Tuple<StrokeCollection, Stroke, int>(
                    LS.PointerStrokes,
                    stroke,
                    nbPts));

            insertionTimer.Elapsed += (src, args) => TimedInsertion(
                src, new Tuple<Timer, int, StylusPointCollection, int>(
                    deletionTimer,
                    uid,
                    points,
                    nbPts));
            insertionTimer.Start();
        }
        protected override void StylusInputBegin(StylusPointCollection stylusPoints, bool userInitiated)
        {
            _userInitiated = false;

            //we only initialize to true if the first stylusPoints were user initiated
            if (userInitiated)
            {
                _userInitiated = true;
            }

            _stylusPoints = new StylusPointCollection(stylusPoints.Description, 100);
            _stylusPoints.Add(stylusPoints);

            _strokeDrawingAttributes = this.InkCanvas.DefaultDrawingAttributes.Clone();

            // Reset the dynamic renderer if it's been flagged.
            if ( _resetDynamicRenderer )
            {
                InputDevice inputDevice = EditingCoordinator.GetInputDeviceForReset();
                if ( InkCanvas.InternalDynamicRenderer != null && inputDevice != null )
                {
                    StylusDevice stylusDevice = inputDevice as StylusDevice;
                    // If the input device is MouseDevice, null will be passed in Reset Method.
                    InkCanvas.InternalDynamicRenderer.Reset(stylusDevice, stylusPoints);
                }

                _resetDynamicRenderer = false;
            }

            // Call InvalidateBehaviorCursor at the end of the routine. The method will cause an external event fired.
            // So it should be invoked after we set up our states.
            EditingCoordinator.InvalidateBehaviorCursor(this);
        }
Example #48
0
        public Correlation(TouchPoint2 points)
        {
            //Account for a degenerate amount of points
            if (points.Stroke.StylusPoints.Count <= 1)
            {
                RSquared = 0;
                Slope = 0;
                Intercept = 0;
                VerticalLine = false;
                SlopeRad = 0;
                return;
            }

            var pointlist = points.Stroke.StylusPoints;

            //Remove duplicate points
            var workingList = new StylusPointCollection();
            for (int i = 1; i < pointlist.Count; i++ )
            {
                var point1 = pointlist[i - 1];
                var point2 = pointlist[i];
                if (!(point1.X == point2.X && point1.Y == point2.Y))
                {
                    workingList.Add(point1);
                }
            }
            VerticalLine = false;

            xavg = 0;
            yavg = 0;

            foreach (var p in workingList)
            {
                xavg += p.X;
                yavg += p.Y;
            }
            xavg = xavg / workingList.Count;
            yavg = yavg / workingList.Count;

            double numerator = 0;
            double denominator = 0;
            foreach (var p in workingList)
            {
                numerator += (p.X - xavg) * (p.Y - yavg);
                denominator += Math.Pow(p.X - xavg,2);
            }

            SlopeRad = Math.Atan2(numerator, denominator);
            if (denominator != 0)
            {
                Slope = numerator / denominator;
                Intercept = yavg - Slope * xavg;
            }
            else
            {
                VerticalLine = true;
            }
            TouchPoint2 tp = points.GetEmptyCopy();
            if(workingList.Count > 0)
                tp.Stroke.StylusPoints = workingList;
            RSquared = CalculateRSquared(tp);
        }
Example #49
0
        // Generates a collection of strokes representing an entire word.
        StrokeCollection GetStrokesForString(string text,
            Dictionary<char, StylusToken> fontData)
        {
            double currentX = 0.0;

            StrokeCollection stringStrokes = new StrokeCollection();

            for (int i = 0; i < text.Length; i++)
            {
                char c = text[i];

                if (fontData.Keys.Contains(c))
                {
                    StylusToken token = fontData[c];

                    double kerningLeft = 2.0;
                    if (i > 0 && Char.ToLower(text[i - 1]) == text[i - 1] &&
                        Char.ToLower(c) == c)
                        kerningLeft += token.width * 0.14;

                    double kerningRight = 2.0;
                    if (i < text.Length - 1 && Char.ToLower(text[i + 1]) == text[i + 1] &&
                        Char.ToLower(c) == c)
                        kerningRight += token.width * 0.14;

                    foreach (Stroke stroke in token.strokes)
                    {
                        StylusPointCollection newPoints = new StylusPointCollection();
                        foreach (StylusPoint point in stroke.StylusPoints)
                        {
                            newPoints.Add(new StylusPoint(
                                point.X + currentX + kerningLeft, point.Y));
                        }
                        stringStrokes.Add(new Stroke(newPoints));
                    }

                    currentX += token.width + kerningLeft + kerningRight;
                }
            }

            return stringStrokes;
        }
Example #50
0
        private void PlaybackSession(object sender, RoutedEventArgs e)
        {
            playback = true;

            Microsoft.Win32.OpenFileDialog dialogBox = new Microsoft.Win32.OpenFileDialog();

            dialogBox.DefaultExt = ".xml";

            Nullable<bool> result = dialogBox.ShowDialog();

            String filename;

            if (result == true)
            {
                filename = dialogBox.FileName;

                if (File.Exists(filename))
                {
                    XmlDocument xmlDoc = new XmlDocument();

                    //load xml file
                    xmlDoc.Load(filename);

                    XmlElement session = xmlDoc.DocumentElement;
                    XmlNodeList sceneNodes = session.GetElementsByTagName("Scene");

                    //begin playback
                    playback = true;

                    //load scenes listed in xml file
                    foreach (XmlNode currScene in sceneNodes)
                    {
                        XmlElement sceneNode = currScene as XmlElement;
                        String scenePath = currScene.Attributes.GetNamedItem("FilePath").Value;
                        StreamReader mysr = new StreamReader(scenePath);

                        LoadXAML(scenePath);

                        //InkCanvas sessionScene = LogicalTreeHelper.FindLogicalNode(rootObject, "scene") as InkCanvas;
                        
                        //perform events on scene
                        XmlNode eventNode = sceneNode.GetElementsByTagName("Events").Item(0);

                        XmlNodeList events;

                        if (eventNode.HasChildNodes)
                        {
                            events = eventNode.ChildNodes;
                        }
                        else
                        {
                            continue;
                        }

                        foreach (XmlNode mtEvent in events)
                        {
                            String mtAction = mtEvent.Name;

                            if (mtAction == "InkStroke")
                            {
                                //get points
                                XmlNodeList mtInkPoints = mtEvent.ChildNodes;
                                StylusPoint defaultPoint;
                                StylusPointCollection defaultPoints = new StylusPointCollection();
                                Stroke mtStroke;

                                XmlElement inkPoint = mtInkPoints[0] as XmlElement;

                                String xVal = inkPoint.Attributes.GetNamedItem("X").Value;
                                String yVal = inkPoint.Attributes.GetNamedItem("Y").Value;

                                Double X = Convert.ToDouble(xVal);
                                Double Y = Convert.ToDouble(yVal);

                                defaultPoint = new StylusPoint(X, Y);
                                defaultPoints.Add(defaultPoint);
                                mtStroke = new Stroke(defaultPoints);

                                scene.Strokes.Add(mtStroke);
                                
                                for (int i = 1; i < mtInkPoints.Count; i++)
                                {
                                    inkPoint = mtInkPoints[i] as XmlElement;

                                    xVal = inkPoint.Attributes.GetNamedItem("X").Value;
                                    yVal = inkPoint.Attributes.GetNamedItem("Y").Value;

                                    X = Convert.ToDouble(xVal);
                                    Y = Convert.ToDouble(yVal);

                                    //draw ink stroke one section at a time
                                    mtStroke.StylusPoints.Add(new StylusPoint(X, Y));

                                    //scene.Strokes.Remove(mtStroke);
                                    //scene.Strokes.Add(mtStroke);

                                    Refresh(scene);
                                }
                            }
                            else
                            {
                                XmlAttributeCollection attributes = mtEvent.Attributes;
                                Double X, Y, CenterX, CenterY, Rotation;
                                String elementName = attributes.GetNamedItem("Element").Value;

                                // objects = LogicalTreeHelper.GetChildren(scene);
                                Object mtElement = LogicalTreeHelper.FindLogicalNode(mtViewbox, elementName);
                                String objectType = mtElement.GetType().ToString();
                                UIElement currControl = new UIElement();

                                switch (objectType)
                                {
                                    case "System.Windows.Controls.Image":
                                        currControl = mtElement as Image;
                                        break;
                                    case "System.Windows.Controls.StackPanel":
                                        currControl = mtElement as StackPanel;
                                        break;
                                    case "System.Windows.Controls.MediaElement":
                                        currControl = mtElement as MediaElement;
                                        break;
                                    case "System.Windows.Controls.TextBlock":
                                        currControl = mtElement as TextBlock;
                                        break;
                                    case "System.Windows.Shapes.Ellipse":
                                        currControl = mtElement as Ellipse;
                                        break;
                                    case "System.Windows.Shapes.Rectangle":
                                        currControl = mtElement as Rectangle;
                                        break;
                                }

                                Matrix matrix = ((MatrixTransform)currControl.RenderTransform).Matrix;

                                switch (mtAction)
                                {
                                    case "Rotate":
                                        Rotation = Convert.ToDouble(attributes.GetNamedItem("Rotation").Value);
                                        CenterX = Convert.ToDouble(attributes.GetNamedItem("CenterX").Value);
                                        CenterY = Convert.ToDouble(attributes.GetNamedItem("CenterY").Value);

                                        matrix.RotateAt(Rotation, CenterX, CenterY);
                                        break;
                                    case "Scale":
                                        CenterX = Convert.ToDouble(attributes.GetNamedItem("CenterX").Value);
                                        CenterY = Convert.ToDouble(attributes.GetNamedItem("CenterY").Value);
                                        X = Convert.ToDouble(attributes.GetNamedItem("X").Value);
                                        Y = Convert.ToDouble(attributes.GetNamedItem("Y").Value);

                                        matrix.ScaleAt(X, Y, CenterX, CenterY);
                                        break;
                                    case "Translate":
                                        X = Convert.ToDouble(attributes.GetNamedItem("X").Value);
                                        Y = Convert.ToDouble(attributes.GetNamedItem("Y").Value);

                                        matrix.Translate(X, Y);
                                        break;
                                }
                                currControl.RenderTransform = new MatrixTransform(matrix);
                                bringElementToFront(currControl);
                                //currControl

                                Refresh(currControl);
                            }

                            System.Threading.Thread.Sleep(50);

                        }

                    }

                    //apply each action to the scene
                }
            }
        }
 private void ImageArea_MouseLeftButtonDown(object sender, MouseEventArgs e)
 {
     ImageArea.CaptureMouse();
     var MyStylusPointCollection = new StylusPointCollection();
     MyStylusPointCollection.Add(e.StylusDevice.GetStylusPoints(ImageArea));
     _newStroke = new Stroke(MyStylusPointCollection);
     _newStroke.DrawingAttributes.Color = (LocalizedStrings.LocalizedResources.FeedbackDrawingColor as string).ConvertStringToColor(Colors.Red);
         
     ImageArea.Strokes.Add(_newStroke);
 }
Example #52
0
 void GetBrush(StylusPointCollection pts, Action<StylusPointCollection> exec)
 {
     pts.Add(new StylusPoint(point.X, point.Y));
     exec(pts);
 }
Example #53
0
 private void AddSingleStrokeBasedNote(IdeationUnit strokeBasedIdea)
 {
     try
     {
         StrokeData ideaData = (StrokeData)(strokeBasedIdea.Content);
         List<System.Windows.Point> strokePoints = ideaData.StrokePoints;
         StylusPointCollection stylusPoints = new StylusPointCollection();
         foreach (System.Windows.Point p in strokePoints)
         {
             StylusPoint stylusP = new StylusPoint(p.X, p.Y);
             stylusPoints.Add(stylusP);
         }
         Stroke newStroke = new Stroke(stylusPoints);
         if (!ideaData.IsErasingStroke)
         {
             newStroke.DrawingAttributes = DrawingCanvasModeSwitcher.normalDrawingAttribute.Clone();
             newStroke.DrawingAttributes.Color = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(ideaData.StrokeColorCode);
         }
         else
         {
             newStroke.DrawingAttributes = new DrawingAttributes();
             newStroke.DrawingAttributes.Color = System.Windows.Media.Color.FromRgb(0, 0, 0);
             newStroke.DrawingAttributes.Width = newStroke.DrawingAttributes.Height = 30;
         }
         drawingCanvas.Strokes.Add(newStroke);
     }
     catch (Exception ex)
     {
         Utilities.UtilitiesLib.LogError(ex);
     }
 }
    private void addNextPDF()
    {

        PdfPage page = new PdfPage();
        page.Size = PageSize.A4;

        double h = SystemParameters.PrimaryScreenHeight;
        double w = SystemParameters.PrimaryScreenWidth;
        //XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
        var rateW = page.Width / w;
        var rateH = page.Height / h;

        var strokes = CanvasStroke.ToList();
        List<Point[]> pl = new List<Point[]>();
        foreach (Stroke stroke in strokes)
        {

            StylusPointCollection points = stroke.StylusPoints;
            StylusPointCollection newPoints = new StylusPointCollection();
            var pointList = points.ToList();
            foreach (StylusPoint pt in pointList)
            {

                StylusPoint newPt = new StylusPoint(pt.X * rateW, pt.Y * rateH);
                newPoints.Add(newPt);
            }
            Point[] p = (Point[])newPoints;
            pList.Add(p);
            pl.Add(p);
            CanvasStroke.Remove(stroke);
        }

        pointL.Add(pl);

    }
 public void Deserialize(XmlNode xmlNode, FlowDocument flowDocument)
 {
     var strokes = new StrokeCollection();
     foreach(XmlNode strokeNode in xmlNode.ChildNodes) {
         var points = new StylusPointCollection();
         foreach(XmlNode pointNode in strokeNode.ChildNodes) {
             points.Add(new StylusPoint(Double.Parse(pointNode.Attributes["X"].InnerText),
                 Double.Parse(pointNode.Attributes["Y"].InnerText)));
         }
         strokes.Add(new Stroke(points)); //TODO DrawingAttributes
     }
     flowDocument.Blocks.Add(new PlotBlock(strokes));
 }
Example #56
0
		public void Add_StylusPoint_Validation ()
		{
			StylusPointCollection spc = new StylusPointCollection ();
			StylusPoint sp = new StylusPoint ();
			spc.Add (sp);
			Assert.AreEqual (1, spc.Count, "Count");
		}
        // TODO : add opacity
        private void DrawFrame(Object sender, EventArgs e)
        {
            // Test if there are new strokes to draw, not started yet
            while (remainingStrokes && strokesEnum.Current.Beginning == currentDrawing.CurrentFrame)
            {
                IEnumerator<Dot> temp = strokesEnum.Current.Enum;
                temp.MoveNext();
                dotPointerList.Add(temp);
                remainingStrokes = strokesEnum.MoveNext();
            }

            List<IEnumerator<Dot>> toBeRemoved = new List<IEnumerator<Dot>>();

            // Draw the current dots, linked to the previous ones
            foreach (IEnumerator<Dot> Enumerator in dotPointerList)
            {
                Dot d = Enumerator.Current;
                if (Enumerator.MoveNext())
                {
                    Dot d2 = Enumerator.Current;
                    var strokePoints = new StylusPointCollection();
                    strokePoints.Add(new StylusPoint(d.X, d.Y));
                    strokePoints.Add(new StylusPoint(d2.X, d2.Y));
                    var drawingAttributes = new System.Windows.Ink.DrawingAttributes();
                    drawingAttributes.Color = d.GetColor();
                    drawingAttributes.Width = d.Radius;
                    drawingAttributes.Height = d.Radius;
                    Stroke stroke = new Stroke(strokePoints, drawingAttributes);
                    canvas.Strokes.Add(stroke);
                }
                else
                {
                    toBeRemoved.Add(Enumerator);
                }
            }

            // Remove the finished strokes
            dotPointerList.RemoveAll(x => toBeRemoved.Contains(x));
            currentDrawing.NewFrame();

            if (!remainingStrokes && dotPointerList.Count() == 0)
            {
                drawTimer.Stop();
            }
        }
Example #58
0
		public void Add_StylusPoint_Collection_Validation ()
		{
			StylusPointCollection spc = new StylusPointCollection ();
			// not an ArgumentNullException (or NRE)
			Assert.Throws<ArgumentException> (delegate {
				spc.Add ((StylusPointCollection) null);
			}, "null");
		}
Example #59
0
        /// <summary>
        /// StylusInputBegin
        /// </summary> 
        /// <param name="stylusPoints">stylusPoints</param>
        /// <param name="userInitiated">true if the source eventArgs.UserInitiated flag was set to true</param>
        protected override void StylusInputBegin(StylusPointCollection stylusPoints, bool userInitiated)
        {
            //
            // get a disposable dynamic hit-tester and add event handler
            //
            _incrementalStrokeHitTester =
                                this.InkCanvas.Strokes.GetIncrementalStrokeHitTester(this.InkCanvas.EraserShape);


            if ( InkCanvasEditingMode.EraseByPoint == _cachedEraseMode )
            {
                _incrementalStrokeHitTester.StrokeHit += new StrokeHitEventHandler(OnPointEraseResultChanged);
            }
            else
            {
                //we're in stroke hit test mode
                _incrementalStrokeHitTester.StrokeHit += new StrokeHitEventHandler(OnStrokeEraseResultChanged);
            }

            _stylusPoints = new StylusPointCollection(stylusPoints.Description, 100);
            _stylusPoints.Add(stylusPoints);

            //
            // start erasing
            //
            _incrementalStrokeHitTester.AddPoints(stylusPoints);

            // NTRAID:WINDOWSOS#1642274-2006/05/10-WAYNEZEN,
            // Since InkCanvas will ignore the animated tranforms when it receives the property changes.
            // So we should update our cursor when the stylus is down if there are animated transforms applied to InkCanvas.
            if ( InkCanvasEditingMode.EraseByPoint == _cachedEraseMode )
            {
                // Call InvalidateBehaviorCursor at the end of the routine. The method will cause an external event fired.
                // So it should be invoked after we set up our states.
                EditingCoordinator.InvalidateBehaviorCursor(this);
            }
        }
Example #60
0
		public void Add_StylusPointCollection_Empty ()
		{
			StylusPointCollection spc = new StylusPointCollection ();
			StylusPointCollection child = new StylusPointCollection ();
			spc.Add (child);
			// twice
			spc.Add (child);
			// self
			spc.Add (spc);
			Assert.AreEqual (0, spc.Count, "Count-3");
		}