summaryrefslogtreecommitdiff
path: root/noncore/games/kbill/UI.cpp
Unidiff
Diffstat (limited to 'noncore/games/kbill/UI.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/kbill/UI.cpp175
1 files changed, 175 insertions, 0 deletions
diff --git a/noncore/games/kbill/UI.cpp b/noncore/games/kbill/UI.cpp
new file mode 100644
index 0000000..fac731a
--- a/dev/null
+++ b/noncore/games/kbill/UI.cpp
@@ -0,0 +1,175 @@
1/***************************************************************************
2 UI.cc - description
3 -------------------
4 begin : Thu Dec 30 1999
5 copyright : (C) 1999 by Jurrien Loonstra
6 email : j.h.loonstra@st.hanze.nl
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17#include "kbill.h"
18#include "objects.h"
19#include "Strings.h"
20#ifdef KDEVER
21#include <kapplication.h>
22#endif
23#include <qpixmap.h>
24#include <qmessagebox.h>
25#include <qnamespace.h>
26
27#include "inputbox.h"
28
29/**************************/
30/* Timer control routines */
31/**************************/
32
33UI::~UI() {
34 paint.end();
35 delete pix;
36}
37
38void UI::restart_timer() {
39 field->startTimer();
40}
41
42void UI::kill_timer() {
43 field->stopTimer();
44}
45
46/*******************/
47/* Window routines */
48/*******************/
49
50void UI::initialize(int *argc, char **argv) {
51 #ifdef KDEVER
52 app = new KApplication(*argc, argv, "kbill");
53 #endif
54 app = new QPEApplication(*argc, argv);
55}
56
57void UI::graph_init() {
58 pix = new QPixmap(Game::scrwidth, Game::scrheight);
59 paint.begin(pix, field);
60 paint.setPen(QPen(Qt::black, 3));
61}
62
63void UI::make_mainwin() {
64 main = new KBill();
65 app->showMainWidget(main,true);
66 main->showMaximized();
67 field = main->getField();
68}
69
70void UI::popup_dialog (int dialog) {
71 kill_timer();
72 switch (dialog) {
73 case Game::ENDGAME:
74 QMessageBox::message(("Endgame"), (endgamestr));
75 break;
76 case Game::HIGHSCORE:
77 //QMessageBox::message(("HighScore"), highscorestr);
78 break;
79 case Game::ENTERNAME: {
80 InputBox b(main, 0, ("Enter Name"), (enternamestr));
81 bool state = b.exec() == 2;
82 char str[20], *nl;
83 strcpy(str, b.getText());
84 if (!str[0] || state)
85 strcpy(str, "Anonymous");
86 else if ((nl = strchr(str, '\n')))
87 *nl = '\0';
88 if (strlen(str) > 20)
89 str[20] = 0; /* truncate string if too long */
90 // scores.recalc(str);
91 }
92 break;
93 case Game::SCORE:
94 QMessageBox::message(("Score"), scorestr);
95 break;
96 }
97 restart_timer();
98}
99
100/*********************/
101/* Graphics routines */
102/*********************/
103
104void UI::set_cursor(int cursor) {
105 QCursor *cur;
106 switch (cursor) {
107 case Game::BUCKETC:
108 cur = bucket.cursor.cursor;
109 break;
110 case Game::DOWNC:
111 cur = downcursor.cursor;
112 break;
113 case Game::DEFAULTC:
114 cur = defaultcursor.cursor;
115 break;
116 default:
117 cur = OS.cursor[cursor].cursor;
118 }
119 field->setCursor(*cur);
120}
121
122void UI::load_cursors() {
123 defaultcursor.load("hand_up", MCursor::SEP_MASK);
124 field->setCursor(*defaultcursor.cursor);
125 downcursor.load("hand_down", MCursor::SEP_MASK);
126}
127
128void UI::clear() {
129 paint.eraseRect(0, 0, field->width(), field->height());
130}
131
132void UI::refresh() {
133 paint.flush();
134 field->setPixmap(pix);
135 field->repaint(FALSE);
136}
137
138void UI::draw (Picture pict, int x, int y) {
139 paint.drawPixmap(x, y, *pict.pix);
140}
141
142void UI::draw_centered (Picture pict) {
143 draw(pict, (field->width() - pict.width) / 2, (field->height() - pict.height) / 2);
144}
145
146void UI::draw_line(int x1, int y1, int x2, int y2) {
147 paint.drawLine(x1, y1, x2, y2);
148
149}
150
151void UI::draw_str(char *str, int x, int y) {
152 paint.drawText(x, y, str);
153}
154
155
156/******************/
157/* Other routines */
158/******************/
159
160void UI::set_pausebutton (int action) {
161 main->file->setItemEnabled(main->pauseid, action);
162}
163
164
165int UI::MainLoop() {
166 return app->exec();
167}
168
169void UI::update_hsbox(char *str) {
170 highscorestr = str;
171}
172
173void UI::update_scorebox(int level, int score) {
174 scorestr.sprintf ("%s %d:\n%s: %d", ("After Level"), level, ("Your score"), score);
175}