Baka_MPlayer.Controls.ColorSlider.DrawColorSlider C# (CSharp) Method

DrawColorSlider() private method

Draws the colorslider control using passed colors.
private DrawColorSlider ( PaintEventArgs e, Color thumbFirstColorPaint, Color thumbSecondColorPaint, Color thumbBorderColorPaint, Color barColorPaint, Color elapsedBarColorPaint ) : void
e PaintEventArgs The instance containing the event data.
thumbFirstColorPaint Color The first color of the thumb.
thumbSecondColorPaint Color The second color of the thumb.
thumbBorderColorPaint Color The thumb border color.
barColorPaint Color The bar color paint.
elapsedBarColorPaint Color The elapsed color paint.
return void
        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);
            }
        }