Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed Jan 1, 2025
1 parent c7beda3 commit 33b8b0f
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 32 deletions.
8 changes: 3 additions & 5 deletions ColorPicker/Classes/Bookmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,9 @@ public BookmarkText(string font, string fore, string back)

public bool Equals(BookmarkText? obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
return FontFamily == obj.FontFamily && ForegroundColor == obj.ForegroundColor && BackgroundColor == obj.BackgroundColor;
return obj == null || GetType() != obj.GetType()
? false
: FontFamily == obj.FontFamily && ForegroundColor == obj.ForegroundColor && BackgroundColor == obj.BackgroundColor;
}


Expand Down
12 changes: 3 additions & 9 deletions ColorPicker/Classes/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ public static (string, int) GetContrast(int[] rgb1, int[] rgb2)

var result = Math.Round((brightest + 0.05) / (darkest + 0.05), 4);

int gridRow;
if (result > 7) gridRow = 0;
else gridRow = 0;
int gridRow = result > 7 ? 0 : 0;
if (result <= 3) gridRow = 3;
if (result >= 3 && result <= 4.5) gridRow = 2;
if (result >= 4.5 && result <= 7) gridRow = 1;
Expand Down Expand Up @@ -528,10 +526,7 @@ public static void ColorToHSL(Color color, out float h, out float s, out float l
float delta = max - min;
if (max == r)
h = (g - b) / delta + (g < b ? 6 : 0);
else if (max == g)
h = (b - r) / delta + 2;
else
h = (r - g) / delta + 4;
else h = max == g ? (b - r) / delta + 2 : (r - g) / delta + 4;
h /= 6f;
}

Expand Down Expand Up @@ -566,7 +561,6 @@ private static float HueToRGB(float p, float q, float t)
if (t > 1) t -= 1;
if (t < 1.0 / 6.0) return p + (q - p) * 6 * t;
if (t < 1.0 / 2.0) return q;
if (t < 2.0 / 3.0) return p + (q - p) * (2.0f / 3.0f - t) * 6;
return p;
return t < 2.0 / 3.0 ? p + (q - p) * (2.0f / 3.0f - t) * 6 : p;
}
}
4 changes: 2 additions & 2 deletions ColorPicker/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ public MainWindow()
GC.Collect();
}

DoubleAnimation expandAnimation = new()
readonly DoubleAnimation expandAnimation = new()
{
From = 0,
To = 180,
Duration = new Duration(TimeSpan.FromSeconds(0.2)),
};

DoubleAnimation collapseAnimation = new()
readonly DoubleAnimation collapseAnimation = new()
{
From = 180,
To = 0,
Expand Down
1 change: 0 additions & 1 deletion ColorPicker/Pages/AiGenPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using OpenAI.ObjectModels.RequestModels;
using Synethia;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.Json;
Expand Down
5 changes: 3 additions & 2 deletions ColorPicker/Pages/ContrastPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ private RGB ConvertToRgb()
else if (SelectedColorBtn == YuvBtn) return ColorHelper.ColorConverter.YuvToRgb(new(double.Parse(Txt1.Text),
double.Parse(Txt2.Text),
double.Parse(Txt3.Text)));
else if (SelectedColorBtn == DecBtn) return new DEC(int.Parse(Txt5.Text)).ToRgb();
else return ColorHelper.ColorConverter.YiqToRgb(new(double.Parse(Txt1.Text),
else return SelectedColorBtn == DecBtn
? new DEC(int.Parse(Txt5.Text)).ToRgb()
: ColorHelper.ColorConverter.YiqToRgb(new(double.Parse(Txt1.Text),
double.Parse(Txt2.Text),
double.Parse(Txt3.Text)));
}
Expand Down
5 changes: 3 additions & 2 deletions ColorPicker/Pages/ConverterPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ private RGB ConvertToRgb()
else if (SelectedColorBtn == YuvBtn) return ColorHelper.ColorConverter.YuvToRgb(new(double.Parse(Txt1.Text),
double.Parse(Txt2.Text),
double.Parse(Txt3.Text)));
else if (SelectedColorBtn == DecBtn) return new DEC(int.Parse(Txt5.Text)).ToRgb();
else return ColorHelper.ColorConverter.YiqToRgb(new(double.Parse(Txt1.Text),
else return SelectedColorBtn == DecBtn
? new DEC(int.Parse(Txt5.Text)).ToRgb()
: ColorHelper.ColorConverter.YiqToRgb(new(double.Parse(Txt1.Text),
double.Parse(Txt2.Text),
double.Parse(Txt3.Text)));
}
Expand Down
5 changes: 3 additions & 2 deletions ColorPicker/Pages/GradientPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,9 @@ private ColorHelper.RGB ConvertToRgb()
else if (SelectedColorBtn == YuvBtn) return ColorHelper.ColorConverter.YuvToRgb(new(double.Parse(Txt1.Text),
double.Parse(Txt2.Text),
double.Parse(Txt3.Text)));
else if (SelectedColorBtn == DecBtn) return new DEC(int.Parse(Txt5.Text)).ToRgb();
else return ColorHelper.ColorConverter.YiqToRgb(new(double.Parse(Txt1.Text),
else return SelectedColorBtn == DecBtn
? new DEC(int.Parse(Txt5.Text)).ToRgb()
: ColorHelper.ColorConverter.YiqToRgb(new(double.Parse(Txt1.Text),
double.Parse(Txt2.Text),
double.Parse(Txt3.Text)));
}
Expand Down
1 change: 0 additions & 1 deletion ColorPicker/Pages/ImageExtractorPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using ColorPicker.UserControls;
using Microsoft.Win32;
using Synethia;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
Expand Down
5 changes: 3 additions & 2 deletions ColorPicker/Pages/PalettePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ private RGB ConvertToRgb()
else if (SelectedColorBtn == YuvBtn) return ColorHelper.ColorConverter.YuvToRgb(new(double.Parse(Txt1.Text),
double.Parse(Txt2.Text),
double.Parse(Txt3.Text)));
else if (SelectedColorBtn == DecBtn) return new DEC(int.Parse(Txt5.Text)).ToRgb();
else return ColorHelper.ColorConverter.YiqToRgb(new(double.Parse(Txt1.Text),
else return SelectedColorBtn == DecBtn
? new DEC(int.Parse(Txt5.Text)).ToRgb()
: ColorHelper.ColorConverter.YiqToRgb(new(double.Parse(Txt1.Text),
double.Parse(Txt2.Text),
double.Parse(Txt3.Text)));
}
Expand Down
6 changes: 3 additions & 3 deletions ColorPicker/Pages/SelectorPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private void HandleSelectKeyboard()
Global.SynethiaConfig.ActionsInfo[0].UsageCount++; // Increment the usage counter
}

List<string> RecentColors = [];
readonly List<string> RecentColors = [];
private void HandleCopyKeyboard()
{
try
Expand Down Expand Up @@ -324,10 +324,10 @@ internal void LoadDetails()
{
1 => new ColorInfo(ColorHelper.ColorConverter.HsvToRgb(new((int)RedSlider.Value, (byte)GreenSlider.Value, (byte)BlueSlider.Value))),
2 => new ColorInfo(ColorHelper.ColorConverter.HslToRgb(new((int)RedSlider.Value, (byte)GreenSlider.Value, (byte)BlueSlider.Value))),
3 => new ColorInfo(ColorHelper.ColorConverter.CmykToRgb(new((byte)RedSlider.Value, (byte)GreenSlider.Value, (byte)BlueSlider.Value, (byte)KSlider.Value)))
3 => new ColorInfo(ColorHelper.ColorConverter.CmykToRgb(new((byte)RedSlider.Value, (byte)GreenSlider.Value, (byte)BlueSlider.Value, (byte)KSlider.Value)))
{ CMYK = new((byte)RedSlider.Value, (byte)GreenSlider.Value, (byte)BlueSlider.Value, (byte)KSlider.Value) },
_ => new ColorInfo(new((byte)RedSlider.Value, (byte)GreenSlider.Value, (byte)BlueSlider.Value))
} ;
};
RgbTxt.Text = $"{ColorInfo.RGB.R}{Global.Settings.RgbSeparator}{ColorInfo.RGB.G}{Global.Settings.RgbSeparator}{ColorInfo.RGB.B}";
HexTxt.Text = $"#{ColorInfo.HEX.Value}";
HsvTxt.Text = $"{ColorInfo.HSV.H}, {ColorInfo.HSV.S}, {ColorInfo.HSV.V}";
Expand Down
7 changes: 4 additions & 3 deletions ColorPicker/Pages/TextPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private void BackgroundBorder_MouseLeftButtonUp(object sender, MouseButtonEventA
RgbBtn_Click(SelectedColorBtn, null);
ColorSelector.IsOpen = true;
}
Random random = new();
readonly Random random = new();

private void GenerateGradientBtn_Click(object sender, System.Windows.RoutedEventArgs e)
{
Expand Down Expand Up @@ -529,8 +529,9 @@ private ColorHelper.RGB ConvertToRgb()
else if (SelectedColorBtn == YuvBtn) return ColorHelper.ColorConverter.YuvToRgb(new(double.Parse(Txt1.Text),
double.Parse(Txt2.Text),
double.Parse(Txt3.Text)));
else if (SelectedColorBtn == DecBtn) return new DEC(int.Parse(Txt5.Text)).ToRgb();
else return ColorHelper.ColorConverter.YiqToRgb(new(double.Parse(Txt1.Text),
else return SelectedColorBtn == DecBtn
? new DEC(int.Parse(Txt5.Text)).ToRgb()
: ColorHelper.ColorConverter.YiqToRgb(new(double.Parse(Txt1.Text),
double.Parse(Txt2.Text),
double.Parse(Txt3.Text)));
}
Expand Down

0 comments on commit 33b8b0f

Please sign in to comment.