As 2.x takes longer as planned, I added the SpeechbubbleContainer and StepLabelContainer (Enumerable label) to the 1.2 branch. This code was stored somewhere on my hard-drive, is still experimental.

This commit is contained in:
RKrom 2014-05-23 15:49:14 +02:00
parent 01ce82dbeb
commit ff3f898f54
21 changed files with 648 additions and 166 deletions

View file

@ -36,6 +36,12 @@ namespace Greenshot.Drawing {
private static readonly AdjustableArrowCap ARROW_CAP = new AdjustableArrowCap(4, 6); private static readonly AdjustableArrowCap ARROW_CAP = new AdjustableArrowCap(4, 6);
public ArrowContainer(Surface parent) : base(parent) { public ArrowContainer(Surface parent) : base(parent) {
}
/// <summary>
/// Do not use the base, just override so we have our own defaults
/// </summary>
protected override void InitializeFields() {
AddField(GetType(), FieldType.ARROWHEADS, 2); AddField(GetType(), FieldType.ARROWHEADS, 2);
AddField(GetType(), FieldType.LINE_COLOR, Color.Red); AddField(GetType(), FieldType.LINE_COLOR, Color.Red);
AddField(GetType(), FieldType.FILL_COLOR, Color.Transparent); AddField(GetType(), FieldType.FILL_COLOR, Color.Transparent);

View file

@ -30,11 +30,14 @@ 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) {
}
protected override void InitializeFields() {
AddField(GetType(), FieldType.FLAGS, FieldType.Flag.CONFIRMABLE); AddField(GetType(), FieldType.FLAGS, FieldType.Flag.CONFIRMABLE);
} }
public override void Invalidate() { public override void Invalidate() {
parent.Invalidate(); _parent.Invalidate();
} }
/// <summary> /// <summary>
@ -43,7 +46,7 @@ namespace Greenshot.Drawing {
/// </summary> /// </summary>
public override Rectangle DrawingBounds { public override Rectangle DrawingBounds {
get { get {
return new Rectangle(0,0,parent.Width, parent.Height); return new Rectangle(0,0,_parent.Width, _parent.Height);
} }
} }
@ -55,13 +58,13 @@ namespace Greenshot.Drawing {
DrawSelectionBorder(g, selectionRect); DrawSelectionBorder(g, selectionRect);
// top // top
g.FillRectangle(cropBrush, new Rectangle(0, 0, parent.Width, cropRectangle.Top)); g.FillRectangle(cropBrush, new Rectangle(0, 0, _parent.Width, cropRectangle.Top));
// left // left
g.FillRectangle(cropBrush, new Rectangle(0, cropRectangle.Top, cropRectangle.Left, cropRectangle.Height)); g.FillRectangle(cropBrush, new Rectangle(0, cropRectangle.Top, cropRectangle.Left, cropRectangle.Height));
// right // right
g.FillRectangle(cropBrush, new Rectangle(cropRectangle.Left + cropRectangle.Width, cropRectangle.Top, parent.Width - (cropRectangle.Left + cropRectangle.Width), cropRectangle.Height)); g.FillRectangle(cropBrush, new Rectangle(cropRectangle.Left + cropRectangle.Width, cropRectangle.Top, _parent.Width - (cropRectangle.Left + cropRectangle.Width), cropRectangle.Height));
// bottom // bottom
g.FillRectangle(cropBrush, new Rectangle(0, cropRectangle.Top + cropRectangle.Height, parent.Width, parent.Height - (cropRectangle.Top + cropRectangle.Height))); g.FillRectangle(cropBrush, new Rectangle(0, cropRectangle.Top + cropRectangle.Height, _parent.Width, _parent.Height - (cropRectangle.Top + cropRectangle.Height)));
} }
} }

View file

@ -18,22 +18,22 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
using Greenshot.Configuration;
using Greenshot.Drawing.Fields;
using Greenshot.Drawing.Filters;
using Greenshot.Helpers;
using Greenshot.IniFile;
using Greenshot.Memento;
using Greenshot.Plugin;
using Greenshot.Plugin.Drawing;
using log4net;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Windows.Forms;
using Greenshot.Drawing.Fields;
using Greenshot.Drawing.Filters;
using Greenshot.Helpers;
using Greenshot.Plugin;
using Greenshot.Plugin.Drawing;
using Greenshot.Memento;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using Greenshot.Configuration; using System.Windows.Forms;
using Greenshot.IniFile;
using log4net;
namespace Greenshot.Drawing { namespace Greenshot.Drawing {
/// <summary> /// <summary>
@ -42,12 +42,19 @@ namespace Greenshot.Drawing {
/// Subclasses should fulfill INotifyPropertyChanged contract, i.e. call /// Subclasses should fulfill INotifyPropertyChanged contract, i.e. call
/// OnPropertyChanged whenever a public property has been changed. /// OnPropertyChanged whenever a public property has been changed.
/// </summary> /// </summary>
[Serializable()] [Serializable]
public abstract class DrawableContainer : AbstractFieldHolderWithChildren, INotifyPropertyChanged, IDrawableContainer { public abstract class DrawableContainer : AbstractFieldHolderWithChildren, INotifyPropertyChanged, 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 = false; private bool isMadeUndoable = false;
protected EditStatus _defaultEditMode = EditStatus.DRAWING;
public EditStatus DefaultEditMode {
get {
return _defaultEditMode;
}
}
public virtual void Dispose() { public virtual void Dispose() {
Dispose(true); Dispose(true);
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
@ -55,17 +62,17 @@ namespace Greenshot.Drawing {
protected virtual void Dispose(bool disposing) { protected virtual void Dispose(bool disposing) {
if (disposing) { if (disposing) {
if (grippers != null) { if (_grippers != null) {
for (int i = 0; i < grippers.Length; i++) { for (int i = 0; i < _grippers.Length; i++) {
if (grippers[i] != null) { if (_grippers[i] != null) {
grippers[i].Dispose(); _grippers[i].Dispose();
grippers[i] = null; _grippers[i] = null;
} }
} }
grippers = null; _grippers = null;
} }
FieldAggregator aggProps = parent.FieldAggregator; FieldAggregator aggProps = _parent.FieldAggregator;
aggProps.UnbindElement(this); aggProps.UnbindElement(this);
} }
} }
@ -94,33 +101,42 @@ namespace Greenshot.Drawing {
} }
[NonSerialized] [NonSerialized]
internal Surface parent; internal Surface _parent;
public ISurface Parent { public ISurface Parent {
get { return parent; } get { return _parent; }
set { SwitchParent((Surface)value); } set { SwitchParent((Surface)value); }
} }
[NonSerialized] [NonSerialized]
protected Gripper[] grippers; protected Gripper[] _grippers;
private bool layoutSuspended = false; private bool layoutSuspended = false;
[NonSerialized] [NonSerialized]
private bool selected = false; private Gripper _targetGripper;
public Gripper TargetGripper {
get {
return _targetGripper;
}
}
[NonSerialized]
private bool _selected = false;
public bool Selected { public bool Selected {
get {return selected;} get {return _selected;}
set { set {
selected = value; _selected = value;
OnPropertyChanged("Selected"); OnPropertyChanged("Selected");
} }
} }
[NonSerialized] [NonSerialized]
private EditStatus status = EditStatus.UNDRAWN; private EditStatus _status = EditStatus.UNDRAWN;
public EditStatus Status { public EditStatus Status {
get { get {
return status; return _status;
} }
set { set {
status = value; _status = value;
} }
} }
@ -211,7 +227,8 @@ namespace Greenshot.Drawing {
} }
public DrawableContainer(Surface parent) { public DrawableContainer(Surface parent) {
this.parent = parent; InitializeFields();
this._parent = parent;
InitControls(); InitControls();
} }
@ -240,7 +257,7 @@ namespace Greenshot.Drawing {
get { get {
foreach(IFilter filter in Filters) { foreach(IFilter filter in Filters) {
if (filter.Invert) { if (filter.Invert) {
return new Rectangle(Point.Empty, parent.Image.Size); return new Rectangle(Point.Empty, _parent.Image.Size);
} }
} }
// Take a base safetymargin // Take a base safetymargin
@ -260,7 +277,7 @@ namespace Greenshot.Drawing {
} }
public virtual void Invalidate() { public virtual void Invalidate() {
parent.Invalidate(DrawingBounds); _parent.Invalidate(DrawingBounds);
} }
public void AlignToParent(HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment) { public void AlignToParent(HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment) {
@ -270,20 +287,20 @@ namespace Greenshot.Drawing {
Left = lineThickness/2; Left = lineThickness/2;
} }
if (horizontalAlignment == HorizontalAlignment.Right) { if (horizontalAlignment == HorizontalAlignment.Right) {
Left = parent.Width - Width - lineThickness/2; Left = _parent.Width - Width - lineThickness/2;
} }
if (horizontalAlignment == HorizontalAlignment.Center) { if (horizontalAlignment == HorizontalAlignment.Center) {
Left = (parent.Width / 2) - (Width / 2) - lineThickness/2; Left = (_parent.Width / 2) - (Width / 2) - lineThickness/2;
} }
if (verticalAlignment == VerticalAlignment.TOP) { if (verticalAlignment == VerticalAlignment.TOP) {
Top = lineThickness/2; Top = lineThickness/2;
} }
if (verticalAlignment == VerticalAlignment.BOTTOM) { if (verticalAlignment == VerticalAlignment.BOTTOM) {
Top = parent.Height - Height - lineThickness/2; Top = _parent.Height - Height - lineThickness/2;
} }
if (verticalAlignment == VerticalAlignment.CENTER) { if (verticalAlignment == VerticalAlignment.CENTER) {
Top = (parent.Height / 2) - (Height / 2) - lineThickness/2; Top = (_parent.Height / 2) - (Height / 2) - lineThickness/2;
} }
} }
@ -296,24 +313,54 @@ namespace Greenshot.Drawing {
DoLayout(); DoLayout();
} }
protected void InitGrippers() { /// <summary>
grippers = new Gripper[8]; /// Should be overridden to handle gripper moves on the "TargetGripper"
for(int i=0; i<grippers.Length; i++) { /// </summary>
grippers[i] = new Gripper(); /// <param name="newX"></param>
grippers[i].Position = i; /// <param name="newY"></param>
grippers[i].MouseDown += gripperMouseDown; protected virtual void TargetGripperMove(int newX, int newY) {
grippers[i].MouseUp += gripperMouseUp; _targetGripper.Left = newX;
grippers[i].MouseMove += gripperMouseMove; _targetGripper.Top = newY;
grippers[i].Visible = false; }
grippers[i].Parent = parent;
/// <summary>
/// Initialize a target gripper
/// </summary>
protected void InitTargetGripper(Color gripperColor, Point location) {
_targetGripper = new Gripper {
Cursor = Cursors.SizeAll,
BackColor = gripperColor,
Visible = false,
Parent = _parent,
Location = location
};
_targetGripper.MouseDown += gripperMouseDown;
_targetGripper.MouseUp += gripperMouseUp;
_targetGripper.MouseMove += gripperMouseMove;
if (_parent != null) {
_parent.Controls.Add(_targetGripper); // otherwise we'll attach them in switchParent
} }
grippers[Gripper.POSITION_TOP_CENTER].Cursor = Cursors.SizeNS; }
grippers[Gripper.POSITION_MIDDLE_RIGHT].Cursor = Cursors.SizeWE;
grippers[Gripper.POSITION_BOTTOM_CENTER].Cursor = Cursors.SizeNS; protected void InitGrippers() {
grippers[Gripper.POSITION_MIDDLE_LEFT].Cursor = Cursors.SizeWE;
if (parent != null) { _grippers = new Gripper[8];
parent.Controls.AddRange(grippers); // otherwise we'll attach them in switchParent for(int i=0; i<_grippers.Length; i++) {
_grippers[i] = new Gripper();
_grippers[i].Position = i;
_grippers[i].MouseDown += gripperMouseDown;
_grippers[i].MouseUp += gripperMouseUp;
_grippers[i].MouseMove += gripperMouseMove;
_grippers[i].Visible = false;
_grippers[i].Parent = _parent;
}
_grippers[Gripper.POSITION_TOP_CENTER].Cursor = Cursors.SizeNS;
_grippers[Gripper.POSITION_MIDDLE_RIGHT].Cursor = Cursors.SizeWE;
_grippers[Gripper.POSITION_BOTTOM_CENTER].Cursor = Cursors.SizeNS;
_grippers[Gripper.POSITION_MIDDLE_LEFT].Cursor = Cursors.SizeWE;
if (_parent != null) {
_parent.Controls.AddRange(_grippers); // otherwise we'll attach them in switchParent
} }
} }
@ -327,40 +374,40 @@ namespace Greenshot.Drawing {
} }
protected virtual void DoLayout() { protected virtual void DoLayout() {
if (grippers == null) { if (_grippers == null) {
return; return;
} }
if (!layoutSuspended) { if (!layoutSuspended) {
int[] xChoords = new int[]{Left-2,Left+Width/2-2,Left+Width-2}; int[] xChoords = new int[]{Left-2,Left+Width/2-2,Left+Width-2};
int[] yChoords = new int[]{Top-2,Top+Height/2-2,Top+Height-2}; int[] yChoords = new int[]{Top-2,Top+Height/2-2,Top+Height-2};
grippers[Gripper.POSITION_TOP_LEFT].Left = xChoords[0]; grippers[Gripper.POSITION_TOP_LEFT].Top = yChoords[0]; _grippers[Gripper.POSITION_TOP_LEFT].Left = xChoords[0]; _grippers[Gripper.POSITION_TOP_LEFT].Top = yChoords[0];
grippers[Gripper.POSITION_TOP_CENTER].Left = xChoords[1]; grippers[Gripper.POSITION_TOP_CENTER].Top = yChoords[0]; _grippers[Gripper.POSITION_TOP_CENTER].Left = xChoords[1]; _grippers[Gripper.POSITION_TOP_CENTER].Top = yChoords[0];
grippers[Gripper.POSITION_TOP_RIGHT].Left = xChoords[2]; grippers[Gripper.POSITION_TOP_RIGHT].Top = yChoords[0]; _grippers[Gripper.POSITION_TOP_RIGHT].Left = xChoords[2]; _grippers[Gripper.POSITION_TOP_RIGHT].Top = yChoords[0];
grippers[Gripper.POSITION_MIDDLE_RIGHT].Left = xChoords[2]; grippers[Gripper.POSITION_MIDDLE_RIGHT].Top = yChoords[1]; _grippers[Gripper.POSITION_MIDDLE_RIGHT].Left = xChoords[2]; _grippers[Gripper.POSITION_MIDDLE_RIGHT].Top = yChoords[1];
grippers[Gripper.POSITION_BOTTOM_RIGHT].Left = xChoords[2]; grippers[Gripper.POSITION_BOTTOM_RIGHT].Top = yChoords[2]; _grippers[Gripper.POSITION_BOTTOM_RIGHT].Left = xChoords[2]; _grippers[Gripper.POSITION_BOTTOM_RIGHT].Top = yChoords[2];
grippers[Gripper.POSITION_BOTTOM_CENTER].Left = xChoords[1]; grippers[Gripper.POSITION_BOTTOM_CENTER].Top = yChoords[2]; _grippers[Gripper.POSITION_BOTTOM_CENTER].Left = xChoords[1]; _grippers[Gripper.POSITION_BOTTOM_CENTER].Top = yChoords[2];
grippers[Gripper.POSITION_BOTTOM_LEFT].Left = xChoords[0]; grippers[Gripper.POSITION_BOTTOM_LEFT].Top = yChoords[2]; _grippers[Gripper.POSITION_BOTTOM_LEFT].Left = xChoords[0]; _grippers[Gripper.POSITION_BOTTOM_LEFT].Top = yChoords[2];
grippers[Gripper.POSITION_MIDDLE_LEFT].Left = xChoords[0]; grippers[Gripper.POSITION_MIDDLE_LEFT].Top = yChoords[1]; _grippers[Gripper.POSITION_MIDDLE_LEFT].Left = xChoords[0]; _grippers[Gripper.POSITION_MIDDLE_LEFT].Top = yChoords[1];
if((grippers[Gripper.POSITION_TOP_LEFT].Left < grippers[Gripper.POSITION_BOTTOM_RIGHT].Left && grippers[Gripper.POSITION_TOP_LEFT].Top < grippers[Gripper.POSITION_BOTTOM_RIGHT].Top) || if((_grippers[Gripper.POSITION_TOP_LEFT].Left < _grippers[Gripper.POSITION_BOTTOM_RIGHT].Left && _grippers[Gripper.POSITION_TOP_LEFT].Top < _grippers[Gripper.POSITION_BOTTOM_RIGHT].Top) ||
grippers[Gripper.POSITION_TOP_LEFT].Left > grippers[Gripper.POSITION_BOTTOM_RIGHT].Left && grippers[Gripper.POSITION_TOP_LEFT].Top > grippers[Gripper.POSITION_BOTTOM_RIGHT].Top) { _grippers[Gripper.POSITION_TOP_LEFT].Left > _grippers[Gripper.POSITION_BOTTOM_RIGHT].Left && _grippers[Gripper.POSITION_TOP_LEFT].Top > _grippers[Gripper.POSITION_BOTTOM_RIGHT].Top) {
grippers[Gripper.POSITION_TOP_LEFT].Cursor = Cursors.SizeNWSE; _grippers[Gripper.POSITION_TOP_LEFT].Cursor = Cursors.SizeNWSE;
grippers[Gripper.POSITION_TOP_RIGHT].Cursor = Cursors.SizeNESW; _grippers[Gripper.POSITION_TOP_RIGHT].Cursor = Cursors.SizeNESW;
grippers[Gripper.POSITION_BOTTOM_RIGHT].Cursor = Cursors.SizeNWSE; _grippers[Gripper.POSITION_BOTTOM_RIGHT].Cursor = Cursors.SizeNWSE;
grippers[Gripper.POSITION_BOTTOM_LEFT].Cursor = Cursors.SizeNESW; _grippers[Gripper.POSITION_BOTTOM_LEFT].Cursor = Cursors.SizeNESW;
} else if((grippers[Gripper.POSITION_TOP_LEFT].Left > grippers[Gripper.POSITION_BOTTOM_RIGHT].Left && grippers[Gripper.POSITION_TOP_LEFT].Top < grippers[Gripper.POSITION_BOTTOM_RIGHT].Top) || } else if((_grippers[Gripper.POSITION_TOP_LEFT].Left > _grippers[Gripper.POSITION_BOTTOM_RIGHT].Left && _grippers[Gripper.POSITION_TOP_LEFT].Top < _grippers[Gripper.POSITION_BOTTOM_RIGHT].Top) ||
grippers[Gripper.POSITION_TOP_LEFT].Left < grippers[Gripper.POSITION_BOTTOM_RIGHT].Left && grippers[Gripper.POSITION_TOP_LEFT].Top > grippers[Gripper.POSITION_BOTTOM_RIGHT].Top) { _grippers[Gripper.POSITION_TOP_LEFT].Left < _grippers[Gripper.POSITION_BOTTOM_RIGHT].Left && _grippers[Gripper.POSITION_TOP_LEFT].Top > _grippers[Gripper.POSITION_BOTTOM_RIGHT].Top) {
grippers[Gripper.POSITION_TOP_LEFT].Cursor = Cursors.SizeNESW; _grippers[Gripper.POSITION_TOP_LEFT].Cursor = Cursors.SizeNESW;
grippers[Gripper.POSITION_TOP_RIGHT].Cursor = Cursors.SizeNWSE; _grippers[Gripper.POSITION_TOP_RIGHT].Cursor = Cursors.SizeNWSE;
grippers[Gripper.POSITION_BOTTOM_RIGHT].Cursor = Cursors.SizeNESW; _grippers[Gripper.POSITION_BOTTOM_RIGHT].Cursor = Cursors.SizeNESW;
grippers[Gripper.POSITION_BOTTOM_LEFT].Cursor = Cursors.SizeNWSE; _grippers[Gripper.POSITION_BOTTOM_LEFT].Cursor = Cursors.SizeNWSE;
} else if (grippers[Gripper.POSITION_TOP_LEFT].Left == grippers[Gripper.POSITION_BOTTOM_RIGHT].Left) { } else if (_grippers[Gripper.POSITION_TOP_LEFT].Left == _grippers[Gripper.POSITION_BOTTOM_RIGHT].Left) {
grippers[Gripper.POSITION_TOP_LEFT].Cursor = Cursors.SizeNS; _grippers[Gripper.POSITION_TOP_LEFT].Cursor = Cursors.SizeNS;
grippers[Gripper.POSITION_BOTTOM_RIGHT].Cursor = Cursors.SizeNS; _grippers[Gripper.POSITION_BOTTOM_RIGHT].Cursor = Cursors.SizeNS;
} else if (grippers[Gripper.POSITION_TOP_LEFT].Top == grippers[Gripper.POSITION_BOTTOM_RIGHT].Top) { } else if (_grippers[Gripper.POSITION_TOP_LEFT].Top == _grippers[Gripper.POSITION_BOTTOM_RIGHT].Top) {
grippers[Gripper.POSITION_TOP_LEFT].Cursor = Cursors.SizeWE; _grippers[Gripper.POSITION_TOP_LEFT].Cursor = Cursors.SizeWE;
grippers[Gripper.POSITION_BOTTOM_RIGHT].Cursor = Cursors.SizeWE; _grippers[Gripper.POSITION_BOTTOM_RIGHT].Cursor = Cursors.SizeWE;
} }
} }
} }
@ -385,7 +432,12 @@ namespace Greenshot.Drawing {
} }
private void gripperMouseMove(object sender, MouseEventArgs e) { private void gripperMouseMove(object sender, MouseEventArgs e) {
if(Status.Equals(EditStatus.RESIZING)) { Gripper originatingGripper = (Gripper)sender;
int absX = originatingGripper.Left + e.X;
int absY = originatingGripper.Top + e.Y;
if (originatingGripper == _targetGripper && Status.Equals(EditStatus.MOVING)) {
TargetGripperMove(absX, absY);
} 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
@ -397,10 +449,6 @@ namespace Greenshot.Drawing {
Invalidate(); Invalidate();
SuspendLayout(); SuspendLayout();
Gripper gr = (Gripper)sender;
int absX = gr.Left + e.X;
int absY = gr.Top + e.Y;
// 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;
@ -408,7 +456,7 @@ namespace Greenshot.Drawing {
boundsAfterResize.Height = boundsBeforeResize.Height; boundsAfterResize.Height = boundsBeforeResize.Height;
// calculate scaled rectangle // calculate scaled rectangle
ScaleHelper.Scale(ref boundsAfterResize, gr.Position, new PointF(absX, absY), ScaleHelper.GetScaleOptions()); ScaleHelper.Scale(ref boundsAfterResize, originatingGripper.Position, new PointF(absX, absY), ScaleHelper.GetScaleOptions());
// apply scaled bounds to this DrawableContainer // apply scaled bounds to this DrawableContainer
ApplyBounds(boundsAfterResize); ApplyBounds(boundsAfterResize);
@ -484,12 +532,12 @@ namespace Greenshot.Drawing {
} }
public virtual void ShowGrippers() { public virtual void ShowGrippers() {
if (grippers != null) { if (_grippers != null) {
for (int i = 0; i < grippers.Length; i++) { for (int i = 0; i < _grippers.Length; i++) {
if (grippers[i].Enabled) { if (_grippers[i].Enabled) {
grippers[i].Show(); _grippers[i].Show();
} else { } else {
grippers[i].Hide(); _grippers[i].Hide();
} }
} }
} }
@ -498,9 +546,9 @@ namespace Greenshot.Drawing {
public void HideGrippers() { public void HideGrippers() {
SuspendLayout(); SuspendLayout();
if (grippers != null) { if (_grippers != null) {
for (int i = 0; i < grippers.Length; i++) { for (int i = 0; i < _grippers.Length; i++) {
grippers[i].Hide(); _grippers[i].Hide();
} }
} }
} }
@ -517,7 +565,7 @@ namespace Greenshot.Drawing {
/// </summary> /// </summary>
/// <param name="allowMerge">true means allow the moves to be merged</param> /// <param name="allowMerge">true means allow the moves to be merged</param>
public void MakeBoundsChangeUndoable(bool allowMerge) { public void MakeBoundsChangeUndoable(bool allowMerge) {
parent.MakeUndoable(new DrawableContainerBoundsChangeMemento(this), allowMerge); _parent.MakeUndoable(new DrawableContainerBoundsChangeMemento(this), allowMerge);
} }
public void MoveBy(int dx, int dy) { public void MoveBy(int dx, int dy) {
@ -574,15 +622,15 @@ namespace Greenshot.Drawing {
} }
private void SwitchParent(Surface newParent) { private void SwitchParent(Surface newParent) {
if (parent != null && grippers != null) { if (_parent != null && _grippers != null) {
for (int i=0; i<grippers.Length; i++) { for (int i=0; i<_grippers.Length; i++) {
parent.Controls.Remove(grippers[i]); _parent.Controls.Remove(_grippers[i]);
} }
} else if (grippers == null) { } else if (_grippers == null) {
InitControls(); InitControls();
} }
parent = newParent; _parent = newParent;
parent.Controls.AddRange(grippers); _parent.Controls.AddRange(_grippers);
foreach(IFilter filter in Filters) { foreach(IFilter filter in Filters) {
filter.Parent = this; filter.Parent = this;
} }
@ -618,7 +666,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(Field fieldToBeChanged, object newValue) { public virtual void BeforeFieldChange(Field fieldToBeChanged, object newValue) {
parent.MakeUndoable(new ChangeFieldHolderMemento(this, fieldToBeChanged), true); _parent.MakeUndoable(new ChangeFieldHolderMemento(this, fieldToBeChanged), true);
Invalidate(); Invalidate();
} }
@ -653,15 +701,15 @@ namespace Greenshot.Drawing {
GraphicsPath translatePath = new GraphicsPath(); GraphicsPath translatePath = new GraphicsPath();
translatePath.AddRectangle(beforeBounds); translatePath.AddRectangle(beforeBounds);
Matrix rotateMatrix = new Matrix(); Matrix rotateMatrix = new Matrix();
rotateMatrix.RotateAt(angle, new PointF(parent.Width >> 1, parent.Height >> 1)); rotateMatrix.RotateAt(angle, new PointF(_parent.Width >> 1, _parent.Height >> 1));
translatePath.Transform(rotateMatrix); translatePath.Transform(rotateMatrix);
RectangleF newBounds = translatePath.GetBounds(); RectangleF newBounds = translatePath.GetBounds();
LOG.DebugFormat("New bounds by using graphics path: {0}", newBounds); LOG.DebugFormat("New bounds by using graphics path: {0}", newBounds);
int ox = 0; int ox = 0;
int oy = 0; int oy = 0;
int centerX = parent.Width >> 1; int centerX = _parent.Width >> 1;
int centerY = parent.Height >> 1; int centerY = _parent.Height >> 1;
// Transform from screen to normal coordinates // Transform from screen to normal coordinates
int px = Left - centerX; int px = Left - centerX;
int py = centerY - Top; int py = centerY - Top;
@ -717,5 +765,11 @@ namespace Greenshot.Drawing {
throw new NotSupportedException("Object doesn't have a default size"); throw new NotSupportedException("Object doesn't have a default size");
} }
} }
/// <summary>
/// Allows to override the initializing of the fields, so we can actually have our own defaults
/// </summary>
protected virtual void InitializeFields() {
}
} }
} }

View file

@ -118,7 +118,7 @@ namespace Greenshot.Drawing {
Surface surface = null; Surface surface = null;
foreach(DrawableContainer dc in this) { foreach(DrawableContainer dc in this) {
movingList.Add(dc); movingList.Add(dc);
surface = dc.parent; surface = dc._parent;
} }
if (movingList.Count > 0 && surface != null) { if (movingList.Count > 0 && surface != null) {
surface.MakeUndoable(new DrawableContainerBoundsChangeMemento(movingList), allowMerge); surface.MakeUndoable(new DrawableContainerBoundsChangeMemento(movingList), allowMerge);

View file

@ -33,12 +33,15 @@ 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) {
}
protected override void InitializeFields() {
AddField(GetType(), FieldType.LINE_THICKNESS, 2); AddField(GetType(), FieldType.LINE_THICKNESS, 2);
AddField(GetType(), FieldType.LINE_COLOR, Color.Red); AddField(GetType(), FieldType.LINE_COLOR, Color.Red);
AddField(GetType(), FieldType.FILL_COLOR, Color.Transparent); AddField(GetType(), FieldType.FILL_COLOR, Color.Transparent);
AddField(GetType(), FieldType.SHADOW, true); AddField(GetType(), FieldType.SHADOW, true);
} }
public override void Draw(Graphics graphics, RenderMode renderMode) { public override void Draw(Graphics graphics, RenderMode renderMode) {
graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

View file

@ -40,6 +40,9 @@ namespace Greenshot.Drawing {
} }
public FilterContainer(Surface parent) : base(parent) { public FilterContainer(Surface parent) : base(parent) {
}
protected override void InitializeFields() {
AddField(GetType(), FieldType.LINE_THICKNESS, 0); AddField(GetType(), FieldType.LINE_THICKNESS, 0);
AddField(GetType(), FieldType.LINE_COLOR, Color.Red); AddField(GetType(), FieldType.LINE_COLOR, Color.Red);
AddField(GetType(), FieldType.SHADOW, false); AddField(GetType(), FieldType.SHADOW, false);

View file

@ -49,19 +49,22 @@ namespace Greenshot.Drawing {
/// </summary> /// </summary>
public FreehandContainer(Surface parent) : base(parent) { public FreehandContainer(Surface parent) : base(parent) {
Init(); Init();
AddField(GetType(), FieldType.LINE_THICKNESS, 3);
AddField(GetType(), FieldType.LINE_COLOR, Color.Red);
Width = parent.Width; Width = parent.Width;
Height = parent.Height; Height = parent.Height;
Top = 0; Top = 0;
Left = 0; Left = 0;
} }
protected override void InitializeFields() {
AddField(GetType(), FieldType.LINE_THICKNESS, 3);
AddField(GetType(), FieldType.LINE_COLOR, Color.Red);
}
protected void Init() { protected void Init() {
if (grippers != null) { if (_grippers != null) {
for (int i = 0; i < grippers.Length; i++) { for (int i = 0; i < _grippers.Length; i++) {
grippers[i].Enabled = false; _grippers[i].Enabled = false;
grippers[i].Visible = false; _grippers[i].Visible = false;
} }
} }
} }
@ -229,7 +232,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, _parent.Height);
} }
} }

View file

@ -32,13 +32,17 @@ namespace Greenshot.Drawing {
[Serializable] [Serializable]
public class HighlightContainer : FilterContainer { public class HighlightContainer : FilterContainer {
public HighlightContainer(Surface parent) : base(parent) { public HighlightContainer(Surface parent) : base(parent) {
AddField(GetType(), FieldType.LINE_THICKNESS, 0);
AddField(GetType(), FieldType.LINE_COLOR, Color.Red);
AddField(GetType(), FieldType.SHADOW, false);
AddField(GetType(), FieldType.PREPARED_FILTER_HIGHLIGHT, PreparedFilter.TEXT_HIGHTLIGHT);
Init(); Init();
} }
/// <summary>
/// Use settings from base, extend with our own field
/// </summary>
protected override void InitializeFields() {
base.InitializeFields();
AddField(GetType(), FieldType.PREPARED_FILTER_HIGHLIGHT, PreparedFilter.TEXT_HIGHTLIGHT);
}
[OnDeserialized] [OnDeserialized]
private void OnDeserialized(StreamingContext context) { private void OnDeserialized(StreamingContext context) {
Init(); Init();

View file

@ -57,10 +57,13 @@ namespace Greenshot.Drawing {
} }
public ImageContainer(Surface parent) : base(parent) { public ImageContainer(Surface parent) : base(parent) {
AddField(GetType(), FieldType.SHADOW, false);
FieldChanged += BitmapContainer_OnFieldChanged; FieldChanged += BitmapContainer_OnFieldChanged;
} }
protected override void InitializeFields() {
AddField(GetType(), FieldType.SHADOW, false);
}
protected void BitmapContainer_OnFieldChanged(object sender, FieldChangedEventArgs e) { protected void BitmapContainer_OnFieldChanged(object sender, FieldChangedEventArgs e) {
if (sender.Equals(this)) { if (sender.Equals(this)) {
if (e.Field.FieldType == FieldType.SHADOW) { if (e.Field.FieldType == FieldType.SHADOW) {

View file

@ -37,6 +37,9 @@ namespace Greenshot.Drawing {
public LineContainer(Surface parent) : base(parent) { public LineContainer(Surface parent) : base(parent) {
Init(); Init();
}
protected override void InitializeFields() {
AddField(GetType(), FieldType.LINE_THICKNESS, 2); AddField(GetType(), FieldType.LINE_THICKNESS, 2);
AddField(GetType(), FieldType.LINE_COLOR, Color.Red); AddField(GetType(), FieldType.LINE_COLOR, Color.Red);
AddField(GetType(), FieldType.SHADOW, true); AddField(GetType(), FieldType.SHADOW, true);
@ -50,9 +53,9 @@ namespace Greenshot.Drawing {
} }
protected void Init() { protected void Init() {
if (grippers != null) { if (_grippers != null) {
foreach (int index in new[] { 1, 2, 3, 5, 6, 7 }) { foreach (int index in new[] { 1, 2, 3, 5, 6, 7 }) {
grippers[index].Enabled = false; _grippers[index].Enabled = false;
} }
} }
} }

View file

@ -30,9 +30,13 @@ namespace Greenshot.Drawing {
[Serializable] [Serializable]
public class ObfuscateContainer : FilterContainer { public class ObfuscateContainer : FilterContainer {
public ObfuscateContainer(Surface parent) : base(parent) { public ObfuscateContainer(Surface parent) : base(parent) {
AddField(GetType(), FieldType.PREPARED_FILTER_OBFUSCATE, PreparedFilter.PIXELIZE);
Init(); Init();
} }
protected override void InitializeFields() {
base.InitializeFields();
AddField(GetType(), FieldType.PREPARED_FILTER_OBFUSCATE, PreparedFilter.PIXELIZE);
}
[OnDeserialized] [OnDeserialized]
private void OnDeserialized(StreamingContext context) { private void OnDeserialized(StreamingContext context) {

View file

@ -35,13 +35,15 @@ namespace Greenshot.Drawing {
private static readonly ILog LOG = LogManager.GetLogger(typeof(RectangleContainer)); private static readonly ILog LOG = LogManager.GetLogger(typeof(RectangleContainer));
public RectangleContainer(Surface parent) : base(parent) { public RectangleContainer(Surface parent) : base(parent) {
}
protected override void InitializeFields() {
AddField(GetType(), FieldType.LINE_THICKNESS, 2); AddField(GetType(), FieldType.LINE_THICKNESS, 2);
AddField(GetType(), FieldType.LINE_COLOR, Color.Red); AddField(GetType(), FieldType.LINE_COLOR, Color.Red);
AddField(GetType(), FieldType.FILL_COLOR, Color.Transparent); AddField(GetType(), FieldType.FILL_COLOR, Color.Transparent);
AddField(GetType(), FieldType.SHADOW, true); AddField(GetType(), FieldType.SHADOW, true);
} }
public override void Draw(Graphics graphics, RenderMode rm) { public override void Draw(Graphics graphics, RenderMode rm) {
graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

View file

@ -0,0 +1,203 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2012 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.Drawing.Fields;
using Greenshot.Helpers;
using Greenshot.Plugin;
using Greenshot.Plugin.Drawing;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace Greenshot.Drawing {
/// <summary>
/// Description of SpeechbubbleContainer.
/// </summary>
[Serializable()]
public class SpeechbubbleContainer : TextContainer {
public SpeechbubbleContainer(Surface parent)
: base(parent) {
}
/// <summary>
/// We set our own field values
/// </summary>
protected override void InitializeFields() {
AddField(GetType(), FieldType.LINE_THICKNESS, 4);
AddField(GetType(), FieldType.LINE_COLOR, Color.Blue);
AddField(GetType(), FieldType.SHADOW, true);
AddField(GetType(), FieldType.FONT_ITALIC, false);
AddField(GetType(), FieldType.FONT_BOLD, false);
AddField(GetType(), FieldType.FILL_COLOR, Color.Transparent);
AddField(GetType(), FieldType.FONT_FAMILY, FontFamily.GenericSansSerif.Name);
AddField(GetType(), FieldType.FONT_SIZE, 20f);
AddField(GetType(), FieldType.TEXT_HORIZONTAL_ALIGNMENT, HorizontalAlignment.Center);
AddField(GetType(), FieldType.TEXT_VERTICAL_ALIGNMENT, VerticalAlignment.CENTER);
}
protected override void TargetGripperMove(int absX, int absY) {
base.TargetGripperMove(absX, absY);
Invalidate();
}
/// <summary>
/// Called from Surface (the _parent) when the drawing begins (mouse-down)
/// </summary>
/// <returns>true if the surface doesn't need to handle the event</returns>
public override bool HandleMouseDown(int mouseX, int mouseY) {
if (TargetGripper == null) {
InitTargetGripper(Color.Green, new Point(mouseX, mouseY));
}
return base.HandleMouseDown(mouseX, mouseY);
}
public override Rectangle DrawingBounds {
get {
return new Rectangle(0, 0, _parent.Width, _parent.Height);
}
}
public override void Draw(Graphics graphics, RenderMode renderMode) {
if (TargetGripper == null) {
return;
}
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.None;
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
Color fillColor = GetFieldValueAsColor(FieldType.FILL_COLOR);
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
bool lineVisible = (lineThickness > 0 && Colors.IsVisible(lineColor));
Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
int tailAngle = 90 + (int)GeometryHelper.Angle2D(Left + (Width / 2), Top + (Height / 2), TargetGripper.Left, TargetGripper.Top);
int tailLength = GeometryHelper.Distance2D(Left + (Width / 2), Top + (Height / 2), TargetGripper.Left, TargetGripper.Top);
int tailWidth = (Math.Abs(Width) + Math.Abs(Height)) / 20;
GraphicsPath bubble = new GraphicsPath();
bubble.AddEllipse(0, 0, Math.Abs(rect.Width), Math.Abs(rect.Height));
bubble.CloseAllFigures();
GraphicsPath tail = new GraphicsPath();
tail.AddLine(-tailWidth, 0, tailWidth, 0);
tail.AddLine(tailWidth, 0, 0, -tailLength);
tail.CloseFigure();
GraphicsState state = graphics.Save();
// draw the tail border where the bubble is not visible
using (Region clipRegion = new Region(bubble)) {
clipRegion.Translate(Left, Top);
graphics.SetClip(clipRegion, CombineMode.Exclude);
graphics.TranslateTransform(Left + (Width / 2), Top + (Height / 2));
graphics.RotateTransform(tailAngle);
using (Pen pen = new Pen(lineColor, lineThickness)) {
graphics.DrawPath(pen, tail);
}
}
graphics.Restore(state);
if (Colors.IsVisible(fillColor)) {
//draw the bubbleshape
state = graphics.Save();
graphics.TranslateTransform(Left, Top);
using (Brush brush = new SolidBrush(fillColor)) {
graphics.FillPath(brush, bubble);
}
graphics.Restore(state);
}
if (lineVisible) {
//draw the bubble border
state = graphics.Save();
// Draw bubble where the Tail is not visible.
using (Region clipRegion = new Region(tail)) {
Matrix transformMatrix = new Matrix();
transformMatrix.Rotate(tailAngle);
clipRegion.Transform(transformMatrix);
clipRegion.Translate(Left + (Width / 2), Top + (Height / 2));
graphics.SetClip(clipRegion, CombineMode.Exclude);
graphics.TranslateTransform(Left, Top);
using (Pen pen = new Pen(lineColor, lineThickness)) {
graphics.DrawPath(pen, bubble);
}
}
graphics.Restore(state);
}
if (Colors.IsVisible(fillColor)) {
// Draw the tail border
state = graphics.Save();
graphics.TranslateTransform(Left + (Width / 2), Top + (Height / 2));
graphics.RotateTransform(tailAngle);
using (Brush brush = new SolidBrush(fillColor)) {
graphics.FillPath(brush, tail);
}
graphics.Restore(state);
}
// Draw the text
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
DrawText(graphics, GuiRectangle.GetGuiRectangle(Left, Top, Width, Height), format);
// cleanup
bubble.Dispose();
tail.Dispose();
}
public override bool Contains(int x, int y) {
double xDistanceFromCenter = x - (Left + Width / 2);
double yDistanceFromCenter = y - (Top + Height / 2);
// ellipse: x^2/a^2 + y^2/b^2 = 1
return Math.Pow(xDistanceFromCenter, 2) / Math.Pow(Width / 2, 2) + Math.Pow(yDistanceFromCenter, 2) / Math.Pow(Height / 2, 2) < 1;
}
public override bool ClickableAt(int x, int y) {
Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
int lineThicknessPlusSafety = lineThickness + 10;
// If we clicked inside the rectangle and it's visible we are clickable at.
Color fillColor = GetFieldValueAsColor(FieldType.FILL_COLOR);
if (!Color.Transparent.Equals(fillColor)) {
if (Contains(x, y)) {
return true;
}
}
// check the rest of the lines
if (lineThicknessPlusSafety > 0) {
using (Pen pen = new Pen(Color.White, lineThicknessPlusSafety)) {
using (GraphicsPath path = new GraphicsPath()) {
path.AddEllipse(rect);
return path.IsOutlineVisible(x, y, pen);
}
}
} else {
return false;
}
}
}
}

View file

@ -0,0 +1,81 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2012 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.Drawing.Fields;
using Greenshot.Helpers;
using Greenshot.Plugin.Drawing;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace Greenshot.Drawing {
/// <summary>
/// Description of StepLabelContainer.
/// This is an enumerated label, every single StepLabelContainer shows the number of the order it was created.
/// To make sure that deleting recalculates, we check the location before every draw.
/// </summary>
[Serializable()]
public class StepLabelContainer : TextContainer {
public StepLabelContainer(Surface parent) : base(parent) {
_defaultEditMode = EditStatus.IDLE;
parent.StepContainers.AddLast(this);
// Set defaults
Width = 40;
Height = 40;
}
public override void Dispose() {
Parent.StepContainers.Remove(this);
base.Dispose();
}
/// <summary>
/// We set our own field values
/// </summary>
protected override void InitializeFields() {
AddField(GetType(), FieldType.LINE_COLOR, Color.White);
AddField(GetType(), FieldType.FILL_COLOR, Color.DarkRed);
AddField(GetType(), FieldType.FONT_SIZE, 21f);
AddField(GetType(), FieldType.LINE_THICKNESS, 0);
base.InitializeFields();
}
/// <summary>
/// Override the parent, calculate the label number, than draw
/// </summary>
/// <param name="graphics"></param>
/// <param name="rm"></param>
public override void Draw(Graphics graphics, RenderMode rm) {
int number = 1;
foreach (StepLabelContainer possibleThis in Parent.StepContainers) {
if (possibleThis == this) {
break;
}
if (Parent.IsOnSurface(possibleThis)) {
number++;
}
}
this.Text = number.ToString();
base.Draw(graphics, rm);
}
}
}

View file

@ -209,6 +209,17 @@ namespace Greenshot.Drawing {
[NonSerialized] [NonSerialized]
private Bitmap buffer = null; private Bitmap buffer = null;
/// <summary>
/// all stepcontainers for the surface, needed with serialization
/// </summary>
private readonly LinkedList<IDrawableContainer> _stepContainers = new LinkedList<IDrawableContainer>();
public LinkedList<IDrawableContainer> StepContainers {
get {
return _stepContainers;
}
}
/// <summary> /// <summary>
/// all elements on the surface, needed with serialization /// all elements on the surface, needed with serialization
/// </summary> /// </summary>
@ -633,6 +644,12 @@ namespace Greenshot.Drawing {
case DrawingModes.Text: case DrawingModes.Text:
undrawnElement = new TextContainer(this); undrawnElement = new TextContainer(this);
break; break;
case DrawingModes.SpeechBubble:
undrawnElement = new SpeechbubbleContainer(this);
break;
case DrawingModes.StepLabel:
undrawnElement = new StepLabelContainer(this);
break;
case DrawingModes.Line: case DrawingModes.Line:
undrawnElement = new LineContainer(this); undrawnElement = new LineContainer(this);
break; break;
@ -1002,7 +1019,7 @@ namespace Greenshot.Drawing {
} }
} }
drawingElement = undrawnElement; drawingElement = undrawnElement;
drawingElement.Status = EditStatus.DRAWING; drawingElement.Status = undrawnElement.DefaultEditMode;
undrawnElement = null; undrawnElement = null;
// if a new element has been drawn, set location and register it // if a new element has been drawn, set location and register it
if (drawingElement != null) { if (drawingElement != null) {
@ -1274,7 +1291,7 @@ namespace Greenshot.Drawing {
} }
elementToRemove.PropertyChanged -= ElementPropertyChanged; elementToRemove.PropertyChanged -= ElementPropertyChanged;
// Do not dispose, the memento should!! element.Dispose(); // Do not dispose, the memento should!! element.Dispose();
elementToRemove.Invalidate(); Invalidate();
if (makeUndoable) { if (makeUndoable) {
MakeUndoable(new DeleteElementMemento(this, elementToRemove), false); MakeUndoable(new DeleteElementMemento(this, elementToRemove), false);
} }
@ -1690,5 +1707,9 @@ namespace Greenshot.Drawing {
public void element_FieldChanged(object sender, FieldChangedEventArgs e) { public void element_FieldChanged(object sender, FieldChangedEventArgs e) {
selectedElements.HandleFieldChangedEvent(sender, e); selectedElements.HandleFieldChangedEvent(sender, e);
} }
public bool IsOnSurface(IDrawableContainer container) {
return elements.Contains(container);
}
} }
} }

View file

@ -18,18 +18,19 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
using Greenshot.Drawing.Fields;
using Greenshot.Helpers;
using Greenshot.Memento;
using Greenshot.Plugin;
using Greenshot.Plugin.Drawing;
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Runtime.Serialization;
using System.Windows.Forms;
using Greenshot.Drawing.Fields;
using Greenshot.Helpers;
using Greenshot.Plugin;
using Greenshot.Plugin.Drawing;
using Greenshot.Memento;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Drawing.Text; using System.Drawing.Text;
using System.Runtime.Serialization;
using System.Windows.Forms;
namespace Greenshot.Drawing { namespace Greenshot.Drawing {
/// <summary> /// <summary>
@ -41,7 +42,7 @@ namespace Greenshot.Drawing {
// 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;
private Font font; private Font _font;
/// <summary> /// <summary>
/// The StringFormat object is not serializable!! /// The StringFormat object is not serializable!!
@ -49,22 +50,22 @@ namespace Greenshot.Drawing {
[NonSerialized] [NonSerialized]
StringFormat stringFormat = new StringFormat(); StringFormat stringFormat = new 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");
} }
} }
@ -74,6 +75,11 @@ namespace Greenshot.Drawing {
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() {
AddField(GetType(), FieldType.LINE_THICKNESS, 2); AddField(GetType(), FieldType.LINE_THICKNESS, 2);
AddField(GetType(), FieldType.LINE_COLOR, Color.Red); AddField(GetType(), FieldType.LINE_COLOR, Color.Red);
AddField(GetType(), FieldType.SHADOW, true); AddField(GetType(), FieldType.SHADOW, true);
@ -84,8 +90,6 @@ namespace Greenshot.Drawing {
AddField(GetType(), FieldType.FONT_SIZE, 11f); AddField(GetType(), FieldType.FONT_SIZE, 11f);
AddField(GetType(), FieldType.TEXT_HORIZONTAL_ALIGNMENT, HorizontalAlignment.Center); AddField(GetType(), FieldType.TEXT_HORIZONTAL_ALIGNMENT, HorizontalAlignment.Center);
AddField(GetType(), FieldType.TEXT_VERTICAL_ALIGNMENT, VerticalAlignment.CENTER); AddField(GetType(), FieldType.TEXT_VERTICAL_ALIGNMENT, VerticalAlignment.CENTER);
stringFormat = new StringFormat();
stringFormat.Trimming = StringTrimming.EllipsisWord;
} }
[OnDeserialized] [OnDeserialized]
@ -97,9 +101,9 @@ namespace Greenshot.Drawing {
protected override void Dispose(bool disposing) { protected override void Dispose(bool disposing) {
if (disposing) { if (disposing) {
if (font != null) { if (_font != null) {
font.Dispose(); _font.Dispose();
font = null; _font = null;
} }
if (stringFormat != null) { if (stringFormat != null) {
stringFormat.Dispose(); stringFormat.Dispose();
@ -121,7 +125,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;
@ -150,8 +154,8 @@ namespace Greenshot.Drawing {
UpdateFormat(); UpdateFormat();
//Invalidate(); //Invalidate();
} }
font.Dispose(); _font.Dispose();
font = null; _font = null;
fontInvalidated = true; fontInvalidated = true;
} }
@ -175,8 +179,8 @@ namespace Greenshot.Drawing {
} }
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();
@ -195,10 +199,10 @@ namespace Greenshot.Drawing {
} }
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);
} }
private void UpdateFormat() { private void UpdateFormat() {
@ -236,7 +240,7 @@ namespace Greenshot.Drawing {
} }
} }
} }
font = new Font(fam, fontSize, fs, GraphicsUnit.Pixel); _font = new Font(fam, fontSize, fs, GraphicsUnit.Pixel);
} }
fontInvalidated = false; fontInvalidated = false;
} }
@ -268,7 +272,7 @@ namespace Greenshot.Drawing {
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;
} }
void textBox_KeyDown(object sender, KeyEventArgs e) { void textBox_KeyDown(object sender, KeyEventArgs e) {
@ -299,7 +303,7 @@ namespace Greenshot.Drawing {
DrawSelectionBorder(graphics, rect); DrawSelectionBorder(graphics, rect);
} }
if (text == null || text.Length == 0 ) { if (_text == null || _text.Length == 0 ) {
return; return;
} }
@ -321,24 +325,37 @@ namespace Greenshot.Drawing {
shadowRect.Inflate(-textOffset, -textOffset); shadowRect.Inflate(-textOffset, -textOffset);
} }
using (Brush fontBrush = new SolidBrush(Color.FromArgb(alpha, 100, 100, 100))) { using (Brush fontBrush = new SolidBrush(Color.FromArgb(alpha, 100, 100, 100))) {
graphics.DrawString(text, font, fontBrush, shadowRect, stringFormat); graphics.DrawString(_text, _font, fontBrush, shadowRect, stringFormat);
currentStep++; currentStep++;
alpha = alpha - basealpha / steps; alpha = alpha - basealpha / steps;
} }
} }
} }
DrawText(graphics, rect, null);
}
protected void DrawText(Graphics graphics, Rectangle drawingRectange, StringFormat stringFormat) {
UpdateFormat();
Color fillColor = GetFieldValueAsColor(FieldType.FILL_COLOR);
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR); Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
Rectangle fontRect = rect; Rectangle fontRect = drawingRectange;
int textOffset = (lineThickness > 0) ? (int)Math.Ceiling(lineThickness / 2d) : 0;
if (lineThickness > 0) { if (lineThickness > 0) {
graphics.SmoothingMode = SmoothingMode.HighSpeed; graphics.SmoothingMode = SmoothingMode.HighSpeed;
fontRect.Inflate(-textOffset, -textOffset); fontRect.Inflate(-textOffset, -textOffset);
} }
graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.SmoothingMode = SmoothingMode.HighQuality;
using (Brush fontBrush = new SolidBrush(lineColor)) { using (Brush fontBrush = new SolidBrush(lineColor)) {
graphics.DrawString(text, font, fontBrush, fontRect, stringFormat); graphics.DrawString(_text, _font, fontBrush, fontRect);
if (stringFormat != null) {
graphics.DrawString(_text, _font, fontBrush, fontRect, stringFormat);
} else {
graphics.DrawString(_text, _font, fontBrush, fontRect);
}
} }
} }
public override bool ClickableAt(int x, int y) { public override bool ClickableAt(int x, int y) {
Rectangle r = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height); Rectangle r = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
r.Inflate(5, 5); r.Inflate(5, 5);

View file

@ -62,6 +62,8 @@ namespace Greenshot {
this.btnArrow = new GreenshotPlugin.Controls.GreenshotToolStripButton(); this.btnArrow = new GreenshotPlugin.Controls.GreenshotToolStripButton();
this.btnFreehand = new GreenshotPlugin.Controls.GreenshotToolStripButton(); this.btnFreehand = new GreenshotPlugin.Controls.GreenshotToolStripButton();
this.btnText = new GreenshotPlugin.Controls.GreenshotToolStripButton(); this.btnText = new GreenshotPlugin.Controls.GreenshotToolStripButton();
this.btnSpeechBubble = new GreenshotPlugin.Controls.GreenshotToolStripButton();
this.btnStepLabel = new GreenshotPlugin.Controls.GreenshotToolStripButton();
this.toolStripSeparator14 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator14 = new System.Windows.Forms.ToolStripSeparator();
this.btnHighlight = new GreenshotPlugin.Controls.GreenshotToolStripButton(); this.btnHighlight = new GreenshotPlugin.Controls.GreenshotToolStripButton();
this.btnObfuscate = new GreenshotPlugin.Controls.GreenshotToolStripButton(); this.btnObfuscate = new GreenshotPlugin.Controls.GreenshotToolStripButton();
@ -300,6 +302,8 @@ namespace Greenshot {
this.btnArrow, this.btnArrow,
this.btnFreehand, this.btnFreehand,
this.btnText, this.btnText,
this.btnSpeechBubble,
this.btnStepLabel,
this.toolStripSeparator14, this.toolStripSeparator14,
this.btnHighlight, this.btnHighlight,
this.btnObfuscate, this.btnObfuscate,
@ -397,6 +401,28 @@ namespace Greenshot {
this.btnText.Size = new System.Drawing.Size(22, 20); this.btnText.Size = new System.Drawing.Size(22, 20);
this.btnText.Click += new System.EventHandler(this.BtnTextClick); this.btnText.Click += new System.EventHandler(this.BtnTextClick);
// //
// btnSpeechBubble
//
this.btnSpeechBubble.CheckOnClick = true;
this.btnSpeechBubble.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.btnSpeechBubble.Image = ((System.Drawing.Image)(resources.GetObject("btnText.Image")));
this.btnSpeechBubble.ImageTransparentColor = System.Drawing.Color.Magenta;
this.btnSpeechBubble.LanguageKey = "editor_drawtextbox";
this.btnSpeechBubble.Name = "btnSpeechBubble";
this.btnSpeechBubble.Size = new System.Drawing.Size(22, 20);
this.btnSpeechBubble.Click += new System.EventHandler(this.BtnSpeechBubbleClick);
//
// btnStepLabel
//
this.btnStepLabel.CheckOnClick = true;
this.btnStepLabel.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.btnStepLabel.Image = ((System.Drawing.Image)(resources.GetObject("btnText.Image")));
this.btnStepLabel.ImageTransparentColor = System.Drawing.Color.Magenta;
this.btnStepLabel.LanguageKey = "editor_drawtextbox";
this.btnStepLabel.Name = "btnStepLabel";
this.btnStepLabel.Size = new System.Drawing.Size(22, 20);
this.btnStepLabel.Click += new System.EventHandler(this.BtnStepLabelClick);
//
// toolStripSeparator14 // toolStripSeparator14
// //
this.toolStripSeparator14.Name = "toolStripSeparator14"; this.toolStripSeparator14.Name = "toolStripSeparator14";
@ -1785,6 +1811,8 @@ namespace Greenshot {
private GreenshotPlugin.Controls.GreenshotToolStripMenuItem drawArrowToolStripMenuItem; private GreenshotPlugin.Controls.GreenshotToolStripMenuItem drawArrowToolStripMenuItem;
private GreenshotPlugin.Controls.GreenshotToolStripMenuItem drawFreehandToolStripMenuItem; private GreenshotPlugin.Controls.GreenshotToolStripMenuItem drawFreehandToolStripMenuItem;
private GreenshotPlugin.Controls.GreenshotToolStripButton btnText; private GreenshotPlugin.Controls.GreenshotToolStripButton btnText;
private GreenshotPlugin.Controls.GreenshotToolStripButton btnSpeechBubble;
private GreenshotPlugin.Controls.GreenshotToolStripButton btnStepLabel;
private GreenshotPlugin.Controls.GreenshotToolStripMenuItem drawLineToolStripMenuItem; private GreenshotPlugin.Controls.GreenshotToolStripMenuItem drawLineToolStripMenuItem;
private GreenshotPlugin.Controls.GreenshotToolStripButton btnLine; private GreenshotPlugin.Controls.GreenshotToolStripButton btnLine;
private GreenshotPlugin.Controls.GreenshotToolStripButton btnSettings; private GreenshotPlugin.Controls.GreenshotToolStripButton btnSettings;

View file

@ -391,6 +391,12 @@ namespace Greenshot {
case DrawingModes.Text: case DrawingModes.Text:
SetButtonChecked(btnText); SetButtonChecked(btnText);
break; break;
case DrawingModes.SpeechBubble:
SetButtonChecked(btnSpeechBubble);
break;
case DrawingModes.StepLabel:
SetButtonChecked(btnStepLabel);
break;
case DrawingModes.Line: case DrawingModes.Line:
SetButtonChecked(btnLine); SetButtonChecked(btnLine);
break; break;
@ -480,7 +486,16 @@ namespace Greenshot {
surface.DrawingMode = DrawingModes.Text; surface.DrawingMode = DrawingModes.Text;
refreshFieldControls(); refreshFieldControls();
} }
void BtnSpeechBubbleClick(object sender, EventArgs e) {
surface.DrawingMode = DrawingModes.SpeechBubble;
refreshFieldControls();
}
void BtnStepLabelClick(object sender, EventArgs e) {
surface.DrawingMode = DrawingModes.StepLabel;
refreshFieldControls();
}
void BtnLineClick(object sender, EventArgs e) { void BtnLineClick(object sender, EventArgs e) {
surface.DrawingMode = DrawingModes.Line; surface.DrawingMode = DrawingModes.Line;
refreshFieldControls(); refreshFieldControls();

View file

@ -75,6 +75,7 @@
<Compile Include="Destinations\PickerDestination.cs" /> <Compile Include="Destinations\PickerDestination.cs" />
<Compile Include="Destinations\PrinterDestination.cs" /> <Compile Include="Destinations\PrinterDestination.cs" />
<Compile Include="Drawing\ArrowContainer.cs" /> <Compile Include="Drawing\ArrowContainer.cs" />
<Compile Include="Drawing\StepLabelContainer.cs" />
<Compile Include="Drawing\Fields\Binding\AlignmentConverter.cs" /> <Compile Include="Drawing\Fields\Binding\AlignmentConverter.cs" />
<Compile Include="Drawing\ImageContainer.cs" /> <Compile Include="Drawing\ImageContainer.cs" />
<Compile Include="Drawing\CropContainer.cs" /> <Compile Include="Drawing\CropContainer.cs" />
@ -115,6 +116,7 @@
<Compile Include="Drawing\FreehandContainer.cs" /> <Compile Include="Drawing\FreehandContainer.cs" />
<Compile Include="Drawing\RectangleContainer.cs" /> <Compile Include="Drawing\RectangleContainer.cs" />
<Compile Include="Drawing\RoundedRectangle.cs" /> <Compile Include="Drawing\RoundedRectangle.cs" />
<Compile Include="Drawing\SpeechbubbleContainer.cs" />
<Compile Include="Drawing\Surface.cs"> <Compile Include="Drawing\Surface.cs">
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>

View file

@ -92,6 +92,9 @@ namespace Greenshot.Plugin.Drawing {
bool HandleMouseMove(int x, int y); bool HandleMouseMove(int x, int y);
bool InitContent(); bool InitContent();
void MakeBoundsChangeUndoable(bool allowMerge); void MakeBoundsChangeUndoable(bool allowMerge);
EditStatus DefaultEditMode {
get;
}
} }
public interface ITextContainer: IDrawableContainer { public interface ITextContainer: IDrawableContainer {

View file

@ -75,7 +75,21 @@ namespace Greenshot.Plugin {
public delegate void SurfaceMessageEventHandler(object sender, SurfaceMessageEventArgs eventArgs); public delegate void SurfaceMessageEventHandler(object sender, SurfaceMessageEventArgs eventArgs);
public delegate void SurfaceElementEventHandler(object sender, SurfaceElementEventArgs eventArgs); public delegate void SurfaceElementEventHandler(object sender, SurfaceElementEventArgs eventArgs);
public delegate void SurfaceDrawingModeEventHandler(object sender, SurfaceDrawingModeEventArgs eventArgs); public delegate void SurfaceDrawingModeEventHandler(object sender, SurfaceDrawingModeEventArgs eventArgs);
public enum DrawingModes { None, Rect, Ellipse, Text, Line, Arrow, Crop, Highlight, Obfuscate, Bitmap, Path } public enum DrawingModes {
None,
Rect,
Ellipse,
Text,
Line,
Arrow,
Crop,
Highlight,
Obfuscate,
Bitmap,
Path,
SpeechBubble,
StepLabel
}
/// <summary> /// <summary>
/// The interface to the Surface object, so Plugins can use it. /// The interface to the Surface object, so Plugins can use it.
@ -152,6 +166,12 @@ namespace Greenshot.Plugin {
void DeselectElement(IDrawableContainer container); void DeselectElement(IDrawableContainer container);
void DeselectAllElements(); void DeselectAllElements();
void SelectElement(IDrawableContainer container); void SelectElement(IDrawableContainer container);
/// <summary>
/// Is the supplied container "on" the surface?
/// </summary>
/// <param name="container"></param>
/// <returns>This returns false if the container is deleted but still in the undo stack</returns>
bool IsOnSurface(IDrawableContainer container);
void Invalidate(Rectangle rectangleToInvalidate); void Invalidate(Rectangle rectangleToInvalidate);
void Invalidate(); void Invalidate();
bool Modified { bool Modified {
@ -178,5 +198,9 @@ namespace Greenshot.Plugin {
get; get;
set; set;
} }
LinkedList<IDrawableContainer> StepContainers {
get;
}
} }
} }