Fixing some NPR Exceptions.

This commit is contained in:
Robin 2016-06-16 21:35:32 +02:00
commit 9fe00fdbdb
4 changed files with 24 additions and 43 deletions

View file

@ -50,24 +50,20 @@ namespace Greenshot.Drawing {
} }
public override void Invalidate() { public override void Invalidate() {
if (_parent == null) _parent?.Invalidate();
{
return;
}
_parent.Invalidate();
} }
/// <summary> /// <summary>
/// We need to override the DrawingBound, return a rectangle in the size of the image, to make sure this element is always draw /// We need to override the DrawingBound, return a rectangle in the size of the image, to make sure this element is always draw
/// (we create a transparent brown over the complete picture) /// (we create a transparent brown over the complete picture)
/// </summary> /// </summary>
public override Rectangle DrawingBounds { public override Rectangle DrawingBounds => new Rectangle(0,0,_parent?.Width??0, _parent?.Height ?? 0);
get {
return new Rectangle(0,0,_parent.Width, _parent.Height);
}
}
public override void Draw(Graphics g, RenderMode rm) { public override void Draw(Graphics g, RenderMode rm) {
if (_parent == null)
{
return;
}
using (Brush cropBrush = new SolidBrush(Color.FromArgb(100, 150, 150, 100))) { using (Brush cropBrush = new SolidBrush(Color.FromArgb(100, 150, 150, 100))) {
Rectangle cropRectangle = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height); Rectangle cropRectangle = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
Rectangle selectionRect = new Rectangle(cropRectangle.Left - 1, cropRectangle.Top - 1, cropRectangle.Width + 1, cropRectangle.Height + 1); Rectangle selectionRect = new Rectangle(cropRectangle.Left - 1, cropRectangle.Top - 1, cropRectangle.Width + 1, cropRectangle.Height + 1);

View file

@ -89,14 +89,7 @@ namespace Greenshot.Drawing
if (!disposing) { if (!disposing) {
return; return;
} }
if (_parent != null) _parent?.FieldAggregator?.UnbindElement(this);
{
FieldAggregator fieldAggregator = _parent.FieldAggregator;
if (fieldAggregator != null)
{
fieldAggregator.UnbindElement(this);
}
}
} }
~DrawableContainer() { ~DrawableContainer() {
@ -306,7 +299,7 @@ namespace Greenshot.Drawing
public virtual void Invalidate() { public virtual void Invalidate() {
if (Status != EditStatus.UNDRAWN) { if (Status != EditStatus.UNDRAWN) {
_parent.Invalidate(DrawingBounds); _parent?.Invalidate(DrawingBounds);
} }
} }
@ -491,15 +484,7 @@ namespace Greenshot.Drawing
{ {
return; return;
} }
if (_parent != null) _parent.FieldAggregator?.UnbindElement(this);
{
// Remove FieldAggregator
FieldAggregator fieldAggregator = _parent.FieldAggregator;
if (fieldAggregator != null)
{
fieldAggregator.UnbindElement(this);
}
}
_parent = newParent; _parent = newParent;
foreach(IFilter filter in Filters) { foreach(IFilter filter in Filters) {
@ -521,7 +506,7 @@ namespace Greenshot.Drawing
/// <param name="fieldToBeChanged">The field to be changed</param> /// <param name="fieldToBeChanged">The field to be changed</param>
/// <param name="newValue">The new value</param> /// <param name="newValue">The new value</param>
public virtual void BeforeFieldChange(IField fieldToBeChanged, object newValue) { public virtual void BeforeFieldChange(IField fieldToBeChanged, object newValue) {
_parent.MakeUndoable(new ChangeFieldHolderMemento(this, fieldToBeChanged), true); _parent?.MakeUndoable(new ChangeFieldHolderMemento(this, fieldToBeChanged), true);
Invalidate(); Invalidate();
} }

View file

@ -217,7 +217,7 @@ namespace Greenshot.Drawing {
int safetymargin = 10; 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); return new Rectangle(0, 0, _parent?.Width??0, _parent?.Height?? 0);
} }
} }

View file

@ -40,14 +40,12 @@ namespace Greenshot.Drawing {
public class TextContainer : RectangleContainer, ITextContainer { public class TextContainer : RectangleContainer, ITextContainer {
// If makeUndoable is true the next text-change will make the change undoable. // If makeUndoable is true the next text-change will make the change undoable.
// This is set to true AFTER the first change is made, as there is already a "add element" on the undo stack // This is set to true AFTER the first change is made, as there is already a "add element" on the undo stack
// Although the name is wrong, we can't change it due to file serialization
// ReSharper disable once InconsistentNaming
private bool makeUndoable; private bool makeUndoable;
[NonSerialized] [NonSerialized]
private Font _font; private Font _font;
public Font Font { public Font Font => _font;
get {
return _font;
}
}
[NonSerialized] [NonSerialized]
private TextBox _textBox; private TextBox _textBox;
@ -57,11 +55,10 @@ namespace Greenshot.Drawing {
/// </summary> /// </summary>
[NonSerialized] [NonSerialized]
StringFormat _stringFormat = new StringFormat(); StringFormat _stringFormat = new StringFormat();
public StringFormat StringFormat { public StringFormat StringFormat => _stringFormat;
get {
return _stringFormat; // Although the name is wrong, we can't change it due to file serialization
} // ReSharper disable once InconsistentNaming
}
private string text; private string text;
// there is a binding on the following property! // there is a binding on the following property!
public string Text { public string Text {
@ -168,7 +165,7 @@ namespace Greenshot.Drawing {
HideTextBox(); HideTextBox();
} else if (Selected && Status == EditStatus.DRAWING) { } else if (Selected && Status == EditStatus.DRAWING) {
ShowTextBox(); ShowTextBox();
} else if (Selected && Status == EditStatus.IDLE && _textBox.Visible) { } else if (_parent != null && Selected && Status == EditStatus.IDLE && _textBox.Visible) {
// Fix (workaround) for BUG-1698 // Fix (workaround) for BUG-1698
_parent.KeysLocked = true; _parent.KeysLocked = true;
} }
@ -221,8 +218,11 @@ namespace Greenshot.Drawing {
} }
private void ShowTextBox() { private void ShowTextBox() {
_parent.KeysLocked = true; if (_parent != null)
_parent.Controls.Add(_textBox); {
_parent.KeysLocked = true;
_parent.Controls.Add(_textBox);
}
EnsureTextBoxContrast(); EnsureTextBoxContrast();
_textBox.Show(); _textBox.Show();
_textBox.Focus(); _textBox.Focus();