diff --git a/Greenshot/Drawing/Adorners/MoveAdorner.cs b/Greenshot/Drawing/Adorners/MoveAdorner.cs new file mode 100644 index 000000000..78e00e2dd --- /dev/null +++ b/Greenshot/Drawing/Adorners/MoveAdorner.cs @@ -0,0 +1,165 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2015 Thomas Braun, Jens Klingen, Robin Krom + * + * For more information see: http://getgreenshot.org/ + * The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +using Greenshot.Helpers; +using Greenshot.Plugin.Drawing; +using Greenshot.Plugin.Drawing.Adorners; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Windows.Forms; + +namespace Greenshot.Drawing.Adorners +{ + /// + /// This is the adorner for the line based containers + /// + public class MoveAdorner : AbstractAdorner + { + private Rectangle _boundsBeforeResize = Rectangle.Empty; + private RectangleF _boundsAfterResize = RectangleF.Empty; + + public Positions Position { get; private set; } + + public MoveAdorner(IDrawableContainer owner, Positions position) : base(owner) + { + Position = position; + } + + /// + /// Returns the cursor for when the mouse is over the adorner + /// + public override Cursor Cursor + { + get + { + return Cursors.SizeAll; + } + } + + /// + /// Handle the mouse down + /// + /// + /// + public override void MouseDown(object sender, MouseEventArgs mouseEventArgs) + { + EditStatus = EditStatus.RESIZING; + _boundsBeforeResize = new Rectangle(Owner.Left, Owner.Top, Owner.Width, Owner.Height); + _boundsAfterResize = _boundsBeforeResize; + } + + /// + /// Handle the mouse move + /// + /// + /// + public override void MouseMove(object sender, MouseEventArgs mouseEventArgs) + { + if (EditStatus != EditStatus.RESIZING) + { + return; + } + Owner.Invalidate(); + Owner.MakeBoundsChangeUndoable(false); + + // reset "workbench" rectangle to current bounds + _boundsAfterResize.X = _boundsBeforeResize.X; + _boundsAfterResize.Y = _boundsBeforeResize.Y; + _boundsAfterResize.Width = _boundsBeforeResize.Width; + _boundsAfterResize.Height = _boundsBeforeResize.Height; + + // calculate scaled rectangle + ScaleHelper.Scale(ref _boundsAfterResize, Position, new PointF(mouseEventArgs.X, mouseEventArgs.Y), ScaleHelper.GetScaleOptions()); + + // apply scaled bounds to this DrawableContainer + Owner.ApplyBounds(_boundsAfterResize); + + Owner.Invalidate(); + } + + /// + /// Return the location of the adorner + /// + public override Point Location { + get + { + int x = 0,y = 0; + switch (Position) + { + case Positions.TopLeft: + x = Owner.Left; + y = Owner.Top; + break; + case Positions.BottomLeft: + x = Owner.Left; + y = Owner.Top + Owner.Height; + break; + case Positions.MiddleLeft: + x = Owner.Left; + y = Owner.Top + (Owner.Height / 2); + break; + case Positions.TopCenter: + x = Owner.Left + (Owner.Width / 2); + y = Owner.Top; + break; + case Positions.BottomCenter: + x = Owner.Left + (Owner.Width / 2); + y = Owner.Top + Owner.Height; + break; + case Positions.TopRight: + x = Owner.Left + Owner.Width; + y = Owner.Top; + break; + case Positions.BottomRight: + x = Owner.Left + Owner.Width; + y = Owner.Top + Owner.Height; + break; + case Positions.MiddleRight: + x = Owner.Left + Owner.Width; + y = Owner.Top + (Owner.Height / 2); + break; + } + return new Point(x, y); + } + } + + /// + /// Draw the adorner + /// + /// PaintEventArgs + public override void Paint(PaintEventArgs paintEventArgs) + { + Graphics targetGraphics = paintEventArgs.Graphics; + Rectangle clipRectangle = paintEventArgs.ClipRectangle; + + var bounds = Bounds; + GraphicsState state = targetGraphics.Save(); + + targetGraphics.SmoothingMode = SmoothingMode.None; + targetGraphics.CompositingMode = CompositingMode.SourceCopy; + targetGraphics.PixelOffsetMode = PixelOffsetMode.Half; + targetGraphics.InterpolationMode = InterpolationMode.NearestNeighbor; + + targetGraphics.FillRectangle(Brushes.Black, bounds.X, bounds.Y, bounds.Width , bounds.Height); + targetGraphics.Restore(state); + } + } +} diff --git a/Greenshot/Drawing/Adorners/GripperAdorner.cs b/Greenshot/Drawing/Adorners/ResizeAdorner.cs similarity index 93% rename from Greenshot/Drawing/Adorners/GripperAdorner.cs rename to Greenshot/Drawing/Adorners/ResizeAdorner.cs index a550f5195..da536b1f5 100644 --- a/Greenshot/Drawing/Adorners/GripperAdorner.cs +++ b/Greenshot/Drawing/Adorners/ResizeAdorner.cs @@ -31,14 +31,14 @@ namespace Greenshot.Drawing.Adorners /// /// This is the default "legacy" gripper adorner, not the one used for the tail in the speech-bubble /// - public class GripperAdorner : AbstractAdorner + public class ResizeAdorner : AbstractAdorner { private Rectangle _boundsBeforeResize = Rectangle.Empty; private RectangleF _boundsAfterResize = RectangleF.Empty; public Positions Position { get; private set; } - public GripperAdorner(IDrawableContainer owner, Positions position) : base(owner) + public ResizeAdorner(IDrawableContainer owner, Positions position) : base(owner) { Position = position; } @@ -101,8 +101,6 @@ namespace Greenshot.Drawing.Adorners Owner.Invalidate(); Owner.MakeBoundsChangeUndoable(false); - //SuspendLayout(); - // reset "workbench" rectangle to current bounds _boundsAfterResize.X = _boundsBeforeResize.X; _boundsAfterResize.Y = _boundsBeforeResize.Y; @@ -115,9 +113,6 @@ namespace Greenshot.Drawing.Adorners // apply scaled bounds to this DrawableContainer Owner.ApplyBounds(_boundsAfterResize); - //ResumeLayout(); - Owner.DoLayout(); - Owner.Invalidate(); } @@ -186,7 +181,6 @@ namespace Greenshot.Drawing.Adorners targetGraphics.FillRectangle(Brushes.Black, bounds.X, bounds.Y, bounds.Width , bounds.Height); targetGraphics.Restore(state); - } } } diff --git a/Greenshot/Drawing/Adorners/TargetAdorner.cs b/Greenshot/Drawing/Adorners/TargetAdorner.cs index a2817421e..27e499bac 100644 --- a/Greenshot/Drawing/Adorners/TargetAdorner.cs +++ b/Greenshot/Drawing/Adorners/TargetAdorner.cs @@ -20,7 +20,6 @@ */ using Greenshot.Plugin.Drawing; -using Greenshot.Plugin.Drawing.Adorners; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; diff --git a/Greenshot/Drawing/CropContainer.cs b/Greenshot/Drawing/CropContainer.cs index 676836f93..e1bf7a78a 100644 --- a/Greenshot/Drawing/CropContainer.cs +++ b/Greenshot/Drawing/CropContainer.cs @@ -20,6 +20,7 @@ */ using System.Drawing; +using System.Runtime.Serialization; using Greenshot.Drawing.Fields; using Greenshot.Helpers; using Greenshot.Plugin.Drawing; @@ -30,8 +31,19 @@ namespace Greenshot.Drawing { /// public class CropContainer : DrawableContainer { public CropContainer(Surface parent) : base(parent) { + Init(); } + protected override void OnDeserialized(StreamingContext streamingContext) + { + base.OnDeserialized(streamingContext); + Init(); + } + + private void Init() + { + CreateDefaultAdorners(); + } protected override void InitializeFields() { AddField(GetType(), FieldType.FLAGS, FieldType.Flag.CONFIRMABLE); } diff --git a/Greenshot/Drawing/CursorContainer.cs b/Greenshot/Drawing/CursorContainer.cs index 3911d5940..5d9d41b74 100644 --- a/Greenshot/Drawing/CursorContainer.cs +++ b/Greenshot/Drawing/CursorContainer.cs @@ -26,6 +26,7 @@ using System.Windows.Forms; using Greenshot.Plugin.Drawing; using System.Drawing.Drawing2D; using log4net; +using System.Runtime.Serialization; namespace Greenshot.Drawing { /// @@ -38,9 +39,21 @@ namespace Greenshot.Drawing { protected Cursor cursor; public CursorContainer(Surface parent) : base(parent) { + Init(); } - public CursorContainer(Surface parent, string filename) : base(parent) { + protected override void OnDeserialized(StreamingContext streamingContext) + { + base.OnDeserialized(streamingContext); + Init(); + } + + private void Init() + { + CreateDefaultAdorners(); + } + + public CursorContainer(Surface parent, string filename) : this(parent) { Load(filename); } diff --git a/Greenshot/Drawing/DrawableContainer.cs b/Greenshot/Drawing/DrawableContainer.cs index 56f84c25d..21971e5f7 100644 --- a/Greenshot/Drawing/DrawableContainer.cs +++ b/Greenshot/Drawing/DrawableContainer.cs @@ -35,6 +35,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; +using System.Runtime.Serialization; using System.Windows.Forms; namespace Greenshot.Drawing @@ -55,6 +56,20 @@ namespace Greenshot.Drawing private const int M21 = 2; private const int M22 = 3; + [OnDeserialized] + private void OnDeserializedInit(StreamingContext context) + { + _adorners = new List(); + OnDeserialized(context); + } + + /// + /// Override to implement your own deserialization logic, like initializing properties which are not serialized + /// + /// + protected virtual void OnDeserialized(StreamingContext streamingContext) + { + } protected EditStatus _defaultEditMode = EditStatus.DRAWING; public EditStatus DefaultEditMode { @@ -111,11 +126,8 @@ namespace Greenshot.Drawing set { SwitchParent((Surface)value); } } - private bool layoutSuspended; - [NonSerialized] private TargetAdorner _targetGripper; - public TargetAdorner TargetGripper { get { return _targetGripper; @@ -152,7 +164,6 @@ namespace Greenshot.Drawing return; } left = value; - DoLayout(); } } @@ -164,7 +175,6 @@ namespace Greenshot.Drawing return; } top = value; - DoLayout(); } } @@ -176,7 +186,6 @@ namespace Greenshot.Drawing return; } width = value; - DoLayout(); } } @@ -188,7 +197,6 @@ namespace Greenshot.Drawing return; } height = value; - DoLayout(); } } @@ -215,7 +223,15 @@ namespace Greenshot.Drawing /// /// List of available Adorners /// - public IList Adorners { get; } = new List(); + [NonSerialized] + private IList _adorners = new List(); + public IList Adorners + { + get + { + return _adorners; + } + } [NonSerialized] // will store current bounds of this DrawableContainer before starting a resize @@ -245,7 +261,6 @@ namespace Greenshot.Drawing public DrawableContainer(Surface parent) { InitializeFields(); _parent = parent; - InitControls(); } public void Add(IFilter filter) { @@ -319,12 +334,6 @@ namespace Greenshot.Drawing public virtual bool InitContent() { return true; } public virtual void OnDoubleClick() {} - - private void InitControls() { - InitGrippers(); - - DoLayout(); - } /// /// Initialize a target gripper @@ -334,29 +343,23 @@ namespace Greenshot.Drawing Adorners.Add(_targetGripper); } - protected void InitGrippers() { + /// + /// Create the default adorners for a rectangle based container + /// + protected void CreateDefaultAdorners() { + if (Adorners.Count > 0) + { + LOG.Warn("Adorners are already defined!"); + } // Create the GripperAdorners - Adorners.Add(new GripperAdorner(this, Positions.TopLeft)); - Adorners.Add(new GripperAdorner(this, Positions.TopCenter)); - Adorners.Add(new GripperAdorner(this, Positions.TopRight)); - Adorners.Add(new GripperAdorner(this, Positions.BottomLeft)); - Adorners.Add(new GripperAdorner(this, Positions.BottomCenter)); - Adorners.Add(new GripperAdorner(this, Positions.BottomRight)); - Adorners.Add(new GripperAdorner(this, Positions.MiddleLeft)); - Adorners.Add(new GripperAdorner(this, Positions.MiddleRight)); - } - - public void SuspendLayout() { - layoutSuspended = true; - } - - public void ResumeLayout() { - layoutSuspended = false; - DoLayout(); - } - - public virtual void DoLayout() { - + Adorners.Add(new ResizeAdorner(this, Positions.TopLeft)); + Adorners.Add(new ResizeAdorner(this, Positions.TopCenter)); + Adorners.Add(new ResizeAdorner(this, Positions.TopRight)); + Adorners.Add(new ResizeAdorner(this, Positions.BottomLeft)); + Adorners.Add(new ResizeAdorner(this, Positions.BottomCenter)); + Adorners.Add(new ResizeAdorner(this, Positions.BottomRight)); + Adorners.Add(new ResizeAdorner(this, Positions.MiddleLeft)); + Adorners.Add(new ResizeAdorner(this, Positions.MiddleRight)); } public bool hasFilters { @@ -414,10 +417,8 @@ namespace Greenshot.Drawing } public void ResizeTo(int width, int height, int anchorPosition) { - SuspendLayout(); Width = width; Height = height; - ResumeLayout(); } /// @@ -429,10 +430,8 @@ namespace Greenshot.Drawing } public void MoveBy(int dx, int dy) { - SuspendLayout(); Left += dx; Top += dy; - ResumeLayout(); } /// @@ -455,7 +454,6 @@ namespace Greenshot.Drawing /// true if the event is handled, false if the surface needs to handle it public virtual bool HandleMouseMove(int x, int y) { Invalidate(); - SuspendLayout(); // reset "workrbench" rectangle to current bounds _boundsAfterResize.X = _boundsBeforeResize.Left; @@ -468,7 +466,6 @@ namespace Greenshot.Drawing // apply scaled bounds to this DrawableContainer ApplyBounds(_boundsAfterResize); - ResumeLayout(); Invalidate(); return true; } @@ -482,6 +479,7 @@ namespace Greenshot.Drawing } protected virtual void SwitchParent(Surface newParent) { + _parent = newParent; foreach(IFilter filter in Filters) { filter.Parent = this; } @@ -576,7 +574,6 @@ namespace Greenshot.Drawing if (matrix == null) { return; } - SuspendLayout(); Point topLeft = new Point(Left, Top); Point bottomRight = new Point(Left + Width, Top + Height); Point[] points = new[] { topLeft, bottomRight }; @@ -586,7 +583,6 @@ namespace Greenshot.Drawing Top = points[0].Y; Width = points[1].X - points[0].X; Height = points[1].Y - points[0].Y; - ResumeLayout(); } protected virtual ScaleHelper.IDoubleProcessor GetAngleRoundProcessor() { diff --git a/Greenshot/Drawing/EllipseContainer.cs b/Greenshot/Drawing/EllipseContainer.cs index caf41824b..6873baf8a 100644 --- a/Greenshot/Drawing/EllipseContainer.cs +++ b/Greenshot/Drawing/EllipseContainer.cs @@ -33,6 +33,7 @@ namespace Greenshot.Drawing { [Serializable()] public class EllipseContainer : DrawableContainer { public EllipseContainer(Surface parent) : base(parent) { + CreateDefaultAdorners(); } protected override void InitializeFields() { diff --git a/Greenshot/Drawing/Fields/AbstractFieldHolder.cs b/Greenshot/Drawing/Fields/AbstractFieldHolder.cs index 0f8df4937..e1f91c6d4 100644 --- a/Greenshot/Drawing/Fields/AbstractFieldHolder.cs +++ b/Greenshot/Drawing/Fields/AbstractFieldHolder.cs @@ -55,7 +55,7 @@ namespace Greenshot.Drawing.Fields { public AbstractFieldHolder() {} [OnDeserialized] - private void OnDeserialized(StreamingContext context) { + private void OnFieldHolderDeserialized(StreamingContext context) { fieldsByType = new Dictionary(); // listen to changing properties foreach(Field field in fields) { diff --git a/Greenshot/Drawing/Fields/AbstractFieldHolderWithChildren.cs b/Greenshot/Drawing/Fields/AbstractFieldHolderWithChildren.cs index b919edd9b..1680e7c22 100644 --- a/Greenshot/Drawing/Fields/AbstractFieldHolderWithChildren.cs +++ b/Greenshot/Drawing/Fields/AbstractFieldHolderWithChildren.cs @@ -46,8 +46,8 @@ namespace Greenshot.Drawing.Fields { fieldChangedEventHandler = OnFieldChanged; } - [OnDeserialized()] - private void OnDeserialized(StreamingContext context) { + [OnDeserialized] + private void OnFieldHolderWithChildrenDeserialized(StreamingContext context) { // listen to changing properties foreach(IFieldHolder fieldHolder in Children) { fieldHolder.FieldChanged += fieldChangedEventHandler; diff --git a/Greenshot/Drawing/FilterContainer.cs b/Greenshot/Drawing/FilterContainer.cs index 630c5c35d..40bb93e95 100644 --- a/Greenshot/Drawing/FilterContainer.cs +++ b/Greenshot/Drawing/FilterContainer.cs @@ -24,6 +24,7 @@ using Greenshot.Drawing.Fields; using Greenshot.Helpers; using Greenshot.Plugin.Drawing; using System.Drawing.Drawing2D; +using System.Runtime.Serialization; namespace Greenshot.Drawing { /// @@ -40,6 +41,18 @@ namespace Greenshot.Drawing { } public FilterContainer(Surface parent) : base(parent) { + Init(); + } + + protected override void OnDeserialized(StreamingContext streamingContext) + { + base.OnDeserialized(streamingContext); + Init(); + } + + private void Init() + { + CreateDefaultAdorners(); } protected override void InitializeFields() { diff --git a/Greenshot/Drawing/FreehandContainer.cs b/Greenshot/Drawing/FreehandContainer.cs index 553d28294..b51299037 100644 --- a/Greenshot/Drawing/FreehandContainer.cs +++ b/Greenshot/Drawing/FreehandContainer.cs @@ -49,7 +49,6 @@ namespace Greenshot.Drawing { /// Constructor /// public FreehandContainer(Surface parent) : base(parent) { - Init(); Width = parent.Width; Height = parent.Height; Top = 0; @@ -61,11 +60,6 @@ namespace Greenshot.Drawing { AddField(GetType(), FieldType.LINE_COLOR, Color.Red); } - - protected void Init() { - // TODO: Remove grippers - } - public override void Transform(Matrix matrix) { Point[] points = capturePoints.ToArray(); @@ -75,11 +69,7 @@ namespace Greenshot.Drawing { RecalculatePath(); } - [OnDeserialized] - private void OnDeserialized(StreamingContext context) { - InitGrippers(); - DoLayout(); - Init(); + protected override void OnDeserialized(StreamingContext context) { RecalculatePath(); } diff --git a/Greenshot/Drawing/HighlightContainer.cs b/Greenshot/Drawing/HighlightContainer.cs index aec48208f..0cb2791a5 100644 --- a/Greenshot/Drawing/HighlightContainer.cs +++ b/Greenshot/Drawing/HighlightContainer.cs @@ -43,8 +43,8 @@ namespace Greenshot.Drawing { AddField(GetType(), FieldType.PREPARED_FILTER_HIGHLIGHT, PreparedFilter.TEXT_HIGHTLIGHT); } - [OnDeserialized] - private void OnDeserialized(StreamingContext context) { + protected override void OnDeserialized(StreamingContext context) + { Init(); } diff --git a/Greenshot/Drawing/IconContainer.cs b/Greenshot/Drawing/IconContainer.cs index 86b82a46f..623e10bfc 100644 --- a/Greenshot/Drawing/IconContainer.cs +++ b/Greenshot/Drawing/IconContainer.cs @@ -24,6 +24,7 @@ using System.IO; using Greenshot.Plugin.Drawing; using System.Drawing.Drawing2D; using log4net; +using System.Runtime.Serialization; namespace Greenshot.Drawing { /// @@ -36,6 +37,18 @@ namespace Greenshot.Drawing { protected Icon icon; public IconContainer(Surface parent) : base(parent) { + Init(); + } + + protected override void OnDeserialized(StreamingContext streamingContext) + { + base.OnDeserialized(streamingContext); + Init(); + } + + private void Init() + { + CreateDefaultAdorners(); } public IconContainer(Surface parent, string filename) : base(parent) { diff --git a/Greenshot/Drawing/ImageContainer.cs b/Greenshot/Drawing/ImageContainer.cs index b9f9c6dc3..7c023bf2f 100644 --- a/Greenshot/Drawing/ImageContainer.cs +++ b/Greenshot/Drawing/ImageContainer.cs @@ -27,6 +27,7 @@ using GreenshotPlugin.Core; using System.Drawing.Drawing2D; using Greenshot.Core; using log4net; +using System.Runtime.Serialization; namespace Greenshot.Drawing { /// @@ -58,6 +59,18 @@ namespace Greenshot.Drawing { public ImageContainer(Surface parent) : base(parent) { FieldChanged += BitmapContainer_OnFieldChanged; + Init(); + } + + protected override void OnDeserialized(StreamingContext streamingContext) + { + base.OnDeserialized(streamingContext); + Init(); + } + + private void Init() + { + CreateDefaultAdorners(); } protected override void InitializeFields() { diff --git a/Greenshot/Drawing/LineContainer.cs b/Greenshot/Drawing/LineContainer.cs index 37357b4fa..d42d2d5b9 100644 --- a/Greenshot/Drawing/LineContainer.cs +++ b/Greenshot/Drawing/LineContainer.cs @@ -26,6 +26,7 @@ using System.Runtime.Serialization; using Greenshot.Drawing.Fields; using Greenshot.Helpers; using Greenshot.Plugin.Drawing; +using Greenshot.Drawing.Adorners; namespace Greenshot.Drawing { /// @@ -45,15 +46,14 @@ namespace Greenshot.Drawing { AddField(GetType(), FieldType.SHADOW, true); } - [OnDeserialized()] - private void OnDeserialized(StreamingContext context) { - InitGrippers(); - DoLayout(); + protected override void OnDeserialized(StreamingContext context) + { Init(); } protected void Init() { - // TODO: Remove the unneeded grippers (1, 2, 3, 5, 6, 7) + Adorners.Add(new MoveAdorner(this, Positions.TopLeft)); + Adorners.Add(new MoveAdorner(this, Positions.BottomRight)); } public override void Draw(Graphics graphics, RenderMode rm) { @@ -109,8 +109,6 @@ namespace Greenshot.Drawing { protected override ScaleHelper.IDoubleProcessor GetAngleRoundProcessor() { return ScaleHelper.LineAngleRoundBehavior.Instance; - } - - + } } } diff --git a/Greenshot/Drawing/ObfuscateContainer.cs b/Greenshot/Drawing/ObfuscateContainer.cs index 80f395c31..032291527 100644 --- a/Greenshot/Drawing/ObfuscateContainer.cs +++ b/Greenshot/Drawing/ObfuscateContainer.cs @@ -37,15 +37,16 @@ namespace Greenshot.Drawing { base.InitializeFields(); AddField(GetType(), FieldType.PREPARED_FILTER_OBFUSCATE, PreparedFilter.PIXELIZE); } - - [OnDeserialized] - private void OnDeserialized(StreamingContext context) { + + protected override void OnDeserialized(StreamingContext context) + { Init(); } private void Init() { FieldChanged += ObfuscateContainer_OnFieldChanged; ConfigurePreparedFilters(); + CreateDefaultAdorners(); } protected void ObfuscateContainer_OnFieldChanged(object sender, FieldChangedEventArgs e) { diff --git a/Greenshot/Drawing/RectangleContainer.cs b/Greenshot/Drawing/RectangleContainer.cs index c235346c5..e81ec6624 100644 --- a/Greenshot/Drawing/RectangleContainer.cs +++ b/Greenshot/Drawing/RectangleContainer.cs @@ -25,6 +25,7 @@ using System.Drawing.Drawing2D; using Greenshot.Drawing.Fields; using Greenshot.Helpers; using Greenshot.Plugin.Drawing; +using System.Runtime.Serialization; namespace Greenshot.Drawing { /// @@ -34,6 +35,22 @@ namespace Greenshot.Drawing { public class RectangleContainer : DrawableContainer { public RectangleContainer(Surface parent) : base(parent) { + Init(); + } + + /// + /// Do some logic to make sure all field are initiated correctly + /// + /// StreamingContext + protected override void OnDeserialized(StreamingContext streamingContext) + { + base.OnDeserialized(streamingContext); + Init(); + } + + private void Init() + { + CreateDefaultAdorners(); } protected override void InitializeFields() { diff --git a/Greenshot/Drawing/SpeechbubbleContainer.cs b/Greenshot/Drawing/SpeechbubbleContainer.cs index 6b2f6e7ba..1f9360fc3 100644 --- a/Greenshot/Drawing/SpeechbubbleContainer.cs +++ b/Greenshot/Drawing/SpeechbubbleContainer.cs @@ -21,17 +21,15 @@ using Greenshot.Drawing.Fields; using Greenshot.Helpers; -using Greenshot.Plugin; using Greenshot.Plugin.Drawing; using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Text; using System.Runtime.Serialization; -using System.Windows.Forms; -using log4net; -namespace Greenshot.Drawing { +namespace Greenshot.Drawing +{ /// /// Description of SpeechbubbleContainer. /// @@ -59,8 +57,8 @@ namespace Greenshot.Drawing { /// Restore the target gripper /// /// - [OnDeserialized] - private void SetValuesOnDeserialized(StreamingContext context) { + protected override void OnDeserialized(StreamingContext context) + { InitTargetGripper(Color.Green, _storedTargetGripperLocation); } #endregion diff --git a/Greenshot/Drawing/StepLabelContainer.cs b/Greenshot/Drawing/StepLabelContainer.cs index 79583c5ab..6dff35dcf 100644 --- a/Greenshot/Drawing/StepLabelContainer.cs +++ b/Greenshot/Drawing/StepLabelContainer.cs @@ -45,6 +45,12 @@ namespace Greenshot.Drawing { public StepLabelContainer(Surface parent) : base(parent) { parent.AddStepLabel(this); InitContent(); + Init(); + } + + private void Init() + { + CreateDefaultAdorners(); } #region Number serializing @@ -75,8 +81,9 @@ namespace Greenshot.Drawing { /// Restore values that don't serialize /// /// - [OnDeserialized] - private void SetValuesOnDeserialized(StreamingContext context) { + protected override void OnDeserialized(StreamingContext context) + { + Init(); _stringFormat = new StringFormat(); _stringFormat.Alignment = StringAlignment.Center; _stringFormat.LineAlignment = StringAlignment.Center; diff --git a/Greenshot/Drawing/Surface.cs b/Greenshot/Drawing/Surface.cs index 71ebc154a..99f34824e 100644 --- a/Greenshot/Drawing/Surface.cs +++ b/Greenshot/Drawing/Surface.cs @@ -21,7 +21,6 @@ using Greenshot.Configuration; using Greenshot.Core; -using Greenshot.Drawing.Adorners; using Greenshot.Drawing.Fields; using Greenshot.Helpers; using Greenshot.IniFile; @@ -42,7 +41,8 @@ using System.IO; using System.Runtime.Serialization.Formatters.Binary; using System.Windows.Forms; -namespace Greenshot.Drawing { +namespace Greenshot.Drawing +{ /// /// Description of Surface. @@ -1300,8 +1300,10 @@ namespace Greenshot.Drawing { _elements.Draw(targetGraphics, null, RenderMode.EDIT, clipRectangle); } + // No clipping for the adorners + targetGraphics.ResetClip(); // Draw adorners last - foreach(var drawableContainer in selectedElements) + foreach (var drawableContainer in selectedElements) { foreach(var adorner in drawableContainer.Adorners) { diff --git a/Greenshot/Drawing/TextContainer.cs b/Greenshot/Drawing/TextContainer.cs index 110c40775..06ab4d5c4 100644 --- a/Greenshot/Drawing/TextContainer.cs +++ b/Greenshot/Drawing/TextContainer.cs @@ -98,9 +98,13 @@ namespace Greenshot.Drawing { AddField(GetType(), FieldType.TEXT_HORIZONTAL_ALIGNMENT, StringAlignment.Center); AddField(GetType(), FieldType.TEXT_VERTICAL_ALIGNMENT, StringAlignment.Center); } - - [OnDeserialized] - private void OnDeserialized(StreamingContext context) { + + /// + /// Do some logic to make sure all field are initiated correctly + /// + /// StreamingContext + protected override void OnDeserialized(StreamingContext streamingContext) { + base.OnDeserialized(streamingContext); Init(); } diff --git a/Greenshot/Greenshot.csproj b/Greenshot/Greenshot.csproj index d92465c41..0fc6043a0 100644 --- a/Greenshot/Greenshot.csproj +++ b/Greenshot/Greenshot.csproj @@ -76,7 +76,8 @@ - + + diff --git a/GreenshotPlugin/Interfaces/Drawing/Container.cs b/GreenshotPlugin/Interfaces/Drawing/Container.cs index cd96f774b..afae80489 100644 --- a/GreenshotPlugin/Interfaces/Drawing/Container.cs +++ b/GreenshotPlugin/Interfaces/Drawing/Container.cs @@ -26,6 +26,7 @@ using System.Windows.Forms; using System.ComponentModel; using System.Collections.Generic; using Greenshot.Plugin.Drawing.Adorners; +using System.Runtime.Serialization; namespace Greenshot.Plugin.Drawing { public enum RenderMode {EDIT, EXPORT}; @@ -77,8 +78,6 @@ namespace Greenshot.Plugin.Drawing { } void ApplyBounds(RectangleF newBounds); - - void DoLayout(); bool hasFilters { get;