コード例 #1
0
ファイル: CommandDelete.cs プロジェクト: heng222/MyRepository
        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);
                }
            }
        }
コード例 #2
0
ファイル: DrawArea.cs プロジェクト: Xaprice/XView
        /// <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;
        }
コード例 #3
0
ファイル: DrawArea.cs プロジェクト: kallotec/Bonsai
        /// <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);
        }
コード例 #4
0
        // 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());
            }
        }
コード例 #5
0
        // 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());
            }
        }
コード例 #6
0
 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);
     }
 }
コード例 #7
0
 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);
     }
 }
コード例 #8
0
ファイル: CommandDelete.cs プロジェクト: heng222/MyRepository
        public override void Undo(GraphicsList list)
        {
            list.UnselectAll();

            // Add all objects from cloneList to list.
            foreach (DrawObject o in cloneList)
            {
                list.Add(o);
            }
        }
コード例 #9
0
ファイル: CommandDelete.cs プロジェクト: heng222/MyRepository
        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());
            }
        }
コード例 #10
0
        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]);
            }
        }
コード例 #11
0
        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]);
            }
        }
コード例 #12
0
        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]);
            }
        }
コード例 #13
0
        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]);
            }
        }
コード例 #14
0
        // 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());
            }
        }
コード例 #15
0
        // 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());
            }
        }
コード例 #16
0
        /// <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();
        }
コード例 #17
0
ファイル: DrawArea.cs プロジェクト: kallotec/Bonsai
        /// <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();
        }
コード例 #18
0
        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);
                }
            }
        }
コード例 #19
0
        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);
                }
            }
        }
コード例 #20
0
ファイル: Layer.cs プロジェクト: pos0637/codec
        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);
            }
        }
コード例 #21
0
        // 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);
                }
            }
        }
コード例 #22
0
        // 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);
                }
            }
        }
コード例 #23
0
        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);
        }
コード例 #24
0
ファイル: DrawArea.cs プロジェクト: prsly/Vector-Editor
        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);
        }
コード例 #25
0
 public override void Redo(GraphicsList list)
 {
     // Clear list - make DeleteAll again
     list.Clear();
 }
コード例 #26
0
 // Create this command BEFORE operation.
 public CommandChangeState(GraphicsList graphicsList)
 {
     // Keep objects state before operation.
     FillList(graphicsList, ref listBefore);
 }
コード例 #27
0
ファイル: DrawArea.cs プロジェクト: Xaprice/XView
 public void IsDirty(GraphicsList gList)
 {
     AdjustRendering();
 }
コード例 #28
0
ファイル: DrawArea.cs プロジェクト: Xaprice/XView
        /// <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]);
                    }
                }
            };
        }
コード例 #29
0
ファイル: CommandAdd.cs プロジェクト: ArsenShnurkov/DrawTools
 public override void Redo(GraphicsList list)
 {
     list.UnselectAll();
     list.Add(drawObject);
 }
コード例 #30
0
 public override void Undo(GraphicsList list)
 {
     // Replace all objects in the list with objects from listBefore
     ReplaceObjects(list, listBefore);
 }
コード例 #31
0
        public UndoManager(GraphicsList graphicsList)
        {
            this.graphicsList = graphicsList;

            ClearHistory();
        }
コード例 #32
0
 public override void Undo(GraphicsList list)
 {
     // Replace all objects in the list with objects from listBefore
     ReplaceObjects(list, listBefore);
 }
コード例 #33
0
 public override void Undo(GraphicsList list)
 {
     list.DeleteLastAddedObject();
 }
コード例 #34
0
ファイル: Command.cs プロジェクト: Helio452b/DrawTool2005
 // This command is used to make Redo operation.
 // It makes original command again.
 public abstract void Redo(GraphicsList list);
コード例 #35
0
ファイル: DrawArea.cs プロジェクト: ArsenShnurkov/DrawTools
        /// <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();
        }
コード例 #36
0
 // Create this command BEFORE operation.
 public CommandChangeState(GraphicsList graphicsList)
 {
     // Keep objects state before operation.
     FillList(graphicsList, ref listBefore);
 }
コード例 #37
0
 public override void Redo(GraphicsList list)
 {
     // Replace all objects in the list with objects from listAfter
     ReplaceObjects(list, listAfter);
 }
コード例 #38
0
 // Call this function AFTER operation.
 public void NewState(GraphicsList graphicsList)
 {
     // Keep objects state after operation.
     FillList(graphicsList, ref listAfter);
 }
コード例 #39
0
ファイル: Command.cs プロジェクト: ArsenShnurkov/DrawTools
 // This function is used to make Undo operation.
 // It makes action opposite to the original command.
 public abstract void Undo(GraphicsList list);
コード例 #40
0
 public override void Redo(GraphicsList list)
 {
     // Replace all objects in the list with objects from listAfter
     ReplaceObjects(list, listAfter);
 }
コード例 #41
0
        public UndoManager(GraphicsList graphicsList)
        {
            this.graphicsList = graphicsList;

            ClearHistory();
        }
コード例 #42
0
ファイル: CommandAdd.cs プロジェクト: ArsenShnurkov/DrawTools
 public override void Undo(GraphicsList list)
 {
     list.DeleteLastAddedObject();
 }
コード例 #43
0
 public override void Redo(GraphicsList list)
 {
     // Clear list - make DeleteAll again
     list.Clear();
 }
コード例 #44
0
 public override void Redo(GraphicsList list)
 {
     list.UnselectAll();
     list.Add(drawObject);
 }
コード例 #45
0
 // Call this function AFTER operation.
 public void NewState(GraphicsList graphicsList)
 {
     // Keep objects state after operation.
     FillList(graphicsList, ref listAfter);
 }