예제 #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);
        }
예제 #2
0
        /// <summary>
        /// Deserialize paint group
        /// </summary>
        /// <param name="jObject">paintgroup JObject</param>
        /// <param name="baseProps">basic shape properties</param>
        /// <returns>Paintgroup</returns>
        private PaintGroup GetPaintGroup(JObject jObject, PaintBaseProperties baseProps)
        {
            PaintGroup group = new PaintGroup
            {
                Height = baseProps.Height,
                Width  = baseProps.Width,
                X      = baseProps.X,
                Y      = baseProps.Y
            };

            if (jObject.GetValue("children") is JArray children)
            {
                // Deserialize children
                foreach (JToken child in children)
                {
                    if (child is JObject jChild &&
                        Enum.TryParse(jChild.GetValue("type").ToString(), out PaintType type))
                    {
                        PaintBaseProperties deserBase = GetBaseProperties(jChild);

                        if (deserBase != null)
                        {
                            if (type == PaintType.Shape)
                            {
                                PaintShape shape = GetPaintShape(jChild, deserBase);
                                if (shape != null)
                                {
                                    group.Add(AddDecorators(jChild, shape));
                                }
                            }
                            else if (type == PaintType.Group)
                            {
                                // If child is a group, recursively deserialize to object
                                PaintGroup innerGroup = GetPaintGroup(jChild, deserBase);
                                if (innerGroup != null)
                                {
                                    group.Add(AddDecorators(jChild, innerGroup));
                                }
                            }
                        }
                    }
                }
            }

            return(group);
        }
예제 #3
0
        /// <summary>
        /// Convert json string into a state with objects
        /// </summary>
        /// <param name="jsonSaveString">savefile as json string</param>
        /// <returns>Canvas state</returns>
        private List <PaintBase> DeserializeJsonSave(string jsonSaveString)
        {
            List <PaintBase> newShapeList = new List <PaintBase>();

            // Savefile should contain json array at root
            JArray jArray = JArray.Parse(jsonSaveString);

            if (jArray != null)
            {
                // Iterate through items in array
                foreach (JToken jToken in jArray)
                {
                    if (jToken is JObject jObject)
                    {
                        if (Enum.TryParse(jObject.GetValue("type").ToString(), out PaintType type))
                        {
                            // Get base properties
                            PaintBaseProperties deserializedProperties = GetBaseProperties(jObject);

                            if (deserializedProperties != null)
                            {
                                if (type == PaintType.Shape)
                                {
                                    PaintShape shape = GetPaintShape(jObject, deserializedProperties);
                                    if (shape != null)
                                    {
                                        newShapeList.Add(AddDecorators(jObject, shape));
                                    }
                                }
                                else if (type == PaintType.Group)
                                {
                                    PaintGroup group = GetPaintGroup(jObject, deserializedProperties);
                                    if (group != null)
                                    {
                                        newShapeList.Add(AddDecorators(jObject, group));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(newShapeList);
        }