mirror of
https://github.com/greenshot/greenshot
synced 2025-07-16 10:03:44 -07:00
Fixed serialization issues with the StepLabelContainer and the SpeechbubbleContainer, they should now be in the correct shape/location when loading from the .greenshot file.
This commit is contained in:
parent
87406d90da
commit
fb993c2238
4 changed files with 213 additions and 159 deletions
|
@ -27,6 +27,7 @@ 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.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Greenshot.Drawing {
|
namespace Greenshot.Drawing {
|
||||||
|
@ -35,7 +36,34 @@ namespace Greenshot.Drawing {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class SpeechbubbleContainer : TextContainer {
|
public class SpeechbubbleContainer : TextContainer {
|
||||||
public SpeechbubbleContainer(Surface parent) : base(parent) {
|
|
||||||
|
#region TargetGripper serializing code
|
||||||
|
// Only used for serializing the TargetGripper location
|
||||||
|
private Point _storedTargetGripperLocation;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Store the current location of the target gripper
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context"></param>
|
||||||
|
[OnSerializing]
|
||||||
|
private void SetValuesOnSerializing(StreamingContext context) {
|
||||||
|
if (TargetGripper != null) {
|
||||||
|
_storedTargetGripperLocation = TargetGripper.Location;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Restore the target gripper
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context"></param>
|
||||||
|
[OnDeserialized]
|
||||||
|
private void SetValuesOnDeserialized(StreamingContext context) {
|
||||||
|
InitTargetGripper(Color.Green, _storedTargetGripperLocation);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public SpeechbubbleContainer(Surface parent)
|
||||||
|
: base(parent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -48,25 +48,52 @@ namespace Greenshot.Drawing {
|
||||||
InitContent();
|
InitContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Number serializing
|
||||||
|
// Used to store the number of this label, so when deserializing it can be placed back to the StepLabels list in the right location
|
||||||
|
private int _number;
|
||||||
|
public int Number {
|
||||||
|
get {
|
||||||
|
return _number;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
_number = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve the counter before serializing
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context"></param>
|
||||||
|
[OnSerializing]
|
||||||
|
private void SetValuesOnSerializing(StreamingContext context) {
|
||||||
|
if (Parent != null) {
|
||||||
|
Number = ((Surface)Parent).CountStepLabels(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Restore values that don't serialize
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context"></param>
|
||||||
[OnDeserialized]
|
[OnDeserialized]
|
||||||
private void OnDeserialized(StreamingContext context) {
|
private void SetValuesOnDeserialized(StreamingContext context) {
|
||||||
_stringFormat = new StringFormat();
|
_stringFormat = new StringFormat();
|
||||||
_stringFormat.Alignment = StringAlignment.Center;
|
_stringFormat.Alignment = StringAlignment.Center;
|
||||||
_stringFormat.LineAlignment = StringAlignment.Center;
|
_stringFormat.LineAlignment = StringAlignment.Center;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Make sure the StepLabel is addded to the parent after deserializing
|
/// Add the StepLabel to the parent
|
||||||
/// by removing it from the current parent and added it to the new
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="newParent"></param>
|
/// <param name="newParent"></param>
|
||||||
protected override void SwitchParent(Surface newParent) {
|
protected override void SwitchParent(Surface newParent) {
|
||||||
if (Parent != null) {
|
if (Parent != null) {
|
||||||
Parent.RemoveStepLabel(this);
|
((Surface)Parent).RemoveStepLabel(this);
|
||||||
}
|
}
|
||||||
base.SwitchParent(newParent);
|
base.SwitchParent(newParent);
|
||||||
if (Parent != null) {
|
if (newParent != null) {
|
||||||
Parent.AddStepLabel(this);
|
((Surface)Parent).AddStepLabel(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +134,7 @@ namespace Greenshot.Drawing {
|
||||||
/// Make sure this element is no longer referenced from the surface
|
/// Make sure this element is no longer referenced from the surface
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override void Dispose() {
|
public override void Dispose() {
|
||||||
Parent.RemoveStepLabel(this);
|
((Surface)Parent).RemoveStepLabel(this);
|
||||||
base.Dispose();
|
base.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +157,7 @@ namespace Greenshot.Drawing {
|
||||||
graphics.CompositingQuality = CompositingQuality.HighQuality;
|
graphics.CompositingQuality = CompositingQuality.HighQuality;
|
||||||
graphics.PixelOffsetMode = PixelOffsetMode.None;
|
graphics.PixelOffsetMode = PixelOffsetMode.None;
|
||||||
graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
|
graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
|
||||||
string text = Parent.CountStepLabels(this).ToString();
|
string text = ((Surface)Parent).CountStepLabels(this).ToString();
|
||||||
Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
|
Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
|
||||||
Color fillColor = GetFieldValueAsColor(FieldType.FILL_COLOR);
|
Color fillColor = GetFieldValueAsColor(FieldType.FILL_COLOR);
|
||||||
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
|
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
|
||||||
|
|
|
@ -208,24 +208,23 @@ namespace Greenshot.Drawing {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// all stepLabels for the surface, needed with serialization
|
/// all stepLabels for the surface, needed with serialization
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private List<IDrawableContainer> _stepLabels = new List<IDrawableContainer>();
|
private List<StepLabelContainer> _stepLabels = new List<StepLabelContainer>();
|
||||||
|
|
||||||
public void AddStepLabel(IDrawableContainer stepLabel) {
|
public void AddStepLabel(StepLabelContainer stepLabel) {
|
||||||
_stepLabels.Add(stepLabel);
|
_stepLabels.Add(stepLabel);
|
||||||
}
|
}
|
||||||
public void RemoveStepLabel(IDrawableContainer stepLabel) {
|
public void RemoveStepLabel(StepLabelContainer stepLabel) {
|
||||||
_stepLabels.Remove(stepLabel);
|
_stepLabels.Remove(stepLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Count all the steplabels in the surface, up to the supplied one
|
/// Count all the VISIBLE steplabels in the surface, up to the supplied one
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="stopAtContainer">can be null, if not the counting stops here</param>
|
/// <param name="stopAtContainer">can be null, if not the counting stops here</param>
|
||||||
/// <returns>number of steplabels before the supplied container</returns>
|
/// <returns>number of steplabels before the supplied container</returns>
|
||||||
public int CountStepLabels(IDrawableContainer stopAtContainer) {
|
public int CountStepLabels(IDrawableContainer stopAtContainer) {
|
||||||
int number = 1;
|
int number = 1;
|
||||||
foreach (var drawableContainer in _stepLabels) {
|
foreach (var possibleThis in _stepLabels) {
|
||||||
var possibleThis = (StepLabelContainer) drawableContainer;
|
|
||||||
if (possibleThis == stopAtContainer) {
|
if (possibleThis == stopAtContainer) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -631,6 +630,10 @@ namespace Greenshot.Drawing {
|
||||||
BinaryFormatter binaryRead = new BinaryFormatter();
|
BinaryFormatter binaryRead = new BinaryFormatter();
|
||||||
DrawableContainerList loadedElements = (DrawableContainerList) binaryRead.Deserialize(streamRead);
|
DrawableContainerList loadedElements = (DrawableContainerList) binaryRead.Deserialize(streamRead);
|
||||||
loadedElements.Parent = this;
|
loadedElements.Parent = this;
|
||||||
|
// Make sure the steplabels are sorted accoring to their number
|
||||||
|
_stepLabels.Sort(delegate(StepLabelContainer p1, StepLabelContainer p2) {
|
||||||
|
return p1.Number.CompareTo(p2.Number);
|
||||||
|
});
|
||||||
DeselectAllElements();
|
DeselectAllElements();
|
||||||
AddElements(loadedElements);
|
AddElements(loadedElements);
|
||||||
SelectElements(loadedElements);
|
SelectElements(loadedElements);
|
||||||
|
|
|
@ -198,9 +198,5 @@ namespace Greenshot.Plugin {
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddStepLabel(IDrawableContainer stepLabel);
|
|
||||||
void RemoveStepLabel(IDrawableContainer stepLabel);
|
|
||||||
int CountStepLabels(IDrawableContainer stopCountingOnStepLabel);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue