-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
111 lines (96 loc) · 2.43 KB
/
MainWindow.cpp
File metadata and controls
111 lines (96 loc) · 2.43 KB
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
#include <QWidget>
#include <QtGui>
#include <QGridLayout>
#include "MainWindow.h"
#include "GameInfo.h"
#include "GraphicRender.h"
#include "GameRender.h"
#include "ControlPanel.h"
MainWindow::MainWindow()
: QWidget(0)
{
setWindowTitle(tr("Optic-OPS"));
setWindowState(Qt::WindowFullScreen);
Info = new GameInfo;
Render = new GraphicRender(Info);
Panel = new ControlPanel(Info);
GameEngine = new GameRender(Info);
QGridLayout *MainLayout = new QGridLayout;
MainLayout->addWidget(Render, 0, 0);
MainLayout->addWidget(Panel, 1, 0);
setLayout(MainLayout);
}
MainWindow::~MainWindow()
{
delete Panel;
delete Render;
delete Info;
}
void MainWindow::keyPressEvent(QKeyEvent *event)
{
switch (event->key())
{
case Qt::Key_Left:
Info->ScrollHorizontal = -1;
break;
case Qt::Key_Right:
Info->ScrollHorizontal = 1;
break;
case Qt::Key_Up:
Info->ScrollVertical = -1;
break;
case Qt::Key_Down:
Info->ScrollVertical = 1;
break;
}
}
void MainWindow::keyReleaseEvent(QKeyEvent *event)
{
switch (event->key())
{
case Qt::Key_Left:
case Qt::Key_Right:
Info->ScrollHorizontal = 0;
break;
case Qt::Key_Up:
case Qt::Key_Down:
Info->ScrollVertical = 0;
break;
}
}
void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
int mouse_x = event->x();
int mouse_y = event->y();
int screen_size_x = width();
int screen_size_y = height();
if (mouse_x <= 3)
{
Info->ScrollHorizontal = -1; // Scroll in left
if (mouse_y <= 10) Info->ScrollVertical = -1; // and in up
else if (mouse_y >= screen_size_y-10) Info->ScrollVertical = 1; // then and in down
}
else if (mouse_x >= screen_size_x-3)
{
Info->ScrollHorizontal = 1; // Scroll in rigth
if (mouse_y <= 10) Info->ScrollVertical = -1; // and in up
else if (mouse_y >= screen_size_y-10) Info->ScrollVertical = 1; // then and in down
}
else if (mouse_y <= 3)
{
Info->ScrollVertical = -1; // Scroll in up
if (mouse_x <= 10) Info->ScrollHorizontal = -1; // and in left
else if (mouse_x >= screen_size_x-10) Info->ScrollHorizontal = 1; // then and in rigth
}
else if (mouse_y >= screen_size_y-3)
{
Info->ScrollVertical = 1; // Scroll in down
if (mouse_x <= 10) Info->ScrollHorizontal = -1; // and in left
else if (mouse_x >= screen_size_x-10) Info->ScrollHorizontal = 1; // then and in rigth
}
else
{ // Dont scrolling
Info->ScrollHorizontal = 0;
Info->ScrollVertical = 0;
}
}