aboutsummaryrefslogtreecommitdiff
path: root/mwe/events/src/event.cpp
blob: 25090882c5d59fdfaf8cb126ad12086e9e427bda (plain)
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
#include "event.h"
#include "keyCodes.h"
// Event class methods
Event::Event(std::string eventType) { eventData["eventType"] = eventType; }

void Event::addArgument(const std::string & key,
						const std::variant<int, std::string, float> & value) {
	eventData[key] = value;
}

std::variant<int, std::string, float>
Event::getArgument(const std::string & key) const {
	return eventData.at(key);
}

std::string Event::getType() const {
	return std::get<std::string>(eventData.at("eventType"));
}
std::string Event::toString() const { return std::to_string(getEventType()); }
bool Event::getHandled() const { return isHandled; }

void Event::markHandled() { isHandled = true; }

// KeyPressedEvent class methods
KeyPressedEvent::KeyPressedEvent(int keycode)
	: Event("KeyPressedEvent"), key(keycode), repeatCount(0) {}

Keycode KeyPressedEvent::getKeyCode() const { return key; }

int KeyPressedEvent::getRepeatCount() const { return repeatCount; }

// KeyReleasedEvent class methods
KeyReleasedEvent::KeyReleasedEvent(int keycode)
	: Event("KeyReleasedEvent"), key(keycode) {}

Keycode KeyReleasedEvent::getKeyCode() const { return key; }

// MousePressedEvent class methods
MousePressedEvent::MousePressedEvent(int mouseX, int mouseY)
	: Event("MousePressedEvent"), mouseX(mouseX), mouseY(mouseY) {}

std::pair<int, int> MousePressedEvent::getMousePosition() const {
	return {mouseX, mouseY};
}

//Collision event
CollisionEvent::CollisionEvent(Collision collision) : collisionData(collision), Event("CollisionEvent") {

}

Collision CollisionEvent::getCollisionData() const
{
	return this->collisionData;
}

TextSubmitEvent::TextSubmitEvent(std::string text) : Event("TextSubmitEvent"){

}
std::string TextSubmitEvent::getText() const{
	return this->text;
}