DotNet 4.8.1 build of DotNetBar
This commit is contained in:
@@ -0,0 +1,784 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DevComponents.Instrumentation
|
||||
{
|
||||
internal class GaugeBarRenderer : GaugePointerRenderer
|
||||
{
|
||||
#region Private variables
|
||||
|
||||
private float _StartAngle;
|
||||
private float _SweepAngle;
|
||||
private float _RoundAngle;
|
||||
|
||||
private double _Marker;
|
||||
private double _Origin;
|
||||
|
||||
private Rectangle _Bounds;
|
||||
|
||||
#endregion
|
||||
|
||||
internal GaugeBarRenderer(GaugePointer gaugePointer)
|
||||
: base(gaugePointer)
|
||||
{
|
||||
}
|
||||
|
||||
#region Internal properties
|
||||
|
||||
#region Bounds
|
||||
|
||||
internal Rectangle Bounds
|
||||
{
|
||||
get { return (_Bounds); }
|
||||
set { _Bounds = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Marker
|
||||
|
||||
internal double Marker
|
||||
{
|
||||
get { return (_Marker); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Origin
|
||||
|
||||
internal double Origin
|
||||
{
|
||||
get { return (_Origin); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RoundAngle
|
||||
|
||||
internal float RoundAngle
|
||||
{
|
||||
get { return (_RoundAngle); }
|
||||
set { _RoundAngle = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region RecalcLayout
|
||||
|
||||
public override void RecalcLayout()
|
||||
{
|
||||
base.RecalcLayout();
|
||||
|
||||
if (Scale is GaugeCircularScale)
|
||||
CalcCircularMarkerPoint(Scale as GaugeCircularScale);
|
||||
|
||||
else if (Scale is GaugeLinearScale)
|
||||
CalcLinearMarkerPoint(Scale as GaugeLinearScale);
|
||||
}
|
||||
|
||||
#region CalcCircularMarkerPoint
|
||||
|
||||
private void CalcCircularMarkerPoint(GaugeCircularScale scale)
|
||||
{
|
||||
int radius = Radius;
|
||||
|
||||
switch (GaugePointer.Placement)
|
||||
{
|
||||
case DisplayPlacement.Near:
|
||||
radius -= (Width / 2);
|
||||
break;
|
||||
|
||||
case DisplayPlacement.Far:
|
||||
radius += (Width / 2);
|
||||
break;
|
||||
}
|
||||
|
||||
_Bounds.Size = new Size(radius * 2, radius * 2);
|
||||
_Bounds.Location = new Point(scale.Center.X - radius, scale.Center.Y - radius);
|
||||
|
||||
Dpt = scale.SweepAngle / scale.Spread;
|
||||
|
||||
_Origin = GetOriginInterval() - scale.MinValue;
|
||||
_Marker = GetInterval(Value) - scale.MinValue;
|
||||
|
||||
if (scale.Reversed == true)
|
||||
{
|
||||
IntervalAngle = (float)(scale.StartAngle + scale.SweepAngle - (_Marker * Dpt));
|
||||
_StartAngle = (float)(scale.StartAngle + scale.SweepAngle - (_Origin * Dpt));
|
||||
}
|
||||
else
|
||||
{
|
||||
IntervalAngle = (float)(scale.StartAngle + _Marker * Dpt);
|
||||
_StartAngle = (float)(scale.StartAngle + _Origin * Dpt);
|
||||
}
|
||||
|
||||
IntervalPoint = scale.GetPoint(radius, IntervalAngle);
|
||||
_SweepAngle = IntervalAngle - _StartAngle;
|
||||
|
||||
if (GaugePointer.BarStyle != BarPointerStyle.Square)
|
||||
{
|
||||
_RoundAngle = 0;
|
||||
|
||||
if (_SweepAngle != 0)
|
||||
{
|
||||
float x = (float)((360 * Width / 2) / (radius * 2 * Math.PI));
|
||||
|
||||
_RoundAngle = (_SweepAngle > 0)
|
||||
? Math.Min(x, _SweepAngle) : Math.Max(-x, _SweepAngle);
|
||||
|
||||
_SweepAngle -= _RoundAngle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CalcLinearMarkerPoint
|
||||
|
||||
protected virtual void CalcLinearMarkerPoint(GaugeLinearScale scale)
|
||||
{
|
||||
if (scale.Orientation == Orientation.Horizontal)
|
||||
CalcHorizontalMarkerPoint(scale);
|
||||
else
|
||||
CalcVerticalMarkerPoint(scale);
|
||||
}
|
||||
|
||||
#region CalcHorizontalMarkerPoint
|
||||
|
||||
protected virtual void CalcHorizontalMarkerPoint(GaugeLinearScale scale)
|
||||
{
|
||||
int offset = GaugePointer.Offset;
|
||||
|
||||
int y = scale.ScaleBounds.Y + scale.ScaleBounds.Height / 2 + offset;
|
||||
|
||||
switch (GaugePointer.Placement)
|
||||
{
|
||||
case DisplayPlacement.Near:
|
||||
y -= Width;
|
||||
break;
|
||||
|
||||
case DisplayPlacement.Center:
|
||||
y -= (Width / 2);
|
||||
break;
|
||||
|
||||
case DisplayPlacement.Far:
|
||||
break;
|
||||
}
|
||||
|
||||
Dpt = scale.ScaleBounds.Width / scale.Spread;
|
||||
|
||||
_Origin = GetOriginInterval() - scale.MinValue;
|
||||
_Marker = GetInterval(Value) - scale.MinValue;
|
||||
|
||||
CalcHorizontalMarkerBounds(scale, y);
|
||||
}
|
||||
|
||||
#region CalcHorizontalMarkerBounds
|
||||
|
||||
protected virtual void CalcHorizontalMarkerBounds(GaugeLinearScale scale, int y)
|
||||
{
|
||||
double origin = _Origin;
|
||||
double marker = _Marker;
|
||||
|
||||
_RoundAngle = 0;
|
||||
|
||||
if (marker < origin)
|
||||
{
|
||||
_RoundAngle += 180;
|
||||
|
||||
SwapDoubles(ref marker, ref origin);
|
||||
}
|
||||
|
||||
int len = (int)((marker - origin) * Dpt);
|
||||
|
||||
int x = (scale.Reversed == true)
|
||||
? scale.ScaleBounds.Right - (int)(origin * Dpt) - len
|
||||
: scale.ScaleBounds.X + (int)(origin * Dpt);
|
||||
|
||||
_Bounds = new Rectangle(0, 0, len, Width);
|
||||
_Bounds.Location = new Point(x, y);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region CalcVerticalMarkerPoint
|
||||
|
||||
protected virtual void CalcVerticalMarkerPoint(GaugeLinearScale scale)
|
||||
{
|
||||
int offset = GaugePointer.Offset;
|
||||
|
||||
int x = scale.ScaleBounds.X + scale.ScaleBounds.Width / 2 + offset;
|
||||
|
||||
switch (GaugePointer.Placement)
|
||||
{
|
||||
case DisplayPlacement.Near:
|
||||
x -= Width;
|
||||
break;
|
||||
|
||||
case DisplayPlacement.Center:
|
||||
x -= (Width / 2);
|
||||
break;
|
||||
|
||||
case DisplayPlacement.Far:
|
||||
break;
|
||||
}
|
||||
|
||||
Dpt = scale.ScaleBounds.Height / scale.Spread;
|
||||
|
||||
_Origin = GetOriginInterval() - scale.MinValue;
|
||||
_Marker = GetInterval(Value) - scale.MinValue;
|
||||
|
||||
CalcVerticalMarkerBounds(scale, x);
|
||||
}
|
||||
|
||||
#region CalcVerticalMarkerBounds
|
||||
|
||||
protected virtual void CalcVerticalMarkerBounds(GaugeLinearScale scale, int x)
|
||||
{
|
||||
double origin = _Origin;
|
||||
double marker = _Marker;
|
||||
|
||||
_RoundAngle = -90;
|
||||
|
||||
if (marker < origin)
|
||||
{
|
||||
_RoundAngle += 180;
|
||||
|
||||
SwapDoubles(ref marker, ref origin);
|
||||
}
|
||||
|
||||
int len = (int)((marker - origin) * Dpt);
|
||||
|
||||
int y = (scale.Reversed == true)
|
||||
? scale.ScaleBounds.Top + (int)(marker * Dpt) - len
|
||||
: scale.ScaleBounds.Bottom - (int)(marker * Dpt);
|
||||
|
||||
_Bounds = new Rectangle(0, 0, Width, len);
|
||||
_Bounds.Location = new Point(x, y);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetOriginInterval
|
||||
|
||||
private double GetOriginInterval()
|
||||
{
|
||||
switch (GaugePointer.Origin)
|
||||
{
|
||||
case PointerOrigin.Minimum:
|
||||
return (GetInterval(double.MinValue));
|
||||
|
||||
case PointerOrigin.Maximum:
|
||||
return (GetInterval(double.MaxValue));
|
||||
|
||||
default:
|
||||
return (GetInterval(GaugePointer.OriginInterval));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region RenderCircular
|
||||
|
||||
public override void RenderCircular(PaintEventArgs e)
|
||||
{
|
||||
Graphics g = e.Graphics;
|
||||
|
||||
GaugeCircularScale scale = Scale as GaugeCircularScale;
|
||||
|
||||
if (scale != null)
|
||||
{
|
||||
if (Width > 0 && Radius > 0 && (_SweepAngle != 0 || _RoundAngle != 0))
|
||||
{
|
||||
using (GraphicsPath path = GetCircularBarPath(scale))
|
||||
RenderBar(g, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region GetCircularBarPath
|
||||
|
||||
private GraphicsPath GetCircularBarPath(GaugeCircularScale scale)
|
||||
{
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
|
||||
Rectangle r = _Bounds;
|
||||
r.Inflate(Width / 2, Width / 2);
|
||||
|
||||
path.AddArc(r, _StartAngle, _SweepAngle);
|
||||
|
||||
if (_RoundAngle != 0)
|
||||
{
|
||||
if (GaugePointer.BarStyle != BarPointerStyle.Square)
|
||||
{
|
||||
Point pt = scale.GetPoint(_Bounds.Width/2, _StartAngle + _SweepAngle);
|
||||
Point pt2 = scale.GetPoint(_Bounds.Width/2, _StartAngle + _SweepAngle + _RoundAngle);
|
||||
|
||||
int dx = pt2.X - pt.X;
|
||||
int dy = pt2.Y - pt.Y;
|
||||
|
||||
double n = Math.Max(1, Math.Sqrt((dx * dx) + (dy * dy)));
|
||||
|
||||
float angle = (_StartAngle + _SweepAngle) % 360;
|
||||
|
||||
using (GraphicsPath path2 = new GraphicsPath())
|
||||
{
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.RotateAt(angle, pt);
|
||||
|
||||
r.X = pt.X - Width/2 + 1;
|
||||
r.Y = pt.Y - (int) n;
|
||||
r.Width = Width - 1;
|
||||
r.Height = (int) (n*2);
|
||||
|
||||
if (GaugePointer.BarStyle == BarPointerStyle.Rounded)
|
||||
{
|
||||
path2.AddArc(r, 0, _SweepAngle + _RoundAngle > 0 ? 180 : -180);
|
||||
}
|
||||
else
|
||||
{
|
||||
path2.AddLine(new Point(r.Right, r.Y + r.Height/2),
|
||||
new Point(r.X + Width/2, _SweepAngle + _RoundAngle > 0 ? r.Bottom : r.Y));
|
||||
}
|
||||
|
||||
path2.Transform(matrix);
|
||||
|
||||
path.AddPath(path2, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
r = _Bounds;
|
||||
r.Inflate(-Width / 2, -Width / 2);
|
||||
|
||||
path.AddArc(r, _StartAngle + _SweepAngle, -_SweepAngle);
|
||||
|
||||
path.CloseFigure();
|
||||
|
||||
return (path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region RenderLinear
|
||||
|
||||
public override void RenderLinear(PaintEventArgs e)
|
||||
{
|
||||
Graphics g = e.Graphics;
|
||||
|
||||
GaugeLinearScale scale = Scale as GaugeLinearScale;
|
||||
|
||||
if (scale != null)
|
||||
{
|
||||
if (_Bounds.Width > 0 && _Bounds.Height > 0)
|
||||
{
|
||||
using (GraphicsPath path = GetLinearBarPath(scale, _Bounds))
|
||||
RenderBar(g, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region GetLinearBarPath
|
||||
|
||||
private GraphicsPath GetLinearBarPath(GaugeLinearScale scale, Rectangle b)
|
||||
{
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
|
||||
if (GaugePointer.BarStyle == BarPointerStyle.Square)
|
||||
{
|
||||
path.AddRectangle(b);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ((scale.Orientation == Orientation.Horizontal)
|
||||
? GetHorizontalBarPath(path, b)
|
||||
: GetVerticalBarPath(path, b));
|
||||
}
|
||||
|
||||
return (path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetHorizontalBarPath
|
||||
|
||||
private GraphicsPath GetHorizontalBarPath(GraphicsPath path, Rectangle b)
|
||||
{
|
||||
if (_Marker < _Origin != Scale.Reversed)
|
||||
{
|
||||
int x = Math.Min(b.X + Width / 2, b.Right);
|
||||
|
||||
Point[] pts = new Point[] {
|
||||
new Point(x, b.Y),
|
||||
new Point (b.Right, b.Y),
|
||||
new Point (b.Right, b.Bottom),
|
||||
new Point (x, b.Bottom)};
|
||||
|
||||
path.AddLines(pts);
|
||||
|
||||
Rectangle r = new Rectangle(b.X, b.Y, (x - b.X) * 2, Width);
|
||||
|
||||
if (GaugePointer.BarStyle == BarPointerStyle.Rounded)
|
||||
{
|
||||
path.AddArc(r, 90, 180);
|
||||
}
|
||||
else
|
||||
{
|
||||
path.AddLine(new Point(r.X + r.Width/2, r.Bottom),
|
||||
new Point(r.X, r.Y + r.Height/2));
|
||||
}
|
||||
|
||||
path.CloseAllFigures();
|
||||
}
|
||||
else
|
||||
{
|
||||
int x = Math.Max(b.Right - Width / 2, b.X);
|
||||
|
||||
Point[] pts = new Point[] {
|
||||
new Point(x, b.Bottom),
|
||||
new Point (b.X, b.Bottom),
|
||||
new Point (b.X, b.Y),
|
||||
new Point (x, b.Y)};
|
||||
|
||||
path.AddLines(pts);
|
||||
|
||||
int n = b.Right - x;
|
||||
|
||||
Rectangle r = new Rectangle(x - n, b.Y, n * 2, Width);
|
||||
|
||||
if (GaugePointer.BarStyle == BarPointerStyle.Rounded)
|
||||
{
|
||||
path.AddArc(r, 270, 180);
|
||||
}
|
||||
else
|
||||
{
|
||||
path.AddLine(new Point(r.X + r.Width / 2, r.Y),
|
||||
new Point(r.Right, r.Y + r.Height / 2));
|
||||
}
|
||||
|
||||
path.CloseAllFigures();
|
||||
}
|
||||
|
||||
return (path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetVerticalBarPath
|
||||
|
||||
private GraphicsPath GetVerticalBarPath(GraphicsPath path, Rectangle b)
|
||||
{
|
||||
if (_Marker < _Origin != Scale.Reversed)
|
||||
{
|
||||
int y = Math.Max(b.Bottom - Width / 2, b.Y);
|
||||
|
||||
Point[] pts = new Point[] {
|
||||
new Point(b.X, y),
|
||||
new Point (b.X, b.Y),
|
||||
new Point (b.Right, b.Y),
|
||||
new Point (b.Right, y)};
|
||||
|
||||
path.AddLines(pts);
|
||||
|
||||
int n = b.Bottom - y;
|
||||
|
||||
Rectangle r = new Rectangle(b.X, y - n, Width, n * 2);
|
||||
|
||||
if (GaugePointer.BarStyle == BarPointerStyle.Rounded)
|
||||
{
|
||||
path.AddArc(r, 0, 180);
|
||||
}
|
||||
else
|
||||
{
|
||||
path.AddLine(new Point(r.Right, r.Y + r.Height / 2),
|
||||
new Point(r.X + r.Width / 2, r.Bottom ));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int y = Math.Min(b.Y + Width / 2, b.Bottom);
|
||||
|
||||
Point[] pts = new Point[] {
|
||||
new Point(b.Right, y),
|
||||
new Point (b.Right, b.Bottom),
|
||||
new Point (b.X, b.Bottom),
|
||||
new Point (b.X, y)};
|
||||
|
||||
path.AddLines(pts);
|
||||
|
||||
Rectangle r = new Rectangle(b.X, b.Y, Width, (y - b.Y) * 2);
|
||||
|
||||
if (GaugePointer.BarStyle == BarPointerStyle.Rounded)
|
||||
{
|
||||
path.AddArc(r, 180, 180);
|
||||
}
|
||||
else
|
||||
{
|
||||
path.AddLine(new Point(r.X, r.Y + r.Height / 2),
|
||||
new Point(r.X + r.Width / 2, r.Y));
|
||||
}
|
||||
}
|
||||
|
||||
path.CloseAllFigures();
|
||||
|
||||
return (path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region RenderBar
|
||||
|
||||
#region RenderBar
|
||||
|
||||
protected void RenderBar(Graphics g, GraphicsPath path)
|
||||
{
|
||||
RenderBar(g, path, GetPointerFillColor(GaugePointer.Value));
|
||||
}
|
||||
|
||||
protected void RenderBar(Graphics g, GraphicsPath path, GradientFillColor fillColor)
|
||||
{
|
||||
|
||||
if (fillColor.End.IsEmpty == true || fillColor.Color1 == fillColor.Color2 ||
|
||||
fillColor.GradientFillType == GradientFillType.None)
|
||||
{
|
||||
using (Brush br = new SolidBrush(fillColor.Color1))
|
||||
g.FillPath(br, path);
|
||||
}
|
||||
else
|
||||
{
|
||||
GradientFillType fillType = (fillColor.GradientFillType == GradientFillType.Auto)
|
||||
? GradientFillType.Center
|
||||
: fillColor.GradientFillType;
|
||||
switch (fillType)
|
||||
{
|
||||
case GradientFillType.Auto:
|
||||
case GradientFillType.StartToEnd:
|
||||
RenderBarStartToEnd(g, path, fillColor);
|
||||
break;
|
||||
|
||||
case GradientFillType.Angle:
|
||||
RenderBarByAngle(g, path, fillColor);
|
||||
break;
|
||||
|
||||
case GradientFillType.Center:
|
||||
RenderBarByCenter(g, path, fillColor);
|
||||
break;
|
||||
|
||||
case GradientFillType.HorizontalCenter:
|
||||
RenderBarByHc(g, path, fillColor);
|
||||
break;
|
||||
|
||||
case GradientFillType.VerticalCenter:
|
||||
RenderBarByVc(g, path, fillColor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (fillColor.BorderWidth > 0)
|
||||
{
|
||||
using (Pen pen = new Pen(fillColor.BorderColor, fillColor.BorderWidth))
|
||||
g.DrawPath(pen, path);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RenderBarStartToEnd
|
||||
|
||||
private void RenderBarStartToEnd(Graphics g,
|
||||
GraphicsPath path, GradientFillColor fillColor)
|
||||
{
|
||||
if (Scale is GaugeCircularScale)
|
||||
{
|
||||
using (PathGradientBrush br = ((GaugeCircularScale)Scale).CreateGradient(
|
||||
Scale.GaugeControl.Frame.Bounds, _StartAngle, _SweepAngle, fillColor, Width * 2))
|
||||
{
|
||||
if (GaugePointer.BarStyle == BarPointerStyle.Rounded)
|
||||
{
|
||||
using (Brush br2 = new SolidBrush(fillColor.Color2))
|
||||
g.FillPath(br2, path);
|
||||
}
|
||||
|
||||
g.FillPath(br, path);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Rectangle t = Rectangle.Round(path.GetBounds());
|
||||
|
||||
float angle = _RoundAngle + (Scale.Reversed ? 180 : 0);
|
||||
|
||||
using (Brush br = fillColor.GetBrush(t, (int)angle))
|
||||
g.FillPath(br, path);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RenderBarByAngle
|
||||
|
||||
private void RenderBarByAngle(Graphics g, GraphicsPath path, GradientFillColor fillColor)
|
||||
{
|
||||
int n = Width / 2;
|
||||
|
||||
Rectangle t = Rectangle.Round(path.GetBounds());
|
||||
t.Inflate(n, n);
|
||||
|
||||
using (Brush br = fillColor.GetBrush(t))
|
||||
g.FillPath(br, path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RenderBarByCenter
|
||||
|
||||
protected virtual void RenderBarByCenter(Graphics g, GraphicsPath path, GradientFillColor fillColor)
|
||||
{
|
||||
using (PathGradientBrush br = new PathGradientBrush(path))
|
||||
{
|
||||
br.WrapMode = WrapMode.TileFlipXY;
|
||||
|
||||
br.CenterColor = fillColor.Color1;
|
||||
br.SurroundColors = new Color[] {fillColor.Color2};
|
||||
|
||||
if (Scale is GaugeCircularScale)
|
||||
{
|
||||
br.CenterPoint = Scale.Center;
|
||||
|
||||
float m = (float)Width / (_Bounds.Width / 2);
|
||||
|
||||
Blend blnd = new Blend();
|
||||
blnd.Positions = new float[] { 0f, m, 1f };
|
||||
blnd.Factors = new float[] { 1f, 0f, 0f };
|
||||
br.Blend = blnd;
|
||||
}
|
||||
|
||||
g.FillPath(br, path);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RenderBarByHc
|
||||
|
||||
private void RenderBarByHc(Graphics g, GraphicsPath path, GradientFillColor fillColor)
|
||||
{
|
||||
Rectangle t = Rectangle.Round(path.GetBounds());
|
||||
t.Height /= 2;
|
||||
|
||||
using (LinearGradientBrush br = new
|
||||
LinearGradientBrush(t, fillColor.Color1, fillColor.Color2, 90))
|
||||
{
|
||||
br.WrapMode = WrapMode.TileFlipXY;
|
||||
|
||||
g.FillPath(br, path);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RenderBarByVc
|
||||
|
||||
private void RenderBarByVc(Graphics g, GraphicsPath path, GradientFillColor fillColor)
|
||||
{
|
||||
Rectangle t = Rectangle.Round(path.GetBounds());
|
||||
t.Width /= 2;
|
||||
|
||||
using (LinearGradientBrush br = new
|
||||
LinearGradientBrush(t, fillColor.Color1, fillColor.Color2, 0f))
|
||||
{
|
||||
br.WrapMode = WrapMode.TileFlipXY;
|
||||
|
||||
g.FillPath(br, path);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetPointerPath
|
||||
|
||||
public override GraphicsPath GetPointerPath()
|
||||
{
|
||||
if (PointerPath == null)
|
||||
{
|
||||
if (Width > 0)
|
||||
{
|
||||
PointerPath = Scale.GaugeControl.OnGetPointerPath(GaugePointer, Scale.Bounds);
|
||||
|
||||
if (PointerPath == null)
|
||||
{
|
||||
if (Scale is GaugeCircularScale)
|
||||
GetCPointerPath(Scale as GaugeCircularScale);
|
||||
else
|
||||
GetLPointerPath(Scale as GaugeLinearScale);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return (PointerPath);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetCPointerPath
|
||||
|
||||
private void GetCPointerPath(GaugeCircularScale scale)
|
||||
{
|
||||
if (Radius > 0 && (_SweepAngle != 0 || _RoundAngle != 0))
|
||||
PointerPath = GetCircularBarPath(scale);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetLPointerPath
|
||||
|
||||
private void GetLPointerPath(GaugeLinearScale scale)
|
||||
{
|
||||
if (_Bounds.Width > 0 && _Bounds.Height > 0)
|
||||
PointerPath = GetLinearBarPath(scale, _Bounds);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnMouseDown
|
||||
|
||||
internal override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
|
||||
GaugePointer.ValueEx = GetValueFromPoint(e.Location);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region Enums
|
||||
|
||||
public enum BarPointerStyle
|
||||
{
|
||||
Square,
|
||||
Rounded,
|
||||
Pointed
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
@@ -0,0 +1,417 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DevComponents.Instrumentation
|
||||
{
|
||||
internal class GaugeMarkerRenderer : GaugePointerRenderer, IDisposable
|
||||
{
|
||||
#region Private variables
|
||||
|
||||
private int _LastWidth;
|
||||
private int _LastLength;
|
||||
private GaugeMarkerStyle _LastMarkerStyle;
|
||||
|
||||
private Rectangle _Bounds;
|
||||
|
||||
private GaugeMarker _GaugeMarker;
|
||||
|
||||
#endregion
|
||||
|
||||
internal GaugeMarkerRenderer(GaugePointer gaugePointer)
|
||||
: base(gaugePointer)
|
||||
{
|
||||
_GaugeMarker = new GaugeMarker();
|
||||
}
|
||||
|
||||
#region Internal properties
|
||||
|
||||
#region Bounds
|
||||
|
||||
internal Rectangle Bounds
|
||||
{
|
||||
get { return (_Bounds); }
|
||||
set { _Bounds = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region RecalcLayout
|
||||
|
||||
public override void RecalcLayout()
|
||||
{
|
||||
base.RecalcLayout();
|
||||
|
||||
if (Scale is GaugeCircularScale)
|
||||
CalcCircularMarkerPoint(Scale as GaugeCircularScale);
|
||||
|
||||
else if (Scale is GaugeLinearScale)
|
||||
CalcLinearMarkerPoint(Scale as GaugeLinearScale);
|
||||
|
||||
if ((Width != _LastWidth || Length != _LastLength) ||
|
||||
(GaugePointer.MarkerStyle != _LastMarkerStyle))
|
||||
{
|
||||
_GaugeMarker.Clear();
|
||||
|
||||
_LastWidth = Width;
|
||||
_LastLength = Length;
|
||||
_LastMarkerStyle = GaugePointer.MarkerStyle;
|
||||
}
|
||||
}
|
||||
|
||||
#region CalcCircularMarkerPoint
|
||||
|
||||
private void CalcCircularMarkerPoint(GaugeCircularScale scale)
|
||||
{
|
||||
int radius = Radius;
|
||||
|
||||
switch (GaugePointer.Placement)
|
||||
{
|
||||
case DisplayPlacement.Near:
|
||||
radius -= Length;
|
||||
break;
|
||||
|
||||
case DisplayPlacement.Center:
|
||||
radius += (Length / 2);
|
||||
break;
|
||||
|
||||
case DisplayPlacement.Far:
|
||||
radius += Length;
|
||||
break;
|
||||
}
|
||||
|
||||
Dpt = scale.SweepAngle / scale.Spread;
|
||||
|
||||
double marker = GetInterval(Value) - scale.MinValue;
|
||||
|
||||
IntervalAngle = (float)(scale.Reversed
|
||||
? scale.StartAngle + scale.SweepAngle - (marker * Dpt)
|
||||
: scale.StartAngle + (marker * Dpt));
|
||||
|
||||
IntervalPoint = scale.GetPoint(radius, IntervalAngle);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CalcLinearMarkerPoint
|
||||
|
||||
private void CalcLinearMarkerPoint(GaugeLinearScale scale)
|
||||
{
|
||||
if (scale.Orientation == Orientation.Horizontal)
|
||||
CalcHorizontalMarkerPoint(scale);
|
||||
else
|
||||
CalcVerticalMarkerPoint(scale);
|
||||
}
|
||||
|
||||
#region CalcHorizontalMarkerPoint
|
||||
|
||||
private void CalcHorizontalMarkerPoint(GaugeLinearScale scale)
|
||||
{
|
||||
int offset = GaugePointer.Offset;
|
||||
|
||||
_Bounds = new Rectangle(0, 0, Width, Length);
|
||||
|
||||
int y = scale.ScaleBounds.Y + scale.ScaleBounds.Height / 2 + offset;
|
||||
|
||||
switch (GaugePointer.Placement)
|
||||
{
|
||||
case DisplayPlacement.Near:
|
||||
y -= Length;
|
||||
break;
|
||||
|
||||
case DisplayPlacement.Center:
|
||||
y -= (Length / 2);
|
||||
break;
|
||||
|
||||
case DisplayPlacement.Far:
|
||||
break;
|
||||
}
|
||||
|
||||
Dpt = scale.ScaleBounds.Width / scale.Spread;
|
||||
|
||||
double marker = GetInterval(Value) - scale.MinValue;
|
||||
|
||||
int n = _Bounds.Width / 2;
|
||||
|
||||
int x = (scale.Reversed == true)
|
||||
? scale.ScaleBounds.Right - (int)(marker * Dpt) - n
|
||||
: scale.ScaleBounds.X + (int)(marker * Dpt) - n;
|
||||
|
||||
_Bounds.Location = new Point(x, y);
|
||||
|
||||
IntervalPoint = new Point(_Bounds.X + n, _Bounds.Y + _Bounds.Height / 2);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CalcVerticalMarkerPoint
|
||||
|
||||
private void CalcVerticalMarkerPoint(GaugeLinearScale scale)
|
||||
{
|
||||
int offset = GaugePointer.Offset;
|
||||
|
||||
_Bounds = new Rectangle(0, 0, Width, Length);
|
||||
|
||||
int x = scale.ScaleBounds.X + scale.ScaleBounds.Width / 2 + offset;
|
||||
|
||||
switch (GaugePointer.Placement)
|
||||
{
|
||||
case DisplayPlacement.Near:
|
||||
x -= Width;
|
||||
break;
|
||||
|
||||
case DisplayPlacement.Center:
|
||||
x -= (Width / 2);
|
||||
break;
|
||||
|
||||
case DisplayPlacement.Far:
|
||||
break;
|
||||
}
|
||||
|
||||
Dpt = scale.ScaleBounds.Height / scale.Spread;
|
||||
|
||||
double marker = GetInterval(Value) - scale.MinValue;
|
||||
|
||||
int n = _Bounds.Height / 2;
|
||||
|
||||
int y = (scale.Reversed == true)
|
||||
? scale.ScaleBounds.Top + (int)(marker * Dpt) - n
|
||||
: scale.ScaleBounds.Bottom - (int)(marker * Dpt) - n;
|
||||
|
||||
_Bounds.Location = new Point(x, y);
|
||||
|
||||
IntervalPoint = new Point(_Bounds.X + _Bounds.Width / 2, _Bounds.Y + n);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region RenderCircular
|
||||
|
||||
public override void RenderCircular(PaintEventArgs e)
|
||||
{
|
||||
if (IntervalPoint.IsEmpty == false &&
|
||||
(Width > 0 && Length > 0 && Radius > 0))
|
||||
{
|
||||
Graphics g = e.Graphics;
|
||||
|
||||
Rectangle r = new Rectangle(0, 0, Width, Length);
|
||||
r.X -= Width / 2;
|
||||
|
||||
float angle = IntervalAngle + 90;
|
||||
|
||||
if (GaugePointer.Placement == DisplayPlacement.Near)
|
||||
angle += 180;
|
||||
|
||||
g.TranslateTransform(IntervalPoint.X, IntervalPoint.Y);
|
||||
g.RotateTransform(angle % 360);
|
||||
|
||||
if (GaugePointer.Image != null)
|
||||
{
|
||||
g.DrawImage(GaugePointer.Image, r);
|
||||
}
|
||||
else
|
||||
{
|
||||
GraphicsPath path = GetMarkerPath(r);
|
||||
|
||||
if (path != null)
|
||||
{
|
||||
GradientFillColor fillColor =
|
||||
GetPointerFillColor(GaugePointer.Value);
|
||||
|
||||
_GaugeMarker.FillMarkerPath(g, path, r, MarkerStyle, fillColor);
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetTransform();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RenderLinear
|
||||
|
||||
public override void RenderLinear(PaintEventArgs e)
|
||||
{
|
||||
if (_Bounds.Width > 0 && _Bounds.Height > 0)
|
||||
{
|
||||
Graphics g = e.Graphics;
|
||||
|
||||
Rectangle r = new Rectangle(0, 0, Width, Length);
|
||||
r.X -= Width / 2;
|
||||
r.Y -= Length / 2;
|
||||
|
||||
g.TranslateTransform(IntervalPoint.X, IntervalPoint.Y);
|
||||
|
||||
if (((GaugeLinearScale)Scale).Orientation == Orientation.Horizontal)
|
||||
{
|
||||
if (GaugePointer.Placement == DisplayPlacement.Far)
|
||||
g.RotateTransform(180);
|
||||
}
|
||||
else
|
||||
{
|
||||
int angle = (GaugePointer.Placement == DisplayPlacement.Far) ? 90 : -90;
|
||||
|
||||
g.RotateTransform(angle);
|
||||
}
|
||||
|
||||
if (GaugePointer.Image != null)
|
||||
{
|
||||
g.DrawImage(GaugePointer.Image, r);
|
||||
}
|
||||
else
|
||||
{
|
||||
GraphicsPath path = GetMarkerPath(r);
|
||||
|
||||
if (path != null)
|
||||
{
|
||||
GradientFillColor fillColor =
|
||||
GetPointerFillColor(GaugePointer.Value);
|
||||
|
||||
_GaugeMarker.FillMarkerPath(g, path, r, MarkerStyle, fillColor);
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetTransform();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetPointerPath
|
||||
|
||||
public override GraphicsPath GetPointerPath()
|
||||
{
|
||||
if (PointerPath == null)
|
||||
{
|
||||
if (MarkerStyle != GaugeMarkerStyle.None)
|
||||
{
|
||||
if (Width > 0 && Length > 0)
|
||||
{
|
||||
if (Scale is GaugeCircularScale)
|
||||
GetCPointerPath();
|
||||
else
|
||||
GetLPointerPath();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (PointerPath);
|
||||
}
|
||||
|
||||
#region GetCPointerPath
|
||||
|
||||
private void GetCPointerPath()
|
||||
{
|
||||
Rectangle r = new Rectangle(IntervalPoint.X, IntervalPoint.Y, Width, Length);
|
||||
r.X -= Width / 2;
|
||||
|
||||
PointerPath = GetMarkerPath(r);
|
||||
|
||||
if (PointerPath != null)
|
||||
{
|
||||
float angle = IntervalAngle + 90;
|
||||
|
||||
if (GaugePointer.Placement == DisplayPlacement.Near)
|
||||
angle += 180;
|
||||
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.RotateAt(angle % 360, IntervalPoint);
|
||||
|
||||
PointerPath.Transform(matrix);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetLPointerPath
|
||||
|
||||
private void GetLPointerPath()
|
||||
{
|
||||
if (((GaugeLinearScale)Scale).Orientation == Orientation.Horizontal)
|
||||
GetLhPointerPath();
|
||||
else
|
||||
GetLvPointerPath();
|
||||
}
|
||||
|
||||
#region GetLhPointerPath
|
||||
|
||||
private void GetLhPointerPath()
|
||||
{
|
||||
Rectangle r = new Rectangle(IntervalPoint.X, IntervalPoint.Y, Width, Length);
|
||||
|
||||
r.X -= Width / 2;
|
||||
r.Y -= Length / 2;
|
||||
|
||||
PointerPath = GetMarkerPath(r);
|
||||
|
||||
if (GaugePointer.Placement == DisplayPlacement.Far)
|
||||
{
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.RotateAt(180, IntervalPoint);
|
||||
|
||||
PointerPath.Transform(matrix);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetLvPointerPath
|
||||
|
||||
private void GetLvPointerPath()
|
||||
{
|
||||
Rectangle r = new Rectangle(IntervalPoint.X, IntervalPoint.Y, Width, Length);
|
||||
|
||||
r.X -= Width / 2;
|
||||
r.Y -= Length / 2;
|
||||
|
||||
PointerPath = GetMarkerPath(r);
|
||||
|
||||
int angle = (GaugePointer.Placement == DisplayPlacement.Far) ? 90 : -90;
|
||||
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.RotateAt(angle, IntervalPoint);
|
||||
|
||||
PointerPath.Transform(matrix);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetMarkerPath
|
||||
|
||||
private GraphicsPath GetMarkerPath(Rectangle r)
|
||||
{
|
||||
GraphicsPath path = GaugePointer.Scale.GaugeControl.OnGetPointerPath(GaugePointer, r);
|
||||
|
||||
if (path == null)
|
||||
path = _GaugeMarker.GetMarkerPath(MarkerStyle, r);
|
||||
else
|
||||
PointerPath = null;
|
||||
|
||||
return (path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
PointerPath = null;
|
||||
|
||||
_GaugeMarker.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,707 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DevComponents.Instrumentation
|
||||
{
|
||||
internal class GaugeNeedleRenderer : GaugePointerRenderer, IDisposable
|
||||
{
|
||||
#region Private variables
|
||||
|
||||
private int _CapWidth;
|
||||
private Rectangle _CapBounds;
|
||||
|
||||
#endregion
|
||||
|
||||
internal GaugeNeedleRenderer(GaugePointer gaugePointer)
|
||||
: base(gaugePointer)
|
||||
{
|
||||
}
|
||||
|
||||
#region Public properties
|
||||
|
||||
#region CapBounds
|
||||
|
||||
public Rectangle CapBounds
|
||||
{
|
||||
get { return (_CapBounds); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region RecalcLayout
|
||||
|
||||
public override void RecalcLayout()
|
||||
{
|
||||
base.RecalcLayout();
|
||||
|
||||
CalcMarkerPoint();
|
||||
}
|
||||
|
||||
#region CalcMarkerPoint
|
||||
|
||||
private void CalcMarkerPoint()
|
||||
{
|
||||
if (Scale is GaugeCircularScale)
|
||||
CalcCircularMarkerPoint(Scale as GaugeCircularScale);
|
||||
}
|
||||
|
||||
#region CalcCircularMarkerPoint
|
||||
|
||||
private void CalcCircularMarkerPoint(GaugeCircularScale scale)
|
||||
{
|
||||
Dpt = scale.SweepAngle / scale.Spread;
|
||||
|
||||
double marker = GetInterval(Value) - scale.MinValue;
|
||||
|
||||
IntervalAngle = (float)(scale.Reversed
|
||||
? scale.StartAngle + scale.SweepAngle - (marker * Dpt)
|
||||
: scale.StartAngle + (marker * Dpt));
|
||||
|
||||
IntervalPoint = scale.GetPoint(Radius, IntervalAngle);
|
||||
|
||||
_CapWidth = (int)(scale.AbsRadius * GaugePointer.CapWidth);
|
||||
|
||||
if (_CapWidth % 2 != 0)
|
||||
_CapWidth++;
|
||||
|
||||
int n = _CapWidth / 2;
|
||||
|
||||
_CapBounds = new Rectangle(
|
||||
scale.Center.X - n, scale.Center.Y - n, _CapWidth, _CapWidth);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region RenderCircular
|
||||
|
||||
public override void RenderCircular(PaintEventArgs e)
|
||||
{
|
||||
if (IntervalPoint.IsEmpty == false && Radius > 0)
|
||||
{
|
||||
Graphics g = e.Graphics;
|
||||
|
||||
if (GaugePointer.CapOnTop == false)
|
||||
RenderCap(g);
|
||||
|
||||
RenderNeedle(g);
|
||||
|
||||
if (GaugePointer.CapOnTop == true)
|
||||
RenderCap(g);
|
||||
}
|
||||
}
|
||||
|
||||
#region RenderNeedle
|
||||
|
||||
#region RenderNeedle
|
||||
|
||||
private void RenderNeedle(Graphics g)
|
||||
{
|
||||
if (GaugePointer.NeedleStyle != NeedlePointerStyle.None)
|
||||
{
|
||||
g.TranslateTransform(IntervalPoint.X, IntervalPoint.Y);
|
||||
g.RotateTransform((IntervalAngle + 90) % 360);
|
||||
|
||||
int length = Math.Max(Radius, Radius + Length);
|
||||
|
||||
if (Width > 0 && length > 0)
|
||||
{
|
||||
Rectangle r = new Rectangle(0, 0, Width, length);
|
||||
r.X -= Width/2;
|
||||
|
||||
if (GaugePointer.Image != null)
|
||||
{
|
||||
g.DrawImage(GaugePointer.Image, r);
|
||||
}
|
||||
else
|
||||
{
|
||||
GradientFillColor fillColor = GaugePointer.FillColorEx;
|
||||
|
||||
if (fillColor != null)
|
||||
{
|
||||
GradientFillType fillType = (fillColor.GradientFillType == GradientFillType.Auto)
|
||||
? GradientFillType.Center
|
||||
: fillColor.GradientFillType;
|
||||
|
||||
using (GraphicsPath path = GetNeedlePath(r))
|
||||
{
|
||||
RenderFill(g, r, path, fillColor, fillType, 0, false);
|
||||
RenderBorder(g, path, fillColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetTransform();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetNeedlePath
|
||||
|
||||
private GraphicsPath GetNeedlePath(Rectangle r)
|
||||
{
|
||||
GaugeControl gc = GaugePointer.Scale.GaugeControl;
|
||||
|
||||
return (gc.OnGetPointerPath(GaugePointer, r) ?? GetNeedlePathEx(r));
|
||||
}
|
||||
|
||||
private GraphicsPath GetNeedlePathEx(Rectangle r)
|
||||
{
|
||||
switch (GaugePointer.NeedleStyle)
|
||||
{
|
||||
case NeedlePointerStyle.Style1:
|
||||
return (GetNeedlePathStyle1(r));
|
||||
|
||||
case NeedlePointerStyle.Style2:
|
||||
return (GetNeedlePathStyle2(r));
|
||||
|
||||
case NeedlePointerStyle.Style3:
|
||||
return (GetNeedlePathStyle3(r));
|
||||
|
||||
case NeedlePointerStyle.Style4:
|
||||
return (GetNeedlePathStyle4(r));
|
||||
|
||||
case NeedlePointerStyle.Style5:
|
||||
return (GetNeedlePathStyle5(r));
|
||||
|
||||
case NeedlePointerStyle.Style6:
|
||||
return (GetNeedlePathStyle6(r));
|
||||
|
||||
case NeedlePointerStyle.Style7:
|
||||
return (GetNeedlePathStyle7(r));
|
||||
|
||||
case NeedlePointerStyle.Style8:
|
||||
return (GetNeedlePathStyle8(r));
|
||||
|
||||
default:
|
||||
return (GetNeedlePathStyle1(r));
|
||||
}
|
||||
}
|
||||
|
||||
#region GetNeedlePathStyle1
|
||||
|
||||
private GraphicsPath GetNeedlePathStyle1(Rectangle r)
|
||||
{
|
||||
Point[] pts = new Point[]
|
||||
{
|
||||
new Point(r.Left, r.Bottom),
|
||||
new Point(r.Left + (r.Width / 2), r.Top),
|
||||
new Point(r.Right, r.Bottom),
|
||||
};
|
||||
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
|
||||
path.AddLines(pts);
|
||||
path.CloseFigure();
|
||||
|
||||
return (path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetNeedlePathStyle2
|
||||
|
||||
private GraphicsPath GetNeedlePathStyle2(Rectangle r)
|
||||
{
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
|
||||
path.AddRectangle(r);
|
||||
|
||||
return (path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetNeedlePathStyle3
|
||||
|
||||
private GraphicsPath GetNeedlePathStyle3(Rectangle r)
|
||||
{
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
Rectangle t = r;
|
||||
|
||||
t.Height = t.Width;
|
||||
path.AddArc(t, 180, 180);
|
||||
|
||||
t.Y = r.Bottom - t.Height;
|
||||
path.AddArc(t, 0, 180);
|
||||
|
||||
path.CloseFigure();
|
||||
|
||||
return (path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetNeedlePathStyle4
|
||||
|
||||
private GraphicsPath GetNeedlePathStyle4(Rectangle r)
|
||||
{
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
|
||||
Rectangle t = r;
|
||||
t.Width = t.Width / 2;
|
||||
t.Height = t.Width;
|
||||
t.X += t.Width / 2;
|
||||
|
||||
path.AddArc(t, 180, 180);
|
||||
path.AddLine(r.Right, r.Bottom, r.Left, r.Bottom);
|
||||
|
||||
path.CloseFigure();
|
||||
|
||||
return (path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetNeedlePathStyle5
|
||||
|
||||
private GraphicsPath GetNeedlePathStyle5(Rectangle r)
|
||||
{
|
||||
int n = r.Width / 4;
|
||||
|
||||
Point[] pts = new Point[]
|
||||
{
|
||||
new Point(r.Left + n, r.Top + r.Width),
|
||||
new Point(r.Left + r.Width / 2, r.Top),
|
||||
new Point(r.Right - n, r.Top + r.Width)
|
||||
};
|
||||
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
|
||||
path.AddLines(pts);
|
||||
path.AddLine(r.Right, r.Bottom, r.Left, r.Bottom);
|
||||
|
||||
path.CloseFigure();
|
||||
|
||||
return (path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetNeedlePathStyle6
|
||||
|
||||
private GraphicsPath GetNeedlePathStyle6(Rectangle r)
|
||||
{
|
||||
if (r.Height <= Radius)
|
||||
return (GetNeedlePathStyle1(r));
|
||||
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
|
||||
Point[] pts = new Point[]
|
||||
{
|
||||
new Point(r.Left, r.Y + Radius),
|
||||
new Point(r.Left + (r.Width / 2), r.Top),
|
||||
new Point(r.Right, r.Y + Radius),
|
||||
new Point(r.Left + (r.Width / 2), r.Bottom),
|
||||
new Point(r.Left, r.Y + Radius),
|
||||
};
|
||||
|
||||
path.AddLines(pts);
|
||||
|
||||
return (path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetNeedlePathStyle7
|
||||
|
||||
private GraphicsPath GetNeedlePathStyle7(Rectangle r)
|
||||
{
|
||||
if (r.Height <= Radius)
|
||||
return (GetNeedlePathStyle1(r));
|
||||
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
|
||||
Point[] pts =
|
||||
{
|
||||
new Point(r.X + r.Width / 2, r.Y),
|
||||
new Point(r.Right, r.Y + (r.Height / 3)),
|
||||
new Point(r.Right - (r.Width / 4), r.Y + (r.Height / 3)),
|
||||
new Point(r.Right, r.Bottom),
|
||||
new Point(r.X + r.Width / 2, r.Bottom - r.Width / 2),
|
||||
new Point(r.X, r.Bottom),
|
||||
new Point(r.X + r.Width / 2, r.Y),
|
||||
};
|
||||
|
||||
path.AddLines(pts);
|
||||
|
||||
return (path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetNeedlePathStyle8
|
||||
|
||||
private GraphicsPath GetNeedlePathStyle8(Rectangle r)
|
||||
{
|
||||
if (r.Height <= Radius)
|
||||
return (GetNeedlePathStyle1(r));
|
||||
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
|
||||
Point[] pts = {
|
||||
new Point(r.X + r.Width / 2, r.Y),
|
||||
new Point(r.Right, r.Y + (r.Height / 3)),
|
||||
new Point(r.Right - (r.Width / 4), r.Y + (r.Height / 3)),
|
||||
new Point(r.Right, r.Bottom),
|
||||
new Point(r.X + r.Width / 2, r.Bottom - r.Width / 2),
|
||||
new Point(r.X, r.Bottom),
|
||||
new Point(r.X + (r.Width / 4), r.Y + (r.Height / 3)),
|
||||
new Point(r.X, r.Y + (r.Height / 3)),
|
||||
};
|
||||
|
||||
path.AddLines(pts);
|
||||
|
||||
return (path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region RenderCap
|
||||
|
||||
#region RenderCap
|
||||
|
||||
public void RenderCap(Graphics g)
|
||||
{
|
||||
if (_CapWidth > 2)
|
||||
{
|
||||
if (GaugePointer.CapImage != null)
|
||||
RenderCapImage(g);
|
||||
else
|
||||
RenderCapStyle(g);
|
||||
}
|
||||
}
|
||||
|
||||
#region RenderCapStyle
|
||||
|
||||
private void RenderCapStyle(Graphics g)
|
||||
{
|
||||
if (GaugePointer.CapStyle != NeedlePointerCapStyle.None)
|
||||
{
|
||||
GradientFillColor fillColor = GaugePointer.CapFillColorEx;
|
||||
|
||||
if (fillColor != null)
|
||||
{
|
||||
GradientFillType fillType = (fillColor.GradientFillType == GradientFillType.Auto)
|
||||
? GradientFillType.Angle
|
||||
: fillColor.GradientFillType;
|
||||
|
||||
if (fillType == GradientFillType.Angle && fillColor.GradientAngle % 90 != 0)
|
||||
{
|
||||
Matrix myMatrix = new Matrix();
|
||||
myMatrix.RotateAt(fillColor.GradientAngle, Scale.Center);
|
||||
|
||||
g.Transform = myMatrix;
|
||||
}
|
||||
|
||||
switch (GaugePointer.CapStyle)
|
||||
{
|
||||
case NeedlePointerCapStyle.Style1:
|
||||
RenderCapPathSytle1(g, _CapBounds, fillColor, fillType);
|
||||
break;
|
||||
|
||||
case NeedlePointerCapStyle.Style2:
|
||||
RenderCapPathSytle2(g, _CapBounds, fillColor, fillType);
|
||||
break;
|
||||
}
|
||||
|
||||
g.ResetTransform();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RenderCapImage
|
||||
|
||||
private void RenderCapImage(Graphics g)
|
||||
{
|
||||
if (GaugePointer.RotateCap == true)
|
||||
{
|
||||
g.TranslateTransform(Scale.Center.X, Scale.Center.Y);
|
||||
g.RotateTransform((IntervalAngle + 90) % 360);
|
||||
|
||||
Rectangle r = _CapBounds;
|
||||
r.Location = new Point(-_CapBounds.Width / 2, -_CapBounds.Height / 2);
|
||||
|
||||
g.DrawImage(GaugePointer.CapImage, r);
|
||||
|
||||
g.ResetTransform();
|
||||
}
|
||||
else
|
||||
{
|
||||
g.DrawImage(GaugePointer.CapImage, _CapBounds);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region RenderCapPathSytle1
|
||||
|
||||
private void RenderCapPathSytle1(Graphics g,
|
||||
Rectangle r, GradientFillColor fillColor, GradientFillType fillType)
|
||||
{
|
||||
using (GraphicsPath path = new GraphicsPath())
|
||||
{
|
||||
path.AddEllipse(r);
|
||||
|
||||
RenderFill(g, r, path, fillColor, fillType, 0, true);
|
||||
RenderBorder(g, path, fillColor);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RenderCapPathSytle2
|
||||
|
||||
private void RenderCapPathSytle2(Graphics g,
|
||||
Rectangle r, GradientFillColor fillColor, GradientFillType fillType)
|
||||
{
|
||||
using (GraphicsPath path = new GraphicsPath())
|
||||
{
|
||||
path.AddEllipse(r);
|
||||
|
||||
RenderFill(g, r, path, fillColor, fillType, 0, true);
|
||||
RenderBorder(g, path, fillColor);
|
||||
|
||||
path.Reset();
|
||||
|
||||
int angle = 180;
|
||||
int outer = (int)(r.Width * GaugePointer.CapOuterBevel);
|
||||
|
||||
if (outer > 0)
|
||||
{
|
||||
r.Inflate(-outer, -outer);
|
||||
|
||||
if (r.Width >= 2)
|
||||
{
|
||||
path.AddEllipse(r);
|
||||
RenderFill(g, r, path, fillColor, fillType, 180, true);
|
||||
|
||||
path.Reset();
|
||||
|
||||
angle = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int inner = (int) (r.Width*GaugePointer.CapInnerBevel);
|
||||
|
||||
if (inner > 0)
|
||||
{
|
||||
r.Inflate(-inner, -inner);
|
||||
|
||||
if (r.Width >= 2)
|
||||
{
|
||||
path.AddEllipse(r);
|
||||
RenderFill(g, r, path, fillColor, fillType, angle, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region RenderFill
|
||||
|
||||
private void RenderFill(Graphics g, Rectangle r, GraphicsPath path,
|
||||
GradientFillColor fillColor, GradientFillType fillType, int angle, bool offset)
|
||||
{
|
||||
if (fillColor.Color2.IsEmpty)
|
||||
fillType = GradientFillType.None;
|
||||
|
||||
switch (fillType)
|
||||
{
|
||||
case GradientFillType.Auto:
|
||||
case GradientFillType.Angle:
|
||||
if (offset == false)
|
||||
angle += fillColor.GradientAngle;
|
||||
|
||||
using (Brush br = fillColor.GetBrush(r, angle))
|
||||
{
|
||||
if (br is LinearGradientBrush)
|
||||
((LinearGradientBrush)br).WrapMode = WrapMode.TileFlipXY;
|
||||
|
||||
g.FillPath(br, path);
|
||||
}
|
||||
break;
|
||||
|
||||
case GradientFillType.StartToEnd:
|
||||
using (Brush br = fillColor.GetBrush(r, 90 + angle))
|
||||
{
|
||||
if (br is LinearGradientBrush)
|
||||
((LinearGradientBrush)br).WrapMode = WrapMode.TileFlipXY;
|
||||
|
||||
g.FillPath(br, path);
|
||||
}
|
||||
break;
|
||||
|
||||
case GradientFillType.HorizontalCenter:
|
||||
if (r.Height >= 2)
|
||||
r.Height /= 2;
|
||||
|
||||
using (LinearGradientBrush br = new
|
||||
LinearGradientBrush(r, fillColor.Start, fillColor.End, 90 + angle))
|
||||
{
|
||||
br.WrapMode = WrapMode.TileFlipXY;
|
||||
|
||||
g.FillPath(br, path);
|
||||
}
|
||||
break;
|
||||
|
||||
case GradientFillType.VerticalCenter:
|
||||
if (r.Width >= 2)
|
||||
r.Width /= 2;
|
||||
|
||||
using (LinearGradientBrush br = new
|
||||
LinearGradientBrush(r, fillColor.Start, fillColor.End, 0f + angle))
|
||||
{
|
||||
br.WrapMode = WrapMode.TileFlipXY;
|
||||
|
||||
g.FillPath(br, path);
|
||||
}
|
||||
break;
|
||||
|
||||
case GradientFillType.Center:
|
||||
using (PathGradientBrush br = new PathGradientBrush(path))
|
||||
{
|
||||
if (offset == true && Scale is GaugeCircularScale)
|
||||
br.CenterPoint = ((GaugeCircularScale)Scale).GetPoint((int) (r.Width * .45f), 180 + 45 + angle);
|
||||
|
||||
br.CenterColor = fillColor.Start;
|
||||
br.SurroundColors = new Color[] { fillColor.End };
|
||||
|
||||
g.FillPath(br, path);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
using (Brush br = new SolidBrush(fillColor.Start))
|
||||
g.FillPath(br, path);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RenderBorder
|
||||
|
||||
private void RenderBorder(
|
||||
Graphics g, GraphicsPath path, GradientFillColor fillColor)
|
||||
{
|
||||
if (fillColor.BorderWidth > 0)
|
||||
{
|
||||
using (Pen pen = new Pen(fillColor.BorderColor, fillColor.BorderWidth))
|
||||
{
|
||||
pen.Alignment = PenAlignment.Inset;
|
||||
|
||||
g.DrawPath(pen, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region RenderLinear
|
||||
|
||||
public override void RenderLinear(PaintEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetPointerPath
|
||||
|
||||
public override GraphicsPath GetPointerPath()
|
||||
{
|
||||
if (PointerPath == null)
|
||||
{
|
||||
if (GaugePointer.NeedleStyle != NeedlePointerStyle.None)
|
||||
{
|
||||
int length = Math.Max(Radius, Radius + Length);
|
||||
|
||||
if (Width > 0 && length > 0)
|
||||
{
|
||||
Rectangle r = new Rectangle(IntervalPoint.X, IntervalPoint.Y, Width, length);
|
||||
r.X -= Width / 2;
|
||||
|
||||
PointerPath = GetNeedlePath(r);
|
||||
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.RotateAt((IntervalAngle + 90) % 360, IntervalPoint);
|
||||
|
||||
PointerPath.Transform(matrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (PointerPath);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnMouseDown
|
||||
|
||||
internal override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
|
||||
GaugePointer.MouseDownAngle = IntervalAngle;
|
||||
GaugePointer.MouseDownRadians = GetPointRadians(e.Location);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
PointerPath = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region Enums
|
||||
|
||||
public enum NeedlePointerStyle
|
||||
{
|
||||
None,
|
||||
Style1,
|
||||
Style2,
|
||||
Style3,
|
||||
Style4,
|
||||
Style5,
|
||||
Style6,
|
||||
Style7,
|
||||
Style8
|
||||
}
|
||||
|
||||
public enum NeedlePointerCapStyle
|
||||
{
|
||||
None,
|
||||
Style1,
|
||||
Style2,
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,563 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DevComponents.Instrumentation
|
||||
{
|
||||
internal abstract class GaugePointerRenderer
|
||||
{
|
||||
#region Private variables
|
||||
|
||||
private GaugePointer _GaugePointer;
|
||||
|
||||
private int _Width;
|
||||
private int _Length;
|
||||
|
||||
private float _IntervalAngle;
|
||||
private Point _IntervalPoint;
|
||||
|
||||
private double _Dpt;
|
||||
|
||||
private GraphicsPath _PointerPath;
|
||||
|
||||
#endregion
|
||||
|
||||
protected GaugePointerRenderer(GaugePointer gaugePointer)
|
||||
{
|
||||
_GaugePointer = gaugePointer;
|
||||
}
|
||||
|
||||
#region Abstract methods
|
||||
|
||||
public abstract void RenderCircular(PaintEventArgs e);
|
||||
public abstract void RenderLinear(PaintEventArgs e);
|
||||
public abstract GraphicsPath GetPointerPath();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Protected properties
|
||||
|
||||
#region GaugePointer
|
||||
|
||||
protected GaugePointer GaugePointer
|
||||
{
|
||||
get { return (_GaugePointer); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IntervalAngle
|
||||
|
||||
internal float IntervalAngle
|
||||
{
|
||||
get { return (_IntervalAngle); }
|
||||
set { _IntervalAngle = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IntervalPoint
|
||||
|
||||
internal Point IntervalPoint
|
||||
{
|
||||
get { return (_IntervalPoint); }
|
||||
set { _IntervalPoint = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Length
|
||||
|
||||
protected int Length
|
||||
{
|
||||
get { return (_Length); }
|
||||
set { _Length = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MarkerStyle
|
||||
|
||||
protected GaugeMarkerStyle MarkerStyle
|
||||
{
|
||||
get { return (_GaugePointer.MarkerStyle); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region PointerPath
|
||||
|
||||
internal GraphicsPath PointerPath
|
||||
{
|
||||
get { return (_PointerPath); }
|
||||
|
||||
set
|
||||
{
|
||||
if (_PointerPath != value)
|
||||
{
|
||||
if (_PointerPath != null)
|
||||
_PointerPath.Dispose();
|
||||
|
||||
_PointerPath = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Radius
|
||||
|
||||
protected int Radius
|
||||
{
|
||||
get { return (_GaugePointer.Radius); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Scale
|
||||
|
||||
protected GaugeScale Scale
|
||||
{
|
||||
get { return (_GaugePointer.Scale); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Value
|
||||
|
||||
protected double Value
|
||||
{
|
||||
get { return (_GaugePointer.DValue); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Width
|
||||
|
||||
protected int Width
|
||||
{
|
||||
get { return (_Width); }
|
||||
set { _Width = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal properties
|
||||
|
||||
#region Dpt
|
||||
|
||||
internal double Dpt
|
||||
{
|
||||
get { return (_Dpt > 0 ? _Dpt : 1); }
|
||||
set { _Dpt = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetCapFillColor
|
||||
|
||||
protected GradientFillColor GetCapFillColor(double interval)
|
||||
{
|
||||
const ColorSourceFillEntry entry = ColorSourceFillEntry.Cap;
|
||||
|
||||
GradientFillColor fillColor = (Scale.GetRangeFillColor(interval, entry) ??
|
||||
Scale.GetSectionFillColor(interval, entry)) ?? GaugePointer.CapFillColor;
|
||||
|
||||
return (fillColor);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetPointerFillColor
|
||||
|
||||
protected GradientFillColor GetPointerFillColor(double interval)
|
||||
{
|
||||
const ColorSourceFillEntry entry = ColorSourceFillEntry.Pointer;
|
||||
|
||||
GradientFillColor fillColor = (Scale.GetRangeFillColor(interval, entry) ??
|
||||
Scale.GetSectionFillColor(interval, entry)) ?? GaugePointer.FillColor;
|
||||
|
||||
return (fillColor);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetInterval
|
||||
|
||||
internal double GetInterval(double interval)
|
||||
{
|
||||
bool pegged;
|
||||
|
||||
return (GetIntervalEx(interval, out pegged));
|
||||
}
|
||||
|
||||
internal double GetInterval(double interval, out bool pegged)
|
||||
{
|
||||
double min, max;
|
||||
GetRange(out min, out max);
|
||||
|
||||
pegged = true;
|
||||
|
||||
if (interval.Equals(double.NaN))
|
||||
return (min);
|
||||
|
||||
if (interval < min)
|
||||
interval = min;
|
||||
|
||||
else if (interval > max)
|
||||
interval = max;
|
||||
else
|
||||
pegged = false;
|
||||
|
||||
return (interval);
|
||||
}
|
||||
|
||||
internal double GetIntervalEx(double interval, out bool pegged)
|
||||
{
|
||||
int n = (GaugePointer.Scale is GaugeLinearScale)
|
||||
? ((GaugeLinearScale) Scale).AbsLength
|
||||
: 360;
|
||||
|
||||
double minPinValue = GaugePointer.HonorMinPin ? (Scale.MinPinEndOffset*n)/Dpt : 0;
|
||||
double maxPinValue = GaugePointer.HonorMaxPin ? (Scale.MaxPinEndOffset*n)/Dpt : 0;
|
||||
|
||||
double min = Scale.MinValue;
|
||||
double max = Scale.MaxValue;
|
||||
|
||||
if (Scale.MinValue <= Scale.AbsMinLimit)
|
||||
min -= minPinValue;
|
||||
|
||||
if (Scale.MaxValue >= Scale.AbsMaxLimit)
|
||||
max += maxPinValue;
|
||||
|
||||
pegged = true;
|
||||
|
||||
if (interval.Equals(double.NaN))
|
||||
return (min);
|
||||
|
||||
if (interval < min)
|
||||
{
|
||||
interval = Scale.MinValue > Scale.AbsMinLimit
|
||||
? Math.Max(min - 1, Scale.AbsMinLimit)
|
||||
: min;
|
||||
}
|
||||
else if (interval > max)
|
||||
{
|
||||
interval = Scale.MaxValue < Scale.AbsMaxLimit
|
||||
? Math.Min(max + 1, Scale.AbsMaxLimit)
|
||||
: max;
|
||||
}
|
||||
else
|
||||
{
|
||||
pegged = false;
|
||||
}
|
||||
|
||||
return (interval);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetRange
|
||||
|
||||
internal void GetRange(out double min, out double max)
|
||||
{
|
||||
int n = (GaugePointer.Scale is GaugeLinearScale)
|
||||
? ((GaugeLinearScale) Scale).AbsLength
|
||||
: 360;
|
||||
|
||||
double minPinValue = GaugePointer.HonorMinPin ? (Scale.MinPinEndOffset * n) / Dpt : 0;
|
||||
double maxPinValue = GaugePointer.HonorMaxPin ? (Scale.MaxPinEndOffset * n) / Dpt : 0;
|
||||
|
||||
min = Scale.MinValue - minPinValue;
|
||||
max = Scale.MaxValue + maxPinValue;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetRangeEx
|
||||
|
||||
internal void GetRangeEx(out double min, out double max)
|
||||
{
|
||||
int n = (GaugePointer.Scale is GaugeLinearScale)
|
||||
? ((GaugeLinearScale)Scale).AbsLength
|
||||
: 360;
|
||||
|
||||
double minPinValue = GaugePointer.HonorMinPin ? (Scale.MinPinEndOffset * n) / Dpt : 0;
|
||||
double maxPinValue = GaugePointer.HonorMaxPin ? (Scale.MaxPinEndOffset * n) / Dpt : 0;
|
||||
|
||||
min = Scale.AbsMinLimit - minPinValue;
|
||||
max = Scale.AbsMaxLimit + maxPinValue;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SwapDoubles
|
||||
|
||||
protected void SwapDoubles(ref double marker, ref double origin)
|
||||
{
|
||||
double temp = marker;
|
||||
|
||||
marker = origin;
|
||||
origin = temp;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RecalcLayout
|
||||
|
||||
public virtual void RecalcLayout()
|
||||
{
|
||||
PointerPath = null;
|
||||
|
||||
if (Scale is GaugeCircularScale)
|
||||
CalcCircularMetrics(Scale as GaugeCircularScale);
|
||||
|
||||
else if (Scale is GaugeLinearScale)
|
||||
CalcLinearMetrics(Scale as GaugeLinearScale);
|
||||
}
|
||||
|
||||
#region CalcCircularMetrics
|
||||
|
||||
private void CalcCircularMetrics(GaugeCircularScale scale)
|
||||
{
|
||||
_Width = (int)(scale.AbsRadius * GaugePointer.Width);
|
||||
_Length = (int)(scale.AbsRadius * GaugePointer.Length);
|
||||
|
||||
if (_Width % 2 != 0)
|
||||
_Width++;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CalcLinearMetrics
|
||||
|
||||
private void CalcLinearMetrics(GaugeLinearScale scale)
|
||||
{
|
||||
int n = scale.AbsWidth;
|
||||
|
||||
_Width = (int)(n * GaugePointer.Width);
|
||||
_Length = (int)(n * GaugePointer.Length);
|
||||
|
||||
if (_Width % 2 != 0)
|
||||
_Width++;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetValueFromPoint
|
||||
|
||||
public virtual double GetValueFromPoint(Point pt)
|
||||
{
|
||||
if (Scale is GaugeCircularScale)
|
||||
return (GetCValueFromPoint(Scale as GaugeCircularScale, pt));
|
||||
|
||||
return (GetLValueFromPoint(Scale as GaugeLinearScale, pt));
|
||||
}
|
||||
|
||||
#region GetCValueFromPoint
|
||||
|
||||
private double GetCValueFromPoint(GaugeCircularScale scale, Point pt)
|
||||
{
|
||||
double minValue = scale.MinValue;
|
||||
double maxValue = scale.MaxValue;
|
||||
|
||||
double startAngle = scale.StartAngle;
|
||||
double sweepAngle = scale.SweepAngle;
|
||||
|
||||
double radians = GetPointRadians(pt);
|
||||
|
||||
double spread = scale.MaxValue - scale.MinValue;
|
||||
double dpt = spread / scale.SweepAngle;
|
||||
|
||||
if (minValue <= scale.AbsMinLimit)
|
||||
minValue -= GetCMinPinOffset(dpt, ref startAngle, ref sweepAngle);
|
||||
|
||||
if (maxValue >= scale.AbsMaxLimit)
|
||||
maxValue += GetCMaxPinOffset(dpt, ref startAngle, ref sweepAngle);
|
||||
|
||||
double angle = (GaugePointer.MouseDownAngle +
|
||||
scale.GetDegrees(radians - GaugePointer.MouseDownRadians) - startAngle) % 360;
|
||||
|
||||
if (angle < 0)
|
||||
angle += 360;
|
||||
|
||||
if (scale.Reversed == true)
|
||||
{
|
||||
angle = sweepAngle - angle;
|
||||
|
||||
if (angle < 0)
|
||||
angle += 360;
|
||||
}
|
||||
|
||||
if (angle < sweepAngle)
|
||||
{
|
||||
double value = angle * dpt + minValue;
|
||||
|
||||
if (GaugePointer.SnapInterval > 0)
|
||||
value = (int)(value / GaugePointer.SnapInterval) * GaugePointer.SnapInterval;
|
||||
|
||||
return (value);
|
||||
}
|
||||
|
||||
if (angle > sweepAngle + (360 - sweepAngle) / 2)
|
||||
{
|
||||
double limit = minValue;
|
||||
|
||||
if (limit > scale.AbsMinLimit)
|
||||
limit = Math.Max(limit - 1, scale.AbsMinLimit);
|
||||
|
||||
return (limit);
|
||||
}
|
||||
|
||||
double limit2 = maxValue;
|
||||
|
||||
if (limit2 < scale.AbsMaxLimit)
|
||||
limit2 = Math.Min(limit2 + 1, scale.AbsMaxLimit);
|
||||
|
||||
return (limit2);
|
||||
}
|
||||
|
||||
#region GetCMinPinOffset
|
||||
|
||||
private double GetCMinPinOffset(
|
||||
double dpt, ref double startAngle, ref double sweepAngle)
|
||||
{
|
||||
if (GaugePointer.HonorMinPin == true)
|
||||
{
|
||||
double d = Scale.MinPinEndOffset * 360;
|
||||
|
||||
if (Scale.Reversed == false)
|
||||
startAngle -= d;
|
||||
|
||||
sweepAngle += d;
|
||||
|
||||
return (d * dpt);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetCMaxPinOffset
|
||||
|
||||
private double GetCMaxPinOffset(
|
||||
double dpt, ref double startAngle, ref double sweepAngle)
|
||||
{
|
||||
if (GaugePointer.HonorMaxPin == true)
|
||||
{
|
||||
double d = Scale.MaxPinEndOffset * 360;
|
||||
|
||||
if (Scale.Reversed == true)
|
||||
startAngle -= d;
|
||||
|
||||
sweepAngle += d;
|
||||
|
||||
return (d * dpt);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetPointRadians
|
||||
|
||||
internal double GetPointRadians(Point pt)
|
||||
{
|
||||
int dx = pt.X - Scale.Center.X;
|
||||
int dy = pt.Y - Scale.Center.Y;
|
||||
|
||||
if (dx >= 0)
|
||||
{
|
||||
if (dy >= 0)
|
||||
return (Math.Atan((double)dy / dx));
|
||||
|
||||
return (-Math.Atan((double)dx / dy) + Math.PI * 1.5);
|
||||
}
|
||||
|
||||
if (dy >= 0)
|
||||
return (-Math.Atan((double)dx / dy) + Math.PI / 2);
|
||||
|
||||
return (Math.Atan((double)dy / dx) + Math.PI);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetLValueFromPoint
|
||||
|
||||
private double GetLValueFromPoint(GaugeLinearScale scale, Point pt)
|
||||
{
|
||||
bool pegged;
|
||||
|
||||
double value = (scale.Orientation == Orientation.Horizontal)
|
||||
? GetLhValueFromPoint(scale, pt, out pegged)
|
||||
: GetLvValueFromPoint(scale, pt, out pegged);
|
||||
|
||||
if (GaugePointer.SnapInterval > 0)
|
||||
{
|
||||
if (pegged == false)
|
||||
value = (int)(value / GaugePointer.SnapInterval) * GaugePointer.SnapInterval;
|
||||
}
|
||||
|
||||
return (value);
|
||||
}
|
||||
|
||||
#region GetLhValueFromPoint
|
||||
|
||||
private double GetLhValueFromPoint(GaugeLinearScale scale, Point pt, out bool pegged)
|
||||
{
|
||||
double spread = scale.MaxValue - scale.MinValue;
|
||||
double tpd = spread / scale.ScaleBounds.Width;
|
||||
|
||||
double interval = (pt.X - scale.ScaleBounds.X) * tpd;
|
||||
|
||||
if (scale.Reversed == true)
|
||||
return (GetIntervalEx(scale.MaxValue - interval, out pegged));
|
||||
|
||||
return (GetIntervalEx(scale.MinValue + interval, out pegged));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetLvValueFromPoint
|
||||
|
||||
private double GetLvValueFromPoint(GaugeLinearScale scale, Point pt, out bool pegged)
|
||||
{
|
||||
double spread = scale.MaxValue - scale.MinValue;
|
||||
double tpd = spread / scale.ScaleBounds.Height;
|
||||
|
||||
double interval = (pt.Y - scale.ScaleBounds.Y) * tpd;
|
||||
|
||||
if (scale.Reversed == true)
|
||||
return (GetIntervalEx(scale.MinValue + interval, out pegged));
|
||||
|
||||
return (GetIntervalEx(scale.MaxValue - interval, out pegged));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnMouseDown
|
||||
|
||||
internal virtual void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
GaugePointer.MouseDownAngle = 0;
|
||||
GaugePointer.MouseDownRadians = 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,636 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DevComponents.Instrumentation
|
||||
{
|
||||
internal class GaugeThermoRenderer : GaugeBarRenderer
|
||||
{
|
||||
#region Private variables
|
||||
|
||||
private Rectangle _BackBounds;
|
||||
private Rectangle _BulbBounds;
|
||||
|
||||
#endregion
|
||||
|
||||
internal GaugeThermoRenderer(GaugePointer gaugePointer)
|
||||
: base(gaugePointer)
|
||||
{
|
||||
}
|
||||
|
||||
#region RecalcLayout
|
||||
|
||||
#region CalcHorizontalMarkerBounds
|
||||
|
||||
protected override void CalcHorizontalMarkerBounds(GaugeLinearScale scale, int y)
|
||||
{
|
||||
int n = (int)(GaugePointer.BulbOffset * scale.ScaleBounds.Width);
|
||||
|
||||
if (Marker < Origin)
|
||||
{
|
||||
RoundAngle = 180;
|
||||
|
||||
int len = Math.Max(1, (int)((Origin - Marker) * Dpt) + n);
|
||||
int x;
|
||||
|
||||
if (scale.Reversed == true)
|
||||
{
|
||||
x = scale.ScaleBounds.Right - (int)(Origin * Dpt) - n;
|
||||
}
|
||||
else
|
||||
{
|
||||
x = scale.ScaleBounds.X + (int)(Marker * Dpt);
|
||||
int x2 = scale.ScaleBounds.X + (int)(Origin * Dpt) + n;
|
||||
|
||||
len = Math.Max(1, x2 - x + 1);
|
||||
}
|
||||
|
||||
Bounds = new Rectangle(x, y, len, Width);
|
||||
|
||||
double maxMarker = GetInterval(double.MinValue) - scale.MinValue;
|
||||
|
||||
_BackBounds = Bounds;
|
||||
_BackBounds.Width = (int)((Origin - maxMarker) * Dpt + n);
|
||||
|
||||
if (scale.Reversed == false)
|
||||
_BackBounds.X = scale.ScaleBounds.Left + (int)(maxMarker * Dpt);
|
||||
}
|
||||
else
|
||||
{
|
||||
RoundAngle = 0;
|
||||
|
||||
int len = Math.Max(1, (int)((Marker - Origin) * Dpt) + n);
|
||||
int x;
|
||||
|
||||
if (scale.Reversed == true)
|
||||
x = scale.ScaleBounds.Right - (int)(Origin * Dpt) - len + n;
|
||||
else
|
||||
x = scale.ScaleBounds.X + (int)(Origin * Dpt) - n;
|
||||
|
||||
Bounds = new Rectangle(x, y, len, Width);
|
||||
|
||||
double maxMarker = GetInterval(double.MaxValue) - scale.MinValue;
|
||||
|
||||
_BackBounds = Bounds;
|
||||
_BackBounds.Width = (int)((maxMarker - Origin) * Dpt + n);
|
||||
|
||||
if (scale.Reversed == true)
|
||||
_BackBounds.X = scale.ScaleBounds.Right - (int)(maxMarker * Dpt) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CalcVerticalMarkerBounds
|
||||
|
||||
protected override void CalcVerticalMarkerBounds(GaugeLinearScale scale, int x)
|
||||
{
|
||||
int n = (int)(GaugePointer.BulbOffset * scale.ScaleBounds.Height);
|
||||
|
||||
if (Marker < Origin)
|
||||
{
|
||||
RoundAngle = 90;
|
||||
|
||||
int len = Math.Max(1, (int)((Origin - Marker) * Dpt) + n);
|
||||
int y;
|
||||
|
||||
if (scale.Reversed == true)
|
||||
{
|
||||
y = scale.ScaleBounds.Y + (int)(Marker * Dpt);
|
||||
int y2 = scale.ScaleBounds.Y + (int)(Origin * Dpt) + n;
|
||||
|
||||
len = Math.Max(1, y2 - y);
|
||||
}
|
||||
else
|
||||
{
|
||||
y = scale.ScaleBounds.Bottom - (int)(Origin * Dpt) - n;
|
||||
}
|
||||
|
||||
Bounds = new Rectangle(x, y, Width, len);
|
||||
|
||||
_BackBounds = Bounds;
|
||||
|
||||
double minMarker = GetInterval(double.MinValue) - scale.MinValue;
|
||||
|
||||
if (scale.Reversed == true)
|
||||
{
|
||||
_BackBounds.Y = scale.ScaleBounds.Top + (int)(minMarker * Dpt);
|
||||
_BackBounds.Height = Bounds.Bottom - _BackBounds.Y;
|
||||
}
|
||||
else
|
||||
{
|
||||
_BackBounds.Height = (int)((Origin - minMarker) * Dpt + n);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RoundAngle = -90;
|
||||
|
||||
int len = Math.Max(1, (int)((Marker - Origin) * Dpt) + n);
|
||||
int y;
|
||||
|
||||
if (scale.Reversed == true)
|
||||
{
|
||||
y = scale.ScaleBounds.Top + (int)(Origin * Dpt) - n;
|
||||
}
|
||||
else
|
||||
{
|
||||
y = scale.ScaleBounds.Bottom - (int)(Marker * Dpt);
|
||||
int y2 = scale.ScaleBounds.Bottom - (int)(Origin * Dpt) + n;
|
||||
|
||||
len = Math.Max(1, y2 - y);
|
||||
}
|
||||
|
||||
Bounds = new Rectangle(x, y, Width, len);
|
||||
|
||||
_BackBounds = Bounds;
|
||||
|
||||
double maxMarker = GetInterval(double.MaxValue) - scale.MinValue;
|
||||
|
||||
if (scale.Reversed == false)
|
||||
{
|
||||
_BackBounds.Y = scale.ScaleBounds.Bottom - (int)(maxMarker * Dpt);
|
||||
_BackBounds.Height = Bounds.Bottom - _BackBounds.Y;
|
||||
}
|
||||
else
|
||||
{
|
||||
_BackBounds.Height = (int)((maxMarker - Origin) * Dpt + n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region RenderLinear
|
||||
|
||||
public override void RenderLinear(PaintEventArgs e)
|
||||
{
|
||||
Graphics g = e.Graphics;
|
||||
|
||||
GaugeLinearScale scale = Scale as GaugeLinearScale;
|
||||
|
||||
if (scale != null)
|
||||
{
|
||||
if (Bounds.Width > 0 && Bounds.Height > 0)
|
||||
{
|
||||
using (GraphicsPath path = GetBulbBackPath(scale))
|
||||
RenderBar(g, path, GaugePointer.ThermoBackColor);
|
||||
|
||||
using (GraphicsPath path = GetBulbFillPath(scale))
|
||||
RenderBar(g, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region GetBulbBackPath
|
||||
|
||||
private GraphicsPath GetBulbBackPath(GaugeLinearScale scale)
|
||||
{
|
||||
return (GetBulbPath(scale, _BackBounds, 1));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetBulbFillPath
|
||||
|
||||
private GraphicsPath GetBulbFillPath(GaugeLinearScale scale)
|
||||
{
|
||||
return (GetBulbPath(scale, Bounds, 0));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetBulbPath
|
||||
|
||||
private GraphicsPath GetBulbPath(
|
||||
GaugeLinearScale scale, Rectangle r, int inf)
|
||||
{
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
|
||||
r.Inflate(inf, inf);
|
||||
|
||||
if (scale.Orientation == Orientation.Horizontal)
|
||||
{
|
||||
if (Marker < Origin != scale.Reversed)
|
||||
return (GetHorizontalRightBulbPath(scale, path, r, inf));
|
||||
|
||||
return (GetHorizontalLeftBulbPath(scale, path, r, inf));
|
||||
}
|
||||
|
||||
if (Marker < Origin != scale.Reversed)
|
||||
return (GetVerticalTopBulbPath(scale, path, r, inf));
|
||||
|
||||
return (GetVerticalBottomBulbPath(scale, path, r, inf));
|
||||
}
|
||||
|
||||
#region GetHorizontalLeftBulbPath
|
||||
|
||||
private GraphicsPath GetHorizontalLeftBulbPath(
|
||||
GaugeLinearScale scale, GraphicsPath path, Rectangle t, int inflate)
|
||||
{
|
||||
AddLeftTube(path, t, inflate);
|
||||
AddLeftBulb(scale, path, t, inflate);
|
||||
|
||||
path.CloseAllFigures();
|
||||
|
||||
return (path);
|
||||
}
|
||||
|
||||
#region AddLeftTube
|
||||
|
||||
private void AddLeftTube(GraphicsPath path, Rectangle t, int inflate)
|
||||
{
|
||||
if (GaugePointer.BarStyle == BarPointerStyle.Square || inflate > 0)
|
||||
{
|
||||
Point[] pts = new Point[] {
|
||||
new Point(t.X, t.Y),
|
||||
new Point(t.Right, t.Y),
|
||||
new Point(t.Right, t.Bottom),
|
||||
new Point(t.X, t.Bottom) };
|
||||
|
||||
path.AddLines(pts);
|
||||
}
|
||||
else
|
||||
{
|
||||
int x = Math.Max(t.Right - Width / 2, t.X);
|
||||
int n = t.Right - x;
|
||||
|
||||
Rectangle r = new Rectangle(x - n, t.Y, n * 2, t.Height);
|
||||
|
||||
Point[] pts = new Point[] {
|
||||
new Point(t.X, t.Y),
|
||||
new Point (x, t.Y)};
|
||||
|
||||
path.AddLines(pts);
|
||||
|
||||
if (GaugePointer.BarStyle == BarPointerStyle.Rounded)
|
||||
{
|
||||
path.AddArc(r, 270, 180);
|
||||
}
|
||||
else
|
||||
{
|
||||
path.AddLine(new Point(r.X + r.Width / 2, r.Y),
|
||||
new Point(r.Right, r.Y + r.Height / 2));
|
||||
}
|
||||
|
||||
pts = new Point[] {
|
||||
new Point(x, t.Bottom),
|
||||
new Point (t.X, t.Bottom)};
|
||||
|
||||
path.AddLines(pts);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region AddLeftBulb
|
||||
|
||||
private void AddLeftBulb(GaugeLinearScale scale, GraphicsPath path, Rectangle t, int inflate)
|
||||
{
|
||||
int bulbRadius = (int)(GaugePointer.BulbSize * scale.Bounds.Height);
|
||||
|
||||
if (bulbRadius * 2 < t.Height)
|
||||
bulbRadius = t.Height / 2;
|
||||
|
||||
int m = (int)Math.Sqrt((bulbRadius * bulbRadius) - (t.Height * t.Height / 4)) + 4;
|
||||
|
||||
_BulbBounds = new Rectangle(
|
||||
t.X - m - bulbRadius,
|
||||
t.Y - bulbRadius + t.Height / 2, bulbRadius * 2, bulbRadius * 2);
|
||||
|
||||
if (inflate > 0)
|
||||
_BulbBounds.Inflate(inflate, inflate);
|
||||
|
||||
float angle = (GaugePointer.BulbStyle == BulbStyle.Flask)
|
||||
? 90 : (float)(Math.Asin((double)(Width / 2) / bulbRadius) * 180 / Math.PI);
|
||||
|
||||
path.AddArc(_BulbBounds, angle, 360 - (angle * 2));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetHorizontalRightBulbPath
|
||||
|
||||
private GraphicsPath GetHorizontalRightBulbPath(
|
||||
GaugeLinearScale scale, GraphicsPath path, Rectangle t, int inflate)
|
||||
{
|
||||
AddRightTube(path, t, inflate);
|
||||
AddRightBulb(scale, path, t, inflate);
|
||||
|
||||
path.CloseAllFigures();
|
||||
|
||||
return (path);
|
||||
}
|
||||
|
||||
#region AddRightTube
|
||||
|
||||
private void AddRightTube(GraphicsPath path, Rectangle t, int inflate)
|
||||
{
|
||||
if (GaugePointer.BarStyle == BarPointerStyle.Square || inflate > 0)
|
||||
{
|
||||
Point[] pts = new Point[] {
|
||||
new Point(t.Right, t.Bottom),
|
||||
new Point(t.X, t.Bottom),
|
||||
new Point(t.X, t.Y),
|
||||
new Point(t.Right, t.Y) };
|
||||
|
||||
path.AddLines(pts);
|
||||
}
|
||||
else
|
||||
{
|
||||
int x = Math.Min(t.X + Width / 2, t.Right);
|
||||
int n = x - t.X;
|
||||
|
||||
Rectangle r = new Rectangle(t.X, t.Y, n * 2, t.Height);
|
||||
|
||||
Point[] pts = new Point[] {
|
||||
new Point(t.Right, t.Bottom),
|
||||
new Point (x, t.Bottom)};
|
||||
|
||||
path.AddLines(pts);
|
||||
|
||||
if (GaugePointer.BarStyle == BarPointerStyle.Rounded)
|
||||
{
|
||||
path.AddArc(r, 90, 180);
|
||||
}
|
||||
else
|
||||
{
|
||||
path.AddLine(new Point(r.X + r.Width / 2, r.Bottom),
|
||||
new Point(r.X, r.Y + r.Height / 2));
|
||||
}
|
||||
|
||||
pts = new Point[] {
|
||||
new Point(x, t.Y),
|
||||
new Point (t.Right, t.Y)};
|
||||
|
||||
path.AddLines(pts);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region AddRightBulb
|
||||
|
||||
private void AddRightBulb(GaugeLinearScale scale, GraphicsPath path, Rectangle t, int inflate)
|
||||
{
|
||||
int bulbRadius = (int)(GaugePointer.BulbSize * scale.Bounds.Height);
|
||||
|
||||
if (bulbRadius * 2 < t.Height)
|
||||
bulbRadius = t.Height / 2;
|
||||
|
||||
int m = (int)Math.Sqrt((bulbRadius * bulbRadius) - (t.Height * t.Height / 4));
|
||||
|
||||
_BulbBounds = new Rectangle(
|
||||
t.Right - bulbRadius + m,
|
||||
t.Y - bulbRadius + t.Height / 2, bulbRadius * 2, bulbRadius * 2);
|
||||
|
||||
if (inflate > 0)
|
||||
_BulbBounds.Inflate(inflate, inflate);
|
||||
|
||||
float angle = (GaugePointer.BulbStyle == BulbStyle.Flask)
|
||||
? 90 : (float)(Math.Asin((double)(Width / 2) / bulbRadius) * 180 / Math.PI);
|
||||
|
||||
path.AddArc(_BulbBounds, angle + 180, 360 - (angle * 2));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetVerticalBottomBulbPath
|
||||
|
||||
private GraphicsPath GetVerticalBottomBulbPath(
|
||||
GaugeLinearScale scale, GraphicsPath path, Rectangle t, int inflate)
|
||||
{
|
||||
AddBottomTube(path, t, inflate);
|
||||
AddBottomBulb(scale, path, t, inflate);
|
||||
|
||||
path.CloseAllFigures();
|
||||
|
||||
return (path);
|
||||
}
|
||||
|
||||
#region AddBottomTube
|
||||
|
||||
private void AddBottomTube(GraphicsPath path, Rectangle t, int inflate)
|
||||
{
|
||||
if (GaugePointer.BarStyle == BarPointerStyle.Square || inflate > 0)
|
||||
{
|
||||
Point[] pts = new Point[] {
|
||||
new Point(t.X, t.Bottom),
|
||||
new Point(t.X, t.Y),
|
||||
new Point(t.Right, t.Y),
|
||||
new Point(t.Right, t.Bottom) };
|
||||
|
||||
path.AddLines(pts);
|
||||
}
|
||||
else
|
||||
{
|
||||
int y = Math.Min(t.Y + t.Width / 2, t.Bottom);
|
||||
int n = y - t.Y;
|
||||
|
||||
Rectangle r = new Rectangle(t.X, y - n, t.Width, n * 2);
|
||||
|
||||
Point[] pts = new Point[] {
|
||||
new Point(t.X, t.Bottom),
|
||||
new Point (t.X, y)};
|
||||
|
||||
path.AddLines(pts);
|
||||
|
||||
if (GaugePointer.BarStyle == BarPointerStyle.Rounded)
|
||||
{
|
||||
path.AddArc(r, 180, 180);
|
||||
}
|
||||
else
|
||||
{
|
||||
path.AddLine(new Point(r.X, r.Y + r.Height / 2),
|
||||
new Point(r.X + r.Width / 2, r.Y));
|
||||
}
|
||||
|
||||
pts = new Point[] {
|
||||
new Point(t.Right, y),
|
||||
new Point (t.Right, t.Bottom)};
|
||||
|
||||
path.AddLines(pts);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region AddBottomBulb
|
||||
|
||||
private void AddBottomBulb(GaugeLinearScale scale, GraphicsPath path, Rectangle t, int inflate)
|
||||
{
|
||||
int bulbRadius = (int)(GaugePointer.BulbSize * scale.Bounds.Width);
|
||||
|
||||
if (bulbRadius * 2 < t.Width)
|
||||
bulbRadius = t.Width / 2;
|
||||
|
||||
int m = (int)Math.Sqrt((bulbRadius * bulbRadius) - (Width * Width / 4)) + 4;
|
||||
|
||||
_BulbBounds = new Rectangle(
|
||||
t.X - bulbRadius + t.Width / 2,
|
||||
t.Bottom - bulbRadius + m - inflate, bulbRadius * 2, bulbRadius * 2);
|
||||
|
||||
if (inflate > 0)
|
||||
_BulbBounds.Inflate(inflate, inflate);
|
||||
|
||||
float angle = ((GaugePointer.BulbStyle == BulbStyle.Flask)
|
||||
? 90 : (float)(Math.Asin((double)(Width / 2) / bulbRadius) * 180 / Math.PI));
|
||||
|
||||
path.AddArc(_BulbBounds, angle + 270, 360 - (angle * 2));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetVerticalTopBulbPath
|
||||
|
||||
private GraphicsPath GetVerticalTopBulbPath(
|
||||
GaugeLinearScale scale, GraphicsPath path, Rectangle t, int inflate)
|
||||
{
|
||||
AddTopTube(path, t, inflate);
|
||||
AddTopBulb(scale, path, t, inflate);
|
||||
|
||||
path.CloseAllFigures();
|
||||
|
||||
return (path);
|
||||
}
|
||||
|
||||
#region AddTopTube
|
||||
|
||||
private void AddTopTube(GraphicsPath path, Rectangle t, int inflate)
|
||||
{
|
||||
if (GaugePointer.BarStyle == BarPointerStyle.Square || inflate > 0)
|
||||
{
|
||||
Point[] pts = new Point[] {
|
||||
new Point(t.Right, t.Y),
|
||||
new Point(t.Right, t.Bottom),
|
||||
new Point(t.X, t.Bottom),
|
||||
new Point(t.X, t.Y) };
|
||||
|
||||
path.AddLines(pts);
|
||||
}
|
||||
else
|
||||
{
|
||||
int y = Math.Max(t.Bottom - t.Width / 2, t.Y);
|
||||
int n = t.Bottom - y;
|
||||
|
||||
Rectangle r = new Rectangle(t.X, y - n, t.Width, n * 2);
|
||||
|
||||
Point[] pts = new Point[] {
|
||||
new Point(t.Right, t.Y),
|
||||
new Point(t.Right, y)};
|
||||
|
||||
path.AddLines(pts);
|
||||
|
||||
if (GaugePointer.BarStyle == BarPointerStyle.Rounded)
|
||||
{
|
||||
path.AddArc(r, 0, 180);
|
||||
}
|
||||
else
|
||||
{
|
||||
path.AddLine(new Point(r.Right, r.Y + r.Height / 2),
|
||||
new Point(r.X + r.Width / 2, r.Bottom));
|
||||
}
|
||||
|
||||
pts = new Point[] {
|
||||
new Point(t.X, y),
|
||||
new Point (t.X, t.Y)};
|
||||
|
||||
path.AddLines(pts);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region AddTopBulb
|
||||
|
||||
private void AddTopBulb(GaugeLinearScale scale, GraphicsPath path, Rectangle t, int inflate)
|
||||
{
|
||||
int bulbRadius = (int)(GaugePointer.BulbSize * scale.Bounds.Width);
|
||||
|
||||
if (bulbRadius * 2 < t.Width)
|
||||
bulbRadius = t.Width / 2;
|
||||
|
||||
int m = (int)Math.Sqrt((bulbRadius * bulbRadius) - (Width * Width / 4));
|
||||
|
||||
_BulbBounds = new Rectangle(
|
||||
t.X - bulbRadius + t.Width / 2,
|
||||
t.Y - (bulbRadius + m) + inflate, bulbRadius * 2, bulbRadius * 2);
|
||||
|
||||
if (inflate > 0)
|
||||
_BulbBounds.Inflate(inflate, inflate);
|
||||
|
||||
float angle = (GaugePointer.BulbStyle == BulbStyle.Flask)
|
||||
? 90 : (float)(Math.Asin((double)(t.Width / 2) / bulbRadius) * 180 / Math.PI);
|
||||
|
||||
path.AddArc(_BulbBounds, angle + 90, 360 - (angle * 2));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region RenderBarByCenter
|
||||
|
||||
protected override void RenderBarByCenter(
|
||||
Graphics g, GraphicsPath path, GradientFillColor fillColor)
|
||||
{
|
||||
using (PathGradientBrush br = new PathGradientBrush(path))
|
||||
{
|
||||
br.WrapMode = WrapMode.TileFlipXY;
|
||||
|
||||
br.CenterColor = fillColor.Color1;
|
||||
br.SurroundColors = new Color[] { fillColor.Color2 };
|
||||
|
||||
br.CenterPoint = new PointF(
|
||||
_BulbBounds.X + _BulbBounds.Width / 2, _BulbBounds.Y + _BulbBounds.Height / 2);
|
||||
|
||||
g.FillPath(br, path);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetPointerPath
|
||||
|
||||
public override GraphicsPath GetPointerPath()
|
||||
{
|
||||
if (PointerPath == null)
|
||||
{
|
||||
GaugeLinearScale scale = Scale as GaugeLinearScale;
|
||||
|
||||
if (scale != null)
|
||||
{
|
||||
if (Bounds.Width > 0 && Bounds.Height > 0)
|
||||
PointerPath = GetBulbBackPath(scale);
|
||||
}
|
||||
}
|
||||
|
||||
return (PointerPath);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region Enums
|
||||
|
||||
public enum BulbStyle
|
||||
{
|
||||
Bulb,
|
||||
Flask,
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
Reference in New Issue
Block a user