"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Pinta.Tools/Tools/BaseTransformTool.cs" between
pinta-1.7.tar.gz and pinta-1.7.1.tar.gz

About: Pinta is a powerful image drawing and editing program (modeled after Paint.NET).

BaseTransformTool.cs  (pinta-1.7):BaseTransformTool.cs  (pinta-1.7.1)
skipping to change at line 28 skipping to change at line 28
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using Cairo; using Cairo;
using Gtk;
using Pinta.Core; using Pinta.Core;
namespace Pinta.Tools namespace Pinta.Tools
{ {
public abstract class BaseTransformTool : BaseTool public abstract class BaseTransformTool : BaseTool
{ {
#region Members #region Members
private readonly int rotate_steps = 32; private readonly int rotate_steps = 32;
private readonly Matrix transform = new Matrix(); private readonly Matrix transform = new Matrix();
private Rectangle source_rect; private Rectangle source_rect;
private PointD original_point; private PointD original_point;
private bool is_dragging = false; private bool is_dragging = false;
private bool is_rotating = false; private bool is_rotating = false;
private bool rotateBySteps = false; private bool is_scaling = false;
private bool is_scaling = false; private bool using_mouse = false;
#endregion #endregion
#region Constructor #region Constructor
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Pinta.Tools.BaseTransfo rmTool"/> class. /// Initializes a new instance of the <see cref="Pinta.Tools.BaseTransfo rmTool"/> class.
/// </summary> /// </summary>
public BaseTransformTool () public BaseTransformTool ()
{ {
} }
#endregion #endregion
skipping to change at line 70 skipping to change at line 71
source_rect = GetSourceRectangle(); source_rect = GetSourceRectangle();
transform.InitIdentity(); transform.InitIdentity();
} }
protected virtual void OnUpdateTransform(Matrix transform) protected virtual void OnUpdateTransform(Matrix transform)
{ {
} }
protected virtual void OnFinishTransform(Matrix transform) protected virtual void OnFinishTransform(Matrix transform)
{ {
is_dragging = false;
is_rotating = false;
is_scaling = false;
using_mouse = false;
} }
protected override void OnMouseDown (Gtk.DrawingArea canvas, protected override void OnMouseDown (Gtk.DrawingArea canvas,
Gtk.ButtonPressEventArgs arg s, Gtk.ButtonPressEventArgs arg s,
Cairo.PointD point) Cairo.PointD point)
{ {
Document doc = PintaCore.Workspace.ActiveDocument; Document doc = PintaCore.Workspace.ActiveDocument;
if(is_dragging || is_rotating) if(IsActive)
return; return;
original_point = point; original_point = point;
if (!doc.Workspace.PointInCanvas(point)) if (!doc.Workspace.PointInCanvas(point))
return; return;
if(args.Event.Button == GtkExtensions.MouseRightButton) if (args.Event.Button == GtkExtensions.MouseRightButton)
{
is_rotating = true; is_rotating = true;
} else if (args.Event.State.IsControlPressed ())
is_scaling = true;
else else
{
is_dragging = true; is_dragging = true;
}
using_mouse = true;
OnStartTransform(); OnStartTransform();
} }
protected override void OnMouseMove (object o, protected override void OnMouseMove (object o,
Gtk.MotionNotifyEventArgs ar gs, Gtk.MotionNotifyEventArgs ar gs,
Cairo.PointD point) Cairo.PointD point)
{ {
if (!is_dragging && !is_rotating) if (!IsActive || !using_mouse)
return; return;
bool constrain = args.Event.State.IsShiftPressed ();
PointD center = source_rect.GetCenter(); PointD center = source_rect.GetCenter();
double dx = point.X - original_point.X; // The cursor position can be a subpixel value. Round to
double dy = point.Y - original_point.Y; an integer
// so that we only translate by entire pixels.
// (Otherwise, blurring / anti-aliasing may be introduced
)
double dx = Math.Floor(point.X - original_point.X);
double dy = Math.Floor(point.Y - original_point.Y);
double cx1 = original_point.X - center.X; double cx1 = original_point.X - center.X;
double cy1 = original_point.Y - center.Y; double cy1 = original_point.Y - center.Y;
double cx2 = point.X - center.X; double cx2 = point.X - center.X;
double cy2 = point.Y - center.Y; double cy2 = point.Y - center.Y;
double angle = Math.Atan2(cy1, cx1) - Math.Atan2(cy2, cx2 ); double angle = Math.Atan2(cy1, cx1) - Math.Atan2(cy2, cx2 );
transform.InitIdentity (); transform.InitIdentity ();
if (is_scaling) if (is_scaling)
{ {
double sx = (cx1 + dx) / cx1;
double sy = (cy1 + dy) / cy1;
if (constrain)
{
var max_scale = Math.Max (Math.Abs (sx),
Math.Abs (sy));
sx = max_scale * Math.Sign (sx);
sy = max_scale * Math.Sign (sy);
}
transform.Translate(center.X, center.Y); transform.Translate(center.X, center.Y);
transform.Scale( (cx1 + dx) / cx1, (cy1 + dy) / c y1 ); transform.Scale (sx, sy);
transform.Translate(-center.X, -center.Y); transform.Translate(-center.X, -center.Y);
} }
else if (is_rotating) else if (is_rotating)
{ {
if (rotateBySteps) if (constrain)
angle = Utility.GetNearestStepAngle (angl e, rotate_steps); angle = Utility.GetNearestStepAngle (angl e, rotate_steps);
transform.Translate(center.X, center.Y); transform.Translate(center.X, center.Y);
transform.Rotate(-angle); transform.Rotate(-angle);
transform.Translate(-center.X, -center.Y); transform.Translate(-center.X, -center.Y);
} }
else else
{ {
transform.Translate(dx, dy); transform.Translate(dx, dy);
} }
OnUpdateTransform (transform); OnUpdateTransform (transform);
} }
protected override void OnMouseUp (Gtk.DrawingArea canvas, Gtk.Bu ttonReleaseEventArgs args, Cairo.PointD point) protected override void OnMouseUp (Gtk.DrawingArea canvas, Gtk.Bu ttonReleaseEventArgs args, Cairo.PointD point)
{ {
if (!is_dragging && !is_rotating) if (!IsActive || !using_mouse)
return; return;
is_dragging = false;
is_rotating = false;
OnFinishTransform(transform); OnFinishTransform(transform);
} }
protected override void OnKeyDown (Gtk.DrawingArea canvas, Gtk.KeyPressE ventArgs args) protected override void OnKeyDown (DrawingArea canvas, KeyPressEventArgs args)
{ {
rotateBySteps = (args.Event.Key == Gdk.Key.Shift_L || args.Event.Key // Don't handle the arrow keys while already interacting via the mou
== Gdk.Key.Shift_R); se.
is_scaling = (args.Event.Key == Gdk.Key.Control_L || args.Event.Key if (using_mouse) {
== Gdk.Key.Control_R); base.OnKeyDown (canvas, args);
return;
}
double dx = 0.0;
double dy = 0.0;
switch (args.Event.Key) {
case Gdk.Key.Left:
dx = -1;
break;
case Gdk.Key.Right:
dx = 1;
break;
case Gdk.Key.Up:
dy = -1;
break;
case Gdk.Key.Down:
dy = 1;
break;
default:
// Otherwise, let the key be handled elsewhere.
base.OnKeyDown (canvas, args);
return;
}
if (!IsActive) {
is_dragging = true;
OnStartTransform ();
}
transform.Translate (dx, dy);
OnUpdateTransform (transform);
args.RetVal = true;
} }
protected override void OnKeyUp (Gtk.DrawingArea canvas, Gtk.KeyReleaseE ventArgs args) protected override void OnKeyUp (DrawingArea canvas, KeyReleaseEventArgs args)
{ {
rotateBySteps = false; if (IsActive && !using_mouse) {
is_scaling = false; OnFinishTransform (transform);
}
base.OnKeyUp (canvas, args);
} }
private bool IsActive { get { return is_dragging || is_rotating || is_sc
aling; } }
#endregion #endregion
} }
} }
 End of changes. 22 change blocks. 
25 lines changed or deleted 83 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)