Wiesław Šoltés 2022-09-01 08:35:18 +02:00
Родитель 86f0550c7f 44fc7d14f4
Коммит 99396746da
8 изменённых файлов: 37 добавлений и 316 удалений

Просмотреть файл

@ -132,6 +132,10 @@ public class ColorPickerAreaSlider : TemplatedControl
private void ColorThumb_DragDelta(object? sender, VectorEventArgs e)
{
if (_colorThumb is null)
{
return;
}
var left = Canvas.GetLeft(_colorThumb);
var top = Canvas.GetTop(_colorThumb);
_updating = true;
@ -172,6 +176,10 @@ public class ColorPickerAreaSlider : TemplatedControl
private void UpdateValuesFromThumbs()
{
if (_colorThumb is null)
{
return;
}
var colorX = Canvas.GetLeft(_colorThumb);
var colorY = Canvas.GetTop(_colorThumb);
Value2 = ConvertBack(_value2Converter, colorX, GetValue2Range());

Просмотреть файл

@ -120,6 +120,10 @@ public class ColorPickerHorizontalSlider : TemplatedControl
private void AlphaThumb_DragDelta(object? sender, VectorEventArgs e)
{
if (_alphaThumb is null)
{
return;
}
var left = Canvas.GetLeft(_alphaThumb);
_updating = true;
MoveThumb(_alphaCanvas, _alphaThumb, left + e.Vector.X, 0);
@ -158,6 +162,10 @@ public class ColorPickerHorizontalSlider : TemplatedControl
private void UpdateValuesFromThumbs()
{
if (_alphaThumb is null)
{
return;
}
var alphaX = Canvas.GetLeft(_alphaThumb);
Value4 = ConvertBack(_value4Converter, alphaX, GetValue4Range());
}

Просмотреть файл

@ -120,6 +120,10 @@ public class ColorPickerVerticalSlider : TemplatedControl
private void HueThumb_DragDelta(object? sender, VectorEventArgs e)
{
if (_hueThumb is null)
{
return;
}
var top = Canvas.GetTop(_hueThumb);
_updating = true;
MoveThumb(_hueCanvas, _hueThumb, 0, top + e.Vector.Y);
@ -158,6 +162,10 @@ public class ColorPickerVerticalSlider : TemplatedControl
private void UpdateValuesFromThumbs()
{
if (_hueThumb is null)
{
return;
}
var hueY = Canvas.GetTop(_hueThumb);
Value1 = ConvertBack(_value1Converter, hueY, GetValue1Range());
}

Просмотреть файл

@ -6,33 +6,7 @@ namespace ThemeEditor.Controls.ColorPicker.Props;
public class AlphaProperties : ColorPickerProperties
{
public static readonly StyledProperty<double?> AlphaProperty =
AvaloniaProperty.Register<AlphaProperties, double?>(nameof(Alpha), 100.0, validate: ValidateAlpha, coerce: CoerceAlpha);
private static double? CoerceAlpha(IAvaloniaObject arg1, double? arg2)
{
if (arg2 is null)
{
return null;
}
if (double.IsNaN(arg2.Value))
{
return 100.0;
}
return ColorPickerHelpers.Clamp(arg2.Value, 0.0, 100.0);
}
private static bool ValidateAlpha(double? alpha)
{
if (alpha is null)
{
return true;
}
if (alpha < 0.0 || alpha > 100.0)
{
return false;
}
return true;
}
AvaloniaProperty.Register<AlphaProperties, double?>(nameof(Alpha), 100.0);
private bool _updating;

Просмотреть файл

@ -7,120 +7,16 @@ namespace ThemeEditor.Controls.ColorPicker.Props;
public class CmykProperties : ColorPickerProperties
{
public static readonly StyledProperty<double?> CyanProperty =
AvaloniaProperty.Register<CmykProperties, double?>(nameof(Cyan), 0.0, validate: ValidateCyan, coerce: CoerceCyan);
AvaloniaProperty.Register<CmykProperties, double?>(nameof(Cyan), 0.0);
public static readonly StyledProperty<double?> MagentaProperty =
AvaloniaProperty.Register<CmykProperties, double?>(nameof(Magenta), 100.0, validate: ValidateMagenta, coerce: CoerceMagenta);
AvaloniaProperty.Register<CmykProperties, double?>(nameof(Magenta), 100.0);
public static readonly StyledProperty<double?> YellowProperty =
AvaloniaProperty.Register<CmykProperties, double?>(nameof(Yellow), 100.0, validate: ValidateYellow, coerce: CoerceYellow);
AvaloniaProperty.Register<CmykProperties, double?>(nameof(Yellow), 100.0);
public static readonly StyledProperty<double?> BlackKeyProperty =
AvaloniaProperty.Register<CmykProperties, double?>(nameof(BlackKey), 0.0, validate: ValidateBlackKey, coerce: CoerceBlackKey);
private static double? CoerceCyan(IAvaloniaObject arg1, double? arg2)
{
if (arg2 is null)
{
return null;
}
if (double.IsNaN(arg2.Value))
{
return 0.0;
}
return ColorPickerHelpers.Clamp(arg2.Value, 0.0, 100.0);
}
private static double? CoerceMagenta(IAvaloniaObject arg1, double? arg2)
{
if (arg2 is null)
{
return null;
}
if (double.IsNaN(arg2.Value))
{
return 0.0;
}
return ColorPickerHelpers.Clamp(arg2.Value, 0.0, 100.0);
}
private static double? CoerceYellow(IAvaloniaObject arg1, double? arg2)
{
if (arg2 is null)
{
return null;
}
if (double.IsNaN(arg2.Value))
{
return 0.0;
}
return ColorPickerHelpers.Clamp(arg2.Value, 0.0, 100.0);
}
private static double? CoerceBlackKey(IAvaloniaObject arg1, double? arg2)
{
if (arg2 is null)
{
return null;
}
if (double.IsNaN(arg2.Value))
{
return 0.0;
}
return ColorPickerHelpers.Clamp(arg2.Value, 0.0, 100.0);
}
private static bool ValidateCyan(double? cyan)
{
if (cyan is null)
{
return true;
}
if (cyan < 0.0 || cyan > 100.0)
{
return false;
}
return true;
}
private static bool ValidateMagenta(double? magenta)
{
if (magenta is null)
{
return true;
}
if (magenta < 0.0 || magenta > 100.0)
{
return false;
}
return true;
}
private static bool ValidateYellow(double? yellow)
{
if (yellow is null)
{
return true;
}
if (yellow < 0.0 || yellow > 100.0)
{
return false;
}
return true;
}
private static bool ValidateBlackKey(double? blackKey)
{
if (blackKey is null)
{
return true;
}
if (blackKey < 0.0 || blackKey > 100.0)
{
return false;
}
return true;
}
AvaloniaProperty.Register<CmykProperties, double?>(nameof(BlackKey), 0.0);
private bool _updating;

Просмотреть файл

@ -7,35 +7,7 @@ namespace ThemeEditor.Controls.ColorPicker.Props;
public class HexProperties : ColorPickerProperties
{
public static readonly StyledProperty<string?> HexProperty =
AvaloniaProperty.Register<HexProperties, string?>(nameof(Hex), "#FFFF0000", validate: ValidateHex, coerce: CoerceHex);
private static string? CoerceHex(IAvaloniaObject arg1, string? arg2)
{
if (arg2 is null)
{
return "#FFFF0000";
}
if (!ColorPickerHelpers.IsValidHexColor(arg2))
{
return "#FFFF0000";
}
return arg2;
}
private static bool ValidateHex(string? hex)
{
if (hex is null)
{
return true;
}
if (!ColorPickerHelpers.IsValidHexColor(hex))
{
return false;
}
return true;
}
AvaloniaProperty.Register<HexProperties, string?>(nameof(Hex));
private bool _updating;
@ -53,7 +25,7 @@ public class HexProperties : ColorPickerProperties
protected override void UpdateColorPickerValues()
{
if (_updating == false && Presenter != null)
if (_updating == false && Presenter != null && Hex is { })
{
_updating = true;
var color = Color.Parse(Hex);

Просмотреть файл

@ -6,87 +6,13 @@ namespace ThemeEditor.Controls.ColorPicker.Props;
public class HsvProperties : ColorPickerProperties
{
public static readonly StyledProperty<double?> HueProperty =
AvaloniaProperty.Register<HsvProperties, double?>(nameof(Hue), 0.0, validate: ValidateHue, coerce: CoerceHue);
AvaloniaProperty.Register<HsvProperties, double?>(nameof(Hue), 0.0);
public static readonly StyledProperty<double?> SaturationProperty =
AvaloniaProperty.Register<HsvProperties, double?>(nameof(Saturation), 100.0, validate: ValidateSaturation, coerce: CoerceSaturation);
AvaloniaProperty.Register<HsvProperties, double?>(nameof(Saturation), 100.0);
public static readonly StyledProperty<double?> ValueProperty =
AvaloniaProperty.Register<HsvProperties, double?>(nameof(Value), 100.0, validate: ValidateValue, coerce: CoerceValue);
private static double? CoerceHue(IAvaloniaObject arg1, double? arg2)
{
if (arg2 is null)
{
return null;
}
if (double.IsNaN(arg2.Value))
{
return 0.0;
}
return ColorPickerHelpers.Clamp(arg2.Value, 0.0, 360.0);
}
private static double? CoerceSaturation(IAvaloniaObject arg1, double? arg2)
{
if (arg2 is null)
{
return null;
}
if (double.IsNaN(arg2.Value))
{
return 0.0;
}
return ColorPickerHelpers.Clamp(arg2.Value, 0.0, 100.0);
}
private static double? CoerceValue(IAvaloniaObject arg1, double? arg2)
{
if (arg2 is null)
{
return null;
}
if (double.IsNaN(arg2.Value))
{
return 0.0;
}
return ColorPickerHelpers.Clamp(arg2.Value, 0.0, 100.0);
}
private static bool ValidateHue(double? hue)
{
if (hue < 0.0 || hue > 360.0)
{
return false;
}
return true;
}
private static bool ValidateSaturation(double? saturation)
{
if (saturation is null)
{
return true;
}
if (saturation < 0.0 || saturation > 100.0)
{
return false;
}
return true;
}
private static bool ValidateValue(double? value)
{
if (value is null)
{
return true;
}
if (value < 0.0 || value > 100.0)
{
return false;
}
return true;
}
AvaloniaProperty.Register<HsvProperties, double?>(nameof(Value), 100.0);
private bool _updating;

Просмотреть файл

@ -7,84 +7,13 @@ namespace ThemeEditor.Controls.ColorPicker.Props;
public class RgbProperties : ColorPickerProperties
{
public static readonly StyledProperty<byte?> RedProperty =
AvaloniaProperty.Register<RgbProperties, byte?>(nameof(Red), 0xFF, validate: ValidateRed, coerce: CoerceRed);
AvaloniaProperty.Register<RgbProperties, byte?>(nameof(Red), 0xFF);
public static readonly StyledProperty<byte?> GreenProperty =
AvaloniaProperty.Register<RgbProperties, byte?>(nameof(Green), 0x00, validate: ValidateGreen, coerce: CoerceGreen);
AvaloniaProperty.Register<RgbProperties, byte?>(nameof(Green));
public static readonly StyledProperty<byte?> BlueProperty =
AvaloniaProperty.Register<RgbProperties, byte?>(nameof(Blue), 0x00, validate: ValidateBlue, coerce: CoerceBlue);
private static byte? CoerceRed(IAvaloniaObject arg1, byte? arg2)
{
if (arg2 is null)
{
return null;
}
return ColorPickerHelpers.Clamp(arg2.Value, 0, 255);
}
private static byte? CoerceGreen(IAvaloniaObject arg1, byte? arg2)
{
if (arg2 is null)
{
return null;
}
return ColorPickerHelpers.Clamp(arg2.Value, 0, 255);
}
private static byte? CoerceBlue(IAvaloniaObject arg1, byte? arg2)
{
if (arg2 is null)
{
return null;
}
return ColorPickerHelpers.Clamp(arg2.Value, 0, 255);
}
private static bool ValidateRed(byte? red)
{
if (red is null)
{
return true;
}
// ReSharper disable ConditionIsAlwaysTrueOrFalse
if (red < 0 || red > 255) // ReSharper restore ConditionIsAlwaysTrueOrFalse
{
return false;
}
return true;
}
private static bool ValidateGreen(byte? green)
{
if (green is null)
{
return true;
}
// ReSharper disable ConditionIsAlwaysTrueOrFalse
if (green < 0 || green > 255)
// ReSharper restore ConditionIsAlwaysTrueOrFalse
{
return false;
}
return true;
}
private static bool ValidateBlue(byte? blue)
{
if (blue is null)
{
return true;
}
// ReSharper disable ConditionIsAlwaysTrueOrFalse
if (blue < 0 || blue > 255)
// ReSharper restore ConditionIsAlwaysTrueOrFalse
{
return false;
}
return true;
}
AvaloniaProperty.Register<RgbProperties, byte?>(nameof(Blue));
private bool _updating;