File indexing completed on 2021-12-21 12:50:20

0001 /*
0002  *  ksokoban - a Sokoban game by KDE
0003  *  Copyright (C) 1998  Anders Widell  <d95-awi@nada.kth.se>
0004  *
0005  *  This program is free software; you can redistribute it and/or modify
0006  *  it under the terms of the GNU General Public License as published by
0007  *  the Free Software Foundation; either version 2 of the License, or
0008  *  (at your option) any later version.
0009  *
0010  *  This program is distributed in the hope that it will be useful,
0011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  *  GNU General Public License for more details.
0014  *
0015  *  You should have received a copy of the GNU General Public License
0016  *  along with this program; if not, write to the Free Software
0017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0018  */
0019 
0020 #ifndef IMAGEDATA_H
0021 #define IMAGEDATA_H
0022 
0023 #include <QImage>
0024 #include <QPixmap>
0025 
0026 #include <QRandomGenerator>
0027 
0028 class QPainter;
0029 
0030 #define SMALL_STONES 4
0031 #define LARGE_STONES 6
0032 #define OTHER_IMAGES 5
0033 #define NO_OF_IMAGES (SMALL_STONES + LARGE_STONES + OTHER_IMAGES)
0034 
0035 class
0036 ImageData {
0037 public:
0038   virtual ~ImageData();
0039 
0040   int resize(int size);
0041   int size() { return size_; }
0042 
0043   void wall(QPainter &p, int x, int y, int index, bool left, bool right);
0044   void floor(QPainter &p, int x, int y);
0045   void goal(QPainter &p, int x, int y);
0046   void man(QPainter &p, int x, int y);
0047   void object(QPainter &p, int x, int y);
0048   void saveman(QPainter &p, int x, int y);
0049   void treasure(QPainter &p, int x, int y);
0050   void brightObject(QPainter &p, int x, int y);
0051   void brightTreasure(QPainter &p, int x, int y);
0052 
0053   const QPixmap &background() { return background_; }
0054   const QImage& objectImg() const { return objectImg_; }
0055 
0056 protected:
0057   ImageData();
0058 
0059   void expandIndex(int size);
0060   void image2pixmap(const QImage &img, QPixmap& xpm, bool diffuse=true);
0061   void brighten(QImage& img);
0062 
0063   const QPixmap &upperLarge(int index);
0064   const QPixmap &lowerLarge(int index);
0065   const QPixmap &leftSmall(int index);
0066   const QPixmap &rightSmall(int index);
0067 
0068   QImage images_[NO_OF_IMAGES];
0069 
0070   QPixmap smallStone_xpm_[SMALL_STONES];
0071   QPixmap largeStone_xpm_[LARGE_STONES];
0072   QPixmap otherPixmaps_[OTHER_IMAGES];
0073   QPixmap background_, brightObject_, brightTreasure_;
0074   QPixmap floor_;
0075   QImage  objectImg_;
0076   
0077   int indexSize_;
0078   QByteArray upperLargeIndex_;
0079   QByteArray lowerLargeIndex_;
0080   QByteArray leftSmallIndex_;
0081   QByteArray rightSmallIndex_;
0082 
0083   int size_, halfSize_;
0084   QRandomGenerator random;
0085 };
0086 
0087 #endif  /* IMAGEDATA_H */