Browse Source

Change ColorPickerTool to be more intuitive

Equbuxu 3 years ago
parent
commit
965b15c219

+ 3 - 3
PixiEditor/Models/Controllers/BitmapManager.cs

@@ -77,7 +77,7 @@ namespace PixiEditor.Models.Controllers
             ToolSessionController.SessionEnded += OnSessionEnd;
             ToolSessionController.SessionEnded += OnSessionEnd;
             ToolSessionController.PixelMousePositionChanged += OnPixelMousePositionChange;
             ToolSessionController.PixelMousePositionChanged += OnPixelMousePositionChange;
             ToolSessionController.PreciseMousePositionChanged += OnPreciseMousePositionChange;
             ToolSessionController.PreciseMousePositionChanged += OnPreciseMousePositionChange;
-            ToolSessionController.KeyStateChanged += (_, _) => UpdateActionDisplay();
+            ToolSessionController.KeyStateChanged += (_, _) => UpdateActionDisplay(_tools.ActiveTool);
             BitmapOperations = new BitmapOperationsUtility(this, tools);
             BitmapOperations = new BitmapOperationsUtility(this, tools);
 
 
             DocumentChanged += BitmapManager_DocumentChanged;
             DocumentChanged += BitmapManager_DocumentChanged;
@@ -103,9 +103,9 @@ namespace PixiEditor.Models.Controllers
             document.Dispose();
             document.Dispose();
         }
         }
 
 
-        public void UpdateActionDisplay()
+        public void UpdateActionDisplay(Tool tool)
         {
         {
-            _tools.ActiveTool?.UpdateActionDisplay(ToolSessionController.IsCtrlDown, ToolSessionController.IsShiftDown, ToolSessionController.IsAltDown);
+            tool?.UpdateActionDisplay(ToolSessionController.IsCtrlDown, ToolSessionController.IsShiftDown, ToolSessionController.IsAltDown);
         }
         }
 
 
         private void OnSessionStart(object sender, ToolSession e)
         private void OnSessionStart(object sender, ToolSession e)

+ 23 - 17
PixiEditor/Models/Tools/Tools/ColorPickerTool.cs

@@ -15,7 +15,7 @@ namespace PixiEditor.Models.Tools.Tools
     {
     {
         private readonly DocumentProvider _docProvider;
         private readonly DocumentProvider _docProvider;
         private readonly BitmapManager _bitmapManager;
         private readonly BitmapManager _bitmapManager;
-        private readonly string defaultActionDisplay = "Click to pick colors from the canvas. Hold Ctrl to pick from the reference layer. Hold Ctrl and Alt to blend the reference and canvas color";
+        private readonly string defaultActionDisplay = "Click to pick colors. Hold Ctrl to hide the canvas. Hold Shift to hide the reference layer";
 
 
         public ColorPickerTool(DocumentProvider documentProvider, BitmapManager bitmapManager)
         public ColorPickerTool(DocumentProvider documentProvider, BitmapManager bitmapManager)
         {
         {
@@ -44,16 +44,16 @@ namespace PixiEditor.Models.Tools.Tools
         {
         {
             Layer referenceLayer = _docProvider.GetReferenceLayer();
             Layer referenceLayer = _docProvider.GetReferenceLayer();
 
 
-            if (referenceLayer != null && Session.IsCtrlDown)
+            if (referenceLayer != null && referenceLayer.IsVisible)
             {
             {
                 double preciseX = _docProvider.GetDocument().MouseXOnCanvas;
                 double preciseX = _docProvider.GetDocument().MouseXOnCanvas;
                 double preciseY = _docProvider.GetDocument().MouseYOnCanvas;
                 double preciseY = _docProvider.GetDocument().MouseYOnCanvas;
 
 
-                if (Session.IsAltDown)
-                {
-                    return GetCombinedColor(x, y, preciseX, preciseY);
-                }
-                return GetReferenceColor(preciseX, preciseY);
+                if (Session.IsCtrlDown)
+                    return GetReferenceColor(preciseX, preciseY);
+                if (Session.IsShiftDown)
+                    return GetCanvasColor(x, y);
+                return GetCombinedColor(x, y, preciseX, preciseY);
             }
             }
 
 
             return GetCanvasColor(x, y);
             return GetCanvasColor(x, y);
@@ -113,24 +113,30 @@ namespace PixiEditor.Models.Tools.Tools
 
 
         public override void UpdateActionDisplay(bool ctrlIsDown, bool shiftIsDown, bool altIsDown)
         public override void UpdateActionDisplay(bool ctrlIsDown, bool shiftIsDown, bool altIsDown)
         {
         {
-            if (ctrlIsDown)
+            if (!IsActive)
             {
             {
-                if (altIsDown)
-                {
-                    _bitmapManager.HideReferenceLayer = false;
-                    _bitmapManager.OnlyReferenceLayer = false;
-                    ActionDisplay = "Click to pick colors from both the canvas and the reference layer blended together. Release Ctrl and Alt to pick from the canvas. Release just Alt to pick from the reference layer";
-                    return;
-                }
+                _bitmapManager.HideReferenceLayer = false;
+                _bitmapManager.OnlyReferenceLayer = false;
+                return;
+            }
 
 
+            if (ctrlIsDown)
+            {
                 _bitmapManager.HideReferenceLayer = false;
                 _bitmapManager.HideReferenceLayer = false;
                 _bitmapManager.OnlyReferenceLayer = true;
                 _bitmapManager.OnlyReferenceLayer = true;
-                ActionDisplay = "Click to pick colors from the reference layer. Release Ctrl to pick from the canvas. Hold Ctrl and Alt to blend the reference and canvas color";
+                ActionDisplay = "Click to pick colors from the reference layer.";
             }
             }
-            else
+            else if (shiftIsDown)
             {
             {
                 _bitmapManager.HideReferenceLayer = true;
                 _bitmapManager.HideReferenceLayer = true;
                 _bitmapManager.OnlyReferenceLayer = false;
                 _bitmapManager.OnlyReferenceLayer = false;
+                ActionDisplay = "Click to pick colors from the canvas.";
+                return;
+            }
+            else
+            {
+                _bitmapManager.HideReferenceLayer = false;
+                _bitmapManager.OnlyReferenceLayer = false;
                 ActionDisplay = defaultActionDisplay;
                 ActionDisplay = defaultActionDisplay;
             }
             }
         }
         }

+ 14 - 4
PixiEditor/ViewModels/SubViewModels/Main/IoViewModel.cs

@@ -44,10 +44,16 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
         private void OnKeyDown(object parameter)
         private void OnKeyDown(object parameter)
         {
         {
             KeyEventArgs args = (KeyEventArgs)parameter;
             KeyEventArgs args = (KeyEventArgs)parameter;
-            ProcessShortcutDown(args.IsRepeat, args.Key);
+            var key = args.Key;
+            if (key == Key.System)
+                key = args.SystemKey;
+
+            ProcessShortcutDown(args.IsRepeat, key);
 
 
             if (Owner.BitmapManager.ActiveDocument != null)
             if (Owner.BitmapManager.ActiveDocument != null)
-                Owner.BitmapManager.InputTarget.OnKeyDown(args.Key);
+            {
+                Owner.BitmapManager.InputTarget.OnKeyDown(key);
+            }
         }
         }
 
 
         private void ProcessShortcutDown(bool isRepeat, Key key)
         private void ProcessShortcutDown(bool isRepeat, Key key)
@@ -65,10 +71,14 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
         private void OnKeyUp(object parameter)
         private void OnKeyUp(object parameter)
         {
         {
             KeyEventArgs args = (KeyEventArgs)parameter;
             KeyEventArgs args = (KeyEventArgs)parameter;
-            ProcessShortcutUp(args.Key);
+            var key = args.Key;
+            if (key == Key.System)
+                key = args.SystemKey;
+
+            ProcessShortcutUp(key);
 
 
             if (Owner.BitmapManager.ActiveDocument != null)
             if (Owner.BitmapManager.ActiveDocument != null)
-                Owner.BitmapManager.InputTarget.OnKeyUp(args.Key);
+                Owner.BitmapManager.InputTarget.OnKeyUp(key);
         }
         }
 
 
         private void ProcessShortcutUp(Key key)
         private void ProcessShortcutUp(Key key)

+ 5 - 1
PixiEditor/ViewModels/SubViewModels/Main/ToolsViewModel.cs

@@ -88,13 +88,17 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             }
             }
 
 
             LastActionTool = ActiveTool;
             LastActionTool = ActiveTool;
+
+
             ActiveTool = tool;
             ActiveTool = tool;
 
 
             if (LastActionTool != ActiveTool)
             if (LastActionTool != ActiveTool)
                 SelectedToolChanged?.Invoke(this, new SelectedToolEventArgs(LastActionTool, ActiveTool));
                 SelectedToolChanged?.Invoke(this, new SelectedToolEventArgs(LastActionTool, ActiveTool));
 
 
+            //update old tool
+            Owner.BitmapManager.UpdateActionDisplay(LastActionTool);
             //update new tool
             //update new tool
-            Owner.BitmapManager.UpdateActionDisplay();
+            Owner.BitmapManager.UpdateActionDisplay(ActiveTool);
 
 
             tool.IsActive = true;
             tool.IsActive = true;
             SetToolCursor(tool.GetType());
             SetToolCursor(tool.GetType());