/// <summary> /// Generates the linear gradient texture content /// </summary> /// <param name="lineStart">The line start.</param> /// <param name="lineEnd">The line end.</param> /// <param name="borderThickness">The border thickness.</param> /// <param name="sortedStops">The sorted stops.</param> /// <param name="spread">The spread.</param> /// <param name="isBorder">if set to <c>true</c> [is border].</param> public override void GenerateLinearGradient(PointF lineStart, PointF lineEnd, Thickness borderThickness, List<GradientStop> sortedStops, GradientSpreadMethod spread, bool isBorder) { Color[] data = new Color[Width * Height]; Color startColor = Color.Transparent; Color endColor = Color.Transparent; PointF point = new PointF(); float length = GetLength(lineStart, lineEnd); int index = 0; for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { point.Y = y; point.X = x; if ((borderThickness.Top > point.Y || borderThickness.Bottom >= Height - point.Y) || (borderThickness.Left > point.X || borderThickness.Right >= Width - point.X) || !isBorder) { PointF projectPoint = ProjectToLine(lineStart, lineEnd, point, Width); float finalOffset = GetLength(projectPoint, lineStart) / length; switch (spread) { case GradientSpreadMethod.Pad: if (projectPoint.X <= lineStart.X && projectPoint.Y <= lineStart.Y) { finalOffset = 0; } if (projectPoint.X >= lineEnd.X && projectPoint.Y >= lineEnd.Y) { finalOffset = 1; } break; case GradientSpreadMethod.Reflect: if (projectPoint.X <= lineStart.X && projectPoint.Y <= lineStart.Y || projectPoint.X >= lineEnd.X && projectPoint.Y >= lineEnd.Y) { if (finalOffset > 1) { finalOffset = ((float)Math.Ceiling(finalOffset) - finalOffset); } } break; case GradientSpreadMethod.Repeat: if (projectPoint.X <= lineStart.X && projectPoint.Y <= lineStart.Y) { if (finalOffset > 0) { finalOffset = ((float)Math.Ceiling(finalOffset) - finalOffset); } } if (projectPoint.X >= lineEnd.X && projectPoint.Y >= lineEnd.Y) { if (finalOffset > 1) { finalOffset = (finalOffset - (float)Math.Floor(finalOffset)); } } break; default: Debug.Assert(false); break; } GradientStop startStop = GetStartStop(finalOffset, sortedStops); startColor = startStop != null ? new Color { PackedValue = startStop.Color.PackedValue } : Color.Transparent; GradientStop endStop = GetEndStop(finalOffset, sortedStops, spread); endColor = endStop != null ? new Color { PackedValue = endStop.Color.PackedValue } : Color.Transparent; if (endStop != null && startStop != null) { finalOffset = (finalOffset - startStop.Offset) * (1f / (endStop.Offset - startStop.Offset)); } if (float.IsInfinity(finalOffset)) { finalOffset = 0; } if (float.IsNaN(finalOffset)) { finalOffset = 1; } Color finalColor = Color.Lerp(startColor, endColor, finalOffset); data[index] = finalColor; } else { data[index] = Color.Transparent; } index++; } } texture.SetData<Color>(data); }
private static GradientStop GetEndStop(float offset, List<GradientStop> stops, GradientSpreadMethod spreadMethod) { foreach (var gStop in stops) { if (gStop.Offset > offset) { return gStop; } } if (stops.Count != 0) { return stops[stops.Count - 1]; } return null; }
public wpf::System.Windows.Media.GradientSpreadMethod Convert(GradientSpreadMethod gradientSpreadMethod) { return((wpf::System.Windows.Media.GradientSpreadMethod)((int)gradientSpreadMethod)); }
private wpf::System.Windows.Media.GradientSpreadMethod Convert(GradientSpreadMethod gradientSpreadMethod) { return (wpf::System.Windows.Media.GradientSpreadMethod)((int)gradientSpreadMethod); }
private void InitializeGradientBrush(GradientBrush gradientBrush) { spreadMethod = gradientBrush.SpreadMethod; interpolationMode = gradientBrush.ColorInterpolationMode; opacity = gradientBrush.Opacity; }
private static IList <GradientColorStop> AdjustNormalizedStopsToCoverDomain(IList <GradientColorStop> normalizedStops , double[] targetDomain, GradientSpreadMethod spreadMethod) { IList <GradientColorStop> adjustedStops = new List <GradientColorStop>(); GradientColorStop lastColorStop = normalizedStops[normalizedStops.Count - 1]; double originalIntervalEnd = lastColorStop.GetOffset(); double originalIntervalStart = normalizedStops[0].GetOffset(); double originalIntervalLength = originalIntervalEnd - originalIntervalStart; if (originalIntervalLength <= ZERO_EPSILON) { return(JavaUtil.ArraysAsList(new GradientColorStop(lastColorStop, targetDomain[0], GradientColorStop.OffsetType .RELATIVE), new GradientColorStop(lastColorStop, targetDomain[1], GradientColorStop.OffsetType.RELATIVE ))); } double startIntervalsShift = Math.Floor((targetDomain[0] - originalIntervalStart) / originalIntervalLength ); double iterationOffset = originalIntervalStart + (originalIntervalLength * startIntervalsShift); bool isIterationInverse = spreadMethod == GradientSpreadMethod.REFLECT && Math.Abs(startIntervalsShift) % 2 != 0; int currentIterationIndex = isIterationInverse ? normalizedStops.Count - 1 : 0; double lastComputedOffset = iterationOffset; while (lastComputedOffset <= targetDomain[1]) { GradientColorStop currentStop = normalizedStops[currentIterationIndex]; lastComputedOffset = isIterationInverse ? iterationOffset + originalIntervalEnd - currentStop.GetOffset() : iterationOffset + currentStop.GetOffset() - originalIntervalStart; GradientColorStop computedStop = new GradientColorStop(currentStop, lastComputedOffset, GradientColorStop.OffsetType .RELATIVE); if (lastComputedOffset < targetDomain[0] && !adjustedStops.IsEmpty()) { adjustedStops[0] = computedStop; } else { adjustedStops.Add(computedStop); } if (isIterationInverse) { --currentIterationIndex; if (currentIterationIndex < 0) { iterationOffset += originalIntervalLength; isIterationInverse = false; currentIterationIndex = 1; } } else { ++currentIterationIndex; if (currentIterationIndex == normalizedStops.Count) { iterationOffset += originalIntervalLength; isIterationInverse = spreadMethod == GradientSpreadMethod.REFLECT; currentIterationIndex = isIterationInverse ? normalizedStops.Count - 2 : 0; } } // check the next iteration type to set the correct stop color hint for just added stop if (isIterationInverse) { GradientColorStop nextColor = normalizedStops[currentIterationIndex]; // this method should be invoked only after the normalization. it means that // the hint offset type for each stop is either relative to colors interval // (i.e. for inverse iteration we need to inverse the hint offset), or is none // (i.e. the hint offset value should be ignored) computedStop.SetHint(1 - nextColor.GetHintOffset(), nextColor.GetHintOffsetType()); } else { computedStop.SetHint(currentStop.GetHintOffset(), currentStop.GetHintOffsetType()); } } return(adjustedStops); }
/// <summary> /// Generates the linear gradient texture content /// </summary> /// <param name="lineStart">The line start.</param> /// <param name="lineEnd">The line end.</param> /// <param name="borderThickness">The border thickness.</param> /// <param name="sortedStops">The sorted stops.</param> /// <param name="spread">The spread.</param> /// <param name="isBorder">if set to <c>true</c> [is border].</param> public override void GenerateLinearGradient(PointF lineStart, PointF lineEnd, Thickness borderThickness, List <GradientStop> sortedStops, GradientSpreadMethod spread, bool isBorder) { Color[] data = new Color[Width * Height]; Color startColor = Color.Transparent; Color endColor = Color.Transparent; PointF point = new PointF(); float length = GetLength(lineStart, lineEnd); int index = 0; for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { point.Y = y; point.X = x; if ((borderThickness.Top > point.Y || borderThickness.Bottom >= Height - point.Y) || (borderThickness.Left > point.X || borderThickness.Right >= Width - point.X) || !isBorder) { PointF projectPoint = ProjectToLine(lineStart, lineEnd, point, Width); float finalOffset = GetLength(projectPoint, lineStart) / length; switch (spread) { case GradientSpreadMethod.Pad: if (projectPoint.X <= lineStart.X && projectPoint.Y <= lineStart.Y) { finalOffset = 0; } if (projectPoint.X >= lineEnd.X && projectPoint.Y >= lineEnd.Y) { finalOffset = 1; } break; case GradientSpreadMethod.Reflect: if (projectPoint.X <= lineStart.X && projectPoint.Y <= lineStart.Y || projectPoint.X >= lineEnd.X && projectPoint.Y >= lineEnd.Y) { if (finalOffset > 1) { finalOffset = ((float)Math.Ceiling(finalOffset) - finalOffset); } } break; case GradientSpreadMethod.Repeat: if (projectPoint.X <= lineStart.X && projectPoint.Y <= lineStart.Y) { if (finalOffset > 0) { finalOffset = ((float)Math.Ceiling(finalOffset) - finalOffset); } } if (projectPoint.X >= lineEnd.X && projectPoint.Y >= lineEnd.Y) { if (finalOffset > 1) { finalOffset = (finalOffset - (float)Math.Floor(finalOffset)); } } break; default: Debug.Assert(false); break; } GradientStop startStop = GetStartStop(finalOffset, sortedStops); startColor = startStop != null ? new Color { PackedValue = startStop.Color.PackedValue } : Color.Transparent; GradientStop endStop = GetEndStop(finalOffset, sortedStops, spread); endColor = endStop != null ? new Color { PackedValue = endStop.Color.PackedValue } : Color.Transparent; if (endStop != null && startStop != null) { finalOffset = (finalOffset - startStop.Offset) * (1f / (endStop.Offset - startStop.Offset)); } if (float.IsInfinity(finalOffset)) { finalOffset = 0; } if (float.IsNaN(finalOffset)) { finalOffset = 1; } Color finalColor = Color.Lerp(startColor, endColor, finalOffset); data[index] = finalColor; } else { data[index] = Color.Transparent; } index++; } } texture.SetData <Color>(data); }
private static GradientStop GetEndStop(float offset, List <GradientStop> stops, GradientSpreadMethod spreadMethod) { foreach (var gStop in stops) { if (gStop.Offset > offset) { return(gStop); } } if (stops.Count != 0) { return(stops[stops.Count - 1]); } return(null); }
public LinearGradientPaintServer(float x1, float y1, float x2, float y2, GradientSpreadMethod spreadMethod) : base(spreadMethod) { origin = new Vector2(x1, y1); direction = new Vector2(x2, y2) - origin; }
public static T SpreadMethod <T>(this T gradientBrush, GradientSpreadMethod value) where T : IGradientBrush { gradientBrush.SpreadMethod = value; return(gradientBrush); }
/// <summary> /// Generates the linear gradient texture content /// </summary> /// <param name="lineStart">The line start.</param> /// <param name="lineEnd">The line end.</param> /// <param name="borderThickness">The border thickness.</param> /// <param name="sortedStops">The sorted stops.</param> /// <param name="spread">The spread.</param> /// <param name="isBorder">if set to <c>true</c> [is border].</param> public abstract void GenerateLinearGradient(PointF lineStart, PointF lineEnd, Thickness borderThickness, List<GradientStop> sortedStops, GradientSpreadMethod spread, bool isBorder);
public RadialGradientPaintServer(float cx, float cy, float r, float fx, float fy, float fr, GradientSpreadMethod spreadMethod) : base(spreadMethod) { // Input the constants focus = new Vector2(fx, fy); cf = new Vector2(cx, cy) - focus; r -= fr; a = cf.LengthSquared() - r * r; rfr = r * fr; fr2 = fr * fr; }
public static IntPtr Box_GradientSpreadMethod(GradientSpreadMethod val) { IntPtr ret = NoesisGUI_PINVOKE.Box_GradientSpreadMethod((int)val); return(ret); }
public static GradientSpreadMethod Unbox_GradientSpreadMethod(IntPtr val) { GradientSpreadMethod ret = (GradientSpreadMethod)NoesisGUI_PINVOKE.Unbox_GradientSpreadMethod(val); return(ret); }
/// <summary> /// Generates the linear gradient texture content /// </summary> /// <param name="lineStart">The line start.</param> /// <param name="lineEnd">The line end.</param> /// <param name="borderThickness">The border thickness.</param> /// <param name="sortedStops">The sorted stops.</param> /// <param name="spread">The spread.</param> /// <param name="isBorder">if set to <c>true</c> [is border].</param> public abstract void GenerateLinearGradient(PointF lineStart, PointF lineEnd, Thickness borderThickness, List <GradientStop> sortedStops, GradientSpreadMethod spread, bool isBorder);