Exemple #1
0
        public override void OnMouseUp(Designer designer, System.Windows.Forms.MouseEventArgs e)
        {
            //如果是区域选择,选中在此区域的对像
            if (selectmode == SelectionMode.NetSelection)
            {
                designer.Items.SelectInRectangle(designer.SelectRectangle);
                selectmode = SelectionMode.None;
                designer.IsDrawSelectRectangle = false;
            }
            //如果是改变大小则结束改变
            if (resizeObject != null)
            {
                resizeObject.Normalize();

                //如果改变对像的尺寸大小
                if (designer.SelectDrawText != null && (resizeObject.GetType().Name == designer.SelectDrawText.GetType().Name))
                {
                    Rectangle rectangle = DrawRectangle.GetNormalizedRectangle((resizeObject as DrawText).Rectangle);
                    designer.textBox.Location = new Point(rectangle.X + 8, rectangle.Y + 7);
                    designer.textBox.Size     = new Size(rectangle.Width - 10, rectangle.Height - 10);
                    // designer.textBox.Focus();
                    //设置当前选中的文本编辑器
                    //在多个编辑切换时,可以知道当前编辑的是哪一个
                }

                resizeObject = null;
            }
            designer.Capture = false;
            designer.Refresh();
        }
Exemple #2
0
        public override void Draw(Graphics g)
        {
            Pen   pen      = new Pen(Color, PenWidth);
            Brush brushout = new SolidBrush(Color.FromArgb(255, 0, 255, 255));

            g.SmoothingMode = SmoothingMode.AntiAlias;
            if (!flag)
            {
                Rectangle frect = new Rectangle(Rectangle.X, Rectangle.Y, Rectangle.Width, Rectangle.Height);
                g.FillRectangle(brushout, frect);
                g.DrawRectangle(pen, Rectangle);
            }
            else
            {
                g.DrawRectangle(pen, DrawRectangle.GetNormalizedRectangle(Rectangle));
            }

            Brush        brushin0 = new SolidBrush(Color.Red);
            StringFormat style    = new StringFormat();

            style.Alignment = StringAlignment.Near;
            if (showProperty)
            {
                g.DrawString(
                    LogicIDTail,
                    new Font("宋体", 9, FontStyle.Regular),
                    brushin0,
                    Rectangle, style);
            }
            pen.Dispose();
        }
Exemple #3
0
        public override void OnMouseUp(DrawArea drawArea, MouseEventArgs e)
        {
            if (selectMode == SelectionMode.NetSelection)
            {
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint)),
                    Color.Black,
                    FrameStyle.Dashed);

                drawArea.GraphicsList.SelectInRectangle(
                    DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint));

                selectMode = SelectionMode.None;
            }

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

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

            if (commandChangeState != null && wasMove)
            {
                commandChangeState.NewState(drawArea.GraphicsList);
                drawArea.AddCommandToHistory(commandChangeState);
                commandChangeState = null;
            }
        }
Exemple #4
0
        public override void OnMouseUp(Designer designer, MouseEventArgs e)
        {
            //当添加文本编辑时用文本框进行输入编辑内容
            Rectangle rectangle = DrawRectangle.GetNormalizedRectangle((designer.Items[0] as DrawText).Rectangle);

            designer.textBox.Location = new Point(rectangle.X + 8, rectangle.Y + 7);
            designer.textBox.Size     = new Size(rectangle.Width - 14, rectangle.Height - 14);
            designer.textBox.Enabled  = true;
            designer.textBox.Visible  = true;
            designer.textBox.Text     = "";
            designer.textBox.Font     = (designer.Items[0] as DrawText).TextFont;
            designer.textBox.Focus();
            //设置当前选中的文本编辑器
            //在多个编辑切换时,可以知道当前编辑的是哪一个
            designer.SelectDrawText = designer.Items[0] as DrawText;
        }
Exemple #5
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.GraphicsList.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.GraphicsList.UnselectAll();
                    o.Selected = true;

                    commandChangeState = new CommandChangeState(drawArea.GraphicsList);

                    break;
                }
            }

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

                for (int i = 0; i < n1; i++)
                {
                    if (drawArea.GraphicsList[i].HitTest(point) == 0)
                    {
                        o = drawArea.GraphicsList[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.GraphicsList.UnselectAll();
                    }

                    // Select clicked object
                    o.Selected = true;

                    commandChangeState = new CommandChangeState(drawArea.GraphicsList);

                    drawArea.Cursor = Cursors.SizeAll;
                }
            }

            // Net selection
            if (selectMode == SelectionMode.None)
            {
                // click on background
                if ((Control.ModifierKeys & Keys.Control) == 0)
                {
                    drawArea.GraphicsList.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 #6
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.GraphicsList.Count; i++)
                {
                    int n = drawArea.GraphicsList[i].HitTest(point);

                    if (n > 0)
                    {
                        cursor = drawArea.GraphicsList[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)
            {
                List <DrawObject> selectList = new List <DrawObject>();
                int n = drawArea.GraphicsList.Count;
                for (int i = 0; i < n; i++)
                {
                    if (drawArea.GraphicsList[i].Selected)
                    {
                        drawArea.GraphicsList.SelectAlist(drawArea.GraphicsList[i].TagIDBase);
                        selectList.Add(drawArea.GraphicsList[i]);
                    }
                }
                foreach (DrawObject o in selectList)
                {
                    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 #7
0
        public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e)
        {
            commandChangeState = null;
            wasMove            = false;

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

            foreach (DrawObject o in drawArea.GraphicsList.Selection)
            {
                int handleNumber = o.HitTest(point);

                if (handleNumber > 0)
                {
                    selectMode          = SelectionMode.Size;
                    resizedObject       = o;
                    resizedObjectHandle = handleNumber;
                    drawArea.GraphicsList.UnselectAll();
                    o.Selected         = true;
                    commandChangeState = new CommandChangeState(drawArea.GraphicsList);
                    break;
                }
            }

            if (selectMode == SelectionMode.None)
            {
                int        n1 = drawArea.GraphicsList.Count;
                DrawObject o  = null;

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

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

                    if ((Control.ModifierKeys & Keys.Control) == 0 && !o.Selected)
                    {
                        drawArea.GraphicsList.UnselectAll();
                    }

                    o.Selected = true;

                    commandChangeState = new CommandChangeState(drawArea.GraphicsList);

                    drawArea.Cursor = Cursors.SizeAll;
                }
            }

            if (selectMode == SelectionMode.None)
            {
                if ((Control.ModifierKeys & Keys.Control) == 0)
                {
                    drawArea.GraphicsList.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)
            {
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint)),
                    Color.Black,
                    FrameStyle.Dashed);
            }
        }
Exemple #8
0
 /// <summary>
 /// Normalize rectangle
 /// </summary>
 public override void Normalize()
 {
     rectangle = DrawRectangle.GetNormalizedRectangle(rectangle);
 }