2017-05-01 00:54:05 +12:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2022-01-12 05:32:17 +13:00
|
|
|
|
Copyright (c) 2007-2022 ShareX Team
|
2017-05-01 00:54:05 +12: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)
|
|
|
|
|
|
2017-12-31 11:57:13 +13:00
|
|
|
|
using ShareX.HelpersLib;
|
2017-05-01 00:54:05 +12:00
|
|
|
|
using System.Drawing;
|
2017-12-13 05:12:25 +13:00
|
|
|
|
using System.Windows.Forms;
|
2017-05-01 00:54:05 +12:00
|
|
|
|
|
|
|
|
|
namespace ShareX.ScreenCaptureLib
|
|
|
|
|
{
|
2017-12-13 04:50:02 +13:00
|
|
|
|
public class CropTool : BaseTool
|
2017-05-01 00:54:05 +12:00
|
|
|
|
{
|
2017-12-13 04:50:02 +13:00
|
|
|
|
public override ShapeType ShapeType { get; } = ShapeType.ToolCrop;
|
|
|
|
|
|
2017-12-13 12:02:00 +13:00
|
|
|
|
public override bool LimitRectangleToInsideCanvas { get; } = true;
|
|
|
|
|
|
2018-04-08 21:12:52 +12:00
|
|
|
|
private ImageEditorButton confirmButton, cancelButton;
|
2017-12-14 09:03:06 +13:00
|
|
|
|
private Size buttonSize = new Size(80, 40);
|
2017-12-13 12:02:00 +13:00
|
|
|
|
private int buttonOffset = 15;
|
2017-12-13 04:50:02 +13:00
|
|
|
|
|
|
|
|
|
public override void OnUpdate()
|
|
|
|
|
{
|
|
|
|
|
base.OnUpdate();
|
|
|
|
|
|
2017-12-14 09:03:06 +13:00
|
|
|
|
if (confirmButton != null && cancelButton != null)
|
2017-05-09 11:38:37 +12:00
|
|
|
|
{
|
2017-12-14 09:03:06 +13:00
|
|
|
|
if (Rectangle.Bottom + buttonOffset + buttonSize.Height > Manager.Form.ClientArea.Bottom &&
|
2018-05-17 01:27:11 +12:00
|
|
|
|
Rectangle.Width > (buttonSize.Width * 2) + (buttonOffset * 3) &&
|
|
|
|
|
Rectangle.Height > buttonSize.Height + (buttonOffset * 2))
|
2017-12-14 09:03:06 +13:00
|
|
|
|
{
|
2022-02-20 19:30:39 +13:00
|
|
|
|
confirmButton.Rectangle = new RectangleF(Rectangle.Right - (buttonOffset * 2) - (buttonSize.Width * 2),
|
2017-12-14 09:03:06 +13:00
|
|
|
|
Rectangle.Bottom - buttonOffset - buttonSize.Height, buttonSize.Width, buttonSize.Height);
|
2022-02-20 19:30:39 +13:00
|
|
|
|
cancelButton.Rectangle = new RectangleF(Rectangle.Right - buttonOffset - buttonSize.Width,
|
2017-12-14 09:03:06 +13:00
|
|
|
|
Rectangle.Bottom - buttonOffset - buttonSize.Height, buttonSize.Width, buttonSize.Height);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-02-20 19:30:39 +13:00
|
|
|
|
confirmButton.Rectangle = new RectangleF(Rectangle.Right - (buttonSize.Width * 2) - buttonOffset,
|
2017-12-14 09:03:06 +13:00
|
|
|
|
Rectangle.Bottom + buttonOffset, buttonSize.Width, buttonSize.Height);
|
2022-02-20 19:30:39 +13:00
|
|
|
|
cancelButton.Rectangle = new RectangleF(Rectangle.Right - buttonSize.Width,
|
2017-12-14 09:03:06 +13:00
|
|
|
|
Rectangle.Bottom + buttonOffset, buttonSize.Width, buttonSize.Height);
|
|
|
|
|
}
|
2017-05-09 11:38:37 +12:00
|
|
|
|
}
|
2017-05-01 00:54:05 +12:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-31 11:57:13 +13:00
|
|
|
|
public override void OnDraw(Graphics g)
|
|
|
|
|
{
|
|
|
|
|
if (IsValidShape)
|
|
|
|
|
{
|
|
|
|
|
Manager.DrawRegionArea(g, Rectangle, true, Manager.Options.ShowInfo);
|
|
|
|
|
g.DrawCross(Pens.Black, Rectangle.Center(), 10);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-01 00:54:05 +12:00
|
|
|
|
public override void OnCreated()
|
2017-12-13 04:17:38 +13:00
|
|
|
|
{
|
2018-04-08 21:12:52 +12:00
|
|
|
|
confirmButton = new ImageEditorButton()
|
2017-12-13 05:12:25 +13:00
|
|
|
|
{
|
2017-12-13 06:06:06 +13:00
|
|
|
|
Text = "\u2714",
|
|
|
|
|
ButtonColor = Color.ForestGreen,
|
2017-12-14 09:03:06 +13:00
|
|
|
|
Rectangle = new Rectangle(new Point(), buttonSize),
|
2017-12-13 05:12:25 +13:00
|
|
|
|
Visible = true
|
|
|
|
|
};
|
2017-12-15 13:32:41 +13:00
|
|
|
|
confirmButton.MouseDown += ConfirmButton_MousePressed;
|
|
|
|
|
confirmButton.MouseEnter += () => Manager.Form.Cursor = Cursors.Hand;
|
|
|
|
|
confirmButton.MouseLeave += () => Manager.Form.SetDefaultCursor();
|
2017-12-13 04:50:02 +13:00
|
|
|
|
Manager.DrawableObjects.Add(confirmButton);
|
2017-12-13 06:06:06 +13:00
|
|
|
|
|
2018-04-08 21:12:52 +12:00
|
|
|
|
cancelButton = new ImageEditorButton()
|
2017-12-13 06:06:06 +13:00
|
|
|
|
{
|
|
|
|
|
Text = "\u2716",
|
|
|
|
|
ButtonColor = Color.FromArgb(227, 45, 45),
|
2017-12-14 09:03:06 +13:00
|
|
|
|
Rectangle = new Rectangle(new Point(), buttonSize),
|
2017-12-13 06:06:06 +13:00
|
|
|
|
Visible = true
|
|
|
|
|
};
|
2017-12-15 13:32:41 +13:00
|
|
|
|
cancelButton.MouseDown += CancelButton_MousePressed;
|
|
|
|
|
cancelButton.MouseEnter += () => Manager.Form.Cursor = Cursors.Hand;
|
|
|
|
|
cancelButton.MouseLeave += () => Manager.Form.SetDefaultCursor();
|
2017-12-13 06:06:06 +13:00
|
|
|
|
Manager.DrawableObjects.Add(cancelButton);
|
2017-12-13 04:17:38 +13:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-13 05:12:25 +13:00
|
|
|
|
private void ConfirmButton_MousePressed(object sender, MouseEventArgs e)
|
2017-05-01 00:54:05 +12:00
|
|
|
|
{
|
2017-12-13 12:02:00 +13:00
|
|
|
|
Manager.CropArea(Rectangle);
|
2017-05-01 00:54:05 +12:00
|
|
|
|
Remove();
|
|
|
|
|
}
|
2017-12-13 04:50:02 +13:00
|
|
|
|
|
2017-12-13 06:06:06 +13:00
|
|
|
|
private void CancelButton_MousePressed(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Remove();
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-14 00:21:48 +12:00
|
|
|
|
public override void Remove()
|
|
|
|
|
{
|
|
|
|
|
base.Remove();
|
2019-04-14 19:17:12 +12:00
|
|
|
|
|
2019-04-14 00:21:48 +12:00
|
|
|
|
if (Options.SwitchToSelectionToolAfterDrawing)
|
|
|
|
|
{
|
|
|
|
|
Manager.CurrentTool = ShapeType.ToolSelect;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-13 04:50:02 +13:00
|
|
|
|
public override void Dispose()
|
|
|
|
|
{
|
|
|
|
|
base.Dispose();
|
|
|
|
|
|
2017-12-17 18:56:58 +13:00
|
|
|
|
if ((confirmButton != null && confirmButton.IsCursorHover) || (cancelButton != null && cancelButton.IsCursorHover))
|
2017-12-15 13:32:41 +13:00
|
|
|
|
{
|
|
|
|
|
Manager.Form.SetDefaultCursor();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-13 04:50:02 +13:00
|
|
|
|
if (confirmButton != null)
|
|
|
|
|
{
|
|
|
|
|
Manager.DrawableObjects.Remove(confirmButton);
|
|
|
|
|
}
|
2017-12-13 06:06:06 +13:00
|
|
|
|
|
|
|
|
|
if (cancelButton != null)
|
|
|
|
|
{
|
|
|
|
|
Manager.DrawableObjects.Remove(cancelButton);
|
|
|
|
|
}
|
2017-12-13 04:50:02 +13:00
|
|
|
|
}
|
2017-05-01 00:54:05 +12:00
|
|
|
|
}
|
|
|
|
|
}
|