Exemple #1
0
        public override void Redo(DrawArea drawArea)
        {
            // Delete from list all objects kept in cloneList

            int n = drawArea.Count;

            for (int i = n - 1; i >= 0; i--)
            {
                bool toDelete = false;
                DrawObject objectToDelete = drawArea[i];

                foreach (DrawObject o in cloneList)
                {
                    if (objectToDelete.ID == o.ID)
                    {
                        toDelete = true;
                        break;
                    }
                }

                if (toDelete)
                {
                    drawArea.RemoveAt(i);
                }
            }
        }
Exemple #2
0
 public DrawArea OpenFile()
 {
     var drawArea = new DrawArea(this);
     var doc = tabbedView.AddDocument(drawArea);
     doc.Caption = "测试";
     this.tabbedView.ActivateDocument(drawArea);
     return drawArea;
 }
 public override void Undo(DrawArea drawArea)
 {
     // Add all objects from clone list to list -
     // opposite to DeleteAll
     foreach (DrawObject o in cloneList)
     {
         drawArea.Add(o);
     }
 }
        // Fill list from selection
        private void FillList(DrawArea drawArea, ref List<DrawObject> listToFill)
        {
            listToFill = new List<DrawObject>();

            foreach (DrawObject o in drawArea.Selection)
            {
                listToFill.Add(o.Clone());
            }
        }
Exemple #5
0
        /// <summary>
        /// Left mouse is released.
        /// New object is created and resized.
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="e"></param>
        public override void OnMouseUp(DrawArea drawArea, MouseEventArgs e)
        {
            drawArea[0].Normalize();
            drawArea.AddCommandToHistory(new CommandAdd(drawArea[0]));
            drawArea.ActiveDrawTool = DrawToolType.Pointer;

            drawArea.Capture = false;
            drawArea.Refresh();
        }
Exemple #6
0
        public override void Undo(DrawArea drawArea)
        {
            drawArea.UnselectAll();

            // Add all objects from cloneList to list.
            foreach (DrawObject o in cloneList)
            {
                drawArea.Add(o);
            }
        }
Exemple #7
0
        List<DrawObject> cloneList;    // contains selected items which are deleted

        // Create this command BEFORE applying Delete All function.
        public CommandDelete(DrawArea drawArea)
        {
            cloneList = new List<DrawObject>();

            // Make clone of the list selection.

            foreach (DrawObject o in drawArea.Selection)
            {
                cloneList.Add(o.Clone());
            }
        }
Exemple #8
0
        public override void OnMouseMove(DrawArea drawArea, MouseEventArgs e)
        {
            drawArea.Cursor = Cursor;

            //if (e.Button == MouseButtons.Left)
            //{
            //    Point point = new Point(e.X, e.Y);
            //    drawArea[0].MoveHandleTo(point, 5);
            //    drawArea.Refresh();
            //}
        }
Exemple #9
0
        /// <summary>
        /// Add new object to draw area.
        /// Function is called when user left-clicks draw area,
        /// and one of ToolObject-derived tools is active.
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="o"></param>
        protected void AddNewObject(DrawArea drawArea, DrawObject o)
        {
            drawArea.UnselectAll();

            o.Selected = true;
            drawArea.Add(o);

            drawArea.Capture = true;
            drawArea.Refresh();

            drawArea.SetDirty();
        }
        // Create this command BEFORE applying Delete All function.
        public CommandDeleteAll(DrawArea drawArea)
        {
            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 = drawArea.Count;

            for (int i = n - 1; i >= 0; i--)
            {
                cloneList.Add(drawArea[i].Clone());
            }
        }
Exemple #11
0
        public static DrawObject GetHitDrawObject(DrawArea drawArea, Point p)
        {
            var point = ToolObject.TranslatePoint(drawArea, p);
            point = ToolObject.UnzoomPoint(point, drawArea.Zoom);
            for (int i = 0; i < drawArea.Count; i++)
            {
                int n = drawArea[i].HitTest(point);
                //TODO:///
                //if (n >= 0 && !(drawArea[i] is DrawLine))
                //{
                //    return drawArea[i];
                //}
            }

            return null;
        }
Exemple #12
0
        private static Point CalcScrollPoint(Point p, DrawArea drawArea)
        {
            var pt = new Point(p.X, p.Y);
            if (pt.X < drawArea.Left)
                pt.X = drawArea.Left;

            if (pt.Y < drawArea.Top)
                pt.Y = drawArea.Top;

            if (pt.X > drawArea.Left + drawArea.Width - drawArea.AutoScrollPosition.X - 5)
                pt.X = drawArea.Left + drawArea.Width - drawArea.AutoScrollPosition.X - 5;

            if (pt.Y > drawArea.Top + drawArea.Height - drawArea.AutoScrollPosition.Y - 5)
                pt.Y = drawArea.Top + drawArea.Height - drawArea.AutoScrollPosition.Y - 5;

            return pt;
        }
        // Replace objects in graphicsList with objects from list
        private void ReplaceObjects(DrawArea drawArea, List<DrawObject> list)
        {
            for ( int i = 0; i < drawArea.Count; i++ )
            {
                DrawObject replacement = null;

                foreach(DrawObject o in list)
                {
                    if ( o.ID == drawArea[i].ID )
                    {
                        replacement = o;
                        break;
                    }
                }

                if ( replacement != null )
                {
                    drawArea.Replace(i, replacement);
                }
            }
        }
Exemple #14
0
 public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e)
 {
     AddNewObject(drawArea, new DrawRhombus(e.X, e.Y, 1, 1));
 }
 // Call this function AFTER operation.
 public void NewState(DrawArea drawArea)
 {
     // Keep objects state after operation.
     FillList(drawArea, ref listAfter);
 }
 public override void Undo(DrawArea drawArea)
 {
     // Replace all objects in the list with objects from listBefore
     ReplaceObjects(drawArea, listBefore);
 }
 public override void Redo(DrawArea drawArea)
 {
     // Clear list - make DeleteAll again
     drawArea.Clear();
 }
 public override void Redo(DrawArea drawArea)
 {
     // Replace all objects in the list with objects from listAfter
     ReplaceObjects(drawArea, listAfter);
 }
Exemple #19
0
        /// <summary>
        /// Mouse is moved.
        /// None button is pressed, or left button is pressed.
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="e"></param>
        public override void OnMouseMove(DrawArea drawArea, MouseEventArgs e)
        {
            Point point = new Point(e.X, e.Y);
            Point oldPoint = lastPoint;

            wasMove = true;

            // set cursor when mouse button is not pressed
            if (e.Button == MouseButtons.None)
            {
                Cursor cursor = null;

                for (int i = 0; i < drawArea.Count; i++)
                {
                    int n = drawArea[i].HitTest(point);

                    if (n > 0)
                    {
                        cursor = drawArea[i].GetHandleCursor(n);
                        break;
                    }
                }

                if (cursor == null)
                    cursor = Cursors.Default;

                drawArea.Cursor = cursor;

                return;
            }

            if (e.Button != MouseButtons.Left)
                return;

            /// Left button is pressed

            // Find difference between previous and current position
            int dx = e.X - lastPoint.X;
            int dy = e.Y - lastPoint.Y;

            lastPoint.X = e.X;
            lastPoint.Y = e.Y;

            // resize
            if (selectMode == SelectionMode.Size)
            {
                if (resizedObject != null)
                {
                    resizedObject.MoveHandleTo(point, resizedObjectHandle);
                    drawArea.SetDirty();
                    drawArea.Refresh();
                }
            }

            // move
            if (selectMode == SelectionMode.Move)
            {
                foreach (DrawObject o in drawArea.Selection)
                {
                    o.Move(dx, dy);
                }

                drawArea.Cursor = Cursors.SizeAll;
                drawArea.SetDirty();
                drawArea.Refresh();
            }

            if (selectMode == SelectionMode.NetSelection)
            {
                // Remove old selection rectangle
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(startPoint, oldPoint)),
                    Color.Black,
                    FrameStyle.Dashed);

                // Draw new selection rectangle
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(startPoint, point)),
                    Color.Black,
                    FrameStyle.Dashed);

                return;
            }

        }
Exemple #20
0
        /// <summary>
        /// Left mouse button is pressed
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="e"></param>
        public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e)
        {
            commandChangeState = null;
            wasMove = false;

            selectMode = SelectionMode.None;
            Point point = new Point(e.X, e.Y);

            // Test for resizing (only if control is selected, cursor is on the handle)
            foreach (DrawObject o in drawArea.Selection)
            {
                int handleNumber = o.HitTest(point);

                if (handleNumber > 0)
                {
                    selectMode = SelectionMode.Size;

                    // keep resized object in class member
                    resizedObject = o;
                    resizedObjectHandle = handleNumber;

                    // Since we want to resize only one object, unselect all other objects
                    drawArea.UnselectAll();
                    o.Selected = true;

                    commandChangeState = new CommandChangeState(drawArea);

                    break;
                }
            }

            // Test for move (cursor is on the object)
            if (selectMode == SelectionMode.None)
            {
                int n1 = drawArea.Count;
                DrawObject o = null;

                for (int i = 0; i < n1; i++)
                {
                    if (drawArea[i].HitTest(point) == 0)
                    {
                        o = drawArea[i];
                        break;
                    }
                }

                if (o != null)
                {
                    selectMode = SelectionMode.Move;

                    // Unselect all if Ctrl is not pressed and clicked object is not selected yet
                    if ((Control.ModifierKeys & Keys.Control) == 0 && !o.Selected)
                        drawArea.UnselectAll();

                    // Select clicked object
                    o.Selected = true;

                    commandChangeState = new CommandChangeState(drawArea);

                    drawArea.Cursor = Cursors.SizeAll;
                }
            }

            // Net selection
            if (selectMode == SelectionMode.None)
            {
                // click on background
                if ((Control.ModifierKeys & Keys.Control) == 0)
                    drawArea.UnselectAll();

                selectMode = SelectionMode.NetSelection;

            }

            lastPoint.X = e.X;
            lastPoint.Y = e.Y;
            startPoint.X = e.X;
            startPoint.Y = e.Y;

            drawArea.Capture = true;

            drawArea.Refresh();

            if (selectMode == SelectionMode.NetSelection)
            {
                // Draw selection rectangle in initial position
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint)),
                    Color.Black,
                    FrameStyle.Dashed);
            }
        }
Exemple #21
0
        /// <summary>
        /// Right mouse button is released
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="e"></param>
        public override void OnMouseUp(DrawArea drawArea, MouseEventArgs e)
        {
            if (selectMode == SelectionMode.NetSelection)
            {
                // Remove old selection rectangle
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint)),
                    Color.Black,
                    FrameStyle.Dashed);

                // Make group selection
                drawArea.SelectInRectangle(DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint));

                selectMode = SelectionMode.None;
            }

            if (resizedObject != null)
            {
                // after resizing
                resizedObject.Normalize();
                resizedObject = null;
            }

            drawArea.Capture = false;
            drawArea.Refresh();

            if (commandChangeState != null && wasMove)
            {
                // Keep state after moving/resizing and add command to history
                commandChangeState.NewState(drawArea);
                drawArea.AddCommandToHistory(commandChangeState);
                commandChangeState = null;
            }
        }
Exemple #22
0
 // This function is used to make Undo operation.
 // It makes action opposite to the original command.
 public abstract void Undo(DrawArea drawArea);
Exemple #23
0
 // This command is used to make Redo operation.
 // It makes original command again.
 public abstract void Redo(DrawArea drawArea);
Exemple #24
0
 public override void Redo(DrawArea drawArea)
 {
     drawArea.UnselectAll();
     drawArea.Add(drawObject);
 }
 // Create this command BEFORE operation.
 public CommandChangeState(DrawArea drawArea)
 {
     // Keep objects state before operation.
     FillList(drawArea, ref listBefore);
 }
Exemple #26
0
 public static Point TranslatePoint(DrawArea drawArea, Point p)
 {
     var point = new Point(p.X + Math.Abs(drawArea.AutoScrollPosition.X), p.Y + Math.Abs(drawArea.AutoScrollPosition.Y));
     return
         CalcScrollPoint(point, drawArea);
 }
Exemple #27
0
        public UndoManager(DrawArea drawArea)
        {
            this.drawArea = drawArea;

            ClearHistory();
        }
Exemple #28
0
 public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e)
 {
     AddNewObject(drawArea, new DrawRectangle(true, e.X, e.Y, 1, 1));
 }
Exemple #29
0
 public override void Undo(DrawArea drawArea)
 {
     drawArea.DeleteLastAddedObject();
 }
Exemple #30
0
 /// <summary>
 /// Left mouse button is released
 /// </summary>
 /// <param name="drawArea"></param>
 /// <param name="e"></param>
 public virtual void OnMouseUp(DrawArea drawArea, MouseEventArgs e)
 {
 }