static ColorRampConverter() { // populate colorRampList = new ColorRampList(); ColorRampValueList valueList = new ColorRampValueList(); valueList.Add(0, Color.Red); valueList.Add(50, Color.Blue); valueList.Add(100, Color.Green); valueList.Text = "RedBlueGreen"; colorRampList.Add(valueList.Text, valueList); valueList = new ColorRampValueList(); valueList.Add(0, Color.Red); valueList.Add(100, Color.Orange); valueList.Text = "RedOrange"; colorRampList.Add(valueList.Text, valueList); // add extended elements valueList = new ColorRampValueList(); valueList.Add(0, Color.Red); valueList.Add(20, Color.Orange); valueList.Add(40, Color.Brown); valueList.Add(60, Color.Cyan); valueList.Add(80, Color.Magenta); valueList.Add(100, Color.Empty); valueList.Text = "Random values"; valueList.Style = ColorRampStyle.Discrete; colorRampList.Add(valueList.Text, valueList); valueList = new ColorRampValueList(); valueList.Text = "Empty"; colorRampList.Add(valueList.Text, valueList); valueList = new ColorRampValueList(); valueList.Text = "New color ramp ..."; colorRampList.Add(valueList.Text, valueList); }
/// <summary> /// Paints a representation of the value of an object using the specified PaintValueEventArgs. /// </summary> /// <param name="e">A PaintValueEventArgs that indicates what to paint and where to paint it.</param> public override void PaintValue(PaintValueEventArgs e) { if (e.Value != null) { ColorRampValueList valueList = (ColorRampValueList)e.Value; if (valueList.Count > 0) { for (int i = 1; i < valueList.Count; i++) { Rectangle rect = new Rectangle( e.Bounds.X + (int)(valueList.Keys[i - 1] * e.Bounds.Width / 100), e.Bounds.Y, (int)((valueList.Keys[i] - valueList.Keys[i - 1]) * e.Bounds.Width / 100), e.Bounds.Height); if (valueList.Style == ColorRampStyle.Discrete) { using (Brush brush = new SolidBrush(valueList.Values[i - 1])) { e.Graphics.FillRectangle(brush, rect); } } else { using (Brush brush = new LinearGradientBrush(rect, valueList.Values[i - 1], valueList.Values[i], 0.0)) { e.Graphics.FillRectangle(brush, rect); } } } } } }
public void AddValue(ColorRampValueList value) { if (!colorRampList.ContainsKey(value.Text)) { colorRampList.Add(value.Text, value); } }
/// <summary> /// Constructs a new NewColorRampForm class. /// </summary> public ColorRampForm(ColorRampEditor editor, string key) { this.editor = editor; InitializeComponent(); if (key != null && ColorRampConverter.ColorRampList.ContainsKey(key)) { values = ColorRampConverter.ColorRampList[key]; this.Text = "Edit Colour Ramp"; textBoxName.Text = key; textBoxName.Enabled = false; if (values.ContainsKey(0)) { colorPickerStart.Value = values[0]; } if (values.ContainsKey(100)) { colorPickerEnd.Value = values[100]; } } else { values = new ColorRampValueList(); values.Add(0, colorPickerStart.Value); values.Add(100, colorPickerEnd.Value); } comboBoxStyle.DataSource = Enum.GetValues(typeof(ColorRampStyle)); comboBoxStyle.SelectedItem = ColorRampStyle.Gradient; UpdateState(); UpdatePreview(); }
public void EditValue(string key) { ColorRampForm dialog = new ColorRampForm((ColorRampEditor)this.Editor, key); if (dialog.ShowDialog(this) == DialogResult.OK) { Value = dialog.Value; } }
public void NewValue() { ColorRampForm dialog = new ColorRampForm((ColorRampEditor)this.Editor, null); if (dialog.ShowDialog(this) == DialogResult.OK) { ColorRampConverter converter = (ColorRampConverter)this.Converter; converter.AddValue(dialog.Value); Value = dialog.Value; } }
public ColorStopForm(ColorRampValueList values, int index) { this.values = values; this.index = index; InitializeComponent(); if (index >= 0) { colorPickerStopColor.Value = values.Values[index]; textBoxOffset.Text = values.Keys[index].ToString(); } }