Exemplo n.º 1
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 Service_StrokeUpdated(object sender, StrokeUpdatedEventArgs e)
        {
            var pathPart = e.PathPart;
            var data     = pathPart.Data.GetEnumerator();

            //Data is stored XYW
            float x = -1;
            float y = -1;
            float w = -1;

            if (data.MoveNext())
            {
                x = data.Current;
            }

            if (data.MoveNext())
            {
                y = data.Current;
            }

            if (data.MoveNext())
            {
                //Clamp to 0.0 -> 1.0
                w = Math.Max(0.0f, Math.Min(1.0f, (data.Current - 1.0f) * pFactor));
            }

            var point = new System.Windows.Input.StylusPoint(x * m_scale, y * m_scale, w);

            if (m_addNewStrokeToModel)
            {
                m_addNewStrokeToModel = false;
                var points = new System.Windows.Input.StylusPointCollection();
                points.Add(point);

                var stroke = new Stroke(points);
                stroke.DrawingAttributes = m_DrawingAttributes;

                Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                {
                    _strokes.Add(stroke);
                }));
            }
            else
            {
                Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                {
                    _strokes[_strokes.Count - 1].StylusPoints.Add(point);
                }));
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="sketch">SketchPanel to add a label to</param>
        /// <param name="inkStrokes">InkOverlay strokes</param>
        /// <param name="inkStrokes">A StrokeCollection strokes</param>
        /// <param name="label">Label to apply</param>
        /// <param name="domainInfo">DomainInfo for our Labeler</param>
        public EndPointMoveCmd(InkToSketchWPF.InkCanvasSketch inkSketch, Sketch.EndPoint oldLoc, Point newLoc, Stroke attachedStroke, Sketch.Shape shapeAtNewLoc)
        {
            isUndoable            = true;
            this.inkSketch        = inkSketch;
            oldLocation           = oldLoc;
            newLocation           = newLoc;
            this.attachedStroke   = attachedStroke;
            this.shapeAtNewLoc    = shapeAtNewLoc;
            this.changedShape     = inkSketch.GetSketchSubstrokeByInk(attachedStroke).ParentShape;
            oldInternalConnection = changedShape.ConnectedShapes.Contains(changedShape);
            newIsWire             = Domain.LogicDomain.IsWire(shapeAtNewLoc.Type);
            substrokesInNewShape  = shapeAtNewLoc.SubstrokesL;

            // Make a new stroke comprising 100 points along the straight line between oldLocation and newLocation
            System.Windows.Input.StylusPointCollection line = new System.Windows.Input.StylusPointCollection();
            for (double m = 0; m <= 1; m += 0.01)
            {
                double midX = oldLocation.X + m * (newLocation.X - oldLocation.X);
                double midY = oldLocation.Y + m * (newLocation.Y - oldLocation.Y);
                line.Add(new System.Windows.Input.StylusPoint(midX, midY));
            }
            this.newStroke = new Stroke(line);
        }
Exemplo n.º 5
0
 public void Add(System.Windows.Input.StylusPointCollection stylusPoints)
 {
 }
Exemplo n.º 6
0
 public StylusPointsReplacedEventArgs(System.Windows.Input.StylusPointCollection newStylusPoints, System.Windows.Input.StylusPointCollection previousStylusPoints)
 {
 }
Exemplo n.º 7
0
 public Stroke(System.Windows.Input.StylusPointCollection stylusPoints)
 {
 }
Exemplo n.º 8
0
 public Stroke(System.Windows.Input.StylusPointCollection stylusPoints, DrawingAttributes drawingAttributes)
 {
 }
Exemplo n.º 9
0
 protected virtual new void OnDraw(System.Windows.Media.DrawingContext drawingContext, System.Windows.Input.StylusPointCollection stylusPoints, System.Windows.Media.Geometry geometry, System.Windows.Media.Brush fillBrush)
 {
 }
Exemplo n.º 10
0
 public virtual new void Reset(System.Windows.Input.StylusDevice stylusDevice, System.Windows.Input.StylusPointCollection stylusPoints)
 {
 }