Ejemplo n.º 1
0
        private bool checkLineProximity(int indexno, int identifier, Graphics daGe)             //checks whether if the mouse pointer is on an object (i.e. shape)
        {
            Graphics g     = daGe;
            Pen      lePen = new Pen(Color.Yellow, 1);

            g = pictureBox1.CreateGraphics();

            g.TranslateTransform(this.pictureBox1.Left + 8, this.pictureBox1.Size.Height + 8);          //transforms point-of-origin to the lower left corner of the canvas.

            g.SmoothingMode = SmoothingMode.HighQuality;

            switch (identifier)                 //depending on the "identifier" value, the relevant object will be highlighted
            {
            case 2:                             //Line
            {
                Line line = (Line)drawingList[indexno];

                if (mainScale == 0)
                {
                    mainScale = 1;
                }

                if (line.Highlight(lePen, g, aPoint, mainScale))
                {
                    this.Cursor      = Cursors.Hand;
                    line.highlighted = true;
                    return(true);
                }

                break;
            }

            case 3:                             //rectangle
            {
                rectangle rect = (rectangle)drawingList[indexno];

                if (rect.Highlight(lePen, g, aPoint))
                {
                    this.Cursor      = Cursors.Hand;
                    rect.highlighted = true;
                    return(true);
                }

                break;
            }

            case 4:                             //circle
            {
                circle tempCircle = (circle)drawingList[indexno];

                if (mainScale == 0)
                {
                    mainScale = 1;
                }

                if (tempCircle.Highlight(lePen, g, aPoint, mainScale))
                {
                    this.Cursor            = Cursors.Hand;
                    tempCircle.highlighted = true;
                    return(true);
                }

                break;
            }

            case 5:                             //polyline
            {
                polyline tempPoly = (polyline)drawingList[indexno];

                if (mainScale == 0)
                {
                    mainScale = 1;
                }

                if (tempPoly.Highlight(lePen, g, aPoint, mainScale))
                {
                    this.Cursor          = Cursors.Hand;
                    tempPoly.highlighted = true;
                    return(true);
                }
                break;
            }

            case 6:                             //arc
            {
                arc tempArc = (arc)drawingList[indexno];

                if (mainScale == 0)
                {
                    mainScale = 1;
                }

                if (tempArc.Highlight(lePen, g, aPoint, mainScale))
                {
                    this.Cursor         = Cursors.Hand;
                    tempArc.highlighted = true;
                    return(true);
                }
                break;
            }
            }

            return(false);
        }
Ejemplo n.º 2
0
        public void Draw(Graphics g)
        {
            Pen lePen = new Pen(Color.White, 3);

            g.TranslateTransform(this.pictureBox1.Location.X + 1, this.pictureBox1.Location.Y + this.pictureBox1.Size.Height - 1);

            if (YMin < 0)
            {
                g.TranslateTransform(0, -(int)Math.Abs(YMin));                                          //transforms point-of-origin to the lower left corner of the canvas.
            }
            if (XMin < 0)
            {
                g.TranslateTransform((int)Math.Abs(XMin), 0);
            }

            //	g.SmoothingMode = SmoothingMode.AntiAlias;

            foreach (DrawingObject obj in objectIdentifier)                                                     //iterates through the objects
            {
                switch (obj.shapeType)
                {
                case 2:                                                 //line
                {
                    Line temp = (Line)drawingList[obj.indexNo];

                    lePen.Color = temp.AccessContourColor;
                    lePen.Width = temp.AccessLineWidth;


                    highlightedRegion.Location = temp.GetStartPoint;

                    highlightedRegion.Width  = temp.GetStartPoint.X - temp.GetEndPoint.X;
                    highlightedRegion.Height = temp.GetStartPoint.Y - temp.GetEndPoint.Y;

                    if (mainScale == 0)
                    {
                        mainScale = 1;
                    }

                    temp.Draw(lePen, g, mainScale);

                    break;
                }

                case 3:                                                 //rectangle
                {
                    rectangle temp = (rectangle)drawingList[obj.indexNo];

                    lePen.Color = temp.AccessContourColor;
                    lePen.Width = temp.AccessLineWidth;


                    temp.Draw(lePen, g);

                    break;
                }

                case 4:                                                 //circle
                {
                    circle temp = (circle)drawingList[obj.indexNo];

                    lePen.Color = temp.AccessContourColor;
                    lePen.Width = temp.AccessLineWidth;

                    if (mainScale == 0)
                    {
                        mainScale = 1;
                    }

                    temp.Draw(lePen, g, mainScale);

                    break;
                }

                case 5:                                                 //polyline
                {
                    polyline temp = (polyline)drawingList[obj.indexNo];

                    lePen.Color = temp.AccessContourColor;
                    lePen.Width = temp.AccessLineWidth;

                    if (mainScale == 0)
                    {
                        mainScale = 1;
                    }

                    temp.Draw(lePen, g, mainScale);

                    break;
                }

                case 6:                                                 //arc
                {
                    arc temp = (arc)drawingList[obj.indexNo];

                    lePen.Color = temp.AccessContourColor;
                    lePen.Width = temp.AccessLineWidth;

                    if (mainScale == 0)
                    {
                        mainScale = 1;
                    }

                    temp.Draw(lePen, g, mainScale);

                    break;
                }
                }
            }


            //	g.Dispose();		//not disposed because "g" is get from the paintbackground event..
            lePen.Dispose();
        }