-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputBroadcast.cpp
63 lines (42 loc) · 1.59 KB
/
InputBroadcast.cpp
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
#include "InputBroadcast.h"
namespace catapult {
InputBroadcast::InputBroadcast() :
keyboardSubscribersCount(0),
mouseSubscribersCount(0)
{ }
bool InputBroadcast::keyPressed(const OIS::KeyEvent& arg) {
for (size_t i = 0; i < keyboardSubscribersCount; ++i)
keyboardSubscribers.at(i)->keyPressed(arg);
return true;
}
bool InputBroadcast::keyReleased(const OIS::KeyEvent& arg) {
for (size_t i = 0; i < keyboardSubscribersCount; ++i)
keyboardSubscribers.at(i)->keyReleased(arg);
return true;
}
bool InputBroadcast::mouseMoved(const OIS::MouseEvent& arg) {
for (size_t i = 0; i < mouseSubscribersCount; ++i)
mouseSubscribers.at(i)->mouseMoved(arg);
return true;
};
bool InputBroadcast::mousePressed(const OIS::MouseEvent& arg, OIS::MouseButtonID id) {
for (size_t i = 0; i < mouseSubscribersCount; ++i)
mouseSubscribers.at(i)->mousePressed(arg, id);
return true;
}
bool InputBroadcast::mouseReleased(const OIS::MouseEvent& arg, OIS::MouseButtonID id) {
for (size_t i = 0; i < mouseSubscribersCount; ++i)
mouseSubscribers.at(i)->mouseReleased(arg, id);
return true;
}
void InputBroadcast::subscribeToKeyboard(OIS::KeyListener* newListener) {
if (keyboardSubscribersCount == keyboardSubscribers.size())
throw catapult::TooManySubscribers();
keyboardSubscribers.at(keyboardSubscribersCount++) = newListener;
}
void InputBroadcast::subscribeToMouse(OIS::MouseListener* newListener) {
if (mouseSubscribersCount == mouseSubscribers.size())
throw catapult::TooManySubscribers();
mouseSubscribers.at(mouseSubscribersCount++) = newListener;
}
}