private void DrawColorSlider(PaintEventArgs e, Color thumbFirstColorPaint, Color thumbSecondColorPaint,
Color thumbBorderColorPaint, Color barColorPaint, Color elapsedBarColorPaint)
{
try
{
// set up thumbRect aproprietly
int trackX = (((trackerValue - barMinimum) * (ClientRectangle.Width - thumbSize.Width)) / (barMaximum - barMinimum));
thumbRect = new Rectangle(trackX, (ClientRectangle.Height - thumbSize.Height) / 2, thumbSize.Width - 1, thumbSize.Height);
// get thumb shape path
GraphicsPath thumbPath;
if (thumbCustomShape == null)
{
thumbPath = CreateRoundRectPath(thumbRect, thumbRoundRectSize);
}
else
{
thumbPath = thumbCustomShape;
var m = new Matrix();
m.Translate(thumbRect.Left - thumbPath.GetBounds().Left, thumbRect.Top - thumbPath.GetBounds().Top);
thumbPath.Transform(m);
}
thumbHalfRect = thumbRect;
thumbHalfRect.Height /= 2;
// draw bar
// adjust drawing rects
barRect = ClientRectangle;
barRect.Inflate(0, (barHeight - barRect.Height) / 2);
elapsedRect = barRect;
elapsedRect.Width = thumbRect.Left + thumbSize.Width / 2;
using (var barBrush = new SolidBrush(barColorPaint))
{
e.Graphics.FillRectangle(barBrush, barRect);
// draw elapsed bar
using (var elapsedBrush = new SolidBrush(elapsedBarColorPaint))
{
if (Capture && drawSemitransparentThumb)
{
var elapsedReg = new Region(elapsedRect);
elapsedReg.Exclude(thumbPath);
e.Graphics.FillRegion(elapsedBrush, elapsedReg);
}
else
{
e.Graphics.FillRectangle(elapsedBrush, elapsedRect);
}
}
// create tick marks (chapter marks)
foreach (var m in marks)
{
if (m > maxMarkValue)
continue;
var x = (m * this.ClientRectangle.Width) / maxMarkValue;
var r = new Rectangle((int)x, barRect.Y, barRect.Height, barRect.Height);
r.Inflate(0, 2);
e.Graphics.FillRectangle(barBrush, r);
}
}
// draw thumb
Color newthumbFirstColorPaint = thumbFirstColorPaint, newthumbSecondColorPaint = thumbSecondColorPaint;
if (Capture && drawSemitransparentThumb)
{
newthumbFirstColorPaint = Color.FromArgb(175, thumbFirstColorPaint);
newthumbSecondColorPaint = Color.FromArgb(175, thumbSecondColorPaint);
}
using (var lgbThumb = new LinearGradientBrush(thumbRect,
newthumbFirstColorPaint, newthumbSecondColorPaint, LinearGradientMode.Vertical))
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.FillPath(lgbThumb, thumbPath);
// draw thumb border
Color newThumbBorderColor = thumbBorderColorPaint;
using (var thumbPen = new Pen(newThumbBorderColor))
{
e.Graphics.DrawPath(thumbPen, thumbPath);
}
}
}
catch (Exception err)
{
Console.WriteLine("ColorSlider.cs: DrawBackground Error in {0}: {1}", Name, err.Message);
}
}