/// <summary> /// Edits the given object value using the editor style provided by the <see cref="M:System.Drawing.Design.ColorEditor.GetEditStyle(System.ComponentModel.ITypeDescriptorContext)"/> method. /// </summary> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that can be used to gain additional context information.</param> /// <param name="provider">An <see cref="T:System.IServiceProvider"/> through which editing services may be obtained.</param> /// <param name="value">An instance of the value being edited.</param> /// <returns> /// The new value of the object. If the value of the object has not changed, this should return the same object it was passed. /// </returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { var xnaColour = (VariableFloat3)value; if (provider != null) { var edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (edSvc == null) { return(value); } this.StartColourPicker(edSvc, Colour.FromArgb(1, (int)(xnaColour.Value.X * 255f), (int)(xnaColour.Value.Y * 255f), (int)(xnaColour.Value.Z * 255f))); edSvc.DropDownControl(this.ColourPicker); if ((this.ColorPickerValue != null) && (((Colour)this.ColorPickerValue) != Colour.Empty)) { var chosenColour = (Colour)this.ColorPickerValue; value = new VariableFloat3 { Value = new Vector3 { X = chosenColour.R / 255f, Y = chosenColour.G / 255f, Z = chosenColour.B / 255f } }; } this.EndColourPicker(); } return(value); }
/// <summary> /// Edits the given object value using the editor style provided by the <see cref="M:System.Drawing.Design.ColorEditor.GetEditStyle(System.ComponentModel.ITypeDescriptorContext)"/> method. /// </summary> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that can be used to gain additional context information.</param> /// <param name="provider">An <see cref="T:System.IServiceProvider"/> through which editing services may be obtained.</param> /// <param name="value">An instance of the value being edited.</param> /// <returns> /// The new value of the object. If the value of the object has not changed, this should return the same object it was passed. /// </returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { var xnaColour = (VariableFloat3)value; if (provider != null) { var edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (edSvc == null) return value; this.StartColourPicker(edSvc, Colour.FromArgb(1, (int)(xnaColour.Value.X * 255f), (int)(xnaColour.Value.Y * 255f), (int)(xnaColour.Value.Z * 255f))); edSvc.DropDownControl(this.ColourPicker); if ((this.ColorPickerValue != null) && (((Colour)this.ColorPickerValue) != Colour.Empty)) { var chosenColour = (Colour)this.ColorPickerValue; value = new VariableFloat3 { Value = new Vector3 { X = chosenColour.R / 255f, Y = chosenColour.G / 255f, Z = chosenColour.B / 255f } }; } this.EndColourPicker(); } return value; }