FastReport
184 строки · 7.7 Кб
1using System.Drawing;2using System.Drawing.Drawing2D;3using FastReport.Utils;4using System.ComponentModel;5
6namespace FastReport.Gauge.Radial7{
8/// <summary>9/// Represents a linear pointer.10/// </summary>11#if !DEBUG12[DesignTimeVisible(false)]13#endif14public class RadialPointer : GaugePointer15{16#region Fields17private RadialScale scale;18private bool gradAutoRotate;19#endregion // Fields20
21/// <summary>22/// Gets or sets the value, indicating that gradient should be rotated automatically23/// </summary>24[Browsable(true)]25public bool GradientAutoRotate26{27get { return gradAutoRotate; }28set { gradAutoRotate = value; }29}30
31#region Constructors32
33/// <summary>34/// Initializes a new instance of the <see cref="RadialPointer"/>35/// </summary>36/// <param name="parent">The parent gauge object.</param>37/// <param name="scale">The scale object.</param>38public RadialPointer(GaugeObject parent, RadialScale scale) : base(parent)39{40this.scale = scale;41gradAutoRotate = true;42}43
44#endregion // Constructors45
46#region Private Methods47
48private void DrawHorz(FRPaintEventArgs e)49{50IGraphics g = e.Graphics;51Pen pen = e.Cache.GetPen(BorderColor, BorderWidth * e.ScaleX, DashStyle.Solid);52
53PointF center = (Parent as RadialGauge).Center;54float circleWidth = Parent.Width / 16f;55float circleHeight = Parent.Height / 16f;56RectangleF pointerCircle = new RectangleF(center.X - circleWidth / 2 * e.ScaleX, center.Y - circleHeight / 2 * e.ScaleY, circleWidth * e.ScaleX, circleHeight * e.ScaleY);57
58//double rotateTo = (scale.AverageValue - Parent.Minimum);59double startAngle = -135 * RadialGauge.Radians;60double angle = (Parent.Value - Parent.Minimum) / scale.StepValue * scale.MajorStep * RadialGauge.Radians;61if ((Parent as RadialGauge).Type == RadialGaugeType.Semicircle)62{63if ((Parent as RadialGauge).Position == RadialGaugePosition.Bottom || (Parent as RadialGauge).Position == RadialGaugePosition.Top)64{65startAngle = -90 * RadialGauge.Radians;66if ((Parent as RadialGauge).Position == RadialGaugePosition.Bottom)67angle *= -1;68}69else if ((Parent as RadialGauge).Position == RadialGaugePosition.Left)70startAngle = -180 * RadialGauge.Radians;71else if ((Parent as RadialGauge).Position == RadialGaugePosition.Right)72{73startAngle = -180 * RadialGauge.Radians;74angle *= -1;75}76}77else if (RadialUtils.IsQuadrant(Parent))78{79if (RadialUtils.IsLeft(Parent) && RadialUtils.IsTop(Parent))80startAngle = -90 * RadialGauge.Radians;81else if (RadialUtils.IsLeft(Parent) && RadialUtils.IsBottom(Parent))82startAngle = -180 * RadialGauge.Radians;83else if (RadialUtils.IsRight(Parent) && RadialUtils.IsTop(Parent))84startAngle = 90 * RadialGauge.Radians;85else if (RadialUtils.IsRight(Parent) && RadialUtils.IsBottom(Parent))86{87startAngle = 180 * RadialGauge.Radians;88angle *= -1;89}90}91//double startAngle = rotateTo / scale.StepValue * -scale.MajorStep * RadialGauge.Radians;92
93float ptrLineY = center.Y - pointerCircle.Width / 2 - pointerCircle.Width / 5;94float ptrLineY1 = scale.AvrTick.Y + scale.MinorTicks.Length * 1.7f;95float ptrLineWidth = circleWidth / 3 * e.ScaleX;96PointF[] pointerPerpStrt = new PointF[2];97pointerPerpStrt[0] = new PointF(center.X - ptrLineWidth, ptrLineY);98pointerPerpStrt[1] = new PointF(center.X + ptrLineWidth, ptrLineY);99
100PointF[] pointerPerpEnd = new PointF[2];101pointerPerpEnd[0] = new PointF(center.X - ptrLineWidth / 3, ptrLineY1);102pointerPerpEnd[1] = new PointF(center.X + ptrLineWidth / 3, ptrLineY1);103
104
105pointerPerpStrt = RadialUtils.RotateVector(pointerPerpStrt, startAngle, center);106pointerPerpEnd = RadialUtils.RotateVector(pointerPerpEnd, startAngle, center);107
108PointF[] rotatedPointerPerpStrt = RadialUtils.RotateVector(pointerPerpStrt, angle, center);109PointF[] rotatedPointerPerpEnd = RadialUtils.RotateVector(pointerPerpEnd, angle, center);110
111//calc brush rect112float x = 0, y = 0, dx = 0, dy = 0;113if (angle / RadialGauge.Radians >= 0 && angle / RadialGauge.Radians < 45)114{115x = rotatedPointerPerpEnd[1].X;116y = rotatedPointerPerpEnd[0].Y - (rotatedPointerPerpEnd[0].Y - pointerCircle.Y);117dx = pointerCircle.X + pointerCircle.Width - rotatedPointerPerpEnd[0].X;118dy = rotatedPointerPerpEnd[0].Y - pointerCircle.Y;119}120else if (angle / RadialGauge.Radians >= 45 && angle / RadialGauge.Radians < 90)121{122x = rotatedPointerPerpEnd[0].X;123y = rotatedPointerPerpEnd[1].Y;124dx = pointerCircle.X + pointerCircle.Width - rotatedPointerPerpEnd[0].X;125dy = pointerCircle.Y + pointerCircle.Height - rotatedPointerPerpEnd[0].Y;126}127else if (angle / RadialGauge.Radians >= 90 && angle / RadialGauge.Radians < 135)128{129x = rotatedPointerPerpEnd[0].X;130y = rotatedPointerPerpEnd[1].Y;131dx = pointerCircle.X + pointerCircle.Width - rotatedPointerPerpEnd[0].X;132dy = pointerCircle.Y + pointerCircle.Height - rotatedPointerPerpEnd[1].Y;133}134else if (angle / RadialGauge.Radians >= 135 && angle / RadialGauge.Radians < 225)135{136x = pointerCircle.X;137y = rotatedPointerPerpEnd[0].Y;138dx = rotatedPointerPerpEnd[1].X - pointerCircle.X;139dy = pointerCircle.Y + pointerCircle.Height - rotatedPointerPerpEnd[0].Y;140}141else if (angle / RadialGauge.Radians >= 225)142{143x = pointerCircle.X;144y = pointerCircle.Y;145dx = rotatedPointerPerpEnd[0].X - pointerCircle.X;146dy = rotatedPointerPerpEnd[1].Y - pointerCircle.Y;147}148RectangleF brushRect = new RectangleF(x, y, dx, dy);149if (gradAutoRotate && Fill is LinearGradientFill)150{151(Fill as LinearGradientFill).Angle = (int)(startAngle / RadialGauge.Radians + angle / RadialGauge.Radians) + 90;152}153Brush brush = Fill.CreateBrush(brushRect, e.ScaleX, e.ScaleY);154
155PointF[] p = new PointF[]156{157rotatedPointerPerpStrt[0],158rotatedPointerPerpStrt[1],159rotatedPointerPerpEnd[1],160rotatedPointerPerpEnd[0],161};162GraphicsPath path = new GraphicsPath();163path.AddLines(p);164path.AddLine(p[3], p[0]);165
166g.FillAndDrawEllipse(pen, brush, pointerCircle);167
168g.FillAndDrawPath(pen, brush, path);169}170
171#endregion // Private Methods172
173#region Public Methods174
175/// <inheritdoc/>176public override void Draw(FRPaintEventArgs e)177{178base.Draw(e);179DrawHorz(e);180}181
182#endregion // Public Methods183}184}
185