//============================================================================
//ZedGraph Class Library - A Flexible Line Graph/Bar Graph Library in C#
//Copyright ?2006  John Champion
//
//This library is free software; you can redistribute it and/or
//modify it under the terms of the GNU Lesser General Public
//License as published by the Free Software Foundation; either
//version 2.1 of the License, or (at your option) any later version.
//
//This library is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//Lesser General Public License for more details.
//
//You should have received a copy of the GNU Lesser General Public
//License along with this library; if not, write to the Free Software
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//=============================================================================
using System;
using System.Drawing;
using System.Text;
using System.Runtime.Serialization;
using System.Security.Permissions;
namespace DrawGraph
{
	/// 
	/// Class that holds the specific properties for the minor tics.
	/// 
	///  John Champion 
	///  $Revision: 3.1 $ $Date: 2006/06/24 20:26:44 $ 
	[Serializable]
	public class MinorTic : ICloneable, ISerializable
	{
		internal bool	_isOutside,
							_isInside,
							_isOpposite,
							_isCrossOutside,
							_isCrossInside;
		internal float _penWidth,
							_size;
		internal Color _color;
	#region Constructors
		/// 
		/// Default Constructor
		/// 
		public MinorTic()
		{
			_size = Default.Size;
			_color = Default.Color;
			_penWidth = Default.PenWidth;
			this.IsOutside = Default.IsOutside;
			this.IsInside = Default.IsInside;
			this.IsOpposite = Default.IsOpposite;
			_isCrossOutside = Default.IsCrossOutside;
			_isCrossInside = Default.IsCrossInside;
		}
		/// 
		/// Copy constructor.
		/// 
		/// The  that is to be copied.
		public MinorTic( MinorTic rhs )
		{
			_size = rhs._size;
			_color = rhs._color;
			_penWidth = rhs._penWidth;
			this.IsOutside = rhs.IsOutside;
			this.IsInside = rhs.IsInside;
			this.IsOpposite = rhs.IsOpposite;
			_isCrossOutside = rhs._isCrossOutside;
			_isCrossInside = rhs._isCrossInside;
		}
		/// 
		/// Implement the  interface in a typesafe manner by just
		/// calling the typed version of 
		/// 
		/// A deep copy of this object
		object ICloneable.Clone()
		{
			return this.Clone();
		}
		/// 
		/// Typesafe, deep-copy clone method.
		/// 
		/// A new, independent copy of this class
		public MinorTic Clone()
		{
			return new MinorTic( this );
		}
	#endregion
	#region Properties
		/// 
		/// The color to use for drawing the tics of this class instance
		/// 
		///  The color is defined using the
		///  class
		/// .
		/// 
		/// 
		public Color Color
		{
			get { return _color; }
			set { _color = value; }
		}
		/// 
		/// The length of the major tic marks.
		/// 
		/// 
		/// This length will be scaled
		/// according to the  for the
		/// 
		/// 
		/// The tic size is measured in points (1/72 inch)
		/// .
		/// 
		/// 
		/// 
		public float Size
		{
			get { return _size; }
			set { _size = value; }
		}
		/// 
		/// Calculate the scaled tic size for this 
		/// 
		/// 
		/// The scaling factor to be used for rendering objects.  This is calculated and
		/// passed down by the parent  object using the
		///  method, and is used to proportionally adjust
		/// font sizes, etc. according to the actual size of the graph.
		/// 
		/// The scaled tic size, in points (1/72 inch)
		/// 
		/// 
		/// 
		public float ScaledTic( float scaleFactor )
		{
			return (float)( _size * scaleFactor );
		}
		/// 
		/// This is convenience property sets the status of all the different
		/// tic properties in this instance to the same value.  true to activate all tics,
		/// false to clear all tics.
		/// 
		/// 
		/// This setting does not persist.  That is, you can clear all the tics with
		///  = false, then activate them individually (example:
		///  = true).
		/// 
		/// 
		/// 
		/// 
		/// 
		/// 
		public bool IsAllTics
		{
			set
			{
				this.IsOutside = value;
				this.IsInside = value;
				this.IsOpposite = value;
				_isCrossOutside = value;
				_isCrossInside = value;
			}
		}
		/// 
		/// Gets or sets a property that determines whether or not the minor outside tic marks
		/// are shown.
		/// 
		/// 
		/// These are the tic marks on the outside of the  border.
		/// The minor tic spacing is controlled by .
		/// 
		/// true to show the minor outside tic marks, false otherwise
		/// .
		/// 
		/// 
		/// 
		/// 
		/// 
		public bool IsOutside
		{
			get { return _isOutside; }
			set { _isOutside = value; }
		}
		/// 
		/// Gets or sets a property that determines whether or not the major inside tic marks
		/// are shown.
		/// 
		/// 
		/// These are the tic marks on the inside of the  border.
		/// The major tic spacing is controlled by .
		/// 
		/// true to show the major inside tic marks, false otherwise
		/// .
		/// 
		/// 
		/// 
		/// 
		/// 
		public bool IsInside
		{
			get { return _isInside; }
			set { _isInside = value; }
		}
		/// 
		/// Gets or sets a property that determines whether or not the major opposite tic marks
		/// are shown.
		/// 
		/// 
		/// These are the tic marks on the inside of the  border on
		/// the opposite side from the axis.
		/// The major tic spacing is controlled by .
		/// 
		/// true to show the major opposite tic marks, false otherwise
		/// .
		/// 
		/// 
		/// 
		/// 
		/// 
		public bool IsOpposite
		{
			get { return _isOpposite; }
			set { _isOpposite = value; }
		}
		/// 
		/// Gets or sets the display mode for the  major outside 
		/// "cross" tic marks.
		/// 
		/// 
		/// The "cross" tics are a special, additional set of tic marks that
		/// always appear on the actual axis, even if it has been shifted due
		/// to the  setting.  The other tic marks are always
		/// fixed to the edges of the .  The cross tics
		/// are normally not displayed, since, if  is true,
		/// they will exactly overlay the "normal" and "inside" tics.  If
		///  is false, then you will most likely want to
		/// enable the cross tics.
		/// The major tic spacing is controlled by .
		/// 
		/// true to show the major cross tic marks, false otherwise
		public bool IsCrossOutside
		{
			get { return _isCrossOutside; }
			set { _isCrossOutside = value; }
		}
		/// 
		/// Gets or sets the display mode for the  major inside 
		/// "cross" tic marks.
		/// 
		/// 
		/// The "cross" tics are a special, additional set of tic marks that
		/// always appear on the actual axis, even if it has been shifted due
		/// to the  setting.  The other tic marks are always
		/// fixed to the edges of the .  The cross tics
		/// are normally not displayed, since, if  is true,
		/// they will exactly overlay the "normal" and "inside" tics.  If
		///  is false, then you will most likely want to
		/// enable the cross tics.
		/// The major tic spacing is controlled by .
		/// 
		/// true to show the major cross tic marks, false otherwise
		public bool IsCrossInside
		{
			get { return _isCrossInside; }
			set { _isCrossInside = value; }
		}
		/// 
		/// Gets or sets the pen width to be used when drawing the tic marks for
		/// this 
		/// 
		/// The pen width is defined in points (1/72 inch)
		/// .
		/// 
		/// 
		public float PenWidth
		{
			get { return _penWidth; }
			set { _penWidth = value; }
		}
	#endregion
	#region Serialization
		/// 
		/// Current schema value that defines the version of the serialized file
		/// 
		public const int schema = 10;
		/// 
		/// Constructor for deserializing objects
		/// 
		/// A  instance that defines the serialized data
		/// 
		/// A  instance that contains the serialized data
		/// 
		protected MinorTic( SerializationInfo info, StreamingContext context )
		{
			// The schema value is just a file version parameter.  You can use it to make future versions
			// backwards compatible as new member variables are added to classes
			int sch = info.GetInt32( "schema" );
			_color = (Color) info.GetValue( "color", typeof( Color ) );
			_size = info.GetSingle( "size" );
			_penWidth = info.GetSingle( "penWidth" );
			IsOutside = info.GetBoolean( "IsOutside" );
			IsInside = info.GetBoolean( "IsInside" );
			IsOpposite = info.GetBoolean( "IsOpposite" );
			_isCrossOutside = info.GetBoolean( "isCrossOutside" );
			_isCrossInside = info.GetBoolean( "isCrossInside" );
		}
		/// 
		/// Populates a  instance with the data needed to serialize the target object
		/// 
		/// A  instance that defines the serialized data
		/// A  instance that contains the serialized data
		[SecurityPermissionAttribute( SecurityAction.Demand, SerializationFormatter = true )]
		public virtual void GetObjectData( SerializationInfo info, StreamingContext context )
		{
			info.AddValue( "schema", schema );
			info.AddValue( "color", _color );
			info.AddValue( "size", _size );
			info.AddValue( "penWidth", _penWidth );
			info.AddValue( "IsOutside", IsOutside );
			info.AddValue( "IsInside", IsInside );
			info.AddValue( "IsOpposite", IsOpposite );
			info.AddValue( "isCrossOutside", _isCrossOutside );
			info.AddValue( "isCrossInside", _isCrossInside );
		}
	#endregion
	#region Defaults
		/// 
		/// A simple struct that defines the
		/// default property values for the  class.
		/// 
		public struct Default
		{
			/// 
			/// The default size for the  minor tic marks.
			/// ( property). Units are in points (1/72 inch).
			/// 
			public static float Size = 2.5F;
			/// 
			/// The default pen width for drawing the  tic marks.
			/// ( property). Units are in points (1/72 inch).
			/// 
			public static float PenWidth = 1.0F;
			/// 
			/// The display mode for the  minor outside tic marks
			/// ( property).
			/// The minor tic spacing is controlled by .
			/// 
			/// true to show the minor tic marks (outside the axis),
			/// false otherwise
			public static bool IsOutside = true;
			/// 
			/// The display mode for the  minor inside tic marks
			/// ( property).
			/// The minor tic spacing is controlled by .
			/// 
			/// true to show the minor tic marks (inside the axis),
			/// false otherwise
			public static bool IsInside = true;
			/// 
			/// The display mode for the  minor opposite tic marks
			/// ( property).
			/// The minor tic spacing is controlled by .
			/// 
			/// true to show the minor tic marks
			/// (inside the axis on the opposite side),
			/// false otherwise
			public static bool IsOpposite = true;
			/// 
			/// The default display mode for the  minor outside 
			/// "cross" tic marks ( property).
			/// 
			/// 
			/// The "cross" tics are a special, additional set of tic marks that
			/// always appear on the actual axis, even if it has been shifted due
			/// to the  setting.  The other tic marks are always
			/// fixed to the edges of the .  The cross tics
			/// are normally not displayed, since, if  is true,
			/// they will exactly overlay the "normal" and "inside" tics.  If
			///  is false, then you will most likely want to
			/// enable the cross tics.
			/// The minor tic spacing is controlled by .
			/// 
			/// true to show the major cross tic marks, false otherwise
			public static bool IsCrossOutside = false;
			/// 
			/// The default display mode for the  minor inside 
			/// "cross" tic marks ( property).
			/// 
			/// 
			/// The "cross" tics are a special, additional set of tic marks that
			/// always appear on the actual axis, even if it has been shifted due
			/// to the  setting.  The other tic marks are always
			/// fixed to the edges of the .  The cross tics
			/// are normally not displayed, since, if  is true,
			/// they will exactly overlay the "normal" and "inside" tics.  If
			///  is false, then you will most likely want to
			/// enable the cross tics.
			/// The major tic spacing is controlled by .
			/// 
			/// true to show the major cross tic marks, false otherwise
			public static bool IsCrossInside = false;
			/// 
			/// The default color for minor tics ( property).
			/// 
			public static Color Color = Color.Black;
		}
	#endregion
	#region Methods
		/// 
		/// Draw a tic mark at the specified single position.  This includes the inner, outer,
		/// cross and opposite tic marks as required.
		/// 
		/// 
		/// A graphic device object to be drawn into.  This is normally e.Graphics from the
		/// PaintEventArgs argument to the Paint() method.
		/// 
		/// 
		/// A reference to the  object that is the parent or
		/// owner of this object.
		/// 
		/// Graphic  with which to draw the tic mark.
		/// The pixel location of the tic mark on this
		/// 
		/// The pixel value of the top of the axis border
		/// The number of pixels to shift this axis, based on the
		/// value of .  A positive value is into the ChartRect relative to
		/// the default axis position.
		/// The scaled size of a minor tic, in pixel units
		internal void Draw( Graphics g, GraphPane pane, Pen pen, float pixVal, float topPix,
					float shift, float scaledTic )
		{
			// draw the outside tic
			if ( this.IsOutside )
				g.DrawLine( pen, pixVal, shift, pixVal, shift + scaledTic );
			// draw the cross tic
			if ( _isCrossOutside )
				g.DrawLine( pen, pixVal, 0.0f, pixVal, scaledTic );
			// draw the inside tic
			if ( this.IsInside )
				g.DrawLine( pen, pixVal, shift, pixVal, shift - scaledTic );
			// draw the inside cross tic
			if ( _isCrossInside )
				g.DrawLine( pen, pixVal, 0.0f, pixVal, -scaledTic );
			// draw the opposite tic
			if ( this.IsOpposite )
				g.DrawLine( pen, pixVal, topPix, pixVal, topPix + scaledTic );
		}
		internal Pen GetPen( GraphPane pane, float scaleFactor )
		{
			return new Pen( _color, pane.ScaledPenWidth( _penWidth, scaleFactor ) );
		}
	#endregion
	}
}