Exemplo n.º 1
0
		//updates all controls
		private void UpdateUI()
		{
			if (edit.Gradient == null) {
				grpStops.Enabled = false;
			}
			else {
				grpStops.Enabled = true;
				//ColorPoint cpt = edit.Selection as ColorPoint;
				if (edit.Selection.Count > 0) {
					vColorLoc.Enabled = true;
					lblColorSelect.Enabled = btnDeleteColor.Enabled = !edit.FocusSelection;
					//
					vColorLoc.Value =
						(int) ((edit.FocusSelection ? edit.Selection.First().Focus : edit.Selection.First().Position)*100.0);

					if (edit.Selection.Count == 0)
						lblColorSelect.Color = Color.DimGray;
					else {
						ColorPoint cpt = edit.Selection.First() as ColorPoint;
						lblColorSelect.Color = edit.FocusSelection
						                       	? Color.DimGray
						                       	: lblColorSelect.OldColor = (_xyz = cpt.Color).ToRGB().ToArgb();
					}
				}
				else {
					lblColorSelect.Enabled = vColorLoc.Enabled = btnDeleteColor.Enabled = false;
					lblColorSelect.Color = lblColorSelect.OldColor = Color.DimGray;
					vColorLoc.Value = 0;
				}
			}
		}
Exemplo n.º 2
0
 public static LAB FromXYZ(XYZ value)
 {
     //normalize values
     double x=DriveCurve(value.X/XYZ.White.X),
         y=DriveCurve(value.Y/XYZ.White.Y),
         z=DriveCurve(value.Z/XYZ.White.Z);
     //return value
     return new LAB(
         (116.0*y)-16.0,
         500.0*(x-y),
         200.0*(y-z));
 }
Exemplo n.º 3
0
        // edits the selected color in the 'edit' control
        private void editSelectedPoints()
        {
            if (edit.Gradient == null || edit.FocusSelection)
                return;

            if (DiscreteColors) {
                List<Color> selectedColors = new List<Color>();
                foreach (ColorGradient.Point point in edit.Selection) {
                    ColorPoint pt = point as ColorPoint;
                    if (pt == null)
                        continue;
                    selectedColors.Add(pt.Color.ToRGB().ToArgb());
                }

                using (DiscreteColorPicker picker = new DiscreteColorPicker()) {
                    picker.ValidColors = ValidDiscreteColors;
                    picker.SelectedColors = selectedColors;
                    if (picker.ShowDialog() == DialogResult.OK) {
                        if (picker.SelectedColors.Count() == 0) {
                            DeleteColor();
                        }
                        else if (picker.SelectedColors.Count() == selectedColors.Count) {
                            int i = 0;
                            foreach (Color selectedColor in picker.SelectedColors) {
                                ColorPoint pt = edit.Selection[i] as ColorPoint;
                                pt.Color = XYZ.FromRGB(selectedColor);
                            }
                        }
                        else {
                            double position = edit.Selection.First().Position;

                            foreach (ColorGradient.Point point in edit.Selection) {
                                edit.Gradient.Colors.Remove(point as ColorPoint);
                            }

                            foreach (Color selectedColor in picker.SelectedColors) {
                                ColorPoint newPoint = new ColorPoint(selectedColor, position);
                                edit.Gradient.Colors.Add(newPoint);
                            }
                        }
                    }
                }
            }
            else {
                if (edit.Selection.Count > 1)
                    MessageBox.Show("Non-discrete color gradient, >1 selected point. oops! please report it.");
                ColorPoint pt = edit.Selection.FirstOrDefault() as ColorPoint;
                if (pt == null)
                    return;
                using (ColorPicker frm = new ColorPicker(_mode, _fader)) {
                    frm.LockValue_V = LockColorEditorHSV_Value;
                    frm.Color = _xyz;
                    if (frm.ShowDialog(this.FindForm()) == DialogResult.OK) {
                        pt.Color = _xyz = frm.Color;
                        lblColorSelect.Color = _xyz.ToRGB().ToArgb();
                        _mode = frm.SecondaryMode;
                        _fader = frm.PrimaryFader;
                    }
                }
            }
        }
 // edits the selected color in the 'edit' control
 private void editSelectedColor()
 {
     if (edit.Gradient == null || edit.FocusSelection)
         return;
     ColorPoint pt = edit.Selection as ColorPoint;
     if (pt == null)
         return;
     using (ColorPicker frm = new ColorPicker(_mode, _fader)) {
         frm.LockValue_V = LockColorEditorHSV_Value;
         frm.Color = _xyz;
         if (frm.ShowDialog(this.FindForm()) == DialogResult.OK) {
             pt.Color = _xyz = frm.Color;
             lblColorSelect.Color = _xyz.ToRGB().ToArgb();
             _mode = frm.SecondaryMode;
             _fader = frm.PrimaryFader;
         }
     }
 }
Exemplo n.º 5
0
 private void _module_ColorChanged(object sender, EventArgs e)
 {
     if (_module == null) return;
     InternalColor = _module.XYZ;
     lblColorOut.Color = InternalColor.ToRGB();
     UpdatetbValue(null);
 }
Exemplo n.º 6
0
 private void whiteButton_Click(object sender, EventArgs e)
 {
     InternalColor = XYZ.FromRGB(new RGB(255, 255, 255));
     lblColorOut.Color = InternalColor.ToRGB();
     UpdatetbValue(null);
 }
Exemplo n.º 7
0
        private void tbValue_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (!(sender is TextBox)) return;
            if (e.KeyCode == Keys.Return) {
                UpdatetbValue(null);
                e.Handled = true;
                return;
            }
            double value;
            if (!double.TryParse(((TextBox) sender).Text,
                                 System.Globalization.NumberStyles.Integer,
                                 null, out value)) return;

            #region hsv  textboxes

            if (sender == tbHSV_H) {
                HSV chsv = HSV.FromRGB(InternalColor.ToRGB());
                chsv.H = value/360.0;
                InternalColor = XYZ.FromRGB(chsv.ToRGB());
            }
            else if (sender == tbHSV_S) {
                HSV chsv = HSV.FromRGB(InternalColor.ToRGB());
                chsv.S = value/100.0;
                InternalColor = XYZ.FromRGB(chsv.ToRGB());
            }
            else if (sender == tbHSV_V) {
                HSV chsv = HSV.FromRGB(InternalColor.ToRGB());
                chsv.V = value/100.0;
                InternalColor = XYZ.FromRGB(chsv.ToRGB());
            }
                #endregion
                #region secondary textboxes

            else if (_mode == Mode.HSV_RGB) {
                RGB crgb = InternalColor.ToRGB();
                if (sender == tbSecond_1) {
                    crgb.R = value/255.0;
                }
                else if (sender == tbSecond_2) {
                    crgb.G = value/255.0;
                }
                else //sender==tbSecond_3
                {
                    crgb.B = value/255.0;
                }
                InternalColor = XYZ.FromRGB(crgb);
            }
            else if (_mode == Mode.HSV_LAB) {
                LAB clab = LAB.FromXYZ(InternalColor);
                if (sender == tbSecond_1) {
                    clab.L = value;
                }
                else if (sender == tbSecond_2) {
                    clab.a = value;
                }
                else //sender==tbSecond_3
                {
                    clab.b = value;
                }
                InternalColor = clab.ToXYZ();
            }

            #endregion

            //update ui
            _module.XYZ = InternalColor;
            lblColorOut.Color = InternalColor.ToRGB();
            UpdatetbValue((TextBox) sender);
        }
Exemplo n.º 8
0
 private void lblColorOut_ColorChanged(object sender, System.EventArgs e)
 {
     InternalColor = XYZ.FromRGB(lblColorOut.Color);
     _module.XYZ = InternalColor;
     UpdatetbValue(null);
 }
Exemplo n.º 9
0
        // edits the selected color in the 'edit' control
        private void editSelectedPoints()
        {
            if (edit.Gradient == null || edit.FocusSelection)
                return;

            if (DiscreteColors) {
                List<Color> selectedColors = new List<Color>();
                foreach (ColorGradient.Point point in edit.Selection) {
                    ColorPoint pt = point as ColorPoint;
                    if (pt == null)
                        continue;
                    selectedColors.Add(pt.Color.ToRGB().ToArgb());
                }

                using (DiscreteColorPicker picker = new DiscreteColorPicker()) {
                    picker.ValidColors = ValidDiscreteColors;
                    picker.SelectedColors = selectedColors;
                    if (picker.ShowDialog() == DialogResult.OK) {
                        if (picker.SelectedColors.Count() == 0) {
                            DeleteColor();
                        }
                        else if (picker.SelectedColors.Count() == selectedColors.Count) {
                            int i = 0;
                            foreach (Color selectedColor in picker.SelectedColors) {
                                ColorPoint pt = edit.Selection[i] as ColorPoint;
                                pt.Color = XYZ.FromRGB(selectedColor);
                            }
                        }
                        else {
                            double position = edit.Selection.First().Position;

                            foreach (ColorGradient.Point point in edit.Selection) {
                                edit.Gradient.Colors.Remove(point as ColorPoint);
                            }

                            foreach (Color selectedColor in picker.SelectedColors) {
                                ColorPoint newPoint = new ColorPoint(selectedColor, position);
                                edit.Gradient.Colors.Add(newPoint);
                            }
                        }
                    }
                }
            }
            else {
                if (edit.Selection.Count > 1)
                {
                    //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                    MessageBoxForm.msgIcon = SystemIcons.Error; //this is used if you want to add a system icon to the message form.
                    var messageBox = new MessageBoxForm("Non-discrete color gradient, >1 selected point. oops! please report it.", "Delete library gradient?", false, false);
                    messageBox.ShowDialog();
                }
                ColorPoint pt = edit.Selection.FirstOrDefault() as ColorPoint;
                if (pt == null)
                    return;
                using (ColorPicker frm = new ColorPicker(_mode, _fader)) {
                    frm.LockValue_V = LockColorEditorHSV_Value;
                    frm.Color = _xyz;
                    if (frm.ShowDialog(this.FindForm()) == DialogResult.OK) {
                        pt.Color = _xyz = frm.Color;
                        lblColorSelect.Color = _xyz.ToRGB().ToArgb();
                        _mode = frm.SecondaryMode;
                        _fader = frm.PrimaryFader;
                    }
                }
            }
        }