Exemple #1
0
        private void panel1_MouseUp(object sender, MouseEventArgs e)
        {
            if (rb_group.Checked)
            {
                List <Graphic_Object> elements = Helper.findElementsInGroupPanel(obj, drawnObjs);
                foreach (Graphic_Object g in elements)
                {
                    obj.groupedElements.Add(g);
                    //g.IsGrouped = true;
                    g.color = Color.DarkGray;
                    drawnObjs.Remove(g);
                }
            }

            obj = null;

            foreach (Graphic_Object obj in drawnObjs)
            {
                obj.drawShape(g);
                if (obj.IsGrouped)
                {
                    foreach (Graphic_Object j in obj.groupedElements)
                    {
                        j.drawShape(g);
                    }
                }
            }
        }
Exemple #2
0
 public static bool isPointWithinLine(Point p, Graphic_Object obj)
 {
     try
     {
         bool status = (p.X - obj.X) / (obj.Width) == (p.Y - obj.Y) / (obj.Height);
         return(status);
     }
     catch (Exception e) {
         return(false);
     }
 }
Exemple #3
0
        public static List <Graphic_Object> findElementsInGroupPanel(Graphic_Object obj, List <Graphic_Object> mylist)
        {
            List <Graphic_Object> foundlist = new List <Graphic_Object>();

            foreach (Graphic_Object g in mylist)
            {
                if (g.X > obj.X && g.Y > obj.Y && g.X < (obj.X + obj.Width) && g.Y < (obj.Y + obj.Height))
                {
                    foundlist.Add(g);
                }
            }

            return(foundlist);
        }
Exemple #4
0
        public static bool isPointWithinRect(Point g, Graphic_Object obj)
        {
            bool status = (g.X > obj.X && g.Y > obj.Y && g.X < (obj.X + obj.Width) && g.Y < (obj.Y + obj.Height));

            return(status);
        }
Exemple #5
0
        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            if (rb_oval.Checked)
            {
                obj       = new Graphic_Object();
                obj.X     = e.X;
                obj.Y     = e.Y;
                obj.Shape = Helper.ShapeType.Oval;
                drawnObjs.Add(obj);
            }
            else if (rb_line.Checked)
            {
                obj       = new Graphic_Object();
                obj.X     = e.X;
                obj.Y     = e.Y;
                obj.Shape = Helper.ShapeType.Line;
                drawnObjs.Add(obj);
            }
            else if (rb_fill.Checked)
            {
                obj        = new Graphic_Object();
                obj.X      = e.X;
                obj.Y      = e.Y;
                obj.Shape  = Helper.ShapeType.Oval;
                obj.IsFill = true;
                drawnObjs.Add(obj);
            }
            else if (rb_move.Checked)
            {
                if (drawnObjs.Count != 0)
                {
                    bool           isObjectFound = false;
                    Graphic_Object foundedObj    = null;

                    // search for the drawable object near to the clikced point
                    foreach (Graphic_Object o in drawnObjs)
                    {
                        if (o.Shape == Helper.ShapeType.Oval)
                        {
                            isObjectFound = Helper.isPointInTheElipse(new Rectangle(o.X, o.Y, o.Width, o.Height), new Point(e.X, e.Y));
                        }
                        else if (o.Shape == Helper.ShapeType.Line)
                        {
                            isObjectFound = Helper.isPointWithinLine(new Point(e.X, e.Y), o);
                        }
                        else if (o.Shape == Helper.ShapeType.Rectangle)
                        {
                            isObjectFound = Helper.isPointWithinRect(new Point(e.X, e.Y), o);
                        }

                        if (isObjectFound)
                        {
                            foundedObj = o;
                        }
                    }

                    // get the starting point of the object
                    if (foundedObj != null)
                    {
                        obj       = foundedObj;
                        m_started = new Point(e.X - obj.X, e.Y - obj.Y);
                    }
                }
            }
            else if (rb_remove.Checked)
            {
                if (drawnObjs.Count != 0)
                {
                    bool isObjectFound = false;

                    // search for the nearest object
                    foreach (Graphic_Object o in drawnObjs)
                    {
                        if (o.Shape == Helper.ShapeType.Oval)
                        {
                            isObjectFound = Helper.isPointInTheElipse(new Rectangle(o.X, o.Y, o.Width, o.Height), new Point(e.X, e.Y));
                        }
                        else if (o.Shape == Helper.ShapeType.Line)
                        {
                            isObjectFound = Helper.isPointWithinLine(new Point(e.X, e.Y), o);
                        }
                        else if (o.Shape == Helper.ShapeType.Rectangle)
                        {
                            isObjectFound = Helper.isPointWithinRect(new Point(e.X, e.Y), o);
                        }

                        // remove the found object and redraw the form
                        if (isObjectFound)
                        {
                            obj = o;
                            drawnObjs.Remove(o);
                            g.Clear(Color.WhiteSmoke);
                            foreach (Graphic_Object obj in drawnObjs)
                            {
                                obj.drawShape(g);
                                if (obj.IsGrouped)
                                {
                                    foreach (Graphic_Object j in obj.groupedElements)
                                    {
                                        j.drawShape(g);
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
            }
            else if (rb_group.Checked)
            {
                // check the components inside the selected area
                obj           = new Graphic_Object();
                obj.X         = e.X;
                obj.Y         = e.Y;
                obj.Shape     = Helper.ShapeType.Rectangle;
                obj.color     = Color.DarkGray;
                obj.IsGrouped = true;

                drawnObjs.Add(obj);
            }
        }