-
Notifications
You must be signed in to change notification settings - Fork 0
/
MouseManager.cs
82 lines (75 loc) · 2.34 KB
/
MouseManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
namespace FFRMapEditorMono
{
public class MouseState
{
public bool LeftClick;
public bool RightClick;
public bool MiddleClick;
public bool LeftDown;
public bool RightDown;
public bool MiddleDown;
public bool ScrollUp;
public bool ScrollDown;
public Vector2 Position;
private ButtonState lastLeftState;
private ButtonState lastRightState;
private ButtonState lastMiddleState;
private int wheelRoll;
private Vector2 holdOffset;
public MouseState()
{
Update();
}
public void Update()
{
ButtonState currentLeftState = Mouse.GetState().LeftButton;
ButtonState currentRightState = Mouse.GetState().RightButton;
ButtonState currentMiddleState = Mouse.GetState().MiddleButton;
Position = new Vector2(Mouse.GetState().Position.X, Mouse.GetState().Position.Y);
LeftClick = (lastLeftState == ButtonState.Released && currentLeftState == ButtonState.Pressed);
RightClick = (lastRightState == ButtonState.Released && currentRightState == ButtonState.Pressed);
MiddleClick = (lastMiddleState == ButtonState.Released && currentMiddleState == ButtonState.Pressed);
LeftDown = (lastLeftState == ButtonState.Pressed && currentLeftState == ButtonState.Pressed);
RightDown = (lastRightState == ButtonState.Pressed && currentRightState == ButtonState.Pressed);
MiddleDown = (lastMiddleState == ButtonState.Pressed && currentMiddleState == ButtonState.Pressed);
lastLeftState = currentLeftState;
lastRightState = currentRightState;
lastMiddleState = currentMiddleState;
if (Mouse.GetState().ScrollWheelValue > wheelRoll)
{
wheelRoll = Mouse.GetState().ScrollWheelValue;
ScrollUp = true;
ScrollDown = false;
}
else if (Mouse.GetState().ScrollWheelValue < wheelRoll)
{
wheelRoll = Mouse.GetState().ScrollWheelValue;
ScrollUp = false;
ScrollDown = true;
}
else
{
ScrollUp = false;
ScrollDown = false;
}
}
public Vector2 GetHoldOffset()
{
Vector2 offset = new Vector2(holdOffset.X - Position.X, holdOffset.Y - Position.Y);
holdOffset = Position;
return offset;
}
public void SetHoldOffset()
{
holdOffset = Position;
}
}
}