Skip to content

Commit

Permalink
Accept right ctrl and right shift in tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Equbuxu committed Dec 6, 2021
1 parent 93601a3 commit 8db203e
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 35 deletions.
2 changes: 1 addition & 1 deletion PixiEditor/Models/Controllers/BitmapOperationsUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private void UseTool(List<Coordinates> mouseMoveCords, BitmapOperationTool tool,

int thickness = sizeSetting != null ? sizeSetting.Value : 1;

bool shiftDown = Keyboard.IsKeyDown(Key.LeftShift);
bool shiftDown = Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift);

if (shiftDown && tool.UsesShift)
{
Expand Down
15 changes: 8 additions & 7 deletions PixiEditor/Models/Tools/Tools/BrightnessTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ public class BrightnessTool : BitmapOperationTool
private List<DoubleCoords> circleCache = new List<DoubleCoords>();
private int cachedCircleSize = -1;

private string defaultActionDisplay = "Draw on pixels to make them brighter. Hold Ctrl to darken.";
public BrightnessTool()
{
ActionDisplay = "Draw on pixel to make it brighter. Hold Ctrl to darken.";
ActionDisplay = defaultActionDisplay;
Toolbar = new BrightnessToolToolbar(CorrectionFactor);
}

public override bool UsesShift => false;

public override string Tooltip => "Makes pixel brighter or darker pixel (U). Hold Ctrl to make pixel darker.";
public override string Tooltip => "Makes pixels brighter or darker (U). Hold Ctrl to make pixels darker.";

public BrightnessMode Mode { get; set; } = BrightnessMode.Default;

Expand All @@ -45,17 +46,17 @@ public override void OnRecordingLeftMouseDown(MouseEventArgs e)

public override void OnKeyDown(KeyEventArgs e)
{
if (e.Key == Key.LeftCtrl)
if (e.Key is Key.LeftCtrl or Key.RightCtrl)
{
ActionDisplay = "Draw on pixel to make it darker. Release Ctrl to brighten.";
ActionDisplay = "Draw on pixels to make them darker. Release Ctrl to brighten.";
}
}

public override void OnKeyUp(KeyEventArgs e)
{
if (e.Key == Key.LeftCtrl)
if (e.Key is Key.LeftCtrl or Key.RightCtrl)
{
ActionDisplay = "Draw on pixel to make it brighter. Hold Ctrl to darken.";
ActionDisplay = defaultActionDisplay;
}
}

Expand All @@ -65,7 +66,7 @@ public override void Use(Layer layer, List<Coordinates> coordinates, SKColor col
float correctionFactor = Toolbar.GetSetting<FloatSetting>("CorrectionFactor").Value;
Mode = Toolbar.GetEnumSetting<BrightnessMode>("BrightnessMode").Value;

if (Keyboard.IsKeyDown(Key.LeftCtrl))
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
{
ChangeBrightness(layer, coordinates[0], toolSize, -correctionFactor);
}
Expand Down
10 changes: 6 additions & 4 deletions PixiEditor/Models/Tools/Tools/CircleTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,28 @@ public static void DrawEllipseOutline(Layer layer, SKColor color, List<Coordinat
}
}

private string defaultActionDisplay = "Click and move mouse to draw a circle. Hold Shift to draw an even one.";

public CircleTool()
{
ActionDisplay = "Click and move mouse to draw a circle. Hold Shift to draw an even one.";
ActionDisplay = defaultActionDisplay;
}

public override string Tooltip => "Draws circle on canvas (C). Hold Shift to draw even circle.";

public override void OnKeyDown(KeyEventArgs e)
{
if (e.Key == Key.LeftShift)
if (e.Key is Key.LeftShift or Key.RightShift)
{
ActionDisplay = "Click and move mouse to draw an even circle.";
}
}

public override void OnKeyUp(KeyEventArgs e)
{
if (e.Key == Key.LeftShift)
if (e.Key is Key.LeftShift or Key.RightShift)
{
ActionDisplay = "Click and move mouse to draw a circle. Hold Shift to draw an even one.";
ActionDisplay = defaultActionDisplay;
}
}

Expand Down
10 changes: 6 additions & 4 deletions PixiEditor/Models/Tools/Tools/LineTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ public static void CalculateBresenhamLine(Coordinates start, Coordinates end, Li
}
}

private string defaltActionDisplay = "Click and move to draw a line. Hold Shift to draw an even one.";

public LineTool()
{
ActionDisplay = "Click and move to draw a line. Hold Shift to draw an even one.";
ActionDisplay = defaltActionDisplay;
Toolbar = new BasicToolbar();
circleTool = new CircleTool();
}
Expand All @@ -124,17 +126,17 @@ public LineTool()

public override void OnKeyDown(KeyEventArgs e)
{
if (e.Key == Key.LeftShift)
if (e.Key is Key.LeftShift or Key.RightShift)
{
ActionDisplay = "Click and move mouse to draw an even line.";
}
}

public override void OnKeyUp(KeyEventArgs e)
{
if (e.Key == Key.LeftShift)
if (e.Key is Key.LeftShift or Key.RightShift)
{
ActionDisplay = "Click and move to draw a line. Hold Shift to draw an even one.";
ActionDisplay = defaltActionDisplay;
}
}

Expand Down
16 changes: 8 additions & 8 deletions PixiEditor/Models/Tools/Tools/MoveTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ public class MoveTool : BitmapOperationTool

private StorageBasedChange change;

private string defaultActionDisplay = "Hold mouse to move selected pixels. Hold Ctrl to move all layers.";

public MoveTool(BitmapManager bitmapManager)
{
ActionDisplay = "Hold mouse to move selected pixels. Hold Ctrl to move all layers.";
ActionDisplay = defaultActionDisplay;
Cursor = Cursors.Arrow;
RequiresPreviewLayer = true;
UseDefaultUndoMethod = false;
Expand All @@ -59,23 +61,21 @@ public MoveTool(BitmapManager bitmapManager)

public override bool HideHighlight => true;

public bool MoveAll { get; set; }

private BitmapManager BitmapManager { get; }

public override void OnKeyDown(KeyEventArgs e)
{
if (e.Key == Key.LeftCtrl )
if (e.Key is Key.LeftCtrl or Key.RightCtrl)
{
ActionDisplay = "Hold mouse to move all selected layers.";
ActionDisplay = "Hold mouse to move all layers.";
}
}

public override void OnKeyUp(KeyEventArgs e)
{
if (e.Key == Key.LeftCtrl)
if (e.Key is Key.LeftCtrl or Key.RightCtrl)
{
ActionDisplay = "Hold mouse to move selected pixels. Hold Ctrl to move all layers.";
ActionDisplay = defaultActionDisplay;
}
}

Expand Down Expand Up @@ -117,7 +117,7 @@ public override void OnStart(Coordinates startPos)
Selection selection = doc.ActiveSelection;
bool anySelection = selection.SelectedPoints.Any();

if (Keyboard.IsKeyDown(Key.LeftCtrl) || MoveAll)
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
{
affectedLayers = doc.Layers.Where(x => x.IsVisible).ToArray();
}
Expand Down
11 changes: 6 additions & 5 deletions PixiEditor/Models/Tools/Tools/RectangleTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,29 @@ namespace PixiEditor.Models.Tools.Tools
{
public class RectangleTool : ShapeTool
{
private string defaultActionDisplay = "Click and move to draw a rectangle. Hold Shift to draw a square.";
public RectangleTool()
{
ActionDisplay = "Click and move to draw a rectangle. Hold Shift to draw square.";
ActionDisplay = defaultActionDisplay;
}

public override string Tooltip => "Draws rectangle on canvas (R). Hold Shift to draw square.";
public override string Tooltip => "Draws rectangle on canvas (R). Hold Shift to draw a square.";

public bool Filled { get; set; } = false;

public override void OnKeyDown(KeyEventArgs e)
{
if (e.Key == Key.LeftShift)
if (e.Key is Key.LeftShift or Key.RightShift)
{
ActionDisplay = "Click and move to draw a square.";
}
}

public override void OnKeyUp(KeyEventArgs e)
{
if (e.Key == Key.LeftShift)
if (e.Key is Key.LeftShift or Key.RightShift)
{
ActionDisplay = "Click and move to draw a rectangle. Hold Shift to draw square.";
ActionDisplay = defaultActionDisplay;
}
}

Expand Down
9 changes: 5 additions & 4 deletions PixiEditor/Models/Tools/Tools/ZoomTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ namespace PixiEditor.Models.Tools.Tools
public class ZoomTool : ReadonlyTool
{
private BitmapManager BitmapManager { get; }
private string defaultActionDisplay = "Click and move to zoom. Click to zoom in, hold ctrl and click to zoom out.";

public ZoomTool(BitmapManager bitmapManager)
{
CanStartOutsideCanvas = true;
ActionDisplay = "Click and move to zoom. Click to zoom in, hold alt and click to zoom out.";
ActionDisplay = defaultActionDisplay;
BitmapManager = bitmapManager;
}

Expand All @@ -22,17 +23,17 @@ public ZoomTool(BitmapManager bitmapManager)

public override void OnKeyDown(KeyEventArgs e)
{
if (e.Key == Key.LeftCtrl)
if (e.Key is Key.LeftCtrl or Key.RightCtrl)
{
ActionDisplay = "Click and move to zoom. Click to zoom out, release ctrl and click to zoom in.";
}
}

public override void OnKeyUp(KeyEventArgs e)
{
if (e.Key == Key.LeftCtrl)
if (e.Key is Key.LeftCtrl or Key.RightCtrl)
{
ActionDisplay = "Click and move to zoom. Click to zoom in, hold ctrl and click to zoom out.";
ActionDisplay = defaultActionDisplay;
}
}

Expand Down
2 changes: 1 addition & 1 deletion PixiEditor/ViewModels/SubViewModels/Main/ToolsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public void SetActiveTool(Tool tool)
}

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

tool.IsActive = true;
ActiveTool.OnSelected();
Expand Down
2 changes: 1 addition & 1 deletion PixiEditor/Views/UserControls/Zoombox.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private void OnMouseUp(object sender, MouseButtonEventArgs e)
else
{
if (ZoomMode == Mode.ZoomTool && e.ChangedButton == MouseButton.Left)
ZoomInto(e.GetPosition(mainCanvas), Keyboard.IsKeyDown(Key.LeftCtrl) ? -1 : 1);
ZoomInto(e.GetPosition(mainCanvas), Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl) ? -1 : 1);
}
activeMouseDownEventArgs = null;
}
Expand Down

0 comments on commit 8db203e

Please sign in to comment.