Browse Source

Implemented custom action display

CPKreuz 4 years ago
parent
commit
de41d9a44a

+ 22 - 0
PixiEditor/NotifyableObject.cs

@@ -11,6 +11,28 @@ namespace PixiEditor.Helpers
         [field: NonSerialized]
         public event PropertyChangedEventHandler PropertyChanged = (sender, e) => { };
 
+        public void AddPropertyChangedCallback(string propertyName, Action action)
+        {
+            if (action == null)
+            {
+                throw new ArgumentNullException(nameof(propertyName));
+            }
+
+            if (string.IsNullOrWhiteSpace(propertyName))
+            {
+                PropertyChanged += (_, _) => action();
+                return;
+            }
+
+            PropertyChanged += (sender, e) =>
+            {
+                if (e.PropertyName == propertyName)
+                {
+                    action();
+                }
+            };
+        }
+
         protected void RaisePropertyChanged(string property)
         {
             if (property != null)

+ 2 - 9
PixiEditor/ViewModels/ViewModelBase.cs

@@ -1,19 +1,12 @@
-using System.ComponentModel;
+using PixiEditor.Helpers;
 using System.Linq;
 using System.Windows;
 using System.Windows.Input;
 
 namespace PixiEditor.ViewModels
 {
-    public class ViewModelBase : INotifyPropertyChanged
+    public class ViewModelBase : NotifyableObject
     {
-        public event PropertyChangedEventHandler PropertyChanged = delegate { };
-
-        protected void RaisePropertyChanged(string property)
-        {
-            if (property != null) PropertyChanged(this, new PropertyChangedEventArgs(property));
-        }
-
         protected void CloseButton(object parameter)
         {
             ((Window)parameter).Close();

+ 35 - 0
PixiEditor/ViewModels/ViewModelMain.cs

@@ -24,6 +24,9 @@ namespace PixiEditor.ViewModels
 {
     public class ViewModelMain : ViewModelBase
     {
+        private string actionDisplay;
+        private bool overrideActionDisplay;
+
         public static ViewModelMain Current { get; set; }
 
         public Action CloseAction { get; set; }
@@ -74,6 +77,36 @@ namespace PixiEditor.ViewModels
 
         public IPreferences Preferences { get; set; }
 
+        public string ActionDisplay
+        {
+            get
+            {
+                if (OverrideActionDisplay)
+                {
+                    return actionDisplay;
+                }
+
+                return BitmapManager.SelectedTool.ActionDisplay;
+            }
+            set
+            {
+                actionDisplay = value;
+            }
+        }
+
+        /// <summary>
+        /// Gets or sets a value indicating whether a custom action display should be used. If false the action display of the selected tool will be used.
+        /// </summary>
+        public bool OverrideActionDisplay
+        {
+            get => overrideActionDisplay;
+            set
+            {
+                SetProperty(ref overrideActionDisplay, value);
+                RaisePropertyChanged(nameof(ActionDisplay));
+            }
+        }
+
         public bool IsDebug
         {
             get =>
@@ -181,6 +214,8 @@ namespace PixiEditor.ViewModels
                         new Shortcut(Key.F1, MiscSubViewModel.OpenShortcutWindowCommand, "Open the shortcut window", true)));
 
             BitmapManager.PrimaryColor = ColorsSubViewModel.PrimaryColor;
+
+            BitmapManager.AddPropertyChangedCallback(nameof(BitmapManager.SelectedTool), () => { if (!OverrideActionDisplay) RaisePropertyChanged(nameof(ActionDisplay)); });
         }
 
         /// <summary>

+ 1 - 1
PixiEditor/Views/MainWindow.xaml

@@ -476,7 +476,7 @@
                 <ColumnDefinition Width="290"/>
             </Grid.ColumnDefinitions>
             <DockPanel>
-                <TextBlock Text="{Binding BitmapManager.SelectedTool.ActionDisplay}" Foreground="White" FontSize="15" Margin="10,0,0,0" VerticalAlignment="Center"/>
+                <TextBlock Text="{Binding ActionDisplay}" Foreground="White" FontSize="15" Margin="10,0,0,0" VerticalAlignment="Center"/>
                 <StackPanel DockPanel.Dock="Right" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center">
                     <TextBlock Text="X:" Foreground="White" FontSize="16"/>
                     <TextBlock Margin="4,0,10,0" Text="{Binding BitmapManager.ActiveDocument.MouseXOnCanvas, Converter={StaticResource DoubleToIntConverter}}" Foreground="White" FontSize="16"/>

+ 1 - 1
PixiEditor/Views/UserControls/PreviewWindow.xaml

@@ -7,7 +7,7 @@
              xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
              mc:Ignorable="d" 
              d:DesignHeight="400" d:DesignWidth="400" x:Name="uc"
-             Foreground="White">
+             Foreground="White" Background="Transparent">
 
     <UserControl.Resources>
         <BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>

+ 20 - 0
PixiEditor/Views/UserControls/PreviewWindow.xaml.cs

@@ -1,5 +1,6 @@
 using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.ImageManipulation;
+using PixiEditor.ViewModels;
 using System.Linq;
 using System.Windows;
 using System.Windows.Controls;
@@ -55,6 +56,25 @@ namespace PixiEditor.Views.UserControls
 
             MouseMove += PreviewWindow_MouseMove;
             MouseRightButtonDown += PreviewWindow_MouseRightButtonDown;
+            MouseEnter += PreviewWindow_MouseEnter;
+            MouseLeave += PreviewWindow_MouseLeave;
+        }
+
+        private void PreviewWindow_MouseLeave(object sender, MouseEventArgs e)
+        {
+            if (ViewModelMain.Current != null)
+            {
+                ViewModelMain.Current.OverrideActionDisplay = false;
+            }
+        }
+
+        private void PreviewWindow_MouseEnter(object sender, MouseEventArgs e)
+        {
+            if (ViewModelMain.Current != null)
+            {
+                ViewModelMain.Current.ActionDisplay = "Press right click to copy the color at the color cursor to the main color. Hold shift to copy the color the clipboard.";
+                ViewModelMain.Current.OverrideActionDisplay = true;
+            }
         }
 
         private void PreviewWindow_MouseRightButtonDown(object sender, MouseButtonEventArgs e)