/// <summary> /// Initializes the collection with the two color blend. /// </summary> /// <param name="collection">Collection to initialize.</param> /// <param name="backColor1">Solid Color</param> public static void InitializeCollection(BackgroundColorBlendCollection collection, Color backColor) { collection.Clear(); collection.Add(new BackgroundColorBlend(backColor, 0f)); }
/// <summary> /// Initializes the collection with the two color blend. /// </summary> /// <param name="collection">Collection to initialize.</param> /// <param name="backColor1">Start color.</param> /// <param name="backColor2">End color.</param> public static void InitializeCollection(BackgroundColorBlendCollection collection, int backColor1, int backColor2) { InitializeCollection(collection, ColorScheme.GetColor(backColor1), ColorScheme.GetColor(backColor2)); }
public static Brush CreateBrush(Rectangle bounds, BackgroundColorBlendCollection colorBlend, int gradientAngle, eGradientType gradientType) { eBackgroundColorBlendType blendType = colorBlend.GetBlendType(); if (blendType == eBackgroundColorBlendType.Invalid) return null; if (blendType == eBackgroundColorBlendType.SolidColor) { return new SolidBrush(colorBlend[0].Color); } else if (blendType == eBackgroundColorBlendType.Relative) { try { if (gradientType == eGradientType.Linear) { bounds.Inflate(1, 1); LinearGradientBrush brush = DisplayHelp.CreateLinearGradientBrush(bounds, colorBlend[0].Color, colorBlend[colorBlend.Count - 1].Color, gradientAngle); brush.InterpolationColors = colorBlend.GetColorBlend(); return brush; } else if (gradientType == eGradientType.Radial) { int d = (int)Math.Sqrt(bounds.Width * bounds.Width + bounds.Height * bounds.Height) + 4; GraphicsPath fillPath = new GraphicsPath(); fillPath.AddEllipse(bounds.X - (d - bounds.Width) / 2, bounds.Y - (d - bounds.Height) / 2, d, d); PathGradientBrush brush = new PathGradientBrush(fillPath); brush.CenterColor = colorBlend[0].Color; brush.SurroundColors = new Color[] { colorBlend[colorBlend.Count - 1].Color }; brush.InterpolationColors = colorBlend.GetColorBlend(); return brush; } } catch { return null; } } else { BackgroundColorBlendCollection bc = colorBlend; for (int i = 0; i < bc.Count; i += 2) { BackgroundColorBlend b1 = bc[i]; BackgroundColorBlend b2 = null; if (i < bc.Count) b2 = bc[i + 1]; if (b1 != null && b2 != null) { Rectangle rb = new Rectangle(bounds.X, bounds.Y + (int)b1.Position, bounds.Width, (b2.Position == 1f ? bounds.Height : (int)b2.Position) - (int)b1.Position); return DisplayHelp.CreateLinearGradientBrush(rb, b1.Color, b2.Color, gradientAngle); } } } return null; }
/// <summary> /// Adds the BackgroundColorBlend objects from the collection. /// </summary> /// <param name="col">Collection to copy objects from</param> public void CopyFrom(BackgroundColorBlendCollection col) { foreach (BackgroundColorBlend b in col) this.Add(b); }
public BackgroundColorBlendCollection GetColorBlendCollection() { BackgroundColorBlendCollection cbc = new BackgroundColorBlendCollection(); float[] cp = _Positions; if (cp == null || cp.Length != _Colors.Length) { cp = new float[_Colors.Length]; float f = 1 / _Colors.Length; for (int i = 0; i < cp.Length; i++) cp[i] = i * f; cp[_Colors.Length - 1] = 1; } for (int i = 0; i < _Colors.Length; i++) cbc.Add(new BackgroundColorBlend(_Colors[i], cp[i])); return (cbc); }