Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneWandererProductions committed Jan 1, 2025
1 parent 16d49c5 commit f7d0e59
Show file tree
Hide file tree
Showing 83 changed files with 1,276 additions and 481 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)
)]
)]
49 changes: 39 additions & 10 deletions CommonControls/ColorPicker.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ 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 @@ -197,7 +200,10 @@ 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 @@ -218,7 +224,10 @@ 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 @@ -239,7 +248,10 @@ 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 @@ -260,7 +272,10 @@ 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 @@ -281,7 +296,10 @@ 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 @@ -301,7 +319,10 @@ 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 @@ -329,7 +350,10 @@ public string Hex
get => _hex;
set
{
if (_hex == value) return;
if (_hex == value)
{
return;
}

ColorPickerRegister.ColorChanged = true;

Expand Down Expand Up @@ -389,7 +413,9 @@ private static void OnShowTextBoxesChanged(DependencyObject d, DependencyPropert
{
if (d is ColorPicker colorPicker)
// Force layout update on visibility change
{
colorPicker.UpdateLayout();
}
}

/// <summary>
Expand Down Expand Up @@ -471,7 +497,10 @@ private void SetPreview()

_ = CanvasPreview.Children.Add(rectangle);

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

/// <summary>
Expand All @@ -482,4 +511,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: 25 additions & 10 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,9 +62,12 @@ 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 @@ -87,17 +90,29 @@ 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 @@ -113,7 +128,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 @@ -127,7 +142,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: 9 additions & 3 deletions CommonControls/ColorSelection.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ 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 @@ -181,7 +184,10 @@ 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 @@ -196,4 +202,4 @@ private static void ShowErrorMessageBox(string message, Exception ex)
MessageBox.Show($"{message}: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}
70 changes: 51 additions & 19 deletions CommonControls/Colorpick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ 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 @@ -186,18 +189,23 @@ 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 @@ -207,15 +215,24 @@ 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 @@ -232,18 +249,33 @@ 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 @@ -258,7 +290,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 @@ -272,8 +304,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 @@ -332,4 +364,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 @@ -124,4 +124,4 @@ private void AddColor(ColorHsv colorHsv)
_ = CanvasPreview.Children.Add(rectangle);
}
}
}
}
Loading

0 comments on commit f7d0e59

Please sign in to comment.