public override void ControlInsidePropertyItemControlWasCreated() { base.ControlInsidePropertyItemControlWasCreated(); var control = (IHCColorValuePowered)CreatedControlInsidePropertyItemControl; //!!!! //control.TrackBarPower.MouseWheel += TrackBarPower_MouseWheel; //get range var array = Property.GetCustomAttributes(typeof(ApplicableRangeColorValuePowerAttribute), true); if (array.Length != 0) { powerRange = (ApplicableRangeColorValuePowerAttribute)array[0]; } if (powerRange == null) { powerRange = new ApplicableRangeColorValuePowerAttribute(0, 100, RangeAttribute.ConvenientDistributionEnum.Exponential, 2); } //configure track bar //if( powerRange != null ) { var trackBar = control.TrackBarPower; trackBarDisableValueChangedEvent = true; powerRange.GetTrackBarMinMax(false, out int min, out int max); trackBar.Minimum = min; trackBar.Maximum = max; trackBar.LargeChange = (trackBar.Maximum - trackBar.Minimum) / 10; trackBar.SmallChange = (trackBar.Maximum - trackBar.Minimum) / 100; trackBarDisableValueChangedEvent = false; trackBar.GotFocus += TrackBar_GotFocus; trackBar.LostFocus += TrackBar_LostFocus; trackBar.MouseUp += TrackBar_MouseUp; trackBar.ValueChanged += TrackBar_ValueChanged; } ////disable track bar ////!!!!может еще каким-то условием показывать/скрывать //if( powerRange == null ) //{ // control.TrackBar1.Enabled = false; // control.TrackBar1.Visible = false; // control.TextBox1.Dock = DockStyle.Fill; //} }
public ColorValuePoweredSelectControl(HCItemProperty itemProperty) { InitializeComponent(); AddOkCancelButtons(out okButton, out cancelButton); this.itemProperty = itemProperty; powered = ReferenceUtility.GetUnreferencedType(itemProperty.Property.Type.GetNetType()) == typeof(ColorValuePowered); var values = itemProperty.GetValues(); if (values == null) { return; } //!!!!multiselection var value = values[0]; ColorValuePowered initValue; bool readOnly; { var netType = itemProperty.Property.Type.GetNetType(); bool isReferenceType = ReferenceUtility.IsReferenceType(netType); bool referenceSpecified = false; IReference iReference = null; if (isReferenceType && value != null) { iReference = (IReference)value; referenceSpecified = !string.IsNullOrEmpty(iReference.GetByReference); } readOnly = referenceSpecified; } if (powered) { initValue = (ColorValuePowered)ReferenceUtility.GetUnreferencedValue(value); } else { var c = (ColorValue)ReferenceUtility.GetUnreferencedValue(value); initValue = new ColorValuePowered(c.Red, c.Green, c.Blue, c.Alpha, 1); } //for( int n = 0; n < propertyOwners.Length; n++ ) //{ // ColorValue v = (ColorValue)property.GetValue( propertyOwners[ n ], null ); // if( n != 0 ) // { // if( value != v ) // { // value = new ColorValue( 1, 1, 1 ); // break; // } // } // else // value = v; //} bool noAlpha = itemProperty.Property.GetCustomAttributes(typeof(ColorValueNoAlphaAttribute), true).Length != 0; ApplicableRangeColorValuePowerAttribute powerRange = null; if (powered) { var array = itemProperty.Property.GetCustomAttributes(typeof(ApplicableRangeColorValuePowerAttribute), true); if (array.Length != 0) { powerRange = (ApplicableRangeColorValuePowerAttribute)array[0]; } } Init(initValue, noAlpha, powered, powerRange, readOnly); propertyItemForUndoSupport = itemProperty.GetItemInHierarchyToRestoreValues(); propertyItemForUndoSupport.SaveValuesToRestore(); EditorThemeUtility.ApplyDarkThemeToForm(this); }
public void Init(ColorValuePowered value, bool noAlpha, bool powered, ApplicableRangeColorValuePowerAttribute powerRange, bool readOnly) { this.noAlpha = noAlpha; this.powered = powered; if (powered && powerRange == null) { powerRange = new ApplicableRangeColorValuePowerAttribute(0, 100, RangeAttribute.ConvenientDistributionEnum.Exponential, 2); } this.powerRange = powerRange; this.readOnly = readOnly; noUpdate = true; UpdateRGBAControls(value.Color, null); if (powered) { numericUpDownPower.Minimum = (decimal)powerRange.Minimum; numericUpDownPower.Maximum = (decimal)powerRange.Maximum; powerRange.GetTrackBarMinMax(false, out int min, out int max); trackBarPower.Minimum = min; trackBarPower.Maximum = max; trackBarPower.LargeChange = (trackBarPower.Maximum - trackBarPower.Minimum) / 10; trackBarPower.SmallChange = (trackBarPower.Maximum - trackBarPower.Minimum) / 100; UpdatePowerControls(value.Power, null); } else { numericUpDownPower.Enabled = false; trackBarPower.Enabled = false; label5.Enabled = false; numericUpDownPower.Minimum = 0; numericUpDownPower.Maximum = 1; numericUpDownPower.Value = 1; trackBarPower.Minimum = 0; trackBarPower.Maximum = 1; trackBarPower.Value = 1; } //no alpha channel if (noAlpha) { numericUpDownAlpha.Enabled = false; trackBarAlpha.Enabled = false; label4.Enabled = false; } PrepareColorControls(); if (readOnly) { colorWheel.Enabled = false; colorGradientControl.Enabled = false; numericUpDownRed.Enabled = false; numericUpDownGreen.Enabled = false; numericUpDownBlue.Enabled = false; numericUpDownAlpha.Enabled = false; numericUpDownPower.Enabled = false; //!!!!вверх, вниз всё равно работают при ReadOnly //numericUpDownRed.ReadOnly = true; //numericUpDownGreen.ReadOnly = true; //numericUpDownBlue.ReadOnly = true; //numericUpDownAlpha.ReadOnly = true; //numericUpDownPower.ReadOnly = true; trackBarAlpha.Enabled = false; trackBarBlue.Enabled = false; trackBarGreen.Enabled = false; trackBarRed.Enabled = false; trackBarPower.Enabled = false; } numericUpDownRed.TextChanged += NumericUpDown_TextChanged; numericUpDownGreen.TextChanged += NumericUpDown_TextChanged; numericUpDownBlue.TextChanged += NumericUpDown_TextChanged; numericUpDownAlpha.TextChanged += NumericUpDown_TextChanged; numericUpDownPower.TextChanged += NumericUpDown_TextChanged; noUpdate = false; }