-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputHandler.cpp
More file actions
74 lines (63 loc) · 2.22 KB
/
Copy pathInputHandler.cpp
File metadata and controls
74 lines (63 loc) · 2.22 KB
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
#include <sstream>
#include "InputHandler.h"
using namespace sf;
using namespace std;
void InputHandler::initializeInputHandler(
ScreenManagerRemoteControl* sw,
vector<shared_ptr<Button>> buttons,
View* pointerToUIView,
Screen* parentScreen
)
{
m_ScreenManagerRemoteControl = sw;
m_Buttons = buttons;
m_PointerToUIPanelView = pointerToUIView;
m_ParentScreen = parentScreen;
}
void InputHandler::handleInput(RenderWindow& window, Event& event)
{
// Handle key presses
if (event.type == Event::KeyPressed)
{
handleKeyPressed(event, window);
}
if (event.type == Event::KeyReleased)
{
handleKeyReleased(event, window);
}
// Handle left mouse click released
if (event.type == Event::MouseButtonReleased)
{
auto end = m_Buttons.end();
for (auto i = m_Buttons.begin(); i != end; ++i)
{
// Mouse::getPosition() with no argument returns desktop
// coordinates; the window overload returns coordinates relative to
// the window, which is what mapPixelToCoords expects. The two only
// agree when the window is at the origin -- i.e. fullscreen.
if ((*i)->m_Collider.contains(window.mapPixelToCoords(Mouse::getPosition(window), (*getPointerToUIView()))))
{
// Capture text of the button that was interacted with and pass to the specialized version of this class
handleLeftClick((*i)->m_Text, window);
break;
}
}
}
handleGamepad();
}
void InputHandler::handleGamepad(){} // do nothing unless handled by derived class
void InputHandler::handleKeyPressed(Event&, RenderWindow&){} // do nothing unless handled by derived class
void InputHandler::handleKeyReleased(Event&, RenderWindow&){} // do nothing unless handled by derived class
void InputHandler::handleLeftClick(string&, RenderWindow&){} // do nothing unless handled by derived class
View* InputHandler::getPointerToUIView()
{
return m_PointerToUIPanelView;
}
ScreenManagerRemoteControl* InputHandler::getPointerToScreenManagerRemoteControl()
{
return m_ScreenManagerRemoteControl;
}
Screen* InputHandler::getParentScreen()
{
return m_ParentScreen;
}