diff --git a/.idea/.idea.ColorPicker/.idea/.gitignore b/.idea/.idea.ColorPicker/.idea/.gitignore new file mode 100644 index 0000000..e88dfe2 --- /dev/null +++ b/.idea/.idea.ColorPicker/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/contentModel.xml +/.idea.ColorPicker.iml +/modules.xml +/projectSettingsUpdater.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.idea.ColorPicker/.idea/encodings.xml b/.idea/.idea.ColorPicker/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/.idea/.idea.ColorPicker/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.ColorPicker/.idea/indexLayout.xml b/.idea/.idea.ColorPicker/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/.idea.ColorPicker/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/App.xaml b/App.xaml new file mode 100644 index 0000000..12e2123 --- /dev/null +++ b/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/App.xaml.cs b/App.xaml.cs new file mode 100644 index 0000000..d19ce48 --- /dev/null +++ b/App.xaml.cs @@ -0,0 +1,6 @@ +using System.Windows; + +namespace ColorPicker; + +public partial class App : Application { +} diff --git a/AssemblyInfo.cs b/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + 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) +)] diff --git a/ColorPicker.csproj b/ColorPicker.csproj new file mode 100644 index 0000000..0ceaa85 --- /dev/null +++ b/ColorPicker.csproj @@ -0,0 +1,20 @@ + + + + WinExe + net7.0-windows + enable + true + + + + + + + + + + + + + diff --git a/ColorPicker.sln b/ColorPicker.sln new file mode 100644 index 0000000..956967b --- /dev/null +++ b/ColorPicker.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33424.131 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ColorPicker", "ColorPicker.csproj", "{527B253E-F795-40CE-9E4F-030717FB109B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {527B253E-F795-40CE-9E4F-030717FB109B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {527B253E-F795-40CE-9E4F-030717FB109B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {527B253E-F795-40CE-9E4F-030717FB109B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {527B253E-F795-40CE-9E4F-030717FB109B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C45379AD-6848-4D51-9A8D-2866C04E946E} + EndGlobalSection +EndGlobal diff --git a/MainWindow.xaml b/MainWindow.xaml new file mode 100644 index 0000000..a220dfe --- /dev/null +++ b/MainWindow.xaml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs new file mode 100644 index 0000000..793c70d --- /dev/null +++ b/MainWindow.xaml.cs @@ -0,0 +1,9 @@ +using System.Windows; + +namespace ColorPicker; + +public partial class MainWindow : Window { + public MainWindow() { + InitializeComponent(); + } +} diff --git a/ViewModels/ColorPicker.cs b/ViewModels/ColorPicker.cs new file mode 100644 index 0000000..141542e --- /dev/null +++ b/ViewModels/ColorPicker.cs @@ -0,0 +1,39 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using System.Text.RegularExpressions; + +namespace ColorPicker.ViewModels; + +public partial class ColorPickerViewModel : ObservableObject { + + [ObservableProperty] + private byte red = 0, green = 0, blue = 0; + + [ObservableProperty] + private string color = "#000000", hexInput = "#000000"; + + public ColorPickerViewModel() { + calculateColorFromRgb(); + } + + partial void OnRedChanged(byte value) => calculateColorFromRgb(); + partial void OnGreenChanged(byte value) => calculateColorFromRgb(); + partial void OnBlueChanged(byte value) => calculateColorFromRgb(); + + partial void OnHexInputChanged(string value) { + if (!Regex.IsMatch(value, @"^#[\dA-F]{6}$", RegexOptions.IgnoreCase)) + return; + this.Color = HexInput; + calculateRgbFromColor(); + } + + private void calculateRgbFromColor() { + var parse = (int start, int length) => byte.Parse(this.Color.Substring(start, length), System.Globalization.NumberStyles.HexNumber); + (this.Red, this.Green, this.Blue) = (parse(1, 2), parse(3, 2), parse(5, 2)); + } + + private void calculateColorFromRgb() { + this.Color = $"#{this.Red:X2}{this.Green:X2}{this.Blue:X2}"; + this.HexInput = this.Color; + } + +} diff --git a/global.json b/global.json new file mode 100644 index 0000000..7cd6a1f --- /dev/null +++ b/global.json @@ -0,0 +1,7 @@ +{ + "sdk": { + "version": "7.0.0", + "rollForward": "latestMajor", + "allowPrerelease": true + } +} \ No newline at end of file