mirror of
https://github.com/greenshot/greenshot
synced 2025-08-21 14:03:23 -07:00
Small cleanups [skip ci]
This commit is contained in:
parent
02a06a12b0
commit
98e6be5eb6
171 changed files with 1607 additions and 1769 deletions
|
@ -79,7 +79,7 @@ namespace Greenshot.Drawing {
|
|||
Top + currentStep + Height);
|
||||
|
||||
currentStep++;
|
||||
alpha = alpha - (basealpha / steps);
|
||||
alpha = alpha - basealpha / steps;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace Greenshot.Drawing {
|
|||
/// </summary>
|
||||
[Serializable]
|
||||
public class CursorContainer : DrawableContainer, ICursorContainer {
|
||||
private static ILog LOG = LogManager.GetLogger(typeof(CursorContainer));
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(CursorContainer));
|
||||
|
||||
protected Cursor cursor;
|
||||
|
||||
|
|
|
@ -46,10 +46,8 @@ namespace Greenshot.Drawing {
|
|||
public abstract class DrawableContainer : AbstractFieldHolderWithChildren, IDrawableContainer {
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(DrawableContainer));
|
||||
protected static readonly EditorConfiguration EditorConfig = IniConfig.GetIniSection<EditorConfiguration>();
|
||||
private bool isMadeUndoable;
|
||||
private bool _isMadeUndoable;
|
||||
private const int M11 = 0;
|
||||
private const int M12 = 1;
|
||||
private const int M21 = 2;
|
||||
private const int M22 = 3;
|
||||
|
||||
|
||||
|
@ -305,7 +303,7 @@ namespace Greenshot.Drawing {
|
|||
Left = _parent.Width - Width - lineThickness/2;
|
||||
}
|
||||
if (horizontalAlignment == HorizontalAlignment.Center) {
|
||||
Left = (_parent.Width / 2) - (Width / 2) - lineThickness/2;
|
||||
Left = _parent.Width / 2 - Width / 2 - lineThickness/2;
|
||||
}
|
||||
|
||||
if (verticalAlignment == VerticalAlignment.TOP) {
|
||||
|
@ -315,7 +313,7 @@ namespace Greenshot.Drawing {
|
|||
Top = _parent.Height - Height - lineThickness/2;
|
||||
}
|
||||
if (verticalAlignment == VerticalAlignment.CENTER) {
|
||||
Top = (_parent.Height / 2) - (Height / 2) - lineThickness/2;
|
||||
Top = _parent.Height / 2 - Height / 2 - lineThickness/2;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -455,7 +453,7 @@ namespace Greenshot.Drawing {
|
|||
} else {
|
||||
Status = EditStatus.MOVING;
|
||||
}
|
||||
isMadeUndoable = false;
|
||||
_isMadeUndoable = false;
|
||||
}
|
||||
|
||||
private void GripperMouseUp(object sender, MouseEventArgs e) {
|
||||
|
@ -463,7 +461,7 @@ namespace Greenshot.Drawing {
|
|||
if (originatingGripper != _targetGripper) {
|
||||
_boundsBeforeResize = Rectangle.Empty;
|
||||
_boundsAfterResize = RectangleF.Empty;
|
||||
isMadeUndoable = false;
|
||||
_isMadeUndoable = false;
|
||||
}
|
||||
Status = EditStatus.IDLE;
|
||||
Invalidate();
|
||||
|
@ -478,9 +476,9 @@ namespace Greenshot.Drawing {
|
|||
TargetGripperMove(absX, absY);
|
||||
} else if (Status.Equals(EditStatus.RESIZING)) {
|
||||
// check if we already made this undoable
|
||||
if (!isMadeUndoable) {
|
||||
if (!_isMadeUndoable) {
|
||||
// don't allow another undo until we are finished with this move
|
||||
isMadeUndoable = true;
|
||||
_isMadeUndoable = true;
|
||||
// Make undo-able
|
||||
MakeBoundsChangeUndoable(false);
|
||||
}
|
||||
|
@ -699,6 +697,8 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
// TODO: This actually doesn't make sense...
|
||||
// Place the container in a list, and you can't find it :)
|
||||
return left.GetHashCode() ^ top.GetHashCode() ^ width.GetHashCode() ^ height.GetHashCode() ^ GetFields().GetHashCode();
|
||||
}
|
||||
|
||||
|
|
|
@ -322,7 +322,7 @@ namespace Greenshot.Drawing {
|
|||
if (!elements.Contains(dc)) {
|
||||
continue;
|
||||
}
|
||||
if (Count > (i+1) && !elements.Contains(this[i+1])) {
|
||||
if (Count > i+1 && !elements.Contains(this[i+1])) {
|
||||
SwapElements(i,i+1);
|
||||
}
|
||||
}
|
||||
|
@ -468,7 +468,7 @@ namespace Greenshot.Drawing {
|
|||
|
||||
// Copy
|
||||
item = new ToolStripMenuItem(Language.GetString(LangKey.editor_copytoclipboard));
|
||||
item.Image = ((Image)(editorFormResources.GetObject("copyToolStripMenuItem.Image")));
|
||||
item.Image = (Image)editorFormResources.GetObject("copyToolStripMenuItem.Image");
|
||||
item.Click += delegate {
|
||||
ClipboardHelper.SetClipboardData(typeof(DrawableContainerList), this);
|
||||
};
|
||||
|
@ -476,7 +476,7 @@ namespace Greenshot.Drawing {
|
|||
|
||||
// Cut
|
||||
item = new ToolStripMenuItem(Language.GetString(LangKey.editor_cuttoclipboard));
|
||||
item.Image = ((Image)(editorFormResources.GetObject("btnCut.Image")));
|
||||
item.Image = (Image)editorFormResources.GetObject("btnCut.Image");
|
||||
item.Click += delegate {
|
||||
ClipboardHelper.SetClipboardData(typeof(DrawableContainerList), this);
|
||||
List<DrawableContainer> containersToDelete = new List<DrawableContainer>();
|
||||
|
@ -492,7 +492,7 @@ namespace Greenshot.Drawing {
|
|||
|
||||
// Delete
|
||||
item = new ToolStripMenuItem(Language.GetString(LangKey.editor_deleteelement));
|
||||
item.Image = ((Image)(editorFormResources.GetObject("removeObjectToolStripMenuItem.Image")));
|
||||
item.Image = (Image)editorFormResources.GetObject("removeObjectToolStripMenuItem.Image");
|
||||
item.Click += delegate {
|
||||
List<DrawableContainer> containersToDelete = new List<DrawableContainer>();
|
||||
foreach(var drawableContainer in this) {
|
||||
|
|
|
@ -59,12 +59,15 @@ namespace Greenshot.Drawing {
|
|||
/// <summary>
|
||||
/// This allows another container to draw an ellipse
|
||||
/// </summary>
|
||||
/// <param name="caller"></param>
|
||||
/// <param name="rect"></param>
|
||||
/// <param name="graphics"></param>
|
||||
/// <param name="renderMode"></param>
|
||||
/// <param name="lineThickness"></param>
|
||||
/// <param name="lineColor"></param>
|
||||
/// <param name="fillColor"></param>
|
||||
/// <param name="shadow"></param>
|
||||
public static void DrawEllipse(Rectangle rect, Graphics graphics, RenderMode renderMode, int lineThickness, Color lineColor, Color fillColor, bool shadow) {
|
||||
|
||||
bool lineVisible = (lineThickness > 0 && Colors.IsVisible(lineColor));
|
||||
bool lineVisible = lineThickness > 0 && Colors.IsVisible(lineColor);
|
||||
// draw shadow before anything else
|
||||
if (shadow && (lineVisible || Colors.IsVisible(fillColor))) {
|
||||
int basealpha = 100;
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace Greenshot.Drawing.Fields {
|
|||
[Serializable]
|
||||
public abstract class AbstractFieldHolder : IFieldHolder {
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(AbstractFieldHolder));
|
||||
private static EditorConfiguration editorConfiguration = IniConfig.GetIniSection<EditorConfiguration>();
|
||||
private static readonly EditorConfiguration editorConfiguration = IniConfig.GetIniSection<EditorConfiguration>();
|
||||
|
||||
/// <summary>
|
||||
/// called when a field's value has changed
|
||||
|
@ -50,10 +50,8 @@ namespace Greenshot.Drawing.Fields {
|
|||
// this allows us to use default serialization
|
||||
[NonSerialized]
|
||||
private Dictionary<FieldType, Field> fieldsByType = new Dictionary<FieldType, Field>();
|
||||
private List<Field> fields = new List<Field>();
|
||||
|
||||
public AbstractFieldHolder() {}
|
||||
|
||||
private readonly List<Field> fields = new List<Field>();
|
||||
|
||||
[OnDeserialized]
|
||||
private void OnDeserialized(StreamingContext context) {
|
||||
fieldsByType = new Dictionary<FieldType, Field>();
|
||||
|
|
|
@ -30,8 +30,7 @@ namespace Greenshot.Drawing.Fields {
|
|||
/// </summary>
|
||||
[Serializable()]
|
||||
public abstract class AbstractFieldHolderWithChildren : AbstractFieldHolder {
|
||||
|
||||
FieldChangedEventHandler fieldChangedEventHandler;
|
||||
readonly FieldChangedEventHandler fieldChangedEventHandler;
|
||||
|
||||
[NonSerialized]
|
||||
private EventHandler childrenChanged;
|
||||
|
|
|
@ -26,8 +26,6 @@ namespace Greenshot.Drawing.Fields.Binding {
|
|||
/// </summary>
|
||||
public abstract class AbstractBindingConverter<T1,T2> : IBindingConverter
|
||||
{
|
||||
public AbstractBindingConverter() {}
|
||||
|
||||
public object convert(object o) {
|
||||
if(o == null) {
|
||||
return null;
|
||||
|
|
|
@ -29,35 +29,35 @@ namespace Greenshot.Drawing.Fields.Binding {
|
|||
/// behavior (e.g. when binding to a
|
||||
/// </summary>
|
||||
public class BidirectionalBinding {
|
||||
private INotifyPropertyChanged controlObject;
|
||||
private INotifyPropertyChanged fieldObject;
|
||||
private string controlPropertyName;
|
||||
private string fieldPropertyName;
|
||||
private bool updatingControl = false;
|
||||
private bool updatingField = false;
|
||||
private IBindingConverter converter;
|
||||
private IBindingValidator validator;
|
||||
private readonly INotifyPropertyChanged _controlObject;
|
||||
private readonly INotifyPropertyChanged _fieldObject;
|
||||
private readonly string _controlPropertyName;
|
||||
private readonly string _fieldPropertyName;
|
||||
private bool _updatingControl;
|
||||
private bool _updatingField;
|
||||
private IBindingConverter _converter;
|
||||
private readonly IBindingValidator _validator;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not null values are passed on to the other object.
|
||||
/// </summary>
|
||||
protected bool AllowSynchronizeNull = true;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Bind properties of two objects bidirectionally
|
||||
/// </summary>
|
||||
/// <param name="object1">Object containing 1st property to bind</param>
|
||||
/// <param name="property1">Property of 1st object to bind</param>
|
||||
/// <param name="object2">Object containing 2nd property to bind</param>
|
||||
/// <param name="property2">Property of 2nd object to bind</param>
|
||||
/// <param name="controlObject">Object containing 1st property to bind</param>
|
||||
/// <param name="controlPropertyName">Property of 1st object to bind</param>
|
||||
/// <param name="fieldObject">Object containing 2nd property to bind</param>
|
||||
/// <param name="fieldPropertyName">Property of 2nd object to bind</param>
|
||||
public BidirectionalBinding(INotifyPropertyChanged controlObject, string controlPropertyName, INotifyPropertyChanged fieldObject, string fieldPropertyName) {
|
||||
this.controlObject = controlObject;
|
||||
this.fieldObject = fieldObject;
|
||||
this.controlPropertyName = controlPropertyName;
|
||||
this.fieldPropertyName = fieldPropertyName;
|
||||
_controlObject = controlObject;
|
||||
_fieldObject = fieldObject;
|
||||
_controlPropertyName = controlPropertyName;
|
||||
_fieldPropertyName = fieldPropertyName;
|
||||
|
||||
this.controlObject.PropertyChanged += ControlPropertyChanged;
|
||||
this.fieldObject.PropertyChanged += FieldPropertyChanged;
|
||||
_controlObject.PropertyChanged += ControlPropertyChanged;
|
||||
_fieldObject.PropertyChanged += FieldPropertyChanged;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -69,7 +69,7 @@ namespace Greenshot.Drawing.Fields.Binding {
|
|||
/// <param name="fieldPropertyName">Property of 2nd object to bind</param>
|
||||
/// <param name="converter">taking care of converting the synchronized value to the correct target format and back</param>
|
||||
public BidirectionalBinding(INotifyPropertyChanged controlObject, string controlPropertyName, INotifyPropertyChanged fieldObject, string fieldPropertyName, IBindingConverter converter) : this(controlObject, controlPropertyName, fieldObject, fieldPropertyName) {
|
||||
this.converter = converter;
|
||||
_converter = converter;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -82,7 +82,7 @@ namespace Greenshot.Drawing.Fields.Binding {
|
|||
/// <param name="fieldPropertyName">Property of 2nd object to bind</param>
|
||||
/// <param name="validator">validator to intercept synchronization if the value does not match certain criteria</param>
|
||||
public BidirectionalBinding(INotifyPropertyChanged controlObject, string controlPropertyName, INotifyPropertyChanged fieldObject, string fieldPropertyName, IBindingValidator validator) : this(controlObject, controlPropertyName, fieldObject, fieldPropertyName) {
|
||||
this.validator = validator;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -96,46 +96,46 @@ namespace Greenshot.Drawing.Fields.Binding {
|
|||
/// <param name="converter">taking care of converting the synchronized value to the correct target format and back</param>
|
||||
/// <param name="validator">validator to intercept synchronization if the value does not match certain criteria</param>
|
||||
public BidirectionalBinding(INotifyPropertyChanged controlObject, string controlPropertyName, INotifyPropertyChanged fieldObject, string fieldPropertyName, IBindingConverter converter, IBindingValidator validator) : this(controlObject, controlPropertyName, fieldObject, fieldPropertyName, converter) {
|
||||
this.validator = validator;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
public void ControlPropertyChanged(object sender, PropertyChangedEventArgs e) {
|
||||
if (!updatingControl && e.PropertyName.Equals(controlPropertyName)) {
|
||||
updatingField = true;
|
||||
synchronize(controlObject, controlPropertyName, fieldObject, fieldPropertyName);
|
||||
updatingField = false;
|
||||
if (!_updatingControl && e.PropertyName.Equals(_controlPropertyName)) {
|
||||
_updatingField = true;
|
||||
Synchronize(_controlObject, _controlPropertyName, _fieldObject, _fieldPropertyName);
|
||||
_updatingField = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void FieldPropertyChanged(object sender, PropertyChangedEventArgs e) {
|
||||
if (!updatingField && e.PropertyName.Equals(fieldPropertyName)) {
|
||||
updatingControl = true;
|
||||
synchronize(fieldObject, fieldPropertyName, controlObject, controlPropertyName);
|
||||
updatingControl = false;
|
||||
if (!_updatingField && e.PropertyName.Equals(_fieldPropertyName)) {
|
||||
_updatingControl = true;
|
||||
Synchronize(_fieldObject, _fieldPropertyName, _controlObject, _controlPropertyName);
|
||||
_updatingControl = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void synchronize(INotifyPropertyChanged sourceObject, string sourceProperty, INotifyPropertyChanged targetObject, string targetProperty) {
|
||||
PropertyInfo targetPropertyInfo = resolvePropertyInfo(targetObject, targetProperty);
|
||||
PropertyInfo sourcePropertyInfo = resolvePropertyInfo(sourceObject, sourceProperty);
|
||||
private void Synchronize(INotifyPropertyChanged sourceObject, string sourceProperty, INotifyPropertyChanged targetObject, string targetProperty) {
|
||||
PropertyInfo targetPropertyInfo = ResolvePropertyInfo(targetObject, targetProperty);
|
||||
PropertyInfo sourcePropertyInfo = ResolvePropertyInfo(sourceObject, sourceProperty);
|
||||
|
||||
if (sourcePropertyInfo != null && targetPropertyInfo != null && targetPropertyInfo.CanWrite) {
|
||||
object bValue = sourcePropertyInfo.GetValue(sourceObject, null);
|
||||
if (converter != null && bValue != null) {
|
||||
bValue = converter.convert(bValue);
|
||||
if (_converter != null && bValue != null) {
|
||||
bValue = _converter.convert(bValue);
|
||||
}
|
||||
try {
|
||||
if (validator == null || validator.validate(bValue)) {
|
||||
if (_validator == null || _validator.validate(bValue)) {
|
||||
targetPropertyInfo.SetValue(targetObject, bValue, null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new MemberAccessException("Could not set property '"+targetProperty+"' to '"+bValue+"' ["+((bValue!=null)?bValue.GetType().Name:"")+"] on "+targetObject+". Probably other type than expected, IBindingCoverter to the rescue.", e);
|
||||
throw new MemberAccessException("Could not set property '"+targetProperty+"' to '"+bValue+"' ["+(bValue!=null?bValue.GetType().Name:"")+"] on "+targetObject+". Probably other type than expected, IBindingCoverter to the rescue.", e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private PropertyInfo resolvePropertyInfo(object obj, string property) {
|
||||
private static PropertyInfo ResolvePropertyInfo(object obj, string property) {
|
||||
PropertyInfo ret = null;
|
||||
string[] properties = property.Split(".".ToCharArray());
|
||||
for(int i=0; i<properties.Length; i++) {
|
||||
|
@ -149,8 +149,8 @@ namespace Greenshot.Drawing.Fields.Binding {
|
|||
}
|
||||
|
||||
public IBindingConverter Converter {
|
||||
get { return converter; }
|
||||
set { converter = value; }
|
||||
get { return _converter; }
|
||||
set { _converter = value; }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ using System.ComponentModel;
|
|||
using Greenshot.Configuration;
|
||||
using Greenshot.IniFile;
|
||||
using Greenshot.Plugin.Drawing;
|
||||
using log4net;
|
||||
|
||||
namespace Greenshot.Drawing.Fields {
|
||||
/// <summary>
|
||||
|
@ -41,13 +40,10 @@ namespace Greenshot.Drawing.Fields {
|
|||
/// </summary>
|
||||
public class FieldAggregator : AbstractFieldHolder {
|
||||
|
||||
private List<IDrawableContainer> boundContainers;
|
||||
private bool internalUpdateRunning = false;
|
||||
|
||||
enum Status {IDLE, BINDING, UPDATING};
|
||||
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(FieldAggregator));
|
||||
private static EditorConfiguration editorConfiguration = IniConfig.GetIniSection<EditorConfiguration>();
|
||||
private readonly List<IDrawableContainer> boundContainers;
|
||||
private bool internalUpdateRunning;
|
||||
|
||||
private static readonly EditorConfiguration editorConfiguration = IniConfig.GetIniSection<EditorConfiguration>();
|
||||
|
||||
public FieldAggregator() {
|
||||
foreach(FieldType fieldType in FieldType.Values) {
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace Greenshot.Drawing {
|
|||
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
|
||||
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
|
||||
bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
|
||||
bool lineVisible = (lineThickness > 0 && Colors.IsVisible(lineColor));
|
||||
bool lineVisible = lineThickness > 0 && Colors.IsVisible(lineColor);
|
||||
if (lineVisible) {
|
||||
graphics.SmoothingMode = SmoothingMode.HighSpeed;
|
||||
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
|
@ -69,7 +69,7 @@ namespace Greenshot.Drawing {
|
|||
Rectangle shadowRect = GuiRectangle.GetGuiRectangle(Left + currentStep, Top + currentStep, Width, Height);
|
||||
graphics.DrawRectangle(shadowPen, shadowRect);
|
||||
currentStep++;
|
||||
alpha = alpha - (basealpha / steps);
|
||||
alpha = alpha - basealpha / steps;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace Greenshot.Drawing.Filters {
|
|||
remove{ propertyChanged -= value; }
|
||||
}
|
||||
|
||||
private bool invert = false;
|
||||
private bool invert;
|
||||
public bool Invert {
|
||||
get {
|
||||
return invert;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using Greenshot.Drawing.Fields;
|
||||
|
@ -25,13 +26,10 @@ using Greenshot.Plugin.Drawing;
|
|||
using GreenshotPlugin.Core;
|
||||
using GreenshotPlugin.UnmanagedHelpers;
|
||||
using System.Drawing.Drawing2D;
|
||||
using log4net;
|
||||
|
||||
namespace Greenshot.Drawing.Filters {
|
||||
[Serializable()]
|
||||
public class BlurFilter : AbstractFilter {
|
||||
private static ILog LOG = LogManager.GetLogger(typeof(BlurFilter));
|
||||
|
||||
public double previewQuality;
|
||||
public double PreviewQuality {
|
||||
get { return previewQuality; }
|
||||
|
@ -43,7 +41,7 @@ namespace Greenshot.Drawing.Filters {
|
|||
AddField(GetType(), FieldType.PREVIEW_QUALITY, 1.0d);
|
||||
}
|
||||
|
||||
public unsafe override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) {
|
||||
public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) {
|
||||
int blurRadius = GetFieldValueAsInt(FieldType.BLUR_RADIUS);
|
||||
Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);
|
||||
if (applyRect.Width == 0 || applyRect.Height == 0) {
|
||||
|
@ -54,7 +52,7 @@ namespace Greenshot.Drawing.Filters {
|
|||
graphics.SetClip(applyRect);
|
||||
graphics.ExcludeClip(rect);
|
||||
}
|
||||
if (GDIplus.isBlurPossible(blurRadius)) {
|
||||
if (GDIplus.IsBlurPossible(blurRadius)) {
|
||||
GDIplus.DrawWithBlur(graphics, applyBitmap, applyRect, null, null, blurRadius, false);
|
||||
} else {
|
||||
using (IFastBitmap fastBitmap = FastBitmap.CreateCloneOf(applyBitmap, applyRect)) {
|
||||
|
@ -63,7 +61,6 @@ namespace Greenshot.Drawing.Filters {
|
|||
}
|
||||
}
|
||||
graphics.Restore(state);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace Greenshot.Drawing.Filters {
|
|||
int halfHeight = rect.Height / 2;
|
||||
int newWidth = rect.Width / magnificationFactor;
|
||||
int newHeight = rect.Height / magnificationFactor;
|
||||
Rectangle source = new Rectangle(rect.X + halfWidth - (newWidth / 2), rect.Y + halfHeight - (newHeight / 2), newWidth, newHeight);
|
||||
Rectangle source = new Rectangle(rect.X + halfWidth - newWidth / 2, rect.Y + halfHeight - newHeight / 2, newWidth, newHeight);
|
||||
graphics.DrawImage(applyBitmap, rect, source, GraphicsUnit.Pixel);
|
||||
graphics.Restore(state);
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace Greenshot.Drawing.Filters {
|
|||
|
||||
public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) {
|
||||
int pixelSize = GetFieldValueAsInt(FieldType.PIXEL_SIZE);
|
||||
Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);
|
||||
ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);
|
||||
if (pixelSize <= 1 || rect.Width == 0 || rect.Height == 0) {
|
||||
// Nothing to do
|
||||
return;
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
using Greenshot.Drawing.Fields;
|
||||
using Greenshot.Helpers;
|
||||
using Greenshot.Plugin.Drawing;
|
||||
using log4net;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
@ -35,15 +34,14 @@ namespace Greenshot.Drawing {
|
|||
/// </summary>
|
||||
[Serializable]
|
||||
public class FreehandContainer : DrawableContainer {
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(FreehandContainer));
|
||||
private static readonly float [] POINT_OFFSET = new float[]{0.5f, 0.25f, 0.75f};
|
||||
|
||||
[NonSerialized]
|
||||
private GraphicsPath freehandPath = new GraphicsPath();
|
||||
private Rectangle myBounds = Rectangle.Empty;
|
||||
private Point lastMouse = Point.Empty;
|
||||
private List<Point> capturePoints = new List<Point>();
|
||||
private bool isRecalculated = false;
|
||||
private readonly List<Point> capturePoints = new List<Point>();
|
||||
private bool isRecalculated;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
|
@ -119,7 +117,7 @@ namespace Greenshot.Drawing {
|
|||
public override bool HandleMouseMove(int mouseX, int mouseY) {
|
||||
Point previousPoint = capturePoints[capturePoints.Count-1];
|
||||
|
||||
if (GeometryHelper.Distance2D(previousPoint.X, previousPoint.Y, mouseX, mouseY) >= (2*EditorConfig.FreehandSensitivity)) {
|
||||
if (GeometryHelper.Distance2D(previousPoint.X, previousPoint.Y, mouseX, mouseY) >= 2*EditorConfig.FreehandSensitivity) {
|
||||
capturePoints.Add(new Point(mouseX, mouseY));
|
||||
}
|
||||
if (GeometryHelper.Distance2D(lastMouse.X, lastMouse.Y, mouseX, mouseY) >= EditorConfig.FreehandSensitivity) {
|
||||
|
@ -232,7 +230,7 @@ namespace Greenshot.Drawing {
|
|||
if (!myBounds.IsEmpty) {
|
||||
int lineThickness = Math.Max(10, GetFieldValueAsInt(FieldType.LINE_THICKNESS));
|
||||
int safetymargin = 10;
|
||||
return new Rectangle((myBounds.Left + Left) - (safetymargin+lineThickness), (myBounds.Top + Top) - (safetymargin+lineThickness), myBounds.Width + (2*(lineThickness+safetymargin)), myBounds.Height + (2*(lineThickness+safetymargin)));
|
||||
return new Rectangle(myBounds.Left + Left - (safetymargin+lineThickness), myBounds.Top + Top - (safetymargin+lineThickness), myBounds.Width + 2*(lineThickness+safetymargin), myBounds.Height + 2*(lineThickness+safetymargin));
|
||||
}
|
||||
return new Rectangle(0, 0, _parent.Width, _parent.Height);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace Greenshot.Drawing {
|
|||
/// </summary>
|
||||
[Serializable]
|
||||
public class IconContainer : DrawableContainer, IIconContainer {
|
||||
private static ILog LOG = LogManager.GetLogger(typeof(IconContainer));
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(IconContainer));
|
||||
|
||||
protected Icon icon;
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace Greenshot.Drawing {
|
|||
/// </summary>
|
||||
[Serializable]
|
||||
public class ImageContainer : DrawableContainer, IImageContainer {
|
||||
private static ILog LOG = LogManager.GetLogger(typeof(ImageContainer));
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(ImageContainer));
|
||||
|
||||
private Image image;
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ namespace Greenshot.Drawing {
|
|||
Top + currentStep + Height);
|
||||
|
||||
currentStep++;
|
||||
alpha = alpha - (basealpha / steps);
|
||||
alpha = alpha - basealpha / steps;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace Greenshot.Drawing {
|
|||
graphics.CompositingQuality = CompositingQuality.HighQuality;
|
||||
graphics.PixelOffsetMode = PixelOffsetMode.None;
|
||||
|
||||
bool lineVisible = (lineThickness > 0 && Colors.IsVisible(lineColor));
|
||||
bool lineVisible = lineThickness > 0 && Colors.IsVisible(lineColor);
|
||||
if (shadow && (lineVisible || Colors.IsVisible(fillColor))) {
|
||||
//draw shadow first
|
||||
int basealpha = 100;
|
||||
|
@ -86,7 +86,7 @@ namespace Greenshot.Drawing {
|
|||
rect.Height);
|
||||
graphics.DrawRectangle(shadowPen, shadowRect);
|
||||
currentStep++;
|
||||
alpha = alpha - (basealpha / steps);
|
||||
alpha = alpha - basealpha / steps;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,13 +35,13 @@ namespace Greenshot.Drawing {
|
|||
|
||||
public static GraphicsPath Create2(int x, int y, int width, int height, int radius) {
|
||||
GraphicsPath gp = new GraphicsPath();
|
||||
gp.AddLine(x + radius, y, x + width - (radius * 2), y); // Line
|
||||
gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90); // Corner
|
||||
gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2)); // Line
|
||||
gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90); // Corner
|
||||
gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height); // Line
|
||||
gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90); // Corner
|
||||
gp.AddLine(x, y + height - (radius * 2), x, y + radius); // Line
|
||||
gp.AddLine(x + radius, y, x + width - radius * 2, y); // Line
|
||||
gp.AddArc(x + width - radius * 2, y, radius * 2, radius * 2, 270, 90); // Corner
|
||||
gp.AddLine(x + width, y + radius, x + width, y + height - radius * 2); // Line
|
||||
gp.AddArc(x + width - radius * 2, y + height - radius * 2, radius * 2, radius * 2, 0, 90); // Corner
|
||||
gp.AddLine(x + width - radius * 2, y + height, x + radius, y + height); // Line
|
||||
gp.AddArc(x, y + height - radius * 2, radius * 2, radius * 2, 90, 90); // Corner
|
||||
gp.AddLine(x, y + height - radius * 2, x, y + radius); // Line
|
||||
gp.AddArc(x, y, radius * 2, radius * 2, 180, 90); // Corner
|
||||
gp.CloseFigure();
|
||||
|
||||
|
|
|
@ -180,7 +180,7 @@ namespace Greenshot.Drawing {
|
|||
private GraphicsPath CreateTail() {
|
||||
Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
|
||||
|
||||
int tailLength = GeometryHelper.Distance2D(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2), TargetGripper.Left, TargetGripper.Top);
|
||||
int tailLength = GeometryHelper.Distance2D(rect.Left + rect.Width / 2, rect.Top + rect.Height / 2, TargetGripper.Left, TargetGripper.Top);
|
||||
int tailWidth = (Math.Abs(rect.Width) + Math.Abs(rect.Height)) / 20;
|
||||
|
||||
// This should fix a problem with the tail being to wide
|
||||
|
@ -192,10 +192,10 @@ namespace Greenshot.Drawing {
|
|||
tail.AddLine(tailWidth, 0, 0, -tailLength);
|
||||
tail.CloseFigure();
|
||||
|
||||
int tailAngle = 90 + (int)GeometryHelper.Angle2D(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2), TargetGripper.Left, TargetGripper.Top);
|
||||
int tailAngle = 90 + (int)GeometryHelper.Angle2D(rect.Left + rect.Width / 2, rect.Top + rect.Height / 2, TargetGripper.Left, TargetGripper.Top);
|
||||
|
||||
using (Matrix tailMatrix = new Matrix()) {
|
||||
tailMatrix.Translate(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2));
|
||||
tailMatrix.Translate(rect.Left + rect.Width / 2, rect.Top + rect.Height / 2);
|
||||
tailMatrix.Rotate(tailAngle);
|
||||
tail.Transform(tailMatrix);
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ namespace Greenshot.Drawing {
|
|||
bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
|
||||
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
|
||||
|
||||
bool lineVisible = (lineThickness > 0 && Colors.IsVisible(lineColor));
|
||||
bool lineVisible = lineThickness > 0 && Colors.IsVisible(lineColor);
|
||||
Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
|
||||
|
||||
if (Selected && renderMode == RenderMode.EDIT) {
|
||||
|
@ -253,7 +253,7 @@ namespace Greenshot.Drawing {
|
|||
graphics.DrawPath(shadowPen, bubbleClone);
|
||||
}
|
||||
currentStep++;
|
||||
alpha = alpha - (basealpha / steps);
|
||||
alpha = alpha - basealpha / steps;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ namespace Greenshot.Drawing {
|
|||
/// This makes it possible for the label to be placed exactly in the middle of the pointer.
|
||||
/// </summary>
|
||||
public override bool HandleMouseDown(int mouseX, int mouseY) {
|
||||
return base.HandleMouseDown(mouseX - (Width / 2), mouseY - (Height / 2));
|
||||
return base.HandleMouseDown(mouseX - Width / 2, mouseY - Height / 2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -146,8 +146,8 @@ namespace Greenshot.Drawing {
|
|||
|
||||
public override bool HandleMouseMove(int x, int y) {
|
||||
Invalidate();
|
||||
Left = x - (Width / 2);
|
||||
Top = y - (Height / 2);
|
||||
Left = x - Width / 2;
|
||||
Top = y - Height / 2;
|
||||
Invalidate();
|
||||
return true;
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ namespace Greenshot.Drawing {
|
|||
|
||||
int widthAfter = rect.Width;
|
||||
int heightAfter = rect.Height;
|
||||
float factor = (((float)widthAfter / widthBefore) + ((float)heightAfter / heightBefore)) / 2;
|
||||
float factor = ((float)widthAfter / widthBefore + (float)heightAfter / heightBefore) / 2;
|
||||
|
||||
fontSize *= factor;
|
||||
}
|
||||
|
|
|
@ -46,9 +46,9 @@ namespace Greenshot.Drawing {
|
|||
/// Description of Surface.
|
||||
/// </summary>
|
||||
public class Surface : Control, ISurface {
|
||||
private static ILog LOG = LogManager.GetLogger(typeof(Surface));
|
||||
public static int Count = 0;
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(Surface));
|
||||
public static int Count;
|
||||
private static readonly CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
|
||||
// Property to identify the Surface ID
|
||||
private Guid _uniqueId = Guid.NewGuid();
|
||||
|
@ -169,7 +169,7 @@ namespace Greenshot.Drawing {
|
|||
/// all selected elements, do not serialize
|
||||
/// </summary>
|
||||
[NonSerialized]
|
||||
private DrawableContainerList selectedElements;
|
||||
private readonly DrawableContainerList selectedElements;
|
||||
|
||||
/// <summary>
|
||||
/// the element we are drawing with, do not serialize
|
||||
|
@ -208,7 +208,7 @@ namespace Greenshot.Drawing {
|
|||
/// <summary>
|
||||
/// all stepLabels for the surface, needed with serialization
|
||||
/// </summary>
|
||||
private List<StepLabelContainer> _stepLabels = new List<StepLabelContainer>();
|
||||
private readonly List<StepLabelContainer> _stepLabels = new List<StepLabelContainer>();
|
||||
|
||||
public void AddStepLabel(StepLabelContainer stepLabel) {
|
||||
_stepLabels.Add(stepLabel);
|
||||
|
@ -225,7 +225,7 @@ namespace Greenshot.Drawing {
|
|||
public int CountStepLabels(IDrawableContainer stopAtContainer) {
|
||||
int number = 1;
|
||||
foreach (var possibleThis in _stepLabels) {
|
||||
if (possibleThis == stopAtContainer) {
|
||||
if (possibleThis.Equals(stopAtContainer)) {
|
||||
break;
|
||||
}
|
||||
if (IsOnSurface(possibleThis)) {
|
||||
|
@ -1037,7 +1037,10 @@ namespace Greenshot.Drawing {
|
|||
_drawingElement = _undrawnElement;
|
||||
// if a new element has been drawn, set location and register it
|
||||
if (_drawingElement != null) {
|
||||
_drawingElement.Status = _undrawnElement.DefaultEditMode;
|
||||
if (_undrawnElement != null)
|
||||
{
|
||||
_drawingElement.Status = _undrawnElement.DefaultEditMode;
|
||||
}
|
||||
_drawingElement.PropertyChanged += ElementPropertyChanged;
|
||||
if (!_drawingElement.HandleMouseDown(_mouseStart.X, _mouseStart.Y)) {
|
||||
_drawingElement.Left = _mouseStart.X;
|
||||
|
@ -1331,7 +1334,7 @@ namespace Greenshot.Drawing {
|
|||
/// <returns></returns>
|
||||
public bool HasSelectedElements {
|
||||
get {
|
||||
return (selectedElements != null && selectedElements.Count > 0);
|
||||
return selectedElements != null && selectedElements.Count > 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1387,6 +1390,10 @@ namespace Greenshot.Drawing {
|
|||
public void ConfirmSelectedConfirmableElements(bool confirm){
|
||||
// create new collection so that we can iterate safely (selectedElements might change due with confirm/cancel)
|
||||
List<IDrawableContainer> selectedDCs = new List<IDrawableContainer>(selectedElements);
|
||||
if (_cropContainer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (IDrawableContainer dc in selectedDCs){
|
||||
if (dc.Equals(_cropContainer)){
|
||||
DrawingMode = DrawingModes.None;
|
||||
|
@ -1397,6 +1404,7 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
_cropContainer.Dispose();
|
||||
_cropContainer = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1423,7 +1431,7 @@ namespace Greenshot.Drawing {
|
|||
if (dcs != null) {
|
||||
// Make element(s) only move 10,10 if the surface is the same
|
||||
Point moveOffset;
|
||||
bool isSameSurface = (dcs.ParentID == _uniqueId);
|
||||
bool isSameSurface = dcs.ParentID == _uniqueId;
|
||||
dcs.Parent = this;
|
||||
if (isSameSurface) {
|
||||
moveOffset = new Point(10, 10);
|
||||
|
|
|
@ -332,8 +332,8 @@ namespace Greenshot.Drawing {
|
|||
if (lineThickness <= 1) {
|
||||
lineWidth = 0;
|
||||
}
|
||||
_textBox.Width = absRectangle.Width - (2 * lineWidth) + correction;
|
||||
_textBox.Height = absRectangle.Height - (2 * lineWidth) + correction;
|
||||
_textBox.Width = absRectangle.Width - 2 * lineWidth + correction;
|
||||
_textBox.Height = absRectangle.Height - 2 * lineWidth + correction;
|
||||
}
|
||||
|
||||
public override void ApplyBounds(RectangleF newBounds) {
|
||||
|
@ -415,7 +415,7 @@ namespace Greenshot.Drawing {
|
|||
/// <param name="text"></param>
|
||||
/// <param name="font"></param>
|
||||
public static void DrawText(Graphics graphics, Rectangle drawingRectange, int lineThickness, Color fontColor, bool drawShadow, StringFormat stringFormat, string text, Font font) {
|
||||
int textOffset = (lineThickness > 0) ? (int)Math.Ceiling(lineThickness / 2d) : 0;
|
||||
int textOffset = lineThickness > 0 ? (int)Math.Ceiling(lineThickness / 2d) : 0;
|
||||
// draw shadow before anything else
|
||||
if (drawShadow) {
|
||||
int basealpha = 100;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue