ShareX/ShareX.ScreenCaptureLib/RegionHelpers/InputManager.cs

74 lines
2.4 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
2022-01-12 05:32:17 +13:00
Copyright (c) 2007-2022 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.Drawing;
using System.Windows.Forms;
2014-12-11 09:25:20 +13:00
namespace ShareX.ScreenCaptureLib
2013-11-03 23:53:49 +13:00
{
2017-10-24 10:40:37 +13:00
public class InputManager
2013-11-03 23:53:49 +13:00
{
2017-10-24 10:40:37 +13:00
public Point MousePosition => mouseState.Position;
2013-11-03 23:53:49 +13:00
2017-10-24 10:40:37 +13:00
public Point PreviousMousePosition => oldMouseState.Position;
2013-11-03 23:53:49 +13:00
2017-11-07 05:01:02 +13:00
public Point ClientMousePosition => mouseState.ClientPosition;
2013-11-03 23:53:49 +13:00
2017-11-07 05:01:02 +13:00
public Point PreviousClientMousePosition => oldMouseState.ClientPosition;
2013-11-03 23:53:49 +13:00
2017-11-07 05:01:02 +13:00
public Point MouseVelocity => new Point(ClientMousePosition.X - PreviousClientMousePosition.X, ClientMousePosition.Y - PreviousClientMousePosition.Y);
2013-11-03 23:53:49 +13:00
2017-10-24 10:40:37 +13:00
public bool IsMouseMoved => MouseVelocity.X != 0 || MouseVelocity.Y != 0;
2016-08-06 01:35:44 +12:00
2017-10-24 10:40:37 +13:00
private MouseState mouseState = new MouseState();
private MouseState oldMouseState;
2016-08-06 01:35:44 +12:00
2017-10-24 10:40:37 +13:00
public void Update(Control control)
2016-08-06 01:35:44 +12:00
{
oldMouseState = mouseState;
mouseState.Update(control);
2016-08-06 01:35:44 +12:00
}
2017-10-24 10:40:37 +13:00
public bool IsMouseDown(MouseButtons button)
2016-08-06 01:35:44 +12:00
{
return mouseState.Buttons.HasFlag(button);
}
2017-10-24 10:40:37 +13:00
public bool IsBeforeMouseDown(MouseButtons button)
2016-08-06 01:35:44 +12:00
{
return oldMouseState.Buttons.HasFlag(button);
}
2017-10-24 10:40:37 +13:00
public bool IsMousePressed(MouseButtons button)
2016-08-06 01:35:44 +12:00
{
return IsMouseDown(button) && !IsBeforeMouseDown(button);
}
2017-10-24 10:40:37 +13:00
public bool IsMouseReleased(MouseButtons button)
2016-08-06 01:35:44 +12:00
{
return !IsMouseDown(button) && IsBeforeMouseDown(button);
}
2013-11-03 23:53:49 +13:00
}
}