fixed invalidation area and small code improvements

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2318 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
JKlingen 2012-11-25 21:21:23 +00:00
commit 4cb72219a5

View file

@ -167,9 +167,7 @@ namespace Greenshot.Forms {
// set cursor location // set cursor location
cursorPos = WindowCapture.GetCursorLocation(); cursorPos = WindowCapture.GetCursorLocation();
// Offset to screen coordinates cursorPosOnBitmap = GetAbsoluteLocation(cursorPos);
cursorPosOnBitmap = new Point(cursorPos.X, cursorPos.Y);
cursorPosOnBitmap.Offset(-capture.ScreenBounds.X, -capture.ScreenBounds.Y);
this.SuspendLayout(); this.SuspendLayout();
this.Bounds = capture.ScreenBounds; this.Bounds = capture.ScreenBounds;
@ -244,8 +242,7 @@ namespace Greenshot.Forms {
if (e.Button == MouseButtons.Left) { if (e.Button == MouseButtons.Left) {
Point tmpCursorLocation = WindowCapture.GetCursorLocation(); Point tmpCursorLocation = WindowCapture.GetCursorLocation();
// As the cursorPos is not in Bitmap coordinates, we need to correct. // As the cursorPos is not in Bitmap coordinates, we need to correct.
tmpCursorLocation.Offset(-capture.ScreenBounds.Location.X, -capture.ScreenBounds.Location.Y); tmpCursorLocation = GetAbsoluteLocation(tmpCursorLocation);
mX = tmpCursorLocation.X; mX = tmpCursorLocation.X;
mY = tmpCursorLocation.Y; mY = tmpCursorLocation.Y;
mouseDown = true; mouseDown = true;
@ -337,8 +334,8 @@ namespace Greenshot.Forms {
} }
// As the cursorPos is not in Bitmap coordinates, we need to correct. // As the cursorPos is not in Bitmap coordinates, we need to correct.
cursorPosOnBitmap = new Point(cursorPos.X, cursorPos.Y); cursorPosOnBitmap = GetAbsoluteLocation(cursorPos);
cursorPosOnBitmap.Offset(-capture.ScreenBounds.Location.X, -capture.ScreenBounds.Location.Y); Point lastPosOnBitmap = GetAbsoluteLocation(lastPos);
Rectangle lastCaptureRect = new Rectangle(captureRect.Location, captureRect.Size); Rectangle lastCaptureRect = new Rectangle(captureRect.Location, captureRect.Size);
WindowDetails lastWindow = selectedCaptureWindow; WindowDetails lastWindow = selectedCaptureWindow;
@ -383,10 +380,10 @@ namespace Greenshot.Forms {
} }
} }
if (mouseDown && (CaptureMode.Window != captureMode)) { if (mouseDown && (CaptureMode.Window != captureMode)) {
int x1 = Math.Min(mX, lastPos.X); int x1 = Math.Min(mX, lastPosOnBitmap.X);
int x2 = Math.Max(mX, lastPos.X); int x2 = Math.Max(mX, lastPosOnBitmap.X);
int y1 = Math.Min(mY, lastPos.Y); int y1 = Math.Min(mY, lastPosOnBitmap.Y);
int y2 = Math.Max(mY, lastPos.Y); int y2 = Math.Max(mY, lastPosOnBitmap.Y);
x1= Math.Min(x1, cursorPosOnBitmap.X); x1= Math.Min(x1, cursorPosOnBitmap.X);
x2= Math.Max(x2, cursorPosOnBitmap.X); x2= Math.Max(x2, cursorPosOnBitmap.X);
y1= Math.Min(y1, cursorPosOnBitmap.Y); y1= Math.Min(y1, cursorPosOnBitmap.Y);
@ -453,6 +450,12 @@ namespace Greenshot.Forms {
// Force update "now" // Force update "now"
Update(); Update();
} }
private Point GetAbsoluteLocation(Point screenLocation) {
Point ret = screenLocation.Clone();
ret.Offset(-capture.ScreenBounds.X, -capture.ScreenBounds.Y);
return ret;
}
/// <summary> /// <summary>
/// This makes sure there is no background painted, as we have complete "paint" control it doesn't make sense to do otherwise. /// This makes sure there is no background painted, as we have complete "paint" control it doesn't make sense to do otherwise.