[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdegames/katomic
From: Dmitry Suzdalev <dimsuz () gmail ! com>
Date: 2006-11-02 11:07:23
Message-ID: 1162465643.866111.19704.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 601168 by dimsuz:
Now all elements of game field are rendered from SVG!
Starting to implement resizing ;)
M abilder.svgz
M +16 -34 feld.cpp
M +0 -2 feld.h
M +54 -26 katomicrenderer.cpp
M +16 -9 katomicrenderer.h
--- trunk/KDE/kdegames/katomic/feld.cpp #601167:601168
@@ -549,21 +549,6 @@
}
}
-void Feld::putNonAtom (int x, int y, Direction which, QPainter &p, bool brick)
-{
- int xarr=0, yarr=0;
- switch (which)
- {
- case None : xarr = 279, yarr = 31 * (brick?1:2); break;
- case MoveUp : xarr = 248; yarr = 62; break;
- case MoveLeft : xarr = 217; yarr = 93; break;
- case MoveDown : xarr = 248; yarr = 93; break;
- case MoveRight : xarr = 279; yarr = 93; break;
- }
-
- p.drawPixmap(x * 30, y * 30, data, xarr, yarr, 30, 30);
-}
-
void Feld::paintEvent( QPaintEvent * )
{
int i, j, x, y;
@@ -579,7 +564,6 @@
}
paint.fillRect(0, 0, 15 * 30, 15 * 30, Qt::black);
- // spielfeld gleich zeichnen
kDebug() << " -= begin paint event =- " << endl;
for (i = 0; i < FIELD_SIZE; i++)
@@ -592,31 +576,29 @@
x = i * 30;
y = j * 30;
- // zeichnet Randstücke
+ QPixmap aPix;
+ // FIXME dimsuz: move away from all this digits! :)
+ // wall
if (feld[i][j] == 254) {
- putNonAtom(i, j, Feld::None, paint, true); continue;
+ aPix = m_renderer->renderNonAtom('#');
+ }
+ else if (feld[i][j] == 150) {
+ aPix = m_renderer->renderNonAtom('^');
}
-
- if (feld[i][j] == 150) {
- putNonAtom(i, j, Feld::MoveUp, paint); continue;
+ else if (feld[i][j] == 151) {
+ aPix = m_renderer->renderNonAtom('<');
}
-
- if (feld[i][j] == 151) {
- putNonAtom(i, j, Feld::MoveLeft, paint); continue;
+ else if (feld[i][j] == 152) {
+ aPix = m_renderer->renderNonAtom('_');
}
- if (feld[i][j] == 152) {
- putNonAtom(i, j, Feld::MoveDown, paint); continue;
+ else if (feld[i][j] == 153) {
+ aPix = m_renderer->renderNonAtom('>');
}
-
- if (feld[i][j] == 153) {
- putNonAtom(i, j, Feld::MoveRight, paint); continue;
- }
-
- if( getAtom(feld[i][j]).obj != 0 )
+ else if( getAtom(feld[i][j]).obj != 0 )
{
- QPixmap aPix = m_renderer->renderAtom( getAtom(feld[i][j]) );
- paint.drawPixmap(x,y, aPix);
+ aPix = m_renderer->renderAtom( getAtom(feld[i][j]) );
}
+ paint.drawPixmap(x,y, aPix);
}
}
kDebug() << "-= end paint event =-" << endl;
--- trunk/KDE/kdegames/katomic/feld.h #601167:601168
@@ -71,8 +71,6 @@
const atom& getAtom(uint index) const;
- void putNonAtom(int, int, Direction, QPainter &p, bool brick = false);
-
void resetValidDirs();
QPoint *point;
--- trunk/KDE/kdegames/katomic/katomicrenderer.cpp #601167:601168
@@ -32,12 +32,12 @@
{
m_renderer = new KSvgRenderer( pathToSvg, parent);
fillNameHashes();
- setAtomSize(30);
+ setElementSize(30);
}
-void KAtomicRenderer::setAtomSize( int size )
+void KAtomicRenderer::setElementSize( int size )
{
- m_atomSize = size;
+ m_elemSize = size;
// TODO re-render cache contents. Or clear?
}
@@ -46,17 +46,17 @@
if (!m_renderer->isValid()) return QPixmap();
// FIXME dimsuz: move this to function. smth like ensureInCache(at)
QImage baseImg;
- if(!m_atomCache.contains(at.obj))
+ if(!m_cache.contains(at.obj))
{
kDebug() << "putting atom to cache" << endl;
//Construct an image object to render the contents of the .svgz file
- baseImg = QImage(m_atomSize, m_atomSize, QImage::Format_ARGB32_Premultiplied);
+ baseImg = QImage(m_elemSize, m_elemSize, QImage::Format_ARGB32_Premultiplied);
//Fill the buffer, it is unitialised by default
baseImg.fill(0);
QPainter p(&baseImg);
- m_renderer->render(&p, m_atomNames.value(at.obj), QRectF(0,0, m_atomSize, m_atomSize) );
+ m_renderer->render(&p, m_names.value(at.obj), QRectF(0,0, m_elemSize, m_elemSize) );
QPixmap atomPix = QPixmap::fromImage(baseImg);
- m_atomCache[at.obj] = atomPix;
+ m_cache[at.obj] = atomPix;
}
else
kDebug() << "reusing atom from cache" << endl;
@@ -70,11 +70,11 @@
{
kDebug() << "putting bond to cache" << endl;
//Construct an image object to render the contents of the .svgz file
- baseImg = QImage(m_atomSize, m_atomSize, QImage::Format_ARGB32_Premultiplied);
+ baseImg = QImage(m_elemSize, m_elemSize, QImage::Format_ARGB32_Premultiplied);
//Fill the buffer, it is unitialised by default
baseImg.fill(0);
QPainter p(&baseImg);
- m_renderer->render(&p, m_bondNames.value(conn), QRectF(0,0, m_atomSize, m_atomSize) );
+ m_renderer->render(&p, m_bondNames.value(conn), QRectF(0,0, m_elemSize, m_elemSize) );
QPixmap bondPix = QPixmap::fromImage(baseImg);
m_bondCache[conn] = bondPix;
}
@@ -82,7 +82,7 @@
kDebug() << "reusing bond from cache" << endl;
}
- QPixmap res(m_atomSize, m_atomSize);
+ QPixmap res(m_elemSize, m_elemSize);
res.fill( Qt::transparent );
QPainter p(&res);
// paint connections first
@@ -94,28 +94,56 @@
p.drawPixmap( 0, 0, m_bondCache.value( conn ) );
}
// and now the atom
- p.drawPixmap( 0, 0, m_atomCache.value( at.obj ) );
+ p.drawPixmap( 0, 0, m_cache.value( at.obj ) );
p.end();
return res;
}
+QPixmap KAtomicRenderer::renderNonAtom( char element )
+{
+ if (!m_renderer->isValid()) return QPixmap();
+
+ QImage baseImg;
+ if(!m_cache.contains(element))
+ {
+ kDebug() << "putting element to cache" << endl;
+ //Construct an image object to render the contents of the .svgz file
+ baseImg = QImage(m_elemSize, m_elemSize, QImage::Format_ARGB32_Premultiplied);
+ //Fill the buffer, it is unitialised by default
+ baseImg.fill(0);
+ QPainter p(&baseImg);
+ m_renderer->render(&p, m_names.value(element), QRectF(0,0, m_elemSize, m_elemSize) );
+ QPixmap pix = QPixmap::fromImage(baseImg);
+ m_cache[element] = pix;
+ }
+ else
+ kDebug() << "reusing element from cache" << endl;
+
+ return m_cache.value(element);
+}
+
void KAtomicRenderer::fillNameHashes()
{
- m_atomNames['1'] = "atom_H";
- m_atomNames['2'] = "atom_C";
- m_atomNames['3'] = "atom_O";
- m_atomNames['4'] = "atom_N";
- m_atomNames['5'] = "atom_S";
- m_atomNames['6'] = "atom_F";
- m_atomNames['7'] = "atom_Cl";
- m_atomNames['8'] = "atom_Br";
- m_atomNames['9'] = "atom_P";
- m_atomNames['0'] = "atom_J";
- m_atomNames['o'] = "atom_Crystal";
- m_atomNames['A'] = "connector_Hor";
- m_atomNames['B'] = "connector_Slash";
- m_atomNames['C'] = "connector_Ver";
- m_atomNames['D'] = "connector_Backslash";
+ m_names['1'] = "atom_H";
+ m_names['2'] = "atom_C";
+ m_names['3'] = "atom_O";
+ m_names['4'] = "atom_N";
+ m_names['5'] = "atom_S";
+ m_names['6'] = "atom_F";
+ m_names['7'] = "atom_Cl";
+ m_names['8'] = "atom_Br";
+ m_names['9'] = "atom_P";
+ m_names['0'] = "atom_J";
+ m_names['o'] = "atom_Crystal";
+ m_names['A'] = "connector_Hor";
+ m_names['B'] = "connector_Slash";
+ m_names['C'] = "connector_Ver";
+ m_names['D'] = "connector_Backslash";
+ m_names['#'] = "wall";
+ m_names['<'] = "arrow_Left";
+ m_names['>'] = "arrow_Right";
+ m_names['^'] = "arrow_Up";
+ m_names['_'] = "arrow_Down";
m_bondNames['a'] = "bond_I_Top";
m_bondNames['b'] = "bond_I_TopRight";
--- trunk/KDE/kdegames/katomic/katomicrenderer.h #601167:601168
@@ -29,7 +29,7 @@
class KSvgRenderer;
/**
- * Class for rendering atoms to QPixmap
+ * Class for rendering elements of game SVG to QPixmap
*/
class KAtomicRenderer
{
@@ -40,14 +40,21 @@
*/
KAtomicRenderer( const QString& pathToSvg, QObject *parent=0 );
/**
- * Sets atom size
+ * Sets rendered element size.
+ * I.e. render* functions will return QPixmap of (size,size) dimentions
*/
- void setAtomSize(int size);
+ void setElementSize(int size);
/**
* Renders atom to pixmap.
- * If setAtomSize() wasn't called it assumes size of 30 px
+ * If setElementSize() wasn't called it assumes size of 30 px
*/
QPixmap renderAtom( const atom& );
+ /**
+ * Renders non-atom elements (wall and arrows) to pixmap.
+ * @param element if == '#' will render a wall, if '<','>','^','_' will render
+ * arrow-left,arrow-right,arrow-up or arrow-down
+ */
+ QPixmap renderNonAtom( char element );
private:
/**
* FIXME dimsuz: describe better
@@ -55,17 +62,17 @@
*/
void fillNameHashes();
KSvgRenderer *m_renderer;
- // I'd use a two hashes (for Cache and for names)
- // instead of four, but currently both bond and atom chars can be
+ // I'd use a two hashes (for Cache and for names) instead of four,
+ // but currently both bond and atom chars can be
// "A-D", i.e. they overlap, so I need to separate
// If level format changes somehow, then corresponding atom and bond hashes
// can be merged
// FIXME dimsuz: document them
- QHash<char, QPixmap> m_atomCache;
+ QHash<char, QPixmap> m_cache;
QHash<char, QPixmap> m_bondCache;
- QHash<char, QString> m_atomNames; // cryptic_char -> elemName
+ QHash<char, QString> m_names; // cryptic_char -> elemName
QHash<char, QString> m_bondNames; // cryptic_char -> bondName
- int m_atomSize;
+ int m_elemSize;
};
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic