/*=============================================================================
Project: SharpImage
Module: siSamplingRate.cs
Language: C#
Author: Dan Mueller
Date: $Date: 2007-07-06 10:57:00 +1000 (Fri, 06 Jul 2007) $
Revision: $Revision: 2 $
Copyright (c) Queensland University of Technology (QUT) 2007.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=============================================================================*/
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Xml.Serialization;
namespace SharpImage.Rendering
{
///
/// A class which encapsulates two sampling rates: a low-quality (high-speed)
/// value and a high-quality (low-speed) value. The current rate can be
/// set by calling the MakeCurrentLowQuality() and/or MakeCurrentHighQuality()
/// methods.
///
[Serializable()]
public class siSamplingRate
{
public delegate void siSamplingRateHandler(siSamplingRate sender);
private float m_Current = 0.0F;
private float m_Low = 0.0F;
private float m_High = 0.0F;
private siSamplingRateHandler m_EventStorage_Changed;
///
/// Serializable constructor.
///
protected siSamplingRate()
{
}
///
/// Default constructor.
/// The current sampling rate is set to the high-quality value.
///
/// The value of the low-quality (high-speed) sampling rate. Eg. 0.1.
/// The value of the high-quality (low-speed) sampling rate. Eg. 1.5.
public siSamplingRate(float low, float high)
{
this.m_Low = low;
this.m_High = high;
this.m_Current = high;
}
///
/// Get the current sampling rate (either the low-quality or high-quality
/// value depending on the current mode).
///
[RefreshProperties(RefreshProperties.All)]
[System.Xml.Serialization.XmlIgnore]
public float Current
{
get { return this.m_Current; }
}
///
/// Get/set the high-quality (low-speed) sampling rate. Eg. 1.5;
///
[RefreshProperties(RefreshProperties.All)]
public float HighQuality
{
get { return this.m_High; }
set
{
if (this.m_Current == this.m_High)
this.m_Current = value;
this.m_High = value;
this.RaiseChangedEvent();
}
}
///
/// Get/set the low-quality (high-speed) sampling rate. Eg. 0.1;
///
[RefreshProperties(RefreshProperties.All)]
public float LowQuality
{
get { return this.m_Low; }
set
{
if (this.m_Current == this.m_Low)
this.m_Current = value;
this.m_Low = value;
this.RaiseChangedEvent();
}
}
///
/// An event raised when the sampling rate is changed.
///
public event siSamplingRateHandler Changed
{
add { this.m_EventStorage_Changed += value; }
remove { this.m_EventStorage_Changed -= value; }
}
///
/// Make the current sampling rate the high-quality (low-speed) value.
///
public void MakeCurrentHighQuality()
{
this.m_Current = this.m_High;
this.RaiseChangedEvent();
}
///
/// Make the current sampling rate the low-quality (high-speed) value.
///
public void MakeCurrentLowQuality()
{
this.m_Current = this.m_Low;
this.RaiseChangedEvent();
}
///
/// Return a string representation of the sampling rate.
///
///
public override string ToString()
{
return "Low: " + this.m_Low.ToString() + " High: " + this.m_High.ToString();
}
///
/// Raises the Changed event.
///
private void RaiseChangedEvent()
{
if (this.m_EventStorage_Changed != null)
this.m_EventStorage_Changed(this);
}
}
}