summaryrefslogtreecommitdiff
path: root/noncore/games/kbill/UI.cpp
blob: 611cebfd1382f4fefe431398fc10b4b978b60b11 (plain)
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
/***************************************************************************
                          UI.cc  -  description
                             -------------------
    begin                : Thu Dec 30 1999
    copyright            : (C) 1999 by Jurrien Loonstra
    email                : j.h.loonstra@st.hanze.nl
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
#include "objects.h"
#include "Strings.h"
#ifdef KDEVER
#include <kapplication.h>
#endif
#include <qmessagebox.h>

#include "inputbox.h"

/**************************/
/* Timer control routines */
/**************************/

UI::~UI() {
	paint.end();
	delete pix;
}

void UI::restart_timer() {
	field->startTimer();
}

void UI::kill_timer() {
	field->stopTimer();
}

/*******************/
/* Window routines */
/*******************/

void UI::initialize(int *argc, char **argv) {
	 #ifdef KDEVER
	 app = new KApplication(*argc, argv, "kbill");
	 #endif
	 app = new QPEApplication(*argc, argv);
}

void UI::graph_init() {
	pix = new QPixmap(Game::scrwidth, Game::scrheight);
	paint.begin(pix, field);
	paint.setPen(QPen(Qt::black, 3));
}

void UI::make_mainwin() {
	main = new KBill();
	app->showMainWidget(main,true);
	main->showMaximized();
	field = main->getField();
}

void UI::popup_dialog (int dialog) {
	kill_timer();
	switch (dialog) {
	case Game::ENDGAME:
			QMessageBox::message(("Endgame"), QT_TR_NOOP(endgamestr));
			break;
	case Game::HIGHSCORE:
		//	QMessageBox::message(("HighScore"), highscorestr);
			break;
	case Game::ENTERNAME: {
			InputBox b(main, 0, ("Enter Name"), QT_TR_NOOP(enternamestr));
			bool state = b.exec() == 2;
		  char str[20], *nl;
	    strcpy(str, b.getText());
	    if (!str[0] || state)
				strcpy(str, "Anonymous");
	    else if ((nl = strchr(str, '\n')))
				*nl = '\0';
	    if (strlen(str) > 20)
				str[20] = 0;  /* truncate string if too long */
//	    scores.recalc(str);
			}
	    break;
	case Game::SCORE:
			QMessageBox::message(("Score"), scorestr);
			break;
	}
	restart_timer();
}

/*********************/
/* Graphics routines */
/*********************/

void UI::set_cursor(int cursor) {
	QCursor *cur;
	switch (cursor) {
	case Game::BUCKETC:
		cur = bucket.cursor.cursor;
		break;
	case Game::DOWNC:
		cur = downcursor.cursor;
		break;
	case Game::DEFAULTC:
		cur = defaultcursor.cursor;
		break;
	default:
		cur = OS.cursor[cursor].cursor;
	}
	field->setCursor(*cur);
}

void UI::load_cursors() {
	defaultcursor.load("hand_up", MCursor::SEP_MASK);
	field->setCursor(*defaultcursor.cursor);
	downcursor.load("hand_down", MCursor::SEP_MASK);
}

void UI::clear() {
	paint.eraseRect(0, 0, field->width(), field->height());
}

void UI::refresh() {
	paint.flush();
	field->setPixmap(pix);
	field->repaint(FALSE);
}

void UI::draw (Picture pict, int x, int y) {
	paint.drawPixmap(x, y, *pict.pix);
}

void UI::draw_centered (Picture pict) {
	draw(pict, (field->width() - pict.width) / 2, (field->height() - pict.height) / 2);
}

void UI::draw_line(int x1, int y1, int x2, int y2) {
	paint.drawLine(x1, y1, x2, y2);

}

void UI::draw_str(char *str, int x, int y) {
	paint.drawText(x, y, str);
}


/******************/
/* Other routines */
/******************/

void UI::set_pausebutton (int action) {
	main->file->setItemEnabled(main->pauseid, action);
}


int UI::MainLoop() {
  return app->exec();
}

void UI::update_hsbox(char *str) {
	highscorestr = str;	
}

void UI::update_scorebox(int level, int score) {
	scorestr.sprintf ("%s %d:\n%s: %d", QT_TR_NOOP("After Level"), level, QT_TR_NOOP("Your score"), score);
}