ShareX/ShareX.ScreenCaptureLib/Helpers/ImageEditorControl.cs

110 lines
3.1 KiB
C#
Raw Normal View History

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
2024-01-03 12:57:14 +13:00
Copyright (c) 2007-2024 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)
using System;
2013-11-03 23:53:49 +13:00
using System.Drawing;
using System.Windows.Forms;
2013-11-03 23:53:49 +13:00
2014-12-11 09:25:20 +13:00
namespace ShareX.ScreenCaptureLib
2013-11-03 23:53:49 +13:00
{
2018-04-08 21:12:52 +12:00
internal abstract class ImageEditorControl
2013-11-03 23:53:49 +13:00
{
public event MouseEventHandler MouseDown, MouseUp;
public event Action MouseEnter, MouseLeave;
2013-11-03 23:53:49 +13:00
public bool Visible { get; set; }
public bool HandleMouseInput { get; set; } = true;
public RectangleF Rectangle { get; set; }
private bool isCursorHover;
public bool IsCursorHover
{
get
{
return isCursorHover;
}
set
{
if (isCursorHover != value)
{
isCursorHover = value;
if (isCursorHover)
{
OnMouseEnter();
}
else
{
OnMouseLeave();
}
}
}
}
2017-12-11 01:44:02 +13:00
public bool IsDragging { get; protected set; }
2013-11-03 23:53:49 +13:00
public int Order { get; set; }
public virtual void OnDraw(Graphics g)
2013-11-03 23:53:49 +13:00
{
2017-12-11 01:44:02 +13:00
if (IsDragging)
{
g.FillRectangle(Brushes.Blue, Rectangle);
}
else if (IsCursorHover)
2013-11-03 23:53:49 +13:00
{
g.FillRectangle(Brushes.Green, Rectangle);
}
else
{
g.FillRectangle(Brushes.Red, Rectangle);
}
}
public virtual void OnMouseEnter()
{
2021-06-10 10:14:01 +12:00
MouseEnter?.Invoke();
}
public virtual void OnMouseLeave()
{
2021-06-10 10:14:01 +12:00
MouseLeave?.Invoke();
}
public virtual void OnMouseDown(Point position)
{
IsDragging = true;
2021-06-10 10:14:01 +12:00
MouseDown?.Invoke(this, new MouseEventArgs(MouseButtons.Left, 1, position.X, position.Y, 0));
}
public virtual void OnMouseUp(Point position)
{
IsDragging = false;
2021-06-10 10:14:01 +12:00
MouseUp?.Invoke(this, new MouseEventArgs(MouseButtons.Left, 1, position.X, position.Y, 0));
}
2013-11-03 23:53:49 +13:00
}
}