-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2963471
commit 65f3aa1
Showing
13 changed files
with
856 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.29009.5 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PaletteBuddy", "PaletteBuddy\PaletteBuddy.csproj", "{F7401020-58AB-4433-B130-39184AB9BD4D}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{F7401020-58AB-4433-B130-39184AB9BD4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{F7401020-58AB-4433-B130-39184AB9BD4D}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{F7401020-58AB-4433-B130-39184AB9BD4D}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{F7401020-58AB-4433-B130-39184AB9BD4D}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {06074BCF-C746-4529-9DDD-39C6D584B2D7} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Application x:Class="PaletteBuddy.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:PaletteBuddy" | ||
StartupUri="MainWindow.xaml"> | ||
<Application.Resources> | ||
|
||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.IO; | ||
using System.Windows; | ||
using System.Windows.Threading; | ||
|
||
namespace PaletteBuddy | ||
{ | ||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) | ||
{ | ||
// Process unhandled exception | ||
MessageBox.Show(e.Exception.ToString()); | ||
// Prevent default unhandled exception processing | ||
e.Handled = true; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<Window x:Class="PaletteBuddy.MainWindow" | ||
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:local="clr-namespace:PaletteBuddy" | ||
mc:Ignorable="d" | ||
Title="Palette Pal v2" Height="450" Width="800" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" WindowStyle="ToolWindow" FontFamily="Times New Roman" Background="#FF333333" Foreground="White" Closing="Window_Closing"> | ||
<Grid x:Name="grid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> | ||
<Menu HorizontalAlignment="Stretch" Height="20" Margin="0,0,0,0" VerticalAlignment="Top" Background="#FF333333" Foreground="White"> | ||
<MenuItem Header="File"> | ||
<MenuItem Header="Save File" Foreground="Black" Click="Button_SaveToFile"/> | ||
<MenuItem Header="Exit" Foreground="Black" Click="Button_Exit"/> | ||
</MenuItem> | ||
<MenuItem Header="Color"> | ||
<MenuItem Header="Save Color" Foreground="Black" Click="Button_Save"/> | ||
</MenuItem> | ||
<MenuItem Header="View"> | ||
<MenuItem Header="View Colors.xml" Foreground="Black" Click="Button_OpenFile"/> | ||
</MenuItem> | ||
<MenuItem Header="Settings"> | ||
<MenuItem Header="Preferences..." Foreground="Black"/> | ||
<MenuItem Header="Reset Colors" Foreground="Black" Click="Button_ResetColors"/> | ||
</MenuItem> | ||
</Menu> | ||
<TextBox TextChanged="Search_Bar_TextChanged" Name="Search_Bar" HorizontalAlignment="Left" Height="22" Margin="0,25,0,0" VerticalAlignment="Top" Width="600" Background="#FF555555" BorderBrush="Black" Foreground="White" MaxLines="1" VerticalContentAlignment="Center"/> | ||
<ListBox ItemsSource="{Binding}" Name="ItemList" HorizontalAlignment="Left" VerticalAlignment="Bottom" Height="350" Width="600" Background="#FF333333" Foreground="White" Loaded="ItemList_Loaded" SelectionChanged="ItemList_SelectionChanged" SelectionMode="Single"> | ||
<ListBox.ItemTemplate> | ||
<DataTemplate> | ||
<TextBlock Text="{Binding Name}"/> | ||
</DataTemplate> | ||
</ListBox.ItemTemplate> | ||
<ListBox.ContextMenu> | ||
<ContextMenu> | ||
<MenuItem Header="Delete" Click="Button_Remove"/> | ||
</ContextMenu> | ||
</ListBox.ContextMenu> | ||
</ListBox> | ||
<TextBox Name="NameBox" Height="20" VerticalAlignment="Bottom" Width="150" HorizontalAlignment="Right" Margin="0,0,25,170" Background="#FF555555" BorderBrush="Black" Foreground="White" MaxLines="1" VerticalContentAlignment="Center"/> | ||
<Label Content="Name" HorizontalAlignment="Right" Margin="0,0,125,190" VerticalAlignment="Bottom" Foreground="White" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" Width="50"/> | ||
|
||
<TextBox LostFocus="RGBBox_LostFocus" KeyDown="RGBBox_KeyDown" Name="RGBBox" Height="20" VerticalAlignment="Bottom" Width="150" HorizontalAlignment="Right" Margin="0,0,25,70" Background="#FF555555" BorderBrush="Black" Foreground="White" MaxLines="1" VerticalContentAlignment="Center"/> | ||
<Label Content="RGB" HorizontalAlignment="Right" Margin="0,0,125,90" VerticalAlignment="Bottom" Foreground="White" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" Width="50"/> | ||
|
||
<TextBox LostFocus="HexBox_LostFocus" KeyDown="HexBox_KeyDown" Name="HexBox" Height="20" VerticalAlignment="Bottom" Width="150" HorizontalAlignment="Right" Margin="0,0,25,120" Background="#FF555555" BorderBrush="Black" Foreground="White" MaxLines="1" VerticalContentAlignment="Center"/> | ||
<Label Content="Hex" HorizontalAlignment="Right" Margin="0,0,125,140" VerticalAlignment="Bottom" Foreground="White" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" Width="50"/> | ||
|
||
<Border Name="Preview" BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Right" Height="150" Margin="0,25,25,0" VerticalAlignment="Top" Width="150"/> | ||
|
||
<xctk:ColorPicker Name="ColorPicker" HorizontalAlignment="Right" Margin="0,0,25,20" VerticalAlignment="Bottom" Width="150" Background="#FF333333" DropDownBackground="#FF333333" HeaderBackground="#FF333333" TabBackground="#FF333333" TabForeground="White" HeaderForeground="White" SelectedColorChanged="ColorPicker_SelectedColorChanged" ShowStandardColors="False" ShowDropDownButton="False" ShowAvailableColors="False" ShowTabHeaders="False" ColorMode="ColorCanvas"/> | ||
|
||
<Label Name="Status" Content="" Height="22" HorizontalAlignment="Right" Margin="0,180,10,0" VerticalAlignment="Top" Width="175" Foreground="Red" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"/> | ||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,269 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Navigation; | ||
using System.Windows.Shapes; | ||
using System.Runtime.Serialization; | ||
using System.Xml.Serialization; | ||
using System.IO; | ||
using System.Xml; | ||
using System.Diagnostics; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace PaletteBuddy | ||
{ | ||
public class ColorItem | ||
{ | ||
public string Name { get; set; } | ||
public Color Rgb { get; set; } | ||
public string Hex { get; set; } | ||
|
||
public ColorItem(string name, Color rgb, string hex) | ||
{ | ||
Name = name; | ||
Rgb = rgb; | ||
Hex = hex; | ||
} | ||
|
||
public ColorItem() { } | ||
} | ||
|
||
/// <summary> | ||
/// Interaction logic for MainWindow.xaml | ||
/// </summary> | ||
public partial class MainWindow : Window | ||
{ | ||
ObservableCollection<ColorItem> items = new ObservableCollection<ColorItem>(); | ||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
Load_object(); | ||
} | ||
|
||
private void Save_object() | ||
{ | ||
var serl = new XmlSerializer(typeof(ObservableCollection<ColorItem>)); | ||
using (var writer = XmlWriter.Create("Colors.xml")) | ||
{ | ||
serl.Serialize(writer, items); | ||
} | ||
} | ||
|
||
private void Load_object() | ||
{ | ||
if (File.Exists("Colors.xml")) | ||
{ | ||
var serl = new XmlSerializer(typeof(ObservableCollection<ColorItem>)); | ||
using (var reader = new StreamReader("Colors.xml")) | ||
{ | ||
using (var xmlreader = XmlReader.Create(reader)) | ||
{ | ||
items = serl.Deserialize(xmlreader) | ||
as ObservableCollection<ColorItem>; | ||
} | ||
} | ||
} | ||
Refresh(); | ||
} | ||
|
||
private void ItemList_Loaded(object sender, RoutedEventArgs e) | ||
{ | ||
if (items.Count > 0) | ||
{ | ||
var item = items.First(); | ||
ItemList.SelectedItem = item; | ||
NameBox.Text = item.Name; | ||
RGBBox.Text = $"{item.Rgb.A},{item.Rgb.R},{item.Rgb.G},{item.Rgb.B}"; | ||
HexBox.Text = item.Hex; | ||
ColorPicker.SelectedColor = item.Rgb; | ||
} | ||
} | ||
|
||
private void ItemList_SelectionChanged(object sender, SelectionChangedEventArgs e) | ||
{ | ||
//Load Button | ||
if ((sender as ListBox).SelectedItem is ColorItem item) | ||
{ | ||
NameBox.Text = item.Name; | ||
RGBBox.Text = $"{item.Rgb.A},{item.Rgb.R},{item.Rgb.G},{item.Rgb.B}"; | ||
HexBox.Text = item.Hex; | ||
ColorPicker.SelectedColor = item.Rgb; | ||
UpdateStatus("Loaded", item.Name); | ||
} | ||
else | ||
{ | ||
UpdateStatus("Load Failed"); | ||
} | ||
} | ||
|
||
private void UpdateStatus(string status, string obj = "") | ||
{ | ||
Status.Content = $"\"{obj}\" {status}!"; | ||
} | ||
|
||
private void Refresh() | ||
{ | ||
items = new ObservableCollection<ColorItem>(items.OrderBy(x => x.Name)); | ||
ItemList.ItemsSource = items; | ||
} | ||
|
||
private void Button_Save(object sender, RoutedEventArgs e) | ||
{ | ||
//Save Button | ||
if (NameBox.Text.Length == 0) | ||
{ | ||
UpdateStatus("Name cannot be empty"); | ||
return; | ||
} | ||
if (!items.Where(x => x.Name == NameBox.Text).Any()) | ||
{ | ||
var item = new ColorItem(NameBox.Text, ColorPicker.SelectedColor.Value, HexBox.Text); | ||
items.Add(item); | ||
UpdateStatus("Saved", NameBox.Text); | ||
} | ||
else | ||
{ | ||
var result = MessageBox.Show("Do you wish to overrite?", "Warning!", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No); | ||
if (result.Equals("No")) return; | ||
var item = items.Where(x => x.Name == NameBox.Text).First(); | ||
items.Remove(item); | ||
item.Rgb = ColorPicker.SelectedColor.Value; | ||
item.Hex = HexBox.Text; | ||
items.Add(item); | ||
UpdateStatus("Updated", NameBox.Text); | ||
} | ||
Refresh(); | ||
} | ||
|
||
private void ColorPicker_SelectedColorChanged(object sender, RoutedPropertyChangedEventArgs<Color?> e) | ||
{ | ||
var val = e.NewValue.Value; | ||
Preview.Background = (SolidColorBrush)new BrushConverter().ConvertFromString(val.ToString()); | ||
HexBox.Text = val.ToString(); | ||
RGBBox.Text = $"{val.A},{val.R},{val.G},{val.B}"; | ||
} | ||
|
||
private void Button_Remove(object sender, RoutedEventArgs e) | ||
{ | ||
//Remove | ||
var result = MessageBox.Show("This cannot be undone, are you sure?", "Warning!", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No); | ||
if (result.Equals("No")) return; | ||
if (ItemList.SelectedItem is ColorItem item) | ||
{ | ||
items.Remove(item); | ||
UpdateStatus("Removed!", NameBox.Text); | ||
Refresh(); | ||
} | ||
} | ||
|
||
private void Window_Closing(object sender, CancelEventArgs e) | ||
{ | ||
Save_object(); | ||
} | ||
|
||
private void Button_ResetColors(object sender, RoutedEventArgs e) | ||
{ | ||
var result = MessageBox.Show("This cannot be undone, are you sure?", "Warning!", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No); | ||
if (result.Equals("Yes")) items.Clear(); | ||
Refresh(); | ||
} | ||
|
||
private void Button_OpenFile(object sender, RoutedEventArgs e) | ||
{ | ||
if (File.Exists("Colors.xml")) | ||
{ | ||
var proc = Process.Start("Colors.xml"); | ||
proc.Exited += (object s, EventArgs ev) => { Load_object(); }; | ||
} | ||
} | ||
|
||
private void Button_Exit(object sender, RoutedEventArgs e) | ||
{ | ||
Application.Current.Shutdown(); | ||
} | ||
|
||
private void Button_SaveToFile(object sender, RoutedEventArgs e) | ||
{ | ||
Save_object(); | ||
UpdateStatus("Saved!", NameBox.Text); | ||
} | ||
|
||
private void RGBBox_KeyDown(object sender, KeyEventArgs e) | ||
{ | ||
if (e.Key.Equals(Key.Enter)) | ||
{ | ||
var txt = RGBBox.Text; | ||
var mt = Regex.Match(txt, "(\\d+),(\\d+),(\\d+),(\\d+)"); | ||
if (mt.Success) | ||
{ | ||
var c = new Color(); | ||
var g = mt.Groups; | ||
var A = byte.Parse(g[1].Value); | ||
var R = byte.Parse(g[2].Value); | ||
var G = byte.Parse(g[3].Value); | ||
var B = byte.Parse(g[4].Value); | ||
c.A = A; | ||
c.R = R; | ||
c.G = G; | ||
c.B = B; | ||
ColorPicker.SelectedColor = c; | ||
} | ||
} | ||
} | ||
|
||
private void HexBox_KeyDown(object sender, KeyEventArgs e) | ||
{ | ||
if (e.Key.Equals(Key.Enter)) | ||
{ | ||
var txt = HexBox.Text; | ||
if (txt.Length != 9) return; | ||
var mt = Regex.Match(txt, "#.{8,8}"); | ||
if (mt.Success) | ||
{ | ||
try | ||
{ | ||
var c = (Color)ColorConverter.ConvertFromString(txt); | ||
ColorPicker.SelectedColor = c; | ||
} catch (Exception) | ||
{ | ||
// null | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void RGBBox_LostFocus(object sender, RoutedEventArgs e) | ||
{ | ||
var col = ColorPicker.SelectedColor.Value; | ||
RGBBox.Text = $"{col.A},{col.R},{col.G},{col.B}"; | ||
} | ||
|
||
private void HexBox_LostFocus(object sender, RoutedEventArgs e) | ||
{ | ||
HexBox.Text = ColorPicker.SelectedColor.ToString(); | ||
} | ||
|
||
private void Search_Bar_TextChanged(object sender, TextChangedEventArgs e) | ||
{ | ||
var txt = (sender as TextBox).Text; | ||
if (txt.Length > 0) | ||
{ | ||
ItemList.ItemsSource = items.Where(x => x.Name.Contains(txt)); | ||
} else | ||
{ | ||
Refresh(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.