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>()); } }
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); }
private void removeCurrentDrawObject(DrawObject drawObj) { _drawObjects.Remove(drawObj); serializeDrawObjects(); }
private void pictMain_MouseDown(object sender, MouseEventArgs e) { endText(); var previouslySelected = CurrentDrawObject; deselect(true); if (_drawObjectType == null) { for (int i = _drawObjects.Count - 1; i >= 0; i--) { var dobj = _drawObjects[i]; if (dobj.IsInDrawObject(new Point(e.Location.X - _imageRectangle.X, e.Location.Y - _imageRectangle.Y)) || (previouslySelected != null && previouslySelected.Equals(dobj) && _resizeRectangle.Key != Rectangle.Empty)) { CurrentDrawObject = dobj; CurrentDrawObject.Selected = true; _lock = true; chkErase.Checked = CurrentDrawObject.Erase; chkHighlight.Checked = CurrentDrawObject.Highlight; _color = CurrentDrawObject.GetColor(); _currentLineWidth = CurrentDrawObject.GetWidth(); updateColorWidth(true); _lock = false; setVisibilities(); addUndoAction(UndoActionType.MoveResize); if (_resizeRectangle.Key != Rectangle.Empty) { CurrentDrawObject.StartResize(_resizeRectangle.Key); } btnDelete.Visible = true; redraw(true); _mouseDownLocation = e.Location; break; } } } if (previouslySelected != null && previouslySelected is SelectDrawObject && _cropRectangle == Rectangle.Empty) { removeCurrentDrawObject(previouslySelected); redraw(true); } if (_drawObjectType == null) { return; } if (_imageRectangle.Contains(e.Location)) { _mouseDownLocation = e.Location; CurrentDrawObject = DrawObject.CreateDrawObject(_drawObjectType, !_drawObjects.Any() ? 1 : _drawObjects.Max(d => d.ID) + 1, _currGraphics, new Pen(CurrentColor, CurrentWidth), new Point((int)((_mouseDownLocation.X - _imageRectangle.X) / _zoomMultiplier), (int)((_mouseDownLocation.Y - _imageRectangle.Y) / _zoomMultiplier)), _zoomMultiplier); CurrentDrawObject.Erase = chkErase.Checked; CurrentDrawObject.Highlight = chkHighlight.Checked; if (CurrentDrawObject is IRadiusDrawObject) { (CurrentDrawObject as IRadiusDrawObject).CurrentImage = _bmp; (CurrentDrawObject as IRadiusDrawObject).Radius = CurrentRadius; } if (_drawObjectType.GetInterface(typeof(ITextDrawObject).Name) != null) { (CurrentDrawObject as ITextDrawObject).Font = CurrentFont; } if (CurrentDrawObject is NumberDrawObject) { (CurrentDrawObject as NumberDrawObject).CurrentText = _drawObjects.Count(d => d is NumberDrawObject).ToString(); } if (_drawObjectType.Equals(typeof(TextDrawObject))) { redraw(false); //(CurrentDrawObject as TextDrawObject).Typing = true; CurrentDrawObject.Draw(new Point((int)((e.Location.X - _imageRectangle.X) / _zoomMultiplier), (int)((e.Location.Y - _imageRectangle.Y) / _zoomMultiplier))); //pictMain.Focus(); //pictMain.LostFocus += pictMain_LostFocus; //pictMain.KeyPress += pictMain_KeyPress; } } }