示例#1
0
 //Vykreslení
 public void Draw(Graphics g, List <Color> colors)
 {
     foreach (Branch branch in Branches)
     {
         if (branch.Count > 1)
         {
             Pen pen = new Pen(colors[branch.Color], 0.3f);
             pen.StartCap = pen.EndCap = System.Drawing.Drawing2D.LineCap.Round;
             Point a = branch[0];
             for (int i = 1; i < branch.Count; i++)
             {
                 Point b = branch[i];
                 //Ošetří případ, kdy jde o přetečení přes okraj
                 if (Math.Abs(a.X - b.X) + Math.Abs(a.Y - b.Y) > 1)
                 {
                     int dx = Grid.ModW(b.X - a.X);
                     if (dx > 1)
                     {
                         dx -= Grid.Width;
                     }
                     int dy = Grid.ModH(b.Y - a.Y);
                     if (dy > 1)
                     {
                         dy -= Grid.Height;
                     }
                     Pen pen2 = new Pen(colors[branch.Color], 0.3f);
                     pen2.StartCap = System.Drawing.Drawing2D.LineCap.Round;
                     g.DrawLine(pen2, new PointF(a.X + 0.5f, a.Y + 0.5f), new PointF(a.X + 0.5f * dx + 0.5f, a.Y + 0.5f * dy + 0.5f));
                     g.DrawLine(pen2, new PointF(b.X + 0.5f, b.Y + 0.5f), new PointF(b.X - 0.5f * dx + 0.5f, b.Y - 0.5f * dy + 0.5f));
                 }
                 //Ostatní případy
                 else
                 {
                     g.DrawLine(pen, new PointF(a.X + 0.5f, a.Y + 0.5f), new PointF(b.X + 0.5f, b.Y + 0.5f));
                 }
                 //Překreslit horní čáru přes most
                 if (Grid.Bridges[a.X, a.Y])
                 {
                     Pen pen3 = new Pen(Color.Black, 0.3f);
                     if (Cells[a.X, a.Y] >= 0)
                     {
                         pen3 = new Pen(colors[Cells[a.X, a.Y]], 0.3f);
                     }
                     g.DrawLine(pen3, new PointF(a.X, a.Y + 0.5f), new PointF(a.X + 1, a.Y + 0.5f));
                 }
                 a = b;
             }
         }
     }
     Grid.RedrawBridges(g);
 }