mirror of
https://github.com/greenshot/greenshot
synced 2025-07-16 10:03:44 -07:00
Moving back to trunk!
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1602 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
ad265b2c54
commit
8d458998a1
332 changed files with 17647 additions and 9466 deletions
|
@ -22,18 +22,17 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Greenshot.Configuration;
|
||||
using Greenshot.Controls;
|
||||
using Greenshot.Drawing.Fields;
|
||||
using Greenshot.Drawing.Filters;
|
||||
using Greenshot.Helpers;
|
||||
using Greenshot.Plugin;
|
||||
using GreenshotPlugin.Core;
|
||||
using Greenshot.Plugin.Drawing;
|
||||
using Greenshot.Memento;
|
||||
using IniFile;
|
||||
|
||||
namespace Greenshot.Drawing {
|
||||
/// <summary>
|
||||
|
@ -45,6 +44,10 @@ namespace Greenshot.Drawing {
|
|||
[Serializable()]
|
||||
public abstract class DrawableContainer : AbstractFieldHolderWithChildren, INotifyPropertyChanged, IDrawableContainer {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(DrawableContainer));
|
||||
private static System.ComponentModel.ComponentResourceManager editorFormResources = new System.ComponentModel.ComponentResourceManager(typeof(ImageEditorForm));
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
|
||||
private bool isMadeUndoable = false;
|
||||
|
||||
[NonSerialized]
|
||||
private PropertyChangedEventHandler propertyChanged;
|
||||
|
@ -53,32 +56,36 @@ namespace Greenshot.Drawing {
|
|||
remove{ propertyChanged -= value; }
|
||||
}
|
||||
|
||||
// public List<IFilter> filters = new List<IFilter>();
|
||||
public List<IFilter> Filters {
|
||||
get {
|
||||
List<IFilter> ret = new List<IFilter>();
|
||||
foreach(IFieldHolder c in Children) {
|
||||
if(c is IFilter) ret.Add(c as IFilter);
|
||||
if (c is IFilter) {
|
||||
ret.Add(c as IFilter);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
[NonSerialized]
|
||||
protected Surface parent;
|
||||
internal Surface parent;
|
||||
public ISurface Parent {
|
||||
get { return parent; }
|
||||
set { SwitchParent((Surface)value); }
|
||||
}
|
||||
[NonSerialized]
|
||||
protected Label[] grippers;
|
||||
protected Gripper[] grippers;
|
||||
private bool layoutSuspended = false;
|
||||
|
||||
[NonSerialized]
|
||||
private bool selected = false;
|
||||
public bool Selected {
|
||||
get {return selected;}
|
||||
set {selected = value; OnPropertyChanged("Selected"); }
|
||||
set {
|
||||
selected = value;
|
||||
OnPropertyChanged("Selected");
|
||||
}
|
||||
}
|
||||
|
||||
[NonSerialized]
|
||||
|
@ -87,29 +94,86 @@ namespace Greenshot.Drawing {
|
|||
private int left = 0;
|
||||
public int Left {
|
||||
get { return left; }
|
||||
set { left = value; DoLayout();}
|
||||
set {
|
||||
if(value != left) {
|
||||
left = value;
|
||||
DoLayout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int top = 0;
|
||||
public int Top {
|
||||
get { return top; }
|
||||
set { top = value; DoLayout();}
|
||||
set {
|
||||
if(value != top) {
|
||||
top = value;
|
||||
DoLayout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int width = 0;
|
||||
public int Width {
|
||||
get { return width; }
|
||||
set { width = value; DoLayout();}
|
||||
set {
|
||||
if(value != width) {
|
||||
width = value;
|
||||
DoLayout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int height = 0;
|
||||
public int Height {
|
||||
get { return height; }
|
||||
set { height = value; DoLayout();}
|
||||
set {
|
||||
if(value != height) {
|
||||
height = value;
|
||||
DoLayout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Point Location {
|
||||
get {
|
||||
return new Point(left, top);
|
||||
}
|
||||
}
|
||||
|
||||
public Size Size {
|
||||
get {
|
||||
return new Size(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
[NonSerialized]
|
||||
/// <summary>
|
||||
/// will store current bounds of this DrawableContainer before starting a resize
|
||||
/// </summary>
|
||||
private Rectangle boundsBeforeResize = Rectangle.Empty;
|
||||
|
||||
[NonSerialized]
|
||||
/// <summary>
|
||||
/// "workbench" rectangle - used for calculatoing bounds during resizing (to be applied to this DrawableContainer afterwards)
|
||||
/// </summary>
|
||||
private RectangleF boundsAfterResize = RectangleF.Empty;
|
||||
|
||||
public Rectangle Bounds {
|
||||
get { return GuiRectangle.GetGuiRectangle(left, top, width, height); }
|
||||
get { return GuiRectangle.GetGuiRectangle(Left, Top, Width, Height); }
|
||||
set {
|
||||
Left = round(value.Left);
|
||||
Top = round(value.Top);
|
||||
Width = round(value.Width);
|
||||
Height = round(value.Height);
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyBounds(RectangleF newBounds) {
|
||||
Left = round(newBounds.Left);
|
||||
Top = round(newBounds.Top);
|
||||
Width = round(newBounds.Width);
|
||||
Height = round(newBounds.Height);
|
||||
}
|
||||
|
||||
public DrawableContainer(Surface parent) {
|
||||
|
@ -124,6 +188,18 @@ namespace Greenshot.Drawing {
|
|||
public void Remove(IFilter filter) {
|
||||
RemoveChild(filter);
|
||||
}
|
||||
|
||||
private int round(float f) {
|
||||
if(float.IsPositiveInfinity(f) || f>int.MaxValue/2) return int.MaxValue/2;
|
||||
else if (float.IsNegativeInfinity(f) || f<int.MinValue/2) return int.MinValue/2;
|
||||
return (int)Math.Round(f);
|
||||
}
|
||||
|
||||
private int round(double d) {
|
||||
if(Double.IsPositiveInfinity(d) || d>int.MaxValue/2) return int.MaxValue/2;
|
||||
else if (Double.IsNegativeInfinity(d) || d<int.MinValue/2) return int.MinValue/2;
|
||||
else return (int)Math.Round(d);
|
||||
}
|
||||
|
||||
private bool accountForShadowChange = false;
|
||||
public virtual Rectangle DrawingBounds {
|
||||
|
@ -187,24 +263,21 @@ namespace Greenshot.Drawing {
|
|||
DoLayout();
|
||||
}
|
||||
|
||||
void InitGrippers() {
|
||||
grippers = new Label[8];
|
||||
protected void InitGrippers() {
|
||||
grippers = new Gripper[8];
|
||||
for(int i=0; i<grippers.Length; i++) {
|
||||
grippers[i] = new Label();
|
||||
grippers[i].Name = "gripper" + i;
|
||||
grippers[i].Width = 5;
|
||||
grippers[i].Height = 5;
|
||||
grippers[i].BackColor = Color.Black;
|
||||
grippers[i] = new Gripper();
|
||||
grippers[i].Position = i;
|
||||
grippers[i].MouseDown += new MouseEventHandler(gripperMouseDown);
|
||||
grippers[i].MouseUp += new MouseEventHandler(gripperMouseUp);
|
||||
grippers[i].MouseMove += new MouseEventHandler(gripperMouseMove);
|
||||
grippers[i].Visible = false;
|
||||
grippers[i].Parent = parent;
|
||||
}
|
||||
grippers[1].Cursor = Cursors.SizeNS;
|
||||
grippers[3].Cursor = Cursors.SizeWE;
|
||||
grippers[5].Cursor = Cursors.SizeNS;
|
||||
grippers[7].Cursor = Cursors.SizeWE;
|
||||
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
|
||||
}
|
||||
|
@ -219,38 +292,38 @@ namespace Greenshot.Drawing {
|
|||
DoLayout();
|
||||
}
|
||||
|
||||
private void DoLayout() {
|
||||
protected virtual void DoLayout() {
|
||||
if (!layoutSuspended) {
|
||||
int[] xChoords = new int[]{this.Left-2,this.Left+this.Width/2-2,this.Left+this.Width-2};
|
||||
int[] yChoords = new int[]{this.Top-2,this.Top+this.Height/2-2,this.Top+this.Height-2};
|
||||
|
||||
grippers[0].Left = xChoords[0]; grippers[0].Top = yChoords[0];
|
||||
grippers[1].Left = xChoords[1]; grippers[1].Top = yChoords[0];
|
||||
grippers[2].Left = xChoords[2]; grippers[2].Top = yChoords[0];
|
||||
grippers[3].Left = xChoords[2]; grippers[3].Top = yChoords[1];
|
||||
grippers[4].Left = xChoords[2]; grippers[4].Top = yChoords[2];
|
||||
grippers[5].Left = xChoords[1]; grippers[5].Top = yChoords[2];
|
||||
grippers[6].Left = xChoords[0]; grippers[6].Top = yChoords[2];
|
||||
grippers[7].Left = xChoords[0]; grippers[7].Top = yChoords[1];
|
||||
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_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_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_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];
|
||||
|
||||
if((grippers[0].Left < grippers[4].Left && grippers[0].Top < grippers[4].Top) ||
|
||||
grippers[0].Left > grippers[4].Left && grippers[0].Top > grippers[4].Top) {
|
||||
grippers[0].Cursor = Cursors.SizeNWSE;
|
||||
grippers[2].Cursor = Cursors.SizeNESW;
|
||||
grippers[4].Cursor = Cursors.SizeNWSE;
|
||||
grippers[6].Cursor = Cursors.SizeNESW;
|
||||
} else if((grippers[0].Left > grippers[4].Left && grippers[0].Top < grippers[4].Top) ||
|
||||
grippers[0].Left < grippers[4].Left && grippers[0].Top > grippers[4].Top) {
|
||||
grippers[0].Cursor = Cursors.SizeNESW;
|
||||
grippers[2].Cursor = Cursors.SizeNWSE;
|
||||
grippers[4].Cursor = Cursors.SizeNESW;
|
||||
grippers[6].Cursor = Cursors.SizeNWSE;
|
||||
} else if (grippers[0].Left == grippers[4].Left) {
|
||||
grippers[0].Cursor = Cursors.SizeNS;
|
||||
grippers[4].Cursor = Cursors.SizeNS;
|
||||
} else if (grippers[0].Top == grippers[4].Top) {
|
||||
grippers[0].Cursor = Cursors.SizeWE;
|
||||
grippers[4].Cursor = Cursors.SizeWE;
|
||||
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].Cursor = Cursors.SizeNWSE;
|
||||
grippers[Gripper.POSITION_TOP_RIGHT].Cursor = Cursors.SizeNESW;
|
||||
grippers[Gripper.POSITION_BOTTOM_RIGHT].Cursor = Cursors.SizeNWSE;
|
||||
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) ||
|
||||
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_RIGHT].Cursor = Cursors.SizeNWSE;
|
||||
grippers[Gripper.POSITION_BOTTOM_RIGHT].Cursor = Cursors.SizeNESW;
|
||||
grippers[Gripper.POSITION_BOTTOM_LEFT].Cursor = Cursors.SizeNWSE;
|
||||
} 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_BOTTOM_RIGHT].Cursor = Cursors.SizeNS;
|
||||
} 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_BOTTOM_RIGHT].Cursor = Cursors.SizeWE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -270,31 +343,48 @@ namespace Greenshot.Drawing {
|
|||
mx = e.X;
|
||||
my = e.Y;
|
||||
Status = EditStatus.RESIZING;
|
||||
boundsBeforeResize = new Rectangle(left, top, width, height);
|
||||
boundsAfterResize = new RectangleF(boundsBeforeResize.Left, boundsBeforeResize.Top, boundsBeforeResize.Width, boundsBeforeResize.Height);
|
||||
isMadeUndoable = false;
|
||||
}
|
||||
|
||||
private void gripperMouseUp(object sender, MouseEventArgs e) {
|
||||
Status = EditStatus.IDLE;
|
||||
boundsBeforeResize = Rectangle.Empty;
|
||||
boundsAfterResize = RectangleF.Empty;
|
||||
isMadeUndoable = false;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
private void gripperMouseMove(object sender, MouseEventArgs e) {
|
||||
if(Status.Equals(EditStatus.RESIZING)) {
|
||||
// check if we already made this undoable
|
||||
if (!isMadeUndoable) {
|
||||
// don't allow another undo until we are finished with this move
|
||||
isMadeUndoable = true;
|
||||
// Make undo-able
|
||||
MakeBoundsChangeUndoable(false);
|
||||
}
|
||||
|
||||
Invalidate();
|
||||
SuspendLayout();
|
||||
Label gr = (Label)sender;
|
||||
int gripperIndex = Int16.Parse(gr.Name.Substring(7));
|
||||
if(gripperIndex <= 2) { // top row
|
||||
this.Top += e.Y - my;
|
||||
this.Height -= e.Y - my;
|
||||
} else if(gripperIndex >= 4 && gripperIndex <= 6) { // bottom row
|
||||
this.Height += e.Y - my;
|
||||
}
|
||||
if(gripperIndex >=2 && gripperIndex <= 4) { // right row
|
||||
this.Width += e.X - mx;
|
||||
} else if(gripperIndex >=6 || gripperIndex == 0) { // left row
|
||||
this.Left += e.X - mx;
|
||||
this.Width -= e.X - mx;
|
||||
}
|
||||
|
||||
Gripper gr = (Gripper)sender;
|
||||
int absX = gr.Left + e.X;
|
||||
int absY = gr.Top + e.Y;
|
||||
|
||||
// reset "workbench" rectangle to current bounds
|
||||
boundsAfterResize.X = boundsBeforeResize.X;
|
||||
boundsAfterResize.Y = boundsBeforeResize.Y;
|
||||
boundsAfterResize.Width = boundsBeforeResize.Width;
|
||||
boundsAfterResize.Height = boundsBeforeResize.Height;
|
||||
|
||||
// calculate scaled rectangle
|
||||
ScaleHelper.Scale(ref boundsAfterResize, gr.Position, new PointF(absX, absY), ScaleHelper.GetScaleOptions());
|
||||
|
||||
// apply scaled bounds to this DrawableContainer
|
||||
ApplyBounds(boundsAfterResize);
|
||||
|
||||
ResumeLayout();
|
||||
Invalidate();
|
||||
}
|
||||
|
@ -320,11 +410,11 @@ namespace Greenshot.Drawing {
|
|||
public abstract void Draw(Graphics graphics, RenderMode renderMode);
|
||||
|
||||
public virtual void DrawContent(Graphics graphics, Bitmap bmp, RenderMode renderMode, Rectangle clipRectangle) {
|
||||
if(Children.Count > 0) {
|
||||
if (Children.Count > 0) {
|
||||
if(Status != EditStatus.IDLE) {
|
||||
DrawSelectionBorder(graphics, Bounds);
|
||||
} else {
|
||||
if(clipRectangle.Width != 0 && clipRectangle.Height != 0) {
|
||||
if (clipRectangle.Width != 0 && clipRectangle.Height != 0) {
|
||||
foreach(IFilter filter in Filters) {
|
||||
if (filter.Invert) {
|
||||
filter.Apply(graphics, bmp, Bounds, renderMode);
|
||||
|
@ -359,8 +449,8 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
}
|
||||
|
||||
public void ShowGrippers() {
|
||||
for(int i=0; i<grippers.Length; i++) {
|
||||
public virtual void ShowGrippers() {
|
||||
for (int i=0; i<grippers.Length; i++) {
|
||||
if(grippers[i].Enabled) grippers[i].Show();
|
||||
else grippers[i].Hide();
|
||||
}
|
||||
|
@ -369,11 +459,26 @@ namespace Greenshot.Drawing {
|
|||
|
||||
public void HideGrippers() {
|
||||
this.SuspendLayout();
|
||||
for(int i=0; i<grippers.Length; i++) {
|
||||
for (int i=0; i<grippers.Length; i++) {
|
||||
grippers[i].Hide();
|
||||
}
|
||||
}
|
||||
|
||||
public void ResizeTo(int width, int height, int anchorPosition) {
|
||||
this.SuspendLayout();
|
||||
Width = width;
|
||||
Height = height;
|
||||
this.ResumeLayout();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make a following bounds change on this drawablecontainer undoable!
|
||||
/// </summary>
|
||||
/// <param name="allowMerge">true means allow the moves to be merged</param>
|
||||
public void MakeBoundsChangeUndoable(bool allowMerge) {
|
||||
this.parent.MakeUndoable(new DrawableContainerBoundsChangeMemento(this), allowMerge);
|
||||
}
|
||||
|
||||
public void MoveBy(int dx, int dy) {
|
||||
this.SuspendLayout();
|
||||
this.Left += dx;
|
||||
|
@ -381,9 +486,55 @@ namespace Greenshot.Drawing {
|
|||
this.ResumeLayout();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A handler for the MouseDown, used if you don't want the surface to handle this for you
|
||||
/// </summary>
|
||||
/// <param name="x">current mouse x</param>
|
||||
/// <param name="y">current mouse y</param>
|
||||
/// <returns>true if the event is handled, false if the surface needs to handle it</returns>
|
||||
public virtual bool HandleMouseDown(int x, int y) {
|
||||
Left = boundsBeforeResize.X = x;
|
||||
Top = boundsBeforeResize.Y = y;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A handler for the MouseMove, used if you don't want the surface to handle this for you
|
||||
/// </summary>
|
||||
/// <param name="x">current mouse x</param>
|
||||
/// <param name="y">current mouse y</param>
|
||||
/// <returns>true if the event is handled, false if the surface needs to handle it</returns>
|
||||
public virtual bool HandleMouseMove(int x, int y) {
|
||||
Invalidate();
|
||||
SuspendLayout();
|
||||
|
||||
// reset "workrbench" rectangle to current bounds
|
||||
boundsAfterResize.X = boundsBeforeResize.Left;
|
||||
boundsAfterResize.Y = boundsBeforeResize.Top;
|
||||
boundsAfterResize.Width = x - boundsAfterResize.Left;
|
||||
boundsAfterResize.Height = y - boundsAfterResize.Top;
|
||||
|
||||
ScaleHelper.Scale(boundsBeforeResize, x, y, ref boundsAfterResize, GetAngleRoundProcessor());
|
||||
|
||||
// apply scaled bounds to this DrawableContainer
|
||||
ApplyBounds(boundsAfterResize);
|
||||
|
||||
ResumeLayout();
|
||||
Invalidate();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A handler for the MouseUp
|
||||
/// </summary>
|
||||
/// <param name="x">current mouse x</param>
|
||||
/// <param name="y">current mouse y</param>
|
||||
public virtual void HandleMouseUp(int x, int y) {
|
||||
}
|
||||
|
||||
private void SwitchParent(Surface newParent) {
|
||||
if(parent != null) {
|
||||
for(int i=0; i<grippers.Length; i++) {
|
||||
if (parent != null) {
|
||||
for (int i=0; i<grippers.Length; i++) {
|
||||
parent.Controls.Remove(grippers[i]);
|
||||
}
|
||||
} else if(grippers == null) {
|
||||
|
@ -399,9 +550,9 @@ namespace Greenshot.Drawing {
|
|||
// drawablecontainers are regarded equal if they are of the same type and their bounds are equal. this should be sufficient.
|
||||
public override bool Equals(object obj) {
|
||||
bool ret = false;
|
||||
if(obj != null && GetType().Equals(obj.GetType())) {
|
||||
if (obj != null && GetType().Equals(obj.GetType())) {
|
||||
DrawableContainer other = obj as DrawableContainer;
|
||||
if(left==other.left && top==other.top && width==other.width && height==other.height) {
|
||||
if (left==other.left && top==other.top && width==other.width && height==other.height) {
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
|
@ -413,12 +564,23 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
|
||||
protected void OnPropertyChanged(string propertyName) {
|
||||
if(propertyChanged != null) {
|
||||
if (propertyChanged != null) {
|
||||
propertyChanged(this, new PropertyChangedEventArgs(propertyName));
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method will be called before a field is changes.
|
||||
/// Using this makes it possible to invalidate the object as is before changing.
|
||||
/// </summary>
|
||||
/// <param name="fieldToBeChanged">The field to be changed</param>
|
||||
/// <param name="newValue">The new value</param>
|
||||
public virtual void BeforeFieldChange(Field fieldToBeChanged, object newValue) {
|
||||
parent.MakeUndoable(new ChangeFieldHolderMemento(this, fieldToBeChanged), true);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the field changed event, this should invalidate the correct bounds (e.g. when shadow comes or goes more pixels!)
|
||||
/// </summary>
|
||||
|
@ -431,5 +593,101 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected virtual ScaleHelper.IDoubleProcessor GetAngleRoundProcessor() {
|
||||
return ScaleHelper.ShapeAngleRoundBehavior.Instance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add items to a context menu for the selected item
|
||||
/// </summary>
|
||||
/// <param name="menu"></param>
|
||||
public virtual void AddContextMenuItems(ContextMenuStrip menu) {
|
||||
DrawableContainerList myselfAsList = new DrawableContainerList();
|
||||
myselfAsList.Add(this);
|
||||
ILanguage lang = Language.GetInstance();
|
||||
bool push = parent.Elements.CanPushDown(myselfAsList);
|
||||
bool pull = parent.Elements.CanPullUp(myselfAsList);
|
||||
|
||||
ToolStripMenuItem item;
|
||||
|
||||
// Pull "up"
|
||||
if (pull) {
|
||||
item = new ToolStripMenuItem(lang.GetString(LangKey.editor_uptotop));
|
||||
item.Click += delegate {
|
||||
parent.Elements.PullElementsToTop(myselfAsList);
|
||||
parent.Elements.Invalidate();
|
||||
};
|
||||
menu.Items.Add(item);
|
||||
item = new ToolStripMenuItem(lang.GetString(LangKey.editor_uponelevel));
|
||||
item.Click += delegate {
|
||||
parent.Elements.PullElementsUp(myselfAsList);
|
||||
parent.Elements.Invalidate();
|
||||
};
|
||||
menu.Items.Add(item);
|
||||
}
|
||||
// Push "down"
|
||||
if (push) {
|
||||
item = new ToolStripMenuItem(lang.GetString(LangKey.editor_downtobottom));
|
||||
item.Click += delegate {
|
||||
parent.Elements.PushElementsToBottom(myselfAsList);
|
||||
parent.Elements.Invalidate();
|
||||
};
|
||||
menu.Items.Add(item);
|
||||
item = new ToolStripMenuItem(lang.GetString(LangKey.editor_downonelevel));
|
||||
item.Click += delegate {
|
||||
parent.Elements.PushElementsDown(myselfAsList);
|
||||
parent.Elements.Invalidate();
|
||||
};
|
||||
menu.Items.Add(item);
|
||||
}
|
||||
|
||||
// Duplicate
|
||||
item = new ToolStripMenuItem(lang.GetString(LangKey.editor_duplicate));
|
||||
item.Click += delegate {
|
||||
DrawableContainerList dcs = myselfAsList.Clone();
|
||||
dcs.Parent = parent;
|
||||
dcs.MoveBy(10,10);
|
||||
parent.AddElements(dcs);
|
||||
parent.DeselectAllElements();
|
||||
parent.SelectElements(dcs);
|
||||
};
|
||||
menu.Items.Add(item);
|
||||
|
||||
// Copy
|
||||
item = new ToolStripMenuItem(lang.GetString(LangKey.editor_copytoclipboard));
|
||||
item.Image = ((System.Drawing.Image)(editorFormResources.GetObject("copyToolStripMenuItem.Image")));
|
||||
item.Click += delegate {
|
||||
ClipboardHelper.SetClipboardData(typeof(DrawableContainerList), myselfAsList);
|
||||
};
|
||||
menu.Items.Add(item);
|
||||
|
||||
// Cut
|
||||
item = new ToolStripMenuItem(lang.GetString(LangKey.editor_cuttoclipboard));
|
||||
item.Image = ((System.Drawing.Image)(editorFormResources.GetObject("editor_cuttoclipboard.Image")));
|
||||
item.Click += delegate {
|
||||
ClipboardHelper.SetClipboardData(typeof(DrawableContainerList), myselfAsList);
|
||||
parent.RemoveElement(this, true);
|
||||
};
|
||||
menu.Items.Add(item);
|
||||
|
||||
// Delete
|
||||
item = new ToolStripMenuItem(lang.GetString(LangKey.editor_deleteelement));
|
||||
item.Image = ((System.Drawing.Image)(editorFormResources.GetObject("removeObjectToolStripMenuItem.Image")));
|
||||
item.Click += delegate {
|
||||
parent.RemoveElement(this, true);
|
||||
};
|
||||
menu.Items.Add(item);
|
||||
}
|
||||
|
||||
public virtual void ShowContextMenu(MouseEventArgs e) {
|
||||
if (conf.isExperimentalFeatureEnabled("Contextmenu")) {
|
||||
ContextMenuStrip menu = new ContextMenuStrip();
|
||||
AddContextMenuItems(menu);
|
||||
if (menu.Items.Count > 0) {
|
||||
menu.Show(parent, e.Location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue