AddStroke() public method

public AddStroke ( [ stroke ) : void
stroke [
return void
示例#1
0
 public async Task saveInking(int pageNumber, InkStrokeContainer inkStrokeContainer = null)
 {
     InkStrokeContainer container = new InkStrokeContainer();
     List<InkStroke> inAppStrokes = new List<InkStroke>();
     inAppInkStrokes.TryGetValue(pageNumber, out inAppStrokes);
     foreach (InkStroke inkStroke in inAppStrokes)
     {
         container.AddStroke(inkStroke.Clone());
     }
     await inAppInking.saveInking(pageNumber, container);
     // TODO: Save removed ink strokes
 }
        /// <summary>
        /// Save the model (family and their notes) to the app's isolated storage
        /// </summary>
        /// <remarks>
        /// The data format for notes data:
        /// 
        ///     Serialized model data (the people and the sticky notes)
        ///     For each sticky note
        ///     {
        ///         int32 number of inkstrokes for the note
        ///     }
        ///     All ink stroke data (for all notes) combined into one container
        /// </remarks>
        /// <returns></returns>
        public async Task SaveModelAsync()
        {
            // Persist the model
            StorageFile notesDataFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(NOTES_MODEL_FILE, CreationCollisionOption.ReplaceExisting);
            using (Stream notesDataStream = await notesDataFile.OpenStreamForWriteAsync())
            {
                // Serialize the model which contains the people and the stickyNote collection
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Model));
                serializer.WriteObject(notesDataStream, Model);
            }

            /* For each sticky note, save the number of inkstrokes it contains.
               The function on the InkStrokeContainer that persists its contents is not designed
               to save persist containers to the one stream. We also don't want to manage one
               backing file per note. So combine the ink strokes into one container and persist that.
               We'll seperate out the ink strokes to the right ink control by keeping track of how
               many ink strokes belongs to each note */

            InkStrokeContainer CombinedStrokes = new InkStrokeContainer();
            StorageFile inkFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(NOTES_INK_FILE, CreationCollisionOption.ReplaceExisting);
            using (var randomAccessStream = await inkFile.OpenAsync(FileAccessMode.ReadWrite))
            {
                using (IOutputStream inkStream = randomAccessStream.GetOutputStreamAt(0)) // DataWriter requires an IOutputStream
                {
                    bool combinedStrokesHasContent = false; // whether we had any ink to save across all of the notes
                    DataWriter writer = new DataWriter(inkStream);
                    foreach (StickyNote Note in Model.StickyNotes)
                    {
                        // Save # strokes for this note
                        if (Note.Ink != null && Note.Ink.GetStrokes().Count > 0)
                        {
                            IReadOnlyList<InkStroke> InkStrokesInNote = Note.Ink.GetStrokes();
                            writer.WriteInt32(InkStrokesInNote.Count);
                            // capture the ink strokes into the combined container which will be saved at the end of the notes data file
                            foreach (InkStroke s in InkStrokesInNote)
                            {
                                CombinedStrokes.AddStroke(s.Clone());
                            }
                            combinedStrokesHasContent = true;
                        }
                        else
                        {
                            writer.WriteInt32(0); // not all notes have ink
                        }
                    }
                    await writer.StoreAsync(); // flush the data in the writer to the inkStream

                    // Persist the ink data
                    if (combinedStrokesHasContent ) 
                    {
                        await CombinedStrokes.SaveAsync(inkStream);
                    }
                }
            }
        }
 public void SyncStrokeEx(Dictionary<InkStroke,double> strokes, InkStrokeContainer containner, double currentCanvasWidth,bool forcrRefresh = false)
 {
     lock(locker)
     {
         if(strokes.Count > containner.GetStrokes().Count)
         {
             foreach (var item in strokes)
             {
                 bool exist = false;
                 foreach (var itemInner in containner.GetStrokes())
                 {
                     InkStroke strokeCopy = itemInner.Clone();
                     strokeCopy.PointTransform = System.Numerics.Matrix3x2.CreateScale(1f);
                     if (InkHelper.SameInkStroke(item.Key, strokeCopy))
                     {
                         exist = true;
                         break;
                     }
                 }
                 if (!exist)
                 {
                     foreach(var itemMp in StrokeMapping)
                     {
                         if(InkHelper.SameInkStroke(item.Key,itemMp.Key) && item.Value == itemMp.Value)
                         {
                             StrokeMapping.Remove(itemMp.Key);
                             break;
                         }
                     }                           
                 }
             }
         }
         else if(strokes.Count < containner.GetStrokes().Count)
         {
             InkStroke stroke = containner.GetStrokes()[containner.GetStrokes().Count - 1].Clone();
             StrokeMapping.Add(stroke.Clone(),currentCanvasWidth);
         }
         else
         {
             if(strokes.Count == StrokeMapping.Count && !forcrRefresh)
             {
                 return;
             }
         }
         strokes.Clear();
         containner.Clear();
         foreach(var item in StrokeMapping)
         {
             InkStroke stroke = item.Key.Clone();
             strokes.Add(stroke.Clone(), item.Value);
             stroke.PointTransform = System.Numerics.Matrix3x2.CreateScale((float)(currentCanvasWidth / item.Value));
             containner.AddStroke(stroke.Clone());
         }
         //if(read)
         //{
         //    strokes.Clear();
         //    foreach(var item in StrokeMapping)
         //    {
         //        strokes.Add(item.Key.Clone(),item.Value);
         //    }
         //}
         //else
         //{
         //    StrokeMapping.Clear();
         //    foreach(var item in strokes)
         //    {
         //        StrokeMapping.Add(item.Key.Clone(),item.Value);
         //    }
         //}
     }
 }
        public void SyncStroke(InkStrokeContainer containner,double currentCanvasWidth,bool syncAll = true, InkStroke stroke = null)
        {
            lock(locker)
            {
                try
                {
                    if (syncAll)
                    {
                        Strokes.Clear();
                        foreach (var item in containner.GetStrokes())
                        {
                            InkStroke strokeClone = item.Clone();
                            strokeClone.PointTransform = System.Numerics.Matrix3x2.CreateScale((float)(currentCanvasWidth / originalCanvasWidth));
                            Strokes.Add(strokeClone);
                        }
                    }
                    else
                    {
                        if (null != stroke)
                        {
                            InkStroke strokeClone = stroke.Clone();
                            strokeClone.PointTransform = System.Numerics.Matrix3x2.CreateScale((float)(currentCanvasWidth / originalCanvasWidth));
                            Strokes.Add(strokeClone);
                        }
                        else
                        {
                            containner.Clear();
                            foreach (var item in Strokes)
                            {
                                InkStroke strokeClone = item.Clone();
                                strokeClone.PointTransform = System.Numerics.Matrix3x2.CreateScale((float)(currentCanvasWidth / originalCanvasWidth));
                                containner.AddStroke(strokeClone);
                            }
                        }
                    }
                }
                catch(Exception e)
                {
#if DEBUG
                    System.Diagnostics.Debug.WriteLine(e.Message);

#endif
                }                           
            }
        }