1 | using System;
|
---|
2 | using System.Drawing;
|
---|
3 |
|
---|
4 | namespace Netron.Diagramming.Core
|
---|
5 | {
|
---|
6 | /// <summary>
|
---|
7 | /// Implements the horizontal ruler.
|
---|
8 | /// </summary>
|
---|
9 | public class HorizontalRuler : RulerBase
|
---|
10 | {
|
---|
11 |
|
---|
12 |
|
---|
13 |
|
---|
14 | public override Rectangle Rectangle
|
---|
15 | {
|
---|
16 | get
|
---|
17 | {
|
---|
18 | Rectangle rectangle;
|
---|
19 |
|
---|
20 | if (View != null)
|
---|
21 | {
|
---|
22 | rectangle = View.HorizontalRulerBounds;
|
---|
23 | }
|
---|
24 | else
|
---|
25 | {
|
---|
26 | rectangle = Rectangle.Empty;
|
---|
27 | }
|
---|
28 | return rectangle;
|
---|
29 | }
|
---|
30 | }
|
---|
31 |
|
---|
32 | public HorizontalRuler(IView view)
|
---|
33 | : base(view)
|
---|
34 | {
|
---|
35 | }
|
---|
36 |
|
---|
37 | public override void Paint(Graphics g)
|
---|
38 | {
|
---|
39 | if (View == null)
|
---|
40 | {
|
---|
41 | return;
|
---|
42 | }
|
---|
43 | IModel model = View.Model;
|
---|
44 | if (model == null)
|
---|
45 | {
|
---|
46 | return;
|
---|
47 | }
|
---|
48 |
|
---|
49 | float f1 = g.DpiX;
|
---|
50 | MeasurementsUnit measurementsUnit1 = View.RulerUnits;
|
---|
51 | GraphicsUnit graphicsUnit1 = model.MeasurementUnits;
|
---|
52 | float f2 = model.MeasurementScale;
|
---|
53 |
|
---|
54 |
|
---|
55 | Font font = ArtPalette.RulerFont;
|
---|
56 | RectangleF rec = Rectangle;
|
---|
57 | g.FillRectangle(ArtPalette.RullerFillBrush, rec);
|
---|
58 |
|
---|
59 | PointF pointF1 = View.Origin;
|
---|
60 | bool flag1 = false;
|
---|
61 | float f3 = (float)rec.Top;
|
---|
62 | float f4 = (float)rec.Bottom;
|
---|
63 | float f5;
|
---|
64 | bool flag2 = true;
|
---|
65 | GraphicsUnit graphicsUnit2;
|
---|
66 | MeasurementsUnit measurementsUnit2;
|
---|
67 | while (!flag1)
|
---|
68 | {
|
---|
69 | Measurements.MeasurementsUnitToGraphicsUnit(measurementsUnit1, out graphicsUnit2, out f5);
|
---|
70 | float f6 = Measurements.Convert(graphicsUnit2, f5, graphicsUnit1, f2, f1, 1.0F);
|
---|
71 | float f7 = View.ViewToDeviceF(View.WorldToView(new SizeF(f6, f6))).Width;
|
---|
72 | if (f7 > 4.0F)
|
---|
73 | {
|
---|
74 | PointF pointF2 = Measurements.Convert(graphicsUnit1, f2, graphicsUnit2, f5, g, pointF1);
|
---|
75 | int i = (int)Math.Floor((double)pointF2.X) + 1;
|
---|
76 | PointF pointF3 = new PointF((float)i, pointF2.Y);
|
---|
77 | pointF3 = Measurements.Convert(graphicsUnit2, f5, graphicsUnit1, f2, g, pointF3);
|
---|
78 | float f8 = View.ViewToDeviceF(View.WorldToView(pointF3)).X;
|
---|
79 | for (float f9 = (float)rec.Right; f8 < f9; f8 += f7)
|
---|
80 | {
|
---|
81 | g.DrawLine(ArtPalette.RulerPen, f8, f3, f8, f4);
|
---|
82 | if (flag2)
|
---|
83 | {
|
---|
84 | string str = i.ToString();
|
---|
85 | PointF pointF5 = new PointF(f8 + 1.0F, f3 + 1.0F);
|
---|
86 | g.DrawString(str, font, Brushes.Black, pointF5);
|
---|
87 | }
|
---|
88 | i++;
|
---|
89 | }
|
---|
90 | if (Measurements.GetSmallerUnits(measurementsUnit1, out measurementsUnit2))
|
---|
91 | {
|
---|
92 | measurementsUnit1 = measurementsUnit2;
|
---|
93 | f3 = f4 - (f4 - f3) / 2.0F;
|
---|
94 | }
|
---|
95 | else
|
---|
96 | {
|
---|
97 | flag1 = true;
|
---|
98 | }
|
---|
99 | flag2 = false;
|
---|
100 | }
|
---|
101 | else
|
---|
102 | {
|
---|
103 | flag1 = true;
|
---|
104 | }
|
---|
105 | }
|
---|
106 | g.DrawRectangle(ArtPalette.RulerPen, rec.X, rec.Y, rec.Width, rec.Height);
|
---|
107 |
|
---|
108 |
|
---|
109 |
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 | }
|
---|