Fixed serialization issues, and made sure the arrow / line have the right adorners.

This commit is contained in:
Robin 2016-05-23 16:43:10 +02:00
parent 5b2d5b1397
commit 9ab6bff116
23 changed files with 335 additions and 99 deletions

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
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
{
/// <summary>
/// This is the adorner for the line based containers
/// </summary>
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;
}
/// <summary>
/// Returns the cursor for when the mouse is over the adorner
/// </summary>
public override Cursor Cursor
{
get
{
return Cursors.SizeAll;
}
}
/// <summary>
/// Handle the mouse down
/// </summary>
/// <param name="sender"></param>
/// <param name="mouseEventArgs"></param>
public override void MouseDown(object sender, MouseEventArgs mouseEventArgs)
{
EditStatus = EditStatus.RESIZING;
_boundsBeforeResize = new Rectangle(Owner.Left, Owner.Top, Owner.Width, Owner.Height);
_boundsAfterResize = _boundsBeforeResize;
}
/// <summary>
/// Handle the mouse move
/// </summary>
/// <param name="sender"></param>
/// <param name="mouseEventArgs"></param>
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();
}
/// <summary>
/// Return the location of the adorner
/// </summary>
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);
}
}
/// <summary>
/// Draw the adorner
/// </summary>
/// <param name="paintEventArgs">PaintEventArgs</param>
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);
}
}
}

View file

@ -31,14 +31,14 @@ namespace Greenshot.Drawing.Adorners
/// <summary> /// <summary>
/// This is the default "legacy" gripper adorner, not the one used for the tail in the speech-bubble /// This is the default "legacy" gripper adorner, not the one used for the tail in the speech-bubble
/// </summary> /// </summary>
public class GripperAdorner : AbstractAdorner public class ResizeAdorner : AbstractAdorner
{ {
private Rectangle _boundsBeforeResize = Rectangle.Empty; private Rectangle _boundsBeforeResize = Rectangle.Empty;
private RectangleF _boundsAfterResize = RectangleF.Empty; private RectangleF _boundsAfterResize = RectangleF.Empty;
public Positions Position { get; private set; } public Positions Position { get; private set; }
public GripperAdorner(IDrawableContainer owner, Positions position) : base(owner) public ResizeAdorner(IDrawableContainer owner, Positions position) : base(owner)
{ {
Position = position; Position = position;
} }
@ -101,8 +101,6 @@ namespace Greenshot.Drawing.Adorners
Owner.Invalidate(); Owner.Invalidate();
Owner.MakeBoundsChangeUndoable(false); Owner.MakeBoundsChangeUndoable(false);
//SuspendLayout();
// reset "workbench" rectangle to current bounds // reset "workbench" rectangle to current bounds
_boundsAfterResize.X = _boundsBeforeResize.X; _boundsAfterResize.X = _boundsBeforeResize.X;
_boundsAfterResize.Y = _boundsBeforeResize.Y; _boundsAfterResize.Y = _boundsBeforeResize.Y;
@ -115,9 +113,6 @@ namespace Greenshot.Drawing.Adorners
// apply scaled bounds to this DrawableContainer // apply scaled bounds to this DrawableContainer
Owner.ApplyBounds(_boundsAfterResize); Owner.ApplyBounds(_boundsAfterResize);
//ResumeLayout();
Owner.DoLayout();
Owner.Invalidate(); Owner.Invalidate();
} }
@ -186,7 +181,6 @@ namespace Greenshot.Drawing.Adorners
targetGraphics.FillRectangle(Brushes.Black, bounds.X, bounds.Y, bounds.Width , bounds.Height); targetGraphics.FillRectangle(Brushes.Black, bounds.X, bounds.Y, bounds.Width , bounds.Height);
targetGraphics.Restore(state); targetGraphics.Restore(state);
} }
} }
} }

View file

@ -20,7 +20,6 @@
*/ */
using Greenshot.Plugin.Drawing; using Greenshot.Plugin.Drawing;
using Greenshot.Plugin.Drawing.Adorners;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Windows.Forms; using System.Windows.Forms;

View file

@ -20,6 +20,7 @@
*/ */
using System.Drawing; using System.Drawing;
using System.Runtime.Serialization;
using Greenshot.Drawing.Fields; using Greenshot.Drawing.Fields;
using Greenshot.Helpers; using Greenshot.Helpers;
using Greenshot.Plugin.Drawing; using Greenshot.Plugin.Drawing;
@ -30,8 +31,19 @@ namespace Greenshot.Drawing {
/// </summary> /// </summary>
public class CropContainer : DrawableContainer { public class CropContainer : DrawableContainer {
public CropContainer(Surface parent) : base(parent) { 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() { protected override void InitializeFields() {
AddField(GetType(), FieldType.FLAGS, FieldType.Flag.CONFIRMABLE); AddField(GetType(), FieldType.FLAGS, FieldType.Flag.CONFIRMABLE);
} }

View file

@ -26,6 +26,7 @@ using System.Windows.Forms;
using Greenshot.Plugin.Drawing; using Greenshot.Plugin.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using log4net; using log4net;
using System.Runtime.Serialization;
namespace Greenshot.Drawing { namespace Greenshot.Drawing {
/// <summary> /// <summary>
@ -38,9 +39,21 @@ namespace Greenshot.Drawing {
protected Cursor cursor; protected Cursor cursor;
public CursorContainer(Surface parent) : base(parent) { 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); Load(filename);
} }

View file

@ -35,6 +35,7 @@ using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Runtime.Serialization;
using System.Windows.Forms; using System.Windows.Forms;
namespace Greenshot.Drawing namespace Greenshot.Drawing
@ -55,6 +56,20 @@ namespace Greenshot.Drawing
private const int M21 = 2; private const int M21 = 2;
private const int M22 = 3; private const int M22 = 3;
[OnDeserialized]
private void OnDeserializedInit(StreamingContext context)
{
_adorners = new List<IAdorner>();
OnDeserialized(context);
}
/// <summary>
/// Override to implement your own deserialization logic, like initializing properties which are not serialized
/// </summary>
/// <param name="streamingContext"></param>
protected virtual void OnDeserialized(StreamingContext streamingContext)
{
}
protected EditStatus _defaultEditMode = EditStatus.DRAWING; protected EditStatus _defaultEditMode = EditStatus.DRAWING;
public EditStatus DefaultEditMode { public EditStatus DefaultEditMode {
@ -111,11 +126,8 @@ namespace Greenshot.Drawing
set { SwitchParent((Surface)value); } set { SwitchParent((Surface)value); }
} }
private bool layoutSuspended;
[NonSerialized] [NonSerialized]
private TargetAdorner _targetGripper; private TargetAdorner _targetGripper;
public TargetAdorner TargetGripper { public TargetAdorner TargetGripper {
get { get {
return _targetGripper; return _targetGripper;
@ -152,7 +164,6 @@ namespace Greenshot.Drawing
return; return;
} }
left = value; left = value;
DoLayout();
} }
} }
@ -164,7 +175,6 @@ namespace Greenshot.Drawing
return; return;
} }
top = value; top = value;
DoLayout();
} }
} }
@ -176,7 +186,6 @@ namespace Greenshot.Drawing
return; return;
} }
width = value; width = value;
DoLayout();
} }
} }
@ -188,7 +197,6 @@ namespace Greenshot.Drawing
return; return;
} }
height = value; height = value;
DoLayout();
} }
} }
@ -215,7 +223,15 @@ namespace Greenshot.Drawing
/// <summary> /// <summary>
/// List of available Adorners /// List of available Adorners
/// </summary> /// </summary>
public IList<IAdorner> Adorners { get; } = new List<IAdorner>(); [NonSerialized]
private IList<IAdorner> _adorners = new List<IAdorner>();
public IList<IAdorner> Adorners
{
get
{
return _adorners;
}
}
[NonSerialized] [NonSerialized]
// will store current bounds of this DrawableContainer before starting a resize // will store current bounds of this DrawableContainer before starting a resize
@ -245,7 +261,6 @@ namespace Greenshot.Drawing
public DrawableContainer(Surface parent) { public DrawableContainer(Surface parent) {
InitializeFields(); InitializeFields();
_parent = parent; _parent = parent;
InitControls();
} }
public void Add(IFilter filter) { public void Add(IFilter filter) {
@ -320,12 +335,6 @@ namespace Greenshot.Drawing
public virtual void OnDoubleClick() {} public virtual void OnDoubleClick() {}
private void InitControls() {
InitGrippers();
DoLayout();
}
/// <summary> /// <summary>
/// Initialize a target gripper /// Initialize a target gripper
/// </summary> /// </summary>
@ -334,29 +343,23 @@ namespace Greenshot.Drawing
Adorners.Add(_targetGripper); Adorners.Add(_targetGripper);
} }
protected void InitGrippers() { /// <summary>
/// Create the default adorners for a rectangle based container
/// </summary>
protected void CreateDefaultAdorners() {
if (Adorners.Count > 0)
{
LOG.Warn("Adorners are already defined!");
}
// Create the GripperAdorners // Create the GripperAdorners
Adorners.Add(new GripperAdorner(this, Positions.TopLeft)); Adorners.Add(new ResizeAdorner(this, Positions.TopLeft));
Adorners.Add(new GripperAdorner(this, Positions.TopCenter)); Adorners.Add(new ResizeAdorner(this, Positions.TopCenter));
Adorners.Add(new GripperAdorner(this, Positions.TopRight)); Adorners.Add(new ResizeAdorner(this, Positions.TopRight));
Adorners.Add(new GripperAdorner(this, Positions.BottomLeft)); Adorners.Add(new ResizeAdorner(this, Positions.BottomLeft));
Adorners.Add(new GripperAdorner(this, Positions.BottomCenter)); Adorners.Add(new ResizeAdorner(this, Positions.BottomCenter));
Adorners.Add(new GripperAdorner(this, Positions.BottomRight)); Adorners.Add(new ResizeAdorner(this, Positions.BottomRight));
Adorners.Add(new GripperAdorner(this, Positions.MiddleLeft)); Adorners.Add(new ResizeAdorner(this, Positions.MiddleLeft));
Adorners.Add(new GripperAdorner(this, Positions.MiddleRight)); Adorners.Add(new ResizeAdorner(this, Positions.MiddleRight));
}
public void SuspendLayout() {
layoutSuspended = true;
}
public void ResumeLayout() {
layoutSuspended = false;
DoLayout();
}
public virtual void DoLayout() {
} }
public bool hasFilters { public bool hasFilters {
@ -414,10 +417,8 @@ namespace Greenshot.Drawing
} }
public void ResizeTo(int width, int height, int anchorPosition) { public void ResizeTo(int width, int height, int anchorPosition) {
SuspendLayout();
Width = width; Width = width;
Height = height; Height = height;
ResumeLayout();
} }
/// <summary> /// <summary>
@ -429,10 +430,8 @@ namespace Greenshot.Drawing
} }
public void MoveBy(int dx, int dy) { public void MoveBy(int dx, int dy) {
SuspendLayout();
Left += dx; Left += dx;
Top += dy; Top += dy;
ResumeLayout();
} }
/// <summary> /// <summary>
@ -455,7 +454,6 @@ namespace Greenshot.Drawing
/// <returns>true if the event is handled, false if the surface needs to handle it</returns> /// <returns>true if the event is handled, false if the surface needs to handle it</returns>
public virtual bool HandleMouseMove(int x, int y) { public virtual bool HandleMouseMove(int x, int y) {
Invalidate(); Invalidate();
SuspendLayout();
// reset "workrbench" rectangle to current bounds // reset "workrbench" rectangle to current bounds
_boundsAfterResize.X = _boundsBeforeResize.Left; _boundsAfterResize.X = _boundsBeforeResize.Left;
@ -468,7 +466,6 @@ namespace Greenshot.Drawing
// apply scaled bounds to this DrawableContainer // apply scaled bounds to this DrawableContainer
ApplyBounds(_boundsAfterResize); ApplyBounds(_boundsAfterResize);
ResumeLayout();
Invalidate(); Invalidate();
return true; return true;
} }
@ -482,6 +479,7 @@ namespace Greenshot.Drawing
} }
protected virtual void SwitchParent(Surface newParent) { protected virtual void SwitchParent(Surface newParent) {
_parent = newParent;
foreach(IFilter filter in Filters) { foreach(IFilter filter in Filters) {
filter.Parent = this; filter.Parent = this;
} }
@ -576,7 +574,6 @@ namespace Greenshot.Drawing
if (matrix == null) { if (matrix == null) {
return; return;
} }
SuspendLayout();
Point topLeft = new Point(Left, Top); Point topLeft = new Point(Left, Top);
Point bottomRight = new Point(Left + Width, Top + Height); Point bottomRight = new Point(Left + Width, Top + Height);
Point[] points = new[] { topLeft, bottomRight }; Point[] points = new[] { topLeft, bottomRight };
@ -586,7 +583,6 @@ namespace Greenshot.Drawing
Top = points[0].Y; Top = points[0].Y;
Width = points[1].X - points[0].X; Width = points[1].X - points[0].X;
Height = points[1].Y - points[0].Y; Height = points[1].Y - points[0].Y;
ResumeLayout();
} }
protected virtual ScaleHelper.IDoubleProcessor GetAngleRoundProcessor() { protected virtual ScaleHelper.IDoubleProcessor GetAngleRoundProcessor() {

View file

@ -33,6 +33,7 @@ namespace Greenshot.Drawing {
[Serializable()] [Serializable()]
public class EllipseContainer : DrawableContainer { public class EllipseContainer : DrawableContainer {
public EllipseContainer(Surface parent) : base(parent) { public EllipseContainer(Surface parent) : base(parent) {
CreateDefaultAdorners();
} }
protected override void InitializeFields() { protected override void InitializeFields() {

View file

@ -55,7 +55,7 @@ namespace Greenshot.Drawing.Fields {
public AbstractFieldHolder() {} public AbstractFieldHolder() {}
[OnDeserialized] [OnDeserialized]
private void OnDeserialized(StreamingContext context) { private void OnFieldHolderDeserialized(StreamingContext context) {
fieldsByType = new Dictionary<FieldType, Field>(); fieldsByType = new Dictionary<FieldType, Field>();
// listen to changing properties // listen to changing properties
foreach(Field field in fields) { foreach(Field field in fields) {

View file

@ -46,8 +46,8 @@ namespace Greenshot.Drawing.Fields {
fieldChangedEventHandler = OnFieldChanged; fieldChangedEventHandler = OnFieldChanged;
} }
[OnDeserialized()] [OnDeserialized]
private void OnDeserialized(StreamingContext context) { private void OnFieldHolderWithChildrenDeserialized(StreamingContext context) {
// listen to changing properties // listen to changing properties
foreach(IFieldHolder fieldHolder in Children) { foreach(IFieldHolder fieldHolder in Children) {
fieldHolder.FieldChanged += fieldChangedEventHandler; fieldHolder.FieldChanged += fieldChangedEventHandler;

View file

@ -24,6 +24,7 @@ using Greenshot.Drawing.Fields;
using Greenshot.Helpers; using Greenshot.Helpers;
using Greenshot.Plugin.Drawing; using Greenshot.Plugin.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Runtime.Serialization;
namespace Greenshot.Drawing { namespace Greenshot.Drawing {
/// <summary> /// <summary>
@ -40,6 +41,18 @@ namespace Greenshot.Drawing {
} }
public FilterContainer(Surface parent) : base(parent) { 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() { protected override void InitializeFields() {

View file

@ -49,7 +49,6 @@ namespace Greenshot.Drawing {
/// Constructor /// Constructor
/// </summary> /// </summary>
public FreehandContainer(Surface parent) : base(parent) { public FreehandContainer(Surface parent) : base(parent) {
Init();
Width = parent.Width; Width = parent.Width;
Height = parent.Height; Height = parent.Height;
Top = 0; Top = 0;
@ -61,11 +60,6 @@ namespace Greenshot.Drawing {
AddField(GetType(), FieldType.LINE_COLOR, Color.Red); AddField(GetType(), FieldType.LINE_COLOR, Color.Red);
} }
protected void Init() {
// TODO: Remove grippers
}
public override void Transform(Matrix matrix) { public override void Transform(Matrix matrix) {
Point[] points = capturePoints.ToArray(); Point[] points = capturePoints.ToArray();
@ -75,11 +69,7 @@ namespace Greenshot.Drawing {
RecalculatePath(); RecalculatePath();
} }
[OnDeserialized] protected override void OnDeserialized(StreamingContext context) {
private void OnDeserialized(StreamingContext context) {
InitGrippers();
DoLayout();
Init();
RecalculatePath(); RecalculatePath();
} }

View file

@ -43,8 +43,8 @@ namespace Greenshot.Drawing {
AddField(GetType(), FieldType.PREPARED_FILTER_HIGHLIGHT, PreparedFilter.TEXT_HIGHTLIGHT); AddField(GetType(), FieldType.PREPARED_FILTER_HIGHLIGHT, PreparedFilter.TEXT_HIGHTLIGHT);
} }
[OnDeserialized] protected override void OnDeserialized(StreamingContext context)
private void OnDeserialized(StreamingContext context) { {
Init(); Init();
} }

View file

@ -24,6 +24,7 @@ using System.IO;
using Greenshot.Plugin.Drawing; using Greenshot.Plugin.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using log4net; using log4net;
using System.Runtime.Serialization;
namespace Greenshot.Drawing { namespace Greenshot.Drawing {
/// <summary> /// <summary>
@ -36,6 +37,18 @@ namespace Greenshot.Drawing {
protected Icon icon; protected Icon icon;
public IconContainer(Surface parent) : base(parent) { 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) { public IconContainer(Surface parent, string filename) : base(parent) {

View file

@ -27,6 +27,7 @@ using GreenshotPlugin.Core;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using Greenshot.Core; using Greenshot.Core;
using log4net; using log4net;
using System.Runtime.Serialization;
namespace Greenshot.Drawing { namespace Greenshot.Drawing {
/// <summary> /// <summary>
@ -58,6 +59,18 @@ namespace Greenshot.Drawing {
public ImageContainer(Surface parent) : base(parent) { public ImageContainer(Surface parent) : base(parent) {
FieldChanged += BitmapContainer_OnFieldChanged; FieldChanged += BitmapContainer_OnFieldChanged;
Init();
}
protected override void OnDeserialized(StreamingContext streamingContext)
{
base.OnDeserialized(streamingContext);
Init();
}
private void Init()
{
CreateDefaultAdorners();
} }
protected override void InitializeFields() { protected override void InitializeFields() {

View file

@ -26,6 +26,7 @@ using System.Runtime.Serialization;
using Greenshot.Drawing.Fields; using Greenshot.Drawing.Fields;
using Greenshot.Helpers; using Greenshot.Helpers;
using Greenshot.Plugin.Drawing; using Greenshot.Plugin.Drawing;
using Greenshot.Drawing.Adorners;
namespace Greenshot.Drawing { namespace Greenshot.Drawing {
/// <summary> /// <summary>
@ -45,15 +46,14 @@ namespace Greenshot.Drawing {
AddField(GetType(), FieldType.SHADOW, true); AddField(GetType(), FieldType.SHADOW, true);
} }
[OnDeserialized()] protected override void OnDeserialized(StreamingContext context)
private void OnDeserialized(StreamingContext context) { {
InitGrippers();
DoLayout();
Init(); Init();
} }
protected void 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) { public override void Draw(Graphics graphics, RenderMode rm) {
@ -110,7 +110,5 @@ namespace Greenshot.Drawing {
protected override ScaleHelper.IDoubleProcessor GetAngleRoundProcessor() { protected override ScaleHelper.IDoubleProcessor GetAngleRoundProcessor() {
return ScaleHelper.LineAngleRoundBehavior.Instance; return ScaleHelper.LineAngleRoundBehavior.Instance;
} }
} }
} }

View file

@ -38,14 +38,15 @@ namespace Greenshot.Drawing {
AddField(GetType(), FieldType.PREPARED_FILTER_OBFUSCATE, PreparedFilter.PIXELIZE); AddField(GetType(), FieldType.PREPARED_FILTER_OBFUSCATE, PreparedFilter.PIXELIZE);
} }
[OnDeserialized] protected override void OnDeserialized(StreamingContext context)
private void OnDeserialized(StreamingContext context) { {
Init(); Init();
} }
private void Init() { private void Init() {
FieldChanged += ObfuscateContainer_OnFieldChanged; FieldChanged += ObfuscateContainer_OnFieldChanged;
ConfigurePreparedFilters(); ConfigurePreparedFilters();
CreateDefaultAdorners();
} }
protected void ObfuscateContainer_OnFieldChanged(object sender, FieldChangedEventArgs e) { protected void ObfuscateContainer_OnFieldChanged(object sender, FieldChangedEventArgs e) {

View file

@ -25,6 +25,7 @@ using System.Drawing.Drawing2D;
using Greenshot.Drawing.Fields; using Greenshot.Drawing.Fields;
using Greenshot.Helpers; using Greenshot.Helpers;
using Greenshot.Plugin.Drawing; using Greenshot.Plugin.Drawing;
using System.Runtime.Serialization;
namespace Greenshot.Drawing { namespace Greenshot.Drawing {
/// <summary> /// <summary>
@ -34,6 +35,22 @@ namespace Greenshot.Drawing {
public class RectangleContainer : DrawableContainer { public class RectangleContainer : DrawableContainer {
public RectangleContainer(Surface parent) : base(parent) { public RectangleContainer(Surface parent) : base(parent) {
Init();
}
/// <summary>
/// Do some logic to make sure all field are initiated correctly
/// </summary>
/// <param name="streamingContext">StreamingContext</param>
protected override void OnDeserialized(StreamingContext streamingContext)
{
base.OnDeserialized(streamingContext);
Init();
}
private void Init()
{
CreateDefaultAdorners();
} }
protected override void InitializeFields() { protected override void InitializeFields() {

View file

@ -21,17 +21,15 @@
using Greenshot.Drawing.Fields; using Greenshot.Drawing.Fields;
using Greenshot.Helpers; using Greenshot.Helpers;
using Greenshot.Plugin;
using Greenshot.Plugin.Drawing; using Greenshot.Plugin.Drawing;
using System; using System;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Drawing.Text; using System.Drawing.Text;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using System.Windows.Forms;
using log4net;
namespace Greenshot.Drawing { namespace Greenshot.Drawing
{
/// <summary> /// <summary>
/// Description of SpeechbubbleContainer. /// Description of SpeechbubbleContainer.
/// </summary> /// </summary>
@ -59,8 +57,8 @@ namespace Greenshot.Drawing {
/// Restore the target gripper /// Restore the target gripper
/// </summary> /// </summary>
/// <param name="context"></param> /// <param name="context"></param>
[OnDeserialized] protected override void OnDeserialized(StreamingContext context)
private void SetValuesOnDeserialized(StreamingContext context) { {
InitTargetGripper(Color.Green, _storedTargetGripperLocation); InitTargetGripper(Color.Green, _storedTargetGripperLocation);
} }
#endregion #endregion

View file

@ -45,6 +45,12 @@ namespace Greenshot.Drawing {
public StepLabelContainer(Surface parent) : base(parent) { public StepLabelContainer(Surface parent) : base(parent) {
parent.AddStepLabel(this); parent.AddStepLabel(this);
InitContent(); InitContent();
Init();
}
private void Init()
{
CreateDefaultAdorners();
} }
#region Number serializing #region Number serializing
@ -75,8 +81,9 @@ namespace Greenshot.Drawing {
/// Restore values that don't serialize /// Restore values that don't serialize
/// </summary> /// </summary>
/// <param name="context"></param> /// <param name="context"></param>
[OnDeserialized] protected override void OnDeserialized(StreamingContext context)
private void SetValuesOnDeserialized(StreamingContext context) { {
Init();
_stringFormat = new StringFormat(); _stringFormat = new StringFormat();
_stringFormat.Alignment = StringAlignment.Center; _stringFormat.Alignment = StringAlignment.Center;
_stringFormat.LineAlignment = StringAlignment.Center; _stringFormat.LineAlignment = StringAlignment.Center;

View file

@ -21,7 +21,6 @@
using Greenshot.Configuration; using Greenshot.Configuration;
using Greenshot.Core; using Greenshot.Core;
using Greenshot.Drawing.Adorners;
using Greenshot.Drawing.Fields; using Greenshot.Drawing.Fields;
using Greenshot.Helpers; using Greenshot.Helpers;
using Greenshot.IniFile; using Greenshot.IniFile;
@ -42,7 +41,8 @@ using System.IO;
using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization.Formatters.Binary;
using System.Windows.Forms; using System.Windows.Forms;
namespace Greenshot.Drawing { namespace Greenshot.Drawing
{
/// <summary> /// <summary>
/// Description of Surface. /// Description of Surface.
@ -1300,8 +1300,10 @@ namespace Greenshot.Drawing {
_elements.Draw(targetGraphics, null, RenderMode.EDIT, clipRectangle); _elements.Draw(targetGraphics, null, RenderMode.EDIT, clipRectangle);
} }
// No clipping for the adorners
targetGraphics.ResetClip();
// Draw adorners last // Draw adorners last
foreach(var drawableContainer in selectedElements) foreach (var drawableContainer in selectedElements)
{ {
foreach(var adorner in drawableContainer.Adorners) foreach(var adorner in drawableContainer.Adorners)
{ {

View file

@ -99,8 +99,12 @@ namespace Greenshot.Drawing {
AddField(GetType(), FieldType.TEXT_VERTICAL_ALIGNMENT, StringAlignment.Center); AddField(GetType(), FieldType.TEXT_VERTICAL_ALIGNMENT, StringAlignment.Center);
} }
[OnDeserialized] /// <summary>
private void OnDeserialized(StreamingContext context) { /// Do some logic to make sure all field are initiated correctly
/// </summary>
/// <param name="streamingContext">StreamingContext</param>
protected override void OnDeserialized(StreamingContext streamingContext) {
base.OnDeserialized(streamingContext);
Init(); Init();
} }

View file

@ -76,7 +76,8 @@
<Compile Include="Destinations\PickerDestination.cs" /> <Compile Include="Destinations\PickerDestination.cs" />
<Compile Include="Destinations\PrinterDestination.cs" /> <Compile Include="Destinations\PrinterDestination.cs" />
<Compile Include="Drawing\Adorners\AbstractAdorner.cs" /> <Compile Include="Drawing\Adorners\AbstractAdorner.cs" />
<Compile Include="Drawing\Adorners\GripperAdorner.cs" /> <Compile Include="Drawing\Adorners\MoveAdorner.cs" />
<Compile Include="Drawing\Adorners\ResizeAdorner.cs" />
<Compile Include="Drawing\Adorners\TargetAdorner.cs" /> <Compile Include="Drawing\Adorners\TargetAdorner.cs" />
<Compile Include="Drawing\ArrowContainer.cs" /> <Compile Include="Drawing\ArrowContainer.cs" />
<Compile Include="Drawing\Positions.cs" /> <Compile Include="Drawing\Positions.cs" />

View file

@ -26,6 +26,7 @@ using System.Windows.Forms;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
using Greenshot.Plugin.Drawing.Adorners; using Greenshot.Plugin.Drawing.Adorners;
using System.Runtime.Serialization;
namespace Greenshot.Plugin.Drawing { namespace Greenshot.Plugin.Drawing {
public enum RenderMode {EDIT, EXPORT}; public enum RenderMode {EDIT, EXPORT};
@ -78,8 +79,6 @@ namespace Greenshot.Plugin.Drawing {
void ApplyBounds(RectangleF newBounds); void ApplyBounds(RectangleF newBounds);
void DoLayout();
bool hasFilters { bool hasFilters {
get; get;
} }