-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
136 lines (115 loc) · 3.61 KB
/
mainwindow.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
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
this->timer = new QTimer(this);
connect(this->timer, SIGNAL(timeout()), this, SLOT(server_timer()));
ui->setupUi(this);
this->screen = new Screen(false, this);
this->router = new Router(this->screen, this);
this->ui->gv_Visualizer->setBackgroundBrush(Qt::black);
this->ui->gv_Visualizer->setScene(new QGraphicsScene());
Parameters::get()->setScreen(this->screen);
this->drawLines(std::vector<Point>());
this->cal = new calibrer(0,this->screen);
}
MainWindow::~MainWindow()
{
delete ui;
delete this->screen;
}
void MainWindow::updateProcessList(std::map<int,Client*> map){
this->ui->cb_process->clear();
for(std::map<int,Client*>::iterator it = map.begin(); it != map.end(); ++it){
this->ui->cb_process->addItem(it->second->getName());
}
}
void MainWindow::setOnScreen(QString proc_name){
QString disp = QString("Running : ");
disp +=proc_name;
this->ui->lbl_running->setText(disp);
}
void MainWindow::on_pb_launch_clicked()
{
int pid = router->getProcessFromName(this->ui->cb_process->currentText());
router->startProcess(pid);
}
void MainWindow::on_pb_stop_clicked()
{
router->stopProcess();
screen->clearFrame();
}
void MainWindow::drawLines(std::vector<Point> points){
QGraphicsScene * scene = this->ui->gv_Visualizer->scene();
scene->clear();
QRect geo = this->ui->gv_Visualizer->rect();
scene->setBackgroundBrush(Qt::black);
QPen pen;
Point previous;
for(std::vector<Point>::iterator it = points.begin(); it != points.end(); ++it){
if(it == points.begin()){
previous = *it;
}else{
int alpha = 255;
if((previous.r || previous.g || previous.b)){
pen = QPen(QColor(previous.r?255:0,previous.g?255:0,previous.b?255:0,alpha));
}else{
pen = QPen(QColor(0,255,0,70));
pen.setStyle(Qt::DashDotDotLine);
}
scene->addLine(previous.x*geo.width()/65535,previous.y*geo.height()/65535,(*it).x*geo.width()/65535,(*it).y*geo.height()/65535,pen);
previous = *it;
}
}
this->ui->gv_Visualizer->setScene(scene);
this->ui->gv_Visualizer->update();
}
void MainWindow::on_pb_dac_clicked()
{
this->ui->pb_dac->setEnabled(! this->screen->connectDAC());
}
void MainWindow::on_pb_cal_clicked()
{
this->cal->show();
this->cal->setFocus();
}
void MainWindow::setPoints(int nb_points){
QString text = "Points : " + QString::number(nb_points);
this->ui->lbl_points->setText(text);
}
void MainWindow::setLength(int length){
QString text = "Length : " + QString::number(length);
this->ui->lbl_length->setText(text);
}
void MainWindow::on_pb_rand_clicked()
{
this->router->randomGame();
}
void MainWindow::server_timer(){
QString fr = "FPS : "+QString::number(this->frames);
if(this->frames < MIN_FPS)
this->router->banProcess();
this->frames = 0;
QString ob = "OPS : "+QString::number(this->objs);
this->objs = 0;
this->ui->lbl_ops->setText(ob);
this->ui->lbl_fps->setText(fr);
}
void MainWindow::addFrame(int objects){
this->frames++;
this->objs += objects;
}
void MainWindow::on_checkBox_clicked()
{
this->router->setDebug(this->ui->cb_debug->isChecked());
}
void MainWindow::inputConnected(){
this->ui->lbl_input->setText("Input Controller : connected");
}
void MainWindow::on_pb_test_pattern_clicked()
{
this->router->stopProcess();
this->screen->sendTestPattern();
}