Skip to content

Commit

Permalink
format and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneWandererProductions committed Aug 18, 2024
1 parent f5964e9 commit 3088756
Show file tree
Hide file tree
Showing 142 changed files with 815 additions and 2,116 deletions.
2 changes: 1 addition & 1 deletion CommonControls/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
)]
47 changes: 10 additions & 37 deletions CommonControls/ColorPicker.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,7 @@ public double Hue
get => _hue;
set
{
if (_hue.IsEqualTo(value, 10) || value * 180 / Math.PI is > 360 or < 0)
{
return;
}
if (_hue.IsEqualTo(value, 10) || value * 180 / Math.PI is > 360 or < 0) return;

ColorPickerRegister.ColorChanged = true;

Expand All @@ -177,10 +174,7 @@ public double Sat
get => _sat;
set
{
if (_sat.IsEqualTo(value, 10) || value is > 1 or < 0)
{
return;
}
if (_sat.IsEqualTo(value, 10) || value is > 1 or < 0) return;

ColorPickerRegister.ColorChanged = true;

Expand All @@ -201,10 +195,7 @@ public double Val
get => _val;
set
{
if (_val.IsEqualTo(value, 10) || value is > 1 or < 0)
{
return;
}
if (_val.IsEqualTo(value, 10) || value is > 1 or < 0) return;

ColorPickerRegister.ColorChanged = true;

Expand All @@ -225,10 +216,7 @@ public int R
get => _r;
set
{
if (_r == value || value is > 255 or < 0)
{
return;
}
if (_r == value || value is > 255 or < 0) return;

ColorPickerRegister.ColorChanged = true;

Expand All @@ -249,10 +237,7 @@ public int G
get => _g;
set
{
if (_g == value || value is > 255 or < 0)
{
return;
}
if (_g == value || value is > 255 or < 0) return;

ColorPickerRegister.ColorChanged = true;

Expand All @@ -273,10 +258,7 @@ public int B
get => _b;
set
{
if (_b == value || value is > 255 or < 0)
{
return;
}
if (_b == value || value is > 255 or < 0) return;

ColorPickerRegister.ColorChanged = true;

Expand All @@ -296,10 +278,7 @@ public int Alpha
get => _alpha;
set
{
if (_alpha == value || value is > 255 or < 0)
{
return;
}
if (_alpha == value || value is > 255 or < 0) return;

ColorPickerRegister.ColorChanged = true;

Expand Down Expand Up @@ -327,10 +306,7 @@ public string Hex
get => _hex;
set
{
if (_hex == value)
{
return;
}
if (_hex == value) return;

ColorPickerRegister.ColorChanged = true;

Expand Down Expand Up @@ -460,10 +436,7 @@ private void SetPreview()

_ = CanvasPreview.Children.Add(rectangle);

if (ColorPickerRegister.ColorChanged)
{
OnColorChanged();
}
if (ColorPickerRegister.ColorChanged) OnColorChanged();
}

/// <summary>
Expand All @@ -474,4 +447,4 @@ private void OnColorChanged()
ColorChanged?.Invoke(ColorPickerRegister.Colors);
}
}
}
}
2 changes: 1 addition & 1 deletion CommonControls/ColorPickerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ internal static Rectangle GetColorPreview(ColorHsv colorHsv)
return rectangle;
}
}
}
}
2 changes: 1 addition & 1 deletion CommonControls/ColorPickerRegister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ internal static class ColorPickerRegister
/// </value>
internal static ColorHsv Colors { get; set; }
}
}
}
35 changes: 10 additions & 25 deletions CommonControls/ColorProcessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal static bool InCircle(double x, double y)
var xDelta = x - Center;
var yDelta = y - Center;

var dist = (int)Math.Sqrt((xDelta * xDelta) + (yDelta * yDelta));
var dist = (int)Math.Sqrt(xDelta * xDelta + yDelta * yDelta);

return (ColorPickerRegister.InternSize / 2).Interval(dist, 20);
}
Expand All @@ -62,12 +62,9 @@ internal static bool InCircle(double x, double y)
/// <returns>New Hue Value</returns>
internal static double CalcHue(double x, double y)
{
var angle = Math.Atan2(y - Center, x - Center) + (Math.PI / 2);
var angle = Math.Atan2(y - Center, x - Center) + Math.PI / 2;

if (angle < 0)
{
angle += 2 * Math.PI;
}
if (angle < 0) angle += 2 * Math.PI;

return angle;
}
Expand All @@ -90,29 +87,17 @@ internal static bool InTriangle(double x, double y)
//measures: max y = 190, max x = 189

//upper and lower limit
if (y is < 16 or >= 135)
{
return false;
}
if (y is < 16 or >= 135) return false;

// Inside
var sqrt3 = Math.Sqrt(3);
var x1 = (x - Center) * 1.0 / InnerRadius;
var y1 = (y - Center) * 1.0 / InnerRadius;
if ((0 * x1) + (2 * y1) > 1)
{
return false;
}
if (0 * x1 + 2 * y1 > 1) return false;

if ((sqrt3 * x1) + (-1 * y1) > 1)
{
return false;
}
if (sqrt3 * x1 + -1 * y1 > 1) return false;

if ((-sqrt3 * x1) + (-1 * y1) > 1)
{
return false;
}
if (-sqrt3 * x1 + -1 * y1 > 1) return false;

return true;
}
Expand All @@ -128,7 +113,7 @@ internal static double CalcVal(double x, double y)
var x1 = (x - Center) * 1.0 / InnerRadius;
var y1 = (y - Center) * 1.0 / InnerRadius;

return ((Sqrt3 * x1) - y1 + 2) / 3;
return (Sqrt3 * x1 - y1 + 2) / 3;
}

/// <summary>
Expand All @@ -142,7 +127,7 @@ internal static double CalcSat(double x, double y)
var x1 = (x - Center) * 1.0 / InnerRadius;
var y1 = (y - Center) * 1.0 / InnerRadius;

return (1 - (2 * y1)) / ((Sqrt3 * x1) - y1 + 2);
return (1 - 2 * y1) / (Sqrt3 * x1 - y1 + 2);
}
}
}
}
12 changes: 3 additions & 9 deletions CommonControls/ColorSelection.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,7 @@ private void CmbColor_SelectionChanged(object sender, SelectionChangedEventArgs
{
try
{
if (CmbColor?.SelectedItem is not PropertyInfo property)
{
return;
}
if (CmbColor?.SelectedItem is not PropertyInfo property) return;

var selectedColor = (Color)property.GetValue(null, null);
StartColor = _colorDct.FirstOrDefault(x => x.Value == selectedColor).Key;
Expand Down Expand Up @@ -184,10 +181,7 @@ private static Dictionary<string, Color> InitiateColors()
/// </summary>
private void SwitchToStartColor()
{
if (string.IsNullOrEmpty(StartColor))
{
return;
}
if (string.IsNullOrEmpty(StartColor)) return;

CmbColor.SelectedItem = typeof(Colors).GetProperty(StartColor);
}
Expand All @@ -202,4 +196,4 @@ private static void ShowErrorMessageBox(string message, Exception ex)
MessageBox.Show($"{message}: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}
70 changes: 19 additions & 51 deletions CommonControls/Colorpick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ internal static void Selection(double x, double y, int alpha)

//Check circle
check = ColorProcessing.InCircle(x, y);
if (check)
{
_hue = ColorProcessing.CalcHue(x, y);
}
if (check) _hue = ColorProcessing.CalcHue(x, y);

ColorPickerRegister.Colors = new ColorHsv(_hue, _sat, _val, alpha);
}
Expand Down Expand Up @@ -189,23 +186,18 @@ private static Image DrawImage(double hue = 3.3, double sat = 1.0, double val =
/// <returns>Clicked results</returns>
private static PickResult Pick(double x, double y)
{
var distanceFromCenter = Math.Sqrt(((x - Center) * (x - Center)) + ((y - Center) * (y - Center)));
var distanceFromCenter = Math.Sqrt((x - Center) * (x - Center) + (y - Center) * (y - Center));
var sqrt3 = Math.Sqrt(3);

if (distanceFromCenter > OuterRadius)
// Outside
{
return new PickResult { Area = Area.Outside };
}

if (distanceFromCenter > InnerRadius)
{
// Wheel
var angle = Math.Atan2(y - Center, x - Center) + (Math.PI / 2);
if (angle < 0)
{
angle += 2 * Math.PI;
}
var angle = Math.Atan2(y - Center, x - Center) + Math.PI / 2;
if (angle < 0) angle += 2 * Math.PI;

var hue = angle;

Expand All @@ -215,24 +207,15 @@ private static PickResult Pick(double x, double y)
// Inside
var x1 = (x - Center) * 1.0 / InnerRadius;
var y1 = (y - Center) * 1.0 / InnerRadius;
if ((0 * x1) + (2 * y1) > 1)
{
return new PickResult { Area = Area.Outside };
}
if (0 * x1 + 2 * y1 > 1) return new PickResult { Area = Area.Outside };

if ((sqrt3 * x1) + (-1 * y1) > 1)
{
return new PickResult { Area = Area.Outside };
}
if (sqrt3 * x1 + -1 * y1 > 1) return new PickResult { Area = Area.Outside };

if ((-sqrt3 * x1) + (-1 * y1) > 1)
{
return new PickResult { Area = Area.Outside };
}
if (-sqrt3 * x1 + -1 * y1 > 1) return new PickResult { Area = Area.Outside };

// Triangle
var sat = (1 - (2 * y1)) / ((sqrt3 * x1) - y1 + 2);
var val = ((sqrt3 * x1) - y1 + 2) / 3;
var sat = (1 - 2 * y1) / (sqrt3 * x1 - y1 + 2);
var val = (sqrt3 * x1 - y1 + 2) / 3;

return new PickResult { Area = Area.Triangle, Sat = sat, Val = val };
}
Expand All @@ -249,33 +232,18 @@ private static Color Hsv(double hue, double sat, double val, double alpha)
{
var chroma = val * sat;
const double step = Math.PI / 3;
var intern = chroma * (1 - Math.Abs((hue / step % 2.0) - 1));
var intern = chroma * (1 - Math.Abs(hue / step % 2.0 - 1));
var shift = val - chroma;

if (hue < 1 * step)
{
return Rgb(shift + chroma, shift + intern, shift + 0, alpha);
}
if (hue < 1 * step) return Rgb(shift + chroma, shift + intern, shift + 0, alpha);

if (hue < 2 * step)
{
return Rgb(shift + intern, shift + chroma, shift + 0, alpha);
}
if (hue < 2 * step) return Rgb(shift + intern, shift + chroma, shift + 0, alpha);

if (hue < 3 * step)
{
return Rgb(shift + 0, shift + chroma, shift + intern, alpha);
}
if (hue < 3 * step) return Rgb(shift + 0, shift + chroma, shift + intern, alpha);

if (hue < 4 * step)
{
return Rgb(shift + 0, shift + intern, shift + chroma, alpha);
}
if (hue < 4 * step) return Rgb(shift + 0, shift + intern, shift + chroma, alpha);

if (hue < 5 * step)
{
return Rgb(shift + intern, shift + 0, shift + chroma, alpha);
}
if (hue < 5 * step) return Rgb(shift + intern, shift + 0, shift + chroma, alpha);

return Rgb(shift + chroma, shift + 0, shift + intern, alpha);
}
Expand All @@ -290,7 +258,7 @@ private static Point GetWheelPosition()

return new Point
{
X = Center + (middleRadius * Math.Sin(_hue)), Y = Center - (middleRadius * Math.Cos(_hue))
X = Center + middleRadius * Math.Sin(_hue), Y = Center - middleRadius * Math.Cos(_hue)
};
}

Expand All @@ -304,8 +272,8 @@ private static Point GetTrianglePosition()

return new Point
{
X = Center + (InnerRadius * ((2 * _val) - (_sat * _val) - 1) * sqrt3 / 2),
Y = Center + (InnerRadius * (1 - (3 * _sat * _val)) / 2)
X = Center + InnerRadius * (2 * _val - _sat * _val - 1) * sqrt3 / 2,
Y = Center + InnerRadius * (1 - 3 * _sat * _val) / 2
};
}

Expand Down Expand Up @@ -364,4 +332,4 @@ internal struct PickResult
/// </value>
internal double Val { get; init; }
}
}
}
2 changes: 1 addition & 1 deletion CommonControls/ColorpickerMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ private void AddColor(ColorHsv colorHsv)
_ = CanvasPreview.Children.Add(rectangle);
}
}
}
}
2 changes: 1 addition & 1 deletion CommonControls/ComCtlResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ internal static class ComCtlResources
/// </summary>
internal const string Separator = " , ";
}
}
}
Loading

0 comments on commit 3088756

Please sign in to comment.