Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

UI.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           UI.cc  -  description
00003                              -------------------
00004     begin                : Thu Dec 30 1999
00005     copyright            : (C) 1999 by Jurrien Loonstra
00006     email                : j.h.loonstra@st.hanze.nl
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 #include "objects.h"
00018 #include "Strings.h"
00019 #ifdef KDEVER
00020 #include <kapplication.h>
00021 #endif
00022 #include <qmessagebox.h>
00023 
00024 #include "inputbox.h"
00025 
00026 /**************************/
00027 /* Timer control routines */
00028 /**************************/
00029 
00030 UI::~UI() {
00031         paint.end();
00032         delete pix;
00033 }
00034 
00035 void UI::restart_timer() {
00036         field->startTimer();
00037 }
00038 
00039 void UI::kill_timer() {
00040         field->stopTimer();
00041 }
00042 
00043 /*******************/
00044 /* Window routines */
00045 /*******************/
00046 
00047 void UI::initialize(int *argc, char **argv) {
00048          #ifdef KDEVER
00049          app = new KApplication(*argc, argv, "kbill");
00050          #endif
00051          app = new QPEApplication(*argc, argv);
00052 }
00053 
00054 void UI::graph_init() {
00055         pix = new QPixmap(Game::scrwidth, Game::scrheight);
00056         paint.begin(pix, field);
00057         paint.setPen(QPen(Qt::black, 3));
00058 }
00059 
00060 void UI::make_mainwin() {
00061         main = new KBill();
00062         app->showMainWidget(main,true);
00063         main->showMaximized();
00064         field = main->getField();
00065 }
00066 
00067 void UI::popup_dialog (int dialog) {
00068         kill_timer();
00069         switch (dialog) {
00070         case Game::ENDGAME:
00071                         QMessageBox::message(("Endgame"), QT_TR_NOOP(endgamestr));
00072                         break;
00073         case Game::HIGHSCORE:
00074                 //      QMessageBox::message(("HighScore"), highscorestr);
00075                         break;
00076         case Game::ENTERNAME: {
00077                         InputBox b(main, 0, ("Enter Name"), QT_TR_NOOP(enternamestr));
00078                         bool state = b.exec() == 2;
00079                   char str[20], *nl;
00080             strcpy(str, b.getText());
00081             if (!str[0] || state)
00082                                 strcpy(str, "Anonymous");
00083             else if ((nl = strchr(str, '\n')))
00084                                 *nl = '\0';
00085             if (strlen(str) > 20)
00086                                 str[20] = 0;  /* truncate string if too long */
00087 //          scores.recalc(str);
00088                         }
00089             break;
00090         case Game::SCORE:
00091                         QMessageBox::message(("Score"), scorestr);
00092                         break;
00093         }
00094         restart_timer();
00095 }
00096 
00097 /*********************/
00098 /* Graphics routines */
00099 /*********************/
00100 
00101 void UI::set_cursor(int cursor) {
00102         QCursor *cur;
00103         switch (cursor) {
00104         case Game::BUCKETC:
00105                 cur = bucket.cursor.cursor;
00106                 break;
00107         case Game::DOWNC:
00108                 cur = downcursor.cursor;
00109                 break;
00110         case Game::DEFAULTC:
00111                 cur = defaultcursor.cursor;
00112                 break;
00113         default:
00114                 cur = OS.cursor[cursor].cursor;
00115         }
00116         field->setCursor(*cur);
00117 }
00118 
00119 void UI::load_cursors() {
00120         defaultcursor.load("hand_up", MCursor::SEP_MASK);
00121         field->setCursor(*defaultcursor.cursor);
00122         downcursor.load("hand_down", MCursor::SEP_MASK);
00123 }
00124 
00125 void UI::clear() {
00126         paint.eraseRect(0, 0, field->width(), field->height());
00127 }
00128 
00129 void UI::refresh() {
00130         paint.flush();
00131         field->setPixmap(pix);
00132         field->repaint(FALSE);
00133 }
00134 
00135 void UI::draw (Picture pict, int x, int y) {
00136         paint.drawPixmap(x, y, *pict.pix);
00137 }
00138 
00139 void UI::draw_centered (Picture pict) {
00140         draw(pict, (field->width() - pict.width) / 2, (field->height() - pict.height) / 2);
00141 }
00142 
00143 void UI::draw_line(int x1, int y1, int x2, int y2) {
00144         paint.drawLine(x1, y1, x2, y2);
00145 
00146 }
00147 
00148 void UI::draw_str(char *str, int x, int y) {
00149         paint.drawText(x, y, str);
00150 }
00151 
00152 
00153 /******************/
00154 /* Other routines */
00155 /******************/
00156 
00157 void UI::set_pausebutton (int action) {
00158         main->file->setItemEnabled(main->pauseid, action);
00159 }
00160 
00161 
00162 int UI::MainLoop() {
00163   return app->exec();
00164 }
00165 
00166 void UI::update_hsbox(char *str) {
00167         highscorestr = str;     
00168 }
00169 
00170 void UI::update_scorebox(int level, int score) {
00171         scorestr.sprintf ("%s %d:\n%s: %d", QT_TR_NOOP("After Level"), level, QT_TR_NOOP("Your score"), score);
00172 }

Generated on Sat Nov 5 16:17:20 2005 for OPIE by  doxygen 1.4.2