Пример #1
0
        public void Duplicate()
        {
            if (SelectedStrokesIds.Count > 0)
            {
                Clipboard = new StrokeList(SelectedStrokes);
            }

            if (Clipboard == null)
            {
                return;
            }

            SelectionChanged?.Invoke(new StrokeList());

            var copiedStrokes     = new StrokeList();
            var translationMatrix = Constants.DuplicationTransform;
            var offset            = 0;

            foreach (var s in Clipboard.OrderBy(x => (x as StrokeModel)?.CreatedDate))
            {
                var strokeModel = new StrokeModel(s.Clone(), UserId);
                strokeModel.CreatedDate = strokeModel.CreatedDate.AddMilliseconds(offset++);
                strokeModel.Transform(translationMatrix, false);
                copiedStrokes.Add(strokeModel);
            }

            Strokes.Add(new StrokeCollection(copiedStrokes));
            SelectionChanged?.Invoke(copiedStrokes);
            EditingMode = InkCanvasEditingMode.Select;
        }
        public void UpdateStroke(string id, StrokeModel stroke)
        {
            if (stroke != null)
            {
                stroke.AuthorId             = AuthService.CurrentUser?.Id ?? AuthService.OfflineClientId;
                stroke.LastModificationDate = DateTime.Now;
                Logger.Debug($"Adding stroke ${id}");
                if (IsOffline)
                {
                    StrokesMap[id] = stroke;
                }
            }
            else
            {
                Logger.Debug($"Removing stroke ${id}");
                if (IsOffline)
                {
                    StrokeModel _;
                    StrokesMap.TryRemove(id, out _);
                }
            }

            StrokesToUpdate[id]    = stroke;
            StrokesMapOverride[id] = stroke;

            if (IsOffline)
            {
                StrokesUpdated?.Invoke();
            }
        }
Пример #3
0
        private bool IsSelectedByOtherUser(StrokeModel stroke)
        {
            string strokeOwnerId = null;

            DrawingModel?.SelectedStrokes?.TryGetValue(stroke.Id, out strokeOwnerId);

            return(strokeOwnerId != null && strokeOwnerId != UserId);
        }
Пример #4
0
        public void OnStrokesChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (IsRefreshingStrokes)
            {
                return;
            }

            lock (StrokesLock)
            {
                if (e.OldItems != null && e.OldItems.Count > 0)
                {
                    foreach (Stroke s in e.OldItems)
                    {
                        var stroke = s as StrokeModel;
                        if (stroke == null)
                        {
                            continue;
                        }

                        StrokeCollection.UpdateStroke(stroke.Id, null);
                    }
                }

                if (e.NewItems != null && e.NewItems.Count > 0)
                {
                    foreach (Stroke s in e.NewItems)
                    {
                        var stroke = s as StrokeModel;
                        if (stroke == null)
                        {
                            stroke = new StrokeModel(s, UserId);
                        }
                        else
                        {
                            stroke.Id = Guid.NewGuid().ToString();
                        }

                        StrokeCollection.UpdateStroke(stroke.Id, stroke);
                    }
                }

                // Erasing the last stroke is considered like a Reset action.
                if (e.Action == NotifyCollectionChangedAction.Reset)
                {
                    foreach (StrokeModel stroke in StrokeCollection.GetMergedStrokeMaps())
                    {
                        StrokeCollection.UpdateStroke(stroke.Id, null);
                    }
                }
            }
        }