Skip to content

Commit

Permalink
Fix ColorPicker Value setter.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Kovalenko committed Oct 19, 2014
1 parent 6151bb2 commit d0c105f
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/editors/xrSdkControls/Controls/ColorPicker/ColorPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public sealed partial class ColorPicker : UserControl

private Color color;
private bool hexadecimal;
private bool ignoreOnChanged = false;

public ColorPicker()
{
Expand All @@ -24,7 +25,15 @@ public Color Value
get { return color; }
set
{
if (color == value)
return;
color = value;
ignoreOnChanged = true;
nslAlpha.Value = color.A;
nslRed.Value = color.R;
nslGreen.Value = color.G;
nslBlue.Value = color.B;
ignoreOnChanged = false;
UpdateColor();
}
}
Expand Down Expand Up @@ -60,9 +69,17 @@ protected override void OnLoad(EventArgs e)
chkHexadecimal.CheckedChanged += (obj, args) => Hexadecimal = chkHexadecimal.Checked;
UpdateColor();
}


private void OnColorChanged()
{
if (!ignoreOnChanged && ColorChanged != null)
ColorChanged(this, Value);
}

private void UpdateColor()
{
if (ignoreOnChanged)
return;
var newColor = Color.FromArgb(
Convert.ToInt32(nslAlpha.Value),
Convert.ToInt32(nslRed.Value),
Expand All @@ -71,8 +88,7 @@ private void UpdateColor()
if (pbColor.ColorSample == newColor)
return;
pbColor.ColorSample = newColor;
if (ColorChanged != null)
ColorChanged(this, Value);
OnColorChanged();
}
}
}

0 comments on commit d0c105f

Please sign in to comment.