-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventHandler.cpp
167 lines (159 loc) · 5.98 KB
/
eventHandler.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//
// Created by jovasa on 15.1.2024.
//
#include <iostream>
#include "eventHandler.h"
#include "zmq.h"
#include "util.h"
EventHandler::EventHandler(uint32_t width, uint32_t height, void* socket) :
width(width),
height(height),
control_socket(socket) {
#ifdef _MSC_VER
screen_height = sf::VideoMode::getDesktopMode().height;
screen_width = sf::VideoMode::getDesktopMode().width;
QueryPerformanceFrequency(&Frequency);
#endif
}
bool EventHandler::handle(sf::Event &event, config &cfg, sf::RenderWindow &window) {
if (event.type == sf::Event::Closed) {
window.close();
cfg.running = false;
}
if (event.type == sf::Event::KeyPressed) {
if (event.key.code == sf::Keyboard::F) {
toggleFullscreen(cfg, window);
return true;
}
if (event.key.code == sf::Keyboard::Escape) {
window.close();
cfg.running = false;
}
if (event.key.code == sf::Keyboard::G) {
cfg.show_grid = !cfg.show_grid;
return true;
}
if (event.key.code == sf::Keyboard::Z) {
cfg.show_zoom = !cfg.show_zoom;
}
if (event.key.code == sf::Keyboard::I) {
cfg.show_intra = !cfg.show_intra;
return true;
}
if (event.key.code == sf::Keyboard::D) {
cfg.show_debug = !cfg.show_debug;
}
if (event.key.code == sf::Keyboard::F1) {
cfg.show_help = !cfg.show_help;
}
if (event.key.code == sf::Keyboard::Q) {
cfg.show_qp = !cfg.show_qp;
return true;
}
if (event.key.code == sf::Keyboard::H) {
cfg.show_heatmap = (cfg.show_heatmap + 1) & 3;
return true;
}
if (event.key.code == sf::Keyboard::W) {
cfg.show_transform = !cfg.show_transform;
return true;
}
if (event.key.code == sf::Keyboard::E) {
cfg.show_isp = !cfg.show_isp;
return true;
}
if (event.key.code == sf::Keyboard::Space) {
cfg.paused = !cfg.paused;
return true;
}
if(event.key.code == sf::Keyboard::S) {
char *msg = const_cast<char *>(shift_pressed ? "s" : "S");
zmq_send(control_socket, msg, 1, 0);
}
if(event.key.code == sf::Keyboard::M) {
char *msg = const_cast<char *>(shift_pressed ? "m" : "M");
zmq_send(control_socket, msg, 1, 0);
}
if(event.key.code == sf::Keyboard::P) {
char *msg = const_cast<char *>(shift_pressed ? "p" : "P");
zmq_send(control_socket, msg, 1, 0);
}
if(event.key.code == sf::Keyboard::T) {
char *msg = const_cast<char *>(shift_pressed ? "t" : "T");
zmq_send(control_socket, msg, 1, 0);
}
if(event.key.code == sf::Keyboard::L) {
char *msg = const_cast<char *>(shift_pressed ? "l" : "L");
zmq_send(control_socket, msg, 1, 0);
}
if(event.key.code == sf::Keyboard::Num0 || event.key.code == sf::Keyboard::Numpad0) {
char *msg = const_cast<char *>(ctrl_pressed ? "C0" : "0");
zmq_send(control_socket, msg, 2, 0);
}
if(event.key.code == sf::Keyboard::Num1 || event.key.code == sf::Keyboard::Numpad1) {
char *msg = const_cast<char *>(ctrl_pressed ? "C1" : "1");
zmq_send(control_socket, msg, 2, 0);
}
if(event.key.code == sf::Keyboard::Num3 || event.key.code == sf::Keyboard::Numpad3) {
char *msg = const_cast<char *>(ctrl_pressed ? "C2" : "2");
zmq_send(control_socket, msg, 2, 0);
}
if(event.key.code == sf::Keyboard::Num3 || event.key.code == sf::Keyboard::Numpad3) {
char *msg = const_cast<char *>(ctrl_pressed ? "C3" : "3");
zmq_send(control_socket, msg, 2, 0);
}
if(event.key.code >= sf::Keyboard::Num4 && event.key.code < sf::Keyboard::Num9) {
if(!ctrl_pressed && !shift_pressed) {
const std::string temp = std::to_string(event.key.code - sf::Keyboard::Num0);
char *msg = const_cast<char *>(temp.c_str());
zmq_send(control_socket, msg, 1, 0);
}
}
if(event.key.code == sf::Keyboard::LControl || event.key.code == sf::Keyboard::RControl) {
ctrl_pressed = true;
}
if(event.key.code == sf::Keyboard::LShift || event.key.code == sf::Keyboard::RShift) {
shift_pressed = true;
}
if(event.key.code == sf::Keyboard::LAlt || event.key.code == sf::Keyboard::RAlt) {
alt_pressed = true;
}
}
if (event.type == sf::Event::KeyReleased) {
if(event.key.code == sf::Keyboard::LControl || event.key.code == sf::Keyboard::RControl) {
ctrl_pressed = false;
}
if(event.key.code == sf::Keyboard::LShift || event.key.code == sf::Keyboard::RShift) {
shift_pressed = false;
}
if(event.key.code == sf::Keyboard::LAlt || event.key.code == sf::Keyboard::RAlt) {
alt_pressed = false;
}
}
if (event.type == sf::Event::MouseButtonPressed) {
TimeStamp ts;
uint64_t now;
GET_TIME(ts, now);
if (event.mouseButton.button == sf::Mouse::Left) {
if (now - last_click < 400'000'000) {
toggleFullscreen(cfg, window);
return true;
}
last_click = now;
}
if (event.mouseButton.button == sf::Mouse::Right) {
if (now - last_click2 < 200) {
}
last_click2 = now;
}
}
return false;
}
void EventHandler::toggleFullscreen(config &cfg, sf::RenderWindow &window) const {
if (cfg.fullscreen) {
window.create(sf::VideoMode(width, height), "VVC Visualizer", sf::Style::Default);
} else {
window.create(sf::VideoMode(screen_width, screen_height), "VVC Visualizer", sf::Style::Fullscreen);
}
cfg.fullscreen = !cfg.fullscreen;
}