Example #1
0
 public static List <DrawObject> GetDrawObjectsFromXML(Graphics graphics, string xml, float zoomMultiplier)
 {
     try
     {
         List <SerializableDrawObject> serializable = XmlSerialize.DeserializeObject <List <SerializableDrawObject> >(xml);
         return(serializable.ConvertAll(o => DrawObject.FromSerialized(graphics, o, zoomMultiplier)));
     }
     catch
     {
         return(new List <DrawObject>());
     }
 }
Example #2
0
        private void undoRedo(UndoAction action, Stack <UndoAction> opposites, bool redo)
        {
            var opposite = new UndoAction();

            if (action.UndoActionType == UndoActionType.AddDrawObject)
            {
                opposite.UndoActionType = UndoActionType.DeleteDrawObject;
            }
            else if (action.UndoActionType == UndoActionType.DeleteDrawObject)
            {
                opposite.UndoActionType = UndoActionType.AddDrawObject;
            }
            else
            {
                opposite.UndoActionType = action.UndoActionType;
            }

            if (action.UndoActionType == UndoActionType.DeleteDrawObject)
            {
                CurrentDrawObject   = DrawObject.FromSerialized(_currGraphics, action.DrawObject, _zoomMultiplier);
                opposite.DrawObject = CurrentDrawObject.GetSerializable();
                _drawObjects.Add(CurrentDrawObject);
            }
            else
            {
                var drawObj = _drawObjects.First(d => d.ID == action.DrawObject.ID);
                opposite.DrawObject = drawObj.GetSerializable();
                if (action.UndoActionType == UndoActionType.AddDrawObject)
                {
                    _drawObjects.Remove(drawObj);
                }
                else if (action.UndoActionType == UndoActionType.CropImage)
                {
                    _cropRectangle = redo ?
                                     (CurrentDrawObject as SelectDrawObject).GetSelectionRectangle()
                                                : Rectangle.Empty;
                    LoadImage(true);
                }
                else
                {
                    drawObj.Undo(action.DrawObject);
                }
            }

            opposites.Push(opposite);

            serializeDrawObjects();

            redraw(true);
        }