Restrict graphics clipping using the provided path/region instance.
상속: GlobalId, IDisposable
예제 #1
0
        private void RenderBorder(RenderContext context, Rectangle rect)
        {
            Debug.Assert(context != null);

            // Do we need to draw the border?
            if (_paletteBorder.GetBorderDraw(State) == InheritBool.True)
            {
                if (Splitter)
                {
                    bool mouseInSplit = MouseInSplit;
                    switch (State)
                    {
                    case PaletteState.Tracking:
                        DrawBorder(context, rect, _paletteBorder, PaletteState.Tracking);
                        break;

                    case PaletteState.Pressed:
                        DrawBorder(context, rect, _paletteBorder, PaletteState.Tracking);

                        using (Clipping clipToSplitter = new Clipping(context.Graphics, (mouseInSplit ? _splitRectangle : _nonSplitRectangle)))
                            DrawBorder(context, rect, _paletteBorder, PaletteState.Pressed);
                        break;

                    default:
                        DrawBorder(context, rect, _paletteBorder, State);
                        break;
                    }
                }
                else
                {
                    DrawBorder(context, rect, _paletteBorder, State);
                }
            }
        }
        /// <summary>
        /// Draw a background for an expert style button with pressed effect.
        /// </summary>
        /// <param name="context">Rendering context.</param>
        /// <param name="rect">Rectangle to draw.</param>
        /// <param name="backColor1">First color.</param>
        /// <param name="backColor2">Second color.</param>
        /// <param name="orientation">Drawing orientation.</param>
        /// <param name="path">Clipping path.</param>
        /// <param name="memento">Cache used for drawing.</param>
        public static IDisposable DrawBackExpertPressed(RenderContext context,
                                                        Rectangle rect,
                                                        Color backColor1,
                                                        Color backColor2,
                                                        VisualOrientation orientation,
                                                        GraphicsPath path,
                                                        IDisposable memento)
        {
            using (Clipping clip = new Clipping(context.Graphics, path))
            {
                // Cannot draw a zero length rectangle
                if ((rect.Width > 0) && (rect.Height > 0))
                {
                    bool generate = true;
                    MementoBackExpertShadow cache;

                    // Access a cache instance and decide if cache resources need generating
                    if (!(memento is MementoBackExpertShadow))
                    {
                        memento?.Dispose();

                        cache   = new MementoBackExpertShadow(rect, backColor1, backColor2);
                        memento = cache;
                    }
                    else
                    {
                        cache    = (MementoBackExpertShadow)memento;
                        generate = !cache.UseCachedValues(rect, backColor1, backColor2);
                    }

                    // Do we need to generate the contents of the cache?
                    if (generate)
                    {
                        rect.X      -= 1;
                        rect.Y      -= 1;
                        rect.Width  += 2;
                        rect.Height += 2;

                        // Dispose of existing values
                        cache.Dispose();
                        cache.path1  = CreateBorderPath(rect, ITEM_CUT);
                        cache.path2  = CreateBorderPath(new Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height - 2), ITEM_CUT);
                        cache.path3  = CreateBorderPath(new Rectangle(rect.X + 2, rect.Y + 2, rect.Width - 4, rect.Height - 4), ITEM_CUT);
                        cache.brush1 = new SolidBrush(CommonHelper.MergeColors(backColor2, 0.4f, backColor1, 0.6f));
                        cache.brush2 = new SolidBrush(CommonHelper.MergeColors(backColor2, 0.2f, backColor1, 0.8f));
                        cache.brush3 = new SolidBrush(backColor1);
                    }

                    using (AntiAlias aa = new AntiAlias(context.Graphics))
                    {
                        context.Graphics.FillRectangle(cache.brush3, rect);
                        context.Graphics.FillPath(cache.brush1, cache.path1);
                        context.Graphics.FillPath(cache.brush2, cache.path2);
                        context.Graphics.FillPath(cache.brush3, cache.path3);
                    }
                }

                return(memento);
            }
        }
        /// <summary>
        /// Draw a background for an expert style button with tracking effect.
        /// </summary>
        /// <param name="context">Rendering context.</param>
        /// <param name="rect">Rectangle to draw.</param>
        /// <param name="backColor1">First color.</param>
        /// <param name="backColor2">Second color.</param>
        /// <param name="orientation">Drawing orientation.</param>
        /// <param name="path">Clipping path.</param>
        /// <param name="memento">Cache used for drawing.</param>
        public static IDisposable DrawBackExpertTracking(RenderContext context,
                                                         Rectangle rect,
                                                         Color backColor1,
                                                         Color backColor2,
                                                         VisualOrientation orientation,
                                                         GraphicsPath path,
                                                         IDisposable memento)
        {
            using (Clipping clip = new Clipping(context.Graphics, path))
            {
                MementoDouble cache;

                if (!(memento is MementoDouble))
                {
                    memento?.Dispose();

                    cache   = new MementoDouble();
                    memento = cache;
                }
                else
                {
                    cache = (MementoDouble)memento;
                }

                cache.first = DrawBackExpert(rect,
                                             CommonHelper.MergeColors(backColor1, 0.35f, Color.White, 0.65f),
                                             CommonHelper.MergeColors(backColor2, 0.53f, Color.White, 0.65f),
                                             orientation, context.Graphics, memento, true, true);

                cache.second = DrawBackExpert(rect, backColor1, backColor2, orientation, context.Graphics, memento, false, true);

                return(cache);
            }
        }
 /// <summary>
 /// Draw a background for an expert style button that is checked.
 /// </summary>
 /// <param name="context">Rendering context.</param>
 /// <param name="rect">Rectangle to draw.</param>
 /// <param name="backColor1">First color.</param>
 /// <param name="backColor2">Second color.</param>
 /// <param name="orientation">Drawing orientation.</param>
 /// <param name="path">Clipping path.</param>
 /// <param name="memento">Cache used for drawing.</param>
 public static IDisposable DrawBackExpertChecked(RenderContext context,
                                                 Rectangle rect,
                                                 Color backColor1,
                                                 Color backColor2,
                                                 VisualOrientation orientation,
                                                 GraphicsPath path,
                                                 IDisposable memento)
 {
     using (Clipping clip = new Clipping(context.Graphics, path))
     {
         // Draw the expert background which is gradient with highlight at bottom
         return(DrawBackExpert(rect, backColor1, backColor2, orientation, context.Graphics, memento, true, false));
     }
 }
 /// <summary>
 /// Draw a background for an expert style button that is checked.
 /// </summary>
 /// <param name="context">Rendering context.</param>
 /// <param name="rect">Rectangle to draw.</param>
 /// <param name="backColor1">First color.</param>
 /// <param name="backColor2">Second color.</param>
 /// <param name="orientation">Drawing orientation.</param>
 /// <param name="path">Clipping path.</param>
 /// <param name="memento">Cache used for drawing.</param>
 public static IDisposable DrawBackExpertChecked(RenderContext context,
                                                 Rectangle rect,
                                                 Color backColor1,
                                                 Color backColor2,
                                                 VisualOrientation orientation,
                                                 GraphicsPath path,
                                                 IDisposable memento)
 {
     using (Clipping clip = new Clipping(context.Graphics, path))
     {
         // Draw the expert background which is gradient with highlight at bottom
         return DrawBackExpert(rect, backColor1, backColor2, orientation, context.Graphics, memento, true, false);
     }
 }
        /// <summary>
        /// Draw a background with glass effect where the fade is from the bottom.
        /// </summary>
        /// <param name="context">Rendering context.</param>
        /// <param name="rect">Rectangle to draw.</param>
        /// <param name="backColor1">First color.</param>
        /// <param name="backColor2">Second color.</param>
        /// <param name="orientation">Drawing orientation.</param>
        /// <param name="path">Clipping path.</param>
        /// <param name="memento">Cache used for drawing.</param>
        public static IDisposable DrawBackGlassBottom(RenderContext context,
                                                      Rectangle rect,
                                                      Color backColor1,
                                                      Color backColor2,
                                                      VisualOrientation orientation,
                                                      GraphicsPath path,
                                                      IDisposable memento)
        {
            using (Clipping clip = new Clipping(context.Graphics, path))
            {
                MementoDouble cache;

                if ((memento == null) || !(memento is MementoDouble))
                {
                    if (memento != null)
                        memento.Dispose();

                    cache = new MementoDouble();
                    memento = cache;
                }
                else
                    cache = (MementoDouble)memento;

                // Draw the one pixel border around the area
                cache.first = DrawBackLinear(rect, false,
                                             ControlPaint.Light(backColor1),
                                             ControlPaint.LightLight(backColor1),
                                             orientation, context.Graphics,
                                             cache.first);

                // Reduce size on all but the upper edge
                ModifyRectByEdges(ref rect, 1, 0, 1, 1, orientation);

                // Draw the inside areas as a glass effect
                cache.second = DrawBackGlassRadial(rect, backColor1, backColor2,
                                                   _glassColorTopD, _glassColorBottomD,
                                                   3f, 1.1f, orientation, context.Graphics,
                                                   _fullGlassLength, cache.second);
            }

            return memento;
        }
예제 #7
0
        /// <summary>
        /// Draw a background for an expert style button with tracking effect.
        /// </summary>
        /// <param name="context">Rendering context.</param>
        /// <param name="rect">Rectangle to draw.</param>
        /// <param name="backColor1">First color.</param>
        /// <param name="backColor2">Second color.</param>
        /// <param name="orientation">Drawing orientation.</param>
        /// <param name="path">Clipping path.</param>
        /// <param name="memento">Cache used for drawing.</param>
        public static IDisposable DrawBackExpertTracking(RenderContext context,
                                                         Rectangle rect,
                                                         Color backColor1,
                                                         Color backColor2,
                                                         VisualOrientation orientation,
                                                         GraphicsPath path,
                                                         IDisposable memento)
        {
            using (Clipping clip = new Clipping(context.Graphics, path))
            {
                MementoDouble cache;

                if ((memento == null) || !(memento is MementoDouble))
                {
                    if (memento != null)
                    {
                        memento.Dispose();
                    }

                    cache   = new MementoDouble();
                    memento = cache;
                }
                else
                {
                    cache = (MementoDouble)memento;
                }

                // Рисование внешней части фона ( в тч внутренняя граница )
                cache.first = DrawBackExpert(rect,
                                             CommonHelper.MergeColors(backColor1, 0.35f, Color.White, 0.65f),
                                             CommonHelper.MergeColors(backColor2, 0.53f, Color.White, 0.65f),
                                             orientation, context.Graphics, memento, true, true);

                // Рисование внутренней части фона
                cache.second = DrawBackExpert(rect, backColor1, backColor2, orientation, context.Graphics, memento, false, true);



                return(cache);
            }
        }
        /// <summary>
        /// Draw a background in glass effect with three edges lighter.
        /// </summary>
        /// <param name="context">Rendering context.</param>
        /// <param name="rect">Rectangle to draw.</param>
        /// <param name="backColor1">First color.</param>
        /// <param name="backColor2">Second color.</param>
        /// <param name="orientation">Drawing orientation.</param>
        /// <param name="path">Clipping path.</param>
        /// <param name="memento">Cache used for drawing.</param>
        public static IDisposable DrawBackGlassThreeEdge(RenderContext context,
                                                         Rectangle rect,
                                                         Color backColor1,
                                                         Color backColor2,
                                                         VisualOrientation orientation,
                                                         GraphicsPath path,
                                                         IDisposable memento)
        {
            using (Clipping clip = new Clipping(context.Graphics, path))
            {
                bool generate = true;
                MementoBackGlassThreeEdge cache;

                // Access a cache instance and decide if cache resources need generating
                if ((memento == null) || !(memento is MementoBackGlassThreeEdge))
                {
                    if (memento != null)
                        memento.Dispose();

                    cache = new MementoBackGlassThreeEdge(rect, backColor1, backColor2, orientation);
                    memento = cache;
                }
                else
                {
                    cache = (MementoBackGlassThreeEdge)memento;
                    generate = !cache.UseCachedValues(rect, backColor1, backColor2, orientation);
                }

                // Do we need to generate the contents of the cache?
                if (generate)
                {
                    // Dispose of existing values
                    cache.Dispose();

                    // Generate color values
                    cache.colorA1L = CommonHelper.MergeColors(backColor1, 0.7f, Color.White, 0.3f);
                    cache.colorA2L = CommonHelper.MergeColors(backColor2, 0.7f, Color.White, 0.3f);
                    cache.colorA2LL = CommonHelper.MergeColors(cache.colorA2L, 0.8f, Color.White, 0.2f);
                    cache.colorB2LL = CommonHelper.MergeColors(backColor2, 0.8f, Color.White, 0.2f);
                    cache.rectB = new Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 1, rect.Height - 2);
                }

                // Draw entire area in a lighter version
                cache.first = DrawBackGlassLinear(rect, rect,
                                                  cache.colorA1L, _glassColorLight,
                                                  cache.colorA2L, cache.colorA2LL,
                                                  orientation,
                                                  context.Graphics,
                                                  _fullGlassLength,
                                                  cache.first);

                // Draw the inside area in the full color
                cache.second = DrawBackGlassLinear(cache.rectB, cache.rectB,
                                                   backColor1, _glassColorLight,
                                                   backColor2, cache.colorB2LL,
                                                   orientation,
                                                   context.Graphics,
                                                   _fullGlassLength,
                                                   cache.second);

                return cache;
            }
        }
예제 #9
0
        /// <summary>
        /// Internal rendering method.
        /// </summary>
        protected virtual IDisposable DrawRibbonGroupAreaBorderContext(RenderContext context,
                                                                       Rectangle rect,
                                                                       PaletteState state,
                                                                       IPaletteRibbonBack palette,
                                                                       IDisposable memento)
        {
            if ((rect.Width > 0) && (rect.Height > 0))
            {
                Color c1 = palette.GetRibbonBackColor1(state);
                Color c2 = palette.GetRibbonBackColor2(state);
                Color c3 = palette.GetRibbonBackColor3(state);

                bool generate = true;
                MementoRibbonGroupAreaBorderContext cache;

                // Access a cache instance and decide if cache resources need generating
                if ((memento == null) || !(memento is MementoRibbonGroupAreaBorderContext))
                {
                    if (memento != null)
                        memento.Dispose();

                    cache = new MementoRibbonGroupAreaBorderContext(rect, c1, c2, c3);
                    memento = cache;
                }
                else
                {
                    cache = (MementoRibbonGroupAreaBorderContext)memento;
                    generate = !cache.UseCachedValues(rect, c1, c2, c3);
                }

                // Do we need to generate the contents of the cache?
                if (generate)
                {
                    // Dispose of existing values
                    cache.Dispose();

                    GraphicsPath outsidePath = new GraphicsPath();
                    GraphicsPath insidePath = new GraphicsPath();
                    GraphicsPath shadowPath = new GraphicsPath();

                    // Create path for the entire border
                    outsidePath.AddLine(rect.Left + 2, rect.Top, rect.Right - 3, rect.Top);
                    outsidePath.AddLine(rect.Right - 3, rect.Top, rect.Right - 1, rect.Top + 2);
                    outsidePath.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Bottom - 3);
                    outsidePath.AddLine(rect.Right - 1, rect.Bottom - 3, rect.Right - 3, rect.Bottom - 1);
                    outsidePath.AddLine(rect.Right - 3, rect.Bottom - 1, rect.Left + 2, rect.Bottom - 1);
                    outsidePath.AddLine(rect.Left + 2, rect.Bottom - 1, rect.Left, rect.Bottom - 3);
                    outsidePath.AddLine(rect.Left, rect.Bottom - 3, rect.Left, rect.Top + 2);
                    outsidePath.AddLine(rect.Left, rect.Top + 2, rect.Left + 2, rect.Top);

                    // Create the path for the inside highlight
                    insidePath.AddLine(rect.Left + 1, rect.Top + 3, rect.Left + 1, rect.Bottom - 3);
                    insidePath.AddLine(rect.Left + 1, rect.Bottom - 3, rect.Left + 2, rect.Bottom - 2);
                    insidePath.AddLine(rect.Left + 2, rect.Bottom - 2, rect.Right - 3, rect.Bottom - 2);
                    insidePath.AddLine(rect.Right - 3, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 3);
                    insidePath.AddLine(rect.Right - 2, rect.Bottom - 3, rect.Right - 2, rect.Top + 3);

                    // Create the path for the outside shadow
                    shadowPath.AddLine(rect.Left, rect.Bottom - 2, rect.Left + 2, rect.Bottom);
                    shadowPath.AddLine(rect.Left + 2, rect.Bottom, rect.Right - 3, rect.Bottom);
                    shadowPath.AddLine(rect.Right - 4, rect.Bottom, rect.Right, rect.Bottom - 3);
                    shadowPath.AddLine(rect.Right, rect.Bottom - 3, rect.Right, rect.Top + 3);

                    LinearGradientBrush insideBrush = new LinearGradientBrush(rect, Color.Transparent, c2, 95f);
                    cache.insidePen = new Pen(insideBrush);

                    Rectangle rectGradient = new Rectangle(rect.Left - 1, rect.Top, rect.Width + 2, rect.Height + 1);
                    LinearGradientBrush shadowBrush = new LinearGradientBrush(rectGradient, _darken8, _darken38, 90f);
                    cache.shadowPen = new Pen(shadowBrush);

                    cache.fillBrush = new LinearGradientBrush(rect, Color.White, _242, 90f);
                    cache.fillBrush.Blend = _ribbonGroup3Blend;
                    cache.fillTopBrush = new LinearGradientBrush(rect, Color.FromArgb(75, c3), Color.Transparent, 90f);
                    cache.fillTopBrush.Blend = _ribbonGroup4Blend;
                    cache.outsidePath = outsidePath;
                    cache.insidePath = insidePath;
                    cache.shadowPath = shadowPath;
                    cache.outsidePen = new Pen(c1);
                }

                // Fill the inside area with a linear gradient
                context.Graphics.FillPath(cache.fillBrush, cache.outsidePath);

                // Clip drawing to the outside border
                using (Clipping clip = new Clipping(context.Graphics, cache.outsidePath))
                    context.Graphics.FillPath(cache.fillTopBrush, cache.outsidePath);

                using (AntiAlias aa = new AntiAlias(context.Graphics))
                {
                    // Draw the outside of the entire border line
                    context.Graphics.DrawPath(cache.outsidePen, cache.outsidePath);

                    // Draw the highlighting inside border
                    context.Graphics.DrawPath(cache.insidePen, cache.insidePath);
                }

                // Draw the shadow outside the bottom and right edges
                context.Graphics.DrawPath(cache.shadowPen, cache.shadowPath);
                context.Graphics.DrawLine(_medium2ShadowPen, rect.Left, rect.Bottom, rect.Left, rect.Bottom - 1);
                context.Graphics.DrawLine(_medium2ShadowPen, rect.Left, rect.Bottom - 1, rect.Left + 1, rect.Bottom);
                context.Graphics.DrawLine(_darkShadowPen, rect.Right, rect.Bottom - 2, rect.Right - 2, rect.Bottom);
                context.Graphics.DrawLine(_medium2ShadowPen, rect.Right, rect.Bottom - 1, rect.Right - 1, rect.Bottom);
            }

            return memento;
        }
        /// <summary>
        /// Draw a background for an expert style button with pressed effect.
        /// </summary>
        /// <param name="context">Rendering context.</param>
        /// <param name="rect">Rectangle to draw.</param>
        /// <param name="backColor1">First color.</param>
        /// <param name="backColor2">Second color.</param>
        /// <param name="orientation">Drawing orientation.</param>
        /// <param name="path">Clipping path.</param>
        /// <param name="memento">Cache used for drawing.</param>
        public static IDisposable DrawBackExpertPressed(RenderContext context,
                                                        Rectangle rect,
                                                        Color backColor1,
                                                        Color backColor2,
                                                        VisualOrientation orientation,
                                                        GraphicsPath path,
                                                        IDisposable memento)
        {
            using (Clipping clip = new Clipping(context.Graphics, path))
            {
                // Cannot draw a zero length rectangle
                if ((rect.Width > 0) && (rect.Height > 0))
                {
                    bool generate = true;
                    MementoBackExpertShadow cache;

                    // Access a cache instance and decide if cache resources need generating
                    if ((memento == null) || !(memento is MementoBackExpertShadow))
                    {
                        if (memento != null)
                            memento.Dispose();

                        cache = new MementoBackExpertShadow(rect, backColor1, backColor2);
                        memento = cache;
                    }
                    else
                    {
                        cache = (MementoBackExpertShadow)memento;
                        generate = !cache.UseCachedValues(rect, backColor1, backColor2);
                    }

                    // Do we need to generate the contents of the cache?
                    if (generate)
                    {
                        rect.X -= 1;
                        rect.Y -= 1;
                        rect.Width += 2;
                        rect.Height += 2;

                        // Dispose of existing values
                        cache.Dispose();
                        cache.path1 = CreateBorderPath(rect, _itemCut);
                        cache.path2 = CreateBorderPath(new Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height - 2), _itemCut);
                        cache.path3 = CreateBorderPath(new Rectangle(rect.X + 2, rect.Y + 2, rect.Width - 4, rect.Height - 4), _itemCut);
                        cache.brush1 = new SolidBrush(CommonHelper.MergeColors(backColor2, 0.4f, backColor1, 0.6f));
                        cache.brush2 = new SolidBrush(CommonHelper.MergeColors(backColor2, 0.2f, backColor1, 0.8f));
                        cache.brush3 = new SolidBrush(backColor1);
                    }

                    using (AntiAlias aa = new AntiAlias(context.Graphics))
                    {
                        context.Graphics.FillRectangle(cache.brush3, rect);
                        context.Graphics.FillPath(cache.brush1, cache.path1);
                        context.Graphics.FillPath(cache.brush2, cache.path2);
                        context.Graphics.FillPath(cache.brush3, cache.path3);
                    }
                }

                return memento;
            }
        }
        private static IDisposable DrawBackExpert(Rectangle drawRect,
                                                  Color color1,
                                                  Color color2,
                                                  VisualOrientation orientation,
                                                  Graphics g,
                                                  IDisposable memento,
                                                  bool total,
                                                  bool tracking)
        {
            // Cannot draw a zero length rectangle
            if ((drawRect.Width > 0) && (drawRect.Height > 0))
            {
                bool generate = true;
                MementoBackExpertChecked cache;

                // Access a cache instance and decide if cache resources need generating
                if ((memento == null) || !(memento is MementoBackExpertChecked))
                {
                    if (memento != null)
                        memento.Dispose();

                    cache = new MementoBackExpertChecked(drawRect, color1, color2, orientation);
                    memento = cache;
                }
                else
                {
                    cache = (MementoBackExpertChecked)memento;
                    generate = !cache.UseCachedValues(drawRect, color1, color2, orientation);
                }

                // Do we need to generate the contents of the cache?
                if (generate)
                {
                    // Dispose of existing values
                    cache.Dispose();

                    // If not drawing total area...
                    if (!total)
                    {
                        // Update to draw the inside area instead
                        drawRect.Inflate(-1, -1);

                        cache.drawRect = drawRect;
                        cache.clipPath = new GraphicsPath();
                        cache.clipPath.AddLine(drawRect.X + 1, drawRect.Y, drawRect.Right - 1, drawRect.Y);
                        cache.clipPath.AddLine(drawRect.Right - 1, drawRect.Y, drawRect.Right, drawRect.Y + 1);
                        cache.clipPath.AddLine(drawRect.Right, drawRect.Y + 1, drawRect.Right, drawRect.Bottom - 2);
                        cache.clipPath.AddLine(drawRect.Right, drawRect.Bottom - 2, drawRect.Right - 2, drawRect.Bottom);
                        cache.clipPath.AddLine(drawRect.Right - 2, drawRect.Bottom, drawRect.Left + 1, drawRect.Bottom);
                        cache.clipPath.AddLine(drawRect.Left + 1, drawRect.Bottom, drawRect.Left, drawRect.Bottom - 2);
                        cache.clipPath.AddLine(drawRect.Left, drawRect.Bottom - 2, drawRect.Left, drawRect.Y + 1);
                        cache.clipPath.AddLine(drawRect.Left, drawRect.Y + 1, drawRect.X + 1, drawRect.Y);
                    }
                    else
                    {
                        cache.clipPath = new GraphicsPath();
                        cache.clipPath.AddRectangle(drawRect);
                    }

                    // Create rectangle that covers the enter area
                    RectangleF gradientRect = new RectangleF(drawRect.X - 1, drawRect.Y - 1, drawRect.Width + 2, drawRect.Height + 2);

                    // Cannot draw a zero length rectangle
                    if ((gradientRect.Width > 0) && (gradientRect.Height > 0))
                    {
                        // Draw entire area in a gradient color effect
                        cache.entireBrush = new LinearGradientBrush(gradientRect, CommonHelper.WhitenColor(color1, 0.92f, 0.92f, 0.92f), color1, AngleFromOrientation(orientation));
                        cache.entireBrush.Blend = _rounded1Blend;
                    }

                    RectangleF ellipseRect;
                    PointF ellipseCenter;
                    int ellipseHeight = Math.Max(1, drawRect.Height / 4);
                    int ellipseWidth = Math.Max(1, (tracking ? drawRect.Width : drawRect.Width / 4));

                    // Ellipse is based on the orientation
                    switch (orientation)
                    {
                        default:
                        case VisualOrientation.Top:
                            ellipseRect = new RectangleF(drawRect.Left - ellipseWidth, drawRect.Bottom - ellipseHeight, drawRect.Width + ellipseWidth * 2, ellipseHeight * 2);
                            ellipseCenter = new PointF(ellipseRect.Left + (ellipseRect.Width / 2), ellipseRect.Bottom);
                            break;
                        case VisualOrientation.Bottom:
                            ellipseRect = new RectangleF(drawRect.Left - ellipseWidth, drawRect.Top - ellipseHeight, drawRect.Width + ellipseWidth * 2, ellipseHeight * 2);
                            ellipseCenter = new PointF(ellipseRect.Left + (ellipseRect.Width / 2), ellipseRect.Top);
                            break;
                        case VisualOrientation.Left:
                            ellipseRect = new RectangleF(drawRect.Right - ellipseWidth, drawRect.Top - ellipseHeight, ellipseWidth * 2, drawRect.Height + ellipseHeight * 2);
                            ellipseCenter = new PointF(ellipseRect.Right, ellipseRect.Top + (ellipseRect.Height / 2));
                            break;
                        case VisualOrientation.Right:
                            ellipseRect = new RectangleF(drawRect.Left - ellipseWidth, drawRect.Top - ellipseHeight, ellipseWidth * 2, drawRect.Height + ellipseHeight * 2);
                            ellipseCenter = new PointF(ellipseRect.Left, ellipseRect.Top + (ellipseRect.Height / 2));
                            break;
                    }

                    cache.ellipsePath = new GraphicsPath();
                    cache.ellipsePath.AddEllipse(ellipseRect);
                    cache.insideLighten = new PathGradientBrush(cache.ellipsePath);
                    cache.insideLighten.CenterPoint = ellipseCenter;
                    cache.insideLighten.CenterColor = color2;
                    cache.insideLighten.Blend = _rounded2Blend;
                    cache.insideLighten.SurroundColors = new Color[] { Color.Transparent };
                }

                if (cache.entireBrush != null)
                {
                    using(Clipping clip = new Clipping(g, cache.clipPath))
                    {
                        g.FillRectangle(cache.entireBrush, cache.drawRect);
                        g.FillPath(cache.insideLighten, cache.ellipsePath);
                    }
                }
            }

            return memento;
        }
예제 #12
0
        /// <summary>
        /// Raises the RenderToolStripBackground event. 
        /// </summary>
        /// <param name="e">An ToolStripRenderEventArgs containing the event data.</param>
        protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
        {
            // Make sure the font is current
            if (e.ToolStrip.Font != KCT.MenuStripFont)
                e.ToolStrip.Font = KCT.MenuStripFont;

            if ((e.ToolStrip is ContextMenuStrip) ||
                (e.ToolStrip is ToolStripDropDownMenu))
            {
                // Create border and clipping paths
                using (GraphicsPath borderPath = CreateBorderPath(e.AffectedBounds, _cutContextMenu),
                                      clipPath = CreateClipBorderPath(e.AffectedBounds, _cutContextMenu))
                {
                    // Clip all drawing to within the border path
                    using (Clipping clipping = new Clipping(e.Graphics, clipPath))
                    {
                        // Create the background brush
                        using (SolidBrush backBrush = new SolidBrush(KCT.ToolStripDropDownBackground))
                            e.Graphics.FillPath(backBrush, borderPath);
                    }
                }
            }
            else if (e.ToolStrip is StatusStrip)
            {
                // Create rectangle that covers the status strip area
                RectangleF backRect = new RectangleF(0, 0, e.ToolStrip.Width, e.ToolStrip.Height);

                Form owner = e.ToolStrip.FindForm();

                // Check if the status strip is inside a KryptonForm and using the Sparkle renderer, in
                // which case we want to extend the drawing down into the border area for an integrated look
                if ((owner != null) &&
                    (owner is KryptonForm) &&
                    e.ToolStrip.Visible &&
                    (e.ToolStrip.Dock == DockStyle.Bottom) &&
                    (e.ToolStrip.Bottom == owner.ClientSize.Height) &&
                    (e.ToolStrip.RenderMode == ToolStripRenderMode.ManagerRenderMode) &&
                    (ToolStripManager.Renderer is KryptonSparkleRenderer))
                {
                    // Get the window borders
                    KryptonForm kryptonForm = (KryptonForm)owner;

                    // Finally check that the actual form is using custom chrome
                    if (kryptonForm.ApplyCustomChrome)
                    {
                        // Extend down into the bottom border
                        Padding borders = kryptonForm.RealWindowBorders;
                        backRect.Height += borders.Bottom;
                        backRect.Width += borders.Horizontal;
                        backRect.X -= borders.Left;
                    }
                }

                // Cannot paint a zero sized area
                if ((backRect.Width > 0) && (backRect.Height > 0))
                {
                    // Draw entire background
                    using (SolidBrush backBrush = new SolidBrush(KCT.MenuStripGradientBegin))
                        e.Graphics.FillRectangle(backBrush, backRect);

                    // Create path for the rounded bottom edges
                    using (GraphicsPath innerPath = new GraphicsPath())
                    {
                        RectangleF innerRectF = new RectangleF(backRect.X + 2, backRect.Y, backRect.Width - 4, backRect.Height - 2);

                        innerPath.AddLine(innerRectF.Right - 1, innerRectF.Top, innerRectF.Right - 1, innerRectF.Bottom - 7);
                        innerPath.AddArc(innerRectF.Right - 7, innerRectF.Bottom - 7, 6, 6, 0f, 90f);
                        innerPath.AddArc(innerRectF.Left, innerRectF.Bottom - 7, 6, 6, 90f, 90f);
                        innerPath.AddLine(innerRectF.Left, innerRectF.Bottom - 7, innerRectF.Left, innerRectF.Top);

                        // Make the last and first arc join up
                        innerPath.CloseFigure();

                        // Fill with a gradient brush
                        using (LinearGradientBrush innerBrush = new LinearGradientBrush(new Rectangle((int)backRect.X - 1, (int)backRect.Y - 1,
                                                                                                      (int)backRect.Width + 2, (int)backRect.Height + 1),
                                                                                        KCT.StatusStripGradientBegin,
                                                                                        KCT.StatusStripGradientEnd,
                                                                                        90f))
                        {
                            innerBrush.Blend = _statusStripBlend;

                            using(AntiAlias aa = new AntiAlias(e.Graphics))
                                e.Graphics.FillPath(innerBrush, innerPath);
                        }
                    }
                }
            }
            else
                base.OnRenderToolStripBackground(e);
        }
        private static IDisposable DrawBackExpert(Rectangle drawRect,
                                                  Color color1,
                                                  Color color2,
                                                  VisualOrientation orientation,
                                                  Graphics g,
                                                  IDisposable memento,
                                                  bool total,
                                                  bool tracking)
        {
            // Cannot draw a zero length rectangle
            if ((drawRect.Width > 0) && (drawRect.Height > 0))
            {
                bool generate = true;
                MementoBackExpertChecked cache;

                // Access a cache instance and decide if cache resources need generating
                if (!(memento is MementoBackExpertChecked))
                {
                    memento?.Dispose();

                    cache   = new MementoBackExpertChecked(drawRect, color1, color2, orientation);
                    memento = cache;
                }
                else
                {
                    cache    = (MementoBackExpertChecked)memento;
                    generate = !cache.UseCachedValues(drawRect, color1, color2, orientation);
                }

                // Do we need to generate the contents of the cache?
                if (generate)
                {
                    // Dispose of existing values
                    cache.Dispose();

                    // If not drawing total area...
                    if (!total)
                    {
                        // Update to draw the inside area instead
                        drawRect.Inflate(-1, -1);

                        cache.drawRect = drawRect;
                        cache.clipPath = new GraphicsPath();
                        cache.clipPath.AddLine(drawRect.X + 1, drawRect.Y, drawRect.Right - 1, drawRect.Y);
                        cache.clipPath.AddLine(drawRect.Right - 1, drawRect.Y, drawRect.Right, drawRect.Y + 1);
                        cache.clipPath.AddLine(drawRect.Right, drawRect.Y + 1, drawRect.Right, drawRect.Bottom - 2);
                        cache.clipPath.AddLine(drawRect.Right, drawRect.Bottom - 2, drawRect.Right - 2, drawRect.Bottom);
                        cache.clipPath.AddLine(drawRect.Right - 2, drawRect.Bottom, drawRect.Left + 1, drawRect.Bottom);
                        cache.clipPath.AddLine(drawRect.Left + 1, drawRect.Bottom, drawRect.Left, drawRect.Bottom - 2);
                        cache.clipPath.AddLine(drawRect.Left, drawRect.Bottom - 2, drawRect.Left, drawRect.Y + 1);
                        cache.clipPath.AddLine(drawRect.Left, drawRect.Y + 1, drawRect.X + 1, drawRect.Y);
                    }
                    else
                    {
                        cache.clipPath = new GraphicsPath();
                        cache.clipPath.AddRectangle(drawRect);
                    }

                    // Create rectangle that covers the enter area
                    RectangleF gradientRect = new RectangleF(drawRect.X - 1, drawRect.Y - 1, drawRect.Width + 2, drawRect.Height + 2);

                    // Cannot draw a zero length rectangle
                    if ((gradientRect.Width > 0) && (gradientRect.Height > 0))
                    {
                        // Draw entire area in a gradient color effect
                        cache.entireBrush = new LinearGradientBrush(gradientRect, CommonHelper.WhitenColor(color1, 0.92f, 0.92f, 0.92f), color1, AngleFromOrientation(orientation))
                        {
                            Blend = _rounded1Blend
                        };
                    }

                    RectangleF ellipseRect;
                    PointF     ellipseCenter;
                    int        ellipseHeight = Math.Max(1, drawRect.Height / 4);
                    int        ellipseWidth  = Math.Max(1, (tracking ? drawRect.Width : drawRect.Width / 4));

                    // Ellipse is based on the orientation
                    switch (orientation)
                    {
                    default:
                    case VisualOrientation.Top:
                        ellipseRect   = new RectangleF(drawRect.Left - ellipseWidth, drawRect.Bottom - ellipseHeight, drawRect.Width + (ellipseWidth * 2), ellipseHeight * 2);
                        ellipseCenter = new PointF(ellipseRect.Left + (ellipseRect.Width / 2), ellipseRect.Bottom);
                        break;

                    case VisualOrientation.Bottom:
                        ellipseRect   = new RectangleF(drawRect.Left - ellipseWidth, drawRect.Top - ellipseHeight, drawRect.Width + (ellipseWidth * 2), ellipseHeight * 2);
                        ellipseCenter = new PointF(ellipseRect.Left + (ellipseRect.Width / 2), ellipseRect.Top);
                        break;

                    case VisualOrientation.Left:
                        ellipseRect   = new RectangleF(drawRect.Right - ellipseWidth, drawRect.Top - ellipseHeight, ellipseWidth * 2, drawRect.Height + (ellipseHeight * 2));
                        ellipseCenter = new PointF(ellipseRect.Right, ellipseRect.Top + (ellipseRect.Height / 2));
                        break;

                    case VisualOrientation.Right:
                        ellipseRect   = new RectangleF(drawRect.Left - ellipseWidth, drawRect.Top - ellipseHeight, ellipseWidth * 2, drawRect.Height + (ellipseHeight * 2));
                        ellipseCenter = new PointF(ellipseRect.Left, ellipseRect.Top + (ellipseRect.Height / 2));
                        break;
                    }

                    cache.ellipsePath = new GraphicsPath();
                    cache.ellipsePath.AddEllipse(ellipseRect);
                    cache.insideLighten = new PathGradientBrush(cache.ellipsePath)
                    {
                        CenterPoint    = ellipseCenter,
                        CenterColor    = color2,
                        Blend          = _rounded2Blend,
                        SurroundColors = new Color[] { Color.Transparent }
                    };
                }

                if (cache.entireBrush != null)
                {
                    using (Clipping clip = new Clipping(g, cache.clipPath))
                    {
                        g.FillRectangle(cache.entireBrush, cache.drawRect);
                        g.FillPath(cache.insideLighten, cache.ellipsePath);
                    }
                }
            }

            return(memento);
        }
예제 #14
0
        private void DrawBackRounded4(RenderContext context,
                                      Rectangle rect,
                                      Rectangle gradientRect,
                                      Color backColor1,
                                      Color backColor2,
                                      PaletteColorStyle backColorStyle,
                                      float backColorAngle,
                                      VisualOrientation orientation,
                                      GraphicsPath path)
        {
            using (Clipping clip = new Clipping(context.Graphics, path))
            {
                // Use standard helper routine to create appropriate color brush
                using (Brush backBrush = CreateColorBrush(gradientRect, backColor1, backColor2,
                                                          backColorStyle, backColorAngle, orientation))
                {
                    context.Graphics.FillPath(backBrush, path);
                }

                using (Pen linePen = new Pen(backColor1))
                {
                    // Adjust angle for the orientation
                    switch (orientation)
                    {
                        case VisualOrientation.Left:
                            context.Graphics.DrawLine(linePen, rect.Right - 1, rect.Top, rect.Right - 1, rect.Bottom - 1);
                            break;
                        case VisualOrientation.Right:
                            context.Graphics.DrawLine(linePen, rect.Left, rect.Top, rect.Left, rect.Bottom - 1);
                            break;
                        case VisualOrientation.Bottom:
                            context.Graphics.DrawLine(linePen, rect.Left, rect.Top, rect.Right - 1, rect.Top);
                            break;
                        case VisualOrientation.Top:
                            context.Graphics.DrawLine(linePen, rect.Left, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
                            break;
                    }
                }
            }
        }
예제 #15
0
        private void RenderBorder(RenderContext context, Rectangle rect)
        {
            Debug.Assert(context != null);

            // Do we need to draw the border?
            if (_paletteBorder.GetBorderDraw(State) == InheritBool.True)
            {
                if (Splitter)
                {
                    bool mouseInSplit = MouseInSplit;
                    switch (State)
                    {
                        case PaletteState.Tracking:
                            DrawBorder(context, rect, _paletteBorder, PaletteState.Tracking);
                            break;
                        case PaletteState.Pressed:
                            DrawBorder(context, rect, _paletteBorder, PaletteState.Tracking);

                            using (Clipping clipToSplitter = new Clipping(context.Graphics, (mouseInSplit ? _splitRectangle : _nonSplitRectangle)))
                                DrawBorder(context, rect, _paletteBorder, PaletteState.Pressed);
                            break;
                        default:
                            DrawBorder(context, rect, _paletteBorder, State);
                            break;
                    }
                }
                else
                    DrawBorder(context, rect, _paletteBorder, State);
            }
        }
예제 #16
0
        private void DrawBackLinearShadow(RenderContext context,
                                          Rectangle rect,
                                          Rectangle gradientRect,
                                          Color backColor1,
                                          Color backColor2,
                                          PaletteColorStyle backColorStyle,
                                          float backColorAngle,
                                          VisualOrientation orientation,
                                          GraphicsPath path)
        {
            // Prevent drawing over that ourside edge
            using (Clipping clip = new Clipping(context.Graphics, rect))
            {
                // Use standard helper routine to create appropriate color brush
                using (Brush backBrush = CreateColorBrush(gradientRect, backColor1, backColor2,
                                                          PaletteColorStyle.Linear, backColorAngle,
                                                          orientation))
                {
                    context.Graphics.FillPath(backBrush, path);
                }

                // Use path gradient to give the outside of the area a shadow effect
                using (PathGradientBrush borderBrush = new PathGradientBrush(path))
                {
                    borderBrush.Blend = _linearShadowBlend;
                    borderBrush.CenterColor = backColor1;
                    borderBrush.SurroundColors = new Color[] { backColor2 };
                    context.Graphics.FillPath(borderBrush, path);
                }
            }
        }
예제 #17
0
        private void DrawBackOneNote(RenderContext context,
                                     Rectangle gradientRect,
                                     Color backColor1,
                                     Color backColor2,
                                     PaletteColorStyle backColorStyle,
                                     float backColorAngle,
                                     VisualOrientation orientation,
                                     GraphicsPath path)
        {
            // Draw entire background in first color
            using (Brush backBrush = CreateColorBrush(gradientRect,
                                                      backColor1,
                                                      backColor1,
                                                      backColorStyle,
                                                      backColorAngle,
                                                      orientation))
            {
                context.Graphics.FillPath(backBrush, path);
            }

            // Make a copy of the original path, so we can change it
            GraphicsPath insetPath = (GraphicsPath)path.Clone();

            // Offset by 1.5 pixels so the background shows around two of
            // the edges of the background we are about to draw
            switch (orientation)
            {
                case VisualOrientation.Top:
                    insetPath.Transform(new Matrix(1, 0, 0, 1, 1.5f, 1.5f));
                    break;
                case VisualOrientation.Bottom:
                case VisualOrientation.Left:
                    insetPath.Transform(new Matrix(1, 0, 0, 1, 1.5f, -1.5f));
                    break;
                case VisualOrientation.Right:
                    insetPath.Transform(new Matrix(1, 0, 0, 1, -1.5f, 1.5f));
                    break;
            }

            using (Clipping clip = new Clipping(context.Graphics, path))
            {
                // Draw the second color as the offset background
                using (Brush backBrush = CreateColorBrush(gradientRect,
                                                          backColor2,
                                                          backColor2,
                                                          backColorStyle,
                                                          backColorAngle,
                                                          orientation))
                {
                    context.Graphics.FillPath(backBrush, insetPath);
                }
            }

            // Dispose of created resources
            insetPath.Dispose();
        }
예제 #18
0
        private static IDisposable DrawBackGlassCheckedPercent(RenderContext context,
                                                               Rectangle rect,
                                                               Color backColor1,
                                                               Color backColor2,
                                                               VisualOrientation orientation,
                                                               GraphicsPath path,
                                                               float glassPercent,
                                                               IDisposable memento)
        {
            using (Clipping clip = new Clipping(context.Graphics, path))
            {
                MementoTriple cache;

                if ((memento == null) || !(memento is MementoTriple))
                {
                    if (memento != null)
                        memento.Dispose();

                    cache = new MementoTriple();
                    memento = cache;
                }
                else
                {
                    cache = (MementoTriple)memento;
                }

                // Draw the one pixel border around the area
                cache.first = DrawBackLinearRadial(rect, false,
                                                   ControlPaint.Light(backColor1),
                                                   ControlPaint.LightLight(backColor1),
                                                   ControlPaint.LightLight(backColor1),
                                                   orientation, context.Graphics,
                                                   cache.first);

                // Reduce size on all but the upper edge
                ModifyRectByEdges(ref rect, 1, 0, 1, 1, orientation);

                // Draw the inside areas as a glass effect
                cache.second = DrawBackGlassRadial(rect, backColor1, backColor2,
                                                   _glassColorTopL, _glassColorBottomL,
                                                   6f, 1.2f, orientation, context.Graphics,
                                                   glassPercent, cache.second);

                // Widen back to original
                ModifyRectByEdges(ref rect, -1, 0, -1, 0, orientation);

                // Draw a darker area for top edge
                cache.third = DrawBackDarkEdge(rect, ControlPaint.Dark(backColor1),
                                               3, orientation, context.Graphics,
                                               cache.third);
            }

            return memento;
        }
예제 #19
0
        private static IDisposable DrawBackGlassTrackingPercent(RenderContext context,
                                                                Rectangle rect,
                                                                Color backColor1,
                                                                Color backColor2,
                                                                VisualOrientation orientation,
                                                                GraphicsPath path,
                                                                float glassPercent,
                                                                IDisposable memento)
        {
            using (Clipping clip = new Clipping(context.Graphics, path))
            {
                MementoDouble cache;

                if ((memento == null) || !(memento is MementoDouble))
                {
                    if (memento != null)
                        memento.Dispose();

                    cache = new MementoDouble();
                    memento = cache;
                }
                else
                    cache = (MementoDouble)memento;

                // Draw the one pixel border around the area
                cache.first = DrawBackLinearRadial(rect, false,
                                                   ControlPaint.LightLight(backColor2),
                                                   ControlPaint.Light(backColor2),
                                                   ControlPaint.LightLight(backColor2),
                                                   orientation, context.Graphics,
                                                   cache.first);

                // Reduce size of the inside area
                rect.Inflate(-1, -1);

                // Draw the inside area as a glass effect
                cache.second = DrawBackGlassRadial(rect, backColor1, backColor2,
                                                   _glassColorTopL, _glassColorBottomL,
                                                   2f, 1f, orientation, context.Graphics,
                                                   glassPercent, cache.second);
            }

            return memento;
        }
예제 #20
0
 /// <summary>
 /// Draw a background in tracking simple glass effect.
 /// </summary>
 /// <param name="context">Rendering context.</param>
 /// <param name="rect">Rectangle to draw.</param>
 /// <param name="backColor1">First color.</param>
 /// <param name="backColor2">Second color.</param>
 /// <param name="orientation">Drawing orientation.</param>
 /// <param name="path">Clipping path.</param>
 /// <param name="memento">Cache used for drawing.</param>
 public static IDisposable DrawBackGlassTrackingSimple(RenderContext context,
                                                       Rectangle rect,
                                                       Color backColor1,
                                                       Color backColor2,
                                                       VisualOrientation orientation,
                                                       GraphicsPath path,
                                                       IDisposable memento)
 {
     using (Clipping clip = new Clipping(context.Graphics, path))
     {
         // Draw the inside area as a glass effect
         return DrawBackGlassRadial(rect, backColor1, backColor2,
                                    _glassColorTopL, _glassColorBottomL,
                                    2f, 1f, orientation, context.Graphics,
                                    _fullGlassLength, memento);
     }
 }
예제 #21
0
        /// <summary>
        /// Draw border on the inside edge of the specified rectangle.
        /// </summary>
        /// <param name="context">Rendering context.</param>
        /// <param name="rect">Target rectangle.</param>
        /// <param name="palette">Palette used for drawing.</param>
        /// <param name="orientation">Visual orientation of the border.</param>
        /// <param name="state">State associated with rendering.</param>
        public override void DrawBorder(RenderContext context,
									    Rectangle rect,
									    IPaletteBorder palette,
										VisualOrientation orientation,
										PaletteState state)
        {
            Debug.Assert(context != null);
            Debug.Assert(palette != null);

            // Validate parameter references
            if (context == null) throw new ArgumentNullException("context");
            if (palette == null) throw new ArgumentNullException("palette");

            Debug.Assert(context.Control != null);
            Debug.Assert(!context.Control.IsDisposed);

            PaletteDrawBorders borders = palette.GetBorderDrawBorders(state);

            // Is there anything to actually draw?
            if ((rect.Width > 0) && (rect.Height > 0) && CommonHelper.HasABorder(borders))
            {
                // Only use anti aliasing if the border is rounded
                SmoothingMode smoothMode = (palette.GetBorderRounding(state) > 0 ? SmoothingMode.AntiAlias : SmoothingMode.Default);

                // We want to draw using anti aliasing for a nice smooth effect
                using (GraphicsHint hint = new GraphicsHint(context.Graphics, palette.GetBorderGraphicsHint(state)))
                {
                    // Cache commonly used values
                    int borderWidth = palette.GetBorderWidth(state);

                    // Get the orientation correct borders value
                    borders = CommonHelper.OrientateDrawBorders(borders, orientation);

                    // Is there any border to actually draw?
                    if (borderWidth > 0)
                    {
                        using (Clipping clip = new Clipping(context.Graphics, rect))
                        {
                            // We always create the first border path variant
                            GraphicsPath borderPath0 = CreateBorderBackPath(true, true, rect, borders, borderWidth,
                                                                            palette.GetBorderRounding(state),
                                                                            (smoothMode == SmoothingMode.AntiAlias), 0);

                            GraphicsPath borderPath1 = null;

                            // We only need the second border path if the two borders used are opposite each other
                            if ((borders == PaletteDrawBorders.TopBottom) ||
                                (borders == PaletteDrawBorders.LeftRight))
                            {
                                borderPath1 = CreateBorderBackPath(true, true, rect, borders, borderWidth,
                                                                   palette.GetBorderRounding(state),
                                                                   (smoothMode == SmoothingMode.AntiAlias), 1);
                            }

                            // Get the rectangle to use when dealing with gradients
                            Rectangle gradientRect = context.GetAlignedRectangle(palette.GetBorderColorAlign(state), rect);

                            // Use standard helper routine to create appropriate color brush
                            PaletteColorStyle colorStyle = palette.GetBorderColorStyle(state);
                            using (Pen borderPen = new Pen(CreateColorBrush(gradientRect,
                                                                            palette.GetBorderColor1(state),
                                                                            palette.GetBorderColor2(state),
                                                                            colorStyle,
                                                                            palette.GetBorderColorAngle(state),
                                                                            orientation), borderWidth))
                            {
                                if (colorStyle == PaletteColorStyle.Dashed)
                                    borderPen.DashPattern = new float[] { 2, 2 };

                                context.Graphics.DrawPath(borderPen, borderPath0);

                                // Optionally also draw the second path
                                if (borderPath1 != null)
                                    context.Graphics.DrawPath(borderPen, borderPath1);
                            }

                            Image borderImage = palette.GetBorderImage(state);
                            PaletteImageStyle borderImageStyle = palette.GetBorderImageStyle(state);

                            // Do we need to draw the image?
                            if (ShouldDrawImage(borderImage))
                            {
                                // Get the rectangle to use when dealing with gradients
                                Rectangle imageRect = context.GetAlignedRectangle(palette.GetBorderImageAlign(state), rect);

                                // Use standard helper routine to create appropriate image brush
                                using (Pen borderPen = new Pen(CreateImageBrush(imageRect, borderImage, borderImageStyle), borderWidth))
                                {
                                    context.Graphics.DrawPath(borderPen, borderPath0);

                                    // Optionally also draw the second path
                                    if (borderPath1 != null)
                                        context.Graphics.DrawPath(borderPen, borderPath1);
                                }
                            }

                            // Remember to dispose of resources
                            borderPath0.Dispose();

                            if (borderPath1 != null)
                                borderPath1.Dispose();
                        }
                    }
                }
            }
        }
예제 #22
0
        private void DrawBackRoundedTopLeftWhite(RenderContext context,
                                                 Rectangle rect,
                                                 Rectangle gradientRect,
                                                 Color backColor1,
                                                 Color backColor2,
                                                 PaletteColorStyle backColorStyle,
                                                 float backColorAngle,
                                                 VisualOrientation orientation,
                                                 GraphicsPath path)
        {
            using (Clipping clip = new Clipping(context.Graphics, path))
            {
                // Draw entire background in white
                context.Graphics.FillRectangle(Brushes.White, rect);

                // Offset the drawing rectangle for the top and left
                rect.X++;
                rect.Y++;

                // Size is smaller in both directions because of offseting
                rect.Width--;
                rect.Height--;

                // Draw the second color as the offset background
                using (Brush backBrush = CreateColorBrush(gradientRect,
                                                          backColor1,
                                                          backColor2,
                                                          PaletteColorStyle.Rounded,
                                                          backColorAngle,
                                                          orientation))
                {
                    context.Graphics.FillRectangle(backBrush, rect);
                }
            }
        }
예제 #23
0
        private void RenderBackground(RenderContext context, Rectangle rect)
        {
            // Do we need to draw the background?
            if (_drawCanvas && (_paletteBack.GetBackDraw(State) == InheritBool.True))
            {
                if (Splitter)
                {
                    bool mouseInSplit = MouseInSplit;
                    switch (State)
                    {
                        case PaletteState.Tracking:
                            using (Clipping clipToSplitter = new Clipping(context.Graphics, _nonSplitRectangle))
                            {
                                if (SplitWithFading)
                                    DrawBackground(context, rect, (mouseInSplit ? _paletteBackLight : _paletteBack), _paletteBorder, PaletteState.Tracking);
                                else
                                    DrawBackground(context, rect, (mouseInSplit ? _paletteBackDraw : _paletteBack), _paletteBorder, (mouseInSplit ? PaletteState.Normal : PaletteState.Tracking));
                            }

                            using (Clipping clipToSplitter = new Clipping(context.Graphics, _splitRectangle))
                            {
                                if (SplitWithFading)
                                    DrawBackground(context, rect, (mouseInSplit ? _paletteBack : _paletteBackLight), _paletteBorder, PaletteState.Tracking);
                                else
                                    DrawBackground(context, rect, (mouseInSplit ? _paletteBack : _paletteBackDraw), _paletteBorder, (mouseInSplit ? PaletteState.Tracking : PaletteState.Normal));
                            }
                            break;
                        case PaletteState.Pressed:
                            using (Clipping clipToSplitter = new Clipping(context.Graphics, _splitRectangle))
                            {
                                if (SplitWithFading)
                                    DrawBackground(context, rect, (mouseInSplit ? _paletteBack : _paletteBackLight),
                                                   _paletteBorder, (mouseInSplit ? PaletteState.Pressed : PaletteState.Tracking));
                                else
                                    DrawBackground(context, rect, (mouseInSplit ? _paletteBack : _paletteBackDraw),
                                                   _paletteBorder, (mouseInSplit ? PaletteState.Pressed : PaletteState.Normal));
                            }

                            using (Clipping clipToSplitter = new Clipping(context.Graphics, _nonSplitRectangle))
                            {
                                if (SplitWithFading)
                                    DrawBackground(context, rect, (mouseInSplit ? _paletteBackLight : _paletteBack),
                                                  _paletteBorder, (mouseInSplit ? PaletteState.Tracking : PaletteState.Pressed));
                                else
                                    DrawBackground(context, rect, (mouseInSplit ? _paletteBackDraw : _paletteBack),
                                                   _paletteBorder, (mouseInSplit ? PaletteState.Normal : PaletteState.Pressed));
                            }
                            break;
                        default:
                            DrawBackground(context, rect, _paletteBack, _paletteBorder, State);
                            break;
                    }
                }
                else
                    DrawBackground(context, rect, _paletteBack, _paletteBorder, State);
            }
        }
예제 #24
0
        private void DrawBackRoundedTopLight(RenderContext context,
                                             Rectangle rect,
                                             Rectangle gradientRect,
                                             Color backColor1,
                                             Color backColor2,
                                             PaletteColorStyle backColorStyle,
                                             float backColorAngle,
                                             VisualOrientation orientation,
                                             GraphicsPath path)
        {
            using (Clipping clip = new Clipping(context.Graphics, path))
            {
                // Draw entire background in white
                using(SolidBrush lightBrush = new SolidBrush(ControlPaint.LightLight(backColor1)))
                    context.Graphics.FillRectangle(lightBrush, rect);

                // Offset the drawing rectangle depending on the orientation
                switch (orientation)
                {
                    case VisualOrientation.Top:
                        rect.Y++;
                        rect.Height--;
                        break;
                    case VisualOrientation.Bottom:
                        rect.Height--;
                        break;
                    case VisualOrientation.Left:
                        rect.X++;
                        rect.Width--;
                        break;
                    case VisualOrientation.Right:
                        rect.Width--;
                        break;
                }

                // Draw the second color as the offset background
                using (Brush backBrush = CreateColorBrush(gradientRect,
                                                          backColor1,
                                                          backColor2,
                                                          PaletteColorStyle.Rounded,
                                                          backColorAngle,
                                                          orientation))
                {
                    context.Graphics.FillRectangle(backBrush, rect);
                }
            }
        }
예제 #25
0
        /// <summary>
        /// Raises the RenderToolStripBorder event. 
        /// </summary>
        /// <param name="e">An ToolStripRenderEventArgs containing the event data.</param>
        protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
        {
            if ((e.ToolStrip is ContextMenuStrip) ||
                (e.ToolStrip is ToolStripDropDownMenu))
            {
                // If there is a connected area to be drawn
                if (!e.ConnectedArea.IsEmpty)
                    using (SolidBrush excludeBrush = new SolidBrush(KCT.ToolStripDropDownBackground))
                        e.Graphics.FillRectangle(excludeBrush, e.ConnectedArea);

                // Create border and clipping paths
                using (GraphicsPath borderPath = CreateBorderPath(e.AffectedBounds, e.ConnectedArea, _cutContextMenu),
                                    insidePath = CreateInsideBorderPath(e.AffectedBounds, e.ConnectedArea, _cutContextMenu),
                                      clipPath = CreateClipBorderPath(e.AffectedBounds, e.ConnectedArea, _cutContextMenu))
                {
                    // Create the different pen colors we need
                    using (Pen borderPen = new Pen(KCT.MenuBorder),
                               insidePen = new Pen(KCT.ToolStripDropDownBackground))
                    {
                        // Clip all drawing to within the border path
                        using (Clipping clipping = new Clipping(e.Graphics, clipPath))
                        {
                            // Drawing with anti aliasing to create smoother appearance
                            using (AntiAlias aa = new AntiAlias(e.Graphics))
                            {
                                // Draw the inside area first
                                e.Graphics.DrawPath(insidePen, insidePath);

                                // Draw the border area second, so any overlapping gives it priority
                                e.Graphics.DrawPath(borderPen, borderPath);
                            }

                            // Draw the pixel at the bottom right of the context menu
                            e.Graphics.DrawLine(borderPen, e.AffectedBounds.Right, e.AffectedBounds.Bottom,
                                                           e.AffectedBounds.Right - 1, e.AffectedBounds.Bottom - 1);
                        }
                    }
                }
            }
            else if (!(e.ToolStrip is StatusStrip))
            {
                base.OnRenderToolStripBorder(e);
            }
        }
        /// <summary>
        /// Draw a background for an expert style button that is checked and tracking.
        /// </summary>
        /// <param name="context">Rendering context.</param>
        /// <param name="rect">Rectangle to draw.</param>
        /// <param name="backColor1">First color.</param>
        /// <param name="backColor2">Second color.</param>
        /// <param name="orientation">Drawing orientation.</param>
        /// <param name="path">Clipping path.</param>
        /// <param name="memento">Cache used for drawing.</param>
        public static IDisposable DrawBackExpertCheckedTracking(RenderContext context,
                                                                Rectangle rect,
                                                                Color backColor1,
                                                                Color backColor2,
                                                                VisualOrientation orientation,
                                                                GraphicsPath path,
                                                                IDisposable memento)
        {
            using (Clipping clip = new Clipping(context.Graphics, path))
            {
                MementoDouble cache;

                if ((memento == null) || !(memento is MementoDouble))
                {
                    if (memento != null)
                        memento.Dispose();

                    cache = new MementoDouble();
                    memento = cache;
                }
                else
                    cache = (MementoDouble)memento;

                cache.first = DrawBackExpert(rect,
                                             CommonHelper.MergeColors(backColor1, 0.5f, Color.White, 0.5f),
                                             CommonHelper.MergeColors(backColor2, 0.5f, Color.White, 0.5f),
                                             orientation, context.Graphics, memento, true, false);

                cache.second = DrawBackExpert(rect, backColor1, backColor2, orientation, context.Graphics, memento, false, false);

                return cache;
            }
        }
        /// <summary>
        /// Draw a background for an expert style button has a square inside with highlight.
        /// </summary>
        /// <param name="context">Rendering context.</param>
        /// <param name="rect">Rectangle to draw.</param>
        /// <param name="backColor1">First color.</param>
        /// <param name="backColor2">Second color.</param>
        /// <param name="orientation">Drawing orientation.</param>
        /// <param name="path">Clipping path.</param>
        /// <param name="memento">Cache used for drawing.</param>
        /// <param name="light">Use the 'light' variation.</param>
        public static IDisposable DrawBackExpertSquareHighlight(RenderContext context,
                                                                Rectangle rect,
                                                                Color backColor1,
                                                                Color backColor2,
                                                                VisualOrientation orientation,
                                                                GraphicsPath path,
                                                                IDisposable memento,
                                                                bool light)
        {
            using (Clipping clip = new Clipping(context.Graphics, path))
            {
                // Cannot draw a zero length rectangle
                if ((rect.Width > 0) && (rect.Height > 0))
                {
                    bool generate = true;
                    MementoBackExpertSquareHighlight cache;

                    // Access a cache instance and decide if cache resources need generating
                    if (!(memento is MementoBackExpertSquareHighlight))
                    {
                        memento?.Dispose();

                        cache   = new MementoBackExpertSquareHighlight(rect, backColor1, backColor2, orientation);
                        memento = cache;
                    }
                    else
                    {
                        cache    = (MementoBackExpertSquareHighlight)memento;
                        generate = !cache.UseCachedValues(rect, backColor1, backColor2, orientation);
                    }

                    // Do we need to generate the contents of the cache?
                    if (generate)
                    {
                        // Dispose of existing values
                        cache.Dispose();

                        cache.backBrush = new SolidBrush(CommonHelper.WhitenColor(backColor1, 0.8f, 0.8f, 0.8f));
                        cache.innerRect = new Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height - 2);

                        RectangleF ellipseRect;
                        PointF     ellipseCenter;
                        int        ellipseWidth  = Math.Max(1, rect.Width / 8);
                        int        ellipseHeight = Math.Max(1, rect.Height / 8);

                        switch (orientation)
                        {
                        default:
                        case VisualOrientation.Top:
                            cache.innerBrush = new LinearGradientBrush(cache.innerRect, backColor1, backColor2, 90f);
                            ellipseRect      = new RectangleF(rect.Left, rect.Top + (ellipseHeight * 2), rect.Width, ellipseHeight * 12);
                            ellipseCenter    = new PointF(ellipseRect.Left + (ellipseRect.Width / 2), ellipseRect.Bottom);
                            break;

                        case VisualOrientation.Bottom:
                            cache.innerBrush = new LinearGradientBrush(cache.innerRect, backColor1, backColor2, 270f);
                            ellipseRect      = new RectangleF(rect.Left, rect.Top - (ellipseHeight * 6), rect.Width, ellipseHeight * 12);
                            ellipseCenter    = new PointF(ellipseRect.Left + (ellipseRect.Width / 2), ellipseRect.Top);
                            break;

                        case VisualOrientation.Left:
                            cache.innerBrush = new LinearGradientBrush(cache.innerRect, backColor1, backColor2, 180f);
                            ellipseRect      = new RectangleF(rect.Left + (ellipseHeight * 2), rect.Top, ellipseWidth * 12, rect.Height);
                            ellipseCenter    = new PointF(ellipseRect.Right, ellipseRect.Top + (ellipseRect.Height / 2));
                            break;

                        case VisualOrientation.Right:
                            cache.innerBrush = new LinearGradientBrush(rect, backColor1, backColor2, 0f);
                            ellipseRect      = new RectangleF(rect.Left - (ellipseHeight * 6), rect.Top, ellipseWidth * 12, rect.Height);
                            ellipseCenter    = new PointF(ellipseRect.Left, ellipseRect.Top + (ellipseRect.Height / 2));
                            break;
                        }

                        cache.innerBrush.SetSigmaBellShape(0.5f);
                        cache.ellipsePath = new GraphicsPath();
                        cache.ellipsePath.AddEllipse(ellipseRect);
                        cache.insideLighten = new PathGradientBrush(cache.ellipsePath)
                        {
                            CenterPoint    = ellipseCenter,
                            CenterColor    = (light ? Color.FromArgb(64, Color.White) : Color.FromArgb(128, Color.White)),
                            Blend          = _rounded2Blend,
                            SurroundColors = new Color[] { Color.Transparent }
                        };
                    }

                    context.Graphics.FillRectangle(cache.backBrush, rect);
                    context.Graphics.FillRectangle(cache.innerBrush, cache.innerRect);
                    context.Graphics.FillRectangle(cache.insideLighten, cache.innerRect);
                }

                return(memento);
            }
        }
예제 #28
0
        private static IDisposable DrawBackGlassSimplePercent(RenderContext context,
                                                              Rectangle rect,
                                                              Color backColor1,
                                                              Color backColor2,
                                                              VisualOrientation orientation,
                                                              GraphicsPath path,
                                                              float glassPercent,
                                                              IDisposable memento)
        {
            using (Clipping clip = new Clipping(context.Graphics, path))
            {
                MementoDouble cache;

                if ((memento == null) || !(memento is MementoDouble))
                {
                    if (memento != null)
                        memento.Dispose();

                    cache = new MementoDouble();
                    memento = cache;
                }
                else
                    cache = (MementoDouble)memento;

                // Get the drawing rectangle for the path
                RectangleF drawRect = new RectangleF(rect.X, rect.Y, rect.Width, rect.Height);

                // Draw the border as a lighter version of the inside
                cache.first = DrawBackGlassLinear(drawRect, drawRect,
                                                  backColor2,
                                                  backColor2,
                                                  _glassColorBottomDD,
                                                  _glassColorBottomDD,
                                                  orientation,
                                                  context.Graphics,
                                                  0,
                                                  cache.first);

                // Reduce by 1 pixel on all edges to get the inside
                RectangleF insetRect = drawRect;
                insetRect.Inflate(-1f, -1f);

                // Draw the inside area
                cache.second = DrawBackGlassLinear(insetRect, drawRect,
                                                   backColor1,
                                                   CommonHelper.MergeColors(backColor1, 0.5f, backColor2, 0.5f),
                                                   _glassColorTopDD,
                                                   _glassColorBottomDD,
                                                   orientation,
                                                   context.Graphics,
                                                   glassPercent,
                                                   cache.second);
            }

            return memento;
        }
예제 #29
0
        private void DrawContextMenuHeader(Graphics g, ToolStripItem item)
        {
            // Get the rectangle that is the items area
            Rectangle itemRect = new Rectangle(Point.Empty, item.Bounds.Size);

            // Create border and clipping paths
            using (GraphicsPath borderPath = CreateBorderPath(itemRect, _cutToolItemMenu),
                                insidePath = CreateInsideBorderPath(itemRect, _cutToolItemMenu),
                                  clipPath = CreateClipBorderPath(itemRect, _cutToolItemMenu))
            {
                // Clip all drawing to within the border path
                using (Clipping clipping = new Clipping(g, clipPath))
                {
                    // Draw the entire background area first
                    using (SolidBrush backBrush = new SolidBrush(KCT.ToolStripDropDownBackground))
                        g.FillPath(backBrush, borderPath);

                    // Draw the border
                    using (Pen borderPen = new Pen(KCT.MenuBorder))
                        g.DrawPath(borderPen, borderPath);
                }
            }
        }
        /// <summary>
        /// Raises the RenderToolStripBackground event. 
        /// </summary>
        /// <param name="e">An ToolStripRenderEventArgs containing the event data.</param>
        protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
        {
            if ((e.ToolStrip is ContextMenuStrip) ||
                (e.ToolStrip is ToolStripDropDownMenu))
            {
                // Make sure the font is current
                if (e.ToolStrip.Font != KCT.MenuStripFont)
                    e.ToolStrip.Font = KCT.MenuStripFont;

                // Create border and clipping paths
                using (GraphicsPath borderPath = CreateBorderPath(e.AffectedBounds, _cutContextMenu),
                                      clipPath = CreateClipBorderPath(e.AffectedBounds, _cutContextMenu))
                {
                    // Clip all drawing to within the border path
                    using (Clipping clipping = new Clipping(e.Graphics, clipPath))
                    {
                        // Create the background brush
                        using (SolidBrush backBrush = new SolidBrush(KCT.ToolStripDropDownBackground))
                            e.Graphics.FillPath(backBrush, borderPath);
                    }
                }
            }
            else if (e.ToolStrip is StatusStrip)
            {
                // Make sure the font is current
                if (e.ToolStrip.Font != KCT.StatusStripFont)
                    e.ToolStrip.Font = KCT.StatusStripFont;

                // We do not paint the top two pixel lines, as they are drawn by the status strip border render method
                RectangleF backRect = new RectangleF(0, 1.5f, e.ToolStrip.Width, e.ToolStrip.Height - 2);

                // Cannot paint a zero sized area
                if ((backRect.Width > 0) && (backRect.Height > 0))
                {
                    //using (LinearGradientBrush backBrush = new LinearGradientBrush(backRect,
                    //                                                               KCT.StatusStripGradientBegin,
                    //                                                               KCT.StatusStripGradientEnd,
                    //                                                               90f))
                    //{
                    //    backBrush.Blend = _stripBlend;
                    //    e.Graphics.FillRectangle(backBrush, backRect);
                    //}
                    using (SolidBrush backBrush = new SolidBrush(KCT.StatusStripGradientEnd))
                    {
                        e.Graphics.FillRectangle(backBrush, backRect);
                    }
                }
            }
            else
            {
                // Make sure the font is current
                if (e.ToolStrip is MenuStrip)
                {
                    if (e.ToolStrip.Font != KCT.MenuStripFont)
                        e.ToolStrip.Font = KCT.MenuStripFont;

                    base.OnRenderToolStripBackground(e);
                }
                else
                {
                    if (e.ToolStrip.Font != KCT.ToolStripFont)
                        e.ToolStrip.Font = KCT.ToolStripFont;

                    // Cannot paint a zero sized area
                    RectangleF backRect = new RectangleF(0, 0, e.ToolStrip.Width, e.ToolStrip.Height);
                    if ((backRect.Width > 0) && (backRect.Height > 0))
                    {
                        if (e.ToolStrip.Orientation == Orientation.Horizontal)
                        {
                            using (LinearGradientBrush backBrush = new LinearGradientBrush(backRect,
                                                                                           KCT.ToolStripGradientBegin,
                                                                                           KCT.ToolStripGradientEnd,
                                                                                           90f))
                            {
                                backBrush.Blend = _stripBlend;
                                e.Graphics.FillRectangle(backBrush, backRect);
                            }

                            using (Pen darkBorder = new Pen(KCT.ToolStripBorder),
                                       lightBorder = new Pen(KCT.ToolStripGradientBegin))
                            {
                                e.Graphics.DrawLine(lightBorder, 0, 2, 0, e.ToolStrip.Height - 2);
                                e.Graphics.DrawLine(lightBorder, e.ToolStrip.Width - 2, 0, e.ToolStrip.Width - 2, e.ToolStrip.Height - 2);
                                e.Graphics.DrawLine(darkBorder, e.ToolStrip.Width - 1, 0, e.ToolStrip.Width - 1, e.ToolStrip.Height - 1);
                            }
                        }
                        else
                        {
                            using (LinearGradientBrush backBrush = new LinearGradientBrush(backRect,
                                                                                           KCT.ToolStripGradientBegin,
                                                                                           KCT.ToolStripGradientEnd,
                                                                                           0f))
                            {
                                backBrush.Blend = _stripBlend;
                                e.Graphics.FillRectangle(backBrush, backRect);
                            }

                            using (Pen darkBorder = new Pen(KCT.ToolStripBorder),
                                       lightBorder = new Pen(KCT.ToolStripGradientBegin))
                            {
                                e.Graphics.DrawLine(lightBorder, 1, 0, e.ToolStrip.Width - 2, 0);
                                e.Graphics.DrawLine(lightBorder, 1, e.ToolStrip.Height - 2, e.ToolStrip.Width - 2, e.ToolStrip.Height - 2);
                                e.Graphics.DrawLine(darkBorder, e.ToolStrip.Width - 1, 0, e.ToolStrip.Width - 1, e.ToolStrip.Height - 1);
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Draw a background for an expert style button has a square inside with highlight.
        /// </summary>
        /// <param name="context">Rendering context.</param>
        /// <param name="rect">Rectangle to draw.</param>
        /// <param name="backColor1">First color.</param>
        /// <param name="backColor2">Second color.</param>
        /// <param name="orientation">Drawing orientation.</param>
        /// <param name="path">Clipping path.</param>
        /// <param name="memento">Cache used for drawing.</param>
        /// <param name="light">Use the 'light' variation.</param>
        public static IDisposable DrawBackExpertSquareHighlight(RenderContext context,
                                                                Rectangle rect,
                                                                Color backColor1,
                                                                Color backColor2,
                                                                VisualOrientation orientation,
                                                                GraphicsPath path,
                                                                IDisposable memento,
                                                                bool light)
        {
            using (Clipping clip = new Clipping(context.Graphics, path))
            {
                // Cannot draw a zero length rectangle
                if ((rect.Width > 0) && (rect.Height > 0))
                {
                    bool generate = true;
                    MementoBackExpertSquareHighlight cache;

                    // Access a cache instance and decide if cache resources need generating
                    if ((memento == null) || !(memento is MementoBackExpertSquareHighlight))
                    {
                        if (memento != null)
                            memento.Dispose();

                        cache = new MementoBackExpertSquareHighlight(rect, backColor1, backColor2, orientation);
                        memento = cache;
                    }
                    else
                    {
                        cache = (MementoBackExpertSquareHighlight)memento;
                        generate = !cache.UseCachedValues(rect, backColor1, backColor2, orientation);
                    }

                    // Do we need to generate the contents of the cache?
                    if (generate)
                    {
                        // Dispose of existing values
                        cache.Dispose();

                        cache.backBrush = new SolidBrush(CommonHelper.WhitenColor(backColor1, 0.8f, 0.8f, 0.8f));
                        cache.innerRect = new Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height - 2);

                        RectangleF ellipseRect;
                        PointF ellipseCenter;
                        int ellipseWidth = Math.Max(1, rect.Width / 8);
                        int ellipseHeight = Math.Max(1, rect.Height / 8);

                        switch (orientation)
                        {
                            default:
                            case VisualOrientation.Top:
                                cache.innerBrush = new LinearGradientBrush(cache.innerRect, backColor1, backColor2, 90f);
                                ellipseRect = new RectangleF(rect.Left, rect.Top + (ellipseHeight * 2), rect.Width, ellipseHeight * 12);
                                ellipseCenter = new PointF(ellipseRect.Left + (ellipseRect.Width / 2), ellipseRect.Bottom);
                                break;
                            case VisualOrientation.Bottom:
                                cache.innerBrush = new LinearGradientBrush(cache.innerRect, backColor1, backColor2, 270f);
                                ellipseRect = new RectangleF(rect.Left, rect.Top - (ellipseHeight * 6), rect.Width, ellipseHeight * 12);
                                ellipseCenter = new PointF(ellipseRect.Left + (ellipseRect.Width / 2), ellipseRect.Top);
                                break;
                            case VisualOrientation.Left:
                                cache.innerBrush = new LinearGradientBrush(cache.innerRect, backColor1, backColor2, 180f);
                                ellipseRect = new RectangleF(rect.Left + (ellipseHeight * 2), rect.Top, ellipseWidth * 12, rect.Height);
                                ellipseCenter = new PointF(ellipseRect.Right, ellipseRect.Top + (ellipseRect.Height / 2));
                                break;
                            case VisualOrientation.Right:
                                cache.innerBrush = new LinearGradientBrush(rect, backColor1, backColor2, 0f);
                                ellipseRect = new RectangleF(rect.Left - (ellipseHeight * 6), rect.Top, ellipseWidth * 12, rect.Height);
                                ellipseCenter = new PointF(ellipseRect.Left, ellipseRect.Top + (ellipseRect.Height / 2));
                                break;
                        }

                        cache.innerBrush.SetSigmaBellShape(0.5f);
                        cache.ellipsePath = new GraphicsPath();
                        cache.ellipsePath.AddEllipse(ellipseRect);
                        cache.insideLighten = new PathGradientBrush(cache.ellipsePath);
                        cache.insideLighten.CenterPoint = ellipseCenter;
                        cache.insideLighten.CenterColor = (light ? Color.FromArgb(64, Color.White) : Color.FromArgb(128, Color.White));
                        cache.insideLighten.Blend = _rounded2Blend;
                        cache.insideLighten.SurroundColors = new Color[] { Color.Transparent };
                    }

                    context.Graphics.FillRectangle(cache.backBrush, rect);
                    context.Graphics.FillRectangle(cache.innerBrush, cache.innerRect);
                    context.Graphics.FillRectangle(cache.insideLighten, cache.innerRect);
                }

                return memento;
            }
        }
예제 #32
0
        /// <summary>
        /// Internal rendering method.
        /// </summary>
        protected virtual IDisposable DrawRibbonAppTab(PaletteRibbonShape shape,
                                                       RenderContext context,
                                                       Rectangle rect,
                                                       PaletteState state,
                                                       Color baseColor1,
                                                       Color baseColor2,
                                                       IDisposable memento)
        {
            if ((rect.Width > 0) && (rect.Height > 0))
            {
                bool generate = true;
                MementoRibbonAppTab cache;

                // Access a cache instance and decide if cache resources need generating
                if ((memento == null) || !(memento is MementoRibbonAppTab))
                {
                    if (memento != null)
                        memento.Dispose();

                    cache = new MementoRibbonAppTab(rect, baseColor1, baseColor2);
                    memento = cache;
                }
                else
                {
                    cache = (MementoRibbonAppTab)memento;
                    generate = !cache.UseCachedValues(rect, baseColor1, baseColor2);
                }

                // Do we need to generate the contents of the cache?
                if (generate)
                {
                    // Dispose of existing values
                    cache.Dispose();

                    // Create common paths to all the app tab states
                    cache.GeneratePaths(rect, state);
                    cache.borderPen = new Pen(baseColor1);

                    // Create state specific colors/brushes/pens
                    switch (state)
                    {
                        case PaletteState.Normal:
                            cache.borderBrush = new SolidBrush(CommonHelper.MergeColors(baseColor1, 0.2f, baseColor2, 0.8f));
                            cache.insideFillBrush = new LinearGradientBrush(new RectangleF(rect.X, rect.Y + 1, rect.Width, rect.Height),
                                                                            CommonHelper.MergeColors(baseColor1, 0.3f, baseColor2, 0.7f),
                                                                            CommonHelper.MergeColors(baseColor1, 0.6f, baseColor2, 0.4f),
                                                                            90f);

                            cache.insideFillBrush.SetSigmaBellShape(0.33f);
                            cache.highlightBrush.CenterColor = Color.FromArgb(64, Color.White);
                            break;
                        case PaletteState.Tracking:
                            cache.borderBrush = new SolidBrush(baseColor2);
                            cache.insideFillBrush = new LinearGradientBrush(new RectangleF(rect.X, rect.Y + 1, rect.Width, rect.Height),
                                                                            CommonHelper.MergeColors(baseColor1, 0.3f, baseColor2, 0.7f),
                                                                            CommonHelper.MergeColors(baseColor1, 0.6f, baseColor2, 0.4f),
                                                                            90f);

                            cache.insideFillBrush.SetSigmaBellShape(0.33f);
                            cache.highlightBrush.CenterColor = Color.FromArgb(100, Color.White);
                            break;
                        case PaletteState.Tracking | PaletteState.FocusOverride:
                            cache.borderBrush = new SolidBrush(ControlPaint.LightLight(baseColor2));
                            cache.insideFillBrush = new LinearGradientBrush(new RectangleF(rect.X, rect.Y + 1, rect.Width, rect.Height),
                                                                            CommonHelper.MergeColors(baseColor1, 0.3f, baseColor2, 0.7f),
                                                                            CommonHelper.MergeColors(baseColor1, 0.6f, baseColor2, 0.4f),
                                                                            90f);

                            cache.insideFillBrush.SetSigmaBellShape(0.33f);
                            cache.highlightBrush.CenterColor = ControlPaint.LightLight(baseColor2);
                            break;
                        case PaletteState.Pressed:
                            cache.borderBrush = new SolidBrush(CommonHelper.MergeColors(baseColor1, 0.5f, baseColor2, 0.5f));
                            cache.insideFillBrush = new LinearGradientBrush(new RectangleF(rect.X, rect.Y + 1, rect.Width, rect.Height),
                                                                            CommonHelper.MergeColors(baseColor1, 0.3f, baseColor2, 0.7f),
                                                                            CommonHelper.MergeColors(baseColor1, 0.75f, baseColor2, 0.25f),
                                                                            90f);

                            cache.insideFillBrush.SetSigmaBellShape(0f);
                            cache.highlightBrush.CenterColor = Color.FromArgb(90, Color.White);
                            break;
                    }
                }

                // Fill the entire tab area and then add a border around the edge
                context.Graphics.FillPath(cache.borderBrush, cache.borderFillPath);

                // Draw the outside border
                using (AntiAlias aa = new AntiAlias(context.Graphics))
                    context.Graphics.DrawPath(cache.borderPen, cache.borderPath);

                // Fill inside area
                context.Graphics.FillPath(cache.insideFillBrush, cache.insideFillPath);

                // Draw highlight over bottom half
                using(Clipping clip = new Clipping(context.Graphics, cache.insideFillPath))
                    context.Graphics.FillPath(cache.highlightBrush, cache.highlightPath);
            }

            return memento;
        }
예제 #33
0
        private void DrawBackRounding5(RenderContext context,
                                       Rectangle rect,
                                       Rectangle gradientRect,
                                       Color backColor1,
                                       Color backColor2,
                                       PaletteColorStyle backColorStyle,
                                       float backColorAngle,
                                       VisualOrientation orientation,
                                       GraphicsPath path)
        {
            // We want to ignore the ourside pixel edge, so inflate inwards
            rect.Inflate(-1, -1);

            // Prevent drawing over that ourside edge
            using (Clipping clip = new Clipping(context.Graphics, rect))
            {
                // Use standard helper routine to create appropriate color brush
                using (Brush backBrush = CreateColorBrush(gradientRect, backColor1, backColor2,
                                                          PaletteColorStyle.Rounding5, backColorAngle,
                                                          orientation))
                {
                    context.Graphics.FillPath(backBrush, path);
                }
            }
        }
예제 #34
0
        /// <summary>
        /// Draw a background in normal full glass effect but only over 50% of the background.
        /// </summary>
        /// <param name="context">Rendering context.</param>
        /// <param name="rect">Rectangle to draw.</param>
        /// <param name="backColor1">First color.</param>
        /// <param name="backColor2">Second color.</param>
        /// <param name="orientation">Drawing orientation.</param>
        /// <param name="path">Clipping path.</param>
        /// <param name="memento">Cache used for drawing.</param>
        public static IDisposable DrawBackGlassFade(RenderContext context,
                                                    Rectangle rect,
                                                    Color backColor1,
                                                    Color backColor2,
                                                    VisualOrientation orientation,
                                                    GraphicsPath path,
                                                    IDisposable memento)
        {
            using (Clipping clip = new Clipping(context.Graphics, path))
            {
                MementoDouble cache;

                if ((memento == null) || !(memento is MementoDouble))
                {
                    if (memento != null)
                        memento.Dispose();

                    cache = new MementoDouble();
                    memento = cache;
                }
                else
                    cache = (MementoDouble)memento;

                cache.first = DrawBackGlassFade(rect, rect,
                                                backColor1, backColor2,
                                                _glassColorTopL,
                                                _glassColorBottomL,
                                                orientation,
                                                context.Graphics,
                                                cache.first);

                cache.second = DrawBackDarkEdge(rect, ControlPaint.Dark(backColor1),
                                                3, orientation, context.Graphics,
                                                cache.second);
            }

            return memento;
        }
예제 #35
0
        private void RenderBackground(RenderContext context, Rectangle rect)
        {
            // Do we need to draw the background?
            if (_drawCanvas && (_paletteBack.GetBackDraw(State) == InheritBool.True))
            {
                if (Splitter)
                {
                    bool mouseInSplit = MouseInSplit;
                    switch (State)
                    {
                    case PaletteState.Tracking:
                        using (Clipping clipToSplitter = new Clipping(context.Graphics, _nonSplitRectangle))
                        {
                            if (SplitWithFading)
                            {
                                DrawBackground(context, rect, (mouseInSplit ? _paletteBackLight : _paletteBack), _paletteBorder, PaletteState.Tracking);
                            }
                            else
                            {
                                DrawBackground(context, rect, (mouseInSplit ? _paletteBackDraw : _paletteBack), _paletteBorder, (mouseInSplit ? PaletteState.Normal : PaletteState.Tracking));
                            }
                        }

                        using (Clipping clipToSplitter = new Clipping(context.Graphics, _splitRectangle))
                        {
                            if (SplitWithFading)
                            {
                                DrawBackground(context, rect, (mouseInSplit ? _paletteBack : _paletteBackLight), _paletteBorder, PaletteState.Tracking);
                            }
                            else
                            {
                                DrawBackground(context, rect, (mouseInSplit ? _paletteBack : _paletteBackDraw), _paletteBorder, (mouseInSplit ? PaletteState.Tracking : PaletteState.Normal));
                            }
                        }
                        break;

                    case PaletteState.Pressed:
                        using (Clipping clipToSplitter = new Clipping(context.Graphics, _splitRectangle))
                        {
                            if (SplitWithFading)
                            {
                                DrawBackground(context, rect, (mouseInSplit ? _paletteBack : _paletteBackLight),
                                               _paletteBorder, (mouseInSplit ? PaletteState.Pressed : PaletteState.Tracking));
                            }
                            else
                            {
                                DrawBackground(context, rect, (mouseInSplit ? _paletteBack : _paletteBackDraw),
                                               _paletteBorder, (mouseInSplit ? PaletteState.Pressed : PaletteState.Normal));
                            }
                        }

                        using (Clipping clipToSplitter = new Clipping(context.Graphics, _nonSplitRectangle))
                        {
                            if (SplitWithFading)
                            {
                                DrawBackground(context, rect, (mouseInSplit ? _paletteBackLight : _paletteBack),
                                               _paletteBorder, (mouseInSplit ? PaletteState.Tracking : PaletteState.Pressed));
                            }
                            else
                            {
                                DrawBackground(context, rect, (mouseInSplit ? _paletteBackDraw : _paletteBack),
                                               _paletteBorder, (mouseInSplit ? PaletteState.Normal : PaletteState.Pressed));
                            }
                        }
                        break;

                    default:
                        DrawBackground(context, rect, _paletteBack, _paletteBorder, State);
                        break;
                    }
                }
                else
                {
                    DrawBackground(context, rect, _paletteBack, _paletteBorder, State);
                }
            }
        }
예제 #36
0
        private void DrawBackSolidInside(RenderContext context,
                                         Rectangle gradientRect,
                                         Color backColor1,
                                         Color backColor2,
                                         GraphicsPath path)
        {
            // Clip to prevent drawing outside the path
            using(Clipping clip = new Clipping(context.Graphics, path))
            {
                // Get the rectangle that encloses the path
                RectangleF rectF = path.GetBounds();

                // Convert to a pixel aligned rectangle
                Rectangle rect;

                // Do we have any non-integeer numbers to convert
                if ((Math.Round(rectF.X) != rectF.X) ||
                    (Math.Round(rectF.Y) != rectF.Y) ||
                    (Math.Round(rectF.Width) != rectF.Width) ||
                    (Math.Round(rectF.Height) != rectF.Height))
                {
                    int x = (int)Math.Round(rectF.X);
                    int y = (int)Math.Round(rectF.Y);
                    int width = (int)Math.Round(rectF.Width + 1 + (rectF.X - x));
                    int height = (int)Math.Round(rectF.Height + 1 + (rectF.Y - y));
                    rect = new Rectangle(x, y, width, height);
                }
                else
                    rect = new Rectangle((int)rectF.X, (int)rectF.Y, (int)rectF.Width, (int)rectF.Height);

                using (Brush backBrush1 = CreateColorBrush(gradientRect, backColor1, backColor1, PaletteColorStyle.Solid, 0f, VisualOrientation.Top),
                             backBrush2 = CreateColorBrush(gradientRect, backColor2, backColor2, PaletteColorStyle.Solid, 0f, VisualOrientation.Top))
                {
                    // Draw the first color over the entire area
                    context.Graphics.FillRectangle(backBrush1, rect);

                    // Draw the second color on the inside of the area
                    rect.Inflate(-2, -2);
                    context.Graphics.FillRectangle(backBrush2, rect);

                    // Draw the first color inside the rest of the area
                    rect.Inflate(-1, -1);
                    context.Graphics.FillRectangle(backBrush1, rect);
                }
            }
        }
        private void DrawVerticalSplit(RenderContext context, PaletteState drawState)
        {
            // We need the rectangle that represents just the split area
            int partialHeight = (ClientHeight / 3 * 2);
            Rectangle partialRect = new Rectangle(ClientLocation, new Size(ClientWidth, partialHeight));
            Rectangle splitRectangle = _controller.SplitRectangle;
            Rectangle aboveSplitRect = new Rectangle(ClientLocation, new Size(ClientWidth, splitRectangle.Y - ClientLocation.Y));
            Rectangle splitterRect = new Rectangle(splitRectangle.Location, new Size(ClientWidth, 1));
            Rectangle belowSplitRect = new Rectangle(ClientLocation.X, splitRectangle.Y, ClientWidth, splitRectangle.Height);

            bool splitWithFading = SplitWithFading(drawState);
            switch (drawState)
            {
                case PaletteState.Normal:
                    // Draw the entire border around the button
                    if (_constantBorder)
                    {
                        DrawBackground(_paletteBack, context, ClientRectangle, PaletteState.Normal);
                        DrawBorder(_paletteBorder, context, ClientRectangle, PaletteState.Normal);
                    }
                    break;
                case PaletteState.Tracking:
                    // Draw the background for the click and split areas
                    if (_controller.MouseInSplit)
                    {
                        using (Clipping clipToSplitter = new Clipping(context.Graphics, belowSplitRect))
                            if (splitWithFading)
                            {
                                if (_drawNonTrackingAreas)
                                    DrawBackground(_paletteBackLight, context, ClientRectangle, PaletteState.Tracking);
                            }
                            else
                                DrawBackground(_paletteBackDraw, context, ClientRectangle, PaletteState.Normal);

                        Rectangle belowSplitRect1 = new Rectangle(belowSplitRect.X, belowSplitRect.Y + 1, belowSplitRect.Width, belowSplitRect.Height - 1);
                        using (Clipping clipToSplitter = new Clipping(context.Graphics, belowSplitRect1))
                            DrawBackground(_paletteBack, context, ClientRectangle, PaletteState.Tracking);

                        using (Clipping clipToSplitter = new Clipping(context.Graphics, aboveSplitRect))
                            if (splitWithFading)
                            {
                                if (_drawNonTrackingAreas)
                                    DrawBackground(_paletteBackLight, context, partialRect, PaletteState.Tracking);
                            }
                            else
                                DrawBackground(_paletteBackDraw, context, partialRect, PaletteState.Normal);
                    }
                    else
                    {
                        using (Clipping clipToSplitter = new Clipping(context.Graphics, aboveSplitRect))
                            DrawBackground(_paletteBack, context, partialRect, PaletteState.Tracking);

                        using (Clipping clipToSplitter = new Clipping(context.Graphics, belowSplitRect))
                            if (splitWithFading)
                            {
                                if (_drawNonTrackingAreas)
                                    DrawBackground(_paletteBackLight, context, ClientRectangle, PaletteState.Tracking);
                            }
                            else
                                DrawBackground(_paletteBackDraw, context, ClientRectangle, PaletteState.Normal);
                    }

                    // Draw the single pixel splitter line
                    using (Clipping clipToSplitter = new Clipping(context.Graphics, splitterRect))
                        DrawBorder(_paletteBorderAll, context, new Rectangle(splitRectangle.X, splitRectangle.Y, splitRectangle.Width, 2), PaletteState.Tracking);

                    // Draw the entire border around the button
                    DrawBorder(_paletteBorder, context, ClientRectangle, PaletteState.Tracking);
                    break;
                case PaletteState.Pressed:
                    // Draw the background for the click and split areas
                    if (_controller.MouseInSplit)
                    {
                        using (Clipping clipToSplitter = new Clipping(context.Graphics, belowSplitRect))
                            if (splitWithFading)
                            {
                                if (_drawNonTrackingAreas)
                                    DrawBackground(_paletteBackLight, context, ClientRectangle, PaletteState.Pressed);
                            }
                            else
                                DrawBackground(_paletteBackDraw, context, ClientRectangle, PaletteState.Normal);

                        Rectangle belowSplitRect1 = new Rectangle(belowSplitRect.X, belowSplitRect.Y + 1, belowSplitRect.Width, belowSplitRect.Height - 1);
                        using (Clipping clipToSplitter = new Clipping(context.Graphics, belowSplitRect1))
                            DrawBackground(_paletteBack, context, ClientRectangle, PaletteState.Pressed);

                        using (Clipping clipToSplitter = new Clipping(context.Graphics, aboveSplitRect))
                            if (splitWithFading)
                            {
                                if (_drawNonTrackingAreas)
                                    DrawBackground(_paletteBackLight, context, partialRect, PaletteState.Tracking);
                            }
                            else
                                DrawBackground(_paletteBackDraw, context, partialRect, PaletteState.Normal);
                    }
                    else
                    {
                        using (Clipping clipToSplitter = new Clipping(context.Graphics, aboveSplitRect))
                            DrawBackground(_paletteBack, context, partialRect, PaletteState.Pressed);

                        using (Clipping clipToSplitter = new Clipping(context.Graphics, belowSplitRect))
                            if (splitWithFading)
                            {
                                if (_drawNonTrackingAreas)
                                    DrawBackground(_paletteBackLight, context, ClientRectangle, PaletteState.Tracking);
                            }
                            else
                                DrawBackground(_paletteBackDraw, context, ClientRectangle, PaletteState.Normal);
                    }

                    // Draw the entire border around the button
                    DrawBorder(_paletteBorder, context, ClientRectangle, PaletteState.Tracking);

                    // Draw the single pixel splitter line
                    using (Clipping clipToSplitter = new Clipping(context.Graphics, splitterRect))
                        DrawBorder(_paletteBorderAll, context, new Rectangle(splitRectangle.X, splitRectangle.Y, splitRectangle.Width, 2), PaletteState.Pressed);

                    // Draw the border for the click and split areas
                    if (_controller.MouseInSplit)
                        using (Clipping clipToSplitter = new Clipping(context.Graphics, belowSplitRect))
                            DrawBorder(_paletteBorder, context, ClientRectangle, PaletteState.Pressed);
                    else
                        using (Clipping clipToSplitter = new Clipping(context.Graphics, aboveSplitRect))
                            DrawBorder(_paletteBorder, context, ClientRectangle, PaletteState.Pressed);
                    break;
                default:
                    // Should never happen
                    Debug.Assert(false);
                    break;
            }
        }
예제 #38
0
        private void DrawBackSolidLine(RenderContext context,
                                       Rectangle rect,
                                       Color backColor1,
                                       Color backColor2,
                                       PaletteColorStyle style,
                                       GraphicsPath path)
        {
            using (Clipping clip = new Clipping(context.Graphics, path))
            {
                // Draw entire background in second color
                using (SolidBrush brushColor2 = new SolidBrush(backColor2))
                    context.Graphics.FillRectangle(brushColor2, rect);

                // Reduce area by edge(s) we want to leave alone
                switch (style)
                {
                    case PaletteColorStyle.SolidTopLine:
                        rect.Y++;
                        rect.Height--;
                        break;
                    case PaletteColorStyle.SolidBottomLine:
                        rect.Height--;
                        break;
                    case PaletteColorStyle.SolidLeftLine:
                        rect.X++;
                        rect.Width--;
                        break;
                    case PaletteColorStyle.SolidRightLine:
                        rect.Width--;
                        break;
                    case PaletteColorStyle.SolidAllLine:
                        rect.X++;
                        rect.Y++;
                        rect.Width -= 2;
                        rect.Height -= 2;
                        break;
                }

                // Draw the second color as a solid block
                using (SolidBrush brushColor2 = new SolidBrush(backColor1))
                    context.Graphics.FillRectangle(brushColor2, rect);
            }
        }