Exemplo n.º 1
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.GraphicsList.UnselectAll();

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

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

            drawArea.SetDirty();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get properties from selected objects and fill GraphicsProperties instance
        /// </summary>
        /// <returns></returns>
        private GraphicsProperties GetProperties()
        {
            GraphicsProperties properties = new GraphicsProperties();

            int n = SelectionCount;

            if (n < 1)
            {
                return(properties);
            }

            DrawObject o = GetSelectedObject(0);

            int firstColor    = o.Color.ToArgb();
            int firstPenWidth = o.PenWidth;

            bool allColorsAreEqual = true;
            bool allWidthAreEqual  = true;

            for (int i = 1; i < n; i++)
            {
                if (GetSelectedObject(i).Color.ToArgb() != firstColor)
                {
                    allColorsAreEqual = false;
                }

                if (GetSelectedObject(i).PenWidth != firstPenWidth)
                {
                    allWidthAreEqual = false;
                }
            }

            if (allColorsAreEqual)
            {
                properties.ColorDefined = true;
                properties.Color        = Color.FromArgb(firstColor);
            }

            if (allWidthAreEqual)
            {
                properties.PenWidthDefined = true;
                properties.PenWidth        = firstPenWidth;
            }

            return(properties);
        }
Exemplo n.º 3
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)
            {
                // Group selection
                drawArea.GraphicsList.SelectInRectangle(drawArea.NetRectangle);

                selectMode = SelectionMode.None;
                drawArea.DrawNetRectangle = false;
            }

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

            drawArea.Capture = false;
            drawArea.Refresh();
        }
Exemplo n.º 4
0
 public void Add(DrawObject obj)
 {
     // insert to the top of z-order
     graphicsList.Insert(0, obj);
 }
Exemplo n.º 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)
        {
            selectMode = SelectionMode.None;
            Point point = new Point(e.X, e.Y);

            // Test for resizing (only if control is selected, cursor is on the handle)
            int n = drawArea.GraphicsList.SelectionCount;

            for (int i = 0; i < n; i++)
            {
                DrawObject o            = drawArea.GraphicsList.GetSelectedObject(i);
                int        handleNumber = o.HitTest(point);

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

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

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

                    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;

                    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;
                drawArea.DrawNetRectangle = true;
            }

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

            drawArea.Capture = true;


            drawArea.NetRectangle = DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint);

            drawArea.Refresh();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Right-click handler
        /// </summary>
        /// <param name="e"></param>
        private void OnContextMenu(MouseEventArgs e)
        {
            return;

            // Change current selection if necessary

            Point 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;
            }
            else
            {
                GraphicsList.UnselectAll();
            }

            Refresh();

            // Show context menu.
            // Make ugly trick which saves a lot of code.
            // Get menu items from Edit menu in main form and
            // make context menu from them.
            // These menu items are handled in the parent form without
            // any additional efforts.

            MainMenu mainMenu = Owner.Menu;            // Main menu
            MenuItem editItem = mainMenu.MenuItems[1]; // Edit submenu

            // Make array of items for ContextMenu constructor
            // taking them from the Edit submenu
            MenuItem[] items = new MenuItem[editItem.MenuItems.Count];

            for (int i = 0; i < editItem.MenuItems.Count; i++)
            {
                items[i] = editItem.MenuItems[i];
            }

            //Owner.SetStateOfControls();  // enable/disable menu items//设置菜单的选种状态

            // Create and show context menu
            ContextMenu menu = new ContextMenu(items);

            menu.Show(this, point);

            // Restore items in the Edit menu (without this line Edit menu
            // is empty after forst right-click)
            editItem.MergeMenu(menu);
        }