Skip to content

Commit

Permalink
Change ColorPickerTool to be more intuitive
Browse files Browse the repository at this point in the history
  • Loading branch information
Equbuxu committed Dec 11, 2021
1 parent 4ffca37 commit 965b15c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 25 deletions.
6 changes: 3 additions & 3 deletions PixiEditor/Models/Controllers/BitmapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public BitmapManager(ToolsViewModel tools)
ToolSessionController.SessionEnded += OnSessionEnd;
ToolSessionController.PixelMousePositionChanged += OnPixelMousePositionChange;
ToolSessionController.PreciseMousePositionChanged += OnPreciseMousePositionChange;
ToolSessionController.KeyStateChanged += (_, _) => UpdateActionDisplay();
ToolSessionController.KeyStateChanged += (_, _) => UpdateActionDisplay(_tools.ActiveTool);
BitmapOperations = new BitmapOperationsUtility(this, tools);

DocumentChanged += BitmapManager_DocumentChanged;
Expand All @@ -103,9 +103,9 @@ public void CloseDocument(Document document)
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)
Expand Down
40 changes: 23 additions & 17 deletions PixiEditor/Models/Tools/Tools/ColorPickerTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class ColorPickerTool : ReadonlyTool
{
private readonly DocumentProvider _docProvider;
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)
{
Expand Down Expand Up @@ -44,16 +44,16 @@ public SKColor GetColorAt(int x, int y)
{
Layer referenceLayer = _docProvider.GetReferenceLayer();

if (referenceLayer != null && Session.IsCtrlDown)
if (referenceLayer != null && referenceLayer.IsVisible)
{
double preciseX = _docProvider.GetDocument().MouseXOnCanvas;
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);
Expand Down Expand Up @@ -113,24 +113,30 @@ private Coordinates CanvasSpaceToReferenceSpace(double canvasX, double canvasY,

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.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.OnlyReferenceLayer = false;
ActionDisplay = "Click to pick colors from the canvas.";
return;
}
else
{
_bitmapManager.HideReferenceLayer = false;
_bitmapManager.OnlyReferenceLayer = false;
ActionDisplay = defaultActionDisplay;
}
}
Expand Down
18 changes: 14 additions & 4 deletions PixiEditor/ViewModels/SubViewModels/Main/IoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ public IoViewModel(ViewModelMain owner)
private void OnKeyDown(object 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)
Owner.BitmapManager.InputTarget.OnKeyDown(args.Key);
{
Owner.BitmapManager.InputTarget.OnKeyDown(key);
}
}

private void ProcessShortcutDown(bool isRepeat, Key key)
Expand All @@ -65,10 +71,14 @@ private void ProcessShortcutDown(bool isRepeat, Key key)
private void OnKeyUp(object 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)
Owner.BitmapManager.InputTarget.OnKeyUp(args.Key);
Owner.BitmapManager.InputTarget.OnKeyUp(key);
}

private void ProcessShortcutUp(Key key)
Expand Down
6 changes: 5 additions & 1 deletion PixiEditor/ViewModels/SubViewModels/Main/ToolsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,17 @@ public void SetActiveTool(Tool tool)
}

LastActionTool = ActiveTool;


ActiveTool = tool;

if (LastActionTool != ActiveTool)
SelectedToolChanged?.Invoke(this, new SelectedToolEventArgs(LastActionTool, ActiveTool));

//update old tool
Owner.BitmapManager.UpdateActionDisplay(LastActionTool);
//update new tool
Owner.BitmapManager.UpdateActionDisplay();
Owner.BitmapManager.UpdateActionDisplay(ActiveTool);

tool.IsActive = true;
SetToolCursor(tool.GetType());
Expand Down

0 comments on commit 965b15c

Please sign in to comment.