-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswTextMenu.cpp
More file actions
49 lines (41 loc) · 1.46 KB
/
swTextMenu.cpp
File metadata and controls
49 lines (41 loc) · 1.46 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
#include "swTextMenu.h"
#include <QKeyEvent>
swTextMenu::swTextMenu(swGame* g) : game(g), title(&game->font, "TITLE"), text(&game->font, "TEXT") {
type = SW_TEXT_MENU;
title.pos = swVector(0, 0.8);
title.scale = swVector(0.1, 0.1);
text.scale = swVector(0.05, 0.05);
connect(game, SIGNAL(keyEvent(QKeyEvent*)), SLOT(keyHandle(QKeyEvent*)));
connect(game, SIGNAL(mouseEvent(QMouseEvent*)), SLOT(mouseHandle(QMouseEvent*)));
}
swTextMenu::~swTextMenu() {}
void swTextMenu::draw() {
glPushMatrix();
transform();
title.draw();
text.draw();
glPopMatrix();
}
void swTextMenu::keyHandle(QKeyEvent* event) {
if(event->type() == QKeyEvent::KeyPress) {
if(event->key() == Qt::Key_Backspace && text.string.length()) {
text.string.chop(1);
}else if(event->key() == Qt::Key_Return && text.string.length()) {
enteredText(text.string);
}else if(event->text().length() < 20 &&
text.font->hasLetter(event->text().toUpper().toAscii().data()[0])) {
text.string.append(event->text().toUpper());
}
}
}
void swTextMenu::mouseHandle(QMouseEvent*) {
// we don't do anything interesting with the mouse here
// maybe I should have a continue button
}
void swTextMenu::remove() {
game->drawables.removeAll(this);
delete this;
}
void swTextMenu::enteredText(QString) {
// Qt doesn't like pure virtual classes
}