DotNet 4.8.1 build of DotNetBar

This commit is contained in:
2025-02-07 10:35:23 -05:00
parent 33439b63a0
commit 6b0a5d60f4
2609 changed files with 989814 additions and 7 deletions

View File

@@ -0,0 +1,674 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Globalization;
using System.Windows.Forms;
using DevComponents.Instrumentation.Primitives;
namespace DevComponents.Instrumentation
{
/// <summary>
/// Collection of GaugeSections
/// </summary>
public class GaugeSectionCollection : GenericCollection<GaugeSection>
{
#region ICloneable Members
public override object Clone()
{
GaugeSectionCollection copy = new GaugeSectionCollection();
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
internal void CopyToItem(GaugeSectionCollection copy)
{
foreach (GaugeSection item in this)
{
GaugeSection ic = new GaugeSection();
item.CopyToItem(ic);
copy.Add(ic);
}
}
#endregion
}
[TypeConverter(typeof(GaugeSectionConvertor))]
public class GaugeSection : GaugeStrip
{
#region Private variables
private float _Width;
private int _AbsWidth;
#endregion
public GaugeSection(GaugeScale scale)
: base(scale)
{
}
public GaugeSection()
{
}
#region Public properties
#region Width
/// <summary>
/// Gets or sets the Width of the Section, specified as a percentage
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(.0f)]
[Editor("DevComponents.Instrumentation.Design.WidthRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates the Width of the Section, specified as a percentage.")]
public float Width
{
get { return (_Width); }
set
{
if (value < 0 || value > 1)
throw new ArgumentException("Width must be between 0 and 1.");
if (_Width != value)
{
_Width = value;
OnGaugeItemChanged();
}
}
}
#endregion
#endregion
#region RecalcLayout
public override void RecalcLayout()
{
base.RecalcLayout();
if (Scale is GaugeCircularScale)
CalcCircularLayout(Scale as GaugeCircularScale);
else if (Scale is GaugeLinearScale)
CalcLinearLayout(Scale as GaugeLinearScale);
}
#region CalcCircularLayout
private void CalcCircularLayout(GaugeCircularScale scale)
{
int radius = scale.AbsRadius;
int scaleOffset = (int)(radius * ScaleOffset);
_AbsWidth = (int)(radius * (_Width > 0 ? _Width : scale.Width));
Rectangle r = scale.Bounds;
r.Inflate(scaleOffset, scaleOffset);
Bounds = r;
}
#endregion
#region CalcLinearLayout
#region CalcLinearLayout
private void CalcLinearLayout(GaugeLinearScale scale)
{
float spread = (float)(scale.MaxValue - scale.MinValue);
if (spread == 0)
spread = 1;
if (scale.Orientation == Orientation.Horizontal)
CalcHorizontalLayout(scale, spread);
else
CalcVerticalLayout(scale, spread);
}
#endregion
#region CalcHorizontalLayout
private void CalcHorizontalLayout(GaugeLinearScale scale, float spread)
{
int length = scale.ScaleBounds.Width;
int width = scale.ScaleBounds.Height;
float dl = length / spread;
int start = (int)(dl * MinValue);
int len = (int)(dl * (MaxValue - MinValue));
int offset = (int)(width * ScaleOffset);
_AbsWidth = (int)(_Width > 0 ? width * _Width : width);
Rectangle r = scale.Bounds;
if (scale.Reversed == true)
r.X = r.Right - (start + len);
else
r.X += start;
r.Width = len;
r.Y = scale.Center.Y - (_AbsWidth / 2) + offset;
r.Height = _AbsWidth;
Bounds = r;
}
#endregion
#region CalcVerticalLayout
private void CalcVerticalLayout(GaugeLinearScale scale, float spread)
{
int length = scale.ScaleBounds.Height;
int width = scale.ScaleBounds.Width;
int n = width;
float dl = length / spread;
int start = (int)(dl * MinValue);
int len = (int)(dl * (MaxValue - MinValue));
int offset = (int)(length * ScaleOffset);
_AbsWidth = (int)(_Width > 0 ? n * _Width : n);
Rectangle r = scale.Bounds;
if (scale.Reversed == true)
r.Y += start;
else
r.Y = r.Bottom - (start + len);
r.X = scale.Center.X - (_AbsWidth / 2) + offset;
r.Width = _AbsWidth;
r.Height = len;
Bounds = r;
}
#endregion
#endregion
#endregion
#region OnPaint
public override void OnPaint(PaintEventArgs e)
{
RecalcLayout();
if (Scale.GaugeControl.OnPreRenderScaleSection(e, this) == false)
{
if (Scale is GaugeCircularScale)
{
if (SweepAngle != 0)
PaintCircularSection(e, Scale as GaugeCircularScale);
}
else if (Scale is GaugeLinearScale)
{
PaintLinearSection(e, Scale as GaugeLinearScale);
}
Scale.GaugeControl.OnPostRenderScaleSection(e, this);
}
}
#endregion
#region PaintCircularSection
#region PaintCircularSection
private void PaintCircularSection(PaintEventArgs e, GaugeCircularScale scale)
{
Graphics g = e.Graphics;
int radius = scale.AbsRadius;
int n = (int)(radius * (_Width > 0 ? _Width : scale.Width));
if (n > 0 && Bounds.Width > 0 && Bounds.Height > 0 && Math.Abs(SweepAngle) > .05)
{
if (FillColor.End.IsEmpty == true || FillColor.Color1 == FillColor.Color2 ||
FillColor.GradientFillType == GradientFillType.None)
{
using (Pen pen = new Pen(FillColor.Color1, n))
g.DrawArc(pen, Bounds, StartAngle, SweepAngle);
}
else
{
switch (FillColor.GradientFillType)
{
case GradientFillType.Auto:
case GradientFillType.StartToEnd:
PaintCircularStartToEnd(g, Bounds, n, scale);
break;
case GradientFillType.Angle:
PaintCircularByAngle(g, Bounds, n);
break;
case GradientFillType.Center:
PaintCircularByCenter(g, Bounds, n);
break;
case GradientFillType.HorizontalCenter:
PaintCircularByHc(g, Bounds, n);
break;
case GradientFillType.VerticalCenter:
PaintCircularByVc(g, Bounds, n);
break;
}
}
}
}
#endregion
#region PaintCircularStartToEnd
private void PaintCircularStartToEnd(Graphics g,
Rectangle r, int n, GaugeCircularScale scale)
{
using (PathGradientBrush br = scale.CreateGradient(
Scale.GaugeControl.Frame.Bounds, StartAngle, SweepAngle, FillColor, 10))
{
using (Pen pen = new Pen(br, n))
g.DrawArc(pen, r, StartAngle, SweepAngle);
}
}
#endregion
#region PaintCircularByAngle
private void PaintCircularByAngle(Graphics g, Rectangle r, int n)
{
Rectangle t = r;
t.Inflate(10, 10);
using (Brush br = FillColor.GetBrush(t))
{
using (Pen pen = new Pen(br, n))
g.DrawArc(pen, r, StartAngle, SweepAngle);
}
}
#endregion
#region PaintCircularByCenter
private void PaintCircularByCenter(Graphics g, Rectangle r, int n)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddArc(r, StartAngle, SweepAngle);
using (Pen pen = new Pen(Color.Black, n))
path.Widen(pen);
using (PathGradientBrush br = new PathGradientBrush(path))
{
br.CenterColor = FillColor.Color1;
br.SurroundColors = new Color[] {FillColor.Color2};
br.CenterPoint = Scale.Center;
float m = (float)n / (r.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 PaintCircularByHc
private void PaintCircularByHc(Graphics g, Rectangle r, int n)
{
Rectangle t = r;
t.Height /= 2;
using (LinearGradientBrush br = new
LinearGradientBrush(t, FillColor.Color1, FillColor.Color2, 90))
{
br.WrapMode = WrapMode.TileFlipXY;
using (Pen pen = new Pen(br, n))
g.DrawArc(pen, r, StartAngle, SweepAngle);
}
}
#endregion
#region PaintCircularByVc
private void PaintCircularByVc(Graphics g, Rectangle r, int n)
{
Rectangle t = r;
t.Width /= 2;
using (LinearGradientBrush br = new
LinearGradientBrush(t, FillColor.Color1, FillColor.Color2, 0f))
{
br.WrapMode = WrapMode.TileFlipXY;
using (Pen pen = new Pen(br, n))
g.DrawArc(pen, r, StartAngle, SweepAngle);
}
}
#endregion
#endregion
#region PaintLinearSection
#region PaintLinearSection
private void PaintLinearSection(PaintEventArgs e, GaugeLinearScale scale)
{
Graphics g = e.Graphics;
if (Bounds.Width > 0 && Bounds.Height > 0)
{
if (FillColor.End.IsEmpty == true || FillColor.Color1 == FillColor.Color2 ||
FillColor.GradientFillType == GradientFillType.None)
{
using (Brush br = new SolidBrush(FillColor.Color1))
g.FillRectangle(br, Bounds);
}
else
{
switch (FillColor.GradientFillType)
{
case GradientFillType.Auto:
case GradientFillType.StartToEnd:
PaintLinearStartToEnd(g, Bounds, scale);
break;
case GradientFillType.Angle:
PaintLinearByAngle(g, Bounds);
break;
case GradientFillType.Center:
PaintLinearByCenter(g, Bounds);
break;
case GradientFillType.HorizontalCenter:
PaintLinearByHc(g, Bounds);
break;
case GradientFillType.VerticalCenter:
PaintLinearByVc(g, Bounds);
break;
}
}
}
}
#endregion
#region PaintLinearStartToEnd
private void PaintLinearStartToEnd(
Graphics g, Rectangle r, GaugeLinearScale scale)
{
int angle = scale.Orientation == Orientation.Horizontal ? 0 : -90;
if (scale.Reversed == true)
angle += 180;
using (Brush br = FillColor.GetBrush(r, angle))
g.FillRectangle(br, r);
}
#endregion
#region PaintLinearByAngle
private void PaintLinearByAngle(Graphics g, Rectangle r)
{
using (Brush br = FillColor.GetBrush(r))
g.FillRectangle(br, r);
}
#endregion
#region PaintLinearByCenter
private void PaintLinearByCenter(Graphics g, Rectangle r)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddRectangle(r);
using (PathGradientBrush br = new PathGradientBrush(path))
{
Point pt = new Point(r.X + r.Width / 2, r.Y + r.Height / 2);
br.CenterColor = FillColor.Color1;
br.SurroundColors = new Color[] { FillColor.Color2 };
br.CenterPoint = pt;
g.FillPath(br, path);
}
}
}
#endregion
#region PaintLinearByHc
private void PaintLinearByHc(Graphics g, Rectangle r)
{
Rectangle t = r;
if (r.Height >= 2)
t.Height /= 2;
using (LinearGradientBrush br = new
LinearGradientBrush(t, FillColor.Color1, FillColor.Color2, 90))
{
br.WrapMode = WrapMode.TileFlipXY;
g.FillRectangle(br, r);
}
}
#endregion
#region PaintLinearByVc
private void PaintLinearByVc(Graphics g, Rectangle r)
{
Rectangle t = r;
if (t.Width >= 2)
t.Width /= 2;
using (LinearGradientBrush br = new
LinearGradientBrush(t, FillColor.Color1, FillColor.Color2, 0f))
{
br.WrapMode = WrapMode.TileFlipXY;
g.FillRectangle(br, r);
}
}
#endregion
#endregion
#region FindItem
internal override GaugeItem FindItem(Point pt)
{
GraphicsPath path = GetSectionPath();
if (path != null)
{
if (path.IsVisible(pt) == true)
return (this);
}
return (null);
}
#endregion
#region GetSectionPath
public GraphicsPath GetSectionPath()
{
if (StripePath == null)
{
if (Scale is GaugeCircularScale)
StripePath = GetCSectionPath(Scale as GaugeCircularScale);
else
StripePath = GetLSectionPath();
}
return (StripePath);
}
#endregion
#region GetCSectionPath
private GraphicsPath GetCSectionPath(GaugeCircularScale scale)
{
int radius = scale.AbsRadius;
int n = (int)(radius * (_Width > 0 ? _Width : scale.Width));
if (n > 0 && Bounds.Width > 0 && Bounds.Height > 0)
{
GraphicsPath path = new GraphicsPath();
Rectangle r = Bounds;
r.Inflate(n / 2, n / 2);
path.AddArc(r, StartAngle, SweepAngle);
r.Inflate(-n, -n);
path.AddArc(r, StartAngle + SweepAngle, -SweepAngle);
path.CloseAllFigures();
return (path);
}
return (null);
}
#endregion
#region GetLSectionPath
private GraphicsPath GetLSectionPath()
{
if (Bounds.Width > 0 && Bounds.Height > 0)
{
GraphicsPath path = new GraphicsPath();
path.AddRectangle(Bounds);
return (path);
}
return (null);
}
#endregion
#region ICloneable Members
public override object Clone()
{
GaugeSection copy = new GaugeSection();
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
public override void CopyToItem(GaugeItem copy)
{
GaugeSection c = copy as GaugeSection;
if (c != null)
{
base.CopyToItem(c);
c.Width = _Width;
}
}
#endregion
}
#region GaugeScaleConvertor
public class GaugeSectionConvertor : ExpandableObjectConverter
{
public override object ConvertTo(
ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
GaugeSection section = value as GaugeSection;
if (section != null)
{
//ColorConverter cvt = new ColorConverter();
//if (lct.Start != Color.Empty)
// return (cvt.ConvertToString(lct.Start));
//if (lct.End != Color.Empty)
// return (cvt.ConvertToString(lct.End));
//if (lct.GradientAngle != 90)
// return (lct.GradientAngle.ToString());
return (String.Empty);
}
}
return (base.ConvertTo(context, culture, value, destinationType));
}
}
#endregion
}

View File

@@ -0,0 +1,776 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Text;
namespace DevComponents.Instrumentation
{
public class GaugeStrip : GaugeItem, IDisposable
{
#region Events
[Description("Occurs when the coverage of a Strip changes.")]
public event EventHandler<EventArgs> StripCoverChanged;
#endregion
#region Private variables
private double _StartValue;
private double _EndValue;
private float _ScaleOffset;
private GradientFillColor _FillColor;
private Color _LabelColor;
private GradientFillColor _CapFillColor;
private GradientFillColor _PointerFillColor;
private GradientFillColor _MajorTickMarkFillColor;
private GradientFillColor _MinorTickMarkFillColor;
private GaugeScale _Scale;
private float _StartAngle;
private float _SweepAngle;
private double _MinValue;
private double _MaxValue;
private Rectangle _Bounds;
private GraphicsPath _StripePath;
#endregion
public GaugeStrip(GaugeScale scale)
: this()
{
_Scale = scale;
}
public GaugeStrip()
{
FillColor = new GradientFillColor();
_StartValue = double.NaN;
_EndValue = double.NaN;
}
#region Public properties
#region CapFillColor
/// <summary>
/// Gets or sets the Cap Fill Color
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the Cap Fill Color.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public GradientFillColor CapFillColor
{
get
{
if (_CapFillColor == null)
{
_CapFillColor = new GradientFillColor();
_CapFillColor.ColorTableChanged += PointerFillColor_ColorTableChanged;
}
return (_CapFillColor);
}
set
{
if (_CapFillColor != null)
_CapFillColor.ColorTableChanged -= PointerFillColor_ColorTableChanged;
_CapFillColor = value;
if (_CapFillColor != null)
_CapFillColor.ColorTableChanged += PointerFillColor_ColorTableChanged;
OnGaugeItemChanged(true);
}
}
#endregion
#region EndValue
/// <summary>
/// Gets or sets the Ending value for the area
/// </summary>
[Browsable(true), Category("Layout"), DefaultValue(double.NaN)]
[Description("Indicates the Ending value for the area.")]
public double EndValue
{
get { return (_EndValue); }
set
{
if (_EndValue != value)
{
_EndValue = value;
OnStripCoverChanged();
}
}
}
#endregion
#region PointerFillColor
/// <summary>
/// Gets or sets the Pointer Fill Color
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the Pointer Fill Color.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public GradientFillColor PointerFillColor
{
get
{
if (_PointerFillColor == null)
{
_PointerFillColor = new GradientFillColor();
_PointerFillColor.ColorTableChanged += PointerFillColor_ColorTableChanged;
}
return (_PointerFillColor);
}
set
{
if (_PointerFillColor != null)
_PointerFillColor.ColorTableChanged -= PointerFillColor_ColorTableChanged;
_PointerFillColor = value;
if (_PointerFillColor != null)
_PointerFillColor.ColorTableChanged += PointerFillColor_ColorTableChanged;
OnGaugeItemChanged(true);
}
}
#endregion
#region FillColor
/// <summary>
/// Gets or sets the area Fill Color
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the area Fill Color.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public GradientFillColor FillColor
{
get
{
if (_FillColor == null)
{
_FillColor = new GradientFillColor();
_FillColor.ColorTableChanged += FillColor_ColorTableChanged;
}
return (_FillColor);
}
set
{
if (_FillColor != null)
_FillColor.ColorTableChanged -= FillColor_ColorTableChanged;
_FillColor = value;
if (_FillColor != null)
_FillColor.ColorTableChanged += FillColor_ColorTableChanged;
OnGaugeItemChanged();
}
}
#endregion
#region LabelColor
/// <summary>
/// Gets or sets the Section Label Color
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the Section Label Color.")]
public Color LabelColor
{
get { return (_LabelColor); }
set
{
if (_LabelColor != value)
{
_LabelColor = value;
OnGaugeItemChanged();
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal virtual bool ShouldSerializeLabelColor()
{
return (_LabelColor.IsEmpty == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal virtual void ResetLabelColor()
{
LabelColor = Color.Empty;
}
#endregion
#region MajorTickMarkFillColor
/// <summary>
/// Gets or sets the MajorTickMark Fill Color
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the MajorTickMark Fill Color.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public GradientFillColor MajorTickMarkFillColor
{
get
{
if (_MajorTickMarkFillColor == null)
{
_MajorTickMarkFillColor = new GradientFillColor();
_MajorTickMarkFillColor.ColorTableChanged += TickMarkFillColor_ColorTableChanged;
}
return (_MajorTickMarkFillColor);
}
set
{
if (_MajorTickMarkFillColor != null)
_MajorTickMarkFillColor.ColorTableChanged -= TickMarkFillColor_ColorTableChanged;
_MajorTickMarkFillColor = value;
if (_MajorTickMarkFillColor != null)
_MajorTickMarkFillColor.ColorTableChanged += TickMarkFillColor_ColorTableChanged;
OnGaugeItemChanged(true);
}
}
#endregion
#region MinorTickMarkFillColor
/// <summary>
/// Gets or sets the MinorTickMark Fill Color
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the MinorTickMark Fill Color.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public GradientFillColor MinorTickMarkFillColor
{
get
{
if (_MinorTickMarkFillColor == null)
{
_MinorTickMarkFillColor = new GradientFillColor();
_MinorTickMarkFillColor.ColorTableChanged += TickMarkFillColor_ColorTableChanged;
}
return (_MinorTickMarkFillColor);
}
set
{
if (_MinorTickMarkFillColor != null)
_MinorTickMarkFillColor.ColorTableChanged -= TickMarkFillColor_ColorTableChanged;
_MinorTickMarkFillColor = value;
if (_MinorTickMarkFillColor != null)
_MinorTickMarkFillColor.ColorTableChanged += TickMarkFillColor_ColorTableChanged;
OnGaugeItemChanged(true);
}
}
#endregion
#region Scale
/// <summary>
/// Gets the associated Scale
/// </summary>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public GaugeScale Scale
{
get { return (_Scale); }
internal set { _Scale = value; }
}
#endregion
#region ScaleOffset
/// <summary>
/// Gets or sets the distance from the Scale, measured as a percentage
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(0f)]
[Editor("DevComponents.Instrumentation.Design.OffsetRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates the distance from the Scale, measured as a percentage.")]
public float ScaleOffset
{
get { return (_ScaleOffset); }
set
{
if (_ScaleOffset != value)
{
if (value < -1 || value > 1)
throw new ArgumentException("Scale Offset must be bwtween -1 and +1");
_ScaleOffset = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region StartValue
/// <summary>
/// Gets or sets the Starting value for the area
/// </summary>
[Browsable(true), Category("Layout"), DefaultValue(double.NaN)]
[Description("Indicates the Starting value for the area.")]
public double StartValue
{
get { return (_StartValue); }
set
{
if (_StartValue != value)
{
_StartValue = value;
OnStripCoverChanged();
}
}
}
private void OnStripCoverChanged()
{
if (StripCoverChanged != null)
StripCoverChanged(this, EventArgs.Empty);
OnGaugeItemChanged(true);
}
#endregion
#region Visible
/// <summary>
/// Gets or sets the item Visibility state.
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(true)]
[Description("Indicates the item Visibility state.")]
[ParenthesizePropertyName(true)]
public override bool Visible
{
get { return (base.Visible); }
set
{
if (base.Visible != value)
{
base.Visible = value;
OnStripCoverChanged();
}
}
}
#endregion
#endregion
#region Internal properties
#region Bounds
internal Rectangle Bounds
{
get { return (_Bounds); }
set { _Bounds = value; }
}
#endregion
#region HasCapFillColor
internal bool HasCapFillColor
{
get { return (_CapFillColor != null && _CapFillColor.IsEmpty == false); }
}
#endregion
#region HasMajorTickMarkFillColor
internal bool HasMajorTickMarkFillColor
{
get { return (_MajorTickMarkFillColor != null &&
_MajorTickMarkFillColor.IsEmpty == false); }
}
#endregion
#region HasMinorTickMarkFillColor
internal bool HasMinorTickMarkFillColor
{
get { return (_MinorTickMarkFillColor != null && _MinorTickMarkFillColor.IsEmpty == false); }
}
#endregion
#region HasPointerFillColor
internal bool HasPointerFillColor
{
get { return (_PointerFillColor != null && _PointerFillColor.IsEmpty == false); }
}
#endregion
#region MaxValue
internal double MaxValue
{
get { return (_MaxValue); }
set { _MaxValue = value; }
}
#endregion
#region MinValue
internal double MinValue
{
get { return (_MinValue); }
set { _MinValue = value; }
}
#endregion
#region StartAngle
internal float StartAngle
{
get { return (_StartAngle); }
}
#endregion
#region StripePath
internal GraphicsPath StripePath
{
get { return (_StripePath); }
set
{
if (_StripePath != value)
{
if (_StripePath != null)
_StripePath.Dispose();
_StripePath = value;
}
}
}
#endregion
#region SweepAngle
internal float SweepAngle
{
get { return (_SweepAngle); }
}
#endregion
#endregion
#region Event processing
void FillColor_ColorTableChanged(object sender, EventArgs e)
{
OnGaugeItemChanged(true);
}
void TickMarkFillColor_ColorTableChanged(object sender, EventArgs e)
{
OnGaugeItemChanged(true);
}
void PointerFillColor_ColorTableChanged(object sender, EventArgs e)
{
OnGaugeItemChanged(true);
}
#endregion
#region RecalcLayout
public override void RecalcLayout()
{
if (NeedRecalcLayout == true)
{
base.RecalcLayout();
CalcStripMetrics();
_Scale.NeedTickMarkRecalcLayout = true;
_Scale.NeedPointerRecalcLayout = true;
StripePath = null;
}
}
#region CalcStripMetrics
private void CalcStripMetrics()
{
_MinValue = (_StartValue.Equals(double.NaN) ? _Scale.MinValue : _StartValue);
_MaxValue = (_EndValue.Equals(double.NaN) ? _Scale.MaxValue : _EndValue);
if (_MinValue > _Scale.MaxValue)
_MinValue = _Scale.MaxValue;
_MinValue -= _Scale.MinValue;
if (_MinValue < 0)
_MinValue = 0;
if (_MaxValue < _Scale.MinValue)
_MaxValue = _Scale.MinValue;
_MaxValue -= _Scale.MinValue;
if (_MaxValue > _Scale.MaxValue - _Scale.MinValue)
_MaxValue = _Scale.MaxValue - _Scale.MinValue;
if (Scale is GaugeCircularScale)
CalcCircularMetrics(Scale as GaugeCircularScale);
}
#region CalcCircularMetrics
private void CalcCircularMetrics(GaugeCircularScale scale)
{
float spread = (float)Math.Abs(scale.MaxValue - scale.MinValue);
if (spread == 0)
spread = 1;
float dv = scale.SweepAngle / spread;
_StartAngle = (float)(dv * _MinValue) + scale.StartAngle;
_SweepAngle = (float)(dv * (_MaxValue - _MinValue));
if (scale.Reversed == true)
{
_StartAngle = (scale.StartAngle + scale.SweepAngle) - (_StartAngle - scale.StartAngle);
_SweepAngle = -_SweepAngle;
}
}
#endregion
#endregion
#endregion
#region GetPoint
protected PointF GetPoint(float radius, float angle)
{
PointF pt = new PointF();
// Normalize the angle and calculate some
// working vars
if (angle < 0)
angle += 360;
angle = angle % 360;
// Determine the angle quadrant, and then calculate
// the intersecting coordinate accordingly
double radians = GetRadians(angle % 90);
if (angle < 90)
{
pt.X = (float)(Math.Cos(radians) * radius);
pt.Y = (float)(Math.Sin(radians) * radius);
}
else if (angle < 180)
{
pt.X = -(float)(Math.Sin(radians) * radius);
pt.Y = (float)(Math.Cos(radians) * radius);
}
else if (angle < 270)
{
pt.X = -(float)(Math.Cos(radians) * radius);
pt.Y = -(float)(Math.Sin(radians) * radius);
}
else
{
pt.X = (float)(Math.Sin(radians) * radius);
pt.Y = -(float)(Math.Cos(radians) * radius);
}
pt.X += _Scale.Center.X;
pt.Y += _Scale.Center.Y;
return (pt);
}
#endregion
#region GetRadians
/// <summary>
/// Converts Degrees to Radians
/// </summary>
/// <param name="theta">Degrees</param>
/// <returns>Radians</returns>
protected double GetRadians(float theta)
{
return (theta * Math.PI / 180);
}
#endregion
#region ValueInRange
internal bool ValueInRange(double value)
{
RecalcLayout();
double startValue = (_StartValue.Equals(double.NaN) ? MinValue : _StartValue);
double endValue = (_EndValue.Equals(double.NaN) ? MaxValue : _EndValue);
if (startValue > endValue)
{
double temp = startValue;
startValue = endValue;
endValue = temp;
}
return (value >= startValue && value <= endValue);
}
#endregion
#region ProcessTemplateText
protected override void ProcessTemplateText(
GaugeControl gauge, StringBuilder sb, string key, string data)
{
switch (key)
{
case "StartValue":
sb.Append(string.IsNullOrEmpty(data)
? _StartValue.ToString()
: String.Format("{0:" + data + "}", _StartValue));
break;
case "EndValue":
sb.Append(string.IsNullOrEmpty(data)
? _EndValue.ToString()
: String.Format("{0:" + data + "}", _EndValue));
break;
default:
base.ProcessTemplateText(gauge, sb, key, data);
break;
}
}
#endregion
#region IDisposable Members
void IDisposable.Dispose()
{
StripePath = null;
}
#endregion
#region ICloneable Members
public override object Clone()
{
GaugeStrip copy = new GaugeStrip();
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
public override void CopyToItem(GaugeItem copy)
{
GaugeStrip c = copy as GaugeStrip;
if (c != null)
{
base.CopyToItem(c);
if (_CapFillColor != null)
c.CapFillColor = (GradientFillColor)_CapFillColor.Clone();
c.EndValue = _EndValue;
if (_PointerFillColor != null)
c.PointerFillColor = (GradientFillColor)_PointerFillColor.Clone();
if (_FillColor != null)
c.FillColor = (GradientFillColor)_FillColor.Clone();
c.LabelColor = _LabelColor;
if (_MajorTickMarkFillColor != null)
c.MajorTickMarkFillColor = (GradientFillColor)_MajorTickMarkFillColor.Clone();
if (_MinorTickMarkFillColor != null)
c.MinorTickMarkFillColor = (GradientFillColor)_MinorTickMarkFillColor.Clone();
c.ScaleOffset = _ScaleOffset;
c.StartValue = _StartValue;
}
}
#endregion
}
}