/// <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(context.Graphics, path); MementoDouble cache; if (memento is MementoDouble mementoDouble) { cache = mementoDouble; } else { memento?.Dispose(); cache = new MementoDouble(); memento = cache; } 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 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 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; } }
private static IDisposable DrawBackGlassCenter(RectangleF drawRect, Color color1, Color color2, Color glassColor1, Color glassColor2, float factorX, float factorY, VisualOrientation orientation, Graphics g, float glassPercent, IDisposable memento) { // Cannot draw a path that contains a zero sized element if ((drawRect.Width > 0) && (drawRect.Height > 0)) { MementoDouble cache; if ((memento == null) || !(memento is MementoDouble)) { if (memento != null) memento.Dispose(); cache = new MementoDouble(); memento = cache; } else { cache = (MementoDouble)memento; } // Draw the gradient effect background DrawBackGlassBasic(drawRect, color1, color2, glassColor1, glassColor2, factorX, factorY, orientation, g, glassPercent, ref cache.first); bool generate = true; MementoBackGlassCenter cacheThis; // Access a cache instance and decide if cache resources need generating if ((cache.second == null) || !(cache.second is MementoBackGlassCenter)) { if (cache.second != null) cache.second.Dispose(); cacheThis = new MementoBackGlassCenter(drawRect, color2); cache.second = cacheThis; } else { cacheThis = (MementoBackGlassCenter)cache.second; generate = !cacheThis.UseCachedValues(drawRect, color2); } // Do we need to generate the contents of the cache? if (generate) { // Dispose of existing values cacheThis.Dispose(); cacheThis.path = new GraphicsPath(); cacheThis.path.AddEllipse(drawRect); cacheThis.bottomBrush = new PathGradientBrush(cacheThis.path); cacheThis.bottomBrush.CenterColor = color2; cacheThis.bottomBrush.CenterPoint = new PointF(drawRect.X + (drawRect.Width / 2), drawRect.Y + (drawRect.Height / 2)); cacheThis.bottomBrush.SurroundColors = new Color[] { Color.Transparent }; } g.FillRectangle(cacheThis.bottomBrush, drawRect); } return memento; }
/// <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; }
/// <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; }
private static IDisposable DrawBackLinearRadial(RectangleF drawRect, bool sigma, Color color1, Color color2, Color color3, VisualOrientation orientation, Graphics g, IDisposable memento) { MementoDouble cache; if ((memento == null) || !(memento is MementoDouble)) { if (memento != null) memento.Dispose(); cache = new MementoDouble(); memento = cache; } else { cache = (MementoDouble)memento; } // Draw entire background in linear gradient effect cache.first = DrawBackLinear(drawRect, sigma, color1, color2, orientation, g, cache.first); bool generate = true; MementoBackLinearRadial cacheThis; // Access a cache instance and decide if cache resources need generating if ((cache.second == null) || !(cache.second is MementoBackLinearRadial)) { if (cache.second != null) cache.second.Dispose(); cacheThis = new MementoBackLinearRadial(drawRect, color2, color3, orientation); cache.second = cacheThis; } else { cacheThis = (MementoBackLinearRadial)cache.second; generate = !cacheThis.UseCachedValues(drawRect, color2, color3, orientation); } // Do we need to generate the contents of the cache? if (generate) { // Dispose of existing values cacheThis.Dispose(); float third; // Find the 1/3 height used for the ellipse if (VerticalOrientation(orientation)) third = drawRect.Height / 3; else third = drawRect.Width / 3; // Find the bottom area rectangle RectangleF ellipseRect; PointF centerPoint; switch (orientation) { case VisualOrientation.Left: ellipseRect = new RectangleF(drawRect.Right - third, drawRect.Y + 1, third, drawRect.Height - 2); centerPoint = new PointF(ellipseRect.Right, ellipseRect.Y + (ellipseRect.Height / 2)); break; case VisualOrientation.Right: ellipseRect = new RectangleF(drawRect.X - 1, drawRect.Y + 1, third, drawRect.Height - 2); centerPoint = new PointF(ellipseRect.Left, ellipseRect.Y + (ellipseRect.Height / 2)); break; case VisualOrientation.Bottom: ellipseRect = new RectangleF(drawRect.X + 1, drawRect.Y - 1, drawRect.Width - 2, third); centerPoint = new PointF(ellipseRect.X + (ellipseRect.Width / 2), ellipseRect.Top); break; case VisualOrientation.Top: default: ellipseRect = new RectangleF(drawRect.X + 1, drawRect.Bottom - third, drawRect.Width - 2, third); centerPoint = new PointF(ellipseRect.X + (ellipseRect.Width / 2), ellipseRect.Bottom); break; } cacheThis.ellipseRect = ellipseRect; // Cannot draw a path that contains a zero sized element if ((ellipseRect.Width > 0) && (ellipseRect.Height > 0)) { cacheThis.path = new GraphicsPath(); cacheThis.path.AddEllipse(ellipseRect); cacheThis.bottomBrush = new PathGradientBrush(cacheThis.path); cacheThis.bottomBrush.CenterColor = ControlPaint.Light(color3); cacheThis.bottomBrush.CenterPoint = centerPoint; cacheThis.bottomBrush.SurroundColors = new Color[] { color2 }; } } if (cacheThis.bottomBrush != null) g.FillRectangle(cacheThis.bottomBrush, cacheThis.ellipseRect); return memento; }
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; }
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; }
private static IDisposable DrawBackGlassRadial(RectangleF drawRect, Color color1, Color color2, Color glassColor1, Color glassColor2, float factorX, float factorY, VisualOrientation orientation, Graphics g, float glassPercent, IDisposable memento) { MementoDouble cache; if ((memento == null) || !(memento is MementoDouble)) { if (memento != null) memento.Dispose(); cache = new MementoDouble(); memento = cache; } else { cache = (MementoDouble)memento; } // Draw the gradient effect background RectangleF glassRect = DrawBackGlassBasic(drawRect, color1, color2, glassColor1, glassColor2, factorX, factorY, orientation, g, glassPercent, ref cache.first); bool generate = true; MementoBackGlassRadial cacheThis; // Access a cache instance and decide if cache resources need generating if ((cache.second == null) || !(cache.second is MementoBackGlassRadial)) { if (cache.second != null) cache.second.Dispose(); cacheThis = new MementoBackGlassRadial(drawRect, color1, color2, factorX, factorY, orientation); cache.second = cacheThis; } else { cacheThis = (MementoBackGlassRadial)cache.second; generate = !cacheThis.UseCachedValues(drawRect, color1, color2, factorX, factorY, orientation); } // Do we need to generate the contents of the cache? if (generate) { // Dispose of existing values cacheThis.Dispose(); // Find the bottom area rectangle RectangleF mainRect; switch (orientation) { case VisualOrientation.Right: mainRect = new RectangleF(drawRect.X, drawRect.Y, drawRect.Width - glassRect.Width - 1, drawRect.Height); break; case VisualOrientation.Left: mainRect = new RectangleF(glassRect.Right + 1, drawRect.Y, drawRect.Width - glassRect.Width - 1, drawRect.Height); break; case VisualOrientation.Bottom: mainRect = new RectangleF(drawRect.X, drawRect.Y, drawRect.Width, drawRect.Height - glassRect.Height - 1); break; case VisualOrientation.Top: default: mainRect = new RectangleF(drawRect.X, glassRect.Bottom + 1, drawRect.Width, drawRect.Height - glassRect.Height - 1); break; } RectangleF doubleRect; // Find the box that encloses the ellipse (ellipses is sized using the factorX, factorY) if (VerticalOrientation(orientation)) { float mainRectWidth = (mainRect.Width * factorX); float mainRectWidthOffset = (mainRectWidth - mainRect.Width) / 2; float mainRectHeight = (mainRect.Height * factorY); float mainRectHeightOffset; // Find orientation specific ellsipe rectangle if (orientation == VisualOrientation.Top) mainRectHeightOffset = (mainRectHeight - mainRect.Height) / 2; else mainRectHeightOffset = (mainRectHeight + (mainRectHeight - mainRect.Height) / 2); doubleRect = new RectangleF(mainRect.X - mainRectWidthOffset, mainRect.Y - mainRectHeightOffset, mainRectWidth, mainRectHeight * 2); } else { float mainRectHeight = (mainRect.Height * factorX); float mainRectHeightOffset = (mainRectHeight - mainRect.Height) / 2; float mainRectWidth = (mainRect.Width * factorY); float mainRectWidthOffset; // Find orientation specific ellsipe rectangle if (orientation == VisualOrientation.Left) mainRectWidthOffset = (mainRectWidth - mainRect.Width) / 2; else mainRectWidthOffset = (mainRectWidth + (mainRectWidth - mainRect.Width) / 2); doubleRect = new RectangleF(mainRect.X - mainRectWidthOffset, mainRect.Y - mainRectHeightOffset, mainRectWidth * 2, mainRectHeight); } // Cannot draw a path that contains a zero sized element if ((doubleRect.Width > 0) && (doubleRect.Height > 0)) { // We use a path to create an ellipse for the light effect in the bottom of the area cacheThis.path = new GraphicsPath(); cacheThis.path.AddEllipse(doubleRect); // Create a brush from the path cacheThis.bottomBrush = new PathGradientBrush(cacheThis.path); cacheThis.bottomBrush.CenterColor = color2; cacheThis.bottomBrush.CenterPoint = new PointF(doubleRect.X + (doubleRect.Width / 2), doubleRect.Y + (doubleRect.Height / 2)); cacheThis.bottomBrush.SurroundColors = new Color[] { color1 }; cacheThis.mainRect = mainRect; } } if (cacheThis.bottomBrush != null) g.FillRectangle(cacheThis.bottomBrush, cacheThis.mainRect); return memento; }