mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 21:13:23 -07:00
Small fixes for serialization and the enumerator, still didn't fix the counting
This commit is contained in:
parent
515170e44b
commit
efb4807cd1
4 changed files with 86 additions and 51 deletions
|
@ -31,7 +31,7 @@ namespace Greenshot.Drawing.Fields {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Basic IFieldHolder implementation, providing access to a set of fields
|
/// Basic IFieldHolder implementation, providing access to a set of fields
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable()]
|
[Serializable]
|
||||||
public abstract class AbstractFieldHolder : IFieldHolder {
|
public abstract class AbstractFieldHolder : IFieldHolder {
|
||||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(AbstractFieldHolder));
|
private static readonly ILog LOG = LogManager.GetLogger(typeof(AbstractFieldHolder));
|
||||||
private static EditorConfiguration editorConfiguration = IniConfig.GetIniSection<EditorConfiguration>();
|
private static EditorConfiguration editorConfiguration = IniConfig.GetIniSection<EditorConfiguration>();
|
||||||
|
@ -54,9 +54,9 @@ namespace Greenshot.Drawing.Fields {
|
||||||
|
|
||||||
public AbstractFieldHolder() {}
|
public AbstractFieldHolder() {}
|
||||||
|
|
||||||
[OnDeserialized()]
|
[OnDeserialized]
|
||||||
private void OnDeserialized(StreamingContext context) {
|
private void OnDeserialized(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) {
|
||||||
field.PropertyChanged += delegate {
|
field.PropertyChanged += delegate {
|
||||||
|
|
|
@ -33,10 +33,9 @@ namespace Greenshot.Drawing {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Description of SpeechbubbleContainer.
|
/// Description of SpeechbubbleContainer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable()]
|
[Serializable]
|
||||||
public class SpeechbubbleContainer : TextContainer {
|
public class SpeechbubbleContainer : TextContainer {
|
||||||
public SpeechbubbleContainer(Surface parent)
|
public SpeechbubbleContainer(Surface parent) : base(parent) {
|
||||||
: base(parent) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -73,9 +72,11 @@ namespace Greenshot.Drawing {
|
||||||
|
|
||||||
public override Rectangle DrawingBounds {
|
public override Rectangle DrawingBounds {
|
||||||
get {
|
get {
|
||||||
|
// TODO: Use the normal bounds and extend with the TargetGripper
|
||||||
return new Rectangle(0, 0, _parent.Width, _parent.Height);
|
return new Rectangle(0, 0, _parent.Width, _parent.Height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw(Graphics graphics, RenderMode renderMode) {
|
public override void Draw(Graphics graphics, RenderMode renderMode) {
|
||||||
if (TargetGripper == null) {
|
if (TargetGripper == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -93,6 +94,10 @@ namespace Greenshot.Drawing {
|
||||||
bool lineVisible = (lineThickness > 0 && Colors.IsVisible(lineColor));
|
bool lineVisible = (lineThickness > 0 && Colors.IsVisible(lineColor));
|
||||||
Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
|
Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
|
||||||
|
|
||||||
|
if (Selected && renderMode == RenderMode.EDIT) {
|
||||||
|
DrawSelectionBorder(graphics, rect);
|
||||||
|
}
|
||||||
|
|
||||||
int tailAngle = 90 + (int)GeometryHelper.Angle2D(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2), TargetGripper.Left, TargetGripper.Top);
|
int tailAngle = 90 + (int)GeometryHelper.Angle2D(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2), TargetGripper.Left, TargetGripper.Top);
|
||||||
int tailLength = GeometryHelper.Distance2D(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2), TargetGripper.Left, TargetGripper.Top);
|
int tailLength = GeometryHelper.Distance2D(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2), TargetGripper.Left, TargetGripper.Top);
|
||||||
int tailWidth = (Math.Abs(rect.Width) + Math.Abs(rect.Height)) / 20;
|
int tailWidth = (Math.Abs(rect.Width) + Math.Abs(rect.Height)) / 20;
|
||||||
|
|
|
@ -28,6 +28,7 @@ using System.Collections.Generic;
|
||||||
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;
|
||||||
|
|
||||||
namespace Greenshot.Drawing {
|
namespace Greenshot.Drawing {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -39,15 +40,21 @@ namespace Greenshot.Drawing {
|
||||||
public class StepLabelContainer : DrawableContainer {
|
public class StepLabelContainer : DrawableContainer {
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
private StringFormat _stringFormat = new StringFormat();
|
private StringFormat _stringFormat = new StringFormat();
|
||||||
[NonSerialized]
|
|
||||||
private Font _font;
|
private readonly bool _drawAsRectangle = false;
|
||||||
private bool drawAsRectangle = false;
|
|
||||||
|
|
||||||
public StepLabelContainer(Surface parent) : base(parent) {
|
public StepLabelContainer(Surface parent) : base(parent) {
|
||||||
parent.AddStepLabel(this);
|
parent.AddStepLabel(this);
|
||||||
InitContent();
|
InitContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[OnDeserialized]
|
||||||
|
private void OnDeserialized(StreamingContext context) {
|
||||||
|
_stringFormat = new StringFormat();
|
||||||
|
_stringFormat.Alignment = StringAlignment.Center;
|
||||||
|
_stringFormat.LineAlignment = StringAlignment.Center;
|
||||||
|
}
|
||||||
|
|
||||||
public override Size DefaultSize {
|
public override Size DefaultSize {
|
||||||
get {
|
get {
|
||||||
return new Size(30, 30);
|
return new Size(30, 30);
|
||||||
|
@ -112,22 +119,23 @@ namespace Greenshot.Drawing {
|
||||||
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);
|
||||||
if (drawAsRectangle) {
|
if (_drawAsRectangle) {
|
||||||
RectangleContainer.DrawRectangle(rect, graphics, rm, 0, Color.Transparent, fillColor, false);
|
RectangleContainer.DrawRectangle(rect, graphics, rm, 0, Color.Transparent, fillColor, false);
|
||||||
} else {
|
} else {
|
||||||
EllipseContainer.DrawEllipse(rect, graphics, rm, 0, Color.Transparent, fillColor, false);
|
EllipseContainer.DrawEllipse(rect, graphics, rm, 0, Color.Transparent, fillColor, false);
|
||||||
}
|
}
|
||||||
using (FontFamily fam = new FontFamily(FontFamily.GenericSansSerif.Name)) {
|
using (FontFamily fam = new FontFamily(FontFamily.GenericSansSerif.Name)) {
|
||||||
float factor = (((float)rect.Width / DefaultSize.Width) + ((float)rect.Height / DefaultSize.Height)) / 2;
|
float factor = (((float)rect.Width / DefaultSize.Width) + ((float)rect.Height / DefaultSize.Height)) / 2;
|
||||||
_font = new Font(fam, 16 * factor, FontStyle.Bold, GraphicsUnit.Pixel);
|
using (Font _font = new Font(fam, 16 * factor, FontStyle.Bold, GraphicsUnit.Pixel)) {
|
||||||
TextContainer.DrawText(graphics, rect, 0, lineColor, false, _stringFormat, text, _font);
|
TextContainer.DrawText(graphics, rect, 0, lineColor, false, _stringFormat, text, _font);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool ClickableAt(int x, int y) {
|
public override bool ClickableAt(int x, int y) {
|
||||||
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);
|
||||||
if (drawAsRectangle) {
|
if (_drawAsRectangle) {
|
||||||
return RectangleContainer.RectangleClickableAt(rect, 0, fillColor, x, y);
|
return RectangleContainer.RectangleClickableAt(rect, 0, fillColor, x, y);
|
||||||
} else {
|
} else {
|
||||||
return EllipseContainer.EllipseClickableAt(rect, 0, fillColor, x, y);
|
return EllipseContainer.EllipseClickableAt(rect, 0, fillColor, x, y);
|
||||||
|
|
|
@ -38,16 +38,22 @@ namespace Greenshot.Drawing {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class TextContainer : RectangleContainer, ITextContainer {
|
public class TextContainer : RectangleContainer, ITextContainer {
|
||||||
|
[NonSerialized]
|
||||||
private bool fontInvalidated = true;
|
private bool fontInvalidated = true;
|
||||||
// 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
|
||||||
private bool makeUndoable;
|
private bool makeUndoable;
|
||||||
|
[NonSerialized]
|
||||||
private Font _font;
|
private Font _font;
|
||||||
public Font Font {
|
public Font Font {
|
||||||
get {
|
get {
|
||||||
return _font;
|
return _font;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[NonSerialized]
|
||||||
|
private TextBox _textBox;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The StringFormat object is not serializable!!
|
/// The StringFormat object is not serializable!!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -77,14 +83,9 @@ namespace Greenshot.Drawing {
|
||||||
OnPropertyChanged("Text");
|
OnPropertyChanged("Text");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[NonSerialized]
|
|
||||||
private TextBox textBox;
|
|
||||||
|
|
||||||
public TextContainer(Surface parent) : base(parent) {
|
public TextContainer(Surface parent) : base(parent) {
|
||||||
Init();
|
Init();
|
||||||
_stringFormat = new StringFormat();
|
|
||||||
_stringFormat.Trimming = StringTrimming.EllipsisWord;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void InitializeFields() {
|
protected override void InitializeFields() {
|
||||||
|
@ -102,7 +103,6 @@ namespace Greenshot.Drawing {
|
||||||
|
|
||||||
[OnDeserialized]
|
[OnDeserialized]
|
||||||
private void OnDeserialized(StreamingContext context) {
|
private void OnDeserialized(StreamingContext context) {
|
||||||
_stringFormat = new StringFormat();
|
|
||||||
Init();
|
Init();
|
||||||
UpdateFormat();
|
UpdateFormat();
|
||||||
}
|
}
|
||||||
|
@ -117,15 +117,18 @@ namespace Greenshot.Drawing {
|
||||||
_stringFormat.Dispose();
|
_stringFormat.Dispose();
|
||||||
_stringFormat = null;
|
_stringFormat = null;
|
||||||
}
|
}
|
||||||
if (textBox != null) {
|
if (_textBox != null) {
|
||||||
textBox.Dispose();
|
_textBox.Dispose();
|
||||||
textBox = null;
|
_textBox = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Init() {
|
private void Init() {
|
||||||
|
_stringFormat = new StringFormat();
|
||||||
|
_stringFormat.Trimming = StringTrimming.EllipsisWord;
|
||||||
|
fontInvalidated = true;
|
||||||
CreateTextBox();
|
CreateTextBox();
|
||||||
PropertyChanged += TextContainer_PropertyChanged;
|
PropertyChanged += TextContainer_PropertyChanged;
|
||||||
FieldChanged += TextContainer_FieldChanged;
|
FieldChanged += TextContainer_FieldChanged;
|
||||||
|
@ -141,23 +144,23 @@ namespace Greenshot.Drawing {
|
||||||
|
|
||||||
void TextContainer_PropertyChanged(object sender, PropertyChangedEventArgs e) {
|
void TextContainer_PropertyChanged(object sender, PropertyChangedEventArgs e) {
|
||||||
if (e.PropertyName.Equals("Selected")) {
|
if (e.PropertyName.Equals("Selected")) {
|
||||||
if (!Selected && textBox.Visible) {
|
if (!Selected && _textBox.Visible) {
|
||||||
HideTextBox();
|
HideTextBox();
|
||||||
} else if (Selected && Status==EditStatus.DRAWING) {
|
} else if (Selected && Status==EditStatus.DRAWING) {
|
||||||
ShowTextBox();
|
ShowTextBox();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (textBox.Visible) {
|
if (_textBox.Visible) {
|
||||||
UpdateTextBoxPosition();
|
UpdateTextBoxPosition();
|
||||||
UpdateTextBoxFormat();
|
UpdateTextBoxFormat();
|
||||||
textBox.Invalidate();
|
_textBox.Invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextContainer_FieldChanged(object sender, FieldChangedEventArgs e) {
|
void TextContainer_FieldChanged(object sender, FieldChangedEventArgs e) {
|
||||||
if (textBox.Visible) {
|
if (_textBox.Visible) {
|
||||||
UpdateTextBoxFormat();
|
UpdateTextBoxFormat();
|
||||||
textBox.Invalidate();
|
_textBox.Invalidate();
|
||||||
} else {
|
} else {
|
||||||
UpdateFormat();
|
UpdateFormat();
|
||||||
//Invalidate();
|
//Invalidate();
|
||||||
|
@ -169,29 +172,28 @@ namespace Greenshot.Drawing {
|
||||||
|
|
||||||
public override void OnDoubleClick() {
|
public override void OnDoubleClick() {
|
||||||
ShowTextBox();
|
ShowTextBox();
|
||||||
textBox.Focus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateTextBox() {
|
private void CreateTextBox() {
|
||||||
textBox = new TextBox();
|
_textBox = new TextBox();
|
||||||
|
|
||||||
textBox.ImeMode = ImeMode.On;
|
_textBox.ImeMode = ImeMode.On;
|
||||||
textBox.Multiline = true;
|
_textBox.Multiline = true;
|
||||||
textBox.AcceptsTab = true;
|
_textBox.AcceptsTab = true;
|
||||||
textBox.AcceptsReturn = true;
|
_textBox.AcceptsReturn = true;
|
||||||
textBox.DataBindings.Add("Text", this, "Text", false, DataSourceUpdateMode.OnPropertyChanged);
|
_textBox.DataBindings.Add("Text", this, "Text", false, DataSourceUpdateMode.OnPropertyChanged);
|
||||||
textBox.LostFocus += textBox_LostFocus;
|
_textBox.LostFocus += textBox_LostFocus;
|
||||||
textBox.KeyDown += textBox_KeyDown;
|
_textBox.KeyDown += textBox_KeyDown;
|
||||||
textBox.BorderStyle = BorderStyle.FixedSingle;
|
_textBox.BorderStyle = BorderStyle.FixedSingle;
|
||||||
textBox.Visible = false;
|
_textBox.Visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ShowTextBox() {
|
private void ShowTextBox() {
|
||||||
_parent.KeysLocked = true;
|
_parent.KeysLocked = true;
|
||||||
_parent.Controls.Add(textBox);
|
_parent.Controls.Add(_textBox);
|
||||||
EnsureTextBoxContrast();
|
EnsureTextBoxContrast();
|
||||||
textBox.Show();
|
_textBox.Show();
|
||||||
textBox.Focus();
|
_textBox.Focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -200,17 +202,17 @@ namespace Greenshot.Drawing {
|
||||||
private void EnsureTextBoxContrast() {
|
private void EnsureTextBoxContrast() {
|
||||||
Color lc = GetFieldValueAsColor(FieldType.LINE_COLOR);
|
Color lc = GetFieldValueAsColor(FieldType.LINE_COLOR);
|
||||||
if (lc.R > 203 && lc.G > 203 && lc.B > 203) {
|
if (lc.R > 203 && lc.G > 203 && lc.B > 203) {
|
||||||
textBox.BackColor = Color.FromArgb(51, 51, 51);
|
_textBox.BackColor = Color.FromArgb(51, 51, 51);
|
||||||
} else {
|
} else {
|
||||||
textBox.BackColor = Color.White;
|
_textBox.BackColor = Color.White;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HideTextBox() {
|
private void HideTextBox() {
|
||||||
_parent.Focus();
|
_parent.Focus();
|
||||||
textBox.Hide();
|
_textBox.Hide();
|
||||||
_parent.KeysLocked = false;
|
_parent.KeysLocked = false;
|
||||||
_parent.Controls.Remove(textBox);
|
_parent.Controls.Remove(_textBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void UpdateFormat() {
|
protected void UpdateFormat() {
|
||||||
|
@ -265,10 +267,10 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateTextBoxPosition() {
|
private void UpdateTextBoxPosition() {
|
||||||
textBox.Left = Left;
|
_textBox.Left = Left;
|
||||||
textBox.Top = Top;
|
_textBox.Top = Top;
|
||||||
textBox.Width = Width;
|
_textBox.Width = Width;
|
||||||
textBox.Height = Height;
|
_textBox.Height = Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ApplyBounds(RectangleF newBounds) {
|
public override void ApplyBounds(RectangleF newBounds) {
|
||||||
|
@ -279,8 +281,28 @@ namespace Greenshot.Drawing {
|
||||||
private void UpdateTextBoxFormat() {
|
private void UpdateTextBoxFormat() {
|
||||||
UpdateFormat();
|
UpdateFormat();
|
||||||
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
|
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
|
||||||
textBox.ForeColor = lineColor;
|
_textBox.ForeColor = lineColor;
|
||||||
textBox.Font = _font;
|
_textBox.Font = _font;
|
||||||
|
StringAlignment horizontalAlignment = (StringAlignment)GetFieldValue(FieldType.TEXT_HORIZONTAL_ALIGNMENT);
|
||||||
|
switch (horizontalAlignment) {
|
||||||
|
case StringAlignment.Center:
|
||||||
|
_textBox.TextAlign = HorizontalAlignment.Center;
|
||||||
|
break;
|
||||||
|
case StringAlignment.Far:
|
||||||
|
if (_textBox.RightToLeft != RightToLeft.Yes) {
|
||||||
|
_textBox.TextAlign = HorizontalAlignment.Right;
|
||||||
|
} else {
|
||||||
|
_textBox.TextAlign = HorizontalAlignment.Left;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case StringAlignment.Near:
|
||||||
|
if (_textBox.RightToLeft != RightToLeft.Yes) {
|
||||||
|
_textBox.TextAlign = HorizontalAlignment.Left;
|
||||||
|
} else {
|
||||||
|
_textBox.TextAlign = HorizontalAlignment.Right;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void textBox_KeyDown(object sender, KeyEventArgs e) {
|
void textBox_KeyDown(object sender, KeyEventArgs e) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue