internal Brush GetBrush(GaugeGraphics g, RectangleF rect, GaugeHatchStyle hatchStyle, GradientType gradientType, Color fillColor, Color gradientEndColor, bool frame, float frameWidth) { Brush brush = null; if (hatchStyle != 0) { brush = GaugeGraphics.GetHatchBrush(hatchStyle, fillColor, gradientEndColor); } else if (gradientType != 0) { if (FrameShape == BackFrameShape.Circular && gradientType == GradientType.DiagonalLeft) { brush = g.GetGradientBrush(rect, fillColor, gradientEndColor, GradientType.LeftRight); Matrix matrix = new Matrix(); matrix.RotateAt(45f, new PointF(rect.X + rect.Width / 2f, rect.Y + rect.Height / 2f)); ((LinearGradientBrush)brush).Transform = matrix; } else if (FrameShape == BackFrameShape.Circular && gradientType == GradientType.DiagonalRight) { brush = g.GetGradientBrush(rect, fillColor, gradientEndColor, GradientType.TopBottom); Matrix matrix2 = new Matrix(); matrix2.RotateAt(135f, new PointF(rect.X + rect.Width / 2f, rect.Y + rect.Height / 2f)); ((LinearGradientBrush)brush).Transform = matrix2; } else if (gradientType == GradientType.Center) { GraphicsPath graphicsPath = new GraphicsPath(); if (FrameShape == BackFrameShape.Circular) { graphicsPath.AddArc(rect.X, rect.Y, rect.Width, rect.Height, 0f, 360f); } else { graphicsPath.AddRectangle(rect); } PathGradientBrush pathGradientBrush = new PathGradientBrush(graphicsPath); pathGradientBrush.CenterColor = fillColor; pathGradientBrush.CenterPoint = new PointF(rect.X + rect.Width / 2f, rect.Y + rect.Height / 2f); pathGradientBrush.SurroundColors = new Color[1] { gradientEndColor }; if (frame) { pathGradientBrush.FocusScales = new PointF((rect.Width - frameWidth * 2f) / rect.Width, (rect.Height - frameWidth * 2f) / rect.Height); } brush = pathGradientBrush; } else { brush = g.GetGradientBrush(rect, fillColor, gradientEndColor, gradientType); } } else { brush = new SolidBrush(fillColor); } return(brush); }
public Brush GetBackBrush(GaugeGraphics g) { RectangleF absoluteRectangle = g.GetAbsoluteRectangle(new RectangleF(0f, 0f, 100f, 100f)); Brush brush = null; Color color = this.BackColor; Color color2 = this.BackGradientEndColor; GradientType gradientType = this.BackGradientType; GaugeHatchStyle gaugeHatchStyle = this.BackHatchStyle; if (gaugeHatchStyle != 0) { brush = GaugeGraphics.GetHatchBrush(gaugeHatchStyle, color, color2); } else if (gradientType != 0) { brush = g.GetGradientBrush(absoluteRectangle, color, color2, gradientType); if (this.Angle != 0.0) { PointF pointF = new PointF((float)(absoluteRectangle.X + absoluteRectangle.Width / 2.0), (float)(absoluteRectangle.Y + absoluteRectangle.Height / 2.0)); if (brush is LinearGradientBrush) { ((LinearGradientBrush)brush).TranslateTransform((float)(0.0 - pointF.X), (float)(0.0 - pointF.Y), MatrixOrder.Append); ((LinearGradientBrush)brush).RotateTransform(this.Angle, MatrixOrder.Append); ((LinearGradientBrush)brush).TranslateTransform(pointF.X, pointF.Y, MatrixOrder.Append); } else if (brush is PathGradientBrush) { ((PathGradientBrush)brush).TranslateTransform((float)(0.0 - pointF.X), (float)(0.0 - pointF.Y), MatrixOrder.Append); ((PathGradientBrush)brush).RotateTransform(this.Angle, MatrixOrder.Append); ((PathGradientBrush)brush).TranslateTransform(pointF.X, pointF.Y, MatrixOrder.Append); } } } else { brush = new SolidBrush(color); } return(brush); }
private Brush GetFillBrush(GaugeGraphics g, GraphicsPath path, PointF pointOrigin, float angle, Color fillColor, GradientType fillGradientType, Color fillGradientEndColor, GaugeHatchStyle fillHatchStyle) { Brush brush = null; if (fillHatchStyle != 0) { brush = GaugeGraphics.GetHatchBrush(fillHatchStyle, fillColor, fillGradientEndColor); } else if (fillGradientType != 0) { RectangleF bounds = path.GetBounds(); switch (fillGradientType) { case GradientType.DiagonalLeft: brush = g.GetGradientBrush(bounds, fillColor, fillGradientEndColor, GradientType.LeftRight); using (Matrix matrix2 = new Matrix()) { matrix2.RotateAt(45f, new PointF((float)(bounds.X + bounds.Width / 2.0), (float)(bounds.Y + bounds.Height / 2.0))); ((LinearGradientBrush)brush).Transform = matrix2; } break; case GradientType.DiagonalRight: brush = g.GetGradientBrush(bounds, fillColor, fillGradientEndColor, GradientType.TopBottom); using (Matrix matrix = new Matrix()) { matrix.RotateAt(135f, new PointF((float)(bounds.X + bounds.Width / 2.0), (float)(bounds.Y + bounds.Height / 2.0))); ((LinearGradientBrush)brush).Transform = matrix; } break; case GradientType.Center: bounds.Inflate(1f, 1f); using (GraphicsPath graphicsPath = new GraphicsPath()) { graphicsPath.AddArc(bounds, 0f, 360f); PathGradientBrush pathGradientBrush = new PathGradientBrush(graphicsPath); pathGradientBrush.CenterColor = fillColor; pathGradientBrush.CenterPoint = new PointF((float)(bounds.X + bounds.Width / 2.0), (float)(bounds.Y + bounds.Height / 2.0)); pathGradientBrush.SurroundColors = new Color[1] { fillGradientEndColor }; brush = pathGradientBrush; } break; default: brush = g.GetGradientBrush(path.GetBounds(), fillColor, fillGradientEndColor, fillGradientType); break; } if (brush is LinearGradientBrush) { ((LinearGradientBrush)brush).RotateTransform(angle, MatrixOrder.Append); ((LinearGradientBrush)brush).TranslateTransform(pointOrigin.X, pointOrigin.Y, MatrixOrder.Append); } else if (brush is PathGradientBrush) { ((PathGradientBrush)brush).RotateTransform(angle, MatrixOrder.Append); ((PathGradientBrush)brush).TranslateTransform(pointOrigin.X, pointOrigin.Y, MatrixOrder.Append); } } else { brush = new SolidBrush(fillColor); } return(brush); }