-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouse.cpp
More file actions
38 lines (29 loc) · 953 Bytes
/
Mouse.cpp
File metadata and controls
38 lines (29 loc) · 953 Bytes
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
#include "Mouse.h"
sf::Vector2f Mouse::GetRelativePosition()
{
return sf::Vector2f(sf::Mouse::getPosition(Window::Instance()->GetSfWindow()));
}
void Mouse::Update()
{
_lastFrameKeys.SetMask(_thisFrameKeys);
_thisFrameKeys.SetBit((int)Key::LMouseButton, sf::Mouse::isButtonPressed(sf::Mouse::Left));
_thisFrameKeys.SetBit((int)Key::RMouseButton, sf::Mouse::isButtonPressed(sf::Mouse::Right));
}
bool Mouse::IsLMBDown(Key keycode)
{
bool lastFrame = _lastFrameKeys.GetBit((int)keycode);
bool thisFrame = _thisFrameKeys.GetBit((int)keycode);
return thisFrame && !lastFrame;
}
bool Mouse::IsLMBPressed(Key keycode)
{
return _thisFrameKeys.GetBit((int)keycode);;
}
bool Mouse::IsLMBUp(Key keycode)
{
bool lastFrame = _lastFrameKeys.GetBit((int)keycode);
bool thisFrame = _thisFrameKeys.GetBit((int)keycode);
return !thisFrame && lastFrame;
}
Bitmask Mouse::_thisFrameKeys;
Bitmask Mouse::_lastFrameKeys;