protected override void OnPaint( PaintEventArgs pe )
{
Graphics g = pe.Graphics;
Rectangle rc = this.ClientRectangle;
Rectangle rcPie;
Brush brush;
RGB rgb = new RGB( );
HSL hsl = new HSL( );
// get pie rectangle
rcPie = new Rectangle( 4, 4, Math.Min( rc.Right, rc.Bottom ) - 8, Math.Min( rc.Right, rc.Bottom ) - 8 );
// init HSL value
hsl.Luminance = 0.5f;
hsl.Saturation = 1.0f;
if ( type == HuePickerType.Value )
{
// draw HSL pie
for ( int i = 0; i < 360; i++ )
{
hsl.Hue = i;
// convert from HSL to RGB
AForge.Imaging.HSL.ToRGB( hsl, rgb );
// create brush
brush = new SolidBrush( rgb.Color );
// draw one hue value
g.FillPie( brush, rcPie, -i, -1 );
brush.Dispose( );
}
}
else
{
// draw HSL pie
for ( int i = 0; i < 360; i++ )
{
if (
( ( min < max ) && ( i >= min ) && ( i <= max ) ) ||
( ( min > max ) && ( ( i >= min ) || ( i <= max ) ) ) )
{
hsl.Hue = i;
// convert from HSL to RGB
AForge.Imaging.HSL.ToRGB( hsl, rgb );
// create brush
brush = new SolidBrush( rgb.Color );
}
else
{
brush = new SolidBrush( Color.FromArgb( 128, 128, 128 ) );
}
// draw one hue value
g.FillPie( brush, rcPie, -i, -1 );
brush.Dispose( );
}
}
//
double halfWidth = (double) rcPie.Width / 2;
double angleRad = -min * Math.PI / 180;
double angleCos = Math.Cos( angleRad );
double angleSin = Math.Sin( angleRad );
double x = halfWidth * angleCos;
double y = halfWidth * angleSin;
ptCenter.X = rcPie.Left + (int) ( halfWidth );
ptCenter.Y = rcPie.Top + (int) ( halfWidth );
ptMin.X = rcPie.Left + (int) ( halfWidth + x );
ptMin.Y = rcPie.Top + (int) ( halfWidth + y );
// draw MIN pointer
g.FillEllipse( blackBrush,
rcPie.Left + (int) ( halfWidth + x ) - 4,
rcPie.Top + (int) ( halfWidth + y ) - 4,
8, 8 );
g.DrawLine( blackPen, ptCenter, ptMin );
// check picker type
if ( type == HuePickerType.Range )
{
angleRad = -max * Math.PI / 180;
angleCos = Math.Cos( angleRad );
angleSin = Math.Sin( angleRad );
x = halfWidth * angleCos;
y = halfWidth * angleSin;
ptMax.X = rcPie.Left + (int) ( halfWidth + x );
ptMax.Y = rcPie.Top + (int) ( halfWidth + y );
// draw MAX pointer
g.FillEllipse( whiteBrush,
rcPie.Left + (int) ( halfWidth + x ) - 4,
rcPie.Top + (int) ( halfWidth + y ) - 4,
8, 8 );
g.DrawLine( whitePen, ptCenter, ptMax );
}
base.OnPaint( pe );
}