public sd2.PathGradientBrush GetBrush(RectangleF rect) { var scale = 1f; var bounds = rect; if (Matrix != null) { bounds = Matrix.Inverse().TransformRectangle(bounds); } scale = GradientHelper.GetRadialScale(Center, Radius, GradientOrigin, bounds); if (brush == null || lastScale != scale) { lastScale = scale; var scaledRect = new RectangleF(GradientOrigin - (GradientOrigin - Center + Radius) * scale, GradientOrigin + (Center + Radius - GradientOrigin) * scale); var path = new sd2.GraphicsPath(); path.AddEllipse(scaledRect.ToSD()); brush = new sd2.PathGradientBrush(path); brush.CenterColor = StartColor.ToSD(); brush.CenterPoint = GradientOrigin.ToSD(); brush.WrapMode = wrapMode.ToSD(); brush.SurroundColors = new[] { EndColor.ToSD() }; if (Matrix != null) { brush.MultiplyTransform(Matrix.ToSD()); } if (scale > 1f) { var paths = GradientHelper.GetGradientStops(StartColor.ToSD(), EndColor.ToSD(), scale, wrapMode); brush.InterpolationColors = new sd2.ColorBlend { Positions = paths.Reverse().Select(r => 1f - r.Item1).ToArray(), Colors = paths.Reverse().Select(r => r.Item2).ToArray() }; } } return(brush); }
public void SetGradientWrap (LinearGradientBrush widget, GradientWrapMode gradientWrap) { ((BrushObject)widget.ControlObject).Brush.WrapMode = gradientWrap.ToSD (); }
public sd2.LinearGradientBrush GetBrush(RectangleF rect) { var start = StartPoint; var end = EndPoint; if (wrapMode == GradientWrapMode.Pad) { // winforms does not support pad, so extend to fill entire drawing region if (transform != null) { start = transform.TransformPoint(start); end = transform.TransformPoint(end); } PointF min, max; GradientHelper.GetLinearMinMax(start, end, rect, out min, out max, true); var len = max.LengthTo(min); // find start/end pos based on entire position var startpos = min.LengthTo(start) / len; var endpos = min.LengthTo(end) / len; if (brush == null || lastStartPos != startpos || lastEndPos > endpos) { lastStartPos = startpos; lastEndPos = endpos; start = min; end = max; var diff = end - start; // account for innacuracies in system.drawing when nearing horizontal or vertical if (Math.Abs(diff.X) < 0.0001) { end.X = start.X; } if (Math.Abs(diff.Y) < 0.0001) { end.Y = start.Y; } brush = new sd2.LinearGradientBrush(start.ToSD(), end.ToSD(), StartColor, EndColor); brush.WrapMode = sd2.WrapMode.Tile; brush.InterpolationColors = new sd2.ColorBlend { Colors = new[] { StartColor, StartColor, EndColor, EndColor }, Positions = new[] { 0f, startpos, endpos, 1f, } }; } } else if (brush == null) { brush = new sd2.LinearGradientBrush(StartPoint.ToSD(), EndPoint.ToSD(), StartColor, EndColor); brush.WrapMode = wrapMode.ToSD(); if (transform != null) { brush.MultiplyTransform(transform.ToSD()); } } return(brush); }
public void SetGradientWrap(LinearGradientBrush widget, GradientWrapMode gradientWrap) { ((BrushObject)widget.ControlObject).Brush.WrapMode = gradientWrap.ToSD(); }