Skip to content

Commit

Permalink
Merge pull request #330 from Leo-Corporation/vNext
Browse files Browse the repository at this point in the history
Version 5.6.0.2310
  • Loading branch information
lpeyr authored Oct 22, 2023
2 parents 3eac70e + bd4fe60 commit 64c02fb
Show file tree
Hide file tree
Showing 17 changed files with 317 additions and 31 deletions.
4 changes: 2 additions & 2 deletions ColorPicker.Setup/Setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "ColorPicker Max"
#define MyAppVersion "5.5.0.2309"
#define MyAppFullVersion "5.5.0.2309"
#define MyAppVersion "5.6.0.2310"
#define MyAppFullVersion "5.6.0.2310"
#define MyAppPublisher "Léo Corporation"
#define MyAppURL "https://leocorporation.dev/"
#define MyAppExeName "ColorPicker.exe"
Expand Down
9 changes: 8 additions & 1 deletion ColorPicker/Classes/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static class Global
internal static string SettingsPath => $@"{FileSys.AppDataPath}\Léo Corporation\ColorPicker Max\Settings.xml";
public static string LastVersionLink => "https://raw.githubusercontent.com/Leo-Corporation/LeoCorp-Docs/master/Liens/Update%20System/ColorPicker/5.0/Version.txt";

public static string Version => "5.5.0.2309";
public static string Version => "5.6.0.2310";

public static string HiSentence
{
Expand Down Expand Up @@ -335,4 +335,11 @@ public static bool IsSameKeyboardShortcut(string comb1, string comb2)
}
return true;
}

public static string GetRandomAiPrompt()
{
Random random = new();
string[] prompts = Properties.Resources.AiPrompts.Split(",");
return prompts[random.Next(prompts.Length)];
}
}
2 changes: 2 additions & 0 deletions ColorPicker/Classes/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public Settings()
IsMaximized = false;
ApiKey = "";
Model = "gpt-3.5-turbo";
SupportedModels = new[] { "gpt-3.5-turbo", "gpt-4" };
}

public Themes Theme { get; set; }
Expand All @@ -65,5 +66,6 @@ public Settings()
public bool IsMaximized { get; set; }
public string? ApiKey { get; set; }
public string? Model { get; set; }
public string[]? SupportedModels { get; set; }
}
}
8 changes: 4 additions & 4 deletions ColorPicker/ColorPicker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Title>ColorPicker</Title>
<Description>Maximize your creativity.</Description>
<RepositoryUrl>https://github.com/Leo-Corporation/ColorPicker</RepositoryUrl>
<Version>5.5.0.2309</Version>
<Version>5.6.0.2310</Version>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIcon>logo.png</PackageIcon>
<ApplicationIcon>CPM.ico</ApplicationIcon>
Expand Down Expand Up @@ -47,11 +47,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Betalgo.OpenAI" Version="7.1.5" />
<PackageReference Include="Betalgo.OpenAI" Version="7.3.1" />
<PackageReference Include="ColorHelper" Version="1.8.1" />
<PackageReference Include="MouseKeyHook" Version="5.7.1" />
<PackageReference Include="PeyrSharp.Env" Version="1.9.0.2309" />
<PackageReference Include="PeyrSharp.Core" Version="1.9.0.2309" />
<PackageReference Include="PeyrSharp.Env" Version="1.10.0.2310" />
<PackageReference Include="PeyrSharp.Core" Version="1.10.0.2310" />
<PackageReference Include="Synethia" Version="1.1.1.2302" />
</ItemGroup>

Expand Down
67 changes: 62 additions & 5 deletions ColorPicker/Pages/AiGenPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@
Text="{x:Static lang:Resources.AIGeneration}" />
</StackPanel>

<StackPanel
Grid.Row="1"
Margin="10"
Orientation="Horizontal">
<Grid Grid.Row="1" Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Button
x:Name="ColorBtn"
Margin="0 2"
Expand Down Expand Up @@ -77,6 +80,7 @@
</Button>
<Button
x:Name="PaletteBtn"
Grid.Column="1"
Margin="10 2 0 2"
Padding="5"
HorizontalContentAlignment="Stretch"
Expand Down Expand Up @@ -105,7 +109,26 @@
Text="{x:Static lang:Resources.Palettes}" />
</Grid>
</Button>
</StackPanel>
<Button
x:Name="BookmarkBtn"
Grid.Column="3"
Padding="5"
VerticalAlignment="Top"
Background="{Binding Source={StaticResource Background3}}"
Click="BookmarkBtn_Click"
Content="&#xF1F6;"
FontFamily="..\Fonts\#FluentSystemIcons-Regular"
Foreground="{Binding Source={StaticResource Foreground1}}"
Style="{DynamicResource DefaultButton}">
<Button.ToolTip>
<ToolTip
x:Name="BookmarkToolTip"
Background="{Binding Source={StaticResource Background1}}"
Content="{x:Static lang:Resources.AddBookmark}"
Foreground="{Binding Source={StaticResource Foreground1}}" />
</Button.ToolTip>
</Button>
</Grid>

<StackPanel
x:Name="ColorPanel"
Expand Down Expand Up @@ -157,6 +180,23 @@
FontWeight="Bold"
Foreground="{Binding Source={StaticResource WindowButtonsHoverForeground1}}"
Style="{DynamicResource PrimaryButton}" />
<Button
x:Name="IdeaBtn"
Grid.Column="2"
Padding="5"
Background="{Binding Source={StaticResource Background3}}"
Click="IdeaBtn_Click"
Content="&#xF4DB;"
FontFamily="..\Fonts\#FluentSystemIcons-Regular"
Foreground="{Binding Source={StaticResource Foreground1}}"
Style="{DynamicResource DefaultButton}">
<Button.ToolTip>
<ToolTip
Background="{Binding Source={StaticResource Background1}}"
Content="{x:Static lang:Resources.GetIdeas}"
Foreground="{Binding Source={StaticResource Foreground1}}" />
</Button.ToolTip>
</Button>
</StackPanel>
</StackPanel>

Expand Down Expand Up @@ -297,6 +337,23 @@
FontWeight="Bold"
Foreground="{Binding Source={StaticResource WindowButtonsHoverForeground1}}"
Style="{DynamicResource PrimaryButton}" />
<Button
x:Name="IdeaPaletteBtn"
Grid.Column="2"
Padding="5"
Background="{Binding Source={StaticResource Background3}}"
Click="IdeaPaletteBtn_Click"
Content="&#xF4DB;"
FontFamily="..\Fonts\#FluentSystemIcons-Regular"
Foreground="{Binding Source={StaticResource Foreground1}}"
Style="{DynamicResource DefaultButton}">
<Button.ToolTip>
<ToolTip
Background="{Binding Source={StaticResource Background1}}"
Content="{x:Static lang:Resources.GetIdeas}"
Foreground="{Binding Source={StaticResource Foreground1}}" />
</Button.ToolTip>
</Button>
</StackPanel>
</StackPanel>

Expand Down
33 changes: 32 additions & 1 deletion ColorPicker/Pages/AiGenPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ internal void LoadDetails()
YiqTxt.Text = $"{ColorInfo.YIQ.Y:0.00}..; {ColorInfo.YIQ.I:0.00}..; {ColorInfo.YIQ.Q:0.00}..";
YuvTxt.Text = $"{ColorInfo.YUV.Y:0.00}..; {ColorInfo.YUV.U:0.00}..; {ColorInfo.YUV.V:0.00}..";
DecTxt.Text = ColorInfo.DEC.Value.ToString();

// Load the bookmark icon
BookmarkBtn.Content = Global.Bookmarks.ColorBookmarks.Contains(ColorInfo.HEX.Value) ? "\uF1F8" : "\uF1F6";
BookmarkBtn.Visibility = Visibility.Visible;
}

private void LoadBorders(string[] colors)
Expand Down Expand Up @@ -199,13 +203,14 @@ private void UnCheckAllButtons()

ColorPanel.Visibility = Visibility.Collapsed;
PalettePanel.Visibility = Visibility.Collapsed;
if (ColorInfo is null) BookmarkBtn.Visibility = Visibility.Collapsed;
}
private void ColorBtn_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(Global.Settings.ApiKey)) return;
UnCheckAllButtons();
CheckButton(ColorBtn);
ColorPanel.Visibility = Visibility.Visible;
ColorPanel.Visibility = Visibility.Visible;
}

private void PaletteBtn_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -273,4 +278,30 @@ private void CopyDecBtn_Click(object sender, RoutedEventArgs e)
{
Clipboard.SetText(DecTxt.Text);
}

private void BookmarkBtn_Click(object sender, RoutedEventArgs e)
{
var bg = (SolidColorBrush)ColorBorder.Background;
string hex = $"#{new ColorInfo(new(bg.Color.R, bg.Color.G, bg.Color.B)).HEX.Value}";
if (Global.Bookmarks.ColorBookmarks.Contains(hex))
{
Global.Bookmarks.ColorBookmarks.Remove(hex);
BookmarkBtn.Content = "\uF1F6";
BookmarkToolTip.Content = Properties.Resources.AddBookmark;
return;
}
Global.Bookmarks.ColorBookmarks.Add(hex); // Add to color bookmarks
BookmarkBtn.Content = "\uF1F8";
BookmarkToolTip.Content = Properties.Resources.RemoveBookmark;
}

private void IdeaBtn_Click(object sender, RoutedEventArgs e)
{
PromptTxt.Text = Global.GetRandomAiPrompt();
}

private void IdeaPaletteBtn_Click(object sender, RoutedEventArgs e)
{
PalettePromptTxt.Text = Global.GetRandomAiPrompt();
}
}
6 changes: 3 additions & 3 deletions ColorPicker/Pages/ConverterPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ internal void RgbBtn_Click(object sender, RoutedEventArgs? e)
}

private void CheckButton(Button button) => button.Background = new SolidColorBrush { Color = Global.GetColorFromResource("LightAccentColor") };
ColorInfo ColorInfo { get; set; }
internal ColorInfo ColorInfo { get; set; }

private RGB ConvertToRgb()
{
Expand Down Expand Up @@ -131,9 +131,9 @@ private RGB ConvertToRgb()
double.Parse(Txt3.Text)));
}

internal void LoadDetails()
internal void LoadDetails(bool setColor = false)
{
ColorInfo = new ColorInfo(ConvertToRgb());
if (!setColor) ColorInfo = new ColorInfo(ConvertToRgb());
RgbTxt.Text = $"{ColorInfo.RGB.R}; {ColorInfo.RGB.G}; {ColorInfo.RGB.B}";
HexTxt.Text = $"#{ColorInfo.HEX.Value}";
HsvTxt.Text = $"{ColorInfo.HSV.H}, {ColorInfo.HSV.S}, {ColorInfo.HSV.V}";
Expand Down
8 changes: 4 additions & 4 deletions ColorPicker/Pages/PalettePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private void InitUI()
_ => RgbBtn
}, null);
}
ColorInfo ColorInfo { get; set; }
internal ColorInfo ColorInfo { get; set; }

private RGB ConvertToRgb()
{
Expand Down Expand Up @@ -260,9 +260,9 @@ private void LoadInputUI()
}
}

internal void InitPaletteUI()
internal void InitPaletteUI(bool setColor = false)
{
ColorInfo = new ColorInfo(ConvertToRgb());
if (!setColor) ColorInfo = new ColorInfo(ConvertToRgb());
ColorBorder.Background = new SolidColorBrush { Color = Color.FromRgb(ColorInfo.RGB.R, ColorInfo.RGB.G, ColorInfo.RGB.B) };
ColorBorder.Effect = new DropShadowEffect() { BlurRadius = 15, ShadowDepth = 0, Color = Color.FromRgb(ColorInfo.RGB.R, ColorInfo.RGB.G, ColorInfo.RGB.B) };

Expand Down Expand Up @@ -300,7 +300,7 @@ internal void InitPaletteUI()
Foreground = new SolidColorBrush { Color = Global.GetColorFromResource("Foreground1") },
Content = new ColorInfo(new(shades[i].R, shades[i].G, shades[i].B)).ToString()
},
};
};

int j = i > shades.Length ? shades.Length - 1 : i; // Avoid index out of range
border.MouseLeftButtonUp += (o, e) =>
Expand Down
16 changes: 13 additions & 3 deletions ColorPicker/Pages/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="SettingsPage"
d:Background="White"
d:DesignHeight="450"
d:DesignHeight="1450"
d:DesignWidth="800"
FontFamily="../Fonts/#Hauora"
Foreground="{Binding Source={StaticResource Foreground1}}"
Expand Down Expand Up @@ -690,9 +690,19 @@
Foreground="{Binding Source={StaticResource Foreground1}}"
SelectionChanged="ModelComboBox_SelectionChanged"
Style="{DynamicResource ComboBoxStyle1}">
<ComboBoxItem Content="GPT-3.5-Turbo" />
<ComboBoxItem Content="GPT-4" />
</ComboBox>
<Button
x:Name="RefreshModelsBtn"
Margin="0 0 10 0"
Padding="5"
VerticalAlignment="Center"
Background="{Binding Source={StaticResource AccentColor}}"
Click="RefreshModelsBtn_Click"
Content="&#xF140;"
Cursor="Hand"
FontFamily="..\Fonts\#FluentSystemIcons-Regular"
Foreground="{Binding Source={StaticResource WindowButtonsHoverForeground1}}"
Style="{StaticResource PrimaryButton}" />
</StackPanel>
</StackPanel>
</Expander>
Expand Down
33 changes: 30 additions & 3 deletions ColorPicker/Pages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using ColorPicker.Enums;
using Gma.System.MouseKeyHook;
using Microsoft.Win32;
using OpenAI.Managers;
using PeyrSharp.Core;
using PeyrSharp.Env;
using Synethia;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
Expand Down Expand Up @@ -89,7 +91,11 @@ private async void InitUI()
Global.Settings.ApiKey ??= "";
Global.Settings.Model ??= "gpt-3.5-turbo";
ApiKeyTxt.Password = Global.Settings.ApiKey;
ModelComboBox.SelectedIndex = Global.Settings.Model switch { "gpt-4" => 1, _ => 0 };
for (int i = 0; i < Global.Settings.SupportedModels.Length; i++)
{
ModelComboBox.Items.Add(Global.Settings.SupportedModels[i]);
}
ModelComboBox.SelectedItem = Global.Settings.Model;

// Load the Text Tool section
System.Drawing.Text.InstalledFontCollection installedFonts = new();
Expand Down Expand Up @@ -503,9 +509,30 @@ private void ApiKeyTxt_PasswordChanged(object sender, RoutedEventArgs e)

private void ModelComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string[] supportedModels = { "gpt-3.5-turbo", "gpt-4" };
Global.Settings.Model = supportedModels[ModelComboBox.SelectedIndex];
try
{
Global.Settings.Model = Global.Settings.SupportedModels[ModelComboBox.SelectedIndex];
XmlSerializerManager.SaveToXml(Global.Settings, Global.SettingsPath);
}
catch { }
}

private async void RefreshModelsBtn_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(Global.Settings.ApiKey)) return;

OpenAIService sdk = new(new() { ApiKey = Global.Settings.ApiKey });
var modelList = await sdk.Models.ListModel();

Global.Settings.SupportedModels = modelList.Models.Select(m => m.Id).Where(m => m.StartsWith("gpt")).ToArray();
XmlSerializerManager.SaveToXml(Global.Settings, Global.SettingsPath);

ModelComboBox.Items.Clear();
for (int i = 0; i < Global.Settings.SupportedModels.Length; i++)
{
ModelComboBox.Items.Add(Global.Settings.SupportedModels[i]);
}
ModelComboBox.SelectedItem = Global.Settings.Model;
}

private void ResetSynethiaLink_Click(object sender, RoutedEventArgs e)
Expand Down
Loading

0 comments on commit 64c02fb

Please sign in to comment.