1 | using System;
|
---|
2 | using System.Drawing;
|
---|
3 | using System.Drawing.Drawing2D;
|
---|
4 |
|
---|
5 | namespace Netron.Diagramming.Core {
|
---|
6 | public class Grid {
|
---|
7 | // ------------------------------------------------------------------
|
---|
8 | /// <summary>
|
---|
9 | /// Constructor.
|
---|
10 | /// </summary>
|
---|
11 | // ------------------------------------------------------------------
|
---|
12 | public Grid() {
|
---|
13 | }
|
---|
14 |
|
---|
15 | public static void Paint(
|
---|
16 | Graphics g,
|
---|
17 | RectangleF area,
|
---|
18 | float horizontalSpacing,
|
---|
19 | float verticalSpacing,
|
---|
20 | float penWidth) {
|
---|
21 | //ControlPaint.DrawGrid(
|
---|
22 | // g,
|
---|
23 | // area,
|
---|
24 | // new Size(20, 20),
|
---|
25 | // Color.Wheat);
|
---|
26 |
|
---|
27 | //g.SmoothingMode = SmoothingMode.HighQuality;
|
---|
28 | //g.CompositingQuality = CompositingQuality.HighQuality;
|
---|
29 | //g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
---|
30 | g.SetClip(area);
|
---|
31 | float sideLength = Math.Min(area.Width, area.Height);
|
---|
32 | float horizSpacing = sideLength / horizontalSpacing;
|
---|
33 | float vertSpacing = sideLength / verticalSpacing;
|
---|
34 |
|
---|
35 | Pen majorPen = new Pen(Color.DarkGray);
|
---|
36 | majorPen.Width = penWidth;
|
---|
37 | majorPen.DashStyle = DashStyle.Dot;
|
---|
38 |
|
---|
39 | float top = area.Top; // The top y coord.
|
---|
40 | float bottom = area.Bottom; // The bottom y coord.
|
---|
41 | float left = area.Left; // The left y coord.
|
---|
42 | float right = area.Right; // The right y coord.
|
---|
43 | PointF p1; // The starting point for the grid line.
|
---|
44 | PointF p2; // The end point for the grid line.
|
---|
45 |
|
---|
46 | // Draw the horizontal lines, starting at the top.
|
---|
47 | for (float i = top; i <= bottom; i += horizontalSpacing) {
|
---|
48 | p1 = new PointF(left, i);
|
---|
49 | p2 = new PointF(right, i);
|
---|
50 | g.DrawLine(majorPen, p1, p2);
|
---|
51 | }
|
---|
52 |
|
---|
53 | // Draw the major vertical lines, starting at the left edge.
|
---|
54 | for (float i = left; i <= right; i += verticalSpacing) {
|
---|
55 | p1 = new PointF(i, top);
|
---|
56 | p2 = new PointF(i, bottom);
|
---|
57 | g.DrawLine(majorPen, p1, p2);
|
---|
58 | }
|
---|
59 | g.ResetClip();
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|