Fixed backwards compatibility with 1.1 for the save/load of the .greenshot format.

This commit is contained in:
RKrom 2014-06-17 10:29:27 +02:00
parent a91bfab790
commit b6a37aa48e
2 changed files with 45 additions and 45 deletions

View file

@ -46,7 +46,7 @@ namespace Greenshot.Drawing {
public abstract class DrawableContainer : AbstractFieldHolderWithChildren, IDrawableContainer { public abstract class DrawableContainer : AbstractFieldHolderWithChildren, IDrawableContainer {
private static readonly ILog LOG = LogManager.GetLogger(typeof(DrawableContainer)); private static readonly ILog LOG = LogManager.GetLogger(typeof(DrawableContainer));
protected static readonly EditorConfiguration EditorConfig = IniConfig.GetIniSection<EditorConfiguration>(); protected static readonly EditorConfiguration EditorConfig = IniConfig.GetIniSection<EditorConfiguration>();
private bool _isMadeUndoable; private bool isMadeUndoable;
private const int M11 = 0; private const int M11 = 0;
private const int M12 = 1; private const int M12 = 1;
private const int M21 = 2; private const int M21 = 2;
@ -119,7 +119,7 @@ namespace Greenshot.Drawing {
} }
[NonSerialized] [NonSerialized]
protected Gripper[] _grippers; protected Gripper[] _grippers;
private bool _layoutSuspended; private bool layoutSuspended;
[NonSerialized] [NonSerialized]
private Gripper _targetGripper; private Gripper _targetGripper;
@ -152,71 +152,71 @@ namespace Greenshot.Drawing {
} }
private int _left; private int left;
public int Left { public int Left {
get { return _left; } get { return left; }
set { set {
if (value == _left) { if (value == left) {
return; return;
} }
_left = value; left = value;
DoLayout(); DoLayout();
} }
} }
private int _top; private int top;
public int Top { public int Top {
get { return _top; } get { return top; }
set { set {
if (value == _top) { if (value == top) {
return; return;
} }
_top = value; top = value;
DoLayout(); DoLayout();
} }
} }
private int _width; private int width;
public int Width { public int Width {
get { return _width; } get { return width; }
set { set {
if (value == _width) { if (value == width) {
return; return;
} }
_width = value; width = value;
DoLayout(); DoLayout();
} }
} }
private int _height; private int height;
public int Height { public int Height {
get { return _height; } get { return height; }
set { set {
if (value == _height) { if (value == height) {
return; return;
} }
_height = value; height = value;
DoLayout(); DoLayout();
} }
} }
public Point Location { public Point Location {
get { get {
return new Point(_left, _top); return new Point(left, top);
} }
set { set {
_left = value.X; left = value.X;
_top = value.Y; top = value.Y;
} }
} }
public Size Size { public Size Size {
get { get {
return new Size(_width, _height); return new Size(width, height);
} }
set { set {
_width = value.Width; width = value.Width;
_height = value.Height; height = value.Height;
} }
} }
@ -265,7 +265,7 @@ namespace Greenshot.Drawing {
return (int)Math.Round(f); return (int)Math.Round(f);
} }
private bool _accountForShadowChange; private bool accountForShadowChange;
public virtual Rectangle DrawingBounds { public virtual Rectangle DrawingBounds {
get { get {
foreach(IFilter filter in Filters) { foreach(IFilter filter in Filters) {
@ -281,8 +281,8 @@ namespace Greenshot.Drawing {
int offset = lineThickness/2; int offset = lineThickness/2;
int shadow = 0; int shadow = 0;
if (_accountForShadowChange || (HasField(FieldType.SHADOW) && GetFieldValueAsBool(FieldType.SHADOW))){ if (accountForShadowChange || (HasField(FieldType.SHADOW) && GetFieldValueAsBool(FieldType.SHADOW))){
_accountForShadowChange = false; accountForShadowChange = false;
shadow += 10; shadow += 10;
} }
return new Rectangle(Bounds.Left-offset, Bounds.Top-offset, Bounds.Width+lineThickness+shadow, Bounds.Height+lineThickness+shadow); return new Rectangle(Bounds.Left-offset, Bounds.Top-offset, Bounds.Width+lineThickness+shadow, Bounds.Height+lineThickness+shadow);
@ -378,11 +378,11 @@ namespace Greenshot.Drawing {
} }
public void SuspendLayout() { public void SuspendLayout() {
_layoutSuspended = true; layoutSuspended = true;
} }
public void ResumeLayout() { public void ResumeLayout() {
_layoutSuspended = false; layoutSuspended = false;
DoLayout(); DoLayout();
} }
@ -390,7 +390,7 @@ namespace Greenshot.Drawing {
if (_grippers == null) { if (_grippers == null) {
return; return;
} }
if (!_layoutSuspended) { if (!layoutSuspended) {
int[] xChoords = {Left-2,Left+Width/2-2,Left+Width-2}; int[] xChoords = {Left-2,Left+Width/2-2,Left+Width-2};
int[] yChoords = {Top-2,Top+Height/2-2,Top+Height-2}; int[] yChoords = {Top-2,Top+Height/2-2,Top+Height-2};
@ -429,12 +429,12 @@ namespace Greenshot.Drawing {
Gripper originatingGripper = (Gripper)sender; Gripper originatingGripper = (Gripper)sender;
if (originatingGripper != _targetGripper) { if (originatingGripper != _targetGripper) {
Status = EditStatus.RESIZING; Status = EditStatus.RESIZING;
_boundsBeforeResize = new Rectangle(_left, _top, _width, _height); _boundsBeforeResize = new Rectangle(left, top, width, height);
_boundsAfterResize = new RectangleF(_boundsBeforeResize.Left, _boundsBeforeResize.Top, _boundsBeforeResize.Width, _boundsBeforeResize.Height); _boundsAfterResize = new RectangleF(_boundsBeforeResize.Left, _boundsBeforeResize.Top, _boundsBeforeResize.Width, _boundsBeforeResize.Height);
} else { } else {
Status = EditStatus.MOVING; Status = EditStatus.MOVING;
} }
_isMadeUndoable = false; isMadeUndoable = false;
} }
private void GripperMouseUp(object sender, MouseEventArgs e) { private void GripperMouseUp(object sender, MouseEventArgs e) {
@ -442,7 +442,7 @@ namespace Greenshot.Drawing {
if (originatingGripper != _targetGripper) { if (originatingGripper != _targetGripper) {
_boundsBeforeResize = Rectangle.Empty; _boundsBeforeResize = Rectangle.Empty;
_boundsAfterResize = RectangleF.Empty; _boundsAfterResize = RectangleF.Empty;
_isMadeUndoable = false; isMadeUndoable = false;
} }
Status = EditStatus.IDLE; Status = EditStatus.IDLE;
Invalidate(); Invalidate();
@ -456,9 +456,9 @@ namespace Greenshot.Drawing {
TargetGripperMove(absX, absY); TargetGripperMove(absX, absY);
} else if (Status.Equals(EditStatus.RESIZING)) { } else if (Status.Equals(EditStatus.RESIZING)) {
// check if we already made this undoable // check if we already made this undoable
if (!_isMadeUndoable) { if (!isMadeUndoable) {
// don't allow another undo until we are finished with this move // don't allow another undo until we are finished with this move
_isMadeUndoable = true; isMadeUndoable = true;
// Make undo-able // Make undo-able
MakeBoundsChangeUndoable(false); MakeBoundsChangeUndoable(false);
} }
@ -659,7 +659,7 @@ namespace Greenshot.Drawing {
bool ret = false; bool ret = false;
if (obj != null && GetType() == obj.GetType()) { if (obj != null && GetType() == obj.GetType()) {
DrawableContainer other = obj as DrawableContainer; DrawableContainer other = obj as DrawableContainer;
if (other != null && _left==other._left && _top==other._top && _width==other._width && _height==other._height) { if (other != null && left==other.left && top==other.top && width==other.width && height==other.height) {
ret = true; ret = true;
} }
} }
@ -667,7 +667,7 @@ namespace Greenshot.Drawing {
} }
public override int GetHashCode() { public override int GetHashCode() {
return _left.GetHashCode() ^ _top.GetHashCode() ^ _width.GetHashCode() ^ _height.GetHashCode() ^ GetFields().GetHashCode(); return left.GetHashCode() ^ top.GetHashCode() ^ width.GetHashCode() ^ height.GetHashCode() ^ GetFields().GetHashCode();
} }
protected void OnPropertyChanged(string propertyName) { protected void OnPropertyChanged(string propertyName) {
@ -696,7 +696,7 @@ namespace Greenshot.Drawing {
public void HandleFieldChanged(object sender, FieldChangedEventArgs e) { public void HandleFieldChanged(object sender, FieldChangedEventArgs e) {
LOG.DebugFormat("Field {0} changed", e.Field.FieldType); LOG.DebugFormat("Field {0} changed", e.Field.FieldType);
if (e.Field.FieldType == FieldType.SHADOW) { if (e.Field.FieldType == FieldType.SHADOW) {
_accountForShadowChange = true; accountForShadowChange = true;
} }
Invalidate(); Invalidate();
} }

View file

@ -64,22 +64,22 @@ namespace Greenshot.Drawing {
return _stringFormat; return _stringFormat;
} }
} }
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 {
get { return _text; } get { return text; }
set { set {
ChangeText(value, true); ChangeText(value, true);
} }
} }
internal void ChangeText(string newText, bool allowUndoable) { internal void ChangeText(string newText, bool allowUndoable) {
if ((_text == null && newText != null) || !_text.Equals(newText)) { if ((text == null && newText != null) || !text.Equals(newText)) {
if (makeUndoable && allowUndoable) { if (makeUndoable && allowUndoable) {
makeUndoable = false; makeUndoable = false;
_parent.MakeUndoable(new TextChangeMemento(this), false); _parent.MakeUndoable(new TextChangeMemento(this), false);
} }
_text = newText; text = newText;
OnPropertyChanged("Text"); OnPropertyChanged("Text");
} }
} }
@ -136,7 +136,7 @@ namespace Greenshot.Drawing {
public void FitToText() { public void FitToText() {
UpdateFormat(); UpdateFormat();
Size textSize = TextRenderer.MeasureText(_text, _font); Size textSize = TextRenderer.MeasureText(text, _font);
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS); int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
Width = textSize.Width + lineThickness; Width = textSize.Width + lineThickness;
Height = textSize.Height + lineThickness; Height = textSize.Height + lineThickness;
@ -334,7 +334,7 @@ namespace Greenshot.Drawing {
DrawSelectionBorder(graphics, rect); DrawSelectionBorder(graphics, rect);
} }
if (_text == null || _text.Length == 0 ) { if (text == null || text.Length == 0 ) {
return; return;
} }
@ -345,7 +345,7 @@ namespace Greenshot.Drawing {
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR); Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
bool drawShadow = shadow && (fillColor == Color.Transparent || fillColor == Color.Empty); bool drawShadow = shadow && (fillColor == Color.Transparent || fillColor == Color.Empty);
DrawText(graphics, rect, lineThickness, lineColor, drawShadow, _stringFormat, _text, _font); DrawText(graphics, rect, lineThickness, lineColor, drawShadow, _stringFormat, text, _font);
} }
/// <summary> /// <summary>