Ejemplo n.º 1
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (buttonDefault.Checked)
         _Shape = null;
     else if (buttonRect.Checked)
         _Shape = new RoundRectangleShapeDescriptor(0);
     else if (buttonRound.Checked)
     {
         _Shape = new RoundRectangleShapeDescriptor(roundTopLeft.Value, roundTopRight.Value, roundBottomLeft.Value, roundBottomRight.Value);
     }
     else if (buttonEllipse.Checked)
         _Shape = new EllipticalShapeDescriptor();
 }
Ejemplo n.º 2
0
        protected override void PaintStateBackground(ButtonItem button, Graphics g, Office2007ButtonItemStateColorTable stateColors, Rectangle r, IShapeDescriptor shape, bool isDefault, bool paintBorder)
        {
            if (stateColors == null || stateColors.Background == null || stateColors.Background.IsEmpty)
                return;

            Rectangle shadowRect = r;
            ShadowPaintInfo spi = new ShadowPaintInfo();
            spi.Graphics = g;
            spi.Rectangle = shadowRect;
            ShadowPainter.Paint3(spi);

            r.Width -= 4;
            r.Height -= 4;
            r.Offset(1, 1);

            DisplayHelp.FillRectangle(g, r, stateColors.Background);
            if (stateColors.BottomBackgroundHighlight != null && !stateColors.BottomBackgroundHighlight.IsEmpty)
            {
                Rectangle ellipse = new Rectangle(r.X, r.Y + r.Height / 2 - 2, r.Width, r.Height + 4);
                GraphicsPath path = new GraphicsPath();
                path.AddEllipse(ellipse);
                PathGradientBrush brush = new PathGradientBrush(path);
                brush.CenterColor = stateColors.BottomBackgroundHighlight.Start;
                brush.SurroundColors = new Color[] { stateColors.BottomBackgroundHighlight.End };
                brush.CenterPoint = new PointF(ellipse.X + ellipse.Width / 2, r.Bottom);
                Blend blend = new Blend();
                blend.Factors = new float[] { 0f, .5f, .6f };
                blend.Positions = new float[] { .0f, .4f, 1f };
                brush.Blend = blend;

                g.FillRectangle(brush, r);
                brush.Dispose();
                path.Dispose();
            }

            DisplayHelp.DrawGradientRectangle(g, r, stateColors.OuterBorder, 1);
            r.Inflate(-1, -1);
            DisplayHelp.DrawGradientRectangle(g, r, stateColors.InnerBorder, 1);
        }
Ejemplo n.º 3
0
        public static void PaintBackground(Graphics g, Office2007ButtonItemStateColorTable stateColors, Rectangle r, IShapeDescriptor shape, bool isDefault, bool paintBorder)
        {
            float topSplit = .35f;
            float bottomSplit = .65f;
            if (!shape.CanDrawShape(r)) return;

            if (stateColors != null)
            {
                Rectangle fillRectangle = r;
                
                Rectangle backRect = new Rectangle(fillRectangle.X, fillRectangle.Y, fillRectangle.Width, (int)(fillRectangle.Height * topSplit));
                if (!stateColors.OuterBorder.IsEmpty && paintBorder)
                    fillRectangle.Width--;
                GraphicsPath backPath = shape.GetShape(fillRectangle);
                if (stateColors.Background != null)
                {
                    if (backPath != null)
                    {
                        if (stateColors.Background.End.IsEmpty)
                        {
                            using (SolidBrush brush = new SolidBrush(stateColors.Background.Start))
                                g.FillPath(brush, backPath);
                        }
                        else
                        {
                            using (LinearGradientBrush lb = new LinearGradientBrush(fillRectangle, stateColors.Background.Start, stateColors.Background.End, stateColors.Background.GradientAngle))
                            {
                                g.FillPath(lb, backPath);
                            }
                        }
                        backPath.Dispose();
                    }
                }
                else
                {
                    if (backPath != null && stateColors.TopBackground!= null && stateColors.BottomBackground!=null)
                    {
                        if (stateColors.TopBackground.End.IsEmpty && stateColors.BottomBackground.End.IsEmpty)
                        {
                            if (stateColors.TopBackground.Start == stateColors.BottomBackground.Start)
                                using (SolidBrush lb = new SolidBrush(stateColors.TopBackground.Start))
                                    g.FillPath(lb, backPath);
                            else
                            {
                                using (LinearGradientBrush lb = new LinearGradientBrush(fillRectangle, stateColors.TopBackground.Start, stateColors.BottomBackground.Start, stateColors.TopBackground.GradientAngle))
                                {
                                    g.FillPath(lb, backPath);
                                }
                            }
                        }
                        else
                        {
                            using (LinearGradientBrush lb = new LinearGradientBrush(fillRectangle, stateColors.TopBackground.Start, stateColors.BottomBackground.End, stateColors.TopBackground.GradientAngle))
                            {
                                ColorBlend cb = new ColorBlend(4);
                                cb.Colors = new Color[] { stateColors.TopBackground.Start, stateColors.TopBackground.End, stateColors.BottomBackground.Start, stateColors.BottomBackground.End };
                                cb.Positions = new float[] { 0, topSplit, topSplit, 1f };
                                lb.InterpolationColors = cb;
                                g.FillPath(lb, backPath);
                            }
                        }
                        backPath.Dispose();
                    }

                    if (stateColors.TopBackgroundHighlight!=null && !stateColors.TopBackgroundHighlight.IsEmpty)
                    {
                        Rectangle ellipse = new Rectangle(fillRectangle.X, fillRectangle.Y, fillRectangle.Width, fillRectangle.Height);
                        GraphicsPath path = new GraphicsPath();
                        path.AddEllipse(ellipse);
                        PathGradientBrush brush = new PathGradientBrush(path);
                        brush.CenterColor = stateColors.TopBackgroundHighlight.Start;
                        brush.SurroundColors = new Color[] { stateColors.TopBackgroundHighlight.End };
                        brush.CenterPoint = new PointF(ellipse.X + ellipse.Width / 2, fillRectangle.Bottom);
                        Blend blend = new Blend();
                        blend.Factors = new float[] { 0f, .5f, 1f };
                        blend.Positions = new float[] { .0f, .4f, 1f };
                        brush.Blend = blend;

                        g.FillRectangle(brush, backRect);
                        brush.Dispose();
                        path.Dispose();
                    }

                    // Draw Bottom part
                    int bottomHeight = (int)(fillRectangle.Height * bottomSplit);
                    backRect = new Rectangle(fillRectangle.X, fillRectangle.Y + backRect.Height, fillRectangle.Width, fillRectangle.Height - backRect.Height);

                    if (stateColors.BottomBackgroundHighlight!=null && !stateColors.BottomBackgroundHighlight.IsEmpty)
                    {
                        Rectangle ellipse = new Rectangle(fillRectangle.X, fillRectangle.Y + bottomHeight - 2, fillRectangle.Width, fillRectangle.Height + 4);
                        GraphicsPath path = new GraphicsPath();
                        path.AddEllipse(ellipse);
                        PathGradientBrush brush = new PathGradientBrush(path);
                        brush.CenterColor = stateColors.BottomBackgroundHighlight.Start;
                        brush.SurroundColors = new Color[] { stateColors.BottomBackgroundHighlight.End };
                        brush.CenterPoint = new PointF(ellipse.X + ellipse.Width / 2, fillRectangle.Bottom);
                        Blend blend = new Blend();
                        blend.Factors = new float[] { 0f, .5f, .6f };
                        blend.Positions = new float[] { .0f, .4f, 1f };
                        brush.Blend = blend;

                        g.FillRectangle(brush, backRect);
                        brush.Dispose();
                        path.Dispose();
                    }
                }

                if (paintBorder)
                {
                    SmoothingMode sm = g.SmoothingMode;
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                    // Draw Border
                    if (!stateColors.OuterBorder.IsEmpty && stateColors.OuterBorderWidth>0)
                    {
                        Rectangle br = r;
                        br.Width--;
                        br.Height--;

                        if (shape is EllipticalShapeDescriptor && stateColors.OuterBorder.End.IsEmpty)
                        {
                            br.Width -= (stateColors.OuterBorderWidth / 2);
                            br.Height -= (stateColors.OuterBorderWidth / 2);
                            using (Pen pen = new Pen(stateColors.OuterBorder.Start, stateColors.OuterBorderWidth))
                                g.DrawEllipse(pen, br);
                        }
                        else
                        {
                            GraphicsPath path = shape.GetShape(br);
                            if (path != null)
                            {
                                DisplayHelp.DrawGradientPath(g, path, r, stateColors.OuterBorder, stateColors.OuterBorderWidth);
                                path.Dispose();
                            }
                        }
                        //if (cornerSize > 1)
                        //    DisplayHelp.DrawRoundGradientRectangle(g, r, stateColors.OuterBorder, 1, cornerSize);
                        //else
                        //    DisplayHelp.DrawGradientRectangle(g, r, stateColors.OuterBorder, 1);

                        if (isDefault)
                        {
                            Color clr = Color.FromArgb(128, stateColors.OuterBorder.Start);
                            r.Inflate(-1, -1);
                            DisplayHelp.DrawRectangle(g, clr, r);
                            r.Inflate(-1, -1);
                            DisplayHelp.DrawRectangle(g, clr, r);
                        }
                    }
                    if (!isDefault && !stateColors.InnerBorder.IsEmpty)
                    {
                        Rectangle innerRect = r;
                        innerRect.Inflate(-1, -1);
                        innerRect.Width--;
                        innerRect.Height--;
                        using (GraphicsPath path = shape.GetInnerShape(innerRect, 1))
                            DisplayHelp.DrawGradientPath(g, path, innerRect, stateColors.InnerBorder, 1);
                        //cornerSize--;
                        //if (cornerSize > 1)
                        //    DisplayHelp.DrawRoundGradientRectangle(g, innerRect, stateColors.InnerBorder, 1, cornerSize);
                        //else
                        //    DisplayHelp.DrawGradientRectangle(g, innerRect, stateColors.InnerBorder, 1);
                    }

                    g.SmoothingMode = sm;
                }
            }
        }
Ejemplo n.º 4
0
 public static void PaintBackground(Graphics g, Office2007ButtonItemStateColorTable stateColors, Rectangle r, IShapeDescriptor shape, bool isDefault)
 {
     PaintBackground(g, stateColors, r, shape, isDefault, true);
 }
Ejemplo n.º 5
0
 public static void PaintBackground(Graphics g, Office2007ButtonItemStateColorTable stateColors, Rectangle r, IShapeDescriptor shape)
 {
     PaintBackground(g, stateColors, r, shape, false);
 }
Ejemplo n.º 6
0
 protected virtual void PaintStateBackground(ButtonItem button, Graphics g, Office2007ButtonItemStateColorTable stateColors, Rectangle r, IShapeDescriptor shape, bool isDefault, bool paintBorder)
 {
     PaintBackground(g, stateColors, r, shape, isDefault, paintBorder);
 }