[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/games/KWarBots/src
From: Rodrigo Gonçalves de Oliveira <mdkcore () gmail ! com>
Date: 2010-02-27 4:08:50
Message-ID: 1267243730.332993.929.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1096623 by rodrigoo:
Added image caching on ImageLoader
M +6 -0 battlearea.cpp
M +21 -3 imageloader.cpp
M +1 -0 imageloader.h
--- trunk/playground/games/KWarBots/src/battlearea.cpp #1096622:1096623
@@ -17,6 +17,11 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <KGlobal>
+#include <KAboutData>
+#include <KCmdLineArgs>
+#include <KStandardDirs>
+
#include "battlearea.h"
#include "tileobject.h"
#include "map.h"
@@ -50,6 +55,7 @@
timer->start();
///
+ //qDebug() << "---- DIR: " << KGlobal::dirs()->installPath("data") + \
KCmdLineArgs::aboutData()->appName(); }
BattleArea::~BattleArea(){
--- trunk/playground/games/KWarBots/src/imageloader.cpp #1096622:1096623
@@ -18,9 +18,9 @@
*/
#include <QPainter>
+#include <QPixmapCache>
#include "imageloader.h"
-#include <QDebug>
namespace KWB{
@@ -29,9 +29,16 @@
m_base = QColor(192, 192, 192); // base changeable color
m_alternate = QColor(128, 128, 128); // alternate changeable color
+
+ m_fileName = path.mid(path.lastIndexOf("/") + 1).remove(".svgz");
}
QPixmap ImageLoader::retrieve(const QString &element, const QSize &size, const \
QColor &color){ + // caching
+ QPixmap pixmap;
+ if (QPixmapCache::find("kwb_" + m_fileName + element + color.name()))
+ return pixmap;
+
// loading
if (!m_svg->elementExists(element))
return QPixmap();
@@ -62,10 +69,18 @@
// well done!
p.end();
- return QPixmap::fromImage(temp);
+ pixmap = QPixmap::fromImage(temp);
+ QPixmapCache::insert("kwb_" + m_fileName + element + color.name(), pixmap);
+
+ return pixmap;
}
QPixmap ImageLoader::retrieve(const QString &element, const QSize &size, const \
QColor &color1, const QColor &color2){ + // caching
+ QPixmap pixmap;
+ if (QPixmapCache::find("kwb_" + m_fileName + element + color1.name() + \
color2.name(), pixmap)) + return pixmap;
+
// loading
if (!m_svg->elementExists(element))
return QPixmap();
@@ -94,7 +109,10 @@
// well done!
p.end();
- return QPixmap::fromImage(temp);
+ pixmap = QPixmap::fromImage(temp);
+ QPixmapCache::insert("kwb_" + m_fileName + element + color1.name() + color2.name(), \
pixmap); +
+ return pixmap;
}
} // namespace
--- trunk/playground/games/KWarBots/src/imageloader.h #1096622:1096623
@@ -37,6 +37,7 @@
private:
QSvgRenderer *m_svg;
QColor m_base, m_alternate;
+ QString m_fileName;
};
} // namespace
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic