Click here to Skip to main content
15,895,812 members
Articles / Multimedia / GDI+

Drawing Library

Rate me:
Please Sign up or sign in to vote.
4.78/5 (63 votes)
10 Dec 2007CPOL3 min read 294.2K   12.8K   211  
A library for creating shapes and developing tools.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

using Globe.Graphics.Bidimensional.Common;

namespace Globe.Graphics.Bidimensional.Base
{
    /// <summary>
    /// Selects more shapes.
    /// </summary>
    public class MultiSelect : Draw
    {
        #region Events and Delegates

        /// <summary>
        /// Function to notify shapes selection.
        /// </summary>
        /// <param name="tool">Tool that notifies.</param>
        /// <param name="shapes">Shapes.</param>
        public delegate void OnSelectedShapes(Tool tool, ShapeCollection shapes);

        /// <summary>
        /// Fires when shapes are selected.
        /// </summary>
        public event OnSelectedShapes SelectedShapes;

        #endregion

        #region Constructors

        /// <summary>
        /// Default constructor.
        /// </summary>
        public MultiSelect()
        {
            Ghost = new MultiSelectGhost();
        }

        #endregion

        #region IActions Interface

        /// <summary>
        /// Mouse down function.
        /// </summary>
        /// <param name="document">Informations transferred from DrawingPanel.</param>
        /// <param name="e">MouseEventArgs.</param>
        public override void MouseDown(IDocument document, MouseEventArgs e)
        {
            if (Control.ModifierKeys != Keys.Control && e.Button != MouseButtons.Right)
                Select.UnselectAll(document.Shapes);

            base.MouseDown(document, e);
        }

        /// <summary>
        /// Mouse up function.
        /// </summary>
        /// <param name="document">Informations transferred from DrawingPanel.</param>
        /// <param name="e">MouseEventArgs.</param>
        public override void MouseUp(IDocument document, MouseEventArgs e)
        {
			SelectIntersectedShapes(document.Shapes);

            if (SelectedShapes != null)
                SelectedShapes(this, Select.GetSelectedShapes(document.Shapes));

            base.MouseUp(document, e);
        }

        /// <summary>
        /// Paint function.
        /// </summary>
        /// <param name="document">Informations transferred from DrawingPanel.</param>
        /// <param name="e">PaintEventArgs.</param>
        public override void Paint(IDocument document, PaintEventArgs e)
        {
            Ghost.Paint(document, e);
        }

        #endregion

        #region Private Functions

        private void SelectIntersectedShapes(ShapeCollection shapes)
		{
			foreach (IShape shape in shapes)
			{
                if (Ghost.Geometric.GetBounds().IntersectsWith(                    
                    shape.Geometric.GetBounds()))
                    shape.Selected = true;
            }
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Italy Italy
I am a biomedical engineer. I work in Genoa as software developer. I developed MFC ActiveX controls for industrial automation for 2 years and packages for Visual Studio 2005 for 1 year. Currently I'm working in .NET 3.5 in biomedical area.

Comments and Discussions