mirror of
https://github.com/greenshot/greenshot
synced 2025-08-21 14:03:23 -07:00
BUG-2378, BUG-2435, BUG-2486, BUG-2463, BUG-2309, BUG-2307, BUG-2249 : This should solve the issue, without requiring a lock. Just use an atomic assignment.
This commit is contained in:
parent
d299e345b1
commit
2386ea15aa
1 changed files with 36 additions and 45 deletions
|
@ -36,9 +36,6 @@ namespace Greenshot.Drawing {
|
|||
public class FreehandContainer : DrawableContainer {
|
||||
private static readonly float [] PointOffset = {0.5f, 0.25f, 0.75f};
|
||||
|
||||
[NonSerialized]
|
||||
private readonly object _freehandPathLock = new object();
|
||||
|
||||
[NonSerialized]
|
||||
private GraphicsPath freehandPath = new GraphicsPath();
|
||||
private Rectangle myBounds = Rectangle.Empty;
|
||||
|
@ -113,12 +110,9 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
//path.AddCurve(new Point[]{lastMouse, new Point(mouseX, mouseY)});
|
||||
lastMouse = new Point(mouseX, mouseY);
|
||||
lock (_freehandPathLock)
|
||||
{
|
||||
freehandPath.AddLine(lastMouse, new Point(mouseX, mouseY));
|
||||
// Only re-calculate the bounds & redraw when we added something to the path
|
||||
myBounds = Rectangle.Round(freehandPath.GetBounds());
|
||||
}
|
||||
|
||||
Invalidate();
|
||||
return true;
|
||||
|
@ -139,12 +133,9 @@ namespace Greenshot.Drawing {
|
|||
/// Here we recalculate the freehand path by smoothing out the lines with Beziers.
|
||||
/// </summary>
|
||||
private void RecalculatePath() {
|
||||
lock (_freehandPathLock)
|
||||
{
|
||||
isRecalculated = true;
|
||||
// Dispose the previous path, if we have one
|
||||
freehandPath?.Dispose();
|
||||
freehandPath = new GraphicsPath();
|
||||
// Store the previous path, to dispose it later when we are finished
|
||||
var previousFreehandPath = freehandPath;
|
||||
var newFreehandPath = new GraphicsPath();
|
||||
|
||||
// Here we can put some cleanup... like losing all the uninteresting points.
|
||||
if (capturePoints.Count >= 3)
|
||||
|
@ -155,18 +146,22 @@ namespace Greenshot.Drawing {
|
|||
// duplicate points, first at 50% than 25% than 75%
|
||||
capturePoints.Insert((int)(capturePoints.Count * PointOffset[index]), capturePoints[(int)(capturePoints.Count * PointOffset[index++])]);
|
||||
}
|
||||
freehandPath.AddBeziers(capturePoints.ToArray());
|
||||
newFreehandPath.AddBeziers(capturePoints.ToArray());
|
||||
}
|
||||
else if (capturePoints.Count == 2)
|
||||
{
|
||||
freehandPath.AddLine(capturePoints[0], capturePoints[1]);
|
||||
newFreehandPath.AddLine(capturePoints[0], capturePoints[1]);
|
||||
}
|
||||
|
||||
// Recalculate the bounds
|
||||
myBounds = Rectangle.Round(freehandPath.GetBounds());
|
||||
myBounds = Rectangle.Round(newFreehandPath.GetBounds());
|
||||
|
||||
}
|
||||
// assign
|
||||
isRecalculated = true;
|
||||
freehandPath = newFreehandPath;
|
||||
|
||||
// dispose previous
|
||||
previousFreehandPath?.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -196,13 +191,15 @@ namespace Greenshot.Drawing {
|
|||
pen.LineJoin = LineJoin.Round;
|
||||
// Move to where we need to draw
|
||||
graphics.TranslateTransform(Left, Top);
|
||||
lock (_freehandPathLock)
|
||||
var currentFreehandPath = freehandPath;
|
||||
if (currentFreehandPath != null)
|
||||
{
|
||||
if (isRecalculated && Selected && renderMode == RenderMode.EDIT)
|
||||
{
|
||||
DrawSelectionBorder(graphics, pen, freehandPath);
|
||||
isRecalculated = false;
|
||||
DrawSelectionBorder(graphics, pen, currentFreehandPath);
|
||||
}
|
||||
graphics.DrawPath(pen, freehandPath);
|
||||
graphics.DrawPath(pen, currentFreehandPath);
|
||||
}
|
||||
|
||||
// Move back, otherwise everything is shifted
|
||||
|
@ -262,11 +259,8 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
lock (_freehandPathLock)
|
||||
{
|
||||
return freehandPath?.GetHashCode() ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool ClickableAt(int x, int y) {
|
||||
bool returnValue = base.ClickableAt(x, y);
|
||||
|
@ -276,10 +270,7 @@ namespace Greenshot.Drawing {
|
|||
{
|
||||
Width = lineThickness + 10
|
||||
};
|
||||
lock (_freehandPathLock)
|
||||
{
|
||||
returnValue = freehandPath.IsOutlineVisible(x - Left, y - Top, pen);
|
||||
}
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue