Exemplo n.º 1
0
 public bool GetElipse(Point p, out myElipse eli)
 {
     eli = null;
     if (isClose(p))
     {
         eli = this;
         return(true);
     }
     return(false);
 }
Exemplo n.º 2
0
 private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
 {
     dragVertex = false;
     dragPolygon = false;
     dragEdge = false;
     dragElipse = false;
     creatingElipse = false;
     oldPolygon = null;
     oldElipse = null;
     UpdateArea();
     pictureBox1.Refresh();
 }
Exemplo n.º 3
0
 private bool FindElipse(Point w, out myElipse elipse)
 {
     elipse = null;
     foreach (myElipse eli in elipses)
     {
         if (eli.GetElipse(w,out elipse))
         {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 4
0
 private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
 {
     Polygon poly = null;
     Edge edge = null;
     Vertex ver = null;
     myElipse delEli = null;
     //Serialize("polygon");
     if (e.Button == MouseButtons.Left)
     {
         switch (operation)
         {
             case Operations.PolygonAdd:
                 if(!startCreating)
                 {
                     startCreating = true;
                     newVertex = new Vertex(e.Location);
                     startVertex = new Vertex(e.Location);
                     newEdge = new Edge(startVertex, newVertex);
                     newPolygon = new Polygon(newEdge);
                     polygons.Add(newPolygon);
                 }
                 else
                 {
                     if (Math.Abs(e.Location.X - startVertex.X) < Vertex.GetSize() + 20 
                         && Math.Abs(e.Location.Y - startVertex.Y) < Vertex.GetSize() + 20 && newPolygon.Count() > 2)
                     {
                         newEdge.B = startVertex;
                         startCreating = false;
                     }
                     else
                     {
                         Vertex v = new Vertex(e.Location);
                         newEdge = new Edge(newVertex, v);
                         newPolygon.AddEdge(newEdge);
                         newVertex = v;
                     }
                 }
                 UpdateArea();
                 break;
             case Operations.VertexMove:
                 if (FindVertex(e.Location, out vertexP, out polygonP))
                 {
                     oldPolygon = polygonP.Copy();
                     dragVertex = true;
                 }
                 break;
             case Operations.VertexDelete:
                 if(FindVertex(e.Location, out ver, out poly))
                 {
                     poly.DeleteVertex(ver);
                     if(poly.Count() == 0)
                     {
                         polygons.Remove(poly);
                     }
                     UpdateArea();
                 }
                 break;
             case Operations.VertexAdd:
                 if(FindEdge(e.Location, out edge, out poly))
                 {
                     poly.SplitEdge(edge);
                     UpdateArea();
                 }
                 break;
             case Operations.PolygonMove:
                 if(FindPolygon(e.Location, out polygonP))
                 {
                     oldPolygon = polygonP.Copy();
                     pointFrom = e.Location;
                     dragPolygon = true;
                 }
                 break;
             case Operations.EdgeMove:
                 if(FindEdge(e.Location, out edgeP, out polygonP))
                 {
                     oldPolygon = polygonP.Copy();
                     pointFrom = e.Location;
                     dragEdge = true;
                 }
                 break;
             case Operations.PolygonDelete:
                 if(FindPolygon(e.Location, out poly))
                 {
                     polygons.Remove(poly);
                     UpdateArea();
                 }
                 break;
             case Operations.ElipseAdd:
                 S = new Point(e.Location.X, e.Location.Y);
                 R = new Point(e.Location.X, e.Location.Y);
                 elipseP = new myElipse(S, R);
                 elipses.Add(elipseP);
                 creatingElipse = true;
                 break;
             case Operations.ElipseMove:
                 if(FindElipse(e.Location, out elipseP))
                 {
                     oldElipse = elipseP.Copy();
                     pointFrom = e.Location;
                     dragElipse = true;
                 }
                 break;
             case Operations.ElipseSize:
                 if(FindElipse(e.Location, out elipseP))
                 {
                     oldElipse = elipseP.Copy();
                     creatingElipse = true;
                 }
                 break;
             case Operations.ElipseDelete:
                 if(FindElipse(e.Location,out delEli))
                 {
                     elipses.Remove(delEli);
                     UpdateArea();
                 }
                 break;
         }
     }
     else if(e.Button == MouseButtons.Right)
     {
         if (dragEdge || dragPolygon || dragVertex || startCreating) return;
         if(FindVertex(e.Location, out vertexP, out polygonP))
         {
             ContextMenu cm = CreateMenuV();
             cm.Show(pictureBox1, e.Location);
         }
         else if (FindEdge(e.Location, out edgeP, out polygonP))
         {
             ContextMenu cm = CreateMenu();
             cm.Show(pictureBox1, e.Location);
         }
     }
     pictureBox1.Refresh();
 }