Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fixes Bug #1084213] Fixed sizing of canvas invalidation rectangle when zoomed in/out #49

Merged
merged 1 commit into from Dec 8, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 44 additions & 4 deletions Pinta.Core/Classes/DocumentWorkspace.cs
Expand Up @@ -119,10 +119,23 @@ public void Invalidate ()
PintaCore.Workspace.OnCanvasInvalidated (new CanvasInvalidatedEventArgs ()); PintaCore.Workspace.OnCanvasInvalidated (new CanvasInvalidatedEventArgs ());
} }


public void Invalidate (Gdk.Rectangle rect) /// <summary>
/// Repaints a rectangle region on the canvas.
/// </summary>
/// <param name='canvasRect'>
/// The rectangle region of the canvas requiring repainting
/// </param>
public void Invalidate (Gdk.Rectangle canvasRect)
{ {
rect = new Gdk.Rectangle ((int)((rect.X) * Scale + Offset.X), (int)((rect.Y) * Scale + Offset.Y), (int)(rect.Width * Scale), (int)(rect.Height * Scale)); Cairo.PointD canvasTopLeft = new Cairo.PointD(canvasRect.Left, canvasRect.Top);
PintaCore.Workspace.OnCanvasInvalidated (new CanvasInvalidatedEventArgs (rect)); Cairo.PointD canvasBtmRight = new Cairo.PointD(canvasRect.Right, canvasRect.Bottom);

Cairo.PointD winTopLeft = CanvasPointToWindow(canvasTopLeft.X, canvasTopLeft.Y);
Cairo.PointD winBtmRight = CanvasPointToWindow(canvasBtmRight.X, canvasBtmRight.Y);

Gdk.Rectangle winRect = Utility.PointsToRectangle(winTopLeft, winBtmRight, false).ToGdkRectangle();

PintaCore.Workspace.OnCanvasInvalidated (new CanvasInvalidatedEventArgs (winRect));
} }


/// <summary> /// <summary>
Expand Down Expand Up @@ -160,9 +173,36 @@ public void ScrollCanvas (int dx, int dy)
view.Vadjustment.Value = Utility.Clamp (dy + view.Vadjustment.Value, view.Vadjustment.Lower, view.Vadjustment.Upper - view.Vadjustment.PageSize); view.Vadjustment.Value = Utility.Clamp (dy + view.Vadjustment.Value, view.Vadjustment.Lower, view.Vadjustment.Upper - view.Vadjustment.PageSize);
} }


/// <summary>
/// Converts a point from window coordinates to canvas coordinates
/// </summary>
/// <param name='x'>
/// The X coordinate of the window point
/// </param>
/// <param name='y'>
/// The Y coordinate of the window point
/// </param>
public Cairo.PointD WindowPointToCanvas (double x, double y) public Cairo.PointD WindowPointToCanvas (double x, double y)
{ {
return new Cairo.PointD (Math.Floor ((x - Offset.X) / PintaCore.Workspace.Scale), Math.Floor ((y - Offset.Y) / PintaCore.Workspace.Scale)); ScaleFactor sf = new ScaleFactor(PintaCore.Workspace.ImageSize.Width, PintaCore.Workspace.CanvasSize.Width);
Cairo.PointD pt = sf.ScalePoint (new Cairo.PointD(x - Offset.X, y - Offset.Y));
return new Cairo.PointD((int)pt.X, (int)pt.Y);
}

/// <summary>
/// Converts a point from canvas coordinates to window coordinates
/// </summary>
/// <param name='x'>
/// The X coordinate of the canvas point
/// </param>
/// <param name='y'>
/// The Y coordinate of the canvas point
/// </param>
public Cairo.PointD CanvasPointToWindow (double x, double y)
{
ScaleFactor sf = new ScaleFactor(PintaCore.Workspace.ImageSize.Width, PintaCore.Workspace.CanvasSize.Width);
Cairo.PointD pt = sf.UnscalePoint (new Cairo.PointD(x, y));
return new Cairo.PointD((int)(pt.X + Offset.X), (int)(pt.Y + Offset.Y));
} }


public void ZoomIn () public void ZoomIn ()
Expand Down
27 changes: 26 additions & 1 deletion Pinta.Core/Managers/WorkspaceManager.cs
Expand Up @@ -206,12 +206,37 @@ public void ResizeCanvas (int width, int height, Anchor anchor, CompoundHistoryI
{ {
ActiveDocument.ResizeCanvas (width, height, anchor, compoundAction); ActiveDocument.ResizeCanvas (width, height, anchor, compoundAction);
} }


/// <summary>
/// Converts a point from the active documents
/// window coordinates to canvas coordinates
/// </summary>
/// <param name='x'>
/// The X coordinate of the window point
/// </param>
/// <param name='y'>
/// The Y coordinate of the window point
/// </param>
public Cairo.PointD WindowPointToCanvas (double x, double y) public Cairo.PointD WindowPointToCanvas (double x, double y)
{ {
return ActiveWorkspace.WindowPointToCanvas (x, y); return ActiveWorkspace.WindowPointToCanvas (x, y);
} }


/// <summary>
/// Converts a point from the active documents
/// canvas coordinates to window coordinates
/// </summary>
/// <param name='x'>
/// The X coordinate of the canvas point
/// </param>
/// <param name='y'>
/// The Y coordinate of the canvas point
/// </param>
public Cairo.PointD CanvasPointToWindow (double x, double y)
{
return ActiveWorkspace.CanvasPointToWindow (x, y);
}

public Gdk.Rectangle ClampToImageSize (Gdk.Rectangle r) public Gdk.Rectangle ClampToImageSize (Gdk.Rectangle r)
{ {
return ActiveDocument.ClampToImageSize (r); return ActiveDocument.ClampToImageSize (r);
Expand Down