-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainmenuwidget.cpp
215 lines (187 loc) · 5.47 KB
/
mainmenuwidget.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#include "mainmenuwidget.h"
#include <QTimer>
#include <QPixmap>
#include <QPainter>
#include "achievementwidget.h"
#include "basicpainter.h"
#include "mainmenuitems.h"
#include "gamecommonitems.h"
#include "puzzlemenuwidget.h"
#include "othergameinit.h"
#include "helpwidget2.h"
#define LOGICAL_WIDTH 1024
#define LOGICAL_HEIGHT 600
MainMenuWidget::MainMenuWidget() :
frameCount(0)
{
// Create the items and initialize them
items[0] = new MainMenuGameItem((AbstractMainMenuItem::ItemType)0);
items[0]->setPos(QPointF(0.375, 0.5));
items[1] = new MainMenuGameItem((AbstractMainMenuItem::ItemType)1);
items[1]->setPos(QPointF(0.835, 0.5));
items[2] = new MainMenuGameItem((AbstractMainMenuItem::ItemType)2);
items[2]->setPos(QPointF(0.49, 0.16));
items[3] = new MainMenuGameItem((AbstractMainMenuItem::ItemType)3);
items[3]->setPos(QPointF(0.72, 0.84));
items[4] = new MainMenuGameItem((AbstractMainMenuItem::ItemType)4);
items[4]->setPos(QPointF(0.72, 0.16));
items[5] = new MainMenuGameItem((AbstractMainMenuItem::ItemType)5);
items[5]->setPos(QPointF(0.49, 0.84));
items[6] = new MainMenuGameItem(AbstractMainMenuItem::RotatePuzzleItem);
items[6]->setPos(QPointF(0.605, 0.5));
items[7] = new ButtonItem("Achievement");
items[7]->setPos(QPointF(0.1, 0.55));
items[8] = new ButtonItem("Help");
items[8]->setPos(QPointF(0.1, 0.65));
items[9] = new ButtonItem("Exit");
items[9]->setPos(QPointF(0.1, 0.8));
AbstractItem *board = new RotatingCircleItem(false);
board->setPos(QPointF(0.600, 0.495));
myItems.push_back(board);
for (int i = 0;i < 10;++i)
myItems.push_back(items[i]);
// Create the timer and connect signals and slots
t = new QTimer();
t->setInterval(75);
connect(t, SIGNAL(timeout()), this, SLOT(advance()));
t->start();
}
void MainMenuWidget::makePixmap(
#ifdef USE_PIXMAP
QPixmap& pixmap,
#else
QPainter* painter,
#endif
int width,
int height)
{
#ifdef USE_PIXMAP
makeBasicPixmap(pixmap, width, height);
addEffect(pixmap, width, height);
#else
makeBasicPixmap(painter, width, height);
addEffect(painter, width, height);
#endif
}
void MainMenuWidget::makeBasicPixmap(
#ifdef USE_PIXMAP
QPixmap& pixmap,
#else
QPainter* painter,
#endif
int width,
int height)
{
#ifdef USE_PIXMAP
pixmap = QPixmap(width, height);
// Fill the pixmap with black background
pixmap.fill(Qt::black);
// Get the painter
QPainter *painter = new QPainter(&pixmap);
#endif
// Paint the background
BasicPainter::paintBackGround(BasicPainter::MainMenu,
painter,
width,
height,
frameCount);
// Paint the basic balls
BasicPainter::paintItems(painter,
myItems,
width,
height,
frameCount);
#ifdef USE_PIXMAP
// End the paint and release the space
painter->end();
delete painter;
#endif
}
void MainMenuWidget::addEffect(
#ifdef USE_PIXMAP
QPixmap& pixmap,
#else
QPainter* painter,
#endif
int width,
int height)
{
}
QPointF MainMenuWidget::toScene(double xRate, double yRate)
{
return QPointF(xRate * LOGICAL_WIDTH,
yRate * LOGICAL_HEIGHT);
}
void MainMenuWidget::dealPressed(QPointF mousePos, Qt::MouseButton button)
{
// Quit if it's a right button. May be abandoned later
if (button == Qt::RightButton)
{
emit giveControlTo(NULL, true);
delete this;
return;
}
// Create correct game if neccessary
for (int i = 0;i < 6;++i)
{
if (items[i]->in(mousePos, LOGICAL_WIDTH, LOGICAL_HEIGHT))
{
AbstractRule::Gesture gesture = (i % 2 == 0) ?
AbstractRule::Swap :
AbstractRule::Rotate;
AbstractPixmapWidget *game = OtherGameInit::initOtherGame(gesture,
i / 2);
emit giveControlTo(game, false);
return;
}
}
// Create puzzle game if neccessary
if (items[6]->in(mousePos, LOGICAL_WIDTH, LOGICAL_HEIGHT))
{
AbstractPixmapWidget *puzzleMenu = new PuzzleMenuWidget();
emit giveControlTo(puzzleMenu, false);
return;
}
// Go to achievement if neccessary
else if (items[7]->in(mousePos, LOGICAL_WIDTH, LOGICAL_HEIGHT))
{
AbstractPixmapWidget *achievementWidget = new AchievementWidget();
emit giveControlTo(achievementWidget, false);
return;
}
// Go to help if neccessary
else if (items[8]->in(mousePos, LOGICAL_WIDTH, LOGICAL_HEIGHT))
{
AbstractPixmapWidget *helpWidget = new HelpWidget2();
emit giveControlTo(helpWidget, false);
return;
}
// Exit if neccessary
else if (items[9]->in(mousePos, LOGICAL_WIDTH, LOGICAL_HEIGHT))
{
emit giveControlTo(NULL, true);
delete this;
return;
}
}
void MainMenuWidget::dealMoved(QPointF mousePos, Qt::MouseButton button)
{
}
void MainMenuWidget::dealReleased(QPointF mousePos, Qt::MouseButton button)
{
}
void MainMenuWidget::advance()
{
++frameCount;
frameCount = frameCount;
}
MainMenuWidget::~MainMenuWidget()
{
// Stop the timer
t->stop();
// Release the space
delete t;
for (int i = 0;i < myItems.size();++i)
delete myItems[i];
myItems.clear();
}