using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using FastReport.Utils;
namespace FastReport.Gauge
{
///
/// Represents a scale of a gauge.
///
#if !DEBUG
[DesignTimeVisible(false)]
#endif
public class GaugeScale : Component
{
#region Fields
private GaugeObject parent;
private Font font;
private FillBase textFill;
private ScaleTicks majorTicks;
private ScaleTicks minorTicks;
#endregion // Fields
#region Properties
///
/// Gets or sets major ticks of scale.
///
[Browsable(true)]
public ScaleTicks MajorTicks
{
get { return majorTicks; }
set { majorTicks = value; }
}
///
/// Gets or sets minor ticks of scale.
///
[Browsable(true)]
public ScaleTicks MinorTicks
{
get { return minorTicks; }
set { minorTicks = value; }
}
///
/// Gets or sets the parent gauge object.
///
[Browsable(false)]
public GaugeObject Parent
{
get { return parent; }
set { parent = value; }
}
///
/// Gets or sets the font of scale.
///
[Browsable(true)]
public Font Font
{
get { return font; }
set { font = value; }
}
///
/// Gets or sets the scale font color
///
[Editor("FastReport.TypeEditors.FillEditor, FastReport", typeof(UITypeEditor))]
public FillBase TextFill
{
get { return textFill; }
set { textFill = value; }
}
#endregion // Properties
#region Constructors
///
/// Initializes a new instance of the class.
///
/// The parent gauge object.
public GaugeScale(GaugeObject parent)
{
this.parent = parent;
font = new Font("Arial", 8.0f);
TextFill = new SolidFill(Color.Black);
majorTicks = new ScaleTicks();
minorTicks = new ScaleTicks();
}
#endregion // Constructors
#region Public Methods
///
/// Copies the contents of another GaugeScale.
///
/// The GaugeScale instance to copy the contents from.
public virtual void Assign(GaugeScale src)
{
Font = src.Font;
TextFill = src.TextFill;
}
///
/// Draws the scale of gauge.
///
/// Draw event arguments.
public virtual void Draw(FRPaintEventArgs e)
{
}
///
/// Serializes the gauge scale.
///
/// Writer object.
/// Scale property name.
/// Another GaugeScale to compare with.
///
/// This method is for internal use only.
///
public virtual void Serialize(FRWriter writer, string prefix, GaugeScale diff)
{
TextFill.Serialize(writer, prefix + ".TextFill", diff.TextFill);
if ((writer.SerializeTo != SerializeTo.Preview || !Font.Equals(diff.Font)) && writer.ItemName != "inherited")
{
writer.WriteValue(prefix + ".Font", Font);
}
}
#endregion // Public Methods
}
///
/// Represents a scale ticks.
///
[ToolboxItem(false)]
public class ScaleTicks : Component
{
#region Fields
private float length;
private int width;
private Color color;
private int count;
#endregion // Fields
#region Properties
///
/// Gets or sets the length of ticks.
///
[Browsable(false)]
public float Length
{
get { return length; }
set { length = value; }
}
///
/// Gets or sets the width of ticks.
///
[Browsable(true)]
public int Width
{
get { return width; }
set { width = value; }
}
///
/// Gets or sets the color of ticks.
///
[Browsable(true)]
public Color Color
{
get { return color; }
set { color = value; }
}
///
/// Gets or sets the count of ticks
///
[Browsable(false)]
public int Count
{
get { return count; }
set { count = value; }
}
#endregion // Properties
#region Constructors
///
/// Initializes a new instance of the class.
///
public ScaleTicks()
{
length = 8.0f;
width = 1;
color = Color.Black;
count = 6;
}
///
/// Initializes a new instance of the class.
///
/// Ticks length.
/// Ticks width.
/// Ticks color.
public ScaleTicks(float length, int width, Color color)
{
this.length = length;
this.width = width;
this.color = color;
}
///
/// Initializes a new instance of the class.
///
/// Ticks length.
/// Ticks width.
/// Ticks color.
/// Ticks count.
public ScaleTicks(float length, int width, Color color, int count)
{
this.length = length;
this.width = width;
this.color = color;
this.count = count;
}
#endregion // Constructors
#region Public Methods
///
/// Copies the contents of another ScaleTicks.
///
/// The ScaleTicks instance to copy the contents from.
public virtual void Assign(ScaleTicks src)
{
Length = src.Length;
Width = src.Width;
Color = src.Color;
}
///
/// Serializes the scale ticks.
///
/// Writer object.
/// Scale ticks property name.
/// Another ScaleTicks to compare with.
///
/// This method is for internal use only.
///
public virtual void Serialize(FRWriter writer, string prefix, ScaleTicks diff)
{
if (Length != diff.Length)
{
writer.WriteFloat(prefix + ".Length", Length);
}
if (Width != diff.Width)
{
writer.WriteInt(prefix + ".Width", Width);
}
if (Color != diff.Color)
{
writer.WriteValue(prefix + ".Color", Color);
}
}
#endregion // Public Methods
}
}