FastReport

Форк
0
186 строк · 5.4 Кб
1
using System.ComponentModel;
2
using System.Drawing;
3
using System.Drawing.Drawing2D;
4
using FastReport.Utils;
5

6
namespace FastReport.Gauge.Linear
7
{
8
    /// <summary>
9
    /// Represents a linear pointer.
10
    /// </summary>
11
#if !DEBUG
12
    [DesignTimeVisible(false)]
13
#endif
14
    public class LinearPointer : GaugePointer
15
    {
16
        #region Fields
17

18
        private float left;
19
        private float top;
20
        private float height;
21
        private float width;
22

23
        #endregion // Fields
24

25
        #region Properties
26

27
        /// <summary>
28
        /// Gets o sets the height of gauge pointer.
29
        /// </summary>
30
        [Browsable(false)]
31
        public float Height
32
        {
33
            get { return height; }
34
            set { height = value; }
35
        }
36

37
        /// <summary>
38
        /// Gets or sets the width of a pointer.
39
        /// </summary>
40
        [Browsable(false)]
41
        public float Width
42
        {
43
            get { return width; }
44
            set { width = value; }
45
        }
46

47
        #endregion // Properties
48

49
        #region Constructors
50

51
        /// <summary>
52
        /// Initializes a new instance of the <see cref="LinearPointer"/>
53
        /// </summary>
54
        /// <param name="parent">The parent gauge object.</param>
55
        public LinearPointer(GaugeObject parent) : base(parent)
56
        {
57
            height = 4.0f;
58
            width = 8.0f;
59
        }
60

61
        #endregion // Constructors
62

63
        #region Private Methods
64

65
        private void DrawHorz(FRPaintEventArgs e)
66
        {
67
            IGraphics g = e.Graphics;
68
            Pen pen = e.Cache.GetPen(BorderColor, BorderWidth * e.ScaleX, DashStyle.Solid);
69

70
            left = (float)(Parent.AbsLeft + 0.5f * Units.Centimeters + (Parent.Width - 1.0f * Units.Centimeters) * (Parent.Value - Parent.Minimum) / (Parent.Maximum - Parent.Minimum)) * e.ScaleX;
71
            top = (Parent.AbsTop + Parent.Height / 2) * e.ScaleY;
72
            height = Parent.Height * 0.4f * e.ScaleY;
73
            width = Parent.Width * 0.036f * e.ScaleX;
74

75
            float dx = width / 2;
76
            float dy = height * 0.3f;
77
            Brush brush = Fill.CreateBrush(new RectangleF(left - dx, top, width, height), e.ScaleX, e.ScaleY);
78
            PointF[] p = new PointF[]
79
            {
80
                new PointF(left, top),
81
                new PointF(left + dx, top + dy),
82
                new PointF(left + dx, top + height),
83
                new PointF(left - dx, top + height),
84
                new PointF(left - dx, top + dy)
85
            };
86

87
            if ((Parent as LinearGauge).Inverted)
88
            {
89
                p[1].Y = top - dy;
90
                p[2].Y = top - height;
91
                p[3].Y = top - height;
92
                p[4].Y = top - dy;
93
            }
94

95
            GraphicsPath path = new GraphicsPath();
96
            path.AddLines(p);
97
            path.AddLine(p[4], p[0]);
98

99
            g.FillAndDrawPath(pen, brush, path);
100
        }
101

102
        private void DrawVert(FRPaintEventArgs e)
103
        {
104
            IGraphics g = e.Graphics;
105
            Pen pen = e.Cache.GetPen(BorderColor, BorderWidth * e.ScaleX, DashStyle.Solid);
106

107
            left = (Parent.AbsLeft + Parent.Width / 2) * e.ScaleX;
108
            top = (float)(Parent.AbsTop + Parent.Height - 0.5f * Units.Centimeters - (Parent.Height - 1.0f * Units.Centimeters) * (Parent.Value - Parent.Minimum) / (Parent.Maximum - Parent.Minimum)) * e.ScaleY;
109
            height = Parent.Height * 0.036f * e.ScaleY;
110
            width = Parent.Width * 0.4f * e.ScaleX;
111

112
            float dx = width * 0.3f;
113
            float dy = height / 2;
114
            Brush brush = Fill.CreateBrush(new RectangleF(left, top - dy, width, height), e.ScaleX, e.ScaleY);
115
            PointF[] p = new PointF[]
116
            {
117
                new PointF(left, top),
118
                new PointF(left + dx, top - dy),
119
                new PointF(left + width, top - dy),
120
                new PointF(left + width, top + dy),
121
                new PointF(left + dx, top + dy)
122
            };
123

124
            if ((Parent as LinearGauge).Inverted)
125
            {
126
                p[1].X = left - dx;
127
                p[2].X = left - width;
128
                p[3].X = left - width;
129
                p[4].X = left - dx;
130
            }
131

132
            GraphicsPath path = new GraphicsPath();
133
            path.AddLines(p);
134
            path.AddLine(p[4], p[0]);
135

136
            g.FillAndDrawPath(pen, brush, path);
137
        }
138

139
        #endregion // Private Methods
140

141
        #region Public Methods
142

143
        /// <inheritdoc/>
144
        public override void Assign(GaugePointer src)
145
        {
146
            base.Assign(src);
147

148
            LinearPointer s = src as LinearPointer;
149
            Height = s.Height;
150
            Width = s.Width;
151
        }
152

153
        /// <inheritdoc/>
154
        public override void Draw(FRPaintEventArgs e)
155
        {
156
            base.Draw(e);
157

158
            if (Parent.Vertical)
159
            {
160
                DrawVert(e);
161
            }
162
            else
163
            {
164
                DrawHorz(e);
165
            }
166
        }
167

168
        /// <inheritdoc/>
169
        public override void Serialize(FRWriter writer, string prefix, GaugePointer diff)
170
        {
171
            base.Serialize(writer, prefix, diff);
172

173
            LinearPointer dc = diff as LinearPointer;
174
            if (Height != dc.Height)
175
            {
176
                writer.WriteFloat(prefix + ".Height", Height);
177
            }
178
            if (Width != dc.Width)
179
            {
180
                writer.WriteFloat(prefix + ".Width", Width);
181
            }
182
        }
183

184
        #endregion // Public Methods
185
    }
186
}
187

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.