Exemplo n.º 1
0
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CommandDelete command = new CommandDelete(drawArea.Graphics);

            if (drawArea.Graphics.DeleteSelection())
            {
                drawArea.SetDirty();
                drawArea.Refresh();
                drawArea.AddCommandToHistory(command);
            }
        }
Exemplo n.º 2
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)
        {
            if (drawArea.Graphics.Count > 0)
            {
                if (drawArea.Graphics.First.Shape.Length >= 2)//有一定长度才画图
                {
                    DrawObject draw = drawArea.Graphics.First;
                    draw.ShowParamSetting(e.Location);
                    draw.BulidWay(draw.WaySetter);

                    if (draw.WaySetter.CBCreateReverseWay.Checked == true)
                    {
                        DrawObject ctrWay = draw.BuildCtrWay();

                        drawArea.Graphics.AddFirst(ctrWay);
                        drawArea.SetDirty();
                        drawArea.AddCommandToHistory(new CommandAdd(ctrWay));
                    }

                    drawArea.AddCommandToHistory(new CommandAdd(drawArea.Graphics.First));
                    drawArea.ActiveTool = DrawArea.DrawToolType.Pointer;

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

            //drawArea.GraphicsList[0].Normalize();
            //drawArea.AddCommandToHistory(new CommandAdd(drawArea.GraphicsList[0]));
            //drawArea.ActiveTool = DrawArea.DrawToolType.Pointer;

            //drawArea.Capture = false;
            //drawArea.Refresh();
        }
Exemplo n.º 3
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.Graphics.UnselectAll();

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

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

            drawArea.SetDirty();
        }
Exemplo n.º 4
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.Graphics.Count; i++)
                {
                    int n = drawArea.Graphics[i].HitTest(point);

                    if (n > 0)
                    {
                        cursor = drawArea.Graphics[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.Graphics.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;
            }
        }