-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
50 lines (40 loc) · 1.56 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
#include "mainwindow.h"
#include "collision_stuff/box.h"
#include "items/ball.h"
#include "items/wall.h"
#include <QGraphicsScene>
#include <QVBoxLayout>
#include <QSplitter>
MainWindow::MainWindow(QWidget *parent) : QWidget(parent) {
mScene = new QGraphicsScene(this);
mScene->setSceneRect(QRectF(0, 0,gWidth-gBuffer, gHeight-gBuffer));
mView = new View();
mView->getQGraphicsView()->setScene(mScene);
connect(mView->getGraphicsView(), &GraphicsView::singleClick,
this, &MainWindow::createBox);
auto layout = new QVBoxLayout;
layout->addWidget(mView);
setLayout(layout);
setWindowTitle("Interactive collision detection thing");
setFixedSize(gWidth, gHeight+100);
mScene->addItem(mView->getGraphicsView()->getLine());
createWall(QLineF(QPointF(0, 0), QPointF(gWidth-100, 0)), false);
createWall(QLineF(QPointF(gWidth-100, 0), QPointF(gWidth-100, gHeight-100)), false);
createWall(QLineF(QPointF(gWidth-100, gHeight-100), QPointF(0, gHeight-100)), false);
createWall(QLineF(QPointF(0, gHeight-100), QPointF(0, 0)), false);
mView->getGraphicsView()->addEnergyLabel();
mView->getGraphicsView()->startTimer(1000/60);
};
void MainWindow::createBox(qreal x, qreal y)
{
qreal* temp = mView->getGraphicsView()->getTemp();
auto box = new Box(x, y, temp);
for (auto w : box->getWalls())
mScene->addItem(w);
}
void MainWindow::createWall(QLineF l, bool canBeDeleted)
{
qreal* temp = mView->getGraphicsView()->getTemp();
auto item = new Wall(l, temp, canBeDeleted);
mScene->addItem(item);
}