summaryrefslogtreecommitdiff
path: root/utils/themeeditor/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'utils/themeeditor/graphics')
-rw-r--r--utils/themeeditor/graphics/rbfont.cpp19
-rw-r--r--utils/themeeditor/graphics/rbfontcache.cpp21
-rw-r--r--utils/themeeditor/graphics/rbfontcache.h2
-rw-r--r--utils/themeeditor/graphics/rbtext.cpp14
-rw-r--r--utils/themeeditor/graphics/rbtext.h4
-rw-r--r--utils/themeeditor/graphics/rbtextcache.cpp35
-rw-r--r--utils/themeeditor/graphics/rbtextcache.h39
7 files changed, 120 insertions, 14 deletions
diff --git a/utils/themeeditor/graphics/rbfont.cpp b/utils/themeeditor/graphics/rbfont.cpp
index cd68af9..3b73972 100644
--- a/utils/themeeditor/graphics/rbfont.cpp
+++ b/utils/themeeditor/graphics/rbfont.cpp
@@ -21,6 +21,7 @@
#include "rbfont.h"
#include "rbfontcache.h"
+#include "rbtextcache.h"
#include <QFont>
#include <QBrush>
@@ -166,6 +167,13 @@ RBFont::~RBFont()
RBText* RBFont::renderText(QString text, QColor color, int viewWidth,
QGraphicsItem *parent)
{
+
+ /* Checking for a cache hit first */
+ QImage* image = RBTextCache::lookup(header.value("filename").toString()
+ + text);
+ if(image)
+ return new RBText(image, viewWidth, parent);
+
int firstChar = header.value("firstchar").toInt();
int height = header.value("height").toInt();
int maxWidth = header.value("maxwidth").toInt();
@@ -184,10 +192,10 @@ RBText* RBFont::renderText(QString text, QColor color, int viewWidth,
for(int i = 0; i < widths.count(); i++)
totalWidth += widths[i];
- QImage image(totalWidth, height, QImage::Format_Indexed8);
+ image = new QImage(totalWidth, height, QImage::Format_Indexed8);
- image.setColor(0, qRgba(0,0,0,0));
- image.setColor(1, color.rgb());
+ image->setColor(0, qRgba(0,0,0,0));
+ image->setColor(1, color.rgb());
/* Drawing the text */
int startX = 0;
@@ -214,9 +222,9 @@ RBText* RBFont::renderText(QString text, QColor color, int viewWidth,
for(int bit = 0; bit < 8; bit++)
{
if(mask & data)
- image.setPixel(x, y, 1);
+ image->setPixel(x, y, 1);
else
- image.setPixel(x, y, 0);
+ image->setPixel(x, y, 0);
y++;
mask <<= 1;
@@ -230,6 +238,7 @@ RBText* RBFont::renderText(QString text, QColor color, int viewWidth,
startX += widths[i];
}
+ RBTextCache::insert(header.value("filename").toString() + text, image);
return new RBText(image, viewWidth, parent);
}
diff --git a/utils/themeeditor/graphics/rbfontcache.cpp b/utils/themeeditor/graphics/rbfontcache.cpp
index 3b6d56f..7ec77e1 100644
--- a/utils/themeeditor/graphics/rbfontcache.cpp
+++ b/utils/themeeditor/graphics/rbfontcache.cpp
@@ -22,3 +22,24 @@
#include "rbfontcache.h"
QHash<QString, RBFontCache::CacheInfo*> RBFontCache::cache;
+
+void RBFontCache::clearCache()
+{
+ QHash<QString, CacheInfo*>::iterator i;
+ for(i = cache.begin(); i != cache.end(); i++)
+ {
+ CacheInfo* c = *i;
+ if(c->imageData)
+ delete c->imageData;
+
+ if(c->offsetData)
+ delete c->offsetData;
+
+ if(c->widthData)
+ delete c->widthData;
+
+ delete c;
+ }
+
+ cache.clear();
+}
diff --git a/utils/themeeditor/graphics/rbfontcache.h b/utils/themeeditor/graphics/rbfontcache.h
index 50a6d2e..62d82b7 100644
--- a/utils/themeeditor/graphics/rbfontcache.h
+++ b/utils/themeeditor/graphics/rbfontcache.h
@@ -23,6 +23,7 @@
#define RBFONTCACHE_H
#include <QHash>
+#include <QVariant>
class RBFontCache
{
@@ -39,6 +40,7 @@ public:
static CacheInfo* lookup(QString key){ return cache.value(key, 0); }
static void insert(QString key, CacheInfo* data){ cache.insert(key, data); }
+ static void clearCache();
private:
static QHash<QString, CacheInfo*> cache;
diff --git a/utils/themeeditor/graphics/rbtext.cpp b/utils/themeeditor/graphics/rbtext.cpp
index d7fe542..4666f9a 100644
--- a/utils/themeeditor/graphics/rbtext.cpp
+++ b/utils/themeeditor/graphics/rbtext.cpp
@@ -23,24 +23,24 @@
#include <QPainter>
-RBText::RBText(const QImage &image, int maxWidth, QGraphicsItem *parent)
+RBText::RBText(QImage* image, int maxWidth, QGraphicsItem *parent)
:QGraphicsItem(parent), image(image), maxWidth(maxWidth)
{
}
QRectF RBText::boundingRect() const
{
- if(image.width() < maxWidth)
- return QRectF(0, 0, image.width(), image.height());
+ if(image->width() < maxWidth)
+ return QRectF(0, 0, image->width(), image->height());
else
- return QRectF(0, 0, maxWidth, image.height());
+ return QRectF(0, 0, maxWidth, image->height());
}
void RBText::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
- if(image.width() < maxWidth)
- painter->drawImage(0, 0, image, 0, 0, image.width(), image.height());
+ if(image->width() < maxWidth)
+ painter->drawImage(0, 0, *image, 0, 0, image->width(), image->height());
else
- painter->drawImage(0, 0, image, 0, 0, maxWidth, image.height());
+ painter->drawImage(0, 0, *image, 0, 0, maxWidth, image->height());
}
diff --git a/utils/themeeditor/graphics/rbtext.h b/utils/themeeditor/graphics/rbtext.h
index d035054..936a809 100644
--- a/utils/themeeditor/graphics/rbtext.h
+++ b/utils/themeeditor/graphics/rbtext.h
@@ -28,14 +28,14 @@
class RBText : public QGraphicsItem
{
public:
- RBText(const QImage& image, int maxWidth, QGraphicsItem* parent);
+ RBText(QImage* image, int maxWidth, QGraphicsItem* parent);
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
private:
- QImage image;
+ QImage* image;
int maxWidth;
};
diff --git a/utils/themeeditor/graphics/rbtextcache.cpp b/utils/themeeditor/graphics/rbtextcache.cpp
new file mode 100644
index 0000000..0116b80
--- /dev/null
+++ b/utils/themeeditor/graphics/rbtextcache.cpp
@@ -0,0 +1,35 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2010 Robert Bieber
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "rbtextcache.h"
+
+QHash<QString, QImage*> RBTextCache::cache;
+
+void RBTextCache::clearCache()
+{
+ QHash<QString, QImage*>::iterator i;
+ for(i = cache.begin(); i != cache.end(); i++)
+ {
+ delete (*i);
+ }
+
+ cache.clear();
+}
diff --git a/utils/themeeditor/graphics/rbtextcache.h b/utils/themeeditor/graphics/rbtextcache.h
new file mode 100644
index 0000000..a0c0e42
--- /dev/null
+++ b/utils/themeeditor/graphics/rbtextcache.h
@@ -0,0 +1,39 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2010 Robert Bieber
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#ifndef RBTEXTCACHE_H
+#define RBTEXTCACHE_H
+
+#include <QHash>
+#include <QImage>
+
+class RBTextCache
+{
+public:
+ static QImage* lookup(QString key){ return cache.value(key, 0); }
+ static void insert(QString key, QImage* im){ cache.insert(key, im); }
+ static void clearCache();
+
+private:
+ static QHash<QString, QImage*> cache;
+};
+
+#endif // RBTEXTCACHE_H