public ColorGradient GetSubGradient(double start, double end) { double range = end - start; if (range < 0) { throw new ArgumentException("end must be after start"); } ColorGradient result = new ColorGradient(); result.Colors.Clear(); result.Colors.Add(new ColorPoint(GetColorAt(start), 0)); foreach (ColorPoint cp in Colors) { if (cp.Position > start && cp.Position < end) { double scaledPos = (cp.Position - start) / range; if (scaledPos > 1.0 || scaledPos < 0.0) { throw new Exception("Error calculating position: " + scaledPos + " out of range"); } result.Colors.Add(new ColorPoint(cp.Color.ToRGB(), scaledPos)); } } result.Colors.Add(new ColorPoint(GetColorAt(end), 1)); return(result); }
private void PopulateListWithColorGradients() { listViewColorGradients.BeginUpdate(); listViewColorGradients.Items.Clear(); listViewColorGradients.LargeImageList = new ImageList(); listViewColorGradients.LargeImageList.ColorDepth = ColorDepth.Depth32Bit; foreach (KeyValuePair <string, ColorGradient> kvp in Library) { ColorGradient gradient = kvp.Value; string name = kvp.Key; listViewColorGradients.LargeImageList.ImageSize = new Size(64, 64); listViewColorGradients.LargeImageList.Images.Add(name, gradient.GenerateColorGradientImage(new Size(64, 64), false)); ListViewItem item = new ListViewItem(); item.Text = name; item.Name = name; item.ImageKey = name; item.Tag = gradient; listViewColorGradients.Items.Add(item); } listViewColorGradients.EndUpdate(); buttonEditColorGradient.Enabled = false; buttonDeleteColorGradient.Enabled = false; }
/// <summary> /// returns a copy of all gradient points and parameters /// </summary> public object Clone() { ColorGradient ret = new ColorGradient(); if (_title != null) { ret._title = (string)_title.Clone(); } ret._gammacorrected = _gammacorrected; foreach (ColorPoint cp in _colors) { ret._colors.Add((ColorPoint)cp.Clone()); } foreach (AlphaPoint ap in _alphas) { ret._alphas.Add((AlphaPoint)ap.Clone()); } // grab all the library-linking details as well ret.LibraryReferenceName = LibraryReferenceName; ret.IsCurrentLibraryGradient = IsCurrentLibraryGradient; return(ret); }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == null) { throw new ArgumentNullException("destinationType"); } if (destinationType == typeof(InstanceDescriptor)) { ConstructorInfo ci = typeof(ColorGradient).GetConstructor(new[] { typeof(ColorGradient) }); ColorGradient gradient = (ColorGradient)value; return(new InstanceDescriptor(ci, new object[] { gradient })); } if (destinationType == typeof(string)) { if (value is ColorGradient) { ColorGradient cg = (ColorGradient)value; if (cg.IsLibraryReference) { return(string.Format("Library: {0}", cg.LibraryReferenceName)); } return(""); } } return(base.ConvertTo(context, culture, value, destinationType)); }
private void SetFocusPosition <T>(PointList <T> coll, T value, double focuspos) where T : Point, IComparable <T> { if (coll == null || value == null) { throw new ArgumentNullException("coll or value"); } if (!ColorGradient.isValid(focuspos)) { throw new ArgumentException("focuspos"); } // T[] sorted = coll.SortedArray(); int i = Array.IndexOf <T>(sorted, value); if (i > 0) { //calculate focus double w = sorted[i].Position - sorted[i - 1].Position; if (w <= 0) { value.Focus = .5; } else { value.Focus = Math.Max(.0, Math.Min(1.0, (focuspos - sorted[i - 1].Position) / w)); } } }
/// <summary> /// deep copy clone: clones this object from another given one. /// </summary> /// <param name="other"></param> public void CloneFrom(ColorGradient other) { CloneDataFrom(other); // grab all the library-linking details as well LibraryReferenceName = other.LibraryReferenceName; IsCurrentLibraryGradient = other.IsCurrentLibraryGradient; }
/// <summary> /// ctor /// </summary> public AlphaPoint(double alpha, double focus, double point) : base(point, focus) { if (!ColorGradient.isValid(alpha)) { throw new ArgumentException("alpha"); } _alpha = alpha; }
/// <summary> /// ctor /// </summary> public Point(double position, double focus) { if (!ColorGradient.isValid(position) || !ColorGradient.isValid(focus)) { throw new ArgumentException("position or focus"); } _position = position; _focus = focus; }
public ColorGradientEditor(ColorGradient gradient, bool discreteColors, IEnumerable <Color> validDiscreteColors) { InitializeComponent(); Icon = Common.Resources.Properties.Resources.Icon_Vixen3; gradientEditPanel.GradientChanged += GradientChangedHandler; Gradient = gradient; _discreteColors = discreteColors; _validDiscreteColors = validDiscreteColors; PopulateFormWithGradient(_gradient); }
private void buttonLoadFromLibrary_Click(object sender, EventArgs e) { ColorGradientLibrarySelector selector = new ColorGradientLibrarySelector(); if (selector.ShowDialog() == System.Windows.Forms.DialogResult.OK && selector.SelectedItem != null) { // make a new curve that references the selected library curve, and set it to the current Curve ColorGradient newGradient = new ColorGradient(selector.SelectedItem.Item2); newGradient.LibraryReferenceName = selector.SelectedItem.Item1; newGradient.IsCurrentLibraryGradient = false; Gradient = newGradient; } }
public ColorGradient GetSubGradient(double start, double end) { double range = end - start; if (range < 0) { throw new ArgumentException("end must be after start"); } ColorGradient result = new ColorGradient(); result.Colors.Clear(); result.Colors.Add(new ColorPoint(GetColorAt(start), 0)); ColorPoint previous = null; foreach (ColorPoint cp in Colors) { if (cp.Position > start && cp.Position < end) { double scaledPos = (cp.Position - start) / range; if (scaledPos > 1.0 || scaledPos < 0.0) { throw new Exception("Error calculating position: " + scaledPos + " out of range"); } result.Colors.Add(new ColorPoint(cp.Color.ToRGB(), scaledPos)); } } //Sample a few more colors out for more accuracy for (double d = start + .2d; d < end; d += .2d) { if (d < end) { var c = GetColorAt(d); double scaledPos = (d - start) / range; if (scaledPos > 1.0 || scaledPos < 0.0) { throw new Exception("Error calculating position: " + scaledPos + " out of range"); } result.Colors.Add(new ColorPoint(c, scaledPos)); } } result.Colors.Add(new ColorPoint(GetColorAt(end), 1)); return(result); }
public ColorGradientEditor(ColorGradient gradient, bool discreteColors, IEnumerable <Color> validDiscreteColors) { InitializeComponent(); ForeColor = ThemeColorTable.ForeColor; BackColor = ThemeColorTable.BackgroundColor; ThemeUpdateControls.UpdateControls(this); Icon = Resources.Icon_Vixen3; gradientEditPanel.GradientChanged += GradientChangedHandler; Gradient = gradient; _discreteColors = discreteColors; _validDiscreteColors = validDiscreteColors; PopulateFormWithGradient(_gradient); }
private void PopulateFormWithGradient(ColorGradient item) { gradientEditPanel.Gradient = item; gradientEditPanel.DiscreteColors = _discreteColors; gradientEditPanel.ValidDiscreteColors = _validDiscreteColors; // if we're editing one from the library, treat it special if (item.IsCurrentLibraryGradient) { if (LibraryItemName == null) { labelCurve.Text = "This gradient is a library gradient."; Text = "Color Gradient Editor: Library Gradient"; } else { labelCurve.Text = string.Format("This gradient is the library gradient: {0}", LibraryItemName); Text = string.Format("Color Gradient Editor: Library Gradient {0}", LibraryItemName); } gradientEditPanel.ReadOnly = false; buttonSaveToLibrary.Enabled = false; buttonLoadFromLibrary.Enabled = false; buttonUnlink.Enabled = false; buttonEditLibraryItem.Enabled = false; } else { if (item.IsLibraryReference) { labelCurve.Text = string.Format("This gradient is linked to the library: {0}", item.LibraryReferenceName); } else { labelCurve.Text = "This gradient is not linked to any in the library."; } gradientEditPanel.ReadOnly = item.IsLibraryReference; buttonSaveToLibrary.Enabled = !item.IsLibraryReference; buttonLoadFromLibrary.Enabled = true; buttonUnlink.Enabled = item.IsLibraryReference; buttonEditLibraryItem.Enabled = item.IsLibraryReference; Text = "Curve Editor"; } gradientEditPanel.Invalidate(); }
// note: the start and end points returned will _not_ be scaled correctly, as the color gradients have // no concept of 'level', only color. Being discrete colors, they need to keep their 'full' intensity. public ColorGradient GetSubGradientWithDiscreteColors(double start, double end) { double range = end - start; if (range < 0) { throw new ArgumentException("end must be after start"); } ColorGradient result = new ColorGradient(); result.Colors.Clear(); List <Tuple <Color, float> > startPoint = GetDiscreteColorsAndProportionsAt(start); List <Tuple <Color, float> > endPoint = GetDiscreteColorsAndProportionsAt(end); // hmm.. should these colors at the start and end be the discrete colors, exactly? // or should they be scaled based on the intensity? This whole thing is pretty dodgy, // since it's taking a bunch of assumed knowledge about how it needs to be working // elsewhere and applying it here (keeping the color exactly, since discrete filtering // matches by color). foreach (Tuple <Color, float> tuple in startPoint) { result.Colors.Add(new ColorPoint(tuple.Item1, 0.0)); } foreach (ColorPoint cp in Colors) { if (cp.Position > start && cp.Position < end) { double scaledPos = (cp.Position - start) / range; if (scaledPos > 1.0 || scaledPos < 0.0) { throw new Exception("Error calculating position: " + scaledPos + " out of range"); } result.Colors.Add(new ColorPoint(cp.Color.ToRGB(), scaledPos)); } } foreach (Tuple <Color, float> tuple in endPoint) { result.Colors.Add(new ColorPoint(tuple.Item1, 1.0)); } return(result); }
public ColorGradient GetSubGradient(double start, double end) { ColorGradient result = new ColorGradient(); result.Colors.Clear(); result.Colors.Add(new ColorPoint(GetColorAt(start), start)); foreach (ColorPoint cp in Colors) { if (cp.Position > start && cp.Position < end) { result.Colors.Add(new ColorPoint(cp)); } } result.Colors.Add(new ColorPoint(GetColorAt(end), end)); return(result); }
/// <summary> /// Tries to update the library referenced object. /// </summary> /// <returns>true if successfully updated the library reference, and the data has changed. False if /// not (no reference, library doesn't contain the item, etc.)</returns> public bool UpdateLibraryReference() { _libraryReferencedGradient = null; // if we have a name, try and find it in the library. Otherwise, remove the reference. if (IsLibraryReference) { if (Library.Contains(LibraryReferenceName)) { _libraryReferencedGradient = Library.GetColorGradient(LibraryReferenceName); CloneDataFrom(_libraryReferencedGradient); return(true); } else { LibraryReferenceName = ""; } } return(false); }
/// <summary> /// deep copy clone: clones the data only from another given gradient. /// </summary> /// <param name="other"></param> public void CloneDataFrom(ColorGradient other) { _colors = new PointList <ColorPoint>(); foreach (ColorPoint cp in other.Colors) { _colors.Add(new ColorPoint(cp)); } _alphas = new PointList <AlphaPoint>(); foreach (AlphaPoint ap in other.Alphas) { _alphas.Add(new AlphaPoint(ap)); } _gammacorrected = other.Gammacorrected; if (other.Title != null) { _title = other.Title; } _blend = null; SetEventHandlers(); }
public override bool Equals(object obj) { if (obj is ColorGradient) { ColorGradient color = (ColorGradient)obj; if (IsLibraryReference && color.IsLibraryReference && LibraryReferenceName.Equals(color.LibraryReferenceName)) { return(true); } if (IsLibraryReference || color.IsLibraryReference) { return(false); } if (Colors.Equals(color.Colors) && Alphas.Equals(color.Alphas)) { return(true); } } return(base.Equals(obj)); }
private void PopulateListWithColorGradients() { listViewColorGradients.BeginUpdate(); listViewColorGradients.Items.Clear(); listViewColorGradients.LargeImageList = new ImageList(); listViewColorGradients.LargeImageList.ColorDepth = ColorDepth.Depth32Bit; foreach (KeyValuePair <string, ColorGradient> kvp in Library) { ColorGradient gradient = kvp.Value; string name = kvp.Key; listViewColorGradients.LargeImageList.ImageSize = new Size(68, 68); var image = gradient.GenerateColorGradientImage(new Size(68, 68), false); Graphics gfx = Graphics.FromImage(image); gfx.DrawRectangle(_borderPen, 0, 0, 68, 68); listViewColorGradients.LargeImageList.Images.Add(name, image); ListViewItem item = new ListViewItem(); item.Text = name; item.Name = name; item.ImageKey = name; item.Tag = gradient; listViewColorGradients.Items.Add(item); } listViewColorGradients.EndUpdate(); buttonEditColorGradient.Enabled = false; buttonDeleteColorGradient.Enabled = false; buttonEditColorGradient.ForeColor = ThemeColorTable.ForeColorDisabled; buttonDeleteColorGradient.ForeColor = ThemeColorTable.ForeColorDisabled; ; }
public ColorGradientEditor(ColorGradient gradient) { InitializeComponent(); gradientEditPanel.GradientChanged += GradientChangedHandler; Gradient = gradient; }
/// <summary> /// Creates a new pair with the provided <see cref="ColorGradient"/> and <see cref="CurveType"/> /// </summary> /// <param name="cg"></param> /// <param name="type"></param> public GradientLevelPair(ColorGradient cg, CurveType type) { ColorGradient = cg; Curve = new Curve(type); }
/// <summary> /// Deep copy constructor. /// </summary> /// <param name="other"></param> public ColorGradient(ColorGradient other) { CloneFrom(other); }
/// <summary> /// Creates a new pair with a default <see cref="ColorGradient"/> and <see cref="Curve"/> /// </summary> public GradientLevelPair() { ColorGradient = new ColorGradient(); Curve = new Curve(CurveType.Flat100); }
/// <summary> /// Creates a new pair with the provided <see cref="ColorGradient"/> and a default <see cref="Curve"/> /// </summary> /// <param name="cg"></param> public GradientLevelPair(ColorGradient cg) { ColorGradient = cg; Curve = new Curve(); }
/// <summary> /// Creates a new pair with a <see cref="ColorGradient"/> based on the provided <see cref="Color"/> and <see cref="CurveType"/> /// </summary> /// <param name="c"></param> /// <param name="type"></param> public GradientLevelPair(Color c, CurveType type) { ColorGradient = new ColorGradient(c); Curve = new Curve(type); }
//Convienience constructors. /// <summary> /// Creates a new pair with a <see cref="ColorGradient"/> based on the provided <see cref="Color"/> and a default <see cref="Curve"/> /// </summary> /// <param name="c"></param> public GradientLevelPair(Color c) { ColorGradient = new ColorGradient(c); Curve = new Curve(); }
public void UnlinkFromLibrary() { LibraryReferenceName = ""; _libraryReferencedGradient = null; }
/// <summary> /// Creates a new pair with a <see cref="ColorGradient"/> based on the provided <see cref="Color"/> and <see cref="Curve"/> /// </summary> /// <param name="color"></param> /// <param name="c"></param> public GradientLevelPair(Color color, Curve c) { ColorGradient = new ColorGradient(color); Curve = c; }
/// <summary> /// Creates a new pair with the provided <see cref="ColorGradient"/> and <see cref="Curve"/> /// </summary> /// <param name="cg"></param> /// <param name="c"></param> public GradientLevelPair(ColorGradient cg, Curve c) { ColorGradient = cg; Curve = c; }