예제 #1
0
 public void UpdateStroke(uint id, InkStroke newInkStroke)
 {
     if (StrokeMap.ContainsKey(id))
     {
         StrokeMap[id] = newInkStroke;
     }
 }
예제 #2
0
        public IReadOnlyList <uint> AddStrokes(IReadOnlyList <InkStroke> inkStrokes)
        {
            var strokeIds     = new List <uint>();
            var strokeIdArray = new uint[inkStrokes.Count];

            if (inkStrokes.Count == 0)
            {
                return(strokeIds.AsReadOnly());
            }

            // Duplicate list.
            var strokesToAdd = inkStrokes.ToList();

            // Keep a second copy that we can search through.
            var inkStrokesSearchList = inkStrokes.ToList();

            // First search through existing strokes.
            foreach (var pair in StrokeMap)
            {
                var index = strokesToAdd.FindIndex(stroke => stroke == pair.Value);
                if (index >= 0)
                {
                    strokesToAdd.RemoveAt(index);

                    var index2 = inkStrokesSearchList.FindIndex(stroke => stroke == pair.Value);
                    if (index2 >= 0)
                    {
                        strokeIdArray[index2] = pair.Key;
                    }
                }
            }

            // Add remaining strokes.
            foreach (var stroke in strokesToAdd)
            {
                uint newId = TotalStrokeCount;
                ++TotalStrokeCount;
                StrokeMap.Add(newId, stroke);
                RefCountMap.Add(newId, 0);

                var index = inkStrokesSearchList.FindIndex(listStroke => listStroke == stroke);
                if (index >= 0)
                {
                    strokeIdArray[index] = newId;
                }
            }

            // Ensure stroke order is identical.
            for (uint i = 0; i < inkStrokes.Count; i++)
            {
                strokeIds.Add(strokeIdArray[i]);
            }

            return(strokeIds.AsReadOnly());
        }
예제 #3
0
 public InkStroke GetStroke(uint id)
 {
     try
     {
         StrokeMap.TryGetValue(id, out InkStroke stroke);
         return(stroke);
     }
     catch (Exception)
     {
         return(null);
     }
 }
예제 #4
0
        public uint AddStroke(InkStroke inkStroke)
        {
            if (StrokeMap.ContainsValue(inkStroke))
            {
                return(StrokeMap.FirstOrDefault(x => x.Value == inkStroke).Key);
            }

            // Add new stroke.
            var newId = TotalStrokeCount;

            ++TotalStrokeCount;
            StrokeMap.Add(newId, inkStroke);
            RefCountMap.Add(newId, 0);
            return(newId);
        }
예제 #5
0
        public void RemoveRef(uint strokeId)
        {
            if (RefCountMap.ContainsKey(strokeId))
            {
                var currentRef = RefCountMap[strokeId];

                if (currentRef <= 1)
                {
                    RefCountMap.Remove(strokeId);
                    StrokeMap.Remove(strokeId);
                }
                else
                {
                    RefCountMap[strokeId]--;
                }
            }
        }
예제 #6
0
 public void Clear()
 {
     StrokeMap.Clear();
     RefCountMap.Clear();
     TotalStrokeCount = 0;
 }