Пример #1
0
        /// <summary>
        /// Unhighlights the corresponding strokes to the input
        /// </summary>
        /// <param name="name"></param>
        private void truthTableWindow_UnHighlightLabel(string name)
        {
            // If it is not in the dictionary - return
            ListSet <string> strokeSet = new ListSet <string>();

            if (inputMapping.ContainsKey(name))
            {
                strokeSet = inputMapping[name];
            }
            else if (outputMapping.ContainsKey(name))
            {
                strokeSet = outputMapping[name];
            }
            else
            {
                return;
            }

            foreach (string s in strokeSet)
            {
                System.Windows.Ink.Stroke stroke = sketchPanel.InkSketch.GetInkStrokeById(s);
                Substroke sub = sketchPanel.InkSketch.GetSketchSubstrokeByInk(stroke);
                stroke.DrawingAttributes.Color = sub.Type.Color;
            }
        }
Пример #2
0
        /// <summary>
        /// Highlights the corresponding strokes to the input
        /// </summary>
        /// <param name="shape"></param>
        private void truthTableWindow_HighlightLabel(Shape shape)
        {
            // If it is not in the dictionary - return

            ListSet <string> strokeSet = new ListSet <string>();

            if (inputMapping.ContainsKey(shape))
            {
                strokeSet = inputMapping[shape];
            }
            else if (outputMapping.ContainsKey(shape))
            {
                strokeSet = outputMapping[shape];
            }
            else
            {
                return;
            }

            foreach (string s in strokeSet)
            {
                System.Windows.Ink.Stroke stroke = sketchPanel.InkSketch.GetInkStrokeById(s);
                stroke.DrawingAttributes.Color = Colors.DarkRed;
            }
        }
Пример #3
0
        public void ChangeStylusPoints()
        {
            if (strokes != null)
            {
                return;
            }

            wpf.Point[] points = new wpf.Point[] { new wpf.Point(0, 100), new wpf.Point(200, 200) };

            StylusPointCollection stylusPoints = new StylusPointCollection(points);

            wpf.Ink.Stroke stroke1 = new System.Windows.Ink.Stroke(stylusPoints);
            wpf.Ink.Stroke stroke2 = new System.Windows.Ink.Stroke(stylusPoints);

            strokes = new StrokeCollection();
            strokes.Add(stroke1);
            strokes.Add(stroke2);

            ReportStrokes();

            StylusPoint point = stroke2.StylusPoints[1];

            point.Y = 300;
            stroke2.StylusPoints[1] = point;

            ReportStrokes();
        }
Пример #4
0
        public static NineInk.Stroke ToNineStroke(WindowsInk.Stroke windowsStroke)
        {
            var points = new List <NineInk.StrokePoint>();

            foreach (var point in windowsStroke.StylusPoints)
            {
                points.Add(new NineInk.StrokePoint(point.X, point.Y, point.PressureFactor));
            }

            var drwAttr = new DrawingAttributes();

            drwAttr.Color.R = windowsStroke.DrawingAttributes.Color.R;
            drwAttr.Color.G = windowsStroke.DrawingAttributes.Color.G;
            drwAttr.Color.B = windowsStroke.DrawingAttributes.Color.B;
            drwAttr.Color.A = windowsStroke.DrawingAttributes.Color.A;

            switch (windowsStroke.DrawingAttributes.StylusTip.ToString())
            {
            case "Rectangle":
                drwAttr.Brush = Brushes.Rectangle;
                break;

            case "Ellipse":
            default:
                drwAttr.Brush = Brushes.Ellipse;
                break;
            }
            drwAttr.Height        = windowsStroke.DrawingAttributes.Height;
            drwAttr.Width         = windowsStroke.DrawingAttributes.Width;
            drwAttr.IsHighlighter = windowsStroke.DrawingAttributes.IsHighlighter;

            return(new NineInk.Stroke(points, drwAttr));
        }
Пример #5
0
        //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);
                    }
                }
            }
        }
        private StrokeCollection HitTest(System.Windows.Ink.Stroke e)
        {
            StrokeCollection hitList = new StrokeCollection();

            for (int i = 0; i < e.StylusPoints.Count - 1; i++)
            {
                var ps1 = GetVector2(e.StylusPoints[i]);
                var pe1 = GetVector2(e.StylusPoints[i + 1]);
                foreach (var stroke in InkCanvas.Strokes)
                {
                    if (hitList.Contains(stroke))
                    {
                        continue;
                    }
                    for (int j = 0; j < stroke.StylusPoints.Count - 1; j++)
                    {
                        var    ps2 = GetVector2(stroke.StylusPoints[j]);
                        var    pe2 = GetVector2(stroke.StylusPoints[j + 1]);
                        Vector result;
                        if (LineSegementsIntersect(ps1, pe1, ps2, pe2, out result))
                        {
                            hitList.Add(stroke);
                            break;
                        }
                    }
                }
            }
            return(hitList);
        }
        /// <summary>
        /// Highlights the endpoints of a single Wire by
        /// creating EndPointPainters for all endpoints.
        ///
        /// Main function for endpoint highlighting.
        /// </summary>
        /// <param name="wire">The Wire to highlight</param>
        /// <param name="g">The graphics handle to use while creating painters</param>
        private void highlightEndpoints(Shape wire)
        {
            List <int>      newEppIds = new List <int>();
            EndPointPainter epp;
            int             eppId;

            foreach (Sketch.EndPoint endpoint in wire.Endpoints)
            {
                epp    = createEndpointPainter(endpoint);
                eppId  = endPointPainterMap.Keys.Count + 1;
                epp.Id = eppId;
                newEppIds.Add(eppId);
                endPointPainterMap.Add(eppId, epp);
            }

            // Update stroke map to point to endpoint painters
            foreach (Sketch.Substroke substroke in wire.Substrokes)
            {
                String iStrokeId = sketchPanel.InkSketch.GetInkStrokeIdBySubstrokeId(substroke.XmlAttrs.Id);
                System.Windows.Ink.Stroke iStroke = sketchPanel.InkSketch.GetInkStrokeById(iStrokeId);

                if (iStrokeId2EndPtPainterId.ContainsKey(iStroke))
                {
                    throw new ApplicationException("Error: encountered one stroke " +
                                                   "that is part of two or more unique meshes");
                }

                if (iStrokeId != null)
                {
                    iStrokeId2EndPtPainterId.Add(iStroke, newEppIds);
                }
            }

            PaintAllEndpoints();
        }
Пример #8
0
 /// <summary>
 /// [TBS]
 /// </summary>
 public InkCanvasStrokeCollectedEventArgs(Swi.Stroke stroke) : base(InkCanvas.StrokeCollectedEvent)
 {
     if (stroke == null)
     {
         throw new ArgumentNullException("stroke");
     }
     _stroke = stroke;
 }
Пример #9
0
 public TouchPoint2(TouchInfo info, UIElement source, StylusPointCollection stylusPoints)
 {
     this.Source = source;
     Stroke = new Stroke(stylusPoints);
     TouchDeviceId = info.TouchDeviceId;
     StartTime = DateTime.Now;
     UpdateTouchInfo(info);
 }
Пример #10
0
 private void signaturePad_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     signaturePad.CaptureMouse();
     _currentStroke = new Stroke();
     _currentStroke.StylusPoints.Add(GetStylusPoint(e.GetPosition(signaturePad)));
     _currentStroke.DrawingAttributes.Color = Colors.Blue;
     signaturePad.Strokes.Add(_currentStroke);
 }
Пример #11
0
 /// <summary>
 /// Constructor
 /// </summary>
 internal InkCanvasStrokeErasingEventArgs(Swi.Stroke stroke)
 {
     if (stroke == null)
     {
         throw new ArgumentNullException("stroke");
     }
     _stroke = stroke;
 }
 /// <summary>
 /// Unhighlights a single Ink stroke
 /// </summary>
 /// <param name="iStroke">The stroke to unhighlight</param>
 private void unHighlightStroke(System.Windows.Ink.Stroke iStroke)
 {
     if (iStroke == null || iStroke.DrawingAttributes == null)
     {
         return; // Can't unhighlight this stroke
     }
     iStroke.DrawingAttributes.Width  /= MeshHighlightingThickeningFactor;
     iStroke.DrawingAttributes.Height /= MeshHighlightingThickeningFactor;
 }
Пример #13
0
		public void Stroke_Default_Bounds ()
		{
			Stroke s = new Stroke ();

			Rect bounds = s.GetBounds ();
			Assert.AreEqual (-1.5, bounds.Top, "Top");
			Assert.AreEqual (-1.5, bounds.Left, "Left");
			Assert.AreEqual (3, bounds.Height, "Height");
			Assert.AreEqual (3, bounds.Width, "Width");
		}
Пример #14
0
        /// <summary>
        /// Returns whether or not the stroke is within the drawing radius
        /// If it is not in the drawing radius, we start a new overlap collection
        /// </summary>
        /// <param name="stroke"></param>
        /// <returns></returns>
        private bool outsideDrawRadius(System.Windows.Ink.Stroke stroke)
        {
            Point strokeCenter = new Point(stroke.GetBounds().X + stroke.GetBounds().Width / 2,
                                           stroke.GetBounds().Y + stroke.GetBounds().Height / 2);
            Point strokeCollCenter = new Point(overlapStrokes.GetBounds().X + overlapStrokes.GetBounds().Width / 2,
                                               overlapStrokes.GetBounds().Y + overlapStrokes.GetBounds().Height / 2);
            double distance = Math.Sqrt(Math.Pow(strokeCenter.X - strokeCollCenter.X, 2) + Math.Pow(strokeCenter.Y - strokeCollCenter.Y, 2));

            return(distance > DRAW_RADIUS);
        }
Пример #15
0
 public Graph(IDelegate _del, Stroke b)
 {
     del = _del;
     box = b;
     bounds = box.GetBounds();
     box.StylusPoints = InkUtils.xkcd(InkUtils.box(bounds));
     box.DrawingAttributes.Color = Colors.Blue;
     analyzer = new InkAnalyzer();
     analyzer.ContextNodeCreated += ContextNodeCreated;
 }
Пример #16
0
		public void Stroke_Default ()
		{
			Stroke s = new Stroke ();

			Assert.AreEqual (0, s.StylusPoints.Count, "StylusPoints");

			Assert.Throws<ArgumentException> (delegate {
				s.HitTest (null);
			}, "HitTest-null");
			Assert.IsFalse (s.HitTest (s.StylusPoints), "HitTest-StylusPoints");
		}
Пример #17
0
        public void ipMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            myInkPresenter.CaptureMouse();

            _stroke = new Stroke(e.StylusDevice.GetStylusPoints(myInkPresenter))
                      	{
                      		DrawingAttributes = {Color = Colors.Blue,
                            OutlineColor = Colors.White},
                      	};

            myInkPresenter.Strokes.Add(_stroke);
        }
Пример #18
0
        //</SnippetLoadWPF>

        void CreateStrokes()
        {
            wpf.Point[] points  = new wpf.Point[] { new wpf.Point(0, 0), new wpf.Point(100, 100) };
            wpf.Point[] points2 = new wpf.Point[] { new wpf.Point(0, 0), new wpf.Point(150, 150) };

            strokes = new StrokeCollection();
            System.Windows.Ink.Stroke stroke1 = new System.Windows.Ink.Stroke(new StylusPointCollection(points));
            System.Windows.Ink.Stroke stroke2 = new System.Windows.Ink.Stroke(new StylusPointCollection(points2));

            strokes.Add(stroke1);
            strokes.Add(stroke2);
        }
Пример #19
0
        /// <summary>
        /// Deletes a Stroke from our internal data structures - the Sketch and FeatureSketch
        /// </summary>
        /// Precondition: The InkStroke is in the InkCanvas's collection of strokes.
        /// Postcondition: The InkStroke has been removed to the Sketch's list of
        /// Strokes, Substrokes, and FeatureSketch.
        /// <param name="inkStroke"></param>
        public void DeleteStroke(System.Windows.Ink.Stroke inkStroke)
        {
            // Update mappings
            Substroke substroke = substrokeIdMap[ink2sketchStr[(String)inkStroke.GetPropertyData(idGuid)]];

            ink2sketchStr.Remove((String)inkStroke.GetPropertyData(idGuid));
            sketchStr2ink.Remove(substroke.Id);
            substrokeIdMap.Remove(substroke.Id);

            // Remove it from the relevant data structures (InkCanvas last)
            mFeatureSketch.RemoveSubstroke(substroke);
            mInkCanvas.Strokes.Remove(inkStroke);
        }
Пример #20
0
 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);
 }
Пример #21
0
        /// <summary>
        /// Load a Stroke with a corresponding substroke.
        /// Precondition: Substroke is in the Sketch/FeatureSketch.
        /// Postcondition: The stroke's in our bookkeeping data structures.
        /// </summary>
        /// <param name="inkStroke">The Stroke to add</param>
        public void AddInkStrokeWithSubstroke(System.Windows.Ink.Stroke inkStroke, Sketch.Substroke substroke)
        {
            // Format the inkStroke
            inkStroke.AddPropertyData(dtGuid, (ulong)DateTime.Now.ToFileTime());
            String strokeId = System.Guid.NewGuid().ToString();

            inkStroke.AddPropertyData(idGuid, strokeId);

            // Add it to the data structures (InkCanvas last)
            ink2sketchStr.Add(strokeId, substroke.XmlAttrs.Id);
            sketchStr2ink.Add(substroke.XmlAttrs.Id, strokeId);
            substrokeIdMap.Add(substroke.XmlAttrs.Id, substroke);
            mInkCanvas.Strokes.Add(inkStroke);
        }
Пример #22
0
        /// <summary>
        /// Sets the color of Ink Stroke with Id iStrokeId to Color c
        ///
        /// Helper Function
        /// </summary>
        private void setInkStrokeColor(String iStrokeId, Color c)
        {
            System.Windows.Ink.Stroke iStroke = strokeFromString(iStrokeId);

            if (iStroke != null)
            {
                iStroke.DrawingAttributes.Color = c;

                // Invalidate highlighted stroke
                //int padding = highlightThicknessHeight > highlightThicknessWidth ?
                //        highlightThicknessHeight : highlightThicknessWidth;
                sketchPanel.InvalidateStroke(iStroke);
            }
        }
        /// <summary>
        /// Highlights the single Ink stroke that corresponds to the
        /// given substroke.
        ///
        /// Helper Function.
        /// </summary>
        /// <param name="substroke">The substroke to highlight.</param>
        private void highlightStroke(Substroke substroke)
        {
            // Get corresponding Ink stroke
            System.Windows.Ink.Stroke iStroke = sketchPanel.InkSketch.GetInkStrokeBySubstroke(substroke);

            if (iStroke == null || highlightedStrokes.Contains(iStroke))
            {
                return; // Can't highlight this stroke
            }
            iStroke.DrawingAttributes.Width  *= MeshHighlightingThickeningFactor;
            iStroke.DrawingAttributes.Height *= MeshHighlightingThickeningFactor;

            // Update records
            highlightedStrokes.Add(iStroke);
        }
Пример #24
0
        void annotoPenReceiver_PenUp(object sender, AnnotoPenMotionEventArgs e)
        {
            Dispatcher.BeginInvoke((Action)delegate()
            {
                /*if (currentPts == null || currentPts.Count == 0)
                {
                    return;
                }

                inkCanvas.Strokes.Add(new Stroke(currentPts));
                currentPts = new StylusPointCollection();*/
                currentStroke = null;
                Trace.WriteLine("Pen Up");
            }, null);
        }
Пример #25
0
        /// <summary>
        /// Helper wrapper
        /// </summary>
        internal static StrokeNodeIterator GetIterator(Stroke stroke, DrawingAttributes drawingAttributes)
        {
            if (stroke == null)
            {
                throw new System.ArgumentNullException("stroke");
            }
            if (drawingAttributes == null)
            {
                throw new System.ArgumentNullException("drawingAttributes");
            }

            StylusPointCollection stylusPoints =
                drawingAttributes.FitToCurve ? stroke.GetBezierStylusPoints() : stroke.StylusPoints;

            return GetIterator(stylusPoints, drawingAttributes);
        }
Пример #26
0
 private string StrokeToString(Stroke stroke)
 {
     var strokestring = "<stroke>";
     strokestring += "<color>" + stroke.DrawingAttributes.Color.ToString() + "</color>";
     strokestring += "<size>" + stroke.DrawingAttributes.Height.ToString() + "</size>";
     strokestring += "<creator>" + me + "</creator>";
     strokestring += "<points>";
     foreach (StylusPoint sp in stroke.StylusPoints)
     {
         strokestring += sp.X + "," + sp.Y + "," + sp.PressureFactor + " ";
     }
     strokestring.TrimEnd(new char[] { ' ' });
     strokestring += "</points>";
     strokestring += "</stroke>";
     return strokestring;
 }
        /// <summary>
        /// Allows the user to connect shapes by dragging a connection
        /// Stylus up connects the wire to the nearest target
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void InkCanvas_StylusUp(object sender, StylusEventArgs e)
        {
            if (debug)
            {
                Console.WriteLine("Endpoint stylus up recieved.");
            }

            // If no point has been clicked, return
            if (clickedIndex == null)
            {
                return;
            }

            EndPointPainter clickedPoint;

            endPointPainterMap.TryGetValue((int)clickedIndex, out clickedPoint);

            // Check if there are strokes close-by
            Sketch.EndPoint           oldLocation      = clickedPoint.EPoint;
            System.Windows.Point      oldLocationPoint = new System.Windows.Point(oldLocation.X, oldLocation.Y);
            System.Windows.Point      newLocation      = e.GetPosition(sketchPanel.InkCanvas);
            System.Windows.Ink.Stroke attachedStroke   = sketchPanel.InkSketch.GetInkStrokeBySubstroke(clickedPoint.EPoint.ParentSub);

            // Find the shape that the endpoint was dragged to
            // You can't connect a wire to itself!
            Shape closest = sketchPanel.Sketch.shapeAtPoint(newLocation.X, newLocation.Y, 10, clickedPoint.EPoint.ParentShape);

            if (closest != null && attachedStroke != null) //&& !clickedPoint.EPoint.IsConnected)
            {
                clickedPoint.Clear();
                clickedPoint.PointShape = null;
                endPointPainterMap.Remove((int)clickedIndex);

                // pass the endpoint moved event to the display manager
                endPointMoved(oldLocation, newLocation, attachedStroke, closest);
            }
            else
            {
                clickedPoint.ResetMove();
            }
            clickedPoint.PaintMe();

            // Reset the clickedIndex and the editing mode
            sketchPanel.EnableDrawing();
            clickedIndex = null;
        }
Пример #28
0
        /// <summary>
        /// Refreshes the underlying data structures corresponding to the inkStroke after the
        /// inkStroke has been modified (moved or resized)
        /// </summary>
        /// <param name="inkStroke">The Ink Stroke to modify</param>
        public void UpdateInkStroke(System.Windows.Ink.Stroke inkStroke)
        {
            // Delete the old stroke but save its shape for the new Stroke
            Sketch.Shape oldShape = GetSketchSubstrokeByInk(inkStroke).ParentShape;
            DeleteStroke(inkStroke);

            // Add the new stroke to the Sketch and put it in the old Shape
            AddStroke(inkStroke);
            Sketch.Substroke newSubstroke = GetSketchSubstrokeByInk(inkStroke);
            if (oldShape != null)
            {
                oldShape.AddSubstroke(newSubstroke);
                if (!Sketch.ShapesL.Contains(oldShape))
                {
                    Sketch.AddShape(oldShape);
                }
            }
        }
Пример #29
0
 public void process(InkAnalyzer inkAnalyzer)
 {
     ContextNodeCollection nodeCollection = inkAnalyzer.FindLeafNodes();
     foreach (ContextNode childNodes in nodeCollection)
     {
         foreach (Stroke stroke in childNodes.Strokes)
         {
             if (strokeIsCaret(stroke))
             {
                 insertionBox.Visibility = Visibility.Visible;
                 Canvas.SetLeft(insertionBox, stroke.StylusPoints[0].X - 140);
                 Canvas.SetTop(insertionBox, stroke.StylusPoints[1].Y);
                 inkAnalyzer.RemoveStroke(stroke);
                 strokeToBeReplaced = stroke;
             }
         }
     }
 }
        protected void Update( object sender, EventArgs e )
        {
            paintCanvas.Strokes.Clear();
            windowWidth = (float)this.Width;
            windowHeight = (float)this.Height;

            Leap.Frame frame = leap.Frame();
            InteractionBox interactionBox = leap.Frame().InteractionBox;

            foreach ( Pointable pointable in leap.Frame().Pointables ) {
                // ここから追加
                // 伸びている指、ツール以外は無視する
                //if ( !pointable.IsExtended ) {
                //    continue;
                //}
                // ここまで追加

                Leap.Vector normalizedPosition =
                    interactionBox.NormalizePoint( pointable.StabilizedTipPosition );
                float tx = normalizedPosition.x * windowWidth;
                float ty = windowHeight - normalizedPosition.y * windowHeight;

                int alpha = 255;
                if ( (pointable.TouchDistance > 0 && pointable.TouchZone != Pointable.Zone.ZONENONE ) ) {
                    alpha = 255 - (int)(255 * pointable.TouchDistance);
                    touchIndicator.Color = Color.FromArgb( (byte)alpha, 0x0, 0xff, 0x0 );
                }
                else if ( pointable.TouchDistance <= 0 ) {
                    alpha = -(int)(255 * pointable.TouchDistance);
                    touchIndicator.Color = Color.FromArgb( (byte)alpha, 0xff, 0x0, 0x0 );
                }
                else {
                    alpha = 50;
                    touchIndicator.Color = Color.FromArgb( (byte)alpha, 0x0, 0x0, 0xff );
                }

                StylusPoint touchPoint = new StylusPoint( tx, ty );
                StylusPointCollection tips =
                    new StylusPointCollection( new StylusPoint[] { touchPoint } );
                Stroke touchStroke = new Stroke( tips, touchIndicator );
                paintCanvas.Strokes.Add( touchStroke );
            }
        }
Пример #31
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);
        }
Пример #32
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");
		}
        /// <summary>
        /// Highlights the endpoints of a single Wire by
        /// creating EndPointPainters for all endpoints.
        ///
        /// Main function for endpoint highlighting.
        ///
        /// Wire must have "AlreadyLabeled" set to true.
        /// </summary>
        /// <param name="wire">The Wire to highlight</param>
        /// <param name="g">The graphics handle to use while creating painters</param>
        private void highlightEndpoints(Shape wire)
        {
            // If this hasn't been recognized or isn't a wire, don not highlight.
            if (!wire.AlreadyLabeled || !LogicDomain.IsWire(wire.Type))
            {
                return;
            }

            List <int>      newEppIds = new List <int>();
            EndPointPainter epp;
            int             eppId;

            foreach (Sketch.EndPoint endpoint in wire.Endpoints)
            {
                epp    = createEndpointPainter(endpoint);
                eppId  = endPointPainterMap.Keys.Count + 1;
                epp.Id = eppId;
                newEppIds.Add(eppId);
                endPointPainterMap.Add(eppId, epp);
            }

            // Update stroke map to point to endpoint painters
            foreach (Sketch.Substroke substroke in wire.Substrokes)
            {
                String iStrokeId = sketchPanel.InkSketch.GetInkStrokeIdBySubstrokeId(substroke.XmlAttrs.Id);
                System.Windows.Ink.Stroke iStroke = sketchPanel.InkSketch.GetInkStrokeById(iStrokeId);

                if (iStrokeId2EndPtPainterId.ContainsKey(iStroke))
                {
                    throw new ApplicationException("Error: encountered one stroke " +
                                                   "that is part of two or more unique meshes");
                }

                if (iStrokeId != null)
                {
                    iStrokeId2EndPtPainterId[iStroke] = newEppIds;
                }
            }

            PaintAllEndpoints();
        }
Пример #34
0
            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="stroke">a stroke to render into this visual</param>
            /// <param name="renderer">a renderer associated to this visual</param>
            internal StrokeVisual(Stroke stroke, Renderer renderer) : base()
            {
                Debug.Assert(renderer != null);

                if (stroke == null)
                {
                    throw new System.ArgumentNullException("stroke");
                }

                _stroke = stroke;
                _renderer = renderer;

                // The original value of the color and IsHighlighter are cached so
                // when Stroke.Invalidated is fired, Renderer knows whether re-arranging
                // the visual tree is needed.
                _cachedColor = stroke.DrawingAttributes.Color;
                _cachedIsHighlighter = stroke.DrawingAttributes.IsHighlighter;

                // Update the visual contents
                Update();
            }
Пример #35
0
        /// <summary>
        /// Transforms the strokes using the selected TextConverter
        /// </summary>
        public void RecognizeText()
        {
            if (strokes != null && strokes.Count > 0)
            {
                Stroke firstStroke = strokes[0];

                if (firstStroke != null && firstStroke.StylusPoints != null && firstStroke.StylusPoints.Count > 0)
                {
                    StylusPoint firstPoint = firstStroke.StylusPoints[0];
                    int         pageNr     = 0;

                    PdfSourcePoint firstPointOnPage = controller.TransformOnScreenToOnNearestPage(new PdfTargetPoint((int)firstPoint.X, (int)firstPoint.Y), ref pageNr);

                    string   content = controller.ConvertAnnotations(strokes);
                    double[] point   = new double[] { firstPointOnPage.dX, firstPointOnPage.dY };
                    double[] color   = new double[] { AnnotationStrokeColor.R / 255.0, AnnotationStrokeColor.G / 255.0, AnnotationStrokeColor.B / 255.0 };

                    controller.CreateTextAnnotation(content, pageNr, point, color);
                }
            }
        }
Пример #36
0
        /// <summary>
        /// Deletes an error label when its corresponding strokes are erased.
        /// </summary>
        private void InkPicture_StrokesDeleting(object sender, InkCanvasStrokeErasingEventArgs e)
        {
            System.Windows.Ink.Stroke iStroke = e.Stroke;

            if (iStroke2Label == null)
            {
                return;
            }

            if (iStroke2Label.ContainsKey((String)iStroke.GetPropertyData(idGuid)))
            {
                System.Windows.Controls.Label label = iStroke2Label[(String)iStroke.GetPropertyData(idGuid)];

                label.Visibility = System.Windows.Visibility.Visible;
                sketchPanel.InkCanvas.Children.Remove(label);

                errorLabels.Remove(label);

                sketchPanel.InkCanvas.InvalidateArrange();
            }
        }
Пример #37
0
        /// <summary>
        /// Adds a Stroke to our internal data structures - the Sketch and FeatureSketch
        /// </summary>
        /// Precondition: The InkStroke is not in the InkCanvas's collection of strokes.
        /// Postcondition: The InkStroke has been added to the InkCanvas, Sketch's list of
        /// Strokes, Substrokes, and FeatureSketch.
        /// <param name="inkStroke"></param>
        public void AddStroke(System.Windows.Ink.Stroke inkStroke)
        {
            if (mInkCanvas.Strokes.Contains(inkStroke))
            {
                throw new Exception("adding a stroke to the InkCanvasSketch, but it was already there!");
            }
            // Format the stroke
            inkStroke.AddPropertyData(dtGuid, (ulong)DateTime.Now.ToFileTime());
            string strokeId = Guid.NewGuid().ToString();

            inkStroke.AddPropertyData(idGuid, strokeId);

            // Update the dictionaries
            Sketch.Stroke sketchStroke = new Sketch.Stroke(inkStroke, dtGuid, SAMPLE_RATE);
            ink2sketchStr.Add(strokeId, sketchStroke.Substrokes[0].XmlAttrs.Id);
            sketchStr2ink.Add(sketchStroke.Substrokes[0].Id, strokeId);
            substrokeIdMap.Add(sketchStroke.Substrokes[0].Id, sketchStroke.Substrokes[0]);

            // Add it to the relevant data structures (InkCanvas last.)
            mFeatureSketch.AddStroke(sketchStroke);
            mInkCanvas.Strokes.Add(inkStroke);
        }
Пример #38
0
 static void CreatingPage_GetResault(PhoneApplicationPage sender, string obj)
 {
     foreach (ApplicationBarIconButton appBarBtn in (sender as CreatingPage).ApplicationBar.Buttons) {
         appBarBtn.IsEnabled = true;
     }
     if (obj != null) {
         StrokePattern newPattern = new StrokePattern();
         newPattern.PatternName = obj;
         foreach (Stroke stroke in (sender as CreatingPage).inkPresenter.Strokes) {
             Stroke modifiedStroke = new Stroke();
             modifiedStroke.DrawingAttributes.Color = Colors.White;
             modifiedStroke.DrawingAttributes.Width = 3;
             modifiedStroke.DrawingAttributes.Height = 3;
             foreach (StylusPoint point in stroke.StylusPoints) {
                 modifiedStroke.StylusPoints.Add(new StylusPoint(point.X / 3, point.Y / 3));
             }
             newPattern.Items.Add(new StrokeCollection { modifiedStroke });
         }
         App.PatternViewModel.UserPatterns.Add(newPattern);
         sender.NavigationService.GoBack();
     }
 }
Пример #39
0
        /// <summary>
        /// Loads a stroke from the stream based on Stroke Descriptor, StylusPointDescription, Drawing Attributes, Stroke IDs, transform and GuidList
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="size"></param>
        /// <param name="guidList"></param>
        /// <param name="strokeDescriptor"></param>
        /// <param name="stylusPointDescription"></param>
        /// <param name="drawingAttributes"></param>
        /// <param name="transform"></param>
        /// <param name="stroke">Newly decoded stroke</param>
#endif
        internal static uint DecodeStroke(Stream stream,
                                 uint size,
                                 GuidList guidList,
                                 StrokeDescriptor strokeDescriptor,
                                 StylusPointDescription stylusPointDescription,
                                 DrawingAttributes drawingAttributes,
                                 Matrix transform,
#if OLD_ISF
                                 Compressor compressor,
#endif
                                 out Stroke stroke)
        {
            ExtendedPropertyCollection extendedProperties;
            StylusPointCollection stylusPoints;

            uint cb = DecodeISFIntoStroke(
#if OLD_ISF
                compressor, 
#endif 
                stream, 
                size, 
                guidList, 
                strokeDescriptor, 
                stylusPointDescription, 
                transform, 
                out stylusPoints, 
                out extendedProperties);

            if (cb != size)
            {
                throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("Stroke size (" +
                    cb.ToString(System.Globalization.CultureInfo.InvariantCulture) + ") != expected (" + 
                    size.ToString(System.Globalization.CultureInfo.InvariantCulture) + ")"));
            }

            stroke = new Stroke(stylusPoints, drawingAttributes, extendedProperties);

            return cb;
        }
Пример #40
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;
        }
        private bool InterpretScratchoutGesture(System.Windows.Ink.Stroke stroke)
        {
            // Attempt to instantiate a recognizer for scratchout gestures.
            System.Windows.Ink.ApplicationGesture[] gestures = { System.Windows.Ink.ApplicationGesture.ScratchOut };
            GestureRecognizer recognizer = new GestureRecognizer(gestures);

            if (!recognizer.IsRecognizerAvailable)
            {
                return(false);
            }

            // Determine if the stroke was a scratchout gesture.
            StrokeCollection gestureStrokes = new StrokeCollection();

            gestureStrokes.Add(stroke);

            ReadOnlyCollection <GestureRecognitionResult> results = recognizer.Recognize(gestureStrokes);

            if (results.Count == 0)
            {
                return(false);
            }

            // Results are returned sorted in order strongest-to-weakest;
            // we need only analyze the first (strongest) result.
            if (results[0].ApplicationGesture == System.Windows.Ink.ApplicationGesture.ScratchOut &&
                results[0].RecognitionConfidence == System.Windows.Ink.RecognitionConfidence.Strong)
            {
                // Use the scratchout stroke to perform hit-testing and
                // erase existing strokes, as necessary.
                return(true);
            }
            else
            {
                // Not a gesture: display the stroke normally.
                return(false);
            }
        }
Пример #42
0
        /// <summary>
        /// Obtain a smoothed path with the specified granularity from the current path using Catmull-Rom spline.
        /// Also outputs a List of the points corresponding to the smoothed path.
        /// </summary>
        /// <remarks>
        /// Implemented using a modified version of the code in the solution at
        /// http://stackoverflow.com/questions/8702696/drawing-smooth-curves-methods-needed
        /// </remarks>
        public static InkStroke SmoothedPathWithGranularity(InkStroke currentPath, int granularity)
        {
            var currentPoints = currentPath.GetPoints().Select(inkPoint => inkPoint.Position).ToList();

            NativePath         smoothedPath;
            List <NativePoint> smoothedPoints;

            SmoothedPathWithGranularity(currentPoints, granularity, out smoothedPath, out smoothedPoints);
            if (smoothedPath == null)
            {
                return(currentPath);
            }

            // create the new path with the old attributes
#if __ANDROID__ || __IOS__ || WINDOWS_PHONE_APP
            return(new InkStroke(smoothedPath, currentPath.GetPoints(), currentPath.Color, currentPath.Width, currentPath.Source, currentPath.Timestamp));
#elif WINDOWS_PHONE
            var da = currentPath.DrawingAttributes;
            smoothedPath.DrawingAttributes = new DrawingAttributes
            {
                Color        = da.Color,
                OutlineColor = da.OutlineColor,
                Width        = da.Width,
                Height       = da.Height,
            };
            return(smoothedPath);
#elif WINDOWS_UWP || WINDOWS_APP
            var da      = currentPath.DrawingAttributes;
            var builder = new InkStrokeBuilder();
            builder.SetDefaultDrawingAttributes(new InkDrawingAttributes
            {
                Color = da.Color,
                Size  = da.Size
            });
            return(builder.CreateStroke(smoothedPath));
#endif
        }
Пример #43
0
        /// <summary>
        /// Refreshes the underlying data structures corresponding to the inkStroke after the
        /// inkStroke has been modified (moved or resized)
        /// </summary>
        /// <param name="inkStroke">The Ink Stroke to modify</param>
        public void UpdateInkStroke(System.Windows.Ink.Stroke inkStroke)
        {
            // Remove the old substroke, saving the old shape for the new substroke.
            Shape oldShape = GetSketchSubstrokeByInk(inkStroke).ParentShape;

            DeleteStroke(inkStroke);

            AddStroke(inkStroke);
            Substroke newSubstroke = GetSketchSubstrokeByInk(inkStroke);

            if (newSubstroke.ParentShape != null)
            {
                throw new Exception("jesus dear lord why does this newly"
                                    + "created substroke already have a parent Shape");
            }
            if (oldShape != null)
            {
                oldShape.AddSubstroke(newSubstroke);
                if (!Sketch.containsShape(oldShape))
                {
                    Sketch.AddShape(oldShape);
                }
            }
        }
Пример #44
0
        private bool ScribbleDelete(Stroke stroke)
        {
            starPadSDK.Inq.Stroq stroq = new starPadSDK.Inq.Stroq(stroke);
            bool canBeScribble = stroq.OldPolylineCusps().Length > 4;
            if (stroq.OldPolylineCusps().Length == 4)
            {
                int[] pcusps = stroq.OldPolylineCusps();
                Deg a1 = fpdangle(stroq[0], stroq[pcusps[1]], stroq[pcusps[2]] - stroq[pcusps[1]]);
                Deg a2 = fpdangle(stroq[pcusps[1]], stroq[pcusps[1]], stroq[pcusps[3]] - stroq[pcusps[1]]);
                if (a1 < 35 && a2 < 35)
                    canBeScribble = stroq.BackingStroke.HitTest(stroq.ConvexHull().First(), 1);
            }
            if (canBeScribble)
            {
                //BOKANG
               
                bool removeCurrentStroke = CheckRemoveGate(stroke);

                IEnumerable<starPadSDK.Geom.Pt> hull = stroq.ConvexHull();

                List<Point> hullTemp = new List<Point>();
                foreach (starPadSDK.Geom.Pt pt in hull)
                {
                    hullTemp.Add(new Point(pt.X, pt.Y));
                }

                StrokeCollection stks = circuitInkCanvas.Strokes.HitTest(hullTemp, 50);
                //StroqCollection stqs = inqCanvas.Stroqs.HitTest(hull, 1);
                if (stks.Count > 1)
                {
                    //inqCanvas.Stroqs.Remove(stqs);
                    circuitInkCanvas.Strokes.Remove(stks);
                    if (stks.Contains(stroke))
                    {
                        stks.Remove(stroke);
                    }

                    if(circuitInkCanvas.Strokes.Contains(stroke))
                    {
                        circuitInkCanvas.Strokes.Remove(stroke);
                    }
                    //inqCanvas.Stroqs.Remove(stroq);
                    return true;
                }

                if (removeCurrentStroke)
                {
                    if(circuitInkCanvas.Strokes.Contains(stroke))
                    {
                        circuitInkCanvas.Strokes.Remove(stroke);
                    }
                }

            }
            return false;
        }
Пример #45
0
        private bool CheckRemoveGate(Stroke stroke)
        {
            Rect strokeBound = stroke.GetBounds();

            bool removeGate = false;

            List<Gate> removedGates = new List<Gate>();
            
            for(int i = 0; i < circuitInkCanvas.Children.Count; i++)
            {
                UIElement gate = circuitInkCanvas.Children[i];
                
                if (gate is Gate)
                {
                    Gate g = gate as Gate;

                    Rect grect = new Rect(g.Margin.Left + 40, g.Margin.Top + 40, g.Width - 40, g.Height - 40);

                    if (strokeBound.Contains(grect))
                    {   
                        //this.RemoveGate(g);
                        removedGates.Add(g);
                        removeGate = true;
                    } 
                }else if(gate is ConnectedWire)
                {
                    ConnectedWire wire = gate as ConnectedWire;

                    //Debug.WriteLine("Stroke Rect Bound: " + strokeBound.ToString());
                    //Debug.WriteLine("Wire Origin is " + wire.Origin.ToString());
                    //Debug.WriteLine("Wire Destination is " + wire.Destination.ToString());

                    //Debug.WriteLine("Wire Outer Margin is " + wire.Outer.Margin.ToString());

                    HitTestResult result = null;
                    int count = 0;
                    foreach(StylusPoint pt in stroke.StylusPoints)
                    {
                        result = VisualTreeHelper.HitTest(wire, pt.ToPoint());
                        if(result != null)
                        {
                            count++;
                        }
                    }

                    //Debug.WriteLine("Count is " + count.ToString());
                    if(count >= 3)
                    {

                        //trigger remove wire
                        //From connectedWire to get terminal

                        Gates.Terminal t = new Gates.Terminal(wire.DestTerminalID.ID, wire.DestinationGate);
                        c.Disconnect1(t);
                        circuitInkCanvas.Children.Remove(wire);

                        /*
                        for (int j = 0; j < wire.DestinationGate.NumberOfInputs; j++)
                        {
                            Gates.Terminal t = new Gates.Terminal(j, wire.DestinationGate);

                            //Gates.Terminal t = new Gates.Terminal(j, wire.OriginGate);
                            if (t != null)
                            {
                                c.Disconnect1(t);

                                circuitInkCanvas.Children.Remove(wire);
                            }
                        }
                         */
                        
                        removeGate = true;
                    }
                }
            }
            
            if(removeGate)
            {
                foreach (Gate g in removedGates)
                {
                    this.RemoveGate(g);
                } 
                return true;
            }

            return false;
         }
 private static bool IsNearbyPoint(System.Windows.Ink.Stroke stroke, Point point)
 {
     return(stroke.StylusPoints.Any(p => (Math.Abs(p.X - point.X) <= ThreasholdNearbyDistance) &&
                                    (Math.Abs(p.Y - point.Y) <= ThreasholdNearbyDistance)));
 }
Пример #47
0
        /// <summary>
        /// StrokeInfo
        /// </summary>
        internal StrokeInfo(Stroke stroke)
        {
            System.Diagnostics.Debug.Assert(stroke != null);
            _stroke = stroke;
            _bounds = stroke.GetBounds();

            // Start listening to the stroke events
            _stroke.DrawingAttributesChanged += new PropertyDataChangedEventHandler(OnStrokeDrawingAttributesChanged);
            _stroke.StylusPointsReplaced += new StylusPointsReplacedEventHandler(OnStylusPointsReplaced);
            _stroke.StylusPoints.Changed += new EventHandler(OnStylusPointsChanged);
            _stroke.DrawingAttributesReplaced += new DrawingAttributesReplacedEventHandler(OnDrawingAttributesReplaced);
        }
Пример #48
0
        /// <summary>
        /// Obtain a smoothed path with the specified granularity from the current path using Catmull-Rom spline.
        /// Also outputs a List of the points corresponding to the smoothed path.
        /// </summary>
        /// <remarks>
        /// Implemented using a modified version of the code in the solution at
        /// http://stackoverflow.com/questions/8702696/drawing-smooth-curves-methods-needed
        /// </remarks>
        public static InkStroke SmoothedPathWithGranularity(InkStroke currentPath, int granularity)
        {
            var currentPoints = currentPath.GetPoints().ToList();

            // not enough points to smooth effectively, so return the original path and points.
            if (currentPoints.Count < 4)
            {
                return(currentPath);
            }

            // create a new bezier path to hold the smoothed path.
            var smoothedPath   = new NativePath();
            var smoothedPoints = new List <NativePoint> ();

            // duplicate the first and last points as control points.
            currentPoints.Insert(0, currentPoints[0]);
            currentPoints.Add(currentPoints[currentPoints.Count - 1]);

            // add the first point
            smoothedPath.MoveTo(currentPoints[0].X, currentPoints[0].Y);
            smoothedPoints.Add(currentPoints[0]);

            for (var index = 1; index < currentPoints.Count - 2; index++)
            {
                var p0 = currentPoints[index - 1];
                var p1 = currentPoints[index];
                var p2 = currentPoints[index + 1];
                var p3 = currentPoints[index + 2];

                // add n points starting at p1 + dx/dy up until p2 using Catmull-Rom splines
                for (var i = 1; i < granularity; i++)
                {
                    var t   = (float)i * (1f / (float)granularity);
                    var tt  = t * t;
                    var ttt = tt * t;

                    // intermediate point
                    var mid = new NativePoint
                    {
                        X = 0.5f * (2f * p1.X + (p2.X - p0.X) * t +
                                    (2f * p0.X - 5f * p1.X + 4f * p2.X - p3.X) * tt +
                                    (3f * p1.X - p0.X - 3f * p2.X + p3.X) * ttt),

                        Y = 0.5f * (2 * p1.Y + (p2.Y - p0.Y) * t +
                                    (2 * p0.Y - 5 * p1.Y + 4 * p2.Y - p3.Y) * tt +
                                    (3 * p1.Y - p0.Y - 3 * p2.Y + p3.Y) * ttt)
                    };
                    smoothedPath.LineTo(mid.X, mid.Y);
                    smoothedPoints.Add(mid);
                }

                // add p2
                smoothedPath.LineTo(p2.X, p2.Y);
                smoothedPoints.Add(p2);
            }

            // add the last point
            var last = currentPoints[currentPoints.Count - 1];

            smoothedPath.LineTo(last.X, last.Y);
            smoothedPoints.Add(last);

            // create the new path with the old attributes
#if __ANDROID__ || __IOS__
            return(new InkStroke(smoothedPath, smoothedPoints.ToList(), currentPath.Color, currentPath.Width));
#elif WINDOWS_PHONE
            var da = currentPath.DrawingAttributes;
            smoothedPath.DrawingAttributes = new DrawingAttributes
            {
                Color        = da.Color,
                OutlineColor = da.OutlineColor,
                Width        = da.Width,
                Height       = da.Height,
            };
            return(smoothedPath);
#elif WINDOWS_UWP
            var da      = currentPath.DrawingAttributes;
            var builder = new InkStrokeBuilder();
            builder.SetDefaultDrawingAttributes(new InkDrawingAttributes
            {
                Color = da.Color,
                Size  = da.Size
            });
            return(builder.CreateStroke(smoothedPath));
#endif
        }
        private Path StrokeToPath(Stroke oStroke)
        {
            PathFigure myPathFigure = null;
            LineSegment myLineSegment = null;
            PathFigureCollection myPathFigureCollection = new PathFigureCollection();
            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();

            if (oStroke == null) return null;

            // Number of points.
            int n = oStroke.StylusPoints.Count;
            if (n == 0) return null;

            // Start point is first point from sytluspoints collection (M, item 0).
            myPathFigure = new PathFigure();
            myPathFigure.StartPoint =
                new Point(oStroke.StylusPoints[0].X, oStroke.StylusPoints[0].Y);
            myPathFigureCollection.Add(myPathFigure);

            // Make small line segment L if there is only one point in the Stroke (workaround).
            // Data with only M is not shown.
            if (n == 1)
            {
                myLineSegment = new LineSegment();
                myLineSegment.Point =
                    new Point(oStroke.StylusPoints[0].X + 1, oStroke.StylusPoints[0].Y + 1);
                myPathSegmentCollection.Add(myLineSegment);
            }

            // The other points are line segments (L, items 1..n-1).
            for (int i = 1; i < n; i++)
            {
                myLineSegment = new LineSegment();
                myLineSegment.Point = new Point(oStroke.StylusPoints[i].X, oStroke.StylusPoints[i].Y);
                myPathSegmentCollection.Add(myLineSegment);
            }

            myPathFigure.Segments = myPathSegmentCollection;

            PathGeometry myPathGeometry = new PathGeometry();
            myPathGeometry.Figures = myPathFigureCollection;

            Path oPath = new Path();

            // Add the data to the Path.
            oPath.Data = myPathGeometry;                    // <-|

            // Copy Stroke properties to Path.
            // ----------------------------------------
            // Stroke color.
            Color oC = oStroke.DrawingAttributes.Color;     // Stroke color.
            SolidColorBrush oBr = new SolidColorBrush();
            oBr.Color = oC;
            oPath.Stroke = oBr;

            // Stroke thickness.
            double dW = oStroke.DrawingAttributes.Width;    // Width of stylus.
            double dH = oStroke.DrawingAttributes.Height;   // Height of stylus.
            oPath.StrokeThickness = dW;

            // Attribute FitToCurve.
            // FitToCurve has no effect on the points, oStroke.StylusPoints is used.
            // See also oStroke.GetBezierStylusPoints().
            // See also test with GetAllPoints().

            // Stroke has no Fill property in attributes.
            // oPath.Fill = mySolidColorBrush;
            // ----------------------------------------

            return oPath;
        }
Пример #50
0
 /// <summary>
 /// C-tor
 /// </summary>
 internal StrokeHitEventArgs(Stroke stroke, StrokeIntersection[] hitFragments)
 {
     System.Diagnostics.Debug.Assert(stroke != null && hitFragments != null && hitFragments.Length > 0);
     _stroke = stroke;
     _hitFragments = hitFragments;
 }
 private void ImageArea_LostMouseCapture(object sender, MouseEventArgs e)
 {
     _newStroke = null;
 }
 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);
 }
Пример #53
0
		//Allow the user to import an array of points to be used to draw a signature in the view, with new
		//lines indicated by a PointF.Empty in the array.
		public void LoadPoints (Point [] loadedPoints)
		{
			if (loadedPoints == null || loadedPoints.Count () == 0)
				return;

			var startIndex = 0;
			var emptyIndex = loadedPoints.ToList ().IndexOf (new Point (-10000, -10000));

			if (emptyIndex == -1)
				emptyIndex = loadedPoints.Count ();

			//Clear any existing paths or points.
			strokes = new List<Stroke> ();
			points = new List<Point []> ();

			do {
				//Create a new path and set the line options
				currentStroke = new Stroke ();
				currentStroke.DrawingAttributes.Color = strokeColor;
				currentStroke.DrawingAttributes.Width = lineWidth;
				currentStroke.DrawingAttributes.Height = lineWidth;

				currentPoints = new List<Point> ();

				//Move to the first point and add that point to the current_points array.
				currentStroke.StylusPoints.Add (GetPoint (loadedPoints [startIndex]));
				currentPoints.Add (loadedPoints [startIndex]);

				//Iterate through the array until an empty point (or the end of the array) is reached,
				//adding each point to the current_path and to the current_points array.
				for (var i = startIndex + 1; i < emptyIndex; i++) {
					currentStroke.StylusPoints.Add (GetPoint  (loadedPoints [i]));
					currentPoints.Add (loadedPoints [i]);
				}

				//Add the current_path and current_points list to their respective Lists before
				//starting on the next line to be drawn.
				strokes.Add (currentStroke);
				points.Add (currentPoints.ToArray ());

				//Obtain the indices for the next line to be drawn.
				startIndex = emptyIndex + 1;
				if (startIndex < loadedPoints.Count () - 1) {
					emptyIndex = loadedPoints.ToList ().IndexOf (new Point (-10000, -10000), startIndex);

					if (emptyIndex == -1)
						emptyIndex = loadedPoints.Count ();
				} else
					emptyIndex = startIndex;
			} while (startIndex < emptyIndex);

			//Obtain the image for the imported signature and display it in the image view.
			image.Source = GetImage (false);
			//Display the clear button.
			btnClear.Visibility = Visibility.Visible;
		}
Пример #54
0
		protected void inkPresenter_OnMouseLeftButtonUp (object sender, MouseButtonEventArgs e)
		{
			Point point = e.GetPosition (inkPresenter);

			// Only add the point to the stroke if it is on the current view.
			if (currentStroke != null && point.X >= 0 && point.Y >= 0 && point.X <= ActualWidth && 
			    point.Y <= ActualHeight) {
				currentPoints.Add (point);	
				currentStroke.StylusPoints.Add (GetPoint (point));
			}

			//Clear the ink presenter and display an image of all strokes.
			inkPresenter.Strokes.Clear ();
			currentStroke = smoothedPathWithGranularity (40, out currentPoints);
			strokes.Add (currentStroke);
			points.Add (currentPoints.ToArray ());
			
			currentStroke = null;
			image.Source = GetImage (false);
		}
Пример #55
0
 public StrokeOverlayAdorner(InkCanvas canvas, Stroke stroke)
     : base(canvas)
 {
     this.stroke = stroke;
 }
Пример #56
0
        private void LeftMouseUpEventHandler(Object sender, MouseEventArgs e)
        {
            if (!controller.IsOpen)
            {
                return;
            }
            if (mouseScrolling)
            {
                Vector delta = System.Windows.Point.Subtract(e.GetPosition(this), lastMousePosition);
                controller.Scroll(delta);
                this.Cursor    = Cursors.Hand;
                mouseScrolling = false;
            }
            else if (markingRectangle)
            {
                selectedRect     = new Rect(lastMousePosition, e.GetPosition(this));
                markingRectangle = false;
                if (MouseMode == TMouseMode.eMouseZoomMode)
                {
                    controller.ZoomToRectangle(new PdfTargetRect(selectedRect));
                }
                else if (MouseMode == TMouseMode.eMouseMarkMode && selectedRectangleOnCanvas != null)
                {
                    selectedRectangleOnCanvas(controller.TransformOnScreenToOnCanvas(new PdfTargetRect(selectedRect)));
                }

                InvalidateVisual();
            }
            else if (selectingText)
            {
                selectingText = false;
                if (TextSelected != null)
                {
                    TextSelected(_selectedText);
                }
                this.InvalidateVisual();
            }
            else if (creatingDrawingAnnotation) //[InkingForPDF]
            {
                creatingDrawingAnnotation = false;
                CreateInkAnnotation();
            }
            else if (creatingClickAnnotation) //[InkingForPDF]
            {
                if (annotationPoints == null)
                {
                    annotationPoints = new List <Point>();
                }
                annotationPoints.Add(e.GetPosition(this));
            }
            else if (creatingTextRecognitionNote) //[InkingForPDF]
            {
                var s = new Stroke(new StylusPointCollection(annotationPoints));
                strokes.Add(s);

                annotationPoints            = null;
                creatingTextRecognitionNote = false;
            }
            else if (movingAnnotations) //[InkingForPDF]
            {
                movingAnnotations = false;

                if (annotationPoints != null && annotationPoints.Count > 0)
                {
                    MoveSelectedAnnotations(annotationPoints[0], lastMousePosition);
                }
            }

            e.Handled = true;
        }
Пример #57
0
        /// <summary>
        /// Returns a the sketch substroke corresponding to the given
        /// Ink stroke.  Returns null if no corresponding
        /// Sketch stroke exists.
        /// </summary>
        /// <param name="id">The Ink stroke</param>
        /// <returns>The corresponding Sketch substroke</returns>
        public Substroke GetSketchSubstrokeByInk(System.Windows.Ink.Stroke stroke)
        {
            String id = (String)stroke.GetPropertyData(idGuid);

            return(GetSketchSubstrokeByInkId(id));
        }
Пример #58
0
 public StrokeOverlayAdorner(InkCanvas canvas, Stroke stroke, Color color)
     : base(canvas)
 {
     this.stroke = stroke;
     brush = new SolidColorBrush { Opacity = 0.5, Color = color };
 }
Пример #59
0
        /// <summary>
        /// Returns a list of ink strokes from the existing sub strokes
        /// </summary>
        /// Precondition: Sketch has been loaded into the inkSketch
        public StrokeCollection CreateInkStrokesFromSketch()
        {
            StrokeCollection strokeColl = new StrokeCollection();

            foreach (Substroke sub in mSketch.Substrokes)
            {
                StylusPointCollection points = new StylusPointCollection();

                foreach (Sketch.Point point in sub.Points)
                {
                    StylusPoint styPoint = new StylusPoint(point.X, point.Y);
                    if (point.Pressure > 1)
                    {
                        styPoint.PressureFactor = 1;
                    }
                    else if (point.Pressure < 0)
                    {
                        styPoint.PressureFactor = 0;
                    }
                    else
                    {
                        styPoint.PressureFactor = point.Pressure;
                    }
                    points.Add(styPoint);
                }

                System.Windows.Ink.Stroke stroke = new System.Windows.Ink.Stroke(points);

                stroke.DrawingAttributes.FitToCurve     = true;
                stroke.DrawingAttributes.IgnorePressure = false;

                System.Windows.Media.Color color = new System.Windows.Media.Color();
                color = System.Windows.Media.Color.FromArgb(0, 0, 0, 0);
                if (sub.XmlAttrs.Color != null)
                {
                    stroke.DrawingAttributes.Color = color;
                }
                if (sub.XmlAttrs.PenWidth != null)
                {
                    stroke.DrawingAttributes.Width = Convert.ToSingle(sub.XmlAttrs.PenWidth);
                }
                if (sub.XmlAttrs.PenHeight != null)
                {
                    stroke.DrawingAttributes.Height = Convert.ToSingle(sub.XmlAttrs.PenHeight);
                }
                if (sub.XmlAttrs.PenTip != null)
                {
                    if (sub.XmlAttrs.PenTip.Equals("Ball"))
                    {
                        stroke.DrawingAttributes.StylusTip = StylusTip.Ellipse;
                    }
                    else if (sub.XmlAttrs.PenTip.Equals("Rectangle"))
                    {
                        stroke.DrawingAttributes.StylusTip = StylusTip.Rectangle;
                    }
                }

                strokeColl.Add(stroke);
                AddInkStrokeWithSubstroke(stroke, sub);
            }
            return(strokeColl);
        }