Skip to content

Commit

Permalink
Merge pull request #134 from rajter/StepRotateBranch
Browse files Browse the repository at this point in the history
Step rotate branch
  • Loading branch information
cameronwhite committed May 2, 2019
2 parents 936d6aa + 6280566 commit f429bdb
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ po/Makefile.in.in
po/POTFILES
po/stamp-it
xdg/pinta.desktop
.vs

# Help
help/*/*.mo
Expand Down
23 changes: 22 additions & 1 deletion Pinta.Core/Effects/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -639,5 +639,26 @@ public static int FastDivideShortByByte(ushort n, byte d)
0x80808081, 0x00000000, 39 // 255
};

}
/// <summary>
/// Gets the nearest step angle in radians.
/// </summary>
/// <returns>The nearest step angle in radians.</returns>
/// <param name="angle">Angle in radians.</param>
/// <param name="steps">Number of steps to divide the circle.</param>
public static double GetNearestStepAngle (double angle, int steps)
{
double fullTurn = 2 * Math.PI;
double stepAngle = fullTurn / steps;
double normalizedAngle = angle % fullTurn;
int sector = Convert.ToInt32 (Math.Truncate ((normalizedAngle % fullTurn) / stepAngle));

var leftStepAngle = sector * stepAngle;
var rightStepAngle = (sector + 1) * stepAngle;

if ((angle - leftStepAngle) < (rightStepAngle - angle))
return leftStepAngle;
else
return rightStepAngle;
}
}
}
39 changes: 27 additions & 12 deletions Pinta.Tools/Tools/BaseTransformTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,21 @@ namespace Pinta.Tools
{
public abstract class BaseTransformTool : BaseTool
{
#region Members
private readonly Matrix transform = new Matrix();
#region Members
private readonly int rotate_steps = 32;
private readonly Matrix transform = new Matrix();
private Rectangle source_rect;
private PointD original_point;
private bool is_dragging = false;
private bool is_rotating = false;
#endregion

#region Constructor
/// <summary>
/// Initializes a new instance of the <see cref="Pinta.Tools.BaseTransformTool"/> class.
/// </summary>
public BaseTransformTool ()
private bool rotateBySteps = false;
#endregion

#region Constructor
/// <summary>
/// Initializes a new instance of the <see cref="Pinta.Tools.BaseTransformTool"/> class.
/// </summary>
public BaseTransformTool ()
{
}
#endregion
Expand Down Expand Up @@ -115,7 +117,10 @@ protected virtual void OnFinishTransform()

if (is_rotating)
{
transform.Translate(center.X, center.Y);
if (rotateBySteps)
angle = Utility.GetNearestStepAngle (angle, rotate_steps);

transform.Translate(center.X, center.Y);
transform.Rotate(-angle);
transform.Translate(-center.X, -center.Y);
}
Expand All @@ -134,7 +139,17 @@ protected override void OnMouseUp (Gtk.DrawingArea canvas, Gtk.ButtonReleaseEven

OnFinishTransform();
}
#endregion
}

protected override void OnKeyDown (Gtk.DrawingArea canvas, Gtk.KeyPressEventArgs args)
{
rotateBySteps = (args.Event.Key == Gdk.Key.Shift_L);
}

protected override void OnKeyUp (Gtk.DrawingArea canvas, Gtk.KeyReleaseEventArgs args)
{
rotateBySteps = false;
}
#endregion
}
}

2 changes: 1 addition & 1 deletion Pinta.Tools/Tools/MoveSelectedTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class MoveSelectedTool : BaseTransformTool
get { return "Tools.Move.png"; }
}
public override string StatusBarText {
get { return Catalog.GetString ("Left click and drag the selection to move selected content. Right click and drag the selection to rotate selected content."); }
get { return Catalog.GetString ("Left click and drag the selection to move selected content. Right click and drag the selection to rotate selected content. Hold Shift to rotate in steps."); }
}
public override Gdk.Cursor DefaultCursor {
get { return new Gdk.Cursor (Gdk.Display.Default, PintaCore.Resources.GetIcon ("Tools.Move.png"), 0, 0); }
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Tools/Tools/MoveSelectionTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class MoveSelectionTool : BaseTransformTool
get { return "Tools.MoveSelection.png"; }
}
public override string StatusBarText {
get { return Catalog.GetString ("Left click and drag the selection to move selection outline. Right click and drag the selection to rotate selection outline."); }
get { return Catalog.GetString ("Left click and drag the selection to move selection outline. Right click and drag the selection to rotate selection outline. Hold Shift to rotate in steps."); }
}
public override Gdk.Cursor DefaultCursor {
get { return new Gdk.Cursor (Gdk.Display.Default, PintaCore.Resources.GetIcon ("Tools.MoveSelection.png"), 0, 0); }
Expand Down

0 comments on commit f429bdb

Please sign in to comment.