/// <summary> /// Add a new decorator to an element /// </summary> /// <param name="paintBase">element to be decorated</param> private async Task AddNewDecorator(PaintBase paintBase) { // Open dialog DecoratorDialog dialog = new DecoratorDialog(); ContentDialogResult result = await dialog.ShowAsync(); if (result == ContentDialogResult.Primary) { ReplaceShapelistEntry(paintBase, CreateNewTextDecoration(paintBase, dialog.Decoration, dialog.Position)); } }
/// <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(); } }