Browse Source

Rename 'channel' to 'component'

pull/7842/head
robloo 5 years ago
parent
commit
397fd5068f
  1. 44
      src/Avalonia.Controls.ColorPicker/ColorSpectrum/ColorHelpers.cs
  2. 30
      src/Avalonia.Controls.ColorPicker/ColorSpectrum/ColorSpectrum.Properties.cs
  3. 231
      src/Avalonia.Controls.ColorPicker/ColorSpectrum/ColorSpectrum.cs
  4. 18
      src/Avalonia.Controls.ColorPicker/ColorSpectrum/Hsv.cs
  5. 2
      src/Avalonia.Controls.ColorPicker/ColorSpectrum/IncrementAmount.cs
  6. 2
      src/Avalonia.Controls.ColorPicker/ColorSpectrum/IncrementDirection.cs
  7. 20
      src/Avalonia.Controls.ColorPicker/ColorSpectrum/Rgb.cs
  8. 18
      src/Avalonia.Controls.ColorPicker/ColorSpectrumComponents.cs
  9. 33
      src/Avalonia.Controls.ColorPicker/HsvChannel.cs
  10. 47
      src/Avalonia.Controls.ColorPicker/HsvComponent.cs

44
src/Avalonia.Controls.ColorPicker/ColorSpectrum/ColorHelpers.cs

@ -26,9 +26,9 @@ namespace Avalonia.Controls.Primitives
return string.Empty; return string.Empty;
} }
public static Hsv IncrementColorChannel( public static Hsv IncrementColorComponent(
Hsv originalHsv, Hsv originalHsv,
HsvChannel channel, HsvComponent component,
IncrementDirection direction, IncrementDirection direction,
IncrementAmount amount, IncrementAmount amount,
bool shouldWrap, bool shouldWrap,
@ -52,25 +52,25 @@ namespace Avalonia.Controls.Primitives
// If we're adding a large increment, then we want to snap to the next // If we're adding a large increment, then we want to snap to the next
// or previous major value - for hue, this is every increment of 30; // or previous major value - for hue, this is every increment of 30;
// for saturation and value, this is every increment of 10. // for saturation and value, this is every increment of 10.
switch (channel) switch (component)
{ {
case HsvChannel.Hue: case HsvComponent.Hue:
valueToIncrement = ref newHsv.H; valueToIncrement = ref newHsv.H;
incrementAmount = amount == IncrementAmount.Small ? 1 : 30; incrementAmount = amount == IncrementAmount.Small ? 1 : 30;
break; break;
case HsvChannel.Saturation: case HsvComponent.Saturation:
valueToIncrement = ref newHsv.S; valueToIncrement = ref newHsv.S;
incrementAmount = amount == IncrementAmount.Small ? 1 : 10; incrementAmount = amount == IncrementAmount.Small ? 1 : 10;
break; break;
case HsvChannel.Value: case HsvComponent.Value:
valueToIncrement = ref newHsv.V; valueToIncrement = ref newHsv.V;
incrementAmount = amount == IncrementAmount.Small ? 1 : 10; incrementAmount = amount == IncrementAmount.Small ? 1 : 10;
break; break;
default: default:
throw new InvalidOperationException("Invalid HsvChannel."); throw new InvalidOperationException("Invalid HsvComponent.");
} }
double previousValue = valueToIncrement; double previousValue = valueToIncrement;
@ -99,14 +99,14 @@ namespace Avalonia.Controls.Primitives
// While working with named colors, we're going to need to be working in actual HSV units, // While working with named colors, we're going to need to be working in actual HSV units,
// so we'll divide the min bound and max bound by 100 in the case of saturation or value, // so we'll divide the min bound and max bound by 100 in the case of saturation or value,
// since we'll have received units between 0-100 and we need them within 0-1. // since we'll have received units between 0-100 and we need them within 0-1.
if (channel == HsvChannel.Saturation || if (component == HsvComponent.Saturation ||
channel == HsvChannel.Value) component == HsvComponent.Value)
{ {
minBound /= 100; minBound /= 100;
maxBound /= 100; maxBound /= 100;
} }
newHsv = FindNextNamedColor(originalHsv, channel, direction, shouldWrap, minBound, maxBound); newHsv = FindNextNamedColor(originalHsv, component, direction, shouldWrap, minBound, maxBound);
} }
return newHsv; return newHsv;
@ -114,7 +114,7 @@ namespace Avalonia.Controls.Primitives
public static Hsv FindNextNamedColor( public static Hsv FindNextNamedColor(
Hsv originalHsv, Hsv originalHsv,
HsvChannel channel, HsvComponent component,
IncrementDirection direction, IncrementDirection direction,
bool shouldWrap, bool shouldWrap,
double minBound, double minBound,
@ -136,28 +136,28 @@ namespace Avalonia.Controls.Primitives
ref double newValue = ref newHsv.H; ref double newValue = ref newHsv.H;
double incrementAmount = 0.0; double incrementAmount = 0.0;
switch (channel) switch (component)
{ {
case HsvChannel.Hue: case HsvComponent.Hue:
originalValue = originalHsv.H; originalValue = originalHsv.H;
newValue = ref newHsv.H; newValue = ref newHsv.H;
incrementAmount = 1; incrementAmount = 1;
break; break;
case HsvChannel.Saturation: case HsvComponent.Saturation:
originalValue = originalHsv.S; originalValue = originalHsv.S;
newValue = ref newHsv.S; newValue = ref newHsv.S;
incrementAmount = 0.01; incrementAmount = 0.01;
break; break;
case HsvChannel.Value: case HsvComponent.Value:
originalValue = originalHsv.V; originalValue = originalHsv.V;
newValue = ref newHsv.V; newValue = ref newHsv.V;
incrementAmount = 0.01; incrementAmount = 0.01;
break; break;
default: default:
throw new InvalidOperationException("Invalid HsvChannel."); throw new InvalidOperationException("Invalid HsvComponent.");
} }
bool shouldFindMidPoint = true; bool shouldFindMidPoint = true;
@ -228,28 +228,28 @@ namespace Avalonia.Controls.Primitives
ref double currentValue = ref currentHsv.H; ref double currentValue = ref currentHsv.H;
double wrapIncrement = 0; double wrapIncrement = 0;
switch (channel) switch (component)
{ {
case HsvChannel.Hue: case HsvComponent.Hue:
startValue = ref startHsv.H; startValue = ref startHsv.H;
currentValue = ref currentHsv.H; currentValue = ref currentHsv.H;
wrapIncrement = 360.0; wrapIncrement = 360.0;
break; break;
case HsvChannel.Saturation: case HsvComponent.Saturation:
startValue = ref startHsv.S; startValue = ref startHsv.S;
currentValue = ref currentHsv.S; currentValue = ref currentHsv.S;
wrapIncrement = 1.0; wrapIncrement = 1.0;
break; break;
case HsvChannel.Value: case HsvComponent.Value:
startValue = ref startHsv.V; startValue = ref startHsv.V;
currentValue = ref currentHsv.V; currentValue = ref currentHsv.V;
wrapIncrement = 1.0; wrapIncrement = 1.0;
break; break;
default: default:
throw new InvalidOperationException("Invalid HsvChannel."); throw new InvalidOperationException("Invalid HsvComponent.");
} }
while (newColorName == currentColorName) while (newColorName == currentColorName)
@ -316,7 +316,7 @@ namespace Avalonia.Controls.Primitives
return newHsv; return newHsv;
} }
public static double IncrementAlphaChannel( public static double IncrementAlphaComponent(
double originalAlpha, double originalAlpha,
IncrementDirection direction, IncrementDirection direction,
IncrementAmount amount, IncrementAmount amount,

30
src/Avalonia.Controls.ColorPicker/ColorSpectrum/ColorSpectrum.Properties.cs

@ -32,24 +32,24 @@ namespace Avalonia.Controls.Primitives
Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF)); Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF));
/// <summary> /// <summary>
/// Gets or sets the two HSV color channels displayed by the spectrum. /// Gets or sets the two HSV color components displayed by the spectrum.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// Internally, the <see cref="ColorSpectrum"/> uses the HSV color model. /// Internally, the <see cref="ColorSpectrum"/> uses the HSV color model.
/// </remarks> /// </remarks>
public ColorSpectrumChannels Channels public ColorSpectrumComponents Components
{ {
get => GetValue(ChannelsProperty); get => GetValue(ComponentsProperty);
set => SetValue(ChannelsProperty, value); set => SetValue(ComponentsProperty, value);
} }
/// <summary> /// <summary>
/// Defines the <see cref="Channels"/> property. /// Defines the <see cref="Components"/> property.
/// </summary> /// </summary>
public static readonly StyledProperty<ColorSpectrumChannels> ChannelsProperty = public static readonly StyledProperty<ColorSpectrumComponents> ComponentsProperty =
AvaloniaProperty.Register<ColorSpectrum, ColorSpectrumChannels>( AvaloniaProperty.Register<ColorSpectrum, ColorSpectrumComponents>(
nameof(Channels), nameof(Components),
ColorSpectrumChannels.HueSaturation); ColorSpectrumComponents.HueSaturation);
/// <summary> /// <summary>
/// Gets or sets the currently selected color in the HSV color model. /// Gets or sets the currently selected color in the HSV color model.
@ -74,7 +74,7 @@ namespace Avalonia.Controls.Primitives
new HsvColor(1, 0, 0, 1)); new HsvColor(1, 0, 0, 1));
/// <summary> /// <summary>
/// Gets or sets the maximum value of the Hue channel in the range from 0..359. /// Gets or sets the maximum value of the Hue component in the range from 0..359.
/// This property must be greater than <see cref="MinHue"/>. /// This property must be greater than <see cref="MinHue"/>.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
@ -93,7 +93,7 @@ namespace Avalonia.Controls.Primitives
AvaloniaProperty.Register<ColorSpectrum, int>(nameof(MaxHue), 359); AvaloniaProperty.Register<ColorSpectrum, int>(nameof(MaxHue), 359);
/// <summary> /// <summary>
/// Gets or sets the maximum value of the Saturation channel in the range from 0..100. /// Gets or sets the maximum value of the Saturation component in the range from 0..100.
/// This property must be greater than <see cref="MinSaturation"/>. /// This property must be greater than <see cref="MinSaturation"/>.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
@ -112,7 +112,7 @@ namespace Avalonia.Controls.Primitives
AvaloniaProperty.Register<ColorSpectrum, int>(nameof(MaxSaturation), 100); AvaloniaProperty.Register<ColorSpectrum, int>(nameof(MaxSaturation), 100);
/// <summary> /// <summary>
/// Gets or sets the maximum value of the Value channel in the range from 0..100. /// Gets or sets the maximum value of the Value component in the range from 0..100.
/// This property must be greater than <see cref="MinValue"/>. /// This property must be greater than <see cref="MinValue"/>.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
@ -131,7 +131,7 @@ namespace Avalonia.Controls.Primitives
AvaloniaProperty.Register<ColorSpectrum, int>(nameof(MaxValue), 100); AvaloniaProperty.Register<ColorSpectrum, int>(nameof(MaxValue), 100);
/// <summary> /// <summary>
/// Gets or sets the minimum value of the Hue channel in the range from 0..359. /// Gets or sets the minimum value of the Hue component in the range from 0..359.
/// This property must be less than <see cref="MaxHue"/>. /// This property must be less than <see cref="MaxHue"/>.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
@ -150,7 +150,7 @@ namespace Avalonia.Controls.Primitives
AvaloniaProperty.Register<ColorSpectrum, int>(nameof(MinHue), 0); AvaloniaProperty.Register<ColorSpectrum, int>(nameof(MinHue), 0);
/// <summary> /// <summary>
/// Gets or sets the minimum value of the Saturation channel in the range from 0..100. /// Gets or sets the minimum value of the Saturation component in the range from 0..100.
/// This property must be less than <see cref="MaxSaturation"/>. /// This property must be less than <see cref="MaxSaturation"/>.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
@ -169,7 +169,7 @@ namespace Avalonia.Controls.Primitives
AvaloniaProperty.Register<ColorSpectrum, int>(nameof(MinSaturation), 0); AvaloniaProperty.Register<ColorSpectrum, int>(nameof(MinSaturation), 0);
/// <summary> /// <summary>
/// Gets or sets the minimum value of the Value channel in the range from 0..100. /// Gets or sets the minimum value of the Value component in the range from 0..100.
/// This property must be less than <see cref="MaxValue"/>. /// This property must be less than <see cref="MaxValue"/>.
/// </summary> /// </summary>
/// <remarks> /// <remarks>

231
src/Avalonia.Controls.ColorPicker/ColorSpectrum/ColorSpectrum.cs

@ -80,7 +80,7 @@ namespace Avalonia.Controls.Primitives
// in order to function properly while the asynchronous bitmap creation // in order to function properly while the asynchronous bitmap creation
// is in progress. // is in progress.
private ColorSpectrumShape _shapeFromLastBitmapCreation = ColorSpectrumShape.Box; private ColorSpectrumShape _shapeFromLastBitmapCreation = ColorSpectrumShape.Box;
private ColorSpectrumChannels _componentsFromLastBitmapCreation = ColorSpectrumChannels.HueSaturation; private ColorSpectrumComponents _componentsFromLastBitmapCreation = ColorSpectrumComponents.HueSaturation;
private double _imageWidthFromLastBitmapCreation = 0.0; private double _imageWidthFromLastBitmapCreation = 0.0;
private double _imageHeightFromLastBitmapCreation = 0.0; private double _imageHeightFromLastBitmapCreation = 0.0;
private int _minHueFromLastBitmapCreation = 0; private int _minHueFromLastBitmapCreation = 0;
@ -99,7 +99,7 @@ namespace Avalonia.Controls.Primitives
public ColorSpectrum() public ColorSpectrum()
{ {
_shapeFromLastBitmapCreation = Shape; _shapeFromLastBitmapCreation = Shape;
_componentsFromLastBitmapCreation = Channels; _componentsFromLastBitmapCreation = Components;
_imageWidthFromLastBitmapCreation = 0; _imageWidthFromLastBitmapCreation = 0;
_imageHeightFromLastBitmapCreation = 0; _imageHeightFromLastBitmapCreation = 0;
_minHueFromLastBitmapCreation = MinHue; _minHueFromLastBitmapCreation = MinHue;
@ -219,53 +219,53 @@ namespace Avalonia.Controls.Primitives
bool isControlDown = e.KeyModifiers.HasFlag(KeyModifiers.Control); bool isControlDown = e.KeyModifiers.HasFlag(KeyModifiers.Control);
HsvChannel incrementChannel = HsvChannel.Hue; HsvComponent incrementComponent = HsvComponent.Hue;
bool isSaturationValue = false; bool isSaturationValue = false;
if (key == Key.Left || if (key == Key.Left ||
key == Key.Right) key == Key.Right)
{ {
switch (Channels) switch (Components)
{ {
case ColorSpectrumChannels.HueSaturation: case ColorSpectrumComponents.HueSaturation:
case ColorSpectrumChannels.HueValue: case ColorSpectrumComponents.HueValue:
incrementChannel = HsvChannel.Hue; incrementComponent = HsvComponent.Hue;
break; break;
case ColorSpectrumChannels.SaturationValue: case ColorSpectrumComponents.SaturationValue:
isSaturationValue = true; isSaturationValue = true;
goto case ColorSpectrumChannels.SaturationHue; goto case ColorSpectrumComponents.SaturationHue;
case ColorSpectrumChannels.SaturationHue: case ColorSpectrumComponents.SaturationHue:
incrementChannel = HsvChannel.Saturation; incrementComponent = HsvComponent.Saturation;
break; break;
case ColorSpectrumChannels.ValueHue: case ColorSpectrumComponents.ValueHue:
case ColorSpectrumChannels.ValueSaturation: case ColorSpectrumComponents.ValueSaturation:
incrementChannel = HsvChannel.Value; incrementComponent = HsvComponent.Value;
break; break;
} }
} }
else if (key == Key.Up || else if (key == Key.Up ||
key == Key.Down) key == Key.Down)
{ {
switch (Channels) switch (Components)
{ {
case ColorSpectrumChannels.SaturationHue: case ColorSpectrumComponents.SaturationHue:
case ColorSpectrumChannels.ValueHue: case ColorSpectrumComponents.ValueHue:
incrementChannel = HsvChannel.Hue; incrementComponent = HsvComponent.Hue;
break; break;
case ColorSpectrumChannels.HueSaturation: case ColorSpectrumComponents.HueSaturation:
case ColorSpectrumChannels.ValueSaturation: case ColorSpectrumComponents.ValueSaturation:
incrementChannel = HsvChannel.Saturation; incrementComponent = HsvComponent.Saturation;
break; break;
case ColorSpectrumChannels.SaturationValue: case ColorSpectrumComponents.SaturationValue:
isSaturationValue = true; isSaturationValue = true;
goto case ColorSpectrumChannels.HueValue; goto case ColorSpectrumComponents.HueValue;
case ColorSpectrumChannels.HueValue: case ColorSpectrumComponents.HueValue:
incrementChannel = HsvChannel.Value; incrementComponent = HsvComponent.Value;
break; break;
} }
} }
@ -273,19 +273,19 @@ namespace Avalonia.Controls.Primitives
double minBound = 0.0; double minBound = 0.0;
double maxBound = 0.0; double maxBound = 0.0;
switch (incrementChannel) switch (incrementComponent)
{ {
case HsvChannel.Hue: case HsvComponent.Hue:
minBound = MinHue; minBound = MinHue;
maxBound = MaxHue; maxBound = MaxHue;
break; break;
case HsvChannel.Saturation: case HsvComponent.Saturation:
minBound = MinSaturation; minBound = MinSaturation;
maxBound = MaxSaturation; maxBound = MaxSaturation;
break; break;
case HsvChannel.Value: case HsvComponent.Value:
minBound = MinValue; minBound = MinValue;
maxBound = MaxValue; maxBound = MaxValue;
break; break;
@ -295,8 +295,8 @@ namespace Avalonia.Controls.Primitives
// so we want left and up to be lower for hue, but higher for saturation and value. // so we want left and up to be lower for hue, but higher for saturation and value.
// This will ensure that the icon always moves in the direction of the key press. // This will ensure that the icon always moves in the direction of the key press.
IncrementDirection direction = IncrementDirection direction =
(incrementChannel == HsvChannel.Hue && (key == Key.Left || key == Key.Up)) || (incrementComponent == HsvComponent.Hue && (key == Key.Left || key == Key.Up)) ||
(incrementChannel != HsvChannel.Hue && (key == Key.Right || key == Key.Down)) ? (incrementComponent != HsvComponent.Hue && (key == Key.Right || key == Key.Down)) ?
IncrementDirection.Lower : IncrementDirection.Lower :
IncrementDirection.Higher; IncrementDirection.Higher;
@ -320,9 +320,9 @@ namespace Avalonia.Controls.Primitives
IncrementAmount amount = isControlDown ? IncrementAmount.Large : IncrementAmount.Small; IncrementAmount amount = isControlDown ? IncrementAmount.Large : IncrementAmount.Small;
HsvColor hsvColor = HsvColor; HsvColor hsvColor = HsvColor;
UpdateColor(ColorHelpers.IncrementColorChannel( UpdateColor(ColorHelpers.IncrementColorComponent(
new Hsv(hsvColor), new Hsv(hsvColor),
incrementChannel, incrementComponent,
direction, direction,
amount, amount,
shouldWrap: true, shouldWrap: true,
@ -408,12 +408,12 @@ namespace Avalonia.Controls.Primitives
throw new ArgumentException("MaxHue must be between 0 and 359."); throw new ArgumentException("MaxHue must be between 0 and 359.");
} }
ColorSpectrumChannels channels = Channels; ColorSpectrumComponents components = Components;
// If hue is one of the axes in the spectrum bitmap, then we'll need to regenerate it // If hue is one of the axes in the spectrum bitmap, then we'll need to regenerate it
// if the maximum or minimum value has changed. // if the maximum or minimum value has changed.
if (channels != ColorSpectrumChannels.SaturationValue && if (components != ColorSpectrumComponents.SaturationValue &&
channels != ColorSpectrumChannels.ValueSaturation) components != ColorSpectrumComponents.ValueSaturation)
{ {
CreateBitmapsAndColorMap(); CreateBitmapsAndColorMap();
} }
@ -433,12 +433,12 @@ namespace Avalonia.Controls.Primitives
throw new ArgumentException("MaxSaturation must be between 0 and 100."); throw new ArgumentException("MaxSaturation must be between 0 and 100.");
} }
ColorSpectrumChannels channels = Channels; ColorSpectrumComponents components = Components;
// If value is one of the axes in the spectrum bitmap, then we'll need to regenerate it // If value is one of the axes in the spectrum bitmap, then we'll need to regenerate it
// if the maximum or minimum value has changed. // if the maximum or minimum value has changed.
if (channels != ColorSpectrumChannels.HueValue && if (components != ColorSpectrumComponents.HueValue &&
channels != ColorSpectrumChannels.ValueHue) components != ColorSpectrumComponents.ValueHue)
{ {
CreateBitmapsAndColorMap(); CreateBitmapsAndColorMap();
} }
@ -458,12 +458,12 @@ namespace Avalonia.Controls.Primitives
throw new ArgumentException("MaxValue must be between 0 and 100."); throw new ArgumentException("MaxValue must be between 0 and 100.");
} }
ColorSpectrumChannels channels = Channels; ColorSpectrumComponents components = Components;
// If value is one of the axes in the spectrum bitmap, then we'll need to regenerate it // If value is one of the axes in the spectrum bitmap, then we'll need to regenerate it
// if the maximum or minimum value has changed. // if the maximum or minimum value has changed.
if (channels != ColorSpectrumChannels.HueSaturation && if (components != ColorSpectrumComponents.HueSaturation &&
channels != ColorSpectrumChannels.SaturationHue) components != ColorSpectrumComponents.SaturationHue)
{ {
CreateBitmapsAndColorMap(); CreateBitmapsAndColorMap();
} }
@ -472,7 +472,7 @@ namespace Avalonia.Controls.Primitives
{ {
CreateBitmapsAndColorMap(); CreateBitmapsAndColorMap();
} }
else if (change.Property == ChannelsProperty) else if (change.Property == ComponentsProperty)
{ {
CreateBitmapsAndColorMap(); CreateBitmapsAndColorMap();
} }
@ -617,23 +617,22 @@ namespace Avalonia.Controls.Primitives
// Note: This can sometimes cause a crash -- possibly due to differences in c# rounding. Therefore, index is now clamped. // Note: This can sometimes cause a crash -- possibly due to differences in c# rounding. Therefore, index is now clamped.
Hsv hsvAtPoint = _hsvValues[MathUtilities.Clamp((y * width + x), 0, _hsvValues.Count - 1)]; Hsv hsvAtPoint = _hsvValues[MathUtilities.Clamp((y * width + x), 0, _hsvValues.Count - 1)];
var channels = Channels;
var hsvColor = HsvColor; var hsvColor = HsvColor;
switch (channels) switch (Components)
{ {
case ColorSpectrumChannels.HueValue: case ColorSpectrumComponents.HueValue:
case ColorSpectrumChannels.ValueHue: case ColorSpectrumComponents.ValueHue:
hsvAtPoint.S = hsvColor.S; hsvAtPoint.S = hsvColor.S;
break; break;
case ColorSpectrumChannels.HueSaturation: case ColorSpectrumComponents.HueSaturation:
case ColorSpectrumChannels.SaturationHue: case ColorSpectrumComponents.SaturationHue:
hsvAtPoint.V = hsvColor.V; hsvAtPoint.V = hsvColor.V;
break; break;
case ColorSpectrumChannels.ValueSaturation: case ColorSpectrumComponents.ValueSaturation:
case ColorSpectrumChannels.SaturationValue: case ColorSpectrumComponents.SaturationValue:
hsvAtPoint.H = hsvColor.H; hsvAtPoint.H = hsvColor.H;
break; break;
} }
@ -681,8 +680,8 @@ namespace Avalonia.Controls.Primitives
// In the case where saturation was an axis in the spectrum with hue, or value is an axis, full stop, // In the case where saturation was an axis in the spectrum with hue, or value is an axis, full stop,
// we inverted the direction of that axis in order to put more hue on the outside of the ring, // we inverted the direction of that axis in order to put more hue on the outside of the ring,
// so we need to do similarly here when positioning the ellipse. // so we need to do similarly here when positioning the ellipse.
if (_componentsFromLastBitmapCreation == ColorSpectrumChannels.HueSaturation || if (_componentsFromLastBitmapCreation == ColorSpectrumComponents.HueSaturation ||
_componentsFromLastBitmapCreation == ColorSpectrumChannels.SaturationHue) _componentsFromLastBitmapCreation == ColorSpectrumComponents.SaturationHue)
{ {
sPercent = 1 - sPercent; sPercent = 1 - sPercent;
} }
@ -693,32 +692,32 @@ namespace Avalonia.Controls.Primitives
switch (_componentsFromLastBitmapCreation) switch (_componentsFromLastBitmapCreation)
{ {
case ColorSpectrumChannels.HueValue: case ColorSpectrumComponents.HueValue:
xPercent = hPercent; xPercent = hPercent;
yPercent = vPercent; yPercent = vPercent;
break; break;
case ColorSpectrumChannels.HueSaturation: case ColorSpectrumComponents.HueSaturation:
xPercent = hPercent; xPercent = hPercent;
yPercent = sPercent; yPercent = sPercent;
break; break;
case ColorSpectrumChannels.ValueHue: case ColorSpectrumComponents.ValueHue:
xPercent = vPercent; xPercent = vPercent;
yPercent = hPercent; yPercent = hPercent;
break; break;
case ColorSpectrumChannels.ValueSaturation: case ColorSpectrumComponents.ValueSaturation:
xPercent = vPercent; xPercent = vPercent;
yPercent = sPercent; yPercent = sPercent;
break; break;
case ColorSpectrumChannels.SaturationHue: case ColorSpectrumComponents.SaturationHue:
xPercent = sPercent; xPercent = sPercent;
yPercent = hPercent; yPercent = hPercent;
break; break;
case ColorSpectrumChannels.SaturationValue: case ColorSpectrumComponents.SaturationValue:
xPercent = sPercent; xPercent = sPercent;
yPercent = vPercent; yPercent = vPercent;
break; break;
@ -757,8 +756,8 @@ namespace Avalonia.Controls.Primitives
// In the case where saturation was an axis in the spectrum with hue, or value is an axis, full stop, // In the case where saturation was an axis in the spectrum with hue, or value is an axis, full stop,
// we inverted the direction of that axis in order to put more hue on the outside of the ring, // we inverted the direction of that axis in order to put more hue on the outside of the ring,
// so we need to do similarly here when positioning the ellipse. // so we need to do similarly here when positioning the ellipse.
if (_componentsFromLastBitmapCreation == ColorSpectrumChannels.HueSaturation || if (_componentsFromLastBitmapCreation == ColorSpectrumComponents.HueSaturation ||
_componentsFromLastBitmapCreation == ColorSpectrumChannels.SaturationHue) _componentsFromLastBitmapCreation == ColorSpectrumComponents.SaturationHue)
{ {
sThetaValue = 360 - sThetaValue; sThetaValue = 360 - sThetaValue;
sRValue = -sRValue - 1; sRValue = -sRValue - 1;
@ -771,32 +770,32 @@ namespace Avalonia.Controls.Primitives
switch (_componentsFromLastBitmapCreation) switch (_componentsFromLastBitmapCreation)
{ {
case ColorSpectrumChannels.HueValue: case ColorSpectrumComponents.HueValue:
thetaValue = hThetaValue; thetaValue = hThetaValue;
rValue = vRValue; rValue = vRValue;
break; break;
case ColorSpectrumChannels.HueSaturation: case ColorSpectrumComponents.HueSaturation:
thetaValue = hThetaValue; thetaValue = hThetaValue;
rValue = sRValue; rValue = sRValue;
break; break;
case ColorSpectrumChannels.ValueHue: case ColorSpectrumComponents.ValueHue:
thetaValue = vThetaValue; thetaValue = vThetaValue;
rValue = hRValue; rValue = hRValue;
break; break;
case ColorSpectrumChannels.ValueSaturation: case ColorSpectrumComponents.ValueSaturation:
thetaValue = vThetaValue; thetaValue = vThetaValue;
rValue = sRValue; rValue = sRValue;
break; break;
case ColorSpectrumChannels.SaturationHue: case ColorSpectrumComponents.SaturationHue:
thetaValue = sThetaValue; thetaValue = sThetaValue;
rValue = hRValue; rValue = hRValue;
break; break;
case ColorSpectrumChannels.SaturationValue: case ColorSpectrumComponents.SaturationValue:
thetaValue = sThetaValue; thetaValue = sThetaValue;
rValue = vRValue; rValue = vRValue;
break; break;
@ -932,7 +931,7 @@ namespace Avalonia.Controls.Primitives
int minValue = MinValue; int minValue = MinValue;
int maxValue = MaxValue; int maxValue = MaxValue;
ColorSpectrumShape shape = Shape; ColorSpectrumShape shape = Shape;
ColorSpectrumChannels channels = Channels; ColorSpectrumComponents components = Components;
// If min >= max, then by convention, min is the only number that a property can have. // If min >= max, then by convention, min is the only number that a property can have.
if (minHue >= maxHue) if (minHue >= maxHue)
@ -967,8 +966,8 @@ namespace Avalonia.Controls.Primitives
bgraMinPixelData.Capacity = pixelDataSize; bgraMinPixelData.Capacity = pixelDataSize;
// We'll only save pixel data for the middle bitmaps if our third dimension is hue. // We'll only save pixel data for the middle bitmaps if our third dimension is hue.
if (channels == ColorSpectrumChannels.ValueSaturation || if (components == ColorSpectrumComponents.ValueSaturation ||
channels == ColorSpectrumChannels.SaturationValue) components == ColorSpectrumComponents.SaturationValue)
{ {
bgraMiddle1PixelData.Capacity = pixelDataSize; bgraMiddle1PixelData.Capacity = pixelDataSize;
bgraMiddle2PixelData.Capacity = pixelDataSize; bgraMiddle2PixelData.Capacity = pixelDataSize;
@ -1004,7 +1003,7 @@ namespace Avalonia.Controls.Primitives
for (int y = minDimensionInt - 1; y >= 0; --y) for (int y = minDimensionInt - 1; y >= 0; --y)
{ {
FillPixelForBox( FillPixelForBox(
x, y, hsv, minDimensionInt, channels, minHue, maxHue, minSaturation, maxSaturation, minValue, maxValue, x, y, hsv, minDimensionInt, components, minHue, maxHue, minSaturation, maxSaturation, minValue, maxValue,
bgraMinPixelData, bgraMiddle1PixelData, bgraMiddle2PixelData, bgraMiddle3PixelData, bgraMiddle4PixelData, bgraMaxPixelData, bgraMinPixelData, bgraMiddle1PixelData, bgraMiddle2PixelData, bgraMiddle3PixelData, bgraMiddle4PixelData, bgraMaxPixelData,
newHsvValues); newHsvValues);
} }
@ -1017,7 +1016,7 @@ namespace Avalonia.Controls.Primitives
for (int x = 0; x < minDimensionInt; ++x) for (int x = 0; x < minDimensionInt; ++x)
{ {
FillPixelForRing( FillPixelForRing(
x, y, minDimensionInt / 2.0, hsv, channels, minHue, maxHue, minSaturation, maxSaturation, minValue, maxValue, x, y, minDimensionInt / 2.0, hsv, components, minHue, maxHue, minSaturation, maxSaturation, minValue, maxValue,
bgraMinPixelData, bgraMiddle1PixelData, bgraMiddle2PixelData, bgraMiddle3PixelData, bgraMiddle4PixelData, bgraMaxPixelData, bgraMinPixelData, bgraMiddle1PixelData, bgraMiddle2PixelData, bgraMiddle3PixelData, bgraMiddle4PixelData, bgraMaxPixelData,
newHsvValues); newHsvValues);
} }
@ -1030,24 +1029,24 @@ namespace Avalonia.Controls.Primitives
int pixelWidth = (int)Math.Round(minDimension); int pixelWidth = (int)Math.Round(minDimension);
int pixelHeight = (int)Math.Round(minDimension); int pixelHeight = (int)Math.Round(minDimension);
ColorSpectrumChannels channels2 = Channels; ColorSpectrumComponents components2 = Components;
WriteableBitmap minBitmap = ColorHelpers.CreateBitmapFromPixelData(pixelWidth, pixelHeight, bgraMinPixelData); WriteableBitmap minBitmap = ColorHelpers.CreateBitmapFromPixelData(pixelWidth, pixelHeight, bgraMinPixelData);
WriteableBitmap maxBitmap = ColorHelpers.CreateBitmapFromPixelData(pixelWidth, pixelHeight, bgraMaxPixelData); WriteableBitmap maxBitmap = ColorHelpers.CreateBitmapFromPixelData(pixelWidth, pixelHeight, bgraMaxPixelData);
switch (channels2) switch (components2)
{ {
case ColorSpectrumChannels.HueValue: case ColorSpectrumComponents.HueValue:
case ColorSpectrumChannels.ValueHue: case ColorSpectrumComponents.ValueHue:
_saturationMinimumBitmap = minBitmap; _saturationMinimumBitmap = minBitmap;
_saturationMaximumBitmap = maxBitmap; _saturationMaximumBitmap = maxBitmap;
break; break;
case ColorSpectrumChannels.HueSaturation: case ColorSpectrumComponents.HueSaturation:
case ColorSpectrumChannels.SaturationHue: case ColorSpectrumComponents.SaturationHue:
_valueBitmap = maxBitmap; _valueBitmap = maxBitmap;
break; break;
case ColorSpectrumChannels.ValueSaturation: case ColorSpectrumComponents.ValueSaturation:
case ColorSpectrumChannels.SaturationValue: case ColorSpectrumComponents.SaturationValue:
_hueRedBitmap = minBitmap; _hueRedBitmap = minBitmap;
_hueYellowBitmap = ColorHelpers.CreateBitmapFromPixelData(pixelWidth, pixelHeight, bgraMiddle1PixelData); _hueYellowBitmap = ColorHelpers.CreateBitmapFromPixelData(pixelWidth, pixelHeight, bgraMiddle1PixelData);
_hueGreenBitmap = ColorHelpers.CreateBitmapFromPixelData(pixelWidth, pixelHeight, bgraMiddle2PixelData); _hueGreenBitmap = ColorHelpers.CreateBitmapFromPixelData(pixelWidth, pixelHeight, bgraMiddle2PixelData);
@ -1058,7 +1057,7 @@ namespace Avalonia.Controls.Primitives
} }
_shapeFromLastBitmapCreation = Shape; _shapeFromLastBitmapCreation = Shape;
_componentsFromLastBitmapCreation = Channels; _componentsFromLastBitmapCreation = Components;
_imageWidthFromLastBitmapCreation = minDimension; _imageWidthFromLastBitmapCreation = minDimension;
_imageHeightFromLastBitmapCreation = minDimension; _imageHeightFromLastBitmapCreation = minDimension;
_minHueFromLastBitmapCreation = MinHue; _minHueFromLastBitmapCreation = MinHue;
@ -1080,7 +1079,7 @@ namespace Avalonia.Controls.Primitives
double y, double y,
Hsv baseHsv, Hsv baseHsv,
double minDimension, double minDimension,
ColorSpectrumChannels channels, ColorSpectrumComponents components,
double minHue, double minHue,
double maxHue, double maxHue,
double minSaturation, double minSaturation,
@ -1112,30 +1111,30 @@ namespace Avalonia.Controls.Primitives
double xPercent = (minDimension - 1 - x) / (minDimension - 1); double xPercent = (minDimension - 1 - x) / (minDimension - 1);
double yPercent = (minDimension - 1 - y) / (minDimension - 1); double yPercent = (minDimension - 1 - y) / (minDimension - 1);
switch (channels) switch (components)
{ {
case ColorSpectrumChannels.HueValue: case ColorSpectrumComponents.HueValue:
hsvMin.H = hsvMiddle1.H = hsvMiddle2.H = hsvMiddle3.H = hsvMiddle4.H = hsvMax.H = hMin + yPercent * (hMax - hMin); hsvMin.H = hsvMiddle1.H = hsvMiddle2.H = hsvMiddle3.H = hsvMiddle4.H = hsvMax.H = hMin + yPercent * (hMax - hMin);
hsvMin.V = hsvMiddle1.V = hsvMiddle2.V = hsvMiddle3.V = hsvMiddle4.V = hsvMax.V = vMin + xPercent * (vMax - vMin); hsvMin.V = hsvMiddle1.V = hsvMiddle2.V = hsvMiddle3.V = hsvMiddle4.V = hsvMax.V = vMin + xPercent * (vMax - vMin);
hsvMin.S = 0; hsvMin.S = 0;
hsvMax.S = 1; hsvMax.S = 1;
break; break;
case ColorSpectrumChannels.HueSaturation: case ColorSpectrumComponents.HueSaturation:
hsvMin.H = hsvMiddle1.H = hsvMiddle2.H = hsvMiddle3.H = hsvMiddle4.H = hsvMax.H = hMin + yPercent * (hMax - hMin); hsvMin.H = hsvMiddle1.H = hsvMiddle2.H = hsvMiddle3.H = hsvMiddle4.H = hsvMax.H = hMin + yPercent * (hMax - hMin);
hsvMin.S = hsvMiddle1.S = hsvMiddle2.S = hsvMiddle3.S = hsvMiddle4.S = hsvMax.S = sMin + xPercent * (sMax - sMin); hsvMin.S = hsvMiddle1.S = hsvMiddle2.S = hsvMiddle3.S = hsvMiddle4.S = hsvMax.S = sMin + xPercent * (sMax - sMin);
hsvMin.V = 0; hsvMin.V = 0;
hsvMax.V = 1; hsvMax.V = 1;
break; break;
case ColorSpectrumChannels.ValueHue: case ColorSpectrumComponents.ValueHue:
hsvMin.V = hsvMiddle1.V = hsvMiddle2.V = hsvMiddle3.V = hsvMiddle4.V = hsvMax.V = vMin + yPercent * (vMax - vMin); hsvMin.V = hsvMiddle1.V = hsvMiddle2.V = hsvMiddle3.V = hsvMiddle4.V = hsvMax.V = vMin + yPercent * (vMax - vMin);
hsvMin.H = hsvMiddle1.H = hsvMiddle2.H = hsvMiddle3.H = hsvMiddle4.H = hsvMax.H = hMin + xPercent * (hMax - hMin); hsvMin.H = hsvMiddle1.H = hsvMiddle2.H = hsvMiddle3.H = hsvMiddle4.H = hsvMax.H = hMin + xPercent * (hMax - hMin);
hsvMin.S = 0; hsvMin.S = 0;
hsvMax.S = 1; hsvMax.S = 1;
break; break;
case ColorSpectrumChannels.ValueSaturation: case ColorSpectrumComponents.ValueSaturation:
hsvMin.V = hsvMiddle1.V = hsvMiddle2.V = hsvMiddle3.V = hsvMiddle4.V = hsvMax.V = vMin + yPercent * (vMax - vMin); hsvMin.V = hsvMiddle1.V = hsvMiddle2.V = hsvMiddle3.V = hsvMiddle4.V = hsvMax.V = vMin + yPercent * (vMax - vMin);
hsvMin.S = hsvMiddle1.S = hsvMiddle2.S = hsvMiddle3.S = hsvMiddle4.S = hsvMax.S = sMin + xPercent * (sMax - sMin); hsvMin.S = hsvMiddle1.S = hsvMiddle2.S = hsvMiddle3.S = hsvMiddle4.S = hsvMax.S = sMin + xPercent * (sMax - sMin);
hsvMin.H = 0; hsvMin.H = 0;
@ -1146,14 +1145,14 @@ namespace Avalonia.Controls.Primitives
hsvMax.H = 300; hsvMax.H = 300;
break; break;
case ColorSpectrumChannels.SaturationHue: case ColorSpectrumComponents.SaturationHue:
hsvMin.S = hsvMiddle1.S = hsvMiddle2.S = hsvMiddle3.S = hsvMiddle4.S = hsvMax.S = sMin + yPercent * (sMax - sMin); hsvMin.S = hsvMiddle1.S = hsvMiddle2.S = hsvMiddle3.S = hsvMiddle4.S = hsvMax.S = sMin + yPercent * (sMax - sMin);
hsvMin.H = hsvMiddle1.H = hsvMiddle2.H = hsvMiddle3.H = hsvMiddle4.H = hsvMax.H = hMin + xPercent * (hMax - hMin); hsvMin.H = hsvMiddle1.H = hsvMiddle2.H = hsvMiddle3.H = hsvMiddle4.H = hsvMax.H = hMin + xPercent * (hMax - hMin);
hsvMin.V = 0; hsvMin.V = 0;
hsvMax.V = 1; hsvMax.V = 1;
break; break;
case ColorSpectrumChannels.SaturationValue: case ColorSpectrumComponents.SaturationValue:
hsvMin.S = hsvMiddle1.S = hsvMiddle2.S = hsvMiddle3.S = hsvMiddle4.S = hsvMax.S = sMin + yPercent * (sMax - sMin); hsvMin.S = hsvMiddle1.S = hsvMiddle2.S = hsvMiddle3.S = hsvMiddle4.S = hsvMax.S = sMin + yPercent * (sMax - sMin);
hsvMin.V = hsvMiddle1.V = hsvMiddle2.V = hsvMiddle3.V = hsvMiddle4.V = hsvMax.V = vMin + xPercent * (vMax - vMin); hsvMin.V = hsvMiddle1.V = hsvMiddle2.V = hsvMiddle3.V = hsvMiddle4.V = hsvMax.V = vMin + xPercent * (vMax - vMin);
hsvMin.H = 0; hsvMin.H = 0;
@ -1171,8 +1170,8 @@ namespace Avalonia.Controls.Primitives
// so we'll invert the number before assigning the HSL value to the array. // so we'll invert the number before assigning the HSL value to the array.
// Otherwise, we'll have a very narrow section in the middle that actually has meaningful hue // Otherwise, we'll have a very narrow section in the middle that actually has meaningful hue
// in the case of the ring configuration. // in the case of the ring configuration.
if (channels == ColorSpectrumChannels.HueSaturation || if (components == ColorSpectrumComponents.HueSaturation ||
channels == ColorSpectrumChannels.SaturationHue) components == ColorSpectrumComponents.SaturationHue)
{ {
hsvMin.S = sMax - hsvMin.S + sMin; hsvMin.S = sMax - hsvMin.S + sMin;
hsvMiddle1.S = sMax - hsvMiddle1.S + sMin; hsvMiddle1.S = sMax - hsvMiddle1.S + sMin;
@ -1200,8 +1199,8 @@ namespace Avalonia.Controls.Primitives
bgraMinPixelData.Add(255); // a - ignored bgraMinPixelData.Add(255); // a - ignored
// We'll only save pixel data for the middle bitmaps if our third dimension is hue. // We'll only save pixel data for the middle bitmaps if our third dimension is hue.
if (channels == ColorSpectrumChannels.ValueSaturation || if (components == ColorSpectrumComponents.ValueSaturation ||
channels == ColorSpectrumChannels.SaturationValue) components == ColorSpectrumComponents.SaturationValue)
{ {
Rgb rgbMiddle1 = hsvMiddle1.ToRgb(); Rgb rgbMiddle1 = hsvMiddle1.ToRgb();
bgraMiddle1PixelData.Add((byte)Math.Round(rgbMiddle1.B * 255.0)); // b bgraMiddle1PixelData.Add((byte)Math.Round(rgbMiddle1.B * 255.0)); // b
@ -1240,7 +1239,7 @@ namespace Avalonia.Controls.Primitives
double y, double y,
double radius, double radius,
Hsv baseHsv, Hsv baseHsv,
ColorSpectrumChannels channels, ColorSpectrumComponents components,
double minHue, double minHue,
double maxHue, double maxHue,
double minSaturation, double minSaturation,
@ -1298,30 +1297,30 @@ namespace Avalonia.Controls.Primitives
double thetaPercent = theta / 360; double thetaPercent = theta / 360;
switch (channels) switch (components)
{ {
case ColorSpectrumChannels.HueValue: case ColorSpectrumComponents.HueValue:
hsvMin.H = hsvMiddle1.H = hsvMiddle2.H = hsvMiddle3.H = hsvMiddle4.H = hsvMax.H = hMin + thetaPercent * (hMax - hMin); hsvMin.H = hsvMiddle1.H = hsvMiddle2.H = hsvMiddle3.H = hsvMiddle4.H = hsvMax.H = hMin + thetaPercent * (hMax - hMin);
hsvMin.V = hsvMiddle1.V = hsvMiddle2.V = hsvMiddle3.V = hsvMiddle4.V = hsvMax.V = vMin + r * (vMax - vMin); hsvMin.V = hsvMiddle1.V = hsvMiddle2.V = hsvMiddle3.V = hsvMiddle4.V = hsvMax.V = vMin + r * (vMax - vMin);
hsvMin.S = 0; hsvMin.S = 0;
hsvMax.S = 1; hsvMax.S = 1;
break; break;
case ColorSpectrumChannels.HueSaturation: case ColorSpectrumComponents.HueSaturation:
hsvMin.H = hsvMiddle1.H = hsvMiddle2.H = hsvMiddle3.H = hsvMiddle4.H = hsvMax.H = hMin + thetaPercent * (hMax - hMin); hsvMin.H = hsvMiddle1.H = hsvMiddle2.H = hsvMiddle3.H = hsvMiddle4.H = hsvMax.H = hMin + thetaPercent * (hMax - hMin);
hsvMin.S = hsvMiddle1.S = hsvMiddle2.S = hsvMiddle3.S = hsvMiddle4.S = hsvMax.S = sMin + r * (sMax - sMin); hsvMin.S = hsvMiddle1.S = hsvMiddle2.S = hsvMiddle3.S = hsvMiddle4.S = hsvMax.S = sMin + r * (sMax - sMin);
hsvMin.V = 0; hsvMin.V = 0;
hsvMax.V = 1; hsvMax.V = 1;
break; break;
case ColorSpectrumChannels.ValueHue: case ColorSpectrumComponents.ValueHue:
hsvMin.V = hsvMiddle1.V = hsvMiddle2.V = hsvMiddle3.V = hsvMiddle4.V = hsvMax.V = vMin + thetaPercent * (vMax - vMin); hsvMin.V = hsvMiddle1.V = hsvMiddle2.V = hsvMiddle3.V = hsvMiddle4.V = hsvMax.V = vMin + thetaPercent * (vMax - vMin);
hsvMin.H = hsvMiddle1.H = hsvMiddle2.H = hsvMiddle3.H = hsvMiddle4.H = hsvMax.H = hMin + r * (hMax - hMin); hsvMin.H = hsvMiddle1.H = hsvMiddle2.H = hsvMiddle3.H = hsvMiddle4.H = hsvMax.H = hMin + r * (hMax - hMin);
hsvMin.S = 0; hsvMin.S = 0;
hsvMax.S = 1; hsvMax.S = 1;
break; break;
case ColorSpectrumChannels.ValueSaturation: case ColorSpectrumComponents.ValueSaturation:
hsvMin.V = hsvMiddle1.V = hsvMiddle2.V = hsvMiddle3.V = hsvMiddle4.V = hsvMax.V = vMin + thetaPercent * (vMax - vMin); hsvMin.V = hsvMiddle1.V = hsvMiddle2.V = hsvMiddle3.V = hsvMiddle4.V = hsvMax.V = vMin + thetaPercent * (vMax - vMin);
hsvMin.S = hsvMiddle1.S = hsvMiddle2.S = hsvMiddle3.S = hsvMiddle4.S = hsvMax.S = sMin + r * (sMax - sMin); hsvMin.S = hsvMiddle1.S = hsvMiddle2.S = hsvMiddle3.S = hsvMiddle4.S = hsvMax.S = sMin + r * (sMax - sMin);
hsvMin.H = 0; hsvMin.H = 0;
@ -1332,14 +1331,14 @@ namespace Avalonia.Controls.Primitives
hsvMax.H = 300; hsvMax.H = 300;
break; break;
case ColorSpectrumChannels.SaturationHue: case ColorSpectrumComponents.SaturationHue:
hsvMin.S = hsvMiddle1.S = hsvMiddle2.S = hsvMiddle3.S = hsvMiddle4.S = hsvMax.S = sMin + thetaPercent * (sMax - sMin); hsvMin.S = hsvMiddle1.S = hsvMiddle2.S = hsvMiddle3.S = hsvMiddle4.S = hsvMax.S = sMin + thetaPercent * (sMax - sMin);
hsvMin.H = hsvMiddle1.H = hsvMiddle2.H = hsvMiddle3.H = hsvMiddle4.H = hsvMax.H = hMin + r * (hMax - hMin); hsvMin.H = hsvMiddle1.H = hsvMiddle2.H = hsvMiddle3.H = hsvMiddle4.H = hsvMax.H = hMin + r * (hMax - hMin);
hsvMin.V = 0; hsvMin.V = 0;
hsvMax.V = 1; hsvMax.V = 1;
break; break;
case ColorSpectrumChannels.SaturationValue: case ColorSpectrumComponents.SaturationValue:
hsvMin.S = hsvMiddle1.S = hsvMiddle2.S = hsvMiddle3.S = hsvMiddle4.S = hsvMax.S = sMin + thetaPercent * (sMax - sMin); hsvMin.S = hsvMiddle1.S = hsvMiddle2.S = hsvMiddle3.S = hsvMiddle4.S = hsvMax.S = sMin + thetaPercent * (sMax - sMin);
hsvMin.V = hsvMiddle1.V = hsvMiddle2.V = hsvMiddle3.V = hsvMiddle4.V = hsvMax.V = vMin + r * (vMax - vMin); hsvMin.V = hsvMiddle1.V = hsvMiddle2.V = hsvMiddle3.V = hsvMiddle4.V = hsvMax.V = vMin + r * (vMax - vMin);
hsvMin.H = 0; hsvMin.H = 0;
@ -1357,8 +1356,8 @@ namespace Avalonia.Controls.Primitives
// so we'll invert the number before assigning the HSL value to the array. // so we'll invert the number before assigning the HSL value to the array.
// Otherwise, we'll have a very narrow section in the middle that actually has meaningful hue // Otherwise, we'll have a very narrow section in the middle that actually has meaningful hue
// in the case of the ring configuration. // in the case of the ring configuration.
if (channels == ColorSpectrumChannels.HueSaturation || if (components == ColorSpectrumComponents.HueSaturation ||
channels == ColorSpectrumChannels.SaturationHue) components == ColorSpectrumComponents.SaturationHue)
{ {
hsvMin.S = sMax - hsvMin.S + sMin; hsvMin.S = sMax - hsvMin.S + sMin;
hsvMiddle1.S = sMax - hsvMiddle1.S + sMin; hsvMiddle1.S = sMax - hsvMiddle1.S + sMin;
@ -1386,8 +1385,8 @@ namespace Avalonia.Controls.Primitives
bgraMinPixelData.Add(255); // a bgraMinPixelData.Add(255); // a
// We'll only save pixel data for the middle bitmaps if our third dimension is hue. // We'll only save pixel data for the middle bitmaps if our third dimension is hue.
if (channels == ColorSpectrumChannels.ValueSaturation || if (components == ColorSpectrumComponents.ValueSaturation ||
channels == ColorSpectrumChannels.SaturationValue) components == ColorSpectrumComponents.SaturationValue)
{ {
Rgb rgbMiddle1 = hsvMiddle1.ToRgb(); Rgb rgbMiddle1 = hsvMiddle1.ToRgb();
bgraMiddle1PixelData.Add((byte)Math.Round(rgbMiddle1.B * 255)); // b bgraMiddle1PixelData.Add((byte)Math.Round(rgbMiddle1.B * 255)); // b
@ -1432,7 +1431,7 @@ namespace Avalonia.Controls.Primitives
} }
HsvColor hsvColor = HsvColor; HsvColor hsvColor = HsvColor;
ColorSpectrumChannels channels = Channels; ColorSpectrumComponents components = Components;
// We'll set the base image and the overlay image based on which component is our third dimension. // We'll set the base image and the overlay image based on which component is our third dimension.
// If it's saturation or luminosity, then the base image is that dimension at its minimum value, // If it's saturation or luminosity, then the base image is that dimension at its minimum value,
@ -1440,10 +1439,10 @@ namespace Avalonia.Controls.Primitives
// If it's hue, then we'll figure out where in the color wheel we are, and then use the two // If it's hue, then we'll figure out where in the color wheel we are, and then use the two
// colors on either side of our position as our base image and overlay image. // colors on either side of our position as our base image and overlay image.
// For example, if our hue is orange, then the base image would be red and the overlay image yellow. // For example, if our hue is orange, then the base image would be red and the overlay image yellow.
switch (channels) switch (components)
{ {
case ColorSpectrumChannels.HueValue: case ColorSpectrumComponents.HueValue:
case ColorSpectrumChannels.ValueHue: case ColorSpectrumComponents.ValueHue:
{ {
if (_saturationMinimumBitmap == null || if (_saturationMinimumBitmap == null ||
_saturationMaximumBitmap == null) _saturationMaximumBitmap == null)
@ -1463,8 +1462,8 @@ namespace Avalonia.Controls.Primitives
} }
break; break;
case ColorSpectrumChannels.HueSaturation: case ColorSpectrumComponents.HueSaturation:
case ColorSpectrumChannels.SaturationHue: case ColorSpectrumComponents.SaturationHue:
{ {
if (_valueBitmap == null) if (_valueBitmap == null)
{ {
@ -1483,8 +1482,8 @@ namespace Avalonia.Controls.Primitives
} }
break; break;
case ColorSpectrumChannels.ValueSaturation: case ColorSpectrumComponents.ValueSaturation:
case ColorSpectrumChannels.SaturationValue: case ColorSpectrumComponents.SaturationValue:
{ {
if (_hueRedBitmap == null || if (_hueRedBitmap == null ||
_hueYellowBitmap == null || _hueYellowBitmap == null ||
@ -1554,13 +1553,13 @@ namespace Avalonia.Controls.Primitives
// To find how much something contrasts with white, we use the equation // To find how much something contrasts with white, we use the equation
// for relative luminance. // for relative luminance.
// //
// If the third channel is value, then we won't be updating the spectrum's displayed colors, // If the third component is value, then we won't be updating the spectrum's displayed colors,
// so in that case we should use a value of 1 when considering the backdrop // so in that case we should use a value of 1 when considering the backdrop
// for the selection ellipse. // for the selection ellipse.
Color displayedColor; Color displayedColor;
if (Channels == ColorSpectrumChannels.HueSaturation || if (Components == ColorSpectrumComponents.HueSaturation ||
Channels == ColorSpectrumChannels.SaturationHue) Components == ColorSpectrumComponents.SaturationHue)
{ {
HsvColor hsvColor = HsvColor; HsvColor hsvColor = HsvColor;
Rgb color = (new Hsv(hsvColor.H, hsvColor.S, 1.0)).ToRgb(); Rgb color = (new Hsv(hsvColor.H, hsvColor.S, 1.0)).ToRgb();

18
src/Avalonia.Controls.ColorPicker/ColorSpectrum/Hsv.cs

@ -8,39 +8,39 @@ using Avalonia.Media;
namespace Avalonia.Controls.Primitives namespace Avalonia.Controls.Primitives
{ {
/// <summary> /// <summary>
/// Contains and allows modification of Hue, Saturation and Value channel values. /// Contains and allows modification of Hue, Saturation and Value components.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// The is a specialized struct optimized for permanence and memory: /// The is a specialized struct optimized for permanence and memory:
/// <list type="bullet"> /// <list type="bullet">
/// <item>This is not a read-only struct like <see cref="HsvColor"/> and allows editing the fields</item> /// <item>This is not a read-only struct like <see cref="HsvColor"/> and allows editing the fields</item>
/// <item>Removes the alpha component unnecessary in core calculations</item> /// <item>Removes the alpha component unnecessary in core calculations</item>
/// <item>No channel value bounds checks or clamping is done.</item> /// <item>No component bounds checks or clamping is done.</item>
/// </list> /// </list>
/// </remarks> /// </remarks>
internal struct Hsv internal struct Hsv
{ {
/// <summary> /// <summary>
/// The Hue channel value in the range from 0..359. /// The Hue component in the range from 0..359.
/// </summary> /// </summary>
public double H; public double H;
/// <summary> /// <summary>
/// The Saturation channel value in the range from 0..1. /// The Saturation component in the range from 0..1.
/// </summary> /// </summary>
public double S; public double S;
/// <summary> /// <summary>
/// The Value channel value in the range from 0..1. /// The Value component in the range from 0..1.
/// </summary> /// </summary>
public double V; public double V;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Hsv"/> struct. /// Initializes a new instance of the <see cref="Hsv"/> struct.
/// </summary> /// </summary>
/// <param name="h">The Hue channel value in the range from 0..360.</param> /// <param name="h">The Hue component in the range from 0..360.</param>
/// <param name="s">The Saturation channel value in the range from 0..1.</param> /// <param name="s">The Saturation component in the range from 0..1.</param>
/// <param name="v">The Value channel value in the range from 0..1.</param> /// <param name="v">The Value component in the range from 0..1.</param>
public Hsv(double h, double s, double v) public Hsv(double h, double s, double v)
{ {
H = h; H = h;
@ -62,7 +62,7 @@ namespace Avalonia.Controls.Primitives
/// <summary> /// <summary>
/// Converts this <see cref="Hsv"/> struct into a standard <see cref="HsvColor"/>. /// Converts this <see cref="Hsv"/> struct into a standard <see cref="HsvColor"/>.
/// </summary> /// </summary>
/// <param name="alpha">The Alpha channel value in the range from 0..1.</param> /// <param name="alpha">The Alpha component in the range from 0..1.</param>
/// <returns>A new <see cref="HsvColor"/> representing this <see cref="Hsv"/> struct.</returns> /// <returns>A new <see cref="HsvColor"/> representing this <see cref="Hsv"/> struct.</returns>
public HsvColor ToHsvColor(double alpha = 1.0) public HsvColor ToHsvColor(double alpha = 1.0)
{ {

2
src/Avalonia.Controls.ColorPicker/ColorSpectrum/IncrementAmount.cs

@ -6,7 +6,7 @@
namespace Avalonia.Controls.Primitives namespace Avalonia.Controls.Primitives
{ {
/// <summary> /// <summary>
/// Defines a relative amount that a color channel should be incremented. /// Defines a relative amount that a color component should be incremented.
/// </summary> /// </summary>
internal enum IncrementAmount internal enum IncrementAmount
{ {

2
src/Avalonia.Controls.ColorPicker/ColorSpectrum/IncrementDirection.cs

@ -6,7 +6,7 @@
namespace Avalonia.Controls.Primitives namespace Avalonia.Controls.Primitives
{ {
/// <summary> /// <summary>
/// Defines the direction a color channel should be incremented. /// Defines the direction a color component should be incremented.
/// </summary> /// </summary>
internal enum IncrementDirection internal enum IncrementDirection
{ {

20
src/Avalonia.Controls.ColorPicker/ColorSpectrum/Rgb.cs

@ -9,40 +9,40 @@ using Avalonia.Utilities;
namespace Avalonia.Controls.Primitives namespace Avalonia.Controls.Primitives
{ {
/// <summary> /// <summary>
/// Contains and allows modification of Red, Green and Blue channel values. /// Contains and allows modification of Red, Green and Blue components.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// The is a specialized struct optimized for permanence and memory: /// The is a specialized struct optimized for permanence and memory:
/// <list type="bullet"> /// <list type="bullet">
/// <item>This is not a read-only struct like <see cref="Color"/> and allows editing the fields</item> /// <item>This is not a read-only struct like <see cref="Color"/> and allows editing the fields</item>
/// <item>Removes the alpha component unnecessary in core calculations</item> /// <item>Removes the alpha component unnecessary in core calculations</item>
/// <item>Normalizes RGB channel values in the range of 0..1 to simplify calculations.</item> /// <item>Normalizes RGB components in the range of 0..1 to simplify calculations.</item>
/// <item>No channel value bounds checks or clamping is done.</item> /// <item>No component bounds checks or clamping is done.</item>
/// </list> /// </list>
/// </remarks> /// </remarks>
internal struct Rgb internal struct Rgb
{ {
/// <summary> /// <summary>
/// The Red channel value in the range from 0..1. /// The Red component in the range from 0..1.
/// </summary> /// </summary>
public double R; public double R;
/// <summary> /// <summary>
/// The Green channel value in the range from 0..1. /// The Green component in the range from 0..1.
/// </summary> /// </summary>
public double G; public double G;
/// <summary> /// <summary>
/// The Blue channel value in the range from 0..1. /// The Blue component in the range from 0..1.
/// </summary> /// </summary>
public double B; public double B;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Rgb"/> struct. /// Initializes a new instance of the <see cref="Rgb"/> struct.
/// </summary> /// </summary>
/// <param name="r">The Red channel value in the range from 0..1.</param> /// <param name="r">The Red component in the range from 0..1.</param>
/// <param name="g">The Green channel value in the range from 0..1.</param> /// <param name="g">The Green component in the range from 0..1.</param>
/// <param name="b">The Blue channel value in the range from 0..1.</param> /// <param name="b">The Blue component in the range from 0..1.</param>
public Rgb(double r, double g, double b) public Rgb(double r, double g, double b)
{ {
R = r; R = r;
@ -64,7 +64,7 @@ namespace Avalonia.Controls.Primitives
/// <summary> /// <summary>
/// Converts this <see cref="Rgb"/> struct into a standard <see cref="Color"/>. /// Converts this <see cref="Rgb"/> struct into a standard <see cref="Color"/>.
/// </summary> /// </summary>
/// <param name="alpha">The Alpha channel value in the range from 0..1.</param> /// <param name="alpha">The Alpha component in the range from 0..1.</param>
/// <returns>A new <see cref="Color"/> representing this <see cref="Rgb"/> struct.</returns> /// <returns>A new <see cref="Color"/> representing this <see cref="Rgb"/> struct.</returns>
public Color ToColor(double alpha = 1.0) public Color ToColor(double alpha = 1.0)
{ {

18
src/Avalonia.Controls.ColorPicker/ColorSpectrumChannels.cs → src/Avalonia.Controls.ColorPicker/ColorSpectrumComponents.cs

@ -8,16 +8,16 @@ using Avalonia.Controls.Primitives;
namespace Avalonia.Controls namespace Avalonia.Controls
{ {
/// <summary> /// <summary>
/// Defines the two HSV color channels displayed by a <see cref="ColorSpectrum"/>. /// Defines the two HSV color components displayed by a <see cref="ColorSpectrum"/>.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// Order of the color channels is important and correspond with an X/Y axis in Box /// Order of the color components is important and correspond with an X/Y axis in Box
/// shape or a degree/radius in Ring shape. /// shape or a degree/radius in Ring shape.
/// </remarks> /// </remarks>
public enum ColorSpectrumChannels public enum ColorSpectrumComponents
{ {
/// <summary> /// <summary>
/// The Hue and Value channels. /// The Hue and Value components.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// In Box shape, Hue is mapped to the X-axis and Value is mapped to the Y-axis. /// In Box shape, Hue is mapped to the X-axis and Value is mapped to the Y-axis.
@ -26,7 +26,7 @@ namespace Avalonia.Controls
HueValue, HueValue,
/// <summary> /// <summary>
/// The Value and Hue channels. /// The Value and Hue components.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// In Box shape, Value is mapped to the X-axis and Hue is mapped to the Y-axis. /// In Box shape, Value is mapped to the X-axis and Hue is mapped to the Y-axis.
@ -35,7 +35,7 @@ namespace Avalonia.Controls
ValueHue, ValueHue,
/// <summary> /// <summary>
/// The Hue and Saturation channels. /// The Hue and Saturation components.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// In Box shape, Hue is mapped to the X-axis and Saturation is mapped to the Y-axis. /// In Box shape, Hue is mapped to the X-axis and Saturation is mapped to the Y-axis.
@ -44,7 +44,7 @@ namespace Avalonia.Controls
HueSaturation, HueSaturation,
/// <summary> /// <summary>
/// The Saturation and Hue channels. /// The Saturation and Hue components.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// In Box shape, Saturation is mapped to the X-axis and Hue is mapped to the Y-axis. /// In Box shape, Saturation is mapped to the X-axis and Hue is mapped to the Y-axis.
@ -53,7 +53,7 @@ namespace Avalonia.Controls
SaturationHue, SaturationHue,
/// <summary> /// <summary>
/// The Saturation and Value channels. /// The Saturation and Value components.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// In Box shape, Saturation is mapped to the X-axis and Value is mapped to the Y-axis. /// In Box shape, Saturation is mapped to the X-axis and Value is mapped to the Y-axis.
@ -62,7 +62,7 @@ namespace Avalonia.Controls
SaturationValue, SaturationValue,
/// <summary> /// <summary>
/// The Value and Saturation channels. /// The Value and Saturation components.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// In Box shape, Value is mapped to the X-axis and Saturation is mapped to the Y-axis. /// In Box shape, Value is mapped to the X-axis and Saturation is mapped to the Y-axis.

33
src/Avalonia.Controls.ColorPicker/HsvChannel.cs

@ -1,33 +0,0 @@
// This source file is adapted from the WinUI project.
// (https://github.com/microsoft/microsoft-ui-xaml)
//
// Licensed to The Avalonia Project under the MIT License.
namespace Avalonia.Controls
{
/// <summary>
/// Defines a specific HSV color model channel.
/// </summary>
public enum HsvChannel
{
/// <summary>
/// The Hue channel.
/// </summary>
Hue,
/// <summary>
/// The Saturation channel.
/// </summary>
Saturation,
/// <summary>
/// The Value channel.
/// </summary>
Value,
/// <summary>
/// The Alpha channel.
/// </summary>
Alpha
};
}

47
src/Avalonia.Controls.ColorPicker/HsvComponent.cs

@ -0,0 +1,47 @@
// This source file is adapted from the WinUI project.
// (https://github.com/microsoft/microsoft-ui-xaml)
//
// Licensed to The Avalonia Project under the MIT License.
using Avalonia.Media;
namespace Avalonia.Controls
{
/// <summary>
/// Defines a specific component in the HSV color model.
/// </summary>
public enum HsvComponent
{
/// <summary>
/// The Hue component.
/// </summary>
/// <remarks>
/// Also see: <see cref="HsvColor.H"/>
/// </remarks>
Hue,
/// <summary>
/// The Saturation component.
/// </summary>
/// <remarks>
/// Also see: <see cref="HsvColor.S"/>
/// </remarks>
Saturation,
/// <summary>
/// The Value component.
/// </summary>
/// <remarks>
/// Also see: <see cref="HsvColor.V"/>
/// </remarks>
Value,
/// <summary>
/// The Alpha component.
/// </summary>
/// <remarks>
/// Also see: <see cref="HsvColor.A"/>
/// </remarks>
Alpha
};
}
Loading…
Cancel
Save