public int[] GetEdge(int x, int y, int scroll) { int[] edge = new int[2]; int index = ((y - 12) * 4 / 3 + SCROLL_SCALE * scroll - 50) / DIST_BETWEEN_BLOCKS; edge[0] = index; if (graph.GetAdj()[index].Count == 0) { edge[0] = -1; return(edge); } else if (graph.GetAdj()[index].Count == 1) { edge[1] = graph.GetAdj()[index][0]; return(edge); } else { if (graph.GetNodeType(index) != 5) { if (x >= 250) { edge[1] = graph.GetAdj()[index][0]; } else { edge[1] = graph.GetAdj()[index][1]; } } else { if (x >= 250 + 50 * 3 / 4) { edge[1] = graph.GetAdj()[index][1]; } else { edge[1] = graph.GetAdj()[index][0]; } } } return(edge); }
public Bitmap Draw(OrientedGraph graph, int scroll, int selectedID, int[] selectedEdge) { btm = new Bitmap(500, 800); gr = Graphics.FromImage(btm); for (int i = 0; i < graph.CountNodes(); i++) { Pen pen; if (i == selectedID) { pen = new Pen(Color.Red, 3); } else { pen = new Pen(Color.Black, 3); } switch (graph.GetNodeType(i)) { case 1: { gr.DrawRectangle(pen, 200 + graph.GetNodeShift(i) * 100, 25 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll, 100, 100); break; } case 2: { Point[] p = new Point[4]; p[0] = new Point(200 + graph.GetNodeShift(i) * 100, 75 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll); p[1] = new Point(250 + graph.GetNodeShift(i) * 100, 50 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll); p[2] = new Point(300 + graph.GetNodeShift(i) * 100, 75 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll); p[3] = new Point(250 + graph.GetNodeShift(i) * 100, 100 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll); gr.DrawPolygon(pen, p); break; } case 3: { gr.DrawEllipse(pen, 200 + graph.GetNodeShift(i) * 100, 50 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll, 100, 50); break; } case 5: { Point[] p = new Point[4]; p[0] = new Point(200 + graph.GetNodeShift(i) * 100, 75 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll); p[1] = new Point(250 + graph.GetNodeShift(i) * 100, 50 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll); p[2] = new Point(300 + graph.GetNodeShift(i) * 100, 75 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll); p[3] = new Point(250 + graph.GetNodeShift(i) * 100, 100 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll); gr.DrawPolygon(pen, p); break; } } for (int j = 0; j < graph.GetAdj()[i].Count; j++) { if (selectedEdge[0] == i && selectedEdge[1] == graph.GetAdj()[i][j]) { pen = Pens.Red; } else { pen = Pens.Black; } Point p1 = new Point(250 + graph.GetNodeShift(i) * 100, 75 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll); Point p2 = new Point(250 + graph.GetNodeShift(graph.GetAdj()[i][j]) * 100, 75 + DIST_BETWEEN_BLOCKS * graph.GetAdj()[i][j] - SCROLL_SCALE * scroll); Drawline(pen, graph.GetNodeType(i), graph.GetNodeType(graph.GetAdj()[i][j]), p1, p2); } } return(btm); }