Пример #1
0
        public void ColorStrokesByType(List <Sketch.Shape> shapes)
        {
            if (!StrokeColoring)
            {
                ClearColors();
                return;
            }

            if (this.panel.InkSketch.Sketch != null)
            {
                foreach (Sketch.Shape shape in shapes)
                {
                    Color color = shape.Type.Color;
                    if (!shape.AlreadyLabeled)
                    {
                        color = Colors.Black;
                    }

                    foreach (Sketch.Substroke substroke in shape.Substrokes)
                    {
                        System.Windows.Ink.Stroke stroke = panel.InkSketch.GetInkStrokeBySubstroke(substroke);
                        stroke.DrawingAttributes.Color = color;
                    }
                }
                panel.InkCanvas.InvalidateVisual();
                panel.InkCanvas.UpdateLayout();
            }
        }
Пример #2
0
        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;
        }
Пример #3
0
        /// <summary>
        /// Draw the strokes saved up
        /// </summary>
        private void draw()
        {
            canvas.EditingMode = InkCanvasEditingMode.Ink;

            System.Windows.Ink.Stroke stroke = new System.Windows.Ink.Stroke(stylusPoints, canvas.DefaultDrawingAttributes);
            canvas.Strokes.Add(stroke);
        }
Пример #4
0
        /// <summary>
        /// Displays the classification for each stroke, using default (hard-coded) colors
        /// </summary>
        public void displayClassification()
        {
            foreach (Sketch.Substroke substroke in panel.InkSketch.Sketch.Substrokes)
            {
                String mstrokeId = panel.InkSketch.GetInkStrokeBySubstrokeId(substroke.XmlAttrs.Id);
                System.Windows.Ink.Stroke mstroke = panel.InkSketch.GetInkStrokeById(mstrokeId);

                if (substroke.XmlAttrs.Classification == "Wire")
                {
                    mstroke.DrawingAttributes.Color = System.Windows.Media.Colors.Blue;
                }
                else if (substroke.XmlAttrs.Classification == "Gate")
                {
                    mstroke.DrawingAttributes.Color = System.Windows.Media.Colors.Red;
                }
                else if (substroke.XmlAttrs.Classification == "Text")
                {
                    mstroke.DrawingAttributes.Color = System.Windows.Media.Colors.Yellow;
                }
                else
                {
                    mstroke.DrawingAttributes.Color = System.Windows.Media.Colors.Black;
                }
            }

            panel.InkCanvas.InvalidateVisual();
            panel.InkCanvas.UpdateLayout();
        }
Пример #5
0
 /// <summary>
 /// Makes all strokes in the specified shape black
 /// </summary>
 /// <param name="shape"></param>
 public void ClearColors(Sketch.Shape shape)
 {
     foreach (Sketch.Substroke sub in shape.Substrokes)
     {
         System.Windows.Ink.Stroke stroke = panel.InkSketch.GetInkStrokeBySubstroke(sub);
         stroke.DrawingAttributes.Color = Colors.Black;
     }
 }
Пример #6
0
 /// <summary>
 /// Sends the stroke.
 /// </summary>
 /// <param name="boardId">The board identifier.</param>
 /// <param name="stroke">The stroke.</param>
 public void SendStroke(Guid boardId, System.Windows.Ink.Stroke stroke)
 {
     InvokeHubDependantAction(() =>
                              SendStrokes(boardId, new System.Windows.Ink.StrokeCollection()
     {
         stroke
     }));
 }
Пример #7
0
        /// <summary>
        /// Create a stroke from an InkStroke. Used when adding the stroke.
        /// </summary>
        /// <param name="stroke"></param>
        /// <param name="dtGuid"></param>
        /// <param name="SAMPLE_RATE"></param>
        public Stroke(System.Windows.Ink.Stroke stroke, Guid dtGuid, float SAMPLE_RATE)
            : this()
        {
            // Get the timestamp for the function using a const Guid
            ulong theTime;

            if (stroke.ContainsPropertyData(dtGuid))
            {
                // MIT file format
                ulong fileTime = (ulong)stroke.GetPropertyData(dtGuid);
                theTime = (fileTime - 116444736000000000) / 10000;
            }
            else
            {
                theTime = ((ulong)DateTime.Now.ToFileTime() - 116444736000000000) / 10000;
            }

            // Set time data for each point and add it to the list of substroke's points
            List <Point> pointsToAdd = new List <Point>();

            System.Windows.Input.StylusPointCollection stylusPoints = stroke.StylusPoints;
            int numPoints = stylusPoints.Count;

            for (int i = 0; i < numPoints; i++)
            {
                // We believe this to be the standard sample rate.  The multiplication by 1,000 is to convert from
                // seconds to milliseconds.
                //
                // Our time is in the form of milliseconds since Jan 1, 1970
                //
                // NOTE: The timestamp for the stroke is made WHEN THE PEN IS LIFTED
                System.Windows.Input.StylusPoint styPoint = stylusPoints[i];
                ulong adjustedTime = theTime - (ulong)((1 / SAMPLE_RATE * 1000) * (numPoints - i));
                Point toAdd        = new Point((float)styPoint.X, (float)styPoint.Y, (float)styPoint.PressureFactor, Convert.ToUInt64(adjustedTime), "point");
                // HACK: Add back in if debugging: if (!pointsToAdd.Contains(toAdd))
                pointsToAdd.Add(toAdd);
            }

            // Create the new substroke using its drawing attributes
            System.Windows.Ink.DrawingAttributes drawingAttributes = stroke.DrawingAttributes;
            Substroke substroke = new Substroke(pointsToAdd);

            substroke.Name      = "substroke";
            substroke.Color     = drawingAttributes.Color.GetHashCode();
            substroke.PenTip    = drawingAttributes.StylusTip.ToString();
            substroke.PenWidth  = (float)drawingAttributes.Width;
            substroke.PenHeight = (float)drawingAttributes.Height;
            substroke.Source    = "InkSketch.canvasStrokeToSketchStroke";
            substroke.Start     = pointsToAdd[0].Id;
            substroke.End       = pointsToAdd[pointsToAdd.Count - 1].Id;
            this.AddSubstroke(substroke);

            // Update the stroke's attributes
            this._xmlAttributes.Name   = "stroke";
            this._xmlAttributes.Time   = (ulong)theTime;
            this._xmlAttributes.Type   = "stroke";
            this._xmlAttributes.Source = "Converter";
        }
 private void SandyCanvas_OnTouchDown(object sender, TouchEventArgs e)
 {
     var touchPoint = e.GetTouchPoint(this);
     var point = touchPoint.Position;
     System.Windows.Ink.Stroke newStroke = new System.Windows.Ink.Stroke(new StylusPointCollection(new List<Point> { point }), SandyCanvas.DefaultDrawingAttributes);
     if (!myStrokes.ContainsKey(touchPoint.TouchDevice.Id))
     {
         myStrokes.Add(touchPoint.TouchDevice.Id, newStroke);
         SandyCanvas.Strokes.Add(newStroke);
     }
 }
Пример #9
0
        /// <summary>
        /// Displays the classification of each stroke- wire, shape or label
        /// </summary>
        public void displayClassification(Dictionary <string, System.Windows.Media.Color> colorCode)
        {
            foreach (Sketch.Substroke substroke in panel.InkSketch.Sketch.Substrokes)
            {
                String mstrokeId = panel.InkSketch.GetInkStrokeBySubstrokeId(substroke.Id);
                System.Windows.Ink.Stroke mstroke = panel.InkSketch.GetInkStrokeById(mstrokeId);
                mstroke.DrawingAttributes.Color = colorCode[substroke.Classification];
            }

            panel.InkCanvas.InvalidateVisual();
            panel.UpdateLayout();
        }
Пример #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="stroke"></param>
        /// <param name="strokeKind"></param>
        /// <param name="language"></param>
        /// <returns></returns>
        public long AddStroke(
            System.Windows.Ink.Stroke stroke,
            InkStrokeKind strokeKind = InkStrokeKind.Unknown,
            string language          = null)
        {
            var points   = stroke.StylusPoints;
            var strokeId = _strokeCounter;

            var inkRecognizerStroke = new InkRecognizerStroke(points, dpiX, dpiY, strokeId);

            inkRecognizerStroke.Kind     = strokeKind;
            inkRecognizerStroke.Language = language;

            _strokes.Add(inkRecognizerStroke.GetNativeStroke());

            _strokeCounter++;
            return(inkRecognizerStroke.Id);
        }
Пример #11
0
        /// <summary>
        /// Converts a board point collection into a stroke.
        /// </summary>
        /// <param name="bpc">The BPC.</param>
        /// <returns>A stroke created from the given board point collection.</returns>
        private System.Windows.Ink.Stroke GetStroke(BoardPointCollection bpc)
        {
            System.Windows.Input.StylusPointCollection spc = new System.Windows.Input.StylusPointCollection();

            bpc.Points.ForEach(point =>
            {
                spc.Add(new System.Windows.Input.StylusPoint(point.X, point.Y, point.PressureFactor));
            });
            var stroke = new System.Windows.Ink.Stroke(spc, new System.Windows.Ink.DrawingAttributes()
            {
                Color = (Color)ColorConverter.ConvertFromString(bpc.Color)
            });

            stroke.AddPropertyData(bpc.ID, bpc.User);
            stroke.DrawingAttributes.Height = bpc.BrushHeight;
            stroke.DrawingAttributes.Width  = bpc.BrushWidth;
            return(stroke);
        }
Пример #12
0
        public void OnStrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e)
        {
            System.Windows.Ink.Stroke s = e.Stroke;
            if (mode == DrawingMode.RECT)
            {
                StrokeRectConvert(s);
            }
            else if (mode == DrawingMode.CIRCLE)
            {
                StrokeCircleConvert(s);
            }
            else if (mode == DrawingMode.ARROW)
            {
                StrokeArrowConvert(s);
            }

            //otherwise we do nothing as the stroke is added "as is".
        }
Пример #13
0
 public void displayValidity(Dictionary <Sketch.Shape, bool> validity)
 {
     foreach (Sketch.Shape shape in panel.InkSketch.Sketch.Shapes)
     {
         System.Windows.Media.Color shapecolor = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("Red");
         if (validity[shape])
         {
             shapecolor = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("Green");
         }
         foreach (Sketch.Substroke substroke in shape.SubstrokesL)
         {
             String mstrokeId = panel.InkSketch.GetInkStrokeBySubstrokeId(substroke.Id);
             System.Windows.Ink.Stroke mstroke = panel.InkSketch.GetInkStrokeById(mstrokeId);
             mstroke.DrawingAttributes.Color = shapecolor;
         }
     }
     panel.InkCanvas.InvalidateArrange();
     panel.UpdateLayout();
 }
Пример #14
0
        /// <summary>
        /// Displays the grouping of the strokes.
        /// </summary>
        public void displayGroups()
        {
            Random colorPicker = new Random();

            foreach (Sketch.Shape shape in panel.InkSketch.Sketch.Shapes)
            {
                Byte[] colorValues = new Byte[4];
                colorPicker.NextBytes(colorValues);
                System.Windows.Media.Color shapecolor = System.Windows.Media.Color.FromArgb(colorValues[0], colorValues[1], colorValues[2], colorValues[3]);
                foreach (Sketch.Substroke substroke in shape.SubstrokesL)
                {
                    String mstrokeId = panel.InkSketch.GetInkStrokeBySubstrokeId(substroke.Id);
                    System.Windows.Ink.Stroke mstroke = panel.InkSketch.GetInkStrokeById(mstrokeId);
                    mstroke.DrawingAttributes.Color = shapecolor;
                }
            }
            panel.InkCanvas.InvalidateVisual();
            panel.UpdateLayout();
        }
Пример #15
0
        private void StrokeRectConvert(System.Windows.Ink.Stroke stroke)
        {
            StylusPointCollection ptsRect = new StylusPointCollection();
            StylusPointCollection pts     = stroke.StylusPoints;

            double minX = double.MaxValue;
            double minY = minX;
            double maxX = double.MinValue;
            double maxY = maxX;

            //find bounding area
            foreach (StylusPoint pt in pts)
            {
                if (pt.X > maxX)
                {
                    maxX = pt.X;
                }
                if (pt.X < minX)
                {
                    minX = pt.X;
                }

                if (pt.Y > maxY)
                {
                    maxY = pt.Y;
                }
                if (pt.Y < minY)
                {
                    minY = pt.Y;
                }
            }
            //stroke four corners of the rect
            ptsRect.Add(new StylusPoint(minX, minY));
            ptsRect.Add(new StylusPoint(minX, maxY));
            ptsRect.Add(new StylusPoint(maxX, maxY));
            ptsRect.Add(new StylusPoint(maxX, minY));
            ptsRect.Add(new StylusPoint(minX, minY));
            stroke.StylusPoints = ptsRect;

            //no smoothing
            stroke.DrawingAttributes.FitToCurve = false;
        }
Пример #16
0
        /// <summary>
        /// Gets the board point collection.  This allows serializable messages to be sent to the server.
        /// </summary>
        /// <param name="stroke">The stroke.</param>
        /// <returns>A new board point collection.</returns>
        private BoardPointCollection GetBoardPointCollection(System.Windows.Ink.Stroke stroke)
        {
            var bpc = new BoardPointCollection();

            bpc.Color = stroke.DrawingAttributes.Color.ToString();
            var customProperties = stroke.GetPropertyDataIds();

            bpc.ID          = customProperties.First();
            bpc.User        = stroke.GetPropertyData(customProperties.First()).ToString();
            bpc.BrushWidth  = stroke.DrawingAttributes.Width;
            bpc.BrushHeight = stroke.DrawingAttributes.Height;
            stroke.StylusPoints.ToList().ForEach(point =>
            {
                bpc.Points.Add(new BoardPoint()
                {
                    X = point.X,
                    Y = point.Y,
                    PressureFactor = point.PressureFactor
                });
            });
            return(bpc);
        }
Пример #17
0
        /// <summary>
        /// Displays a Deselection Handle over the stroke
        /// </summary>
        private Popup makeDeselectionHandle(System.Windows.Ink.Stroke s)
        {
            Popup handle = new Popup();

            System.Windows.Shapes.Rectangle handleShape = new System.Windows.Shapes.Rectangle();
            // Set the width and height of the rectangle
            int width  = HANDLE_WIDTH;
            int height = (int)s.GetBounds().Height / 2;

            if (height < MINIMUM_HANDLE_HEIGHT)
            {
                height = MINIMUM_HANDLE_HEIGHT;
            }
            if (height > MAXIMUM_HANDLE_HEIGHT)
            {
                height = MAXIMUM_HANDLE_HEIGHT;
            }

            handleShape.Width  = width;
            handleShape.Height = height;

            handleShape.Fill = HANDLE_DESELECT_COLOR;
            handle.Child     = handleShape;
            // Find location based on stroke bounds
            System.Windows.Point point = new System.Windows.Point(s.GetBounds().X + s.GetBounds().Width / 2, s.GetBounds().Y + s.GetBounds().Height / 2);
            handle.PlacementRectangle = new System.Windows.Rect(point, new System.Windows.Size(width, height));
            handle.Placement          = PlacementMode.Top;
            handle.Placement          = PlacementMode.Left;

            // Create event for selection
            sketchPanel.InkCanvas.Children.Add(handle);
            handle.MouseEnter += new MouseEventHandler(addToSelection);

            // Set image and bring into view
            handle.Visibility = System.Windows.Visibility.Visible;
            handle.IsOpen     = true;

            return(handle);
        }
Пример #18
0
        public void ColorStrokesByType(List <Sketch.Substroke> substrokes)
        {
            if (!coloringOn)
            {
                ClearColors();
                return;
            }

            if (this.panel.InkSketch.Sketch != null)
            {
                foreach (Sketch.Substroke substroke in substrokes)
                {
                    Domain.ShapeType label = substroke.Type;

                    Color color = label.Color;

                    System.Windows.Ink.Stroke stroke = panel.InkSketch.GetInkStrokeBySubstroke(substroke);
                    stroke.DrawingAttributes.Color = color;
                }
                panel.InkCanvas.InvalidateVisual();
                panel.InkCanvas.UpdateLayout();
            }
        }
Пример #19
0
        private void StrokeCircleConvert(System.Windows.Ink.Stroke stroke)
        {
            //Console.WriteLine("Stroke Completed");
            double toRadians = Math.PI / 180.0;
            StylusPointCollection ptsRect = new StylusPointCollection();
            StylusPointCollection pts     = stroke.StylusPoints;

            //rather that try to redraw the circle, consider a diagonal line as indicator of circle center and diameter
            StylusPoint ptStart  = pts[0];
            StylusPoint ptEnd    = pts[pts.Count - 1];
            StylusPoint ptCenter = new StylusPoint((ptStart.X + ptEnd.X) / 2.0, (ptStart.Y + ptEnd.Y) / 2.0);

            double deltaX = ptEnd.X - ptCenter.X;
            double deltaY = ptEnd.Y - ptCenter.Y;
            double radius = Math.Sqrt(deltaX * deltaX + deltaY * deltaY);

            for (double theta = 0; theta <= 360.0; theta += 10.0)
            {
                double angle = theta * toRadians;
                ptsRect.Add(new StylusPoint(ptCenter.X + radius * Math.Cos(angle), ptCenter.Y + radius * Math.Sin(angle)));
            }
            stroke.StylusPoints = ptsRect;
            stroke.DrawingAttributes.FitToCurve = false;
        }
Пример #20
0
 /// <summary>
 /// Sends the stroke to erase.
 /// </summary>
 /// <param name="stroke">The stroke.</param>
 public void SendStrokeToErase(System.Windows.Ink.Stroke stroke, Guid boardId)
 {
     InvokeHubDependantAction(() => _hubProxy.Invoke("SendStrokeToErase", JsonConvert.SerializeObject(GetBoardPointCollection(stroke)), boardId));
 }
 public InkCanvasStrokeCollectedEventArgs(System.Windows.Ink.Stroke stroke)
 {
 }
 private static bool CheckPointNearby(System.Windows.Ink.Stroke stroke, Point point)
 {
     return stroke.StylusPoints.Any(p => (Math.Abs(p.X - point.X) <= 1) && (Math.Abs(p.Y - point.Y) <= 1));                
 }
 public void Add(System.Windows.Ink.Stroke s)
 {
     sketchPanel.InkCanvas.GetSelectedStrokes().Add(s);
 }
 private void Remove(System.Windows.Ink.Stroke s)
 {
     sketchPanel.InkCanvas.GetSelectedStrokes().Remove(s);
 }
        private void CreateNewPath(InkCanvas drawingCanvas, string id, Color fill, double width, double height, bool isHighlighter, float pressure, double x, double y)
        {
            this.Dispatcher.Invoke(
                new Action(
                    delegate()
                    {
                        this._strokeIDs.Add(id, drawingCanvas.Strokes.Count);

                        StylusPoint point = new StylusPoint();
                        point.X = x;
                        point.Y = y;
                        point.PressureFactor = pressure;

                        StylusPointCollection collection = new StylusPointCollection();
                        collection.Add(point);

                        System.Windows.Ink.Stroke stroke = new System.Windows.Ink.Stroke(collection);
                        fill.A = 192;
                        stroke.DrawingAttributes.Color = fill;
                        stroke.DrawingAttributes.Width = width;
                        stroke.DrawingAttributes.Height = height;
                        stroke.DrawingAttributes.IsHighlighter = isHighlighter;

                        drawingCanvas.Strokes.Add(stroke);
                    }
            ));
        }