Beispiel #1
0
 protected override void OnPaint(PaintEventArgs e)
 {
     ColorRectangle.Draw(e.Graphics, base.ClientRectangle, this.rectangleColor, base.Enabled, true);
 }
        private void DrawGradient(Graphics g)
        {
            Rectangle rectangle;
            double    num;

            g.PixelOffsetMode = PixelOffsetMode.Half;
            System.Windows.Forms.Orientation orientation = this.orientation;
            if (orientation != System.Windows.Forms.Orientation.Horizontal)
            {
                if (orientation != System.Windows.Forms.Orientation.Vertical)
                {
                    throw ExceptionUtil.InvalidEnumArgumentException <System.Windows.Forms.Orientation>(this.orientation, "this.Orientation");
                }
            }
            else
            {
                num = 180.0;
                goto Label_0040;
            }
            num = 90.0;
Label_0040:
            rectangle   = base.ClientRectangle;
            orientation = this.orientation;
            if (orientation != System.Windows.Forms.Orientation.Horizontal)
            {
                if (orientation != System.Windows.Forms.Orientation.Vertical)
                {
                    throw ExceptionUtil.InvalidEnumArgumentException <System.Windows.Forms.Orientation>(this.orientation, "this.Orientation");
                }
            }
            else
            {
                rectangle.Inflate(-3, -4);
                goto Label_0082;
            }
            rectangle.Inflate(-4, -3);
Label_0082:
            if (((this.customGradient != null) && (rectangle.Width > 1)) && (rectangle.Height > 1))
            {
                Surface surface = new Surface(rectangle.Size.ToSizeInt32());
                using (RenderArgs args = new RenderArgs(surface))
                {
                    ColorRectangle.Draw(args.Graphics, args.Bounds, Color.Transparent, true, false);
                    if (this.Orientation == System.Windows.Forms.Orientation.Horizontal)
                    {
                        for (int j = 0; j < surface.Width; j++)
                        {
                            double num16;
                            double num17;
                            double num18;
                            double d             = ((double)(j * (this.customGradient.Length - 1))) / ((double)(surface.Width - 1));
                            int    index         = (int)Math.Floor(d);
                            double num5          = 1.0 - (d - index);
                            int    num6          = (int)Math.Min((double)(this.customGradient.Length - 1), Math.Ceiling(d));
                            Color  c             = this.customGradient[index];
                            Color  disabledColor = this.customGradient[num6];
                            if (!base.Enabled)
                            {
                                c             = DisabledRendering.GetDisabledColor(c);
                                disabledColor = DisabledRendering.GetDisabledColor(disabledColor);
                            }
                            double num7  = ((double)c.A) / 255.0;
                            double num8  = ((double)c.R) / 255.0;
                            double num9  = ((double)c.G) / 255.0;
                            double num10 = ((double)c.B) / 255.0;
                            double num11 = ((double)disabledColor.A) / 255.0;
                            double num12 = ((double)disabledColor.R) / 255.0;
                            double num13 = ((double)disabledColor.G) / 255.0;
                            double num14 = ((double)disabledColor.B) / 255.0;
                            double num15 = (num5 * num7) + ((1.0 - num5) * num11);
                            if (num15 == 0.0)
                            {
                                num16 = 0.0;
                                num17 = 0.0;
                                num18 = 0.0;
                            }
                            else
                            {
                                num16 = (((num5 * num7) * num8) + (((1.0 - num5) * num11) * num12)) / num15;
                                num17 = (((num5 * num7) * num9) + (((1.0 - num5) * num11) * num13)) / num15;
                                num18 = (((num5 * num7) * num10) + (((1.0 - num5) * num11) * num14)) / num15;
                            }
                            int num19 = ((int)Math.Round((double)(num15 * 255.0), MidpointRounding.AwayFromZero)).Clamp(0, 0xff);
                            int num20 = ((int)Math.Round((double)(num16 * 255.0), MidpointRounding.AwayFromZero)).Clamp(0, 0xff);
                            int num21 = ((int)Math.Round((double)(num17 * 255.0), MidpointRounding.AwayFromZero)).Clamp(0, 0xff);
                            int num22 = ((int)Math.Round((double)(num18 * 255.0), MidpointRounding.AwayFromZero)).Clamp(0, 0xff);
                            for (int k = 0; k < surface.Height; k++)
                            {
                                ColorBgra bgra  = surface[j, k];
                                int       num24 = ((num20 * num19) + (bgra.R * (0xff - num19))) / 0xff;
                                int       num25 = ((num21 * num19) + (bgra.G * (0xff - num19))) / 0xff;
                                int       num26 = ((num22 * num19) + (bgra.B * (0xff - num19))) / 0xff;
                                surface[j, k] = ColorBgra.FromBgra((byte)num26, (byte)num25, (byte)num24, 0xff);
                            }
                        }
                        g.DrawImage(args.Bitmap, rectangle, args.Bounds, GraphicsUnit.Pixel);
                    }
                    else if (this.Orientation != System.Windows.Forms.Orientation.Vertical)
                    {
                        throw ExceptionUtil.InvalidEnumArgumentException <System.Windows.Forms.Orientation>(this.orientation, "this.Orientation");
                    }
                }
                surface.Dispose();
            }
            else
            {
                Color color3 = base.Enabled ? this.maxColor : DisabledRendering.GetDisabledColor(this.maxColor);
                Color color4 = base.Enabled ? this.minColor : DisabledRendering.GetDisabledColor(this.minColor);
                using (LinearGradientBrush brush = new LinearGradientBrush(base.ClientRectangle, color3, color4, (float)num, false))
                {
                    g.FillRectangle(brush, rectangle);
                }
            }
            using (PdnRegion region = new PdnRegion())
            {
                region.MakeInfinite();
                region.Exclude(rectangle);
                using (SolidBrush brush2 = new SolidBrush(this.BackColor))
                {
                    g.FillRegion(brush2, region.GetRegionReadOnly());
                }
            }
            for (int i = 0; i < this.vals.Length; i++)
            {
                Brush blue;
                Pen   pen;
                Point point;
                Point point2;
                Point point3;
                Point point4;
                Point point5;
                Point point6;
                int   x = this.ValueToPosition(this.vals[i]);
                if (i == this.highlight)
                {
                    blue = Brushes.Blue;
                    pen  = (Pen)Pens.White.Clone();
                }
                else
                {
                    blue = base.Enabled ? Brushes.Black : Brushes.Gray;
                    pen  = (Pen)Pens.Gray.Clone();
                }
                g.SmoothingMode = SmoothingMode.AntiAlias;
                orientation     = this.orientation;
                if (orientation != System.Windows.Forms.Orientation.Horizontal)
                {
                    if (orientation != System.Windows.Forms.Orientation.Vertical)
                    {
                        throw ExceptionUtil.InvalidEnumArgumentException <System.Windows.Forms.Orientation>(this.orientation, "this.Orientation");
                    }
                }
                else
                {
                    point  = new Point(x - 3, 0);
                    point2 = new Point(x, 6);
                    point3 = new Point(x + 3, 0);
                    point4 = new Point(point.X, (base.Height - 1) - point.Y);
                    point5 = new Point(point2.X, (base.Height - 1) - point2.Y);
                    point6 = new Point(point3.X, (base.Height - 1) - point3.Y);
                    goto Label_0678;
                }
                point  = new Point(0, x - 3);
                point2 = new Point(6, x);
                point3 = new Point(0, x + 3);
                point4 = new Point((base.Width - 1) - point.X, point.Y);
                point5 = new Point((base.Width - 1) - point2.X, point2.Y);
                point6 = new Point((base.Width - 1) - point3.X, point3.Y);
Label_0678:
                if (this.drawNearNub)
                {
                    Point[] points = new Point[] { point, point2, point3, point };
                    g.FillPolygon(blue, points);
                }
                if (this.drawFarNub)
                {
                    Point[] pointArray2 = new Point[] { point4, point5, point6, point4 };
                    g.FillPolygon(blue, pointArray2);
                }
                if (pen != null)
                {
                    if (this.drawNearNub)
                    {
                        Point[] pointArray3 = new Point[] { point, point2, point3, point };
                        g.DrawPolygon(pen, pointArray3);
                    }
                    if (this.drawFarNub)
                    {
                        Point[] pointArray4 = new Point[] { point4, point5, point6, point4 };
                        g.DrawPolygon(pen, pointArray4);
                    }
                    pen.Dispose();
                }
            }
        }
Beispiel #3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.CompositingMode = CompositingMode.SourceOver;
            int   width         = UIUtil.ScaleWidth(this.unscaledSwatchSize);
            int   num2          = base.ClientSize.Width / width;
            Point mousePosition = Control.MousePosition;

            mousePosition = base.PointToClient(mousePosition);
            int num3 = this.MouseXYToColorIndex(mousePosition.X, mousePosition.Y);

            for (int i = 0; i < this.colors.Count; i++)
            {
                PushButtonState pressed;
                bool            flag;
                ColorBgra       bgra = this.colors[i];
                int             num5 = i % num2;
                int             num6 = i / num2;
                Rectangle       rect = new Rectangle(num5 * width, num6 * width, width, width);
                if (this.mouseDown)
                {
                    if (i == this.mouseDownIndex)
                    {
                        pressed = PushButtonState.Pressed;
                    }
                    else
                    {
                        pressed = PushButtonState.Normal;
                    }
                }
                else if (i == num3)
                {
                    pressed = PushButtonState.Hot;
                }
                else
                {
                    pressed = PushButtonState.Normal;
                }
                switch (pressed)
                {
                case PushButtonState.Normal:
                case PushButtonState.Disabled:
                case PushButtonState.Default:
                    flag = false;
                    break;

                case PushButtonState.Hot:
                    flag = true;
                    break;

                case PushButtonState.Pressed:
                    flag = false;
                    break;

                default:
                    throw ExceptionUtil.InvalidEnumArgumentException <PushButtonState>(pressed, "state");
                }
                ColorRectangle.Draw(e.Graphics, rect, bgra.ToColor(), base.Enabled, flag);
            }
            if (this.blinkHighlight)
            {
                Color window;
                switch (((Math.Abs(Environment.TickCount) / 500) % 2))
                {
                case 0:
                    window = SystemColors.Window;
                    break;

                case 1:
                    window = SystemColors.Highlight;
                    break;

                default:
                    throw new InvalidOperationException();
                }
                using (Pen pen = new Pen(window))
                {
                    e.Graphics.DrawRectangle(pen, new Rectangle(0, 0, base.Width - 1, base.Height - 1));
                }
            }
            base.OnPaint(e);
        }