Added a sensibility property so the Freehand drawing can also be used with a pen. This is for the reported bug [#1454]

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2461 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2013-02-05 12:57:24 +00:00
commit 3cd141eb77
3 changed files with 12 additions and 6 deletions

View file

@ -52,6 +52,8 @@ namespace Greenshot.Configuration {
public Rectangle WindowNormalPosition; public Rectangle WindowNormalPosition;
[IniProperty("ReuseEditor", Description = "Reuse already open editor", DefaultValue = "false")] [IniProperty("ReuseEditor", Description = "Reuse already open editor", DefaultValue = "false")]
public bool ReuseEditor; public bool ReuseEditor;
[IniProperty("FreehandSensitivity", Description = "The smaller this number, the less smoothing is used. Decrease for detailed drawing, e.g. when using a pen. Increase for smoother lines. e.g. when you want to draw a smooth line.", DefaultValue = "3")]
public int FreehandSensitivity;
[IniProperty("SuppressSaveDialogAtClose", Description="Suppressed the 'do you want to save' dialog when closing the editor.", DefaultValue="False")] [IniProperty("SuppressSaveDialogAtClose", Description="Suppressed the 'do you want to save' dialog when closing the editor.", DefaultValue="False")]
public bool SuppressSaveDialogAtClose; public bool SuppressSaveDialogAtClose;

View file

@ -31,6 +31,8 @@ using Greenshot.Plugin;
using Greenshot.Plugin.Drawing; using Greenshot.Plugin.Drawing;
using Greenshot.Memento; using Greenshot.Memento;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using Greenshot.Configuration;
using Greenshot.IniFile;
namespace Greenshot.Drawing { namespace Greenshot.Drawing {
/// <summary> /// <summary>
@ -42,7 +44,7 @@ namespace Greenshot.Drawing {
[Serializable()] [Serializable()]
public abstract class DrawableContainer : AbstractFieldHolderWithChildren, INotifyPropertyChanged, IDrawableContainer { public abstract class DrawableContainer : AbstractFieldHolderWithChildren, INotifyPropertyChanged, IDrawableContainer {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(DrawableContainer)); private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(DrawableContainer));
protected static readonly EditorConfiguration editorConfig = IniConfig.GetIniSection<EditorConfiguration>();
private bool isMadeUndoable = false; private bool isMadeUndoable = false;
[NonSerialized] [NonSerialized]

View file

@ -118,11 +118,11 @@ namespace Greenshot.Drawing {
/// <returns>true if the surface doesn't need to handle the event</returns> /// <returns>true if the surface doesn't need to handle the event</returns>
public override bool HandleMouseMove(int mouseX, int mouseY) { public override bool HandleMouseMove(int mouseX, int mouseY) {
Point previousPoint = capturePoints[capturePoints.Count-1]; Point previousPoint = capturePoints[capturePoints.Count-1];
if (GeometryHelper.Distance2D(previousPoint.X, previousPoint.Y, mouseX, mouseY ) > 5) { if (GeometryHelper.Distance2D(previousPoint.X, previousPoint.Y, mouseX, mouseY) >= (2*editorConfig.FreehandSensitivity)) {
capturePoints.Add(new Point(mouseX, mouseY)); capturePoints.Add(new Point(mouseX, mouseY));
} }
if (GeometryHelper.Distance2D(lastMouse.X, lastMouse.Y, mouseX, mouseY) > 2 ) { if (GeometryHelper.Distance2D(lastMouse.X, lastMouse.Y, mouseX, mouseY) >= editorConfig.FreehandSensitivity) {
//path.AddCurve(new Point[]{lastMouse, new Point(mouseX, mouseY)}); //path.AddCurve(new Point[]{lastMouse, new Point(mouseX, mouseY)});
freehandPath.AddLine(lastMouse, new Point(mouseX, mouseY)); freehandPath.AddLine(lastMouse, new Point(mouseX, mouseY));
lastMouse = new Point(mouseX, mouseY); lastMouse = new Point(mouseX, mouseY);
@ -138,7 +138,7 @@ namespace Greenshot.Drawing {
/// </summary> /// </summary>
public override void HandleMouseUp(int mouseX, int mouseY) { public override void HandleMouseUp(int mouseX, int mouseY) {
// Make sure we don't loose the ending point // Make sure we don't loose the ending point
if (GeometryHelper.Distance2D(lastMouse.X, lastMouse.Y, mouseX, mouseY) > 2) { if (GeometryHelper.Distance2D(lastMouse.X, lastMouse.Y, mouseX, mouseY) >= editorConfig.FreehandSensitivity) {
capturePoints.Add(new Point(mouseX, mouseY)); capturePoints.Add(new Point(mouseX, mouseY));
} }
RecalculatePath(); RecalculatePath();
@ -156,13 +156,15 @@ namespace Greenshot.Drawing {
freehandPath = new GraphicsPath(); freehandPath = new GraphicsPath();
// Here we can put some cleanup... like losing all the uninteresting points. // Here we can put some cleanup... like losing all the uninteresting points.
if (capturePoints.Count > 3) { if (capturePoints.Count >= 3) {
int index = 0; int index = 0;
while ((capturePoints.Count - 1) % 3 != 0) { while ((capturePoints.Count - 1) % 3 != 0) {
// duplicate points, first at 50% than 25% than 75% // duplicate points, first at 50% than 25% than 75%
capturePoints.Insert((int)(capturePoints.Count*POINT_OFFSET[index]), capturePoints[(int)(capturePoints.Count*POINT_OFFSET[index++])]); capturePoints.Insert((int)(capturePoints.Count*POINT_OFFSET[index]), capturePoints[(int)(capturePoints.Count*POINT_OFFSET[index++])]);
} }
freehandPath.AddBeziers(capturePoints.ToArray()); freehandPath.AddBeziers(capturePoints.ToArray());
} else if (capturePoints.Count == 2) {
freehandPath.AddLine(capturePoints[0], capturePoints[1]);
} }
// Recalculate the bounds // Recalculate the bounds