• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kgoldrunner

kgrplayfield.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                     kgrplayfield.cpp  -  description                    *
00003  *                           -------------------                           *
00004  *  begin                : Fri Aug 04 2006                                 *
00005  *  Copyright 2006 Mauricio Piacentini <mauricio@tabuleiro.com>            *
00006  *  Copyright 2006 Dmitry Suzdalev <dimsuz@gmail.com>                      *
00007  *                                                                         *
00008  ***************************************************************************/
00009 
00010 /***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
00016  *                                                                         *
00017  ***************************************************************************/
00018 
00019 #include "kgrplayfield.h"
00020 #include <KDebug>
00021 
00022 KGrPlayField::KGrPlayField (KGameCanvasAbstract* canvas)
00023     : KGameCanvasGroup (canvas), m_tileset (0), m_background (0)
00024 {
00025     show();
00026 }
00027 
00028 KGrPlayField::~KGrPlayField()
00029 {
00030     // Clear all stored data.
00031     while (!m_tilesprites.isEmpty()) 
00032         delete m_tilesprites.takeFirst();
00033     delete m_background;
00034 }
00035 
00036 void KGrPlayField::setTile (int x, int y, int tilenum)
00037 {
00038     Q_ASSERT (m_tileset);
00039     // Update the sprite pixmap using our tileset cache.
00040     if ((m_background != 0) && (tilenum == 0)) {
00041         m_tilesprites.at(y*m_numTilesH + x)->hide();
00042     }
00043     else {
00044         m_tilesprites.at(y*m_numTilesH + x)->setPixmap (m_tileset->at(tilenum));
00045         m_tilesprites.at(y*m_numTilesH + x)->show();
00046         m_tilesprites.at(y*m_numTilesH + x)->raise();
00047     }
00048 }
00049 
00050 void KGrPlayField::setBackground (const bool create, const QPixmap &background,
00051                                         const QPoint & tl)
00052 {
00053     if (create) {
00054         delete m_background;                // Create a background
00055         m_background = 0;               // from tile zero
00056         if (!background.isNull()) {         // or a QImage.
00057             m_background = new KGameCanvasPixmap (this);
00058             m_background->moveTo (tl.x(), tl.y());
00059             m_background->setPixmap (background);
00060             m_background->show();
00061         }
00062     }
00063     else {
00064         m_background->moveTo (tl.x(), tl.y());      // Move an existing bg.
00065     }
00066 }
00067 
00068 void KGrPlayField::setTiles (QList<QPixmap> * tileset, const QPoint & topLeft,
00069         const int h, const int v, const int tilewidth, const int tileheight)
00070 {
00071     QPixmap   pm;
00072     m_tilew = tilewidth;
00073     m_tileh = tileheight;
00074     m_numTilesH = h;
00075     m_numTilesV = v;
00076 
00077     Q_ASSERT (tileset);
00078     // Clear previously cached tile data.
00079     while (! m_tilesprites.isEmpty())
00080         delete m_tilesprites.takeFirst();
00081 
00082     // Now store our tileset as a list of Pixmaps, one for each tile.
00083     m_tileset = tileset;
00084 
00085     // Create the list of tile sprites in the playfield, arranged as a grid.
00086     int totaltiles = m_numTilesH * m_numTilesV;
00087     for (int i=0; i < totaltiles; ++i) {
00088         KGameCanvasPixmap * thissprite = new KGameCanvasPixmap (this);
00089         thissprite->moveTo ((i % m_numTilesH) * m_tilew + topLeft.x(),
00090                            (i / m_numTilesH) * m_tileh + topLeft.y());
00091         if (m_background == 0) {
00092             // If no background pixmap, fill the cell with tile zero.
00093             thissprite->setPixmap (m_tileset->at (0));
00094             thissprite->show();
00095         }
00096 
00097         //Finally, store the item in our tilesprite list
00098         m_tilesprites.append (thissprite);
00099     }
00100 }

kgoldrunner

Skip menu "kgoldrunner"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

API Reference

Skip menu "API Reference"
  • kblackbox
  • kgoldrunner
  • kmahjongg
  • ksquares
  • libkdegames
  •   highscore
  •   kgame
  •   kggzgames
  •   kggzmod
  •   kggznet
  • libkmahjongg
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal