Exemple #1
0
        public override bool Equals(object obj)
        {
            if (!(obj is LinearGradientColor))
            {
                return(false);
            }

            LinearGradientColor lgc = (LinearGradientColor)obj;

            // always return false when compare to an invalid gradient color
            if (lgc.colors.Length != lgc.positions.Length)
            {
                return(false);
            }

            if (colors.Length != lgc.colors.Length ||
                positions.Length != lgc.positions.Length)
            {
                return(false);
            }

            for (int i = 0; i < colors.Length; i++)
            {
                if (colors[i] != lgc.colors[i])
                {
                    return(false);
                }
                if (positions[i] != lgc.positions[i])
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = e.Graphics;

            Rectangle rect = new Rectangle(0, 0, Size.Width - 1, Size.Height - 1);

            // background
            Rectangle bgRect = rect;

            bgRect.Offset(1, 1);
            //g.FillRectangle(isPressed ? Brushes.Black : Brushes.White, bgRect);

            // outter frame
            g.DrawLine(SystemPens.ButtonShadow, rect.X + 1, rect.Y, rect.Right - 1, rect.Y);
            g.DrawLine(SystemPens.ButtonShadow, rect.X + 1, rect.Bottom, rect.Right - 1, rect.Bottom);
            g.DrawLine(SystemPens.ButtonShadow, rect.X, rect.Y + 1, rect.X, rect.Bottom - 1);
            g.DrawLine(SystemPens.ButtonShadow, rect.Right, rect.Y + 1, rect.Right, rect.Bottom - 1);

            // content
            Rectangle bodyRect = rect;

            bodyRect.Inflate(-1, -1);
            bodyRect.Offset(1, 1);
            //g.FillRectangle(Brushes.Gainsboro, bodyRect);

            // shadow
            if (showShadow)
            {
                g.DrawLines(isPressed ? SystemPens.ControlLightLight
                                        : SystemPens.ControlDarkDark, new Point[] {
                    new Point(rect.Left + 1, rect.Bottom - 1),
                    new Point(rect.Right - 1, rect.Bottom - 1),
                    new Point(rect.Right - 1, rect.Top + 1),
                });
            }

            // draw allow
            if (isPressed)
            {
                rect.Offset(1, 1);
            }

            try
            {
                g.FillPolygon(Brushes.Black, new Point[] {
                    new Point(rect.Right - 13, rect.Top + 8),
                    new Point(rect.Right - 4, rect.Top + 8),
                    new Point(rect.Right - 9, rect.Top + 17),
                });
            }
            catch { }

            g.DrawLine(SystemPens.ControlDarkDark, rect.Right - 16, rect.Top + 3,
                       rect.Right - 16, rect.Bottom - 4);
            g.DrawLine(SystemPens.ControlLightLight, rect.Right - 15, rect.Top + 4,
                       rect.Right - 15, rect.Bottom - 4);


            // draw color
            Rectangle colorRect = new Rectangle(4, 4, 14, 14);

            if (isPressed)
            {
                colorRect.Offset(1, 1);
            }

            if (currentColor == null || currentColor.IsEmpty)
            {
                g.DrawRectangle(Pens.Black, colorRect);
                g.DrawLine(Pens.Black, colorRect.Left,
                           colorRect.Bottom, colorRect.Right, colorRect.Top);
            }
            else if (currentColor is SolidColor)
            {
                //g.FillRectangle(ResourcePoolManager.Instance.GetBrush(((SolidColor)currentColor).Color), colorRect);
                Color c = currentColor.CompliantSolidColor;
                if (c.A < 255)
                {
                    GraphicsToolkit.DrawTransparentBlock(g, colorRect);
                }

                using (SolidBrush b = new SolidBrush(currentColor.CompliantSolidColor))
                {
                    g.FillRectangle(b, colorRect);
                }
            }
            else if (currentColor is LinearGradientColor)
            {
                LinearGradientColor lgc = (LinearGradientColor)currentColor;
                using (LinearGradientBrush b = lgc.CreateGradientBrush(colorRect))
                {
                    g.PixelOffsetMode = PixelOffsetMode.Half;
                    g.FillRectangle(b, colorRect);
                    g.PixelOffsetMode = PixelOffsetMode.Default;
                }
            }
            else if (currentColor is HatchPatternColor)
            {
                using (HatchBrush b = ((HatchPatternColor)currentColor).CreateHatchBrush())
                {
                    g.FillRectangle(b, colorRect);
                }
            }
        }