public int GetBlock(int x, int y, int scroll) { int index = 0; for (; index < blocks.Count; ++index) { int shift = 25; if (blocks[index] is SquareBlock) { shift = 50; if (y < (shift * 2 + DIST_BETWEEN_BLOCKS * index - SCROLL_SCALE * scroll + 25) * 3 / 4 + 12 && y > (DIST_BETWEEN_BLOCKS * index - SCROLL_SCALE * scroll + 25) * 3 / 4 + 12 && x < (shift + graph.GetNodeShift(index) * 100) * 3 / 4 + 250 - 172 && x > (-shift + graph.GetNodeShift(index) * 100) * 3 / 4 + 250 - 172) { return(index); } } else { if (y < (shift * 2 + DIST_BETWEEN_BLOCKS * index - SCROLL_SCALE * scroll + 50) * 3 / 4 + 12 && y > (DIST_BETWEEN_BLOCKS * index - SCROLL_SCALE * scroll + 50) * 3 / 4 + 12 && x < (shift * 2 + graph.GetNodeShift(index) * 100) * 3 / 4 + 250 - 172 && x > (-shift * 2 + graph.GetNodeShift(index) * 100) * 3 / 4 + 250 - 172) { return(index); } } } return(-1); }
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); }