diff --git a/src/Artemis.UI/Artemis.UI.csproj b/src/Artemis.UI/Artemis.UI.csproj index dc57c291e..67e4c9841 100644 --- a/src/Artemis.UI/Artemis.UI.csproj +++ b/src/Artemis.UI/Artemis.UI.csproj @@ -171,8 +171,8 @@ Designer - - ColorPickerView.xaml + + ColorPicker.xaml @@ -250,7 +250,7 @@ Code - + Designer MSBuild:Compile diff --git a/src/Artemis.UI/Controls/ColorPicker.xaml b/src/Artemis.UI/Controls/ColorPicker.xaml new file mode 100644 index 000000000..13fe03f15 --- /dev/null +++ b/src/Artemis.UI/Controls/ColorPicker.xaml @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Artemis.UI/Controls/ColorPicker.xaml.cs b/src/Artemis.UI/Controls/ColorPicker.xaml.cs new file mode 100644 index 000000000..eea2f5cb1 --- /dev/null +++ b/src/Artemis.UI/Controls/ColorPicker.xaml.cs @@ -0,0 +1,117 @@ +using System; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Media; + +namespace Artemis.UI.Controls +{ + /// + /// Interaction logic for ColorPicker.xaml + /// + public partial class ColorPicker : UserControl, INotifyPropertyChanged + { + public static readonly DependencyProperty ColorProperty = DependencyProperty.Register( + "Color", + typeof(Color), + typeof(ColorPicker), + new FrameworkPropertyMetadata(default(Color), OnColorPropertyChanged) + ); + + private byte _colorOpacity; + + private static void OnColorPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) + { + if (sender is ColorPicker colorPicker) + { + colorPicker.OnPropertyChanged(nameof(Color)); + colorPicker.OnPropertyChanged(nameof(ColorCode)); + colorPicker.OnPropertyChanged(nameof(SolidColor)); + colorPicker.OnPropertyChanged(nameof(ColorOpacity)); + } + } + + public ColorPicker() + { + InitializeComponent(); + PropertyChanged += OnPropertyChanged; + } + + private void OnPropertyChanged(object sender, PropertyChangedEventArgs e) + { + if (e.PropertyName == nameof(Color)) + { + if (Color.A != _colorOpacity) + Color = Color.FromArgb(_colorOpacity, Color.R, Color.G, Color.B); + } + } + + public Color Color + { + get => (Color) GetValue(ColorProperty); + set => SetValue(ColorProperty, value); + } + + public string ColorCode + { + get => Color.ToString(); + set + { + try + { + if (string.IsNullOrWhiteSpace(value)) + Color = new Color(); + else + { + var color = ColorConverter.ConvertFromString(value); + if (color is Color c) + { + _colorOpacity = c.A; + Color = c; + } + } + } + catch (FormatException) + { + // ignored + } + } + } + + public Color? SolidColor => Color.FromRgb(Color.R, Color.G, Color.B); + + public byte ColorOpacity + { + get => _colorOpacity; + set + { + _colorOpacity = value; + if (Color.A != _colorOpacity) + { + Color = Color.FromArgb(_colorOpacity, Color.R, Color.G, Color.B); + OnPropertyChanged(nameof(Color)); + } + } + } + + public bool PopupOpen { get; set; } + + private void UIElement_OnMouseUp(object sender, MouseButtonEventArgs e) + { + PopupOpen = !PopupOpen; + } + + #region Events + + public event PropertyChangedEventHandler PropertyChanged; + + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + #endregion + } +} \ No newline at end of file diff --git a/src/Artemis.UI/Controls/ColorPicker/ColorPickerView.xaml b/src/Artemis.UI/Controls/ColorPicker/ColorPickerView.xaml deleted file mode 100644 index 88b805a2e..000000000 --- a/src/Artemis.UI/Controls/ColorPicker/ColorPickerView.xaml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/Artemis.UI/Controls/ColorPicker/ColorPickerView.xaml.cs b/src/Artemis.UI/Controls/ColorPicker/ColorPickerView.xaml.cs deleted file mode 100644 index 2bb475ecf..000000000 --- a/src/Artemis.UI/Controls/ColorPicker/ColorPickerView.xaml.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -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; - -namespace Artemis.UI.Controls.ColorPicker -{ - /// - /// Interaction logic for ColorPickerView.xaml - /// - public partial class ColorPickerView : UserControl - { - public ColorPickerView() - { - InitializeComponent(); - } - } -} diff --git a/src/Artemis.UI/Screens/Workshop/WorkshopView.xaml b/src/Artemis.UI/Screens/Workshop/WorkshopView.xaml index 076ee0c1a..c7d9f6c9b 100644 --- a/src/Artemis.UI/Screens/Workshop/WorkshopView.xaml +++ b/src/Artemis.UI/Screens/Workshop/WorkshopView.xaml @@ -4,10 +4,12 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Artemis.UI.Screens.Workshop" - xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:s="https://github.com/canton7/Stylet" + xmlns:controls="clr-namespace:Artemis.UI.Controls" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> - Work work! + + \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Workshop/WorkshopViewModel.cs b/src/Artemis.UI/Screens/Workshop/WorkshopViewModel.cs index b32848801..3b3b267a1 100644 --- a/src/Artemis.UI/Screens/Workshop/WorkshopViewModel.cs +++ b/src/Artemis.UI/Screens/Workshop/WorkshopViewModel.cs @@ -1,9 +1,38 @@ -using Stylet; +using System; +using System.ComponentModel; +using System.Windows.Media; +using Stylet; namespace Artemis.UI.Screens.Workshop { public class WorkshopViewModel : Screen, IScreenViewModel { public string Title => "Workshop"; + + public WorkshopViewModel() + { + PropertyChanged += OnPropertyChanged; + } + + private void OnPropertyChanged(object sender, PropertyChangedEventArgs e) + { + Console.WriteLine("Property changed:" + e.PropertyName); + Console.WriteLine(TestColor); + } + + public Color TestColor { get; set; } + + + protected override void OnActivate() + { + TestColor = Color.FromRgb(255, 0, 0); + base.OnActivate(); + } + + protected override void OnDeactivate() + { + Console.WriteLine(TestColor); + base.OnDeactivate(); + } } } \ No newline at end of file