public override void Redo(GraphicsList list) { // Delete from list all objects kept in cloneList int n = list.Count; for (int i = n - 1; i >= 0; i--) { bool toDelete = false; DrawObject objectToDelete = list[i]; foreach (DrawObject o in cloneList) { if (objectToDelete.ID == o.ID) { toDelete = true; break; } } if (toDelete) { list.RemoveAt(i); } } }
/// <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(); //AdjustRendering(); this.initialized = true; }
/// <summary> /// Initialization /// </summary> /// <param name="owner"></param> public void Initialize(Control owner) { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true); // Keep reference to owner form Owner = owner; // set default tool _activeTool = DrawToolType.Pointer; // create list of graphic objects _graphicsList = new 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(); _tools[(int)DrawToolType.Text] = new ToolText(); _tools[(int)DrawToolType.Bitmap] = new ToolImage(); _tools[(int)DrawToolType.Pan] = new ToolPan(); _tools[(int)DrawToolType.Path] = new ToolPath(); Graphics g = Owner.CreateGraphics(); DrawObject.Dpi = new PointF(g.DpiX, g.DpiY); }
// Fill list from selection private void FillList(GraphicsList graphicsList, ref List <DrawObject> listToFill) { listToFill = new List <DrawObject>(); foreach (DrawObject o in graphicsList.Selection) { listToFill.Add(o.Clone()); } }
// Fill list from selection private void FillList(GraphicsList graphicsList, ref List<DrawObject> listToFill) { listToFill = new List<DrawObject>(); foreach (DrawObject o in graphicsList.Selection) { listToFill.Add(o.Clone()); } }
public override void Undo(GraphicsList list) { // Add all objects from clone list to list - // opposite to DeleteAll foreach (DrawObject o in cloneList) { list.Add(o); } }
public override void Undo(GraphicsList list) { list.UnselectAll(); // Add all objects from cloneList to list. foreach (DrawObject o in cloneList) { list.Add(o); } }
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()); } }
public override void Redo(GraphicsList list) { // Delete from list all objects kept in cloneList int n = indexList.Count; for (int i = n - 1; i >= 0; i--) { list.RemoveAt(indexList[i]); } }
public override void Undo(GraphicsList list) { list.UnselectAll(); // Add all objects from cloneList to list. int n = cloneList.Count; for (int i = n - 1; i >= 0; i--) { list.Insert(indexList[i], cloneList[i]); } }
// 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()); } }
/// <summary> /// Initialization /// </summary> /// <param name="owner"></param> /// <param name="docManager"></param> public void Initialize() { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true); // set default tool activeTool = DrawToolType.Pointer; // create list of graphic objects graphicsList = new GraphicsList(); // create array of drawing tools tools = new Tool[(int)DrawToolType.NumberOfDrawTools]; tools[(int)DrawToolType.Pointer] = new ToolPointer(); }
/// <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; _bringToFrontToolStripMenuItem.Enabled = true; _sendToBackToolStripMenuItem.Enabled = true; _cutToolStripMenuItem.Enabled = true; _copyToolStripMenuItem.Enabled = true; _deleteToolStripMenuItem.Enabled = true; } else { _bringToFrontToolStripMenuItem.Enabled = false; _sendToBackToolStripMenuItem.Enabled = false; _cutToolStripMenuItem.Enabled = false; _copyToolStripMenuItem.Enabled = false; _deleteToolStripMenuItem.Enabled = false; GraphicsList.UnselectAll(); } _pasteToolStripMenuItem.Enabled = GraphicsList.AreItemsInMemory(); _contextMenuStrip.Show(MousePosition); Refresh(); }
List <int> indexList; // contains index of selected items which are deleted // Create this command BEFORE applying Delete All function. public CommandDelete(GraphicsList graphicsList) { cloneList = new List <DrawObject>(); indexList = new List <int>(); // Make clone of the list selection. int n = graphicsList.Count; for (int i = n - 1; i >= 0; i--) { if (graphicsList[i].Selected) { cloneList.Add(graphicsList[i].Clone()); indexList.Add(i); } } }
List<int> indexList; // contains index of selected items which are deleted #endregion Fields #region Constructors // Create this command BEFORE applying Delete All function. public CommandDelete(GraphicsList graphicsList) { cloneList = new List<DrawObject>(); indexList = new List<int>(); // Make clone of the list selection. int n = graphicsList.Count; for (int i = n - 1; i >= 0; i--) { if (graphicsList[i].Selected) { cloneList.Add(graphicsList[i].Clone()); indexList.Add(i); } } }
public void LoadFromStream(SerializationInfo info, int orderNumber) { _graphicsList = new GraphicsList(); _name = info.GetString( String.Format(CultureInfo.InvariantCulture, "{0}{1}", entryLayerName, orderNumber)); _visible = info.GetBoolean( String.Format(CultureInfo.InvariantCulture, "{0}{1}", entryLayerVisible, orderNumber)); _active = info.GetBoolean( String.Format(CultureInfo.InvariantCulture, "{0}{1}", entryLayerActive, orderNumber)); int n = info.GetInt32( String.Format(CultureInfo.InvariantCulture, "{0}{1}", entryGraphicsCount, orderNumber)); for (int i = 0; i < n; i++) { string typeName; typeName = info.GetString( String.Format(CultureInfo.InvariantCulture, "{0}{1}-{2}", entryObjectType, orderNumber, i)); object drawObject; drawObject = Assembly.GetExecutingAssembly().CreateInstance(typeName); ((DrawObject)drawObject).LoadFromStream(info, orderNumber, i); // Thanks to Member 3272353 for this fix to object ordering problem. // _graphicsList.Add((DrawObject)drawObject); _graphicsList.Append((DrawObject)drawObject); } }
// 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 = null; foreach (DrawObject o in list) { if (o.ID == graphicsList[i].ID) { replacement = o; break; } } 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 = null; foreach(DrawObject o in list) { if ( o.ID == graphicsList[i].ID ) { replacement = o; break; } } if ( replacement != null ) { graphicsList.Replace(i, replacement); } } }
private static Point TestForConnection(DrawArea drawArea, Point p, out int objectID) { // Determine if within 5 pixels of a connection point // Step 1: see if a 5 x 5 rectangle centered on the mouse cursor intersects with an object // Step 2: If it does, then see if there is a connection point within the rectangle // Step 3: If there is, move the point to the connection point, record the object's id in the connector // objectID = -1; Rectangle testRectangle = new Rectangle(p.X - 2, p.Y - 2, 5, 5); int al = drawArea.TheLayers.ActiveLayerIndex; bool connectionHere = false; Point h = new Point(-1, -1); GraphicsList gl = drawArea.TheLayers[al].Graphics; for (int i = 1; i < gl.Count; i++) { if (gl[i].IntersectsWith(testRectangle)) { DrawObject obj = (DrawObject)gl[i]; for (int j = 1; j < obj.HandleCount + 1; j++) { h = obj.GetHandle(j); if (testRectangle.Contains(h)) { connectionHere = true; p = h; objectID = obj.ID; // obj.DrawConnection(drawArea., j); break; } } } if (connectionHere) { break; } } return(p); }
public void Initialize(Control owner) { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true); Owner = owner; _activeTool = DrawToolType.Pointer; _graphicsList = new GraphicsList(); _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(); _tools[(int)DrawToolType.Text] = new ToolText(); _tools[(int)DrawToolType.Path] = new ToolPath(); Graphics g = Owner.CreateGraphics(); DrawObject.Dpi = new PointF(g.DpiX, g.DpiY); }
public override 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); }
public void IsDirty(GraphicsList gList) { AdjustRendering(); }
/// <summary> /// Right-click handler /// </summary> /// <param name="e"></param> private void OnContextMenu(MouseEventArgs e) { // Change current selection if necessary Point point = new Point(Math.Abs(this.AutoScrollPosition.X) + e.X, Math.Abs(this.AutoScrollPosition.Y) + 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. m_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 pointscroll from this window coordinates to owner's coordinates. point.X += this.Left; point.Y += this.Top; Point org = new Point(e.X, e.Y); m_ContextMenu.Show(owner, org); 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. m_ContextMenu.Closed += delegate(object sender, ToolStripDropDownClosedEventArgs args) { if (m_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 override void Redo(GraphicsList list) { list.UnselectAll(); list.Add(drawObject); }
public override void Undo(GraphicsList list) { // Replace all objects in the list with objects from listBefore ReplaceObjects(list, listBefore); }
public UndoManager(GraphicsList graphicsList) { this.graphicsList = graphicsList; ClearHistory(); }
public override void Undo(GraphicsList list) { list.DeleteLastAddedObject(); }
// This command is used to make Redo operation. // It makes original command again. public abstract void Redo(GraphicsList list);
/// <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.Triangle] = new ToolTriangle(); tools[(int)DrawToolType.Line] = new ToolLine(); tools[(int)DrawToolType.Polygon] = new ToolPolygon(); }
public override void Redo(GraphicsList list) { // Replace all objects in the list with objects from listAfter ReplaceObjects(list, listAfter); }
// Call this function AFTER operation. public void NewState(GraphicsList graphicsList) { // Keep objects state after operation. FillList(graphicsList, ref listAfter); }
// This function is used to make Undo operation. // It makes action opposite to the original command. public abstract void Undo(GraphicsList list);