/// <summary> /// Initialization /// </summary> /// <param name="owner"> </param> /// <param name="docManager"> </param> public void Initialize(MainForm owner, DocManager docManager) { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true); // Keep reference to owner form // this.Owner = owner; // this.DocManager = docManager; // set default tool _activeTool = DrawToolType.Pointer; // create list of graphic objects _graphicsList = new GraphicsList(); // Create undo manager _undoManager = new UndoManager(_graphicsList); // create array of drawing tools _tools = new Tool[(int)DrawToolType.NumberOfDrawTools]; _tools[(int)DrawToolType.Pointer] = new ToolPointer(); _tools[(int)DrawToolType.Rectangle] = new ToolRectangle(); _tools[(int)DrawToolType.Ellipse] = new ToolEllipse(); _tools[(int)DrawToolType.Line] = new ToolLine(); _tools[(int)DrawToolType.Polygon] = new ToolPolygon(); }
/// <summary> /// This function is used to make Undo operation. /// It makes action opposite to the original command. /// </summary> /// <param name="list">Graphics list</param> public void Undo(GraphicsList list) { // Add all objects from clone list to list - // opposite to DeleteAll foreach (DrawObject o in _cloneList) { list.Add(o); } }
/// <summary> /// This function is used to make Undo operation. /// It makes action opposite to the original command. /// </summary> /// <param name="list">Graphics list</param> public void Undo(GraphicsList list) { // Add all objects from clone list to list - // opposite to DeleteAll foreach (DrawObject o in _cloneList) { list.Add(o); } }
public void Undo(GraphicsList list) { list.UnselectAll(); // Add all objects from cloneList to list. foreach (DrawObject o in _cloneList) { list.Add(o); } }
public void Undo(GraphicsList list) { list.UnselectAll(); // Add all objects from cloneList to list. foreach (DrawObject o in _cloneList) { list.Add(o); } }
private readonly List <DrawObject> _cloneList; // contains selected items which are deleted // Create this command BEFORE applying Delete All function. public CommandDelete(GraphicsList graphicsList) { _cloneList = new List <DrawObject>(); // Make clone of the list selection. foreach (DrawObject o in graphicsList.Selection) { _cloneList.Add(o.Clone()); } }
private readonly List<DrawObject> _cloneList; // contains selected items which are deleted // Create this command BEFORE applying Delete All function. public CommandDelete(GraphicsList graphicsList) { _cloneList = new List<DrawObject>(); // Make clone of the list selection. foreach (DrawObject o in graphicsList.Selection) { _cloneList.Add(o.Clone()); } }
// Replace objects in graphicsList with objects from list private void ReplaceObjects(GraphicsList graphicsList, List <DrawObject> list) { for (int i = 0; i < graphicsList.Count; i++) { DrawObject replacement = list.FirstOrDefault(o => o.ID == graphicsList[i].ID); if (replacement != null) { graphicsList.Replace(i, replacement); } } }
// Replace objects in graphicsList with objects from list private void ReplaceObjects(GraphicsList graphicsList, List<DrawObject> list) { for (int i = 0; i < graphicsList.Count; i++) { DrawObject replacement = list.FirstOrDefault(o => o.ID == graphicsList[i].ID); if (replacement != null) { graphicsList.Replace(i, replacement); } } }
// Create this command BEFORE applying Delete All function. public CommandDeleteAll(GraphicsList graphicsList) { _cloneList = new List <DrawObject>(); // Make clone of the whole list. // Add objects in reverse order because GraphicsList.Add // insert every object to the beginning. int n = graphicsList.Count; for (int i = n - 1; i >= 0; i--) { _cloneList.Add(graphicsList[i].Clone()); } }
// Create this command BEFORE applying Delete All function. public CommandDeleteAll(GraphicsList graphicsList) { _cloneList = new List<DrawObject>(); // Make clone of the whole list. // Add objects in reverse order because GraphicsList.Add // insert every object to the beginning. int n = graphicsList.Count; for (int i = n - 1; i >= 0; i--) { _cloneList.Add(graphicsList[i].Clone()); } }
public void Redo(GraphicsList list) { // Delete from list all objects kept in cloneList int n = list.Count; for (int i = n - 1; i >= 0; i--) { DrawObject objectToDelete = list[i]; bool toDelete = _cloneList.Any(o => objectToDelete.ID == o.ID); if (toDelete) { list.RemoveAt(i); } } }
public void Redo(GraphicsList list) { // Delete from list all objects kept in cloneList int n = list.Count; for (int i = n - 1; i >= 0; i--) { DrawObject objectToDelete = list[i]; bool toDelete = _cloneList.Any(o => objectToDelete.ID == o.ID); if (toDelete) { list.RemoveAt(i); } } }
// Call this function AFTER operation. #region ICommand Members /// <summary> /// This function is used to make Undo operation. /// It makes action opposite to the original command. /// </summary> /// <param name="list">Graphics list</param> public void Undo(GraphicsList list) { // Replace all objects in the list with objects from listBefore ReplaceObjects(list, _listBefore); }
// Create this command BEFORE operation. public CommandChangeState(GraphicsList graphicsList) { // Keep objects state before operation. FillList(graphicsList, ref _listBefore); }
/// <summary> /// Right-click handler /// </summary> /// <param name="e"> </param> private void OnContextMenu(MouseEventArgs e) { // Change current selection if necessary var point = new Point(e.X, e.Y); int n = GraphicsList.Count; DrawObject o = null; for (int i = 0; i < n; i++) { if (GraphicsList[i].HitTest(point) == 0) { o = GraphicsList[i]; break; } } if (o != null) { if (!o.Selected) { GraphicsList.UnselectAll(); } // Select clicked object o.Selected = true; } else { GraphicsList.UnselectAll(); } Refresh(); // in the case selection was changed // Show context menu. // Context menu items are filled from owner form Edit menu items. _contextMenu = new ContextMenuStrip(); // int nItems = owner.ContextParent.DropDownItems.Count; // Read Edit items and move them to context menu. // Since every move reduces number of items, read them in reverse order. // To get items in direct order, insert each of them to beginning. // for (int i = nItems - 1; i >= 0; i--) // { // m_ContextMenu.Items.Insert(0, owner.ContextParent.DropDownItems[i]); // } // Show context menu for owner form, so that it handles items selection. // Convert point from this window coordinates to owner's coordinates. point.X += Left; point.Y += Top; //m_ContextMenu.Show(owner, point); //Owner.SetStateOfControls(); // enable/disable menu items // Context menu is shown, but owner's Edit menu is now empty. // Subscribe to context menu Closed event and restore items there. _contextMenu.Closed += delegate { if (_contextMenu != null) // precaution { // nItems = m_ContextMenu.Items.Count; // for (int k = nItems - 1; k >= 0; k--) // { // owner.ContextParent.DropDownItems.Insert(0, m_ContextMenu.Items[k]); // } } }; }
public UndoManager(GraphicsList graphicsList) { _graphicsList = graphicsList; ClearHistory(); }
/// <summary> /// Initialization /// </summary> /// <param name="owner"> </param> /// <param name="docManager"> </param> public void Initialize(MainForm owner, DocManager docManager) { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true); // Keep reference to owner form // this.Owner = owner; // this.DocManager = docManager; // set default tool _activeTool = DrawToolType.Pointer; // create list of graphic objects _graphicsList = new GraphicsList(); // Create undo manager _undoManager = new UndoManager(_graphicsList); // create array of drawing tools _tools = new Tool[(int) DrawToolType.NumberOfDrawTools]; _tools[(int) DrawToolType.Pointer] = new ToolPointer(); _tools[(int) DrawToolType.Rectangle] = new ToolRectangle(); _tools[(int) DrawToolType.Ellipse] = new ToolEllipse(); _tools[(int) DrawToolType.Line] = new ToolLine(); _tools[(int) DrawToolType.Polygon] = new ToolPolygon(); }
// Fill list from selection private void FillList(GraphicsList graphicsList, ref List<DrawObject> listToFill) { listToFill = graphicsList.Selection.Select(o => o.Clone()).ToList(); }
// Call this function AFTER operation. #region ICommand Members /// <summary> /// This function is used to make Undo operation. /// It makes action opposite to the original command. /// </summary> /// <param name="list">Graphics list</param> public void Undo(GraphicsList list) { // Replace all objects in the list with objects from listBefore ReplaceObjects(list, _listBefore); }
public void NewState(GraphicsList graphicsList) { // Keep objects state after operation. FillList(graphicsList, ref _listAfter); }
/// <summary> /// This command is used to make Redo operation. /// It makes original command again. /// </summary> /// <param name="list">Graphics list</param> public void Redo(GraphicsList list) { // Clear list - make DeleteAll again list.Clear(); }
/// <summary> /// This command is used to make Redo operation. /// It makes original command again. /// </summary> /// <param name="list">Graphics list</param> public void Redo(GraphicsList list) { // Clear list - make DeleteAll again list.Clear(); }
// Create this command BEFORE operation. public CommandChangeState(GraphicsList graphicsList) { // Keep objects state before operation. FillList(graphicsList, ref _listBefore); }
// Fill list from selection private void FillList(GraphicsList graphicsList, ref List <DrawObject> listToFill) { listToFill = graphicsList.Selection.Select(o => o.Clone()).ToList(); }
public void NewState(GraphicsList graphicsList) { // Keep objects state after operation. FillList(graphicsList, ref _listAfter); }
/// <summary> /// This command is used to make Redo operation. /// It makes original command again. /// </summary> /// <param name="list">Graphics list</param> public void Redo(GraphicsList list) { // Replace all objects in the list with objects from listAfter ReplaceObjects(list, _listAfter); }
public UndoManager(GraphicsList graphicsList) { _graphicsList = graphicsList; ClearHistory(); }
/// <summary> /// This command is used to make Redo operation. /// It makes original command again. /// </summary> /// <param name="list">Graphics list</param> public void Redo(GraphicsList list) { // Replace all objects in the list with objects from listAfter ReplaceObjects(list, _listAfter); }