Ejemplo n.º 1
0
        /*
         * DrawFormBorders
         */

        /// <summary>
        /// Draws borders for this <see cref="HostForm"/>.
        /// </summary>
        /// <param name="g">Specifies GDI+ drawing surface to draw on.</param>
        /// <exception cref="ArgumentNullException"><paramref name="g"/> is <see langword="null"/>.</exception>
        protected virtual void DrawFormBorders(Graphics g)
        {
            Debug.Assert(g != null, "g != null");

            if (g == null)
            {
                throw new ArgumentNullException("g");
            }

            Debug.Assert(this.HostForm != null, "this.HostForm != null");

            if (this.HostForm != null)
            {
                NuGenLinearGradientColorTable[] colorTables = this.GetBorderColors();
                RectangleF borderRectangle = new RectangleF(
                    OFFSET,
                    OFFSET,
                    this.HostForm.Width - (1 + OFFSET),
                    this.HostForm.Height - (1 + OFFSET)
                    );
                int           borderWidth           = colorTables.Length;
                SmoothingMode previousSmoothingMode = g.SmoothingMode;

                g.SmoothingMode = SmoothingMode.HighQuality;

                int colorTableIndex = 0;

                for (int i = 0; i < borderWidth; i++)
                {
                    NuGenLinearGradientColorTable colorTable = colorTables[colorTableIndex];

                    using (GraphicsPath gp = this.GetFormPath(borderRectangle))
                    {
                        NuGenRibbonFormPainter.DrawBorders(
                            g,
                            gp,
                            colorTable.StartColor,
                            colorTable.EndColor,
                            colorTable.GradientAngle,
                            colorTables.Length
                            );
                    }

                    borderRectangle.Inflate(-1, -1);

                    if (colorTableIndex < (colorTables.Length - 1))
                    {
                        colorTableIndex++;
                    }
                }

                g.SmoothingMode = previousSmoothingMode;
            }
        }
Ejemplo n.º 2
0
        /*
         * GetFormPath
         */

        /// <summary>
        /// Builds a <see cref="T:System.Drawing.Drawing2D.GraphicsPath"/> according to the specified
        /// bounds.
        /// </summary>
        /// <param name="bounds">Specifies form bounds.</param>
        /// <returns></returns>
        protected virtual GraphicsPath GetFormPath(RectangleF bounds)
        {
            Debug.Assert(this.HostForm != null, "this.HostForm != null");

            if (this.HostForm != null && this.HostForm.WindowState == FormWindowState.Normal)
            {
                GraphicsPath gp          = new GraphicsPath();
                bool         rightToLeft = this.HostForm.RightToLeft == RightToLeft.Yes;

                /* Top-left corner */

                NuGenRibbonFormPainter.AddArcFromDescriptor(
                    gp,
                    NuGenRibbonFormPainter.BuildArcDescriptor(
                        bounds,
                        rightToLeft
                                                        ? this.RibbonFormProperties.TopRightCornerSize
                                                        : this.RibbonFormProperties.TopLeftCornerSize
                        ,
                        NuGenCornerStyle.TopLeft)
                    );

                /* Top-right corner */

                NuGenRibbonFormPainter.AddArcFromDescriptor(
                    gp,
                    NuGenRibbonFormPainter.BuildArcDescriptor(
                        bounds,
                        rightToLeft
                                                        ? this.RibbonFormProperties.TopLeftCornerSize
                                                        : this.RibbonFormProperties.TopRightCornerSize
                        ,
                        NuGenCornerStyle.TopRight)
                    );

                /* Bottom-right corner */

                NuGenRibbonFormPainter.AddArcFromDescriptor(
                    gp,
                    NuGenRibbonFormPainter.BuildArcDescriptor(
                        bounds,
                        this.RibbonFormProperties.BottomRightCornerSize,
                        NuGenCornerStyle.BottomRight)
                    );

                /* Bottom-left corner */

                NuGenRibbonFormPainter.AddArcFromDescriptor(
                    gp,
                    NuGenRibbonFormPainter.BuildArcDescriptor(
                        bounds,
                        this.RibbonFormProperties.BottomLeftCornerSize,
                        NuGenCornerStyle.BottomLeft)
                    );

                gp.CloseAllFigures();
                return(gp);
            }
            else
            {
                GraphicsPath gp = new GraphicsPath();
                gp.AddRectangle(bounds);
                return(gp);
            }
        }