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

ballpainter.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           ballpainter.cpp  -  description
00003                              -------------------
00004     begin                : Fri May 19 2000
00005     copyright            : (C) 2000 by Roman Merzlyakov
00006     email                : roman@sbrf.barrt.ru
00007     copyright            : (C) 2000 by Roman Razilov
00008     email                : Roman.Razilov@gmx.de
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *   This program is free software; you can redistribute it and/or modify  *
00014  *   it under the terms of the GNU General Public License as published by  *
00015  *   the Free Software Foundation; either version 2 of the License, or     *
00016  *   (at your option) any later version.                                   *
00017  *                                                                         *
00018  ***************************************************************************/
00019 
00020 #include <opie2/oresource.h>
00021 
00022 #include "ballpainter.h"
00023 //#include "shotcounter.h"
00024 #include <qpainter.h>
00025 //#include <qcolor.h>
00026 
00027 
00028 #define PIXSIZE 21
00029 
00030 int colorLinesArr[NCOLORS] =
00031 {0x0000ff, 0x00ff00, 0xff0000, 0x00ffff, 0xff00ff, 0xffff00, 0x005080};
00032 // 0x00bbggrr
00033 // red   ,  green  ,  blue   , yellow  , violet  ,   cyan  , brown
00034 
00035 
00036 
00037 BallPainter::BallPainter()
00038         : QObject()
00039 {
00040         createPixmap();
00041 }
00042 
00043 BallPainter::~BallPainter()
00044 {
00045 }
00046 
00047 QPixmap* BallPainter::pixmap( enum Pixmaps pix )
00048 {
00049     QString name;
00050     switch(pix) {
00051     case Field:
00052         name = QString::fromLatin1("zlines/field");
00053         break;
00054     case Balls:
00055         name = QString::fromLatin1("zlines/balls");
00056         break;
00057     case Fire:
00058         name = QString::fromLatin1("zlines/fire");
00059         break;
00060     }
00061 
00062     return new QPixmap(Opie::Core::OResource::loadPixmap(name) );
00063 }
00064 
00065 void BallPainter::createPixmap()
00066 {
00067         //  warning( kapp->kde_datadir() +"/klines/data/balls.bmp");
00068         backgroundPix = pixmap(Field);
00069         QPixmap *balls = pixmap(Balls);
00070         QPixmap *fire = pixmap(Fire);
00071         if (balls->isNull() ||backgroundPix->isNull() || fire->isNull() )
00072                 fatal("Cannot open data files.\nHave you correctly installed klines?");
00073 
00074         warning("Pixsize %i", PIXSIZE);
00075         for(int c=0; c<NCOLORS; c++)
00076         {
00077                 for(int t=0; t<PIXTIME + FIREBALLS + BOOMBALLS + 1 ; t++)
00078                 {
00079                         imgCash[c][t] = new QPixmap(CELLSIZE, CELLSIZE);
00080                         QPainter p(imgCash[c][t]);
00081                         p.drawPixmap(0,0,(*backgroundPix),0,0,CELLSIZE,CELLSIZE);
00082                         p.drawPixmap(1,1,(*balls),t*PIXSIZE,c*PIXSIZE,PIXSIZE,PIXSIZE);
00083                 }
00084                 for(int t=0; t < FIREPIX ; t++)
00085                 {
00086                         firePix[t] = new QPixmap(CELLSIZE, CELLSIZE);
00087                         QPainter p(firePix[t]);
00088                         p.drawPixmap(0,0,(*backgroundPix),0,0,CELLSIZE,CELLSIZE);
00089                         p.drawPixmap(1,1,(*fire),t*PIXSIZE,0,PIXSIZE,PIXSIZE);
00090                 }
00091         }
00092         delete balls;
00093         delete fire;
00094 }
00095 
00096 
00097 QPixmap* BallPainter::GetBall(int color, int animstep, int panim)
00098 {
00099         //    return backgroundPix;
00100 
00101         if( (color<0) || (color>=NCOLORS) || (animstep<0) || color == NOBALL )
00102         {
00103                 // warning("BallPainter::Background");
00104                 return backgroundPix;
00105         }
00106         if ( panim == ANIM_JUMP )
00107         {
00108                 if ( ( animstep < 0 ) || ( animstep >= PIXTIME ) )
00109                         return backgroundPix;
00110                 else
00111                         return imgCash[color][animstep];
00112         }
00113         else if ( panim == ANIM_BURN )
00114         {
00115                 if ( animstep < FIREBALLS )
00116                         return imgCash[color][animstep + PIXTIME + BOOMBALLS + 1];
00117                 else if ( animstep < FIREBALLS + FIREPIX )
00118                         return firePix[animstep - FIREBALLS];
00119         }
00120         else if ( panim == ANIM_BORN )
00121         {
00122                 if ( animstep < BOOMBALLS )
00123                         return imgCash[color][animstep + PIXTIME];
00124                 else
00125                         return imgCash[color][NORMALBALL];
00126         }
00127         // rest is not imlemented yet
00128         return imgCash[color][NORMALBALL];
00129 
00130 }
00131 
00132 

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