Exemple #1
0
        /// <inheritdoc />
        public Task PointerPressedExecuteAsync()
        {
            // Add entry to UndoStack
            UndoStack.Push(ShapeList.DeepCopy());
            RedoStack.Clear();

            // Set pointer starting point
            _pointerStart = PointerEventArgs.GetCurrentPoint(Canvas).Position;


            // Create new shape
            PaintBase shape = new PaintShape(ShapeType);

            shape.X = _pointerStart.X;
            shape.Y = _pointerStart.Y;

            shape.Width  = 2;
            shape.Height = 2;

            ShapeList.Add(shape);
            current = shape;

            _page.Draw();
            _page.UpdateList();

            return(Task.CompletedTask);
        }
        /// <inheritdoc />
        public Task PointerReleasedExecuteAsync()
        {
            double x    = (double)selectorSquare.GetValue(Canvas.LeftProperty);
            double y    = (double)selectorSquare.GetValue(Canvas.TopProperty);
            double xMax = x + selectorSquare.Width;
            double yMax = y + selectorSquare.Height;

            // Find what elements are in the selector square
            foreach (PaintBase paintBase in ShapeList)
            {
                double eX    = paintBase.X;
                double eY    = paintBase.Y;
                double eXMax = eX + paintBase.Width;
                double eYMax = eY + paintBase.Height;

                // Check if paintBase is within the selector square
                if (((eX > x && eX < xMax) && (eY > y && eY < yMax)) &&
                    ((eXMax > x && eXMax < xMax) && (eYMax > y && eYMax < yMax)))
                {
                    paintBase.Selected = true;
                }
            }

            // Delete selector square
            Canvas.Children.Remove(selectorSquare);
            selectorSquare = null;

            _page.UpdateList();
            _page.Draw();

            return(Task.CompletedTask);
        }
Exemple #3
0
        /// <inheritdoc />
        public async Task ExecuteUserActionAsync()
        {
            var openPicker = new FileOpenPicker();

            openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            openPicker.FileTypeFilter.Add(".json");
            openPicker.ViewMode = PickerViewMode.List;

            StorageFile file = await openPicker.PickSingleFileAsync();

            if (file != null)
            {
                string jsonString = await FileIO.ReadTextAsync(file);

                List <PaintBase> newShapeList = DeserializeJsonSave(jsonString);

                // Clear undo, redo and master list
                UndoStack.Clear();
                RedoStack.Clear();
                ShapeList.Clear();
                // Add deserialized master list to main page
                ShapeList.AddRange(newShapeList);

                // Send draw and update list commands to main page
                _page.Draw();
                _page.UpdateList();
            }
        }
Exemple #4
0
        /// <inheritdoc />
        public Task ExecuteUserActionAsync()
        {
            if (UndoStack.Count > 0)
            {
                List <PaintBase> newState = UndoStack.Pop();
                RedoStack.Push(ShapeList.DeepCopy());

                ShapeList.Clear();
                ShapeList.AddRange(newState);

                _page.Draw();
                _page.UpdateList();
            }

            return(Task.CompletedTask);
        }
Exemple #5
0
        /// <inheritdoc />
        public Task ExecuteUserActionAsync()
        {
            // Get all selected elements that are of the type PaintGroup
            List <PaintBase> selected = ShapeList.Where(pb => pb.Selected &&
                                                        !(pb is PaintShape) &&
                                                        (pb is PaintGroup || (pb as TextDecoration).InnerPaintBase is PaintGroup)).ToList();

            // Only run if 1 or more groups are selected
            if (selected.Count > 0)
            {
                // Add undo entry to the undo stack
                UndoStack.Push(ShapeList.DeepCopy());
                RedoStack.Clear();

                foreach (PaintBase paintBase in selected)
                {
                    PaintBase element = paintBase;
                    // Check if element is wrapped in a decorator
                    if (element is TextDecoration decor)
                    {
                        // If so, get inner group
                        element = decor.GetDrawable();
                    }

                    if (element is PaintGroup group)
                    {
                        // Remove group from canvas
                        ShapeList.Remove(paintBase);

                        // Add the groups children back onto the canvas
                        foreach (PaintBase groupChild in group.Children.ToList())
                        {
                            group.Remove(groupChild);
                            ShapeList.Add(groupChild);
                        }
                    }
                }

                _page.Draw();
                _page.UpdateList();
            }

            return(Task.CompletedTask);
        }
Exemple #6
0
        /// <inheritdoc />
        public Task ExecuteUserActionAsync()
        {
            // Add undo entry
            UndoStack.Push(ShapeList.DeepCopy());
            RedoStack.Clear();

            // Get selected items
            List <PaintBase> selected = ShapeList.Where(pb => pb.Selected).ToList();

            foreach (PaintBase paintBase in selected)
            {
                ShapeList.Remove(paintBase);
            }

            _page.Draw();
            _page.UpdateList();

            return(Task.CompletedTask);
        }
Exemple #7
0
        /// <inheritdoc />
        public Task ExecuteUserActionAsync()
        {
            if (RedoStack.Count > 0)
            {
                // Pop prior state from stack
                List <PaintBase> newState = RedoStack.Pop();
                // Push current state onto the undo stack
                UndoStack.Push(ShapeList.DeepCopy());

                // Add prior state as current state
                ShapeList.Clear();
                ShapeList.AddRange(newState);

                _page.Draw();
                _page.UpdateList();
            }

            return(Task.CompletedTask);
        }
Exemple #8
0
        /// <inheritdoc />
        public Task PointerPressedExecuteAsync()
        {
            Point pointer = PointerEventArgs.GetCurrentPoint(Canvas).Position;

            foreach (PaintBase paintBase in ShapeList)
            {
                // Check if the pointer location is withing the paintbase
                if (((pointer.X > paintBase.X) && (pointer.X < paintBase.X + paintBase.Width)) &&
                    ((pointer.Y > paintBase.Y) && (pointer.Y < paintBase.Y + paintBase.Height)))
                {
                    // update selection
                    paintBase.Selected = !paintBase.Selected;

                    break;
                }
            }

            _page.UpdateList();
            _page.Draw();

            return(Task.CompletedTask);
        }
Exemple #9
0
        public Task ExecuteUserActionAsync()
        {
            // Get selected items from ShapeList
            List <PaintBase> selected = ShapeList.Where(pb => pb.Selected).ToList();

            // Only group if 2 or more items are selected
            if (selected.Count > 1)
            {
                // Add undo entry
                UndoStack.Push(ShapeList.DeepCopy());
                RedoStack.Clear();

                // Create new group
                PaintGroup newGroup = new PaintGroup()
                {
                    Selected = true
                };

                // Add selected items to the group
                // Remove selected items from the canvas itself
                foreach (PaintBase paintBase in selected)
                {
                    ShapeList.Remove(paintBase);
                    paintBase.Selected = false;

                    newGroup.Add(paintBase);
                }

                ShapeList.Add(newGroup);

                _page.Draw();
                _page.UpdateList();
            }

            return(Task.CompletedTask);
        }
Exemple #10
0
        /// <inheritdoc />
        public async Task PointerPressedExecuteAsync()
        {
            // Check where the click was executed
            Point pointer = PointerEventArgs.GetCurrentPoint(Canvas).Position;

            // Querry a list of selected items
            List <PaintBase> selected = ShapeList.Where(pb => pb.Selected).ToList();

            // Check
            // if only one item is selected
            if (selected.Count == 1)
            {
                PaintBase paintBase = selected.First();

                // Check if the selected item is a decorator
                if (paintBase is TextDecoration decoration)
                {
                    // Check if a decorator was clicked
                    TextDecoration deco = decoration.GetClickedDecoration(pointer.X, pointer.Y);
                    if (deco != null)
                    {
                        // Create dialog for Decorator editing
                        DecoratorDialog dialog =
                            new DecoratorDialog(deco.DecorationText, deco.GetDecoratorPosition());

                        // When editing add a delete button
                        dialog.SecondaryButtonText = "Delete";

                        ContentDialogResult result = await dialog.ShowAsync();

                        if (result == ContentDialogResult.Primary)
                        {
                            deco.DecorationText = dialog.Decoration;

                            AddUndoEntry();

                            // Check if decorator should be moved
                            if (dialog.Position != GetDecoratorPosition(deco))
                            {
                                TextDecoration newDecoration = decoration.MovePosition(deco, dialog.Position);

                                ReplaceShapelistEntry(decoration, newDecoration);
                            }

                            _page.Draw();
                            _page.UpdateList();

                            // Return to prevent 2 decorations in one action
                            return;
                        }
                        else if (result == ContentDialogResult.Secondary)
                        {
                            AddUndoEntry();

                            PaintBase newElement = decoration.RemoveDecorator(deco);
                            ReplaceShapelistEntry(decoration, newElement);

                            _page.Draw();
                            _page.UpdateList();
                        }
                    }
                }

                // when the item itself is clicked, add a new decorator
                if ((pointer.X > paintBase.X && pointer.X < paintBase.X + paintBase.Width) &&
                    (pointer.Y > paintBase.Y && pointer.Y < paintBase.Y + paintBase.Height))
                {
                    AddUndoEntry();

                    await AddNewDecorator(paintBase);

                    _page.Draw();
                    _page.UpdateList();
                }
            }
            else
            {
                // Show error
                ContentDialog dialog = new ContentDialog()
                {
                    Title           = "Failed adding decorator",
                    Content         = "You may only select one item to add a decorator to",
                    CloseButtonText = "Ok"
                };

                await dialog.ShowAsync();
            }
        }