Esempio n. 1
0
        public static void FillRectangle(Rectangle rectangle, GlassGradient gradient, bool isSunk, bool isGlass,
                                         Graphics graphics)
        {
            if (rectangle.Width == 0 || rectangle.Height == 0)
            {
                return;
            }

            var activeGradient = isSunk
                                     ? new GlassGradient(gradient.Bottom, gradient.Top)
                                     : new GlassGradient(gradient.Top, gradient.Bottom);
            var brush = activeGradient.GetBrush(rectangle);

            graphics.FillRectangle(brush, rectangle);
            brush.Dispose();

            if (isGlass)
            {
                graphics.SetClip(rectangle);

                var glassRectangle = isSunk
                                         ? new Rectangle(new Point(rectangle.Left, rectangle.Height / 2),
                                                         new Size(rectangle.Width, rectangle.Height / 2))
                                         : new Rectangle(rectangle.Location,
                                                         new Size(rectangle.Width, rectangle.Height / 2));
                Brush glassBrush = new LinearGradientBrush(glassRectangle, Color.Transparent,
                                                           Color.FromArgb(32, 255, 255, 255), 90.0f);

                graphics.FillRectangle(glassBrush, glassRectangle);

                glassBrush.Dispose();
            }
        }
Esempio n. 2
0
        public static void FillRoundedRectangle(Rectangle rectangle, GlassGradient gradient, bool isSunk, bool isGlass,
                                                Graphics graphics)
        {
            if (rectangle.Width == 0 || rectangle.Height == 0)
                return;

            var path = GetRoundedRectanglePath(rectangle);

            var activeGradient = isSunk
                                     ? new GlassGradient(gradient.Bottom, gradient.Top)
                                     : new GlassGradient(gradient.Top, gradient.Bottom);

            var brush = activeGradient.GetBrush(rectangle);
            graphics.FillPath(brush, path);
            brush.Dispose();

            if (isGlass)
            {
                graphics.SetClip(path);

                var glassRectangle = isSunk
                                         ? new Rectangle(new Point(rectangle.Left, rectangle.Height/2),
                                                         new Size(rectangle.Width, rectangle.Height/2))
                                         : new Rectangle(rectangle.Location,
                                                         new Size(rectangle.Width, rectangle.Height/2));
                var glassPath = GetRoundedRectanglePath(glassRectangle);
                Brush glassBrush = new LinearGradientBrush(glassRectangle, Color.Transparent,
                                                           Color.FromArgb(32, 255, 255, 255), 90.0f);

                graphics.FillPath(glassBrush, glassPath);

                glassBrush.Dispose();
                glassPath.Dispose();
            }
        }
Esempio n. 3
0
        public GlassPanel()
        {
            this.SetStyle ( ControlStyles.OptimizedDoubleBuffer |
                ControlStyles.AllPaintingInWmPaint |
                ControlStyles.UserPaint |
                ControlStyles.Opaque , true);

            this.gradient = new GlassGradient( Color.FromArgb( 96,96,96 ), Color.FromArgb( 0,0,0 ) );
            this.borders = GlassBorders.All;
        }
Esempio n. 4
0
        public GlassPanel()
        {
            SetStyle(ControlStyles.OptimizedDoubleBuffer |
                     ControlStyles.AllPaintingInWmPaint |
                     ControlStyles.UserPaint |
                     ControlStyles.Opaque, true);

            gradient = new GlassGradient(Color.FromArgb(96, 96, 96), Color.FromArgb(0, 0, 0));
            borders  = GlassBorders.All;
        }
Esempio n. 5
0
        public static void DrawRoundedGradient(Rectangle rectangle, GlassGradient gradient, Graphics graphics)
        {
            if (rectangle.Width == 0 || rectangle.Height == 0)
                return;

            var brush = gradient.GetBrush(rectangle);
            var path = GetRoundedRectanglePath(rectangle);

            graphics.FillPath(brush, path);

            path.Dispose();
            brush.Dispose();
        }
Esempio n. 6
0
        public static void DrawRoundedGradient(Rectangle rectangle, GlassGradient gradient, Graphics graphics)
        {
            if (rectangle.Width == 0 || rectangle.Height == 0)
            {
                return;
            }

            var brush = gradient.GetBrush(rectangle);
            var path  = GetRoundedRectanglePath(rectangle);

            graphics.FillPath(brush, path);

            path.Dispose();
            brush.Dispose();
        }
Esempio n. 7
0
        public GlassButton()
        {
            this.normalGradient = new GlassGradient( Color.FromArgb( 96,96,96 ), Color.FromArgb( 0,0,0 ) );
            this.hoverGradient = new GlassGradient( Color.FromArgb( 0,216,0 ), Color.FromArgb( 0,64,0 ) );
            this.pressedGradient = new GlassGradient( Color.FromArgb( 0,64,0 ), Color.FromArgb( 0,216,0 ) );
            this.disabledGradient = new GlassGradient( Color.FromArgb( 64, 64, 64 ), Color.FromArgb( 64, 64, 64 ) );
            this.highlightGradient = new GlassGradient( Color.FromArgb( 192, 192, 192 ), Color.FromArgb( 96, 96, 96 ) );

            this.TabStop = false;
            this.SetStyle( ControlStyles.Selectable, false );
            this.SetStyle(ControlStyles.Opaque, false);

            this.borderColor = Color.Black;
            this.depth = 3;

            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.BackColor = Color.Transparent;
        }
Esempio n. 8
0
        public GlassButton()
        {
            normalGradient    = new GlassGradient(Color.FromArgb(96, 96, 96), Color.FromArgb(0, 0, 0));
            hoverGradient     = new GlassGradient(Color.FromArgb(0, 216, 0), Color.FromArgb(0, 64, 0));
            pressedGradient   = new GlassGradient(Color.FromArgb(0, 64, 0), Color.FromArgb(0, 216, 0));
            disabledGradient  = new GlassGradient(Color.FromArgb(64, 64, 64), Color.FromArgb(64, 64, 64));
            highlightGradient = new GlassGradient(Color.FromArgb(192, 192, 192), Color.FromArgb(96, 96, 96));

            TabStop = false;
            SetStyle(ControlStyles.Selectable, false);
            SetStyle(ControlStyles.Opaque, false);

            borderColor = Color.Black;
            depth       = 3;

            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            BackColor = Color.Transparent;
        }
Esempio n. 9
0
        private static void readGradient(XmlReader reader, string gradientName, GlassGradient gradient)
        {
            try
            {
                reader.ReadStartElement(gradientName);

                reader.ReadStartElement("Top");
                gradient.Top = parseColor(reader.ReadString());
                reader.ReadEndElement();

                reader.ReadStartElement("Bottom");
                gradient.Bottom = parseColor(reader.ReadString());
                reader.ReadEndElement();

                reader.ReadEndElement();
            }
            catch
            {
            }
        }
Esempio n. 10
0
        private static void writeGradient(XmlWriter writer, string gradientName, GlassGradient gradient)
        {
            writer.WriteStartElement(gradientName);

            writer.WriteStartElement("Top");

            writer.WriteString(String.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", gradient.Top.A, gradient.Top.R, gradient.Top.G,
                                             gradient.Top.B));

            writer.WriteEndElement();

            writer.WriteStartElement("Bottom");

            writer.WriteString(String.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", gradient.Bottom.A, gradient.Bottom.R,
                                             gradient.Bottom.G, gradient.Bottom.B));

            writer.WriteEndElement();

            writer.WriteEndElement();
        }
Esempio n. 11
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle rect = new Rectangle(0, 0, Width, Height);

            if (BackgroundImage != null)
            {
                GlassHelper.FillTexturedRectangle(rect, BackgroundImage, true, e.Graphics);
            }
            else
            {
                GlassGradient activeGradient = Gradient;

                if (UseStyles)
                {
                    activeGradient = GlassStyleManager.Active.Panel;
                }

                GlassHelper.FillRectangle(rect, activeGradient, IsSunk,
                                          UseStyles ? GlassStyleManager.Active.PanelIsGlass : IsGlass, e.Graphics);
            }

            GlassHelper.DrawBorder(rect, Borders, e.Graphics);
        }
Esempio n. 12
0
        private void WriteGradient(XmlWriter writer, string gradientName, GlassGradient gradient)
        {
            writer.WriteStartElement(gradientName);

            writer.WriteStartElement("Top");

            writer.WriteString(String.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", gradient.Top.A, gradient.Top.R, gradient.Top.G, gradient.Top.B));

            writer.WriteEndElement();

            writer.WriteStartElement("Bottom");

            writer.WriteString(String.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", gradient.Bottom.A, gradient.Bottom.R, gradient.Bottom.G, gradient.Bottom.B));

            writer.WriteEndElement();

            writer.WriteEndElement();
        }
Esempio n. 13
0
        private void ReadGradient(XmlReader reader, string gradientName, GlassGradient gradient)
        {
            try
            {
                reader.ReadStartElement(gradientName);

                reader.ReadStartElement("Top");
                gradient.Top = this.ParseColor(reader.ReadString());
                reader.ReadEndElement();

                reader.ReadStartElement("Bottom");
                gradient.Bottom = this.ParseColor(reader.ReadString());
                reader.ReadEndElement();

                reader.ReadEndElement();
            }
            catch { }
        }
Esempio n. 14
0
        protected override void OnPaint(PaintEventArgs e)
        {
            GlassGradient activeGradient = normalGradient;

            if (this.UseStyles == true)
            {
                if (this.Enabled == false)
                    activeGradient = GlassStyleManager.Active.ButtonDisabled;
                else if (this.mouseDown == true)
                    activeGradient = GlassStyleManager.Active.ButtonPressed;
                else if (this.mouseOver == true)
                    activeGradient = GlassStyleManager.Active.ButtonHover;
                else if (this.highlight == true)
                    activeGradient = GlassStyleManager.Active.ButtonHighlight;
                else
                    activeGradient = GlassStyleManager.Active.ButtonNormal;
            }
            else
            {
                if (this.Enabled == false)
                    activeGradient = disabledGradient;
                else if (this.mouseDown == true)
                    activeGradient = pressedGradient;
                else if (this.mouseOver == true)
                    activeGradient = hoverGradient;
                else if (this.highlight == true)
                    activeGradient = highlightGradient;
                else
                    activeGradient = normalGradient;
            }

            e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

            Rectangle clientRectangle = this.ClientRectangle;
            clientRectangle.Inflate(-1, -1);

            GlassGradient sunk = null;
            bool activeIsGlass = true;

            sunk = new GlassGradient(Color.FromArgb(48, Color.White), Color.FromArgb(160, Color.Black));
            if (this.Parent is GlassPanel)
            {
                GlassPanel parent = (GlassPanel)this.Parent;
                if (parent.UseStyles == true)
                {
                    activeIsGlass = GlassStyleManager.Active.PanelIsGlass;
                }
                else
                {
                    activeIsGlass = parent.IsGlass;
                }
            }
            else
            {
                activeIsGlass = false;
            }

            GlassHelper.FillRoundedRectangle(clientRectangle, sunk, true, activeIsGlass, e.Graphics);

            Rectangle rectangle = clientRectangle;
            rectangle.Inflate(-this.depth, -this.depth);

            if (this.UseStyles == true)
                activeIsGlass = GlassStyleManager.Active.ButtonIsGlass;
            else
                activeIsGlass = this.IsGlass;

            GlassHelper.FillRoundedRectangle(rectangle, activeGradient, false, activeIsGlass, e.Graphics);

            e.Graphics.SetClip(this.ClientRectangle);

            GlassHelper.DrawRoundedBorder(rectangle, this.BorderColor, this.Depth / 4.0f, e.Graphics);

            StringAlignment vertical = StringAlignment.Center;
            StringAlignment horizontal = StringAlignment.Center;

            if (this.Image != null)
            {
                switch (this.ImageAlign)
                {
                    case ContentAlignment.BottomCenter:
                        {
                            horizontal = StringAlignment.Center;
                            vertical = StringAlignment.Far;
                            break;
                        }
                    case ContentAlignment.BottomLeft:
                        {
                            horizontal = StringAlignment.Near;
                            vertical = StringAlignment.Far;
                            break;
                        }
                    case ContentAlignment.BottomRight:
                        {
                            horizontal = StringAlignment.Far;
                            vertical = StringAlignment.Far;
                            break;
                        }

                    case ContentAlignment.MiddleCenter:
                        {
                            horizontal = StringAlignment.Center;
                            vertical = StringAlignment.Center;
                            break;
                        }
                    case ContentAlignment.MiddleLeft:
                        {
                            horizontal = StringAlignment.Near;
                            vertical = StringAlignment.Center;
                            break;
                        }
                    case ContentAlignment.MiddleRight:
                        {
                            horizontal = StringAlignment.Far;
                            vertical = StringAlignment.Center;
                            break;
                        }

                    case ContentAlignment.TopCenter:
                        {
                            horizontal = StringAlignment.Center;
                            vertical = StringAlignment.Near;
                            break;
                        }
                    case ContentAlignment.TopLeft:
                        {
                            horizontal = StringAlignment.Near;
                            vertical = StringAlignment.Near;
                            break;
                        }
                    case ContentAlignment.TopRight:
                        {
                            horizontal = StringAlignment.Far;
                            vertical = StringAlignment.Near;
                            break;
                        }
                }

                int imageLeft = 0;
                int imageTop = 0;

                switch (horizontal)
                {
                    case StringAlignment.Near:
                        imageLeft = 4;
                        break;
                    case StringAlignment.Center:
                        imageLeft = 1 + (this.ClientRectangle.Width / 2 - this.Image.Width / 2);
                        break;
                    case StringAlignment.Far:
                        imageLeft = this.Width - this.Image.Width - 4;
                        break;
                }

                switch (vertical)
                {
                    case StringAlignment.Near:
                        imageTop = 2;
                        break;
                    case StringAlignment.Center:
                        imageTop = 0 + (this.ClientRectangle.Height / 2 - this.Image.Height / 2);
                        break;
                    case StringAlignment.Far:
                        imageTop = this.Height - this.Image.Height - 2;
                        break;
                }

                if (this.Enabled == false)
                {
                    ControlPaint.DrawImageDisabled(e.Graphics, this.Image, imageLeft, imageTop, GlassStyleManager.Active.ButtonDisabled.Bottom);
                }
                else
                {
                    if (this.mouseDown == true)
                    {
                        imageLeft++;
                        imageTop++;
                    }

                    e.Graphics.DrawImage(this.Image, imageLeft, imageTop, this.Image.Width, this.Image.Height);
                }
            }

            Rectangle textRectangle = this.ClientRectangle;
            int textPadding = this.Depth + (this.Depth/4) + 2;

            textRectangle.Inflate(-textPadding, -textPadding);

            if (this.Image != null)
            {
                switch (horizontal)
                {
                    case StringAlignment.Near:
                        textRectangle = new Rectangle(this.Image.Width + 4, 0, this.ClientRectangle.Width - this.Image.Width - 2, this.ClientRectangle.Height);
                        break;
                    case StringAlignment.Center:
                        textRectangle = new Rectangle(0, this.Image.Height + 2, this.ClientRectangle.Width, this.ClientRectangle.Height - this.Image.Height - 2);
                        break;
                    case StringAlignment.Far:
                        textRectangle = new Rectangle(0, 0, this.ClientRectangle.Width - this.Image.Width - 2, this.ClientRectangle.Height);
                        break;
                }
            }

            if (this.Enabled == false)
            {
                GlassHelper.DrawText(this.Text, textRectangle, this.TextAlign, e.Graphics, true, ControlPaint.Dark(GlassStyleManager.Active.ForeColor), Color.Empty);
            }
            else
            {
                if (this.mouseDown == true)
                {
                    textRectangle.Offset(1, 1);
                }

                GlassHelper.DrawText(this.Text, textRectangle, this.TextAlign, e.Graphics, true, Color.Empty, Color.Empty);
            }
        }
Esempio n. 15
0
        protected override void OnPaint(PaintEventArgs e)
        {
            GlassGradient activeGradient = normalGradient;

            if (UseStyles)
            {
                if (Enabled == false)
                {
                    activeGradient = GlassStyleManager.Active.ButtonDisabled;
                }
                else if (mouseDown)
                {
                    activeGradient = GlassStyleManager.Active.ButtonPressed;
                }
                else if (mouseOver)
                {
                    activeGradient = GlassStyleManager.Active.ButtonHover;
                }
                else if (highlight)
                {
                    activeGradient = GlassStyleManager.Active.ButtonHighlight;
                }
                else
                {
                    activeGradient = GlassStyleManager.Active.ButtonNormal;
                }
            }
            else
            {
                if (Enabled == false)
                {
                    activeGradient = disabledGradient;
                }
                else if (mouseDown)
                {
                    activeGradient = pressedGradient;
                }
                else if (mouseOver)
                {
                    activeGradient = hoverGradient;
                }
                else if (highlight)
                {
                    activeGradient = highlightGradient;
                }
                else
                {
                    activeGradient = normalGradient;
                }
            }

            e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
            e.Graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
            e.Graphics.SmoothingMode      = SmoothingMode.AntiAlias;

            Rectangle clientRectangle = ClientRectangle;

            clientRectangle.Inflate(-1, -1);

            bool activeIsGlass;

            GlassGradient sunk = new GlassGradient(Color.FromArgb(48, Color.White), Color.FromArgb(160, Color.Black));

            if (Parent is GlassPanel)
            {
                GlassPanel parent = (GlassPanel)Parent;
                if (parent.UseStyles)
                {
                    activeIsGlass = GlassStyleManager.Active.PanelIsGlass;
                }
                else
                {
                    activeIsGlass = parent.IsGlass;
                }
            }
            else
            {
                activeIsGlass = false;
            }

            GlassHelper.FillRoundedRectangle(clientRectangle, sunk, true, activeIsGlass, e.Graphics);

            Rectangle rectangle = clientRectangle;

            rectangle.Inflate(-depth, -depth);

            if (UseStyles)
            {
                activeIsGlass = GlassStyleManager.Active.ButtonIsGlass;
            }
            else
            {
                activeIsGlass = IsGlass;
            }

            GlassHelper.FillRoundedRectangle(rectangle, activeGradient, false, activeIsGlass, e.Graphics);

            e.Graphics.SetClip(ClientRectangle);

            GlassHelper.DrawRoundedBorder(rectangle, BorderColor, Depth / 4.0f, e.Graphics);

            StringAlignment vertical   = StringAlignment.Center;
            StringAlignment horizontal = StringAlignment.Center;

            if (Image != null)
            {
                switch (ImageAlign)
                {
                case ContentAlignment.BottomCenter:
                {
                    horizontal = StringAlignment.Center;
                    vertical   = StringAlignment.Far;
                    break;
                }

                case ContentAlignment.BottomLeft:
                {
                    horizontal = StringAlignment.Near;
                    vertical   = StringAlignment.Far;
                    break;
                }

                case ContentAlignment.BottomRight:
                {
                    horizontal = StringAlignment.Far;
                    vertical   = StringAlignment.Far;
                    break;
                }

                case ContentAlignment.MiddleCenter:
                {
                    horizontal = StringAlignment.Center;
                    vertical   = StringAlignment.Center;
                    break;
                }

                case ContentAlignment.MiddleLeft:
                {
                    horizontal = StringAlignment.Near;
                    vertical   = StringAlignment.Center;
                    break;
                }

                case ContentAlignment.MiddleRight:
                {
                    horizontal = StringAlignment.Far;
                    vertical   = StringAlignment.Center;
                    break;
                }

                case ContentAlignment.TopCenter:
                {
                    horizontal = StringAlignment.Center;
                    vertical   = StringAlignment.Near;
                    break;
                }

                case ContentAlignment.TopLeft:
                {
                    horizontal = StringAlignment.Near;
                    vertical   = StringAlignment.Near;
                    break;
                }

                case ContentAlignment.TopRight:
                {
                    horizontal = StringAlignment.Far;
                    vertical   = StringAlignment.Near;
                    break;
                }
                }

                int imageLeft = 0;
                int imageTop  = 0;

                switch (horizontal)
                {
                case StringAlignment.Near:
                    imageLeft = 4;
                    break;

                case StringAlignment.Center:
                    imageLeft = 1 + (ClientRectangle.Width / 2 - Image.Width / 2);
                    break;

                case StringAlignment.Far:
                    imageLeft = Width - Image.Width - 4;
                    break;
                }

                switch (vertical)
                {
                case StringAlignment.Near:
                    imageTop = 2;
                    break;

                case StringAlignment.Center:
                    imageTop = 0 + (ClientRectangle.Height / 2 - Image.Height / 2);
                    break;

                case StringAlignment.Far:
                    imageTop = Height - Image.Height - 2;
                    break;
                }

                if (Enabled == false)
                {
                    ControlPaint.DrawImageDisabled(e.Graphics, Image, imageLeft, imageTop,
                                                   GlassStyleManager.Active.ButtonDisabled.Bottom);
                }
                else
                {
                    if (mouseDown)
                    {
                        imageLeft++;
                        imageTop++;
                    }

                    e.Graphics.DrawImage(Image, imageLeft, imageTop, Image.Width, Image.Height);
                }
            }

            Rectangle textRectangle = ClientRectangle;
            int       textPadding   = Depth + (Depth / 4) + 2;

            textRectangle.Inflate(-textPadding, -textPadding);

            if (Image != null)
            {
                switch (horizontal)
                {
                case StringAlignment.Near:
                    textRectangle = new Rectangle(Image.Width + 4, 0, ClientRectangle.Width - Image.Width - 2,
                                                  ClientRectangle.Height);
                    break;

                case StringAlignment.Center:
                    textRectangle = new Rectangle(0, Image.Height + 2, ClientRectangle.Width,
                                                  ClientRectangle.Height - Image.Height - 2);
                    break;

                case StringAlignment.Far:
                    textRectangle = new Rectangle(0, 0, ClientRectangle.Width - Image.Width - 2,
                                                  ClientRectangle.Height);
                    break;
                }
            }

            if (Enabled == false)
            {
                GlassHelper.DrawText(Text, textRectangle, TextAlign, e.Graphics, true,
                                     ControlPaint.Dark(GlassStyleManager.Active.ForeColor), Color.Empty);
            }
            else
            {
                if (mouseDown)
                {
                    textRectangle.Offset(1, 1);
                }

                GlassHelper.DrawText(Text, textRectangle, TextAlign, e.Graphics, true, Color.Empty, Color.Empty);
            }
        }
Esempio n. 16
0
        public static void FillRectangle(Rectangle rectangle, GlassGradient gradient, bool isSunk, bool isGlass, Graphics graphics)
        {
            if (rectangle.Width == 0 || rectangle.Height == 0)
                return;

            GlassGradient activeGradient = null;
            if (isSunk == true)
                activeGradient = new GlassGradient(gradient.Bottom, gradient.Top);
            else
                activeGradient = new GlassGradient(gradient.Top, gradient.Bottom);

            Brush brush = activeGradient.GetBrush(rectangle);
            graphics.FillRectangle(brush, rectangle);
            brush.Dispose();

            if (isGlass == true)
            {
                graphics.SetClip(rectangle);

                Rectangle glassRectangle;

                if (isSunk == true)
                    glassRectangle = new Rectangle(new Point(rectangle.Left, rectangle.Height / 2), new Size(rectangle.Width, rectangle.Height / 2));
                else
                    glassRectangle = new Rectangle(rectangle.Location, new Size(rectangle.Width, rectangle.Height / 2));

                Brush glassBrush = new LinearGradientBrush(glassRectangle, Color.Transparent, Color.FromArgb(32, 255, 255, 255), 90.0f);

                graphics.FillRectangle(glassBrush, glassRectangle);

                glassBrush.Dispose();
            }
        }