Skip to content

Commit d0c105f

Browse files
author
Pavel Kovalenko
committed
Fix ColorPicker Value setter.
1 parent 6151bb2 commit d0c105f

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/editors/xrSdkControls/Controls/ColorPicker/ColorPicker.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public sealed partial class ColorPicker : UserControl
1111

1212
private Color color;
1313
private bool hexadecimal;
14+
private bool ignoreOnChanged = false;
1415

1516
public ColorPicker()
1617
{
@@ -24,7 +25,15 @@ public Color Value
2425
get { return color; }
2526
set
2627
{
28+
if (color == value)
29+
return;
2730
color = value;
31+
ignoreOnChanged = true;
32+
nslAlpha.Value = color.A;
33+
nslRed.Value = color.R;
34+
nslGreen.Value = color.G;
35+
nslBlue.Value = color.B;
36+
ignoreOnChanged = false;
2837
UpdateColor();
2938
}
3039
}
@@ -60,9 +69,17 @@ protected override void OnLoad(EventArgs e)
6069
chkHexadecimal.CheckedChanged += (obj, args) => Hexadecimal = chkHexadecimal.Checked;
6170
UpdateColor();
6271
}
63-
72+
73+
private void OnColorChanged()
74+
{
75+
if (!ignoreOnChanged && ColorChanged != null)
76+
ColorChanged(this, Value);
77+
}
78+
6479
private void UpdateColor()
6580
{
81+
if (ignoreOnChanged)
82+
return;
6683
var newColor = Color.FromArgb(
6784
Convert.ToInt32(nslAlpha.Value),
6885
Convert.ToInt32(nslRed.Value),
@@ -71,8 +88,7 @@ private void UpdateColor()
7188
if (pbColor.ColorSample == newColor)
7289
return;
7390
pbColor.ColorSample = newColor;
74-
if (ColorChanged != null)
75-
ColorChanged(this, Value);
91+
OnColorChanged();
7692
}
7793
}
7894
}

0 commit comments

Comments
 (0)