Animatroller.Simulator.Control.Bulb.SuperSimpleBulb.drawControl C# (CSharp) Метод

drawControl() приватный Метод

Renders the control to an image
private drawControl ( Graphics g ) : void
g System.Drawing.Graphics
Результат void
        private void drawControl(Graphics g)
        {
            const int intensityColumnWidth = 3;

            var drawColor = this.On ? this.Color : Color.Black;

            var paddedRectangle = new Rectangle(
                this.Padding.Left,
                this.Padding.Top,
                this.Width - (this.Padding.Left + this.Padding.Right) - 1,
                this.Height - (this.Padding.Top + this.Padding.Bottom) - 1);
            int width = (paddedRectangle.Width < paddedRectangle.Height) ? paddedRectangle.Width : paddedRectangle.Height;
            int offsetX = (paddedRectangle.Width - width) / 2;
            int offsetY = (paddedRectangle.Height - width) / 2;
            var drawRectangle = new Rectangle(
                paddedRectangle.X + offsetX + intensityColumnWidth,
                paddedRectangle.Y + offsetY,
                width - intensityColumnWidth,
                width);

            using (var drawColorBrush = new SolidBrush(drawColor))
                g.FillRectangle(drawColorBrush, drawRectangle);

            Color invertedColor;
            double brightness = Math.Max(Math.Max(drawColor.R, drawColor.G), drawColor.B) / 255.0;
            if (brightness < 0.8)
                invertedColor = Color.White;
            else
                invertedColor = Color.Black;

            using (var invertedBrush = new SolidBrush(invertedColor))
            {
                if (!string.IsNullOrEmpty(Text))
                {
                    var textSize = g.MeasureString(Text, Font);
                    var pos = new PointF((Width - textSize.Width) / 2, (Height - textSize.Height) / 2);

                    g.DrawString(Text, Font, invertedBrush, pos);
                }

                if (_pan.HasValue)
                {
                    string text = string.Format("P: {0:F0}", _pan.Value);

                    var textSize = g.MeasureString(text, _tinyFont);
                    var pos = new PointF(drawRectangle.Right - textSize.Width, 2);

                    g.DrawString(text, _tinyFont, invertedBrush, pos);
                }

                if (_tilt.HasValue)
                {
                    string text = string.Format("T: {0:F0}", _tilt.Value);

                    var textSize = g.MeasureString(text, _tinyFont);
                    var pos = new PointF(drawRectangle.Right - textSize.Width, 10);

                    g.DrawString(text, _tinyFont, invertedBrush, pos);
                }
            }

            // Draw Color Gel
            Rectangle gelRectangle = new Rectangle(drawRectangle.Right - 16, drawRectangle.Bottom - 16, 16, 16);
            using (var gelBrush = new SolidBrush(ColorGel))
                g.FillRectangle(gelBrush, gelRectangle);

            // Draw intensity
            Rectangle intensityRectangle1 = new Rectangle(paddedRectangle.X + offsetX, drawRectangle.Top, intensityColumnWidth, (int)(drawRectangle.Height * (1.0 - Intensity)));
            g.FillRectangle(blackSolidBrush, intensityRectangle1);

            Rectangle intensityRectangle2 = new Rectangle(intensityRectangle1.Left, intensityRectangle1.Bottom, intensityColumnWidth, drawRectangle.Height - intensityRectangle1.Height);
            g.FillRectangle(whiteSolidBrush, intensityRectangle2);
        }