Merge pull request #5902 from Jaex/master

fixed #5899: Added auto copy image to clipboard option to image editor
This commit is contained in:
Jaex 2021-10-23 03:30:56 +03:00 committed by GitHub
commit e0566aff66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 69 additions and 34 deletions

View file

@ -59,7 +59,7 @@ public sealed class RegionCaptureForm : Form
public RegionCaptureMode Mode { get; private set; }
public bool IsEditorMode => Mode == RegionCaptureMode.Editor || Mode == RegionCaptureMode.TaskEditor;
public bool IsAnnotationMode => Mode == RegionCaptureMode.Annotation || IsEditorMode;
public bool IsModified => ShapeManager != null && ShapeManager.IsModified;
public bool IsImageModified => ShapeManager != null && ShapeManager.IsImageModified;
public Point CurrentPosition { get; private set; }
public Point PanningStrech = new Point();
@ -285,6 +285,7 @@ private void Prepare(Bitmap canvas = null)
ShapeManager = new ShapeManager(this);
ShapeManager.WindowCaptureMode = !IsEditorMode && Options.DetectWindows;
ShapeManager.IncludeControls = Options.DetectControls;
ShapeManager.ImageModified += ShapeManager_ImageModified;
InitBackground(canvas);
@ -302,6 +303,15 @@ private void Prepare(Bitmap canvas = null)
}
}
private void ShapeManager_ImageModified()
{
if (Options.EditorAutoCopyImage && !IsClosing && IsEditorMode)
{
Bitmap bmp = GetResultImage();
CopyImageRequested(bmp);
}
}
internal void InitBackground(Bitmap canvas, bool centerCanvas = true)
{
if (Canvas != null) Canvas.Dispose();
@ -543,7 +553,7 @@ internal bool ShowExitConfirmation()
{
bool result = true;
if (IsModified)
if (IsImageModified)
{
Pause();
result = MessageBox.Show(this, Resources.RegionCaptureForm_ShowExitConfirmation_Text, Resources.RegionCaptureForm_ShowExitConfirmation_ShareXImageEditor,
@ -1415,7 +1425,7 @@ private Bitmap ReceiveImageForTask()
{
Bitmap bmp = GetResultImage();
ShapeManager.IsModified = false;
ShapeManager.IsImageModified = false;
if (Options.AutoCloseEditorOnTask)
{

View file

@ -90,6 +90,7 @@ public class RegionCaptureOptions
// Image editor
public ImageEditorStartMode ImageEditorStartMode = ImageEditorStartMode.AutoSize;
public WindowState ImageEditorWindowState = new WindowState();
public bool EditorAutoCopyImage = true;
public bool AutoCloseEditorOnTask = false;
public bool ShowEditorPanTip = true;
public ImageInterpolationMode ImageEditorResizeInterpolationMode = ImageInterpolationMode.Bicubic;

View file

@ -243,6 +243,11 @@ public virtual void OnCreating()
public virtual void OnCreated()
{
InitialSize = Rectangle.Size;
if (ShapeCategory == ShapeCategory.Drawing || ShapeCategory == ShapeCategory.Effect)
{
Manager.OnImageModified();
}
}
public virtual void OnMoving()

View file

@ -49,8 +49,8 @@ public override void ShowNodes()
public override void OnCreating()
{
Manager.IsMoving = true;
UpdateCursor(Manager.GetSelectedCursor().Handle, InputManager.ClientMousePosition);
OnCreated();
}
public override void OnDraw(Graphics g)

View file

@ -57,9 +57,9 @@ private set
public override void OnCreated()
{
base.OnCreated();
AutoSize(true);
TailPosition = Rectangle.Location.Add(0, Rectangle.Height + 30);
OnCreated(false);
}
protected override void UseLightResizeNodes()

View file

@ -75,6 +75,7 @@ public override void OnCreating()
Rectangle = new Rectangle(new Point(pos.X - (Rectangle.Width / 2), pos.Y - (Rectangle.Height / 2)), Rectangle.Size);
int tailOffset = 5;
TailPosition = Rectangle.Location.Add(Rectangle.Width + tailOffset, Rectangle.Height + tailOffset);
OnCreated();
}
protected override void UseLightResizeNodes()

View file

@ -115,7 +115,16 @@ public override void OnCreating()
public override void OnCreated()
{
AutoSize(true);
OnCreated(true);
}
protected void OnCreated(bool autoSize)
{
if (autoSize)
{
AutoSize(true);
}
base.OnCreated();
ShowNodes();
}

View file

@ -255,7 +255,7 @@ public bool IsPanning
public bool IsSnapResizing { get; private set; }
public bool IsRenderingOutput { get; private set; }
public Point RenderOffset { get; private set; }
public bool IsModified { get; internal set; }
public bool IsImageModified { get; internal set; }
public InputManager InputManager { get; private set; } = new InputManager();
public List<SimpleWindowInfo> Windows { get; set; }
@ -306,6 +306,7 @@ public bool NodesVisible
public event Action<BaseShape> CurrentShapeChanged;
public event Action<ShapeType> CurrentShapeTypeChanged;
public event Action<BaseShape> ShapeCreated;
public event Action ImageModified;
internal RegionCaptureForm Form { get; private set; }
@ -378,6 +379,29 @@ public ShapeManager(RegionCaptureForm form)
}
}
private void OnCurrentShapeChanged(BaseShape shape)
{
CurrentShapeChanged?.Invoke(shape);
}
private void OnCurrentShapeTypeChanged(ShapeType shapeType)
{
CurrentShapeTypeChanged?.Invoke(shapeType);
}
private void OnShapeCreated(BaseShape shape)
{
ShapeCreated?.Invoke(shape);
}
internal void OnImageModified()
{
OrderStepShapes();
IsImageModified = true;
ImageModified?.Invoke();
}
private void form_Shown(object sender, EventArgs e)
{
if (Form.IsAnnotationMode)
@ -887,8 +911,6 @@ private void RunAction(RegionCaptureAction action)
public void Update()
{
OrderStepShapes();
BaseShape shape = CurrentShape;
if (shape != null)
@ -1087,11 +1109,6 @@ private void AddShape(BaseShape shape)
{
Shapes.Add(shape);
CurrentShape = shape;
if (shape.ShapeCategory == ShapeCategory.Drawing || shape.ShapeCategory == ShapeCategory.Effect)
{
IsModified = true;
}
}
private BaseShape CreateShape()
@ -1419,7 +1436,7 @@ public void DeleteShape(BaseShape shape)
if (shape.ShapeCategory == ShapeCategory.Drawing || shape.ShapeCategory == ShapeCategory.Effect)
{
IsModified = true;
OnImageModified();
}
UpdateMenu();
@ -1447,7 +1464,7 @@ private void DeleteAllShapes()
Shapes.Clear();
DeselectCurrentShape();
IsModified = true;
OnImageModified();
}
}
@ -1754,7 +1771,7 @@ public void UpdateCanvas(Bitmap canvas, bool centerCanvas = true)
effect.OnMoved();
}
IsModified = true;
OnImageModified();
}
public void CropArea(Rectangle rect)
@ -2103,21 +2120,6 @@ private bool PickColor(Color currentColor, out Color newColor)
return ColorPickerForm.PickColor(currentColor, out newColor, Form, openScreenColorPicker, Options.ColorPickerOptions);
}
private void OnCurrentShapeChanged(BaseShape shape)
{
CurrentShapeChanged?.Invoke(shape);
}
private void OnCurrentShapeTypeChanged(ShapeType shapeType)
{
CurrentShapeTypeChanged?.Invoke(shapeType);
}
private void OnShapeCreated(BaseShape shape)
{
ShapeCreated?.Invoke(shape);
}
public void Dispose()
{
DeleteAllShapes();

View file

@ -885,6 +885,13 @@ internal void CreateToolbar()
(sender, e) => Options.ImageEditorStartMode = (ImageEditorStartMode)tscbImageEditorStartMode.Content.SelectedIndex;
tsddbOptions.DropDownItems.Add(tscbImageEditorStartMode);
// TODO: Translate
ToolStripMenuItem tsmiEditorAutoCopyImage = new ToolStripMenuItem("Auto copy image to clipboard");
tsmiEditorAutoCopyImage.Checked = Options.EditorAutoCopyImage;
tsmiEditorAutoCopyImage.CheckOnClick = true;
tsmiEditorAutoCopyImage.Click += (sender, e) => Options.EditorAutoCopyImage = tsmiEditorAutoCopyImage.Checked;
tsddbOptions.DropDownItems.Add(tsmiEditorAutoCopyImage);
ToolStripMenuItem tsmiAutoCloseEditorOnTask = new ToolStripMenuItem(Resources.ShapeManager_CreateToolbar_AutoCloseEditorOnTask);
tsmiAutoCloseEditorOnTask.Checked = Options.AutoCloseEditorOnTask;
tsmiAutoCloseEditorOnTask.CheckOnClick = true;

View file

@ -98,7 +98,7 @@ protected ImageInfo ExecuteRegionCapture(TaskSettings taskSettings)
if (imageInfo.Image != null)
{
if (form.IsModified)
if (form.IsImageModified)
{
AllowAnnotation = false;
}