Permalink
Browse files

Fixed the invalidation rectangle for redrawing the Canvas

  • Loading branch information...
1 parent cafa78f commit cb8d43bc964bac91b3b599422f7a7dd7401b8a78 @don-mccomb don-mccomb committed Dec 6, 2012
Showing with 70 additions and 5 deletions.
  1. +44 −4 Pinta.Core/Classes/DocumentWorkspace.cs
  2. +26 −1 Pinta.Core/Managers/WorkspaceManager.cs
@@ -119,10 +119,23 @@ public void Invalidate ()
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));
- PintaCore.Workspace.OnCanvasInvalidated (new CanvasInvalidatedEventArgs (rect));
+ Cairo.PointD canvasTopLeft = new Cairo.PointD(canvasRect.Left, canvasRect.Top);
+ 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>
@@ -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);
}
+ /// <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)
{
- 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 ()
@@ -206,12 +206,37 @@ public void ResizeCanvas (int width, int height, Anchor anchor, CompoundHistoryI
{
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)
{
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)
{
return ActiveDocument.ClampToImageSize (r);

0 comments on commit cb8d43b

Please sign in to comment.