2013-11-03 23:53:49 +13:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2017-01-11 21:39:40 +13:00
|
|
|
|
Copyright (c) 2007-2017 ShareX Team
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
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 2
|
|
|
|
|
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, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
|
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endregion License Information (GPL v3)
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
using ShareX.HelpersLib;
|
2015-07-17 07:07:06 +12:00
|
|
|
|
using System;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
namespace ShareX.ScreenCaptureLib
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-10-01 20:58:59 +13:00
|
|
|
|
internal partial class ShapeManager : IDisposable
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-03 20:24:01 +12:00
|
|
|
|
public List<BaseShape> Shapes { get; private set; } = new List<BaseShape>();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-05-12 05:16:29 +12:00
|
|
|
|
private BaseShape currentShape;
|
2016-05-03 20:24:01 +12:00
|
|
|
|
|
2016-05-12 05:16:29 +12:00
|
|
|
|
public BaseShape CurrentShape
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return currentShape;
|
|
|
|
|
}
|
|
|
|
|
private set
|
|
|
|
|
{
|
|
|
|
|
currentShape = value;
|
2016-05-21 09:09:09 +12:00
|
|
|
|
|
|
|
|
|
if (currentShape != null)
|
|
|
|
|
{
|
2016-08-03 17:35:34 +12:00
|
|
|
|
currentShape.OnConfigSave();
|
2016-05-21 09:09:09 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-12 05:16:29 +12:00
|
|
|
|
OnCurrentShapeChanged(currentShape);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ShapeType currentShapeType;
|
2016-05-07 03:01:23 +12:00
|
|
|
|
|
|
|
|
|
public ShapeType CurrentShapeType
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return currentShapeType;
|
|
|
|
|
}
|
|
|
|
|
private set
|
|
|
|
|
{
|
|
|
|
|
currentShapeType = value;
|
2016-05-23 11:18:29 +12:00
|
|
|
|
|
2016-09-04 23:23:21 +12:00
|
|
|
|
if (form.IsAnnotationMode)
|
2016-06-12 21:52:47 +12:00
|
|
|
|
{
|
2016-06-12 23:37:03 +12:00
|
|
|
|
if (IsCurrentShapeTypeRegion)
|
|
|
|
|
{
|
|
|
|
|
Config.LastRegionTool = CurrentShapeType;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Config.LastAnnotationTool = CurrentShapeType;
|
|
|
|
|
}
|
2016-06-12 21:52:47 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-16 08:48:27 +12:00
|
|
|
|
DeselectCurrentShape();
|
2016-05-23 11:18:29 +12:00
|
|
|
|
|
2016-05-12 05:16:29 +12:00
|
|
|
|
OnCurrentShapeTypeChanged(currentShapeType);
|
2016-05-07 03:01:23 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-03 21:35:10 +12:00
|
|
|
|
|
2016-05-03 20:24:01 +12:00
|
|
|
|
public Rectangle CurrentRectangle
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-05-03 20:24:01 +12:00
|
|
|
|
if (CurrentShape != null)
|
|
|
|
|
{
|
|
|
|
|
return CurrentShape.Rectangle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Rectangle.Empty;
|
|
|
|
|
}
|
2016-05-03 19:46:45 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-09 10:24:17 +12:00
|
|
|
|
public bool IsCurrentShapeValid => CurrentShape != null && CurrentShape.IsValidShape;
|
2016-05-23 11:18:29 +12:00
|
|
|
|
|
2016-08-09 10:24:17 +12:00
|
|
|
|
public BaseShape[] Regions => Shapes.OfType<BaseRegionShape>().ToArray();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-08-09 10:24:17 +12:00
|
|
|
|
public BaseShape[] ValidRegions => Regions.Where(x => x.IsValidShape).ToArray();
|
2016-05-03 22:06:58 +12:00
|
|
|
|
|
2016-08-09 10:24:17 +12:00
|
|
|
|
public BaseDrawingShape[] DrawingShapes => Shapes.OfType<BaseDrawingShape>().ToArray();
|
2016-05-11 10:17:51 +12:00
|
|
|
|
|
2016-08-09 10:24:17 +12:00
|
|
|
|
public BaseEffectShape[] EffectShapes => Shapes.OfType<BaseEffectShape>().ToArray();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2017-04-03 19:55:54 +12:00
|
|
|
|
private BaseShape currentHoverShape;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2017-04-03 19:55:54 +12:00
|
|
|
|
public BaseShape CurrentHoverShape
|
2016-05-03 22:48:37 +12:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-04-03 19:55:54 +12:00
|
|
|
|
return currentHoverShape;
|
|
|
|
|
}
|
|
|
|
|
private set
|
|
|
|
|
{
|
2017-04-08 00:09:18 +12:00
|
|
|
|
if (currentHoverShape != null)
|
2017-04-03 19:55:54 +12:00
|
|
|
|
{
|
2017-04-08 00:09:18 +12:00
|
|
|
|
if (PreviousHoverRectangle == Rectangle.Empty || PreviousHoverRectangle != currentHoverShape.Rectangle)
|
|
|
|
|
{
|
|
|
|
|
PreviousHoverRectangle = currentHoverShape.Rectangle;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PreviousHoverRectangle = Rectangle.Empty;
|
2017-04-03 19:55:54 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentHoverShape = value;
|
2016-05-03 22:48:37 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-03 19:55:54 +12:00
|
|
|
|
public Rectangle PreviousHoverRectangle { get; private set; }
|
|
|
|
|
|
|
|
|
|
public bool IsCurrentHoverShapeValid => CurrentHoverShape != null && CurrentHoverShape.IsValidShape;
|
|
|
|
|
|
|
|
|
|
public bool IsCurrentShapeTypeRegion => IsShapeTypeRegion(CurrentShapeType);
|
|
|
|
|
|
2016-08-06 01:35:44 +12:00
|
|
|
|
public bool IsCreating { get; set; }
|
2016-08-20 01:16:40 +12:00
|
|
|
|
public bool IsMoving { get; set; }
|
2017-10-17 12:53:54 +13:00
|
|
|
|
public bool IsPanning { get; set; }
|
2016-08-06 01:35:44 +12:00
|
|
|
|
public bool IsResizing { get; set; }
|
2016-06-11 21:48:58 +12:00
|
|
|
|
public bool IsCornerMoving { get; private set; }
|
2016-08-06 00:24:29 +12:00
|
|
|
|
public bool IsProportionalResizing { get; private set; }
|
2015-08-23 01:13:38 +12:00
|
|
|
|
public bool IsSnapResizing { get; private set; }
|
2017-05-24 10:53:57 +12:00
|
|
|
|
public bool IsRenderingOutput { get; private set; }
|
2015-08-23 01:13:38 +12:00
|
|
|
|
|
2017-08-12 00:32:29 +12:00
|
|
|
|
private bool isAnnotated;
|
2017-05-16 04:54:04 +12:00
|
|
|
|
|
2017-08-12 00:32:29 +12:00
|
|
|
|
public bool IsAnnotated => isAnnotated || DrawingShapes.Where(x => x.ShapeType != ShapeType.DrawingCursor).Count() > 0 || EffectShapes.Length > 0;
|
2017-05-16 04:54:04 +12:00
|
|
|
|
|
2017-10-24 10:40:37 +13:00
|
|
|
|
public InputManager InputManager { get; private set; } = new InputManager();
|
2015-09-25 18:39:08 +12:00
|
|
|
|
public List<SimpleWindowInfo> Windows { get; set; }
|
2013-11-03 23:53:49 +13:00
|
|
|
|
public bool WindowCaptureMode { get; set; }
|
2014-07-10 09:44:08 +12:00
|
|
|
|
public bool IncludeControls { get; set; }
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-06-22 19:51:57 +12:00
|
|
|
|
public RegionCaptureOptions Config { get; private set; }
|
2016-05-21 04:07:29 +12:00
|
|
|
|
|
2016-08-09 10:24:17 +12:00
|
|
|
|
public AnnotationOptions AnnotationOptions => Config.AnnotationOptions;
|
2016-05-21 05:34:45 +12:00
|
|
|
|
|
2016-08-25 00:52:09 +12:00
|
|
|
|
public List<ResizeNode> ResizeNodes { get; private set; }
|
2016-08-06 01:17:53 +12:00
|
|
|
|
|
|
|
|
|
private bool nodesVisible;
|
|
|
|
|
|
|
|
|
|
public bool NodesVisible
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return nodesVisible;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
nodesVisible = value;
|
|
|
|
|
|
|
|
|
|
if (!nodesVisible)
|
|
|
|
|
{
|
2016-08-17 20:35:06 +12:00
|
|
|
|
foreach (ResizeNode node in ResizeNodes)
|
2016-08-06 01:17:53 +12:00
|
|
|
|
{
|
2016-08-25 00:52:09 +12:00
|
|
|
|
node.Visible = false;
|
2016-08-06 01:17:53 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
BaseShape shape = CurrentShape;
|
|
|
|
|
|
|
|
|
|
if (shape != null)
|
|
|
|
|
{
|
2016-08-06 01:35:44 +12:00
|
|
|
|
shape.OnNodePositionUpdate();
|
|
|
|
|
shape.OnNodeVisible();
|
2016-08-06 01:17:53 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-17 20:35:06 +12:00
|
|
|
|
public bool IsCursorOnNode => NodesVisible && ResizeNodes.Any(node => node.IsCursorHover);
|
2016-08-06 01:17:53 +12:00
|
|
|
|
|
2016-05-12 05:16:29 +12:00
|
|
|
|
public event Action<BaseShape> CurrentShapeChanged;
|
2016-05-08 08:31:43 +12:00
|
|
|
|
public event Action<ShapeType> CurrentShapeTypeChanged;
|
2016-11-19 13:03:44 +13:00
|
|
|
|
public event Action<BaseShape> ShapeCreated;
|
2016-05-08 08:31:43 +12:00
|
|
|
|
|
2016-09-05 04:22:27 +12:00
|
|
|
|
private RegionCaptureForm form;
|
2016-10-01 06:37:01 +13:00
|
|
|
|
private bool isLeftPressed, isRightPressed, isUpPressed, isDownPressed;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-09-05 04:22:27 +12:00
|
|
|
|
public ShapeManager(RegionCaptureForm form)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-14 19:03:16 +12:00
|
|
|
|
this.form = form;
|
2016-05-21 04:07:29 +12:00
|
|
|
|
Config = form.Config;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-08-25 00:52:09 +12:00
|
|
|
|
ResizeNodes = new List<ResizeNode>();
|
2016-08-06 01:17:53 +12:00
|
|
|
|
|
2016-08-25 00:52:09 +12:00
|
|
|
|
for (int i = 0; i < 9; i++)
|
2016-08-06 01:17:53 +12:00
|
|
|
|
{
|
2016-08-17 20:35:06 +12:00
|
|
|
|
ResizeNode node = new ResizeNode();
|
2016-08-17 18:35:38 +12:00
|
|
|
|
form.DrawableObjects.Add(node);
|
2016-08-25 00:52:09 +12:00
|
|
|
|
ResizeNodes.Add(node);
|
2016-08-06 01:17:53 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-17 20:35:06 +12:00
|
|
|
|
ResizeNodes[(int)NodePosition.BottomRight].Order = 10;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-10-01 03:48:31 +13:00
|
|
|
|
form.Shown += form_Shown;
|
2016-06-11 22:34:27 +12:00
|
|
|
|
form.LostFocus += form_LostFocus;
|
2016-05-15 19:12:53 +12:00
|
|
|
|
form.MouseDown += form_MouseDown;
|
|
|
|
|
form.MouseUp += form_MouseUp;
|
2016-05-20 10:13:19 +12:00
|
|
|
|
form.MouseDoubleClick += form_MouseDoubleClick;
|
|
|
|
|
form.MouseWheel += form_MouseWheel;
|
2016-05-15 19:12:53 +12:00
|
|
|
|
form.KeyDown += form_KeyDown;
|
|
|
|
|
form.KeyUp += form_KeyUp;
|
2016-05-04 01:28:15 +12:00
|
|
|
|
|
2016-05-12 05:16:29 +12:00
|
|
|
|
CurrentShape = null;
|
2016-06-12 23:28:01 +12:00
|
|
|
|
|
2016-09-04 23:23:21 +12:00
|
|
|
|
if (form.Mode == RegionCaptureMode.Annotation)
|
2016-06-12 23:28:01 +12:00
|
|
|
|
{
|
|
|
|
|
CurrentShapeType = Config.LastRegionTool;
|
|
|
|
|
}
|
2017-03-08 02:49:01 +13:00
|
|
|
|
else if (form.IsEditorMode)
|
2016-09-04 23:23:21 +12:00
|
|
|
|
{
|
|
|
|
|
CurrentShapeType = Config.LastAnnotationTool;
|
|
|
|
|
}
|
2016-06-12 23:28:01 +12:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CurrentShapeType = ShapeType.RegionRectangle;
|
|
|
|
|
}
|
2016-05-07 03:01:23 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-01 03:48:31 +13:00
|
|
|
|
private void form_Shown(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-10-01 06:37:01 +13:00
|
|
|
|
if (form.IsAnnotationMode)
|
|
|
|
|
{
|
2016-11-01 00:30:05 +13:00
|
|
|
|
CreateToolbar();
|
2016-10-01 06:37:01 +13:00
|
|
|
|
}
|
2016-10-01 03:48:31 +13:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-11 22:34:27 +12:00
|
|
|
|
private void form_LostFocus(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-08-06 00:24:29 +12:00
|
|
|
|
IsCornerMoving = IsProportionalResizing = IsSnapResizing = false;
|
2016-06-11 22:34:27 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-15 19:12:53 +12:00
|
|
|
|
private void form_MouseDown(object sender, MouseEventArgs e)
|
2016-05-05 00:53:18 +12:00
|
|
|
|
{
|
|
|
|
|
if (e.Button == MouseButtons.Left)
|
|
|
|
|
{
|
|
|
|
|
if (!IsCreating)
|
|
|
|
|
{
|
2016-08-06 00:10:05 +12:00
|
|
|
|
StartRegionSelection();
|
2016-05-05 00:53:18 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-17 12:53:54 +13:00
|
|
|
|
else if (e.Button == MouseButtons.Middle)
|
|
|
|
|
{
|
|
|
|
|
if (form.IsEditorMode)
|
|
|
|
|
{
|
|
|
|
|
StartPanning();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-05 00:53:18 +12:00
|
|
|
|
}
|
2016-05-04 23:04:26 +12:00
|
|
|
|
|
2016-05-15 19:12:53 +12:00
|
|
|
|
private void form_MouseUp(object sender, MouseEventArgs e)
|
2016-05-05 00:53:18 +12:00
|
|
|
|
{
|
|
|
|
|
if (e.Button == MouseButtons.Left)
|
|
|
|
|
{
|
|
|
|
|
if (IsMoving || IsCreating)
|
|
|
|
|
{
|
|
|
|
|
EndRegionSelection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (e.Button == MouseButtons.Right)
|
|
|
|
|
{
|
|
|
|
|
if (IsCreating)
|
|
|
|
|
{
|
2016-05-23 10:42:52 +12:00
|
|
|
|
DeleteCurrentShape();
|
2016-05-05 00:53:18 +12:00
|
|
|
|
EndRegionSelection();
|
|
|
|
|
}
|
2016-09-04 23:23:21 +12:00
|
|
|
|
else if (form.IsAnnotationMode)
|
2016-05-05 00:53:18 +12:00
|
|
|
|
{
|
2016-10-31 23:53:45 +13:00
|
|
|
|
RunAction(Config.RegionCaptureActionRightClick);
|
2016-05-05 00:53:18 +12:00
|
|
|
|
}
|
2016-05-23 10:42:52 +12:00
|
|
|
|
else if (IsShapeIntersect())
|
2016-05-16 20:06:13 +12:00
|
|
|
|
{
|
|
|
|
|
DeleteIntersectShape();
|
|
|
|
|
}
|
2016-05-14 19:03:16 +12:00
|
|
|
|
else
|
|
|
|
|
{
|
2016-09-19 03:28:57 +12:00
|
|
|
|
form.Close();
|
2016-05-14 19:03:16 +12:00
|
|
|
|
}
|
2016-05-05 00:53:18 +12:00
|
|
|
|
}
|
2016-05-20 03:32:25 +12:00
|
|
|
|
else if (e.Button == MouseButtons.Middle)
|
|
|
|
|
{
|
2017-10-17 12:53:54 +13:00
|
|
|
|
if (form.IsEditorMode)
|
|
|
|
|
{
|
|
|
|
|
EndPanning();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
RunAction(Config.RegionCaptureActionMiddleClick);
|
|
|
|
|
}
|
2016-05-20 03:32:25 +12:00
|
|
|
|
}
|
2016-06-12 23:37:03 +12:00
|
|
|
|
else if (e.Button == MouseButtons.XButton1)
|
|
|
|
|
{
|
2016-10-31 23:53:45 +13:00
|
|
|
|
RunAction(Config.RegionCaptureActionX1Click);
|
2016-06-14 04:48:41 +12:00
|
|
|
|
}
|
|
|
|
|
else if (e.Button == MouseButtons.XButton2)
|
|
|
|
|
{
|
2016-10-31 23:53:45 +13:00
|
|
|
|
RunAction(Config.RegionCaptureActionX2Click);
|
2016-06-12 23:37:03 +12:00
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-20 10:13:19 +12:00
|
|
|
|
private void form_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Button == MouseButtons.Left)
|
|
|
|
|
{
|
2016-06-25 07:09:31 +12:00
|
|
|
|
if (IsCurrentShapeTypeRegion && ValidRegions.Length > 0)
|
2016-05-20 10:13:19 +12:00
|
|
|
|
{
|
2016-06-25 07:09:31 +12:00
|
|
|
|
form.UpdateRegionPath();
|
2016-05-20 10:13:19 +12:00
|
|
|
|
form.Close(RegionResult.Region);
|
|
|
|
|
}
|
2016-06-11 01:54:54 +12:00
|
|
|
|
else if (CurrentShape != null && !IsCreating)
|
2016-05-20 10:13:19 +12:00
|
|
|
|
{
|
2016-08-03 17:35:34 +12:00
|
|
|
|
CurrentShape.OnDoubleClicked();
|
2016-05-20 10:13:19 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void form_MouseWheel(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
2016-09-04 23:23:21 +12:00
|
|
|
|
if (Control.ModifierKeys.HasFlag(Keys.Control) && form.Mode == RegionCaptureMode.Annotation)
|
2016-05-20 10:13:19 +12:00
|
|
|
|
{
|
|
|
|
|
if (e.Delta > 0)
|
|
|
|
|
{
|
2016-08-31 23:55:30 +12:00
|
|
|
|
CurrentShapeType = CurrentShapeType.Previous<ShapeType>();
|
2016-05-20 10:13:19 +12:00
|
|
|
|
}
|
|
|
|
|
else if (e.Delta < 0)
|
|
|
|
|
{
|
2016-08-31 23:55:30 +12:00
|
|
|
|
CurrentShapeType = CurrentShapeType.Next<ShapeType>();
|
2016-05-20 10:13:19 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-31 23:55:30 +12:00
|
|
|
|
else
|
2016-05-20 10:13:19 +12:00
|
|
|
|
{
|
|
|
|
|
if (e.Delta > 0)
|
|
|
|
|
{
|
2016-08-31 23:55:30 +12:00
|
|
|
|
Config.MagnifierPixelCount = Math.Min(Config.MagnifierPixelCount + 2, RegionCaptureOptions.MagnifierPixelCountMaximum);
|
2016-05-20 10:13:19 +12:00
|
|
|
|
}
|
|
|
|
|
else if (e.Delta < 0)
|
|
|
|
|
{
|
2016-08-31 23:55:30 +12:00
|
|
|
|
Config.MagnifierPixelCount = Math.Max(Config.MagnifierPixelCount - 2, RegionCaptureOptions.MagnifierPixelCountMinimum);
|
2016-05-20 10:13:19 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-15 19:12:53 +12:00
|
|
|
|
private void form_KeyDown(object sender, KeyEventArgs e)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2015-08-05 00:40:25 +12:00
|
|
|
|
switch (e.KeyCode)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-08-15 08:32:01 +12:00
|
|
|
|
case Keys.ControlKey:
|
|
|
|
|
IsCornerMoving = true;
|
|
|
|
|
break;
|
|
|
|
|
case Keys.ShiftKey:
|
|
|
|
|
IsProportionalResizing = true;
|
|
|
|
|
break;
|
|
|
|
|
case Keys.Menu:
|
|
|
|
|
IsSnapResizing = true;
|
|
|
|
|
break;
|
2016-08-05 23:37:20 +12:00
|
|
|
|
case Keys.Left:
|
|
|
|
|
case Keys.A:
|
|
|
|
|
isLeftPressed = true;
|
|
|
|
|
break;
|
|
|
|
|
case Keys.Right:
|
|
|
|
|
case Keys.D:
|
|
|
|
|
isRightPressed = true;
|
|
|
|
|
break;
|
|
|
|
|
case Keys.Up:
|
|
|
|
|
case Keys.W:
|
|
|
|
|
isUpPressed = true;
|
|
|
|
|
break;
|
|
|
|
|
case Keys.Down:
|
|
|
|
|
case Keys.S:
|
|
|
|
|
isDownPressed = true;
|
|
|
|
|
break;
|
2016-05-27 08:55:10 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-16 08:48:27 +12:00
|
|
|
|
switch (e.KeyData)
|
|
|
|
|
{
|
|
|
|
|
case Keys.Insert:
|
|
|
|
|
if (IsCreating)
|
|
|
|
|
{
|
|
|
|
|
EndRegionSelection();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
StartRegionSelection();
|
|
|
|
|
}
|
|
|
|
|
break;
|
2016-12-02 04:11:26 +13:00
|
|
|
|
case Keys.Delete:
|
|
|
|
|
DeleteCurrentShape();
|
|
|
|
|
|
|
|
|
|
if (IsCreating)
|
|
|
|
|
{
|
|
|
|
|
EndRegionSelection();
|
|
|
|
|
}
|
|
|
|
|
break;
|
2016-12-15 05:38:07 +13:00
|
|
|
|
case Keys.Shift | Keys.Delete:
|
2016-12-02 04:15:45 +13:00
|
|
|
|
DeleteAllShapes();
|
|
|
|
|
break;
|
2016-12-02 04:11:26 +13:00
|
|
|
|
case Keys.F1:
|
|
|
|
|
Config.ShowHotkeys = !Config.ShowHotkeys;
|
2017-10-06 09:54:06 +13:00
|
|
|
|
if (tsmiTips != null)
|
2017-09-22 12:58:33 +12:00
|
|
|
|
tsmiTips.Checked = Config.ShowHotkeys;
|
2016-12-02 04:11:26 +13:00
|
|
|
|
break;
|
2016-08-16 08:48:27 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-04 23:23:21 +12:00
|
|
|
|
if (!IsCreating)
|
2016-05-27 08:55:10 +12:00
|
|
|
|
{
|
2016-09-04 23:23:21 +12:00
|
|
|
|
if (form.Mode == RegionCaptureMode.Annotation)
|
2016-05-27 08:55:10 +12:00
|
|
|
|
{
|
2016-09-04 23:23:21 +12:00
|
|
|
|
switch (e.KeyData)
|
|
|
|
|
{
|
|
|
|
|
case Keys.Tab:
|
|
|
|
|
SwapShapeType();
|
|
|
|
|
break;
|
|
|
|
|
case Keys.NumPad0:
|
|
|
|
|
CurrentShapeType = ShapeType.RegionRectangle;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (form.IsAnnotationMode)
|
|
|
|
|
{
|
|
|
|
|
switch (e.KeyData)
|
|
|
|
|
{
|
|
|
|
|
case Keys.NumPad1:
|
|
|
|
|
CurrentShapeType = ShapeType.DrawingRectangle;
|
|
|
|
|
break;
|
|
|
|
|
case Keys.NumPad2:
|
2016-12-01 04:17:12 +13:00
|
|
|
|
CurrentShapeType = ShapeType.DrawingEllipse;
|
2016-09-04 23:23:21 +12:00
|
|
|
|
break;
|
|
|
|
|
case Keys.NumPad3:
|
2016-12-01 04:17:12 +13:00
|
|
|
|
CurrentShapeType = ShapeType.DrawingFreehand;
|
2016-09-04 23:23:21 +12:00
|
|
|
|
break;
|
|
|
|
|
case Keys.NumPad4:
|
|
|
|
|
CurrentShapeType = ShapeType.DrawingLine;
|
|
|
|
|
break;
|
|
|
|
|
case Keys.NumPad5:
|
|
|
|
|
CurrentShapeType = ShapeType.DrawingArrow;
|
|
|
|
|
break;
|
|
|
|
|
case Keys.NumPad6:
|
2017-02-16 13:49:13 +13:00
|
|
|
|
CurrentShapeType = ShapeType.DrawingTextOutline;
|
2016-09-04 23:23:21 +12:00
|
|
|
|
break;
|
|
|
|
|
case Keys.NumPad7:
|
|
|
|
|
CurrentShapeType = ShapeType.DrawingStep;
|
|
|
|
|
break;
|
|
|
|
|
case Keys.NumPad8:
|
|
|
|
|
CurrentShapeType = ShapeType.EffectBlur;
|
|
|
|
|
break;
|
|
|
|
|
case Keys.NumPad9:
|
|
|
|
|
CurrentShapeType = ShapeType.EffectPixelate;
|
|
|
|
|
break;
|
|
|
|
|
case Keys.Control | Keys.V:
|
|
|
|
|
PasteFromClipboard();
|
|
|
|
|
break;
|
2016-12-02 01:24:19 +13:00
|
|
|
|
case Keys.Control | Keys.Z:
|
|
|
|
|
UndoShape();
|
|
|
|
|
break;
|
2016-12-01 04:51:23 +13:00
|
|
|
|
case Keys.Home:
|
|
|
|
|
MoveCurrentShapeTop();
|
|
|
|
|
break;
|
|
|
|
|
case Keys.End:
|
|
|
|
|
MoveCurrentShapeBottom();
|
|
|
|
|
break;
|
|
|
|
|
case Keys.PageUp:
|
|
|
|
|
MoveCurrentShapeUp();
|
|
|
|
|
break;
|
|
|
|
|
case Keys.PageDown:
|
|
|
|
|
MoveCurrentShapeDown();
|
|
|
|
|
break;
|
2016-12-02 04:11:26 +13:00
|
|
|
|
case Keys.Q:
|
|
|
|
|
Config.QuickCrop = !Config.QuickCrop;
|
|
|
|
|
tsmiQuickCrop.Checked = !Config.QuickCrop;
|
|
|
|
|
break;
|
2016-09-04 23:23:21 +12:00
|
|
|
|
}
|
2016-05-27 08:55:10 +12:00
|
|
|
|
}
|
2016-05-03 21:35:10 +12:00
|
|
|
|
}
|
2016-08-05 23:37:20 +12:00
|
|
|
|
|
|
|
|
|
int speed;
|
|
|
|
|
|
|
|
|
|
if (e.Shift)
|
|
|
|
|
{
|
|
|
|
|
speed = RegionCaptureOptions.MoveSpeedMaximum;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
speed = RegionCaptureOptions.MoveSpeedMinimum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int x = 0;
|
|
|
|
|
|
|
|
|
|
if (isLeftPressed)
|
|
|
|
|
{
|
|
|
|
|
x -= speed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isRightPressed)
|
|
|
|
|
{
|
|
|
|
|
x += speed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int y = 0;
|
|
|
|
|
|
|
|
|
|
if (isUpPressed)
|
|
|
|
|
{
|
|
|
|
|
y -= speed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isDownPressed)
|
|
|
|
|
{
|
|
|
|
|
y += speed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (x != 0 || y != 0)
|
|
|
|
|
{
|
|
|
|
|
BaseShape shape = CurrentShape;
|
|
|
|
|
|
|
|
|
|
if (shape == null || IsCreating)
|
|
|
|
|
{
|
|
|
|
|
Cursor.Position = Cursor.Position.Add(x, y);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (e.Control)
|
|
|
|
|
{
|
|
|
|
|
shape.Move(x, y);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-08-06 00:24:29 +12:00
|
|
|
|
shape.Resize(x, y, !e.Alt);
|
2016-08-05 23:37:20 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-03 21:35:10 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-15 19:12:53 +12:00
|
|
|
|
private void form_KeyUp(object sender, KeyEventArgs e)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2015-05-07 04:17:58 +12:00
|
|
|
|
switch (e.KeyCode)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-06-11 21:48:58 +12:00
|
|
|
|
case Keys.ControlKey:
|
|
|
|
|
IsCornerMoving = false;
|
|
|
|
|
break;
|
2016-06-13 04:32:33 +12:00
|
|
|
|
case Keys.ShiftKey:
|
|
|
|
|
IsProportionalResizing = false;
|
|
|
|
|
break;
|
2015-08-21 05:33:28 +12:00
|
|
|
|
case Keys.Menu:
|
2015-08-23 01:13:38 +12:00
|
|
|
|
IsSnapResizing = false;
|
2015-08-14 07:23:51 +12:00
|
|
|
|
break;
|
2016-08-05 23:37:20 +12:00
|
|
|
|
case Keys.Left:
|
|
|
|
|
case Keys.A:
|
|
|
|
|
isLeftPressed = false;
|
|
|
|
|
break;
|
|
|
|
|
case Keys.Right:
|
|
|
|
|
case Keys.D:
|
|
|
|
|
isRightPressed = false;
|
|
|
|
|
break;
|
|
|
|
|
case Keys.Up:
|
|
|
|
|
case Keys.W:
|
|
|
|
|
isUpPressed = false;
|
|
|
|
|
break;
|
|
|
|
|
case Keys.Down:
|
|
|
|
|
case Keys.S:
|
|
|
|
|
isDownPressed = false;
|
|
|
|
|
break;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
2016-06-14 04:48:41 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-23 01:09:15 +12:00
|
|
|
|
private void RunAction(RegionCaptureAction action)
|
2016-06-14 04:48:41 +12:00
|
|
|
|
{
|
|
|
|
|
switch (action)
|
|
|
|
|
{
|
|
|
|
|
case RegionCaptureAction.CancelCapture:
|
2017-03-08 03:47:44 +13:00
|
|
|
|
if (form.Mode == RegionCaptureMode.TaskEditor)
|
|
|
|
|
{
|
|
|
|
|
form.Close(RegionResult.AnnotateContinueTask);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
form.Close();
|
|
|
|
|
}
|
2016-06-14 04:48:41 +12:00
|
|
|
|
break;
|
|
|
|
|
case RegionCaptureAction.RemoveShapeCancelCapture:
|
|
|
|
|
if (IsShapeIntersect())
|
|
|
|
|
{
|
|
|
|
|
DeleteIntersectShape();
|
|
|
|
|
}
|
2017-03-08 03:47:44 +13:00
|
|
|
|
else if (form.Mode == RegionCaptureMode.TaskEditor)
|
|
|
|
|
{
|
|
|
|
|
form.Close(RegionResult.AnnotateContinueTask);
|
|
|
|
|
}
|
2016-06-14 04:48:41 +12:00
|
|
|
|
else
|
|
|
|
|
{
|
2016-09-19 03:28:57 +12:00
|
|
|
|
form.Close();
|
2016-06-14 04:48:41 +12:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case RegionCaptureAction.RemoveShape:
|
2016-06-23 01:09:15 +12:00
|
|
|
|
DeleteIntersectShape();
|
2016-06-14 04:48:41 +12:00
|
|
|
|
break;
|
|
|
|
|
case RegionCaptureAction.SwapToolType:
|
2016-06-23 01:09:15 +12:00
|
|
|
|
SwapShapeType();
|
2016-06-14 04:48:41 +12:00
|
|
|
|
break;
|
|
|
|
|
case RegionCaptureAction.CaptureFullscreen:
|
|
|
|
|
form.Close(RegionResult.Fullscreen);
|
|
|
|
|
break;
|
|
|
|
|
case RegionCaptureAction.CaptureActiveMonitor:
|
|
|
|
|
form.Close(RegionResult.ActiveMonitor);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update()
|
|
|
|
|
{
|
2016-08-16 07:29:48 +12:00
|
|
|
|
OrderStepShapes();
|
|
|
|
|
|
2016-05-10 10:54:11 +12:00
|
|
|
|
BaseShape shape = CurrentShape;
|
|
|
|
|
|
|
|
|
|
if (shape != null)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-08-03 12:48:11 +12:00
|
|
|
|
shape.OnUpdate();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-08 00:09:18 +12:00
|
|
|
|
UpdateCurrentHoverShape();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-08-06 01:17:53 +12:00
|
|
|
|
UpdateNodes();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-06 00:10:05 +12:00
|
|
|
|
private void StartRegionSelection()
|
2015-08-20 04:29:00 +12:00
|
|
|
|
{
|
2016-08-06 01:17:53 +12:00
|
|
|
|
if (IsCursorOnNode)
|
2015-08-20 04:29:00 +12:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-24 09:32:44 +13:00
|
|
|
|
InputManager.Update(form); // If it's a touch event we don't have the correct point yet, so refresh it now
|
2017-10-06 07:33:26 +13:00
|
|
|
|
|
2016-08-16 07:29:48 +12:00
|
|
|
|
BaseShape shape = GetIntersectShape();
|
2016-05-23 10:42:52 +12:00
|
|
|
|
|
|
|
|
|
if (shape != null && shape.ShapeType == CurrentShapeType) // Select shape
|
2015-08-20 04:29:00 +12:00
|
|
|
|
{
|
|
|
|
|
IsMoving = true;
|
2017-10-18 08:39:22 +13:00
|
|
|
|
form.Cursor = Cursors.SizeAll;
|
2016-05-03 20:24:01 +12:00
|
|
|
|
CurrentShape = shape;
|
2016-08-16 07:29:48 +12:00
|
|
|
|
SelectCurrentShape();
|
2015-08-20 04:29:00 +12:00
|
|
|
|
}
|
2016-05-23 10:42:52 +12:00
|
|
|
|
else if (!IsCreating) // Create new shape
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-08-16 08:48:27 +12:00
|
|
|
|
DeselectCurrentShape();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-05-23 08:19:13 +12:00
|
|
|
|
shape = AddShape();
|
2016-08-24 01:03:48 +12:00
|
|
|
|
shape.OnCreating();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-20 04:29:00 +12:00
|
|
|
|
private void EndRegionSelection()
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-20 10:13:19 +12:00
|
|
|
|
bool wasCreating = IsCreating;
|
|
|
|
|
|
2015-08-20 04:29:00 +12:00
|
|
|
|
IsCreating = false;
|
|
|
|
|
IsMoving = false;
|
2017-10-18 08:39:22 +13:00
|
|
|
|
form.SetDefaultCursor();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-05-20 10:13:19 +12:00
|
|
|
|
BaseShape shape = CurrentShape;
|
|
|
|
|
|
|
|
|
|
if (shape != null)
|
2015-08-20 04:29:00 +12:00
|
|
|
|
{
|
2016-06-09 12:33:12 +12:00
|
|
|
|
if (!shape.IsValidShape)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-23 10:42:52 +12:00
|
|
|
|
shape.Rectangle = Rectangle.Empty;
|
|
|
|
|
|
2017-04-08 00:09:18 +12:00
|
|
|
|
UpdateCurrentHoverShape();
|
2016-05-23 10:42:52 +12:00
|
|
|
|
|
2016-08-09 10:05:01 +12:00
|
|
|
|
if (IsCurrentHoverShapeValid)
|
2016-05-20 10:13:19 +12:00
|
|
|
|
{
|
2016-08-09 10:05:01 +12:00
|
|
|
|
shape.Rectangle = CurrentHoverShape.Rectangle;
|
2016-05-23 10:42:52 +12:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DeleteCurrentShape();
|
2016-06-09 12:33:12 +12:00
|
|
|
|
shape = null;
|
2016-05-20 10:13:19 +12:00
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-23 10:42:52 +12:00
|
|
|
|
if (shape != null)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-23 10:42:52 +12:00
|
|
|
|
if (Config.QuickCrop && IsCurrentShapeTypeRegion)
|
2016-05-21 03:33:23 +12:00
|
|
|
|
{
|
2016-05-23 10:42:52 +12:00
|
|
|
|
form.UpdateRegionPath();
|
|
|
|
|
form.Close(RegionResult.Region);
|
2016-05-21 03:33:23 +12:00
|
|
|
|
}
|
2016-05-23 10:42:52 +12:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (wasCreating)
|
|
|
|
|
{
|
2016-08-03 17:35:34 +12:00
|
|
|
|
shape.OnCreated();
|
2016-11-19 13:03:44 +13:00
|
|
|
|
|
|
|
|
|
OnShapeCreated(shape);
|
2016-05-23 10:42:52 +12:00
|
|
|
|
}
|
2016-05-21 03:33:23 +12:00
|
|
|
|
|
2016-08-16 07:29:48 +12:00
|
|
|
|
SelectCurrentShape();
|
2016-05-23 10:42:52 +12:00
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-17 12:53:54 +13:00
|
|
|
|
private void StartPanning()
|
|
|
|
|
{
|
|
|
|
|
IsPanning = true;
|
2017-10-18 03:54:19 +13:00
|
|
|
|
form.Cursor = Cursors.SizeAll;
|
2017-10-17 12:53:54 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void EndPanning()
|
|
|
|
|
{
|
|
|
|
|
IsPanning = false;
|
2017-10-18 03:54:19 +13:00
|
|
|
|
form.SetDefaultCursor();
|
2017-10-17 12:53:54 +13:00
|
|
|
|
}
|
2017-10-18 03:44:46 +13:00
|
|
|
|
|
2016-07-07 19:58:04 +12:00
|
|
|
|
private BaseShape AddShape()
|
|
|
|
|
{
|
|
|
|
|
BaseShape shape = CreateShape();
|
2016-08-19 21:59:46 +12:00
|
|
|
|
AddShape(shape);
|
|
|
|
|
return shape;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddShape(BaseShape shape)
|
|
|
|
|
{
|
2016-07-07 19:58:04 +12:00
|
|
|
|
Shapes.Add(shape);
|
|
|
|
|
CurrentShape = shape;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-09 10:05:01 +12:00
|
|
|
|
private BaseShape CreateShape()
|
2015-07-17 07:07:06 +12:00
|
|
|
|
{
|
2016-07-07 19:58:04 +12:00
|
|
|
|
return CreateShape(CurrentShapeType);
|
2015-07-17 07:07:06 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-09 10:05:01 +12:00
|
|
|
|
private BaseShape CreateShape(ShapeType shapeType)
|
2015-07-17 07:07:06 +12:00
|
|
|
|
{
|
2016-05-03 21:35:10 +12:00
|
|
|
|
BaseShape shape;
|
2015-07-17 07:51:19 +12:00
|
|
|
|
|
2016-07-07 19:58:04 +12:00
|
|
|
|
switch (shapeType)
|
2015-07-17 07:51:19 +12:00
|
|
|
|
{
|
2016-05-03 21:35:10 +12:00
|
|
|
|
default:
|
|
|
|
|
case ShapeType.RegionRectangle:
|
|
|
|
|
shape = new RectangleRegionShape();
|
|
|
|
|
break;
|
|
|
|
|
case ShapeType.RegionEllipse:
|
|
|
|
|
shape = new EllipseRegionShape();
|
|
|
|
|
break;
|
2016-08-03 12:48:11 +12:00
|
|
|
|
case ShapeType.RegionFreehand:
|
|
|
|
|
shape = new FreehandRegionShape();
|
|
|
|
|
break;
|
2016-05-03 21:35:10 +12:00
|
|
|
|
case ShapeType.DrawingRectangle:
|
2016-05-06 05:03:57 +12:00
|
|
|
|
shape = new RectangleDrawingShape();
|
2016-05-03 21:35:10 +12:00
|
|
|
|
break;
|
2016-05-06 05:42:56 +12:00
|
|
|
|
case ShapeType.DrawingEllipse:
|
|
|
|
|
shape = new EllipseDrawingShape();
|
|
|
|
|
break;
|
2016-08-15 11:11:21 +12:00
|
|
|
|
case ShapeType.DrawingFreehand:
|
|
|
|
|
shape = new FreehandDrawingShape();
|
|
|
|
|
break;
|
2016-05-06 05:03:57 +12:00
|
|
|
|
case ShapeType.DrawingLine:
|
|
|
|
|
shape = new LineDrawingShape();
|
2016-05-06 04:43:42 +12:00
|
|
|
|
break;
|
2016-05-07 02:38:49 +12:00
|
|
|
|
case ShapeType.DrawingArrow:
|
|
|
|
|
shape = new ArrowDrawingShape();
|
|
|
|
|
break;
|
2017-02-16 13:49:13 +13:00
|
|
|
|
case ShapeType.DrawingTextOutline:
|
|
|
|
|
shape = new TextOutlineDrawingShape();
|
|
|
|
|
break;
|
|
|
|
|
case ShapeType.DrawingTextBackground:
|
2016-05-20 10:13:19 +12:00
|
|
|
|
shape = new TextDrawingShape();
|
|
|
|
|
break;
|
2016-08-25 04:23:49 +12:00
|
|
|
|
case ShapeType.DrawingSpeechBalloon:
|
|
|
|
|
shape = new SpeechBalloonDrawingShape();
|
|
|
|
|
break;
|
2016-05-23 07:19:25 +12:00
|
|
|
|
case ShapeType.DrawingStep:
|
|
|
|
|
shape = new StepDrawingShape();
|
|
|
|
|
break;
|
2016-08-19 21:59:46 +12:00
|
|
|
|
case ShapeType.DrawingImage:
|
|
|
|
|
shape = new ImageDrawingShape();
|
|
|
|
|
break;
|
2017-05-07 08:53:46 +12:00
|
|
|
|
case ShapeType.DrawingImageScreen:
|
|
|
|
|
shape = new ImageScreenDrawingShape();
|
|
|
|
|
break;
|
2017-07-18 06:48:42 +12:00
|
|
|
|
case ShapeType.DrawingCursor:
|
|
|
|
|
shape = new CursorDrawingShape();
|
|
|
|
|
break;
|
2016-09-02 18:16:52 +12:00
|
|
|
|
case ShapeType.EffectBlur:
|
2016-05-11 10:17:51 +12:00
|
|
|
|
shape = new BlurEffectShape();
|
2016-05-07 04:55:16 +12:00
|
|
|
|
break;
|
2016-09-02 18:16:52 +12:00
|
|
|
|
case ShapeType.EffectPixelate:
|
2016-05-11 10:17:51 +12:00
|
|
|
|
shape = new PixelateEffectShape();
|
2016-05-07 05:04:24 +12:00
|
|
|
|
break;
|
2016-09-02 18:16:52 +12:00
|
|
|
|
case ShapeType.EffectHighlight:
|
2016-05-11 10:17:51 +12:00
|
|
|
|
shape = new HighlightEffectShape();
|
2016-05-07 12:11:31 +12:00
|
|
|
|
break;
|
2017-05-03 02:03:28 +12:00
|
|
|
|
case ShapeType.DrawingCrop:
|
|
|
|
|
shape = new CropDrawingShape();
|
|
|
|
|
break;
|
2015-07-17 07:51:19 +12:00
|
|
|
|
}
|
2016-05-03 21:35:10 +12:00
|
|
|
|
|
2016-05-20 11:53:45 +12:00
|
|
|
|
shape.Manager = this;
|
2016-05-03 21:35:10 +12:00
|
|
|
|
|
2016-08-03 17:35:34 +12:00
|
|
|
|
shape.OnConfigLoad();
|
2016-05-06 05:03:57 +12:00
|
|
|
|
|
2016-05-03 21:35:10 +12:00
|
|
|
|
return shape;
|
2015-07-17 07:07:06 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-08 01:24:32 +12:00
|
|
|
|
private void UpdateCurrentShape()
|
2016-05-06 23:48:50 +12:00
|
|
|
|
{
|
2016-05-21 09:09:09 +12:00
|
|
|
|
BaseShape shape = CurrentShape;
|
|
|
|
|
|
|
|
|
|
if (shape != null)
|
|
|
|
|
{
|
2016-08-03 17:35:34 +12:00
|
|
|
|
shape.OnConfigLoad();
|
2016-05-21 09:09:09 +12:00
|
|
|
|
}
|
2016-05-06 23:48:50 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-12 23:37:03 +12:00
|
|
|
|
private void SwapShapeType()
|
|
|
|
|
{
|
2016-09-04 23:23:21 +12:00
|
|
|
|
if (form.Mode == RegionCaptureMode.Annotation)
|
2016-06-12 23:37:03 +12:00
|
|
|
|
{
|
2016-06-23 01:09:15 +12:00
|
|
|
|
if (IsCurrentShapeTypeRegion)
|
|
|
|
|
{
|
|
|
|
|
CurrentShapeType = Config.LastAnnotationTool;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CurrentShapeType = Config.LastRegionTool;
|
|
|
|
|
}
|
2016-06-12 23:37:03 +12:00
|
|
|
|
}
|
2016-06-23 01:09:15 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 17:35:34 +12:00
|
|
|
|
public Point SnapPosition(Point posOnClick, Point posCurrent)
|
2016-05-23 08:19:13 +12:00
|
|
|
|
{
|
2016-06-25 19:44:39 +12:00
|
|
|
|
Size currentSize = CaptureHelpers.CreateRectangle(posOnClick, posCurrent).Size;
|
|
|
|
|
Vector2 vector = new Vector2(currentSize.Width, currentSize.Height);
|
2016-05-23 08:19:13 +12:00
|
|
|
|
|
2016-06-25 19:44:39 +12:00
|
|
|
|
SnapSize snapSize = (from size in Config.SnapSizes
|
|
|
|
|
let distance = MathHelpers.Distance(vector, new Vector2(size.Width, size.Height))
|
2016-07-27 13:56:20 +12:00
|
|
|
|
where distance > 0 && distance < RegionCaptureOptions.SnapDistance
|
2016-06-25 19:44:39 +12:00
|
|
|
|
orderby distance
|
|
|
|
|
select size).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (snapSize != null)
|
2016-05-23 08:19:13 +12:00
|
|
|
|
{
|
2016-06-25 19:44:39 +12:00
|
|
|
|
Point posNew = CaptureHelpers.CalculateNewPosition(posOnClick, posCurrent, snapSize);
|
2016-05-23 08:19:13 +12:00
|
|
|
|
|
2016-06-25 19:44:39 +12:00
|
|
|
|
Rectangle newRect = CaptureHelpers.CreateRectangle(posOnClick, posNew);
|
2016-05-23 08:19:13 +12:00
|
|
|
|
|
2016-06-25 19:44:39 +12:00
|
|
|
|
if (form.ScreenRectangle0Based.Contains(newRect))
|
|
|
|
|
{
|
|
|
|
|
return posNew;
|
|
|
|
|
}
|
2016-05-23 08:19:13 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return posCurrent;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-08 00:09:18 +12:00
|
|
|
|
private void UpdateCurrentHoverShape()
|
2016-05-23 08:19:13 +12:00
|
|
|
|
{
|
2017-04-08 00:09:18 +12:00
|
|
|
|
CurrentHoverShape = CheckHover();
|
|
|
|
|
}
|
2016-05-23 08:19:13 +12:00
|
|
|
|
|
2017-04-08 00:09:18 +12:00
|
|
|
|
private BaseShape CheckHover()
|
|
|
|
|
{
|
2016-08-06 01:17:53 +12:00
|
|
|
|
if (!IsCursorOnNode && !IsCreating && !IsMoving && !IsResizing)
|
2016-05-23 08:19:13 +12:00
|
|
|
|
{
|
2016-08-16 07:29:48 +12:00
|
|
|
|
BaseShape shape = GetIntersectShape();
|
2016-05-23 08:19:13 +12:00
|
|
|
|
|
2016-08-09 10:05:01 +12:00
|
|
|
|
if (shape != null && shape.IsValidShape)
|
2016-05-23 08:19:13 +12:00
|
|
|
|
{
|
2017-04-08 00:09:18 +12:00
|
|
|
|
return shape;
|
2016-05-23 08:19:13 +12:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-05-23 11:30:25 +12:00
|
|
|
|
switch (CurrentShapeType)
|
|
|
|
|
{
|
2016-08-03 21:31:15 +12:00
|
|
|
|
case ShapeType.RegionFreehand:
|
2016-08-15 11:11:21 +12:00
|
|
|
|
case ShapeType.DrawingFreehand:
|
2016-05-23 11:30:25 +12:00
|
|
|
|
case ShapeType.DrawingLine:
|
|
|
|
|
case ShapeType.DrawingArrow:
|
2017-02-16 13:49:13 +13:00
|
|
|
|
case ShapeType.DrawingTextOutline:
|
|
|
|
|
case ShapeType.DrawingTextBackground:
|
2016-08-25 11:01:07 +12:00
|
|
|
|
case ShapeType.DrawingSpeechBalloon:
|
2016-05-23 11:30:25 +12:00
|
|
|
|
case ShapeType.DrawingStep:
|
2016-08-24 10:04:48 +12:00
|
|
|
|
case ShapeType.DrawingImage:
|
2017-07-18 06:48:42 +12:00
|
|
|
|
case ShapeType.DrawingCursor:
|
2017-04-08 00:09:18 +12:00
|
|
|
|
return null;
|
2016-05-23 11:30:25 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-26 06:23:02 +12:00
|
|
|
|
if (Config.IsFixedSize && IsCurrentShapeTypeRegion)
|
|
|
|
|
{
|
|
|
|
|
Point location = InputManager.MousePosition0Based;
|
2016-08-09 10:05:01 +12:00
|
|
|
|
|
2017-04-08 00:09:18 +12:00
|
|
|
|
return new RectangleRegionShape()
|
2016-08-09 10:05:01 +12:00
|
|
|
|
{
|
|
|
|
|
Rectangle = new Rectangle(new Point(location.X - Config.FixedSize.Width / 2, location.Y - Config.FixedSize.Height / 2), Config.FixedSize)
|
|
|
|
|
};
|
2016-05-26 06:23:02 +12:00
|
|
|
|
}
|
|
|
|
|
else
|
2016-05-23 08:19:13 +12:00
|
|
|
|
{
|
2016-05-26 06:23:02 +12:00
|
|
|
|
SimpleWindowInfo window = FindSelectedWindow();
|
|
|
|
|
|
|
|
|
|
if (window != null && !window.Rectangle.IsEmpty)
|
|
|
|
|
{
|
|
|
|
|
Rectangle hoverArea = CaptureHelpers.ScreenToClient(window.Rectangle);
|
2016-08-09 10:05:01 +12:00
|
|
|
|
|
2017-04-08 00:09:18 +12:00
|
|
|
|
return new RectangleRegionShape()
|
2016-08-09 10:05:01 +12:00
|
|
|
|
{
|
|
|
|
|
Rectangle = Rectangle.Intersect(form.ScreenRectangle0Based, hoverArea)
|
|
|
|
|
};
|
2016-05-26 06:23:02 +12:00
|
|
|
|
}
|
2016-05-23 08:19:13 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-08 00:09:18 +12:00
|
|
|
|
|
|
|
|
|
return null;
|
2016-05-23 08:19:13 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SimpleWindowInfo FindSelectedWindow()
|
|
|
|
|
{
|
|
|
|
|
if (Windows != null)
|
|
|
|
|
{
|
|
|
|
|
return Windows.FirstOrDefault(x => x.Rectangle.Contains(InputManager.MousePosition));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-29 22:10:48 +12:00
|
|
|
|
public WindowInfo FindSelectedWindowInfo(Point position)
|
2016-05-23 08:19:13 +12:00
|
|
|
|
{
|
|
|
|
|
if (Windows != null)
|
|
|
|
|
{
|
2016-05-29 22:10:48 +12:00
|
|
|
|
SimpleWindowInfo windowInfo = Windows.FirstOrDefault(x => x.IsWindow && x.Rectangle.Contains(position));
|
2016-05-23 08:19:13 +12:00
|
|
|
|
|
|
|
|
|
if (windowInfo != null)
|
|
|
|
|
{
|
|
|
|
|
return windowInfo.WindowInfo;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-11 10:38:35 +12:00
|
|
|
|
public Image RenderOutputImage(Image img)
|
|
|
|
|
{
|
|
|
|
|
Bitmap bmp = new Bitmap(img);
|
|
|
|
|
|
|
|
|
|
if (DrawingShapes.Length > 0 || EffectShapes.Length > 0)
|
|
|
|
|
{
|
2017-05-24 10:53:57 +12:00
|
|
|
|
IsRenderingOutput = true;
|
|
|
|
|
|
2016-05-11 10:38:35 +12:00
|
|
|
|
using (Graphics g = Graphics.FromImage(bmp))
|
|
|
|
|
{
|
|
|
|
|
foreach (BaseEffectShape shape in EffectShapes)
|
|
|
|
|
{
|
|
|
|
|
if (shape != null)
|
|
|
|
|
{
|
2016-05-22 00:26:49 +12:00
|
|
|
|
shape.OnDrawFinal(g, bmp);
|
2016-05-11 10:38:35 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (BaseDrawingShape shape in DrawingShapes)
|
|
|
|
|
{
|
|
|
|
|
if (shape != null)
|
|
|
|
|
{
|
2016-05-22 00:26:49 +12:00
|
|
|
|
shape.OnDraw(g);
|
2016-05-11 10:38:35 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-24 10:53:57 +12:00
|
|
|
|
|
|
|
|
|
IsRenderingOutput = false;
|
2016-05-11 10:38:35 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bmp;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 01:59:53 +12:00
|
|
|
|
private void SelectShape(BaseShape shape)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-08-25 01:59:53 +12:00
|
|
|
|
if (shape != null)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-08-25 01:59:53 +12:00
|
|
|
|
shape.ShowNodes();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 01:59:53 +12:00
|
|
|
|
private void SelectCurrentShape()
|
|
|
|
|
{
|
|
|
|
|
SelectShape(CurrentShape);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-16 07:29:48 +12:00
|
|
|
|
private void SelectIntersectShape()
|
|
|
|
|
{
|
|
|
|
|
BaseShape shape = GetIntersectShape();
|
|
|
|
|
|
|
|
|
|
if (shape != null)
|
|
|
|
|
{
|
|
|
|
|
CurrentShape = shape;
|
2016-08-25 01:59:53 +12:00
|
|
|
|
SelectShape(shape);
|
2016-08-16 07:29:48 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-16 08:48:27 +12:00
|
|
|
|
private void DeselectShape(BaseShape shape)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-08-16 08:48:27 +12:00
|
|
|
|
if (shape == CurrentShape)
|
|
|
|
|
{
|
|
|
|
|
CurrentShape = null;
|
|
|
|
|
NodesVisible = false;
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-16 08:48:27 +12:00
|
|
|
|
private void DeselectCurrentShape()
|
2016-05-05 02:01:03 +12:00
|
|
|
|
{
|
2016-08-16 08:48:27 +12:00
|
|
|
|
DeselectShape(CurrentShape);
|
|
|
|
|
}
|
2016-05-05 02:01:03 +12:00
|
|
|
|
|
2016-08-24 01:39:15 +12:00
|
|
|
|
public void DeleteShape(BaseShape shape)
|
2016-08-16 08:48:27 +12:00
|
|
|
|
{
|
2016-05-05 02:01:03 +12:00
|
|
|
|
if (shape != null)
|
|
|
|
|
{
|
2016-08-19 22:22:12 +12:00
|
|
|
|
shape.Dispose();
|
2016-05-05 02:01:03 +12:00
|
|
|
|
Shapes.Remove(shape);
|
2016-08-16 08:48:27 +12:00
|
|
|
|
DeselectShape(shape);
|
2016-10-03 02:47:26 +13:00
|
|
|
|
UpdateMenu();
|
2016-05-05 02:01:03 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-16 08:48:27 +12:00
|
|
|
|
private void DeleteCurrentShape()
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-08-16 08:48:27 +12:00
|
|
|
|
DeleteShape(CurrentShape);
|
|
|
|
|
}
|
2016-05-03 19:46:45 +12:00
|
|
|
|
|
2016-08-16 08:48:27 +12:00
|
|
|
|
private void DeleteIntersectShape()
|
|
|
|
|
{
|
|
|
|
|
DeleteShape(GetIntersectShape());
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-16 08:48:27 +12:00
|
|
|
|
private void DeleteAllShapes()
|
2016-05-12 05:16:29 +12:00
|
|
|
|
{
|
2016-08-19 22:22:12 +12:00
|
|
|
|
foreach (BaseShape shape in Shapes)
|
|
|
|
|
{
|
|
|
|
|
shape.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-12 05:16:29 +12:00
|
|
|
|
Shapes.Clear();
|
2016-08-16 08:48:27 +12:00
|
|
|
|
DeselectCurrentShape();
|
2016-05-12 05:16:29 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-16 07:29:48 +12:00
|
|
|
|
public BaseShape GetIntersectShape()
|
|
|
|
|
{
|
|
|
|
|
return GetIntersectShape(InputManager.MousePosition0Based);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BaseShape GetIntersectShape(Point position)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-03 20:24:01 +12:00
|
|
|
|
for (int i = Shapes.Count - 1; i >= 0; i--)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-03 23:39:44 +12:00
|
|
|
|
BaseShape shape = Shapes[i];
|
|
|
|
|
|
2016-05-29 22:10:48 +12:00
|
|
|
|
if (shape.ShapeType == CurrentShapeType && shape.Intersects(position))
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-03 23:39:44 +12:00
|
|
|
|
return shape;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-03 20:24:01 +12:00
|
|
|
|
return null;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-23 10:42:52 +12:00
|
|
|
|
public bool IsShapeIntersect()
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-08-16 07:29:48 +12:00
|
|
|
|
return GetIntersectShape() != null;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-16 08:48:27 +12:00
|
|
|
|
public void UndoShape()
|
|
|
|
|
{
|
|
|
|
|
if (Shapes.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
DeleteShape(Shapes[Shapes.Count - 1]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-01 04:51:23 +13:00
|
|
|
|
public void MoveShapeBottom(BaseShape shape)
|
|
|
|
|
{
|
|
|
|
|
if (shape != null)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < Shapes.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (Shapes[i] == shape)
|
|
|
|
|
{
|
|
|
|
|
Shapes.Move(i, 0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MoveCurrentShapeBottom()
|
|
|
|
|
{
|
|
|
|
|
MoveShapeBottom(CurrentShape);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MoveShapeTop(BaseShape shape)
|
|
|
|
|
{
|
|
|
|
|
if (shape != null)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < Shapes.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (Shapes[i] == shape)
|
|
|
|
|
{
|
|
|
|
|
Shapes.Move(i, Shapes.Count - 1);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MoveCurrentShapeTop()
|
|
|
|
|
{
|
|
|
|
|
MoveShapeTop(CurrentShape);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MoveShapeDown(BaseShape shape)
|
|
|
|
|
{
|
|
|
|
|
if (shape != null)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 1; i < Shapes.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (Shapes[i] == shape)
|
|
|
|
|
{
|
|
|
|
|
Shapes.Move(i, --i);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MoveCurrentShapeDown()
|
|
|
|
|
{
|
|
|
|
|
MoveShapeDown(CurrentShape);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MoveShapeUp(BaseShape shape)
|
|
|
|
|
{
|
|
|
|
|
if (shape != null)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < Shapes.Count - 1; i++)
|
|
|
|
|
{
|
|
|
|
|
if (Shapes[i] == shape)
|
|
|
|
|
{
|
|
|
|
|
Shapes.Move(i, ++i);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MoveCurrentShapeUp()
|
|
|
|
|
{
|
|
|
|
|
MoveShapeUp(CurrentShape);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-18 03:44:46 +13:00
|
|
|
|
public void MoveAll(int x, int y)
|
|
|
|
|
{
|
|
|
|
|
foreach (BaseShape shape in Shapes)
|
|
|
|
|
{
|
|
|
|
|
shape.Move(x, y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MoveAll(Point offset)
|
|
|
|
|
{
|
|
|
|
|
MoveAll(offset.X, offset.Y);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-18 07:34:06 +13:00
|
|
|
|
public void RemoveOutsideShapes()
|
|
|
|
|
{
|
|
|
|
|
foreach (BaseShape shape in Shapes.ToArray())
|
|
|
|
|
{
|
|
|
|
|
if (!form.ImageRectangle.IntersectsWith(shape.Rectangle))
|
|
|
|
|
{
|
|
|
|
|
shape.Remove();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-04 23:23:21 +12:00
|
|
|
|
private bool IsShapeTypeRegion(ShapeType shapeType)
|
|
|
|
|
{
|
|
|
|
|
switch (shapeType)
|
|
|
|
|
{
|
|
|
|
|
case ShapeType.RegionRectangle:
|
|
|
|
|
case ShapeType.RegionEllipse:
|
|
|
|
|
case ShapeType.RegionFreehand:
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-06 01:17:53 +12:00
|
|
|
|
private void UpdateNodes()
|
|
|
|
|
{
|
|
|
|
|
BaseShape shape = CurrentShape;
|
|
|
|
|
|
2016-08-06 01:48:46 +12:00
|
|
|
|
if (shape != null && NodesVisible)
|
2016-08-06 01:17:53 +12:00
|
|
|
|
{
|
|
|
|
|
if (InputManager.IsMouseDown(MouseButtons.Left))
|
|
|
|
|
{
|
2016-08-06 01:35:44 +12:00
|
|
|
|
shape.OnNodeUpdate();
|
2016-08-06 01:17:53 +12:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
IsResizing = false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-06 01:35:44 +12:00
|
|
|
|
shape.OnNodePositionUpdate();
|
2016-08-06 01:17:53 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-20 11:53:45 +12:00
|
|
|
|
public void PauseForm()
|
|
|
|
|
{
|
|
|
|
|
form.Pause();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ResumeForm()
|
|
|
|
|
{
|
|
|
|
|
form.Resume();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-23 08:43:19 +12:00
|
|
|
|
public void OrderStepShapes()
|
|
|
|
|
{
|
|
|
|
|
int i = 1;
|
|
|
|
|
|
|
|
|
|
foreach (StepDrawingShape shape in Shapes.OfType<StepDrawingShape>())
|
|
|
|
|
{
|
|
|
|
|
shape.Number = i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-24 05:33:48 +12:00
|
|
|
|
private void PasteFromClipboard()
|
2016-08-19 21:59:46 +12:00
|
|
|
|
{
|
|
|
|
|
if (Clipboard.ContainsImage())
|
|
|
|
|
{
|
|
|
|
|
Image img = ClipboardHelpers.GetImage();
|
|
|
|
|
|
|
|
|
|
if (img != null)
|
|
|
|
|
{
|
|
|
|
|
CurrentShapeType = ShapeType.DrawingImage;
|
|
|
|
|
ImageDrawingShape shape = (ImageDrawingShape)CreateShape(ShapeType.DrawingImage);
|
2016-08-24 01:30:59 +12:00
|
|
|
|
shape.StartPosition = shape.EndPosition = InputManager.MousePosition0Based;
|
|
|
|
|
shape.SetImage(img, true);
|
2016-08-19 21:59:46 +12:00
|
|
|
|
AddShape(shape);
|
|
|
|
|
SelectCurrentShape();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-24 05:33:48 +12:00
|
|
|
|
else if (Clipboard.ContainsText())
|
|
|
|
|
{
|
|
|
|
|
string text = Clipboard.GetText();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(text))
|
|
|
|
|
{
|
2017-02-16 13:49:13 +13:00
|
|
|
|
CurrentShapeType = ShapeType.DrawingTextBackground;
|
|
|
|
|
TextDrawingShape shape = (TextDrawingShape)CreateShape(ShapeType.DrawingTextBackground);
|
2016-08-24 10:04:48 +12:00
|
|
|
|
shape.StartPosition = shape.EndPosition = InputManager.MousePosition0Based;
|
|
|
|
|
shape.Text = text.Trim();
|
|
|
|
|
shape.AutoSize(true);
|
2016-08-24 05:33:48 +12:00
|
|
|
|
AddShape(shape);
|
|
|
|
|
SelectCurrentShape();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-19 21:59:46 +12:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-21 08:27:03 +12:00
|
|
|
|
public void AddCursor(IntPtr cursorHandle, Point position)
|
2017-07-18 06:48:42 +12:00
|
|
|
|
{
|
|
|
|
|
CursorDrawingShape shape = (CursorDrawingShape)CreateShape(ShapeType.DrawingCursor);
|
2017-07-21 08:27:03 +12:00
|
|
|
|
shape.UpdateCursor(cursorHandle, position);
|
2017-07-18 06:48:42 +12:00
|
|
|
|
Shapes.Add(shape);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-28 21:32:09 +12:00
|
|
|
|
public Rectangle LimitRectangleToImage(Rectangle rect)
|
|
|
|
|
{
|
|
|
|
|
return Rectangle.Intersect(rect, form.ImageRectangle);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-18 23:59:59 +12:00
|
|
|
|
public void DrawRegionArea(Graphics g, Rectangle rect, bool isAnimated)
|
2017-05-01 00:54:05 +12:00
|
|
|
|
{
|
2017-07-18 23:59:59 +12:00
|
|
|
|
form.DrawRegionArea(g, rect, isAnimated);
|
2017-05-01 00:54:05 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CropArea(Rectangle rect)
|
|
|
|
|
{
|
2017-05-07 10:22:26 +12:00
|
|
|
|
Image img = CropImage(rect, true);
|
2017-05-01 00:54:05 +12:00
|
|
|
|
|
2017-05-07 10:22:26 +12:00
|
|
|
|
if (img != null)
|
2017-05-01 00:54:05 +12:00
|
|
|
|
{
|
2017-10-25 19:01:59 +13:00
|
|
|
|
MoveAll(-rect.X, -rect.Y);
|
2017-05-07 10:22:26 +12:00
|
|
|
|
form.InitBackground(img);
|
2017-08-12 00:32:29 +12:00
|
|
|
|
isAnnotated = true;
|
2017-05-01 00:54:05 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-07 10:22:26 +12:00
|
|
|
|
public Image CropImage(Rectangle rect, bool onlyIfSizeDifferent = false)
|
2017-05-07 08:53:46 +12:00
|
|
|
|
{
|
|
|
|
|
rect = CaptureHelpers.ScreenToClient(rect);
|
2017-05-07 10:22:26 +12:00
|
|
|
|
|
2017-05-24 02:28:56 +12:00
|
|
|
|
Point offset = CaptureHelpers.ScreenToClient(form.ImageRectangle.Location);
|
|
|
|
|
|
|
|
|
|
rect.X -= offset.X;
|
|
|
|
|
rect.Y -= offset.Y;
|
|
|
|
|
|
2017-05-07 08:53:46 +12:00
|
|
|
|
rect.Intersect(new Rectangle(0, 0, form.Image.Width, form.Image.Height));
|
|
|
|
|
|
2017-05-07 10:22:26 +12:00
|
|
|
|
if (rect.IsValid() && (!onlyIfSizeDifferent || rect.Size != form.Image.Size))
|
2017-05-07 08:53:46 +12:00
|
|
|
|
{
|
|
|
|
|
return ImageHelpers.CropImage(form.Image, rect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-22 11:33:00 +13:00
|
|
|
|
private void ChangeImageSize()
|
|
|
|
|
{
|
|
|
|
|
Size oldSize = form.Image.Size;
|
|
|
|
|
|
2017-10-22 12:26:47 +13:00
|
|
|
|
using (ImageSizeForm imageSizeForm = new ImageSizeForm(oldSize))
|
|
|
|
|
{
|
|
|
|
|
if (imageSizeForm.ShowDialog() == DialogResult.OK)
|
2017-10-22 11:33:00 +13:00
|
|
|
|
{
|
2017-10-22 12:26:47 +13:00
|
|
|
|
Size size = imageSizeForm.Result;
|
|
|
|
|
|
|
|
|
|
if (size != oldSize)
|
|
|
|
|
{
|
|
|
|
|
Image img = ImageHelpers.ResizeImage(form.Image, size);
|
|
|
|
|
|
|
|
|
|
if (img != null)
|
|
|
|
|
{
|
|
|
|
|
Rectangle oldRect = form.ImageRectangle;
|
|
|
|
|
form.InitBackground(img);
|
|
|
|
|
//MoveAll(form.ImageRectangle.X - oldRect.X, form.ImageRectangle.Y - oldRect.Y);
|
|
|
|
|
isAnnotated = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-22 11:33:00 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ChangeCanvasSize()
|
2017-10-21 12:15:23 +13:00
|
|
|
|
{
|
2017-10-22 09:43:39 +13:00
|
|
|
|
using (CanvasSizeForm canvasSizeForm = new CanvasSizeForm())
|
2017-10-21 12:15:23 +13:00
|
|
|
|
{
|
2017-10-22 09:43:39 +13:00
|
|
|
|
if (canvasSizeForm.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
Padding canvas = canvasSizeForm.Canvas;
|
|
|
|
|
Image img = ImageHelpers.AddCanvas(form.Image, canvas);
|
2017-10-21 12:15:23 +13:00
|
|
|
|
|
2017-10-22 09:43:39 +13:00
|
|
|
|
if (img != null)
|
|
|
|
|
{
|
2017-10-25 19:16:29 +13:00
|
|
|
|
MoveAll(canvas.Left - form.ImageRectangle.X, canvas.Top - form.ImageRectangle.Y);
|
2017-10-22 09:43:39 +13:00
|
|
|
|
form.InitBackground(img);
|
|
|
|
|
isAnnotated = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-21 12:15:23 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-22 11:04:18 +13:00
|
|
|
|
private void RotateImage(RotateFlipType type)
|
|
|
|
|
{
|
|
|
|
|
Image clone = (Image)form.Image.Clone();
|
|
|
|
|
clone.RotateFlip(type);
|
|
|
|
|
form.InitBackground(clone);
|
|
|
|
|
isAnnotated = true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-12 05:16:29 +12:00
|
|
|
|
private void OnCurrentShapeChanged(BaseShape shape)
|
|
|
|
|
{
|
|
|
|
|
if (CurrentShapeChanged != null)
|
|
|
|
|
{
|
|
|
|
|
CurrentShapeChanged(shape);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-08 08:31:43 +12:00
|
|
|
|
private void OnCurrentShapeTypeChanged(ShapeType shapeType)
|
|
|
|
|
{
|
|
|
|
|
if (CurrentShapeTypeChanged != null)
|
|
|
|
|
{
|
|
|
|
|
CurrentShapeTypeChanged(shapeType);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-19 22:22:12 +12:00
|
|
|
|
|
2016-11-19 13:03:44 +13:00
|
|
|
|
private void OnShapeCreated(BaseShape shape)
|
|
|
|
|
{
|
|
|
|
|
if (ShapeCreated != null)
|
|
|
|
|
{
|
|
|
|
|
ShapeCreated(shape);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-19 22:22:12 +12:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
DeleteAllShapes();
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
2015-09-01 22:43:03 +12:00
|
|
|
|
}
|